private void VersionCheck() { _version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); print("img_viewer.dll version: " + _version); if ((_version != _versionlastrun) && (File.Exists <ImgViewer>("config.xml"))) { File.Delete <ImgViewer>("config.xml"); } #if DEBUG File.Delete <ImgViewer>("config.xml"); #endif }
public override void OnLoad(ConfigNode sfsNode) { if (GuiUtils.skin == null) { //GuiUtils.skin = new GUISkin(); new GameObject("zombieGUILoader", typeof(ZombieGUILoader)); } try { bool generateDefaultWindows = false; base.OnLoad(sfsNode); //is this necessary? if (partSettings == null && sfsNode != null) { partSettings = sfsNode; } LoadComputerModules(); ConfigNode global = new ConfigNode("MechJebGlobalSettings"); if (File.Exists <MechJebCore>("mechjeb_settings_global.cfg")) { try { global = ConfigNode.Load(IOUtils.GetFilePathFor(this.GetType(), "mechjeb_settings_global.cfg")); } catch (Exception e) { Debug.LogError("MechJebCore.OnLoad caught an exception trying to load mechjeb_settings_global.cfg: " + e); generateDefaultWindows = true; } } else { generateDefaultWindows = true; } ConfigNode type = new ConfigNode("MechJebTypeSettings"); String vesselName = vessel != null?string.Join("_", vessel.vesselName.Split(System.IO.Path.GetInvalidFileNameChars())) : ""; // Strip illegal char from the filename if ((vessel != null) && File.Exists <MechJebCore>("mechjeb_settings_type_" + vesselName + ".cfg")) { try { type = ConfigNode.Load(IOUtils.GetFilePathFor(this.GetType(), "mechjeb_settings_type_" + vesselName + ".cfg")); } catch (Exception e) { Debug.LogError("MechJebCore.OnLoad caught an exception trying to load mechjeb_settings_type_" + vesselName + ".cfg: " + e); } } ConfigNode local = new ConfigNode("MechJebLocalSettings"); if (sfsNode != null && sfsNode.HasNode("MechJebLocalSettings")) { local = sfsNode.GetNode("MechJebLocalSettings"); } else if (partSettings != null && partSettings.HasNode("MechJebLocalSettings")) { local = partSettings.GetNode("MechJebLocalSettings"); } else if (sfsNode == null) // capture current Local settings { foreach (ComputerModule module in GetComputerModules <ComputerModule>()) { try { module.OnSave(local.AddNode(module.GetType().Name), null, null); } catch (Exception e) { Debug.LogError("MechJeb module " + module.GetType().Name + " threw an exception in OnLoad: " + e); } } } /*Debug.Log("OnLoad: loading from"); * Debug.Log("Local:"); * Debug.Log(local.ToString()); * Debug.Log("Type:"); * Debug.Log(type.ToString()); * Debug.Log("Global:"); * Debug.Log(global.ToString());*/ // Remove any currently loaded custom windows MechJebModuleCustomInfoWindow win; while ((win = GetComputerModule <MechJebModuleCustomInfoWindow>()) != null) { RemoveComputerModule(win); } foreach (ComputerModule module in GetComputerModules <ComputerModule>()) { try { string name = module.GetType().Name; ConfigNode moduleLocal = local.HasNode(name) ? local.GetNode(name) : null; ConfigNode moduleType = type.HasNode(name) ? type.GetNode(name) : null; ConfigNode moduleGlobal = global.HasNode(name) ? global.GetNode(name) : null; module.OnLoad(moduleLocal, moduleType, moduleGlobal); } catch (Exception e) { Debug.LogError("MechJeb module " + module.GetType().Name + " threw an exception in OnLoad: " + e); } } LoadDelayedModules(); if (generateDefaultWindows) { GetComputerModule <MechJebModuleCustomWindowEditor>().AddDefaultWindows(); } } catch (Exception e) { Debug.LogError("MechJeb caught exception in core OnLoad: " + e); } }
public override void OnLoad(ConfigNode sfsNode) { if (GuiUtils.skin == null) { //GuiUtils.skin = new GUISkin(); new GameObject("zombieGUILoader", typeof(ZombieGUILoader)); } try { bool generateDefaultWindows = false; base.OnLoad(sfsNode); //is this necessary? // With the Unity 4.6 upgrade of KSP 1.0 we inherited a serialization problem // with object with high depth like config nodes // so the partmodule config node passed was not ok. // So we use a static dir to save the part config node. if (!savedConfig.ContainsKey(part.name)) { if (HighLogic.LoadedScene == GameScenes.LOADING) { savedConfig.Add(part.name, sfsNode); } } else { partSettings = savedConfig[part.name]; } LoadComputerModules(); ConfigNode global = new ConfigNode("MechJebGlobalSettings"); if (File.Exists <MechJebCore>("mechjeb_settings_global.cfg")) { try { global = ConfigNode.Load(IOUtils.GetFilePathFor(this.GetType(), "mechjeb_settings_global.cfg")); } catch (Exception e) { Debug.LogError("MechJebCore.OnLoad caught an exception trying to load mechjeb_settings_global.cfg: " + e); generateDefaultWindows = true; } } else { generateDefaultWindows = true; } ConfigNode type = new ConfigNode("MechJebTypeSettings"); string vesselName = vessel != null?string.Join("_", vessel.vesselName.Split(System.IO.Path.GetInvalidFileNameChars())) : ""; // Strip illegal char from the filename if ((vessel != null) && File.Exists <MechJebCore>("mechjeb_settings_type_" + vesselName + ".cfg")) { try { type = ConfigNode.Load(IOUtils.GetFilePathFor(this.GetType(), "mechjeb_settings_type_" + vesselName + ".cfg")); } catch (Exception e) { Debug.LogError("MechJebCore.OnLoad caught an exception trying to load mechjeb_settings_type_" + vesselName + ".cfg: " + e); } } ConfigNode local = new ConfigNode("MechJebLocalSettings"); if (sfsNode != null && sfsNode.HasNode("MechJebLocalSettings")) { local = sfsNode.GetNode("MechJebLocalSettings"); } else if (partSettings != null && partSettings.HasNode("MechJebLocalSettings")) { local = partSettings.GetNode("MechJebLocalSettings"); } else if (sfsNode == null) // capture current Local settings { foreach (ComputerModule module in GetComputerModules <ComputerModule>()) { try { module.OnSave(local.AddNode(module.GetType().Name), null, null); } catch (Exception e) { Debug.LogError("MechJeb module " + module.GetType().Name + " threw an exception in OnLoad: " + e); } } } /*Debug.Log("OnLoad: loading from"); * Debug.Log("Local:"); * Debug.Log(local.ToString()); * Debug.Log("Type:"); * Debug.Log(type.ToString()); * Debug.Log("Global:"); * Debug.Log(global.ToString());*/ // Remove any currently loaded custom windows MechJebModuleCustomInfoWindow win; while ((win = GetComputerModule <MechJebModuleCustomInfoWindow>()) != null) { RemoveComputerModule(win); } foreach (ComputerModule module in GetComputerModules <ComputerModule>()) { try { string name = module.GetType().Name; ConfigNode moduleLocal = local.HasNode(name) ? local.GetNode(name) : null; ConfigNode moduleType = type.HasNode(name) ? type.GetNode(name) : null; ConfigNode moduleGlobal = global.HasNode(name) ? global.GetNode(name) : null; module.OnLoad(moduleLocal, moduleType, moduleGlobal); } catch (Exception e) { Debug.LogError("MechJeb module " + module.GetType().Name + " threw an exception in OnLoad: " + e); } } LoadDelayedModules(); if (generateDefaultWindows) { GetComputerModule <MechJebModuleCustomWindowEditor>().AddDefaultWindows(); } } catch (ReflectionTypeLoadException ex) { Debug.LogError("MechJeb caught a ReflectionTypeLoadException. Those DLL are not built for this KSP version:"); var brokenAssembly = ex.Types.Where(x => x != null).Select(x => x.Assembly).Distinct(); foreach (Assembly assembly in brokenAssembly) { Debug.LogError(assembly.GetName().Name + " " + assembly.GetName().Version + " " + assembly.Location.Remove(0, Path.GetFullPath(KSPUtil.ApplicationRootPath).Length)); } } catch (Exception e) { Debug.LogError("MechJeb caught exception in core OnLoad: " + e); } }