From f6b195912327e4b1c483e815c9b9944577103386 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Wed, 1 Aug 2018 22:32:31 -0500 Subject: [PATCH] Added some EXE arguments for auto-updating --- IPA/PatchContext.cs | 11 +++-- IPA/Program.cs | 84 ++++++++++++++++++++++++---------- IPA/Properties/AssemblyInfo.cs | 4 +- 3 files changed, 69 insertions(+), 30 deletions(-) diff --git a/IPA/PatchContext.cs b/IPA/PatchContext.cs index d058ba0a..29f2508c 100644 --- a/IPA/PatchContext.cs +++ b/IPA/PatchContext.cs @@ -30,12 +30,13 @@ namespace IPA private PatchContext() { } - public static PatchContext Create(String[] args) + public static PatchContext Create(String[] args, string exe) { - var context = new PatchContext(); - - context.Args = args; - context.Executable = args[0]; + var context = new PatchContext + { + Args = args, + Executable = exe + }; context.ProjectRoot = new FileInfo(context.Executable).Directory.FullName; context.IPARoot = Path.Combine(context.ProjectRoot, "IPA"); context.IPA = Assembly.GetExecutingAssembly().Location ?? Path.Combine(context.ProjectRoot, "IPA.exe"); diff --git a/IPA/Program.cs b/IPA/Program.cs index 88dbd293..a4614ac9 100644 --- a/IPA/Program.cs +++ b/IPA/Program.cs @@ -20,30 +20,56 @@ namespace IPA { private static Version Version => new Version(Application.ProductVersion); - static void Main(string[] args) { - PatchContext context; - - if (args.Length < 1 || !args[0].EndsWith(".exe")) { - //Fail("Drag an (executable) file on the exe!"); - context = PatchContext.Create(new[] { - new DirectoryInfo(Directory.GetCurrentDirectory()).GetFiles() - .First(o => o.FullName.EndsWith(".exe")) - .FullName - }); - } - else { - context = PatchContext.Create(args); - } + static void Main(string[] args) + { + var ArgList = args.ToList(); + + try + { + string arg = args.FirstOrDefault(s => s.StartsWith("--waitfor=")); + if (arg != null) + { + ArgList.Remove(arg); + int pid = int.Parse(arg.Split('=').Last()); - try { - bool isRevert = args.Contains("--revert") || Keyboard.IsKeyDown(Keys.LMenu); + try + { // wait for beat saber to exit (ensures we can modify the file) + var parent = Process.GetProcessById(pid); + + Console.WriteLine($"Waiting for parent ({pid}) process to die..."); + + parent.WaitForExit(); + } + catch (Exception) { } + } + + PatchContext context; + + var argExeName = ArgList.FirstOrDefault(s => s.EndsWith(".exe")); + + if (argExeName == null) + { + //Fail("Drag an (executable) file on the exe!"); + context = PatchContext.Create(ArgList.ToArray(), + new DirectoryInfo(Directory.GetCurrentDirectory()).GetFiles() + .First(o => o.FullName.EndsWith(".exe")) + .FullName); + } + else + { + context = PatchContext.Create(ArgList.ToArray(), argExeName); + } + + bool isRevert = ArgList.Contains("--revert") || Keyboard.IsKeyDown(Keys.LMenu); // Sanitizing Validate(context); - if (isRevert) { + if (isRevert) + { Revert(context); } - else { + else + { Install(context); StartIfNeedBe(context); } @@ -213,13 +239,25 @@ namespace IPA { } private static void StartIfNeedBe(PatchContext context) { - var argList = context.Args.ToList(); - bool launch = argList.Remove("--launch"); + string startArg = context.Args.FirstOrDefault(s => s.StartsWith("--start=")); + if (startArg != null) + { + var cmdlineSplit = startArg.Split('=').ToList(); + cmdlineSplit.RemoveAt(0); // remove first + var cmdline = string.Join("=", cmdlineSplit); + Process.Start(context.Executable, cmdline); + } + else + { + var argList = context.Args.ToList(); + bool launch = argList.Remove("--launch"); - argList.RemoveAt(0); + argList.Remove(context.Executable); - if (launch) { - Process.Start(context.Executable, Args(argList.ToArray())); + if (launch) + { + Process.Start(context.Executable, Args(argList.ToArray())); + } } } diff --git a/IPA/Properties/AssemblyInfo.cs b/IPA/Properties/AssemblyInfo.cs index 9aecbdde..b5681a34 100644 --- a/IPA/Properties/AssemblyInfo.cs +++ b/IPA/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.7.2")] -[assembly: AssemblyFileVersion("3.7.2")] +[assembly: AssemblyVersion("3.7.3")] +[assembly: AssemblyFileVersion("3.7.3")]