From 18d39fd8b9287aef47f1bfde216c635be17fb708 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Sun, 20 Sep 2020 00:40:20 -0500 Subject: [PATCH] Added --version to installer --- IPA.Loader/Config/SelfConfig.cs | 2 +- IPA.Loader/Loader/PluginLoader.cs | 1 + IPA.Loader/Loader/manifest.json | 2 +- IPA/Program.cs | 64 +++++++++++++++++++++++-------- 4 files changed, 51 insertions(+), 18 deletions(-) diff --git a/IPA.Loader/Config/SelfConfig.cs b/IPA.Loader/Config/SelfConfig.cs index 3ec18da5..01fa7f8e 100644 --- a/IPA.Loader/Config/SelfConfig.cs +++ b/IPA.Loader/Config/SelfConfig.cs @@ -68,7 +68,7 @@ namespace IPA.Config } internal const string IPAName = "Beat Saber IPA"; - internal const string IPAVersion = "4.1.2.0"; + internal const string IPAVersion = "4.1.3.0"; // uses Updates.AutoUpdate, Updates.AutoCheckUpdates, YeetMods, Debug.ShowCallSource, Debug.ShowDebug, // Debug.CondenseModLogs diff --git a/IPA.Loader/Loader/PluginLoader.cs b/IPA.Loader/Loader/PluginLoader.cs index 7ee77156..679b4bb9 100644 --- a/IPA.Loader/Loader/PluginLoader.cs +++ b/IPA.Loader/Loader/PluginLoader.cs @@ -104,6 +104,7 @@ namespace IPA.Loader Logger.loader.Critical("Error loading own manifest"); Logger.loader.Critical(e); } + var resolver = new CecilLibLoader(); resolver.AddSearchDirectory(UnityGame.LibraryPath); resolver.AddSearchDirectory(UnityGame.PluginsPath); diff --git a/IPA.Loader/Loader/manifest.json b/IPA.Loader/Loader/manifest.json index a00a5b81..488dad39 100644 --- a/IPA.Loader/Loader/manifest.json +++ b/IPA.Loader/Loader/manifest.json @@ -8,7 +8,7 @@ "gameVersion": "1.11.1", "id": "BSIPA", "name": "Beat Saber IPA", - "version": "4.1.2", + "version": "4.1.3", "icon": "IPA.icon_white.png", "features": { "IPA.DefineFeature": { diff --git a/IPA/Program.cs b/IPA/Program.cs index ec9a7c49..a5f60161 100644 --- a/IPA/Program.cs +++ b/IPA/Program.cs @@ -23,11 +23,12 @@ namespace IPA Unknown } - public const string FileVersion = "4.1.2.0"; + public const string FileVersion = "4.1.3.0"; public static Version Version => Assembly.GetEntryAssembly().GetName().Version; public static readonly ArgumentFlag ArgHelp = new ArgumentFlag("--help", "-h") { DocString = "prints this message" }; + public static readonly ArgumentFlag ArgVersion = new ArgumentFlag("--version", "-v") { DocString = "prints the version that will be installed and is currently installed" }; public static readonly ArgumentFlag ArgWaitFor = new ArgumentFlag("--waitfor", "-w") { DocString = "waits for the specified PID to exit", ValueString = "PID" }; public static readonly ArgumentFlag ArgForce = new ArgumentFlag("--force", "-f") { DocString = "forces the operation to go through" }; public static readonly ArgumentFlag ArgRevert = new ArgumentFlag("--revert", "-r") { DocString = "reverts the IPA installation" }; @@ -39,7 +40,7 @@ namespace IPA [STAThread] public static void Main() { - Arguments.CmdLine.Flags(ArgHelp, ArgWaitFor, ArgForce, ArgRevert, ArgNoWait, ArgStart, ArgLaunch, ArgNoRevert).Process(); + Arguments.CmdLine.Flags(ArgHelp, ArgVersion, ArgWaitFor, ArgForce, ArgRevert, ArgNoWait, ArgStart, ArgLaunch, ArgNoRevert).Process(); if (ArgHelp) { @@ -47,9 +48,14 @@ namespace IPA return; } + if (ArgVersion) + { + Console.WriteLine($"BSIPA Installer version {Version}"); + } + try { - if (ArgWaitFor.HasValue) + if (ArgWaitFor.HasValue && !ArgVersion) { // wait for process if necessary var pid = int.Parse(ArgWaitFor.Value); @@ -77,7 +83,7 @@ namespace IPA // ReSharper enable AccessToModifiedClosure var asmName = new AssemblyName(e.Name); - var testFile = Path.Combine(libsDir, $"{asmName.Name}.{asmName.Version}.dll"); + var testFile = Path.Combine(libsDir, $"{asmName.Name}.dll"); if (File.Exists(testFile)) return Assembly.LoadFile(testFile); @@ -96,6 +102,17 @@ namespace IPA else context = PatchContext.Create(argExeName); + if (ArgVersion) + { + var installed = GetInstalledVersion(context); + if (installed == null) + Console.WriteLine("No currently installed version"); + else + Console.WriteLine($"Installed version: {installed}"); + + return; + } + // Sanitizing Validate(context); @@ -109,6 +126,11 @@ namespace IPA } catch (Exception e) { + if (ArgVersion) + { + Console.WriteLine("No currently installed version"); + return; + } Fail(e.Message); } @@ -136,24 +158,34 @@ namespace IPA } } + private static Version GetInstalledVersion(PatchContext context) + { + // first, check currently installed version, if any + if (File.Exists(Path.Combine(context.ProjectRoot, "winhttp.dll"))) + { // installed, so check version of installed assembly + string injectorPath = Path.Combine(context.ManagedPath, "IPA.Injector.dll"); + if (File.Exists(injectorPath)) + { + var verInfo = FileVersionInfo.GetVersionInfo(injectorPath); + var fileVersion = new Version(verInfo.FileVersion); + + return fileVersion; + } + } + + return null; + } + private static void Install(PatchContext context) { try { bool installFiles = true; - // first, check currently installed version, if any - if (File.Exists(Path.Combine(context.ProjectRoot, "winhttp.dll"))) - { // installed, so check version of installed assembly - string injectorPath = Path.Combine(context.ManagedPath, "IPA.Injector.dll"); - if (File.Exists(injectorPath)) - { - var verInfo = FileVersionInfo.GetVersionInfo(injectorPath); - var fileVersion = new Version(verInfo.FileVersion); - if (fileVersion > Version) - installFiles = false; - } - } + var fileVersion = GetInstalledVersion(context); + + if (fileVersion != null && fileVersion > Version) + installFiles = false; if (installFiles || ArgForce) {