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.

36 lines
889B

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