CLIPA/IPA/Patcher/BackupManager.cs

40 lines
1,001 B
C#
Raw Normal View History

2016-12-15 20:07:03 +00:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
2017-01-20 19:29:51 +00:00
using System.Text.RegularExpressions;
2016-12-15 20:07:03 +00:00
namespace IPA.Patcher
{
public class BackupManager
{
2017-02-21 23:34:07 +00:00
public static BackupUnit FindLatestBackup(PatchContext context)
2016-12-15 20:07:03 +00:00
{
2017-02-21 23:34:07 +00:00
return new DirectoryInfo(context.BackupPath)
.GetDirectories()
.OrderByDescending(p => p.Name)
.Select(p => BackupUnit.FromDirectory(p, context))
.FirstOrDefault();
2016-12-15 20:07:03 +00:00
}
2017-02-21 23:34:07 +00:00
public static bool HasBackup(PatchContext context)
2017-01-20 19:29:51 +00:00
{
2017-02-21 23:34:07 +00:00
return FindLatestBackup(context) != null;
2017-01-20 19:29:51 +00:00
}
2017-02-21 23:34:07 +00:00
public static bool Restore(PatchContext context)
2017-01-20 19:29:51 +00:00
{
2017-02-21 23:34:07 +00:00
var backup = FindLatestBackup(context);
2017-01-20 19:29:51 +00:00
if(backup != null)
{
2017-02-21 23:34:07 +00:00
backup.Restore();
backup.Delete();
2017-01-20 19:29:51 +00:00
return true;
}
return false;
}
2016-12-15 20:07:03 +00:00
}
}