Skip to content

Commit fda06ab

Browse files
committed
Reapplying my changes back
1 parent 84c32a4 commit fda06ab

15 files changed

+66
-335
lines changed

Source/ModuleManager/CustomConfigsManager.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,47 @@ namespace ModuleManager
99
[KSPAddon(KSPAddon.Startup.SpaceCentre, false)]
1010
public class CustomConfigsManager : MonoBehaviour
1111
{
12+
internal static bool start_techtree_loaded = false;
13+
internal static bool start_physics_loaded = false;
1214
internal void Start()
1315
{
14-
if (HighLogic.CurrentGame.Parameters.Career.TechTreeUrl != techTreeFile && File.Exists(techTreePath))
16+
#if false
17+
Log("Blah");
18+
Log(HighLogic.CurrentGame.Parameters.Career.TechTreeUrl);
19+
Log(TECHTREE_CONFIG.Path);
20+
Log(TECHTREE_CONFIG.IsLoadable.ToString());
21+
#endif
22+
if (start_techtree_loaded)
23+
{
24+
if (HighLogic.CurrentGame.Parameters.Career.TechTreeUrl != TECHTREE_CONFIG.KspPath)
25+
Log(string.Format("Tech tree was changed by third party to [{0}].", HighLogic.CurrentGame.Parameters.Career.TechTreeUrl));
26+
}
27+
else if (TECHTREE_CONFIG.IsLoadable)
1528
{
1629
Log("Setting modded tech tree as the active one");
17-
HighLogic.CurrentGame.Parameters.Career.TechTreeUrl = techTreeFile;
30+
HighLogic.CurrentGame.Parameters.Career.TechTreeUrl = TECHTREE_CONFIG.KspPath;
31+
start_techtree_loaded = true;
1832
}
1933

20-
if (PhysicsGlobals.PhysicsDatabaseFilename != physicsFile && File.Exists(physicsPath))
34+
if (start_physics_loaded)
35+
{
36+
if (PhysicsGlobals.PhysicsDatabaseFilename != PHYSICS_CONFIG.Path)
37+
Log(string.Format("Physics changed by third party to [{0}].", PhysicsGlobals.PhysicsDatabaseFilename));
38+
}
39+
else if (PHYSICS_CONFIG.IsLoadable)
2140
{
2241
Log("Setting modded physics as the active one");
23-
24-
PhysicsGlobals.PhysicsDatabaseFilename = physicsFile;
25-
42+
PhysicsGlobals.PhysicsDatabaseFilename = PHYSICS_CONFIG.Path;
2643
if (!PhysicsGlobals.Instance.LoadDatabase())
2744
Log("Something went wrong while setting the active physics config.");
45+
start_physics_loaded = true;
2846
}
2947
}
3048

31-
public static void Log(String s)
49+
private static readonly KSPe.Util.Log.Logger log = KSPe.Util.Log.Logger.CreateForType<CustomConfigsManager>();
50+
private static void Log(String s)
3251
{
33-
print("[CustomConfigsManager] " + s);
52+
log.info(s);
3453
}
3554

3655
}

Source/ModuleManager/ExceptionIntercept/InterceptLogHandler.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class InterceptLogHandler : ILogHandler
1818

1919
public InterceptLogHandler()
2020
{
21-
baseLogHandler = Debug.unityLogger.logHandler;
22-
Debug.unityLogger.logHandler = this;
21+
baseLogHandler = Debug.logger.logHandler;
22+
Debug.logger.logHandler = this;
2323
gamePathLength = Path.GetFullPath(KSPUtil.ApplicationRootPath).Length;
2424
}
2525

@@ -37,12 +37,12 @@ public void LogException(Exception exception, Object context)
3737
string message = "Intercepted a ReflectionTypeLoadException. List of broken DLLs:\n";
3838
try
3939
{
40-
var assemblies = ex.Types.Where(x => x != null).Select(x => x.Assembly).Distinct();
40+
IEnumerable<Assembly> assemblies = ex.Types.Where(x => x != null).Select(x => x.Assembly).Distinct();
4141
foreach (Assembly assembly in assemblies)
4242
{
43-
if (Warnings == "")
43+
if (string.IsNullOrEmpty(Warnings))
4444
{
45-
Warnings = "Mod(s) DLL that are not compatible with this version of KSP\n";
45+
Warnings = "Add'On(s) DLL that have failed to be dynamically linked on loading\n";
4646
}
4747
string modInfo = assembly.GetName().Name + " " + assembly.GetName().Version + " " +
4848
assembly.Location.Remove(0, gamePathLength) + "\n";
@@ -58,7 +58,8 @@ public void LogException(Exception exception, Object context)
5858
{
5959
message += "Exception " + e.GetType().Name + " while handling the exception...";
6060
}
61-
ModuleManager.Log(message);
61+
Logging.ModLogger.LOG.error("**FATAL** {0}", message);
62+
GUI.ShowStopperAlertBox.Show(message);
6263
}
6364
}
6465
}

