A fork of Eusth's IPA
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.

40 lines
1001B

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. namespace IPA.Patcher
  8. {
  9. public class BackupManager
  10. {
  11. public static BackupUnit FindLatestBackup(PatchContext context)
  12. {
  13. return new DirectoryInfo(context.BackupPath)
  14. .GetDirectories()
  15. .OrderByDescending(p => p.Name)
  16. .Select(p => BackupUnit.FromDirectory(p, context))
  17. .FirstOrDefault();
  18. }
  19. public static bool HasBackup(PatchContext context)
  20. {
  21. return FindLatestBackup(context) != null;
  22. }
  23. public static bool Restore(PatchContext context)
  24. {
  25. var backup = FindLatestBackup(context);
  26. if(backup != null)
  27. {
  28. backup.Restore();
  29. backup.Delete();
  30. return true;
  31. }
  32. return false;
  33. }
  34. }
  35. }