diff options
author | sr55 <[email protected]> | 2018-09-21 23:03:01 +0100 |
---|---|---|
committer | sr55 <[email protected]> | 2018-09-21 23:03:01 +0100 |
commit | ebc64438a1c1621f9aef1d38f166419ed5b6e92c (patch) | |
tree | dfe3f327bf1c0d0651533a9097f2659e9b551ee5 /win/CS/HandBrakeWPF/Helpers | |
parent | 7310e70af440d38fa8979ddf301e0690a117b036 (diff) |
WinGui: Archive Queue Recovery files for 7 days. Add an option on the Source Selection Panel to recover archived queue files. Option will disappear automatically after 7 days.
Diffstat (limited to 'win/CS/HandBrakeWPF/Helpers')
-rw-r--r-- | win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs | 63 |
1 files changed, 58 insertions, 5 deletions
diff --git a/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs b/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs index cb17e2e41..2a7318814 100644 --- a/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs +++ b/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs @@ -92,7 +92,7 @@ namespace HandBrakeWPF.Helpers }
}
- CleanupFiles(removeFiles);
+ CleanupFiles(removeFiles, false);
return acceptedFiles;
}
@@ -159,16 +159,25 @@ namespace HandBrakeWPF.Helpers isRecovered = true;
// Cleanup
- CleanupFiles(new List<string> { file });
+ CleanupFiles(new List<string> { file }, false);
}
return isRecovered;
}
- CleanupFiles(queueFiles);
+ CleanupFiles(queueFiles, true);
return false;
}
+ public static bool ArchivesExist()
+ {
+ string appDataPath = DirectoryUtilities.GetUserStoragePath(VersionHelper.IsNightly());
+ DirectoryInfo info = new DirectoryInfo(appDataPath);
+ IEnumerable<FileInfo> foundFiles = info.GetFiles("*.archive").Where(f => f.Name.StartsWith("hb_queue_recovery"));
+
+ return foundFiles.Any();
+ }
+
private static List<string> GetFilesExcludingActiveProcesses(IEnumerable<FileInfo> foundFiles, List<string> filterQueueFiles)
{
List<string> queueFiles = new List<string>();
@@ -200,7 +209,7 @@ namespace HandBrakeWPF.Helpers return queueFiles;
}
- private static void CleanupFiles(List<string> removeFiles)
+ private static void CleanupFiles(List<string> removeFiles, bool archive)
{
string appDataPath = DirectoryUtilities.GetUserStoragePath(VersionHelper.IsNightly());
@@ -218,7 +227,51 @@ namespace HandBrakeWPF.Helpers }
string fullPath = Path.Combine(appDataPath, file);
- File.Delete(fullPath);
+
+ if (archive)
+ {
+ File.Move(fullPath, fullPath + ".archive");
+ }
+ else
+ {
+ File.Delete(fullPath);
+ }
+ }
+
+ TidyArchiveFiles();
+ }
+
+ /// <summary>
+ /// Tidy up archive files older than 7 days.
+ /// Gives the user an opportunity to recover a queue file they accidentally chose not to import.
+ /// </summary>
+ private static void TidyArchiveFiles()
+ {
+ string appDataPath = DirectoryUtilities.GetUserStoragePath(VersionHelper.IsNightly());
+ DirectoryInfo info = new DirectoryInfo(appDataPath);
+ IEnumerable<FileInfo> foundFiles = info.GetFiles("*.archive").Where(f => f.Name.StartsWith("hb_queue_recovery"));
+
+ DateTime LastWeek = DateTime.Now.AddDays(-7);
+
+ foreach (FileInfo file in foundFiles)
+ {
+ if (file.CreationTime < LastWeek)
+ {
+ string fullPath = Path.Combine(appDataPath, file.Name);
+ File.Delete(fullPath);
+ }
+ }
+ }
+
+ public static void ResetArchives()
+ {
+ string appDataPath = DirectoryUtilities.GetUserStoragePath(VersionHelper.IsNightly());
+ DirectoryInfo info = new DirectoryInfo(appDataPath);
+ IEnumerable<FileInfo> foundFiles = info.GetFiles("*.archive").Where(f => f.Name.StartsWith("hb_queue_recovery"));
+ foreach (FileInfo file in foundFiles)
+ {
+ string fullPath = Path.Combine(appDataPath, file.Name);
+ File.Move(fullPath, fullPath.Replace(".archive", string.Empty));
}
}
}
|