A fork of Eusth's IPA
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

74 行
3.1KB

  1. using System;
  2. using System.IO;
  3. using System.Reflection;
  4. namespace IPA
  5. {
  6. public class PatchContext
  7. {
  8. /// <summary>
  9. /// Gets the filename of the executable.
  10. /// </summary>
  11. public string Executable { get; private set; }
  12. /// <summary>
  13. /// Gets the path to the launcher executable (in the IPA folder)
  14. /// </summary>
  15. public string LauncherPathSrc { get; private set; }
  16. public string DataPathSrc { get; private set; }
  17. public string PluginsFolder { get; private set; }
  18. public string ProjectName { get; private set; }
  19. public string DataPathDst { get; private set; }
  20. public string ManagedPath { get; private set; }
  21. public string EngineFile { get; private set; }
  22. public string AssemblyFile { get; private set; }
  23. public string[] Args { get; private set; }
  24. public string ProjectRoot { get; private set; }
  25. public string IPARoot { get; private set; }
  26. public string ShortcutPath { get; private set; }
  27. public string IPA { get; private set; }
  28. public string BackupPath { get; private set; }
  29. private PatchContext() { }
  30. public static PatchContext Create(String[] args)
  31. {
  32. var context = new PatchContext();
  33. context.Args = args;
  34. context.Executable = args[0];
  35. context.ProjectRoot = new FileInfo(context.Executable).Directory.FullName;
  36. context.IPARoot = Path.Combine(context.ProjectRoot, "IPA");
  37. context.IPA = Assembly.GetExecutingAssembly().Location ?? Path.Combine(context.ProjectRoot, "IPA.exe");
  38. context.LauncherPathSrc = Path.Combine(context.IPARoot, "Launcher.exe");
  39. context.DataPathSrc = Path.Combine(context.IPARoot, "Data");
  40. context.PluginsFolder = Path.Combine(context.ProjectRoot, "Plugins");
  41. context.ProjectName = Path.GetFileNameWithoutExtension(context.Executable);
  42. context.DataPathDst = Path.Combine(context.ProjectRoot, context.ProjectName + "_Data");
  43. context.ManagedPath = Path.Combine(context.DataPathDst, "Managed");
  44. context.EngineFile = DetermineEngineFile(context.ManagedPath, "UnityEngine.CoreModule.dll", "UnityEngine.dll");
  45. context.AssemblyFile = Path.Combine(context.ManagedPath, "Assembly-Csharp.dll");
  46. context.BackupPath = Path.Combine(Path.Combine(context.IPARoot, "Backups"), context.ProjectName);
  47. context.ShortcutPath = Path.Combine(context.ProjectRoot, $"{context.ProjectName} (Patch & Launch)") + ".lnk";
  48. Directory.CreateDirectory(context.BackupPath);
  49. return context;
  50. }
  51. private static string DetermineEngineFile(string basePath, params string[] candidates)
  52. {
  53. foreach (var candidate in candidates)
  54. {
  55. var fullPath = Path.Combine(basePath, candidate);
  56. if (File.Exists(fullPath))
  57. {
  58. return fullPath;
  59. }
  60. }
  61. throw new FileNotFoundException("Could not find engine DLL!");
  62. }
  63. }
  64. }