Browse Source

Added some EXE arguments for auto-updating

refactor
Anairkoen Schno 6 years ago
parent
commit
6ea159eb01
3 changed files with 69 additions and 30 deletions
  1. +6
    -5
      IPA/PatchContext.cs
  2. +61
    -23
      IPA/Program.cs
  3. +2
    -2
      IPA/Properties/AssemblyInfo.cs

+ 6
- 5
IPA/PatchContext.cs View File

@ -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");


+ 61
- 23
IPA/Program.cs View File

@ -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()));
}
}
}


+ 2
- 2
IPA/Properties/AssemblyInfo.cs View File

@ -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")]

Loading…
Cancel
Save