|
| 1 | +/** |
| 2 | + * Based on the InstallChecker from the Kethane mod for Kerbal Space Program. |
| 3 | + * https://github.com/Majiir/Kethane/blob/b93b1171ec42b4be6c44b257ad31c7efd7ea1702/Plugin/InstallChecker.cs |
| 4 | + * |
| 5 | + * Original is (C) Copyright Majiir. |
| 6 | + * CC0 Public Domain (http://creativecommons.org/publicdomain/zero/1.0/) |
| 7 | + * http://forum.kerbalspaceprogram.com/threads/65395-CompatibilityChecker-Discussion-Thread?p=899895&viewfull=1#post899895 |
| 8 | + * |
| 9 | + * This file has been modified extensively and is released under the same license. |
| 10 | + */ |
| 11 | +using System; |
| 12 | +using System.IO; |
| 13 | +using System.Linq; |
| 14 | +using System.Reflection; |
| 15 | +using UnityEngine; |
| 16 | + |
| 17 | +namespace ClickThroughFix |
| 18 | +{ |
| 19 | + [KSPAddon(KSPAddon.Startup.Instantly, true)] |
| 20 | + internal class Startup : MonoBehaviour |
| 21 | + { |
| 22 | + private void Start() |
| 23 | + { |
| 24 | + string v = "n/a"; |
| 25 | + AssemblyTitleAttribute attributes = (AssemblyTitleAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyTitleAttribute), false); |
| 26 | + string title = attributes?.Title; |
| 27 | + if (title == null) |
| 28 | + { |
| 29 | + title = "TitleNotAvailable"; |
| 30 | + } |
| 31 | + v = Assembly.GetExecutingAssembly().FullName; |
| 32 | + if (v == null) |
| 33 | + { |
| 34 | + v = "VersionNotAvailable"; |
| 35 | + } |
| 36 | + Debug.Log("[" + title + "] Version " + v); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + [KSPAddon(KSPAddon.Startup.MainMenu, true)] |
| 41 | + internal class InstallChecker : MonoBehaviour |
| 42 | + { |
| 43 | + internal const string MODNAME = "ClickThroughBlocker"; |
| 44 | + internal const string FOLDERNAME = "000_ClickThroughBlocker"; |
| 45 | + internal const string EXPECTEDPATH = FOLDERNAME + "/Plugins"; |
| 46 | + |
| 47 | + protected void Start() |
| 48 | + { |
| 49 | + // Search for this mod's DLL existing in the wrong location. This will also detect duplicate copies because only one can be in the right place. |
| 50 | + var assemblies = AssemblyLoader.loadedAssemblies.Where(a => a.assembly.GetName().Name == Assembly.GetExecutingAssembly().GetName().Name).Where(a => a.url != EXPECTEDPATH); |
| 51 | + if (assemblies.Any()) |
| 52 | + { |
| 53 | + var badPaths = assemblies.Select(a => a.path).Select(p => Uri.UnescapeDataString(new Uri(Path.GetFullPath(KSPUtil.ApplicationRootPath)).MakeRelativeUri(new Uri(p)).ToString().Replace('/', Path.DirectorySeparatorChar))); |
| 54 | + PopupDialog.SpawnPopupDialog |
| 55 | + ( |
| 56 | + new Vector2(0.5f, 0.5f), |
| 57 | + new Vector2(0.5f, 0.5f), |
| 58 | + "test", |
| 59 | + "Incorrect " + MODNAME + " Installation", |
| 60 | + MODNAME + " has been installed incorrectly and will not function properly. All files should be located in KSP/GameData/" + FOLDERNAME + ". Do not move any files from inside that folder.\n\nIncorrect path(s):\n" + String.Join("\n", badPaths.ToArray()), |
| 61 | + "OK", |
| 62 | + false, |
| 63 | + HighLogic.UISkin |
| 64 | + ); |
| 65 | + Debug.Log("Incorrect " + MODNAME + " Installation: " + MODNAME + " has been installed incorrectly and will not function properly. All files should be located in KSP/GameData/" + EXPECTEDPATH + ". Do not move any files from inside that folder.\n\nIncorrect path(s):\n" + String.Join("\n", badPaths.ToArray()) |
| 66 | + |
| 67 | + ); |
| 68 | + |
| 69 | + } |
| 70 | + |
| 71 | + //// Check for Module Manager |
| 72 | + //if (!AssemblyLoader.loadedAssemblies.Any(a => a.assembly.GetName().Name.StartsWith("ModuleManager") && a.url == "")) |
| 73 | + //{ |
| 74 | + // PopupDialog.SpawnPopupDialog("Missing Module Manager", |
| 75 | + // modName + " requires the Module Manager mod in order to function properly.\n\nPlease download from http://forum.kerbalspaceprogram.com/threads/55219 and copy to the KSP/GameData/ directory.", |
| 76 | + // "OK", false, HighLogic.Skin); |
| 77 | + //} |
| 78 | + |
| 79 | + CleanupOldVersions(); |
| 80 | + } |
| 81 | + |
| 82 | + /* |
| 83 | + * Tries to fix the install if it was installed over the top of a previous version |
| 84 | + */ |
| 85 | + void CleanupOldVersions() |
| 86 | + { |
| 87 | + try |
| 88 | + { |
| 89 | + } |
| 90 | + catch (Exception ex) |
| 91 | + { |
| 92 | + Debug.LogError("-ERROR- " + this.GetType().FullName + "[" + this.GetInstanceID().ToString("X") + "][" + Time.time.ToString("0.00") + "]: " + |
| 93 | + "Exception caught while cleaning up old files.\n" + ex.Message + "\n" + ex.StackTrace); |
| 94 | + |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | +} |
| 99 | + |
0 commit comments