Source/ModuleManager/Extensions/IBasicLoggerExtensions.cs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,8 @@ namespace ModuleManager.Extensions
66
{
77
public static class IBasicLoggerExtensions
88
{
9-
public static void Info(this IBasicLogger logger, string message) => logger.Log(new LogMessage(LogType.Log, message));
10-
public static void Warning(this IBasicLogger logger, string message) => logger.Log(new LogMessage(LogType.Warning, message));
11-
public static void Error(this IBasicLogger logger, string message) => logger.Log(new LogMessage(LogType.Error, message));
12-
13-
public static void Exception(this IBasicLogger logger, Exception exception)
14-
{
15-
if (exception == null) throw new ArgumentNullException(nameof(exception));
16-
logger.Log(new LogMessage(LogType.Exception, exception.ToString()));
17-
}
18-
19-
public static void Exception(this IBasicLogger logger, string message, Exception exception)
20-
{
21-
if (message == null) throw new ArgumentNullException(nameof(message));
22-
if (exception == null) throw new ArgumentNullException(nameof(exception));
23-
logger.Log(new LogMessage(LogType.Exception, message + ": " + exception.ToString()));
24-
}
9+
public static void Info(this IBasicLogger logger, string message) => logger.Log(LogType.Log, message);
10+
public static void Warning(this IBasicLogger logger, string message) => logger.Log(LogType.Warning, message);
11+
public static void Error(this IBasicLogger logger, string message) => logger.Log(LogType.Error, message);
2512
}
2613
}
Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
1-
using System;
2-
using System.IO;
1+
using PluginConfig = KSPe.IO.Data<ModuleManager.ModuleManager>.ConfigNode;
2+
using KspConfig = KSPe.IO.KspConfigNode;
33

44
namespace ModuleManager
55
{
66
internal static class FilePathRepository
77
{
8-
internal static readonly string cachePath = Path.Combine(KSPUtil.ApplicationRootPath, "GameData", "ModuleManager.ConfigCache");
8+
internal static readonly PluginConfig SHA_CONFIG = PluginConfig.For(null, "ConfigSHA.cfg");
9+
internal static readonly PluginConfig CACHE_CONFIG = PluginConfig.For(null, "ConfigCache.cfg");
10+
internal static readonly PluginConfig PHYSICS_CONFIG = PluginConfig.For(null, "Physics.cfg");
11+
internal static readonly PluginConfig TECHTREE_CONFIG = PluginConfig.For("TechTree");
12+
internal static readonly KspConfig PHYSICS_DEFAULT = new KspConfig("Physics");
13+
internal static readonly KspConfig PART_DATABASE = new KspConfig("PartDatabase");
914

10-
internal static readonly string techTreeFile = Path.Combine("GameData", "ModuleManager.TechTree");
11-
internal static readonly string techTreePath = Path.Combine(KSPUtil.ApplicationRootPath, techTreeFile);
12-
13-
internal static readonly string physicsFile = Path.Combine("GameData", "ModuleManager.Physics");
14-
internal static readonly string physicsPath = Path.Combine(KSPUtil.ApplicationRootPath, physicsFile);
15-
internal static readonly string defaultPhysicsPath = Path.Combine(KSPUtil.ApplicationRootPath, "Physics.cfg");
16-
17-
internal static readonly string partDatabasePath = Path.Combine(KSPUtil.ApplicationRootPath, "PartDatabase.cfg");
18-
19-
internal static readonly string shaPath = Path.Combine(KSPUtil.ApplicationRootPath, "GameData", "ModuleManager.ConfigSHA");
20-
21-
internal static readonly string logsDirPath = Path.Combine(KSPUtil.ApplicationRootPath, "Logs", "ModuleManager");
22-
internal static readonly string logPath = Path.Combine(logsDirPath, "ModuleManager.log");
23-
internal static readonly string patchLogPath = Path.Combine(logsDirPath, "MMPatch.log");
15+
internal static readonly string MMCfgOutputPath = KSPe.IO.File<ModuleManager>.Data.Solve("_MMCfgOutput");
2416
}
2517
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
2+
using UnityEngine;
23

34
namespace ModuleManager.Logging
45
{
56
// Stripped down version of UnityEngine.ILogger
67
public interface IBasicLogger
78
{
8-
void Log(ILogMessage message);
9+
void Log(LogType logType, string message);
10+
void Exception(string message, Exception exception);
911
}
1012
}

Source/ModuleManager/Logging/ILogMessage.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

Source/ModuleManager/Logging/LogMessage.cs

Lines changed: 0 additions & 53 deletions
This file was deleted.

Source/ModuleManager/Logging/LogSplitter.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

Source/ModuleManager/Logging/PrefixLogger.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

Source/ModuleManager/Logging/QueueLogRunner.cs

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)