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.

65 lines
2.1 KiB

  1. using IPA.Utilities;
  2. using System;
  3. using System.IO;
  4. using static IPA.Logging.Logger;
  5. namespace IPA.Injector
  6. {
  7. internal static class Updates
  8. {
  9. private const string DeleteFileName = Updating.ModSaber.Updater.SpecialDeletionsFile;
  10. public static void InstallPendingUpdates()
  11. {
  12. var pendingDir = Path.Combine(BeatSaber.InstallPath, "IPA", "Pending");
  13. if (!Directory.Exists(pendingDir)) return;
  14. // there are pending updates, install
  15. updater.Info("Installing pending updates");
  16. var toDelete = new string[0];
  17. var delFn = Path.Combine(pendingDir, DeleteFileName);
  18. if (File.Exists(delFn))
  19. {
  20. toDelete = File.ReadAllLines(delFn);
  21. File.Delete(delFn);
  22. }
  23. foreach (var file in toDelete)
  24. {
  25. try
  26. {
  27. File.Delete(Path.Combine(BeatSaber.InstallPath, file));
  28. }
  29. catch (Exception e)
  30. {
  31. updater.Error("While trying to install pending updates: Error deleting file marked for deletion");
  32. updater.Error(e);
  33. }
  34. }
  35. #region Self Protection
  36. if (Directory.Exists(Path.Combine(pendingDir, "IPA")))
  37. Directory.Delete(Path.Combine(pendingDir, "IPA"), true);
  38. if (File.Exists(Path.Combine(pendingDir, "IPA.exe")))
  39. {
  40. File.Delete(Path.Combine(pendingDir, "IPA.exe"));
  41. if (File.Exists(Path.Combine(pendingDir, "Mono.Cecil.dll")))
  42. File.Delete(Path.Combine(pendingDir, "Mono.Cecil.dll"));
  43. }
  44. #endregion
  45. try
  46. {
  47. LoneFunctions.CopyAll(new DirectoryInfo(pendingDir), new DirectoryInfo(BeatSaber.InstallPath));
  48. }
  49. catch (Exception e)
  50. {
  51. updater.Error("While trying to install pending updates: Error copying files in");
  52. updater.Error(e);
  53. }
  54. Directory.Delete(pendingDir, true);
  55. }
  56. }
  57. }