CLIPA/IPA/PatchContext.cs

77 lines
3.2 KiB
C#
Raw Normal View History

2017-01-20 19:29:51 +00:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
2017-02-17 17:33:07 +00:00
using System.Reflection;
2017-01-20 19:29:51 +00:00
using System.Text;
namespace IPA
{
public class PatchContext
{
/// <summary>
/// Gets the filename of the executable.
/// </summary>
public string Executable { get; private set; }
/// <summary>
/// Gets the path to the launcher executable (in the IPA folder)
/// </summary>
public string LauncherPathSrc { get; private set; }
public string DataPathSrc { get; private set; }
public string PluginsFolder { get; private set; }
public string ProjectName { get; private set; }
public string DataPathDst { get; private set; }
public string ManagedPath { get; private set; }
public string EngineFile { get; private set; }
public string AssemblyFile { get; private set; }
public string[] Args { get; private set; }
public string ProjectRoot { get; private set; }
public string IPARoot { get; private set; }
public string ShortcutPath { get; private set; }
2017-02-17 17:33:07 +00:00
public string IPA { get; private set; }
2017-02-21 23:34:07 +00:00
public string BackupPath { get; private set; }
2017-01-20 19:29:51 +00:00
private PatchContext() { }
public static PatchContext Create(String[] args)
{
var context = new PatchContext();
context.Args = args;
context.Executable = args[0];
2017-02-21 23:34:07 +00:00
context.ProjectRoot = new FileInfo(context.Executable).Directory.FullName;
2017-01-20 19:29:51 +00:00
context.IPARoot = Path.Combine(context.ProjectRoot, "IPA");
2017-02-17 17:33:07 +00:00
context.IPA = Assembly.GetExecutingAssembly().Location ?? Path.Combine(context.ProjectRoot, "IPA.exe");
2017-01-20 19:29:51 +00:00
context.LauncherPathSrc = Path.Combine(context.IPARoot, "Launcher.exe");
context.DataPathSrc = Path.Combine(context.IPARoot, "Data");
context.PluginsFolder = Path.Combine(context.ProjectRoot, "Plugins");
context.ProjectName = Path.GetFileNameWithoutExtension(context.Executable);
context.DataPathDst = Path.Combine(context.ProjectRoot, context.ProjectName + "_Data");
context.ManagedPath = Path.Combine(context.DataPathDst, "Managed");
2018-10-08 20:00:38 +01:00
context.EngineFile = DetermineEngineFile(context.ManagedPath, "UnityEngine.dll", "UnityEngine.CoreModule.dll");
2017-01-20 19:29:51 +00:00
context.AssemblyFile = Path.Combine(context.ManagedPath, "Assembly-Csharp.dll");
2017-02-21 23:34:07 +00:00
context.BackupPath = Path.Combine(Path.Combine(context.IPARoot, "Backups"), context.ProjectName);
2018-10-08 20:01:48 +01:00
context.ShortcutPath = Path.Combine(context.ProjectRoot, $"{context.ProjectName} (Patch & Launch)") + ".lnk";
2017-01-20 19:29:51 +00:00
2017-02-21 23:34:07 +00:00
Directory.CreateDirectory(context.BackupPath);
2017-01-20 19:29:51 +00:00
return context;
}
2018-10-08 20:00:38 +01:00
private static string DetermineEngineFile(string basePath, params string[] candidates)
{
foreach(var candidate in candidates)
{
var fullPath = Path.Combine(basePath, candidate);
if(File.Exists(fullPath))
{
return fullPath;
}
}
throw new FileNotFoundException("Could not find engine DLL!");
}
2017-01-20 19:29:51 +00:00
}
}