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.

53 lines
1.8 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))
  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. try
  36. {
  37. LoneFunctions.CopyAll(new DirectoryInfo(pendingDir), new DirectoryInfo(BeatSaber.InstallPath));
  38. }
  39. catch (Exception e)
  40. {
  41. updater.Error("While trying to install pending updates: Error copying files in");
  42. updater.Error(e);
  43. }
  44. Directory.Delete(pendingDir, true);
  45. }
  46. }
  47. }
  48. }