You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.7 KiB

  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. public string DataPathSrc { get; private set; }
  13. public string LibsPathSrc { get; private set; }
  14. public string PluginsFolder { get; private set; }
  15. public string ProjectName { get; private set; }
  16. public string DataPathDst { get; private set; }
  17. public string LibsPathDst { get; private set; }
  18. public string ManagedPath { get; private set; }
  19. public string EngineFile { get; private set; }
  20. public string AssemblyFile { get; private set; }
  21. public string ProjectRoot { get; private set; }
  22. public string IPARoot { get; private set; }
  23. public string ShortcutPath { get; private set; }
  24. public string IPA { get; private set; }
  25. public string BackupPath { get; private set; }
  26. private PatchContext() { }
  27. public static PatchContext Create(string exe)
  28. {
  29. var context = new PatchContext
  30. {
  31. Executable = exe
  32. };
  33. context.ProjectRoot = new FileInfo(context.Executable).Directory?.FullName;
  34. context.IPARoot = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) ?? throw new InvalidOperationException(), "IPA");
  35. context.IPA = Assembly.GetExecutingAssembly().Location;
  36. context.DataPathSrc = Path.Combine(context.IPARoot, "Data");
  37. context.LibsPathSrc = Path.Combine(context.IPARoot, "Libs");
  38. context.PluginsFolder = Path.Combine(context.ProjectRoot ?? throw new InvalidOperationException(), "Plugins");
  39. context.ProjectName = Path.GetFileNameWithoutExtension(context.Executable);
  40. context.DataPathDst = Path.Combine(context.ProjectRoot, context.ProjectName + "_Data");
  41. context.LibsPathDst = Path.Combine(context.ProjectRoot, "Libs");
  42. context.ManagedPath = Path.Combine(context.DataPathDst, "Managed");
  43. context.EngineFile = Path.Combine(context.ManagedPath, "UnityEngine.CoreModule.dll");
  44. context.AssemblyFile = Path.Combine(context.ManagedPath, "Assembly-CSharp.dll");
  45. context.BackupPath = Path.Combine(context.IPARoot, "Backups", context.ProjectName);
  46. string shortcutName = $"{context.ProjectName} (Patch & Launch)";
  47. context.ShortcutPath = Path.Combine(context.ProjectRoot, shortcutName) + ".lnk";
  48. Directory.CreateDirectory(context.BackupPath);
  49. return context;
  50. }
  51. }
  52. }