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.

57 lines
1.8 KiB

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