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.

59 lines
2.5 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. namespace IPA
  8. {
  9. public class PatchContext
  10. {
  11. /// <summary>
  12. /// Gets the filename of the executable.
  13. /// </summary>
  14. public string Executable { get; private set; }
  15. public string DataPathSrc { get; private set; }
  16. public string PluginsFolder { get; private set; }
  17. public string ProjectName { get; private set; }
  18. public string DataPathDst { get; private set; }
  19. public string ManagedPath { get; private set; }
  20. public string EngineFile { get; private set; }
  21. public string AssemblyFile { get; private set; }
  22. public string[] Args { get; private set; }
  23. public string ProjectRoot { get; private set; }
  24. public string IPARoot { get; private set; }
  25. public string ShortcutPath { get; private set; }
  26. public string IPA { get; private set; }
  27. public string BackupPath { get; private set; }
  28. private PatchContext() { }
  29. public static PatchContext Create(String[] args, string exe)
  30. {
  31. var context = new PatchContext
  32. {
  33. Args = args,
  34. Executable = exe
  35. };
  36. context.ProjectRoot = new FileInfo(context.Executable).Directory.FullName;
  37. context.IPARoot = Path.Combine(context.ProjectRoot, "IPA");
  38. context.IPA = Assembly.GetExecutingAssembly().Location ?? Path.Combine(context.ProjectRoot, "IPA.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 = Path.Combine(context.ManagedPath, "UnityEngine.CoreModule.dll");
  45. context.AssemblyFile = Path.Combine(context.ManagedPath, "Assembly-CSharp.dll");
  46. context.BackupPath = Path.Combine(Path.Combine(context.IPARoot, "Backups"), context.ProjectName);
  47. string shortcutName = $"{context.ProjectName} (Patch & Launch)";
  48. context.ShortcutPath = Path.Combine(context.ProjectRoot, shortcutName) + ".lnk";
  49. Directory.CreateDirectory(context.BackupPath);
  50. return context;
  51. }
  52. }
  53. }