]> granicus.if.org Git - handbrake/commitdiff
WinGui: Archive Queue Recovery files for 7 days. Add an option on the Source Selectio...
authorsr55 <sr55.hb@outlook.com>
Fri, 21 Sep 2018 22:03:01 +0000 (23:03 +0100)
committersr55 <sr55.hb@outlook.com>
Fri, 21 Sep 2018 22:03:01 +0000 (23:03 +0100)
win/CS/HandBrakeWPF/Controls/SourceSelection.xaml
win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs
win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs
win/CS/HandBrakeWPF/Properties/ResourcesUI.resx
win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs

index 84c8c6ee9b4af3cb7f1b915e516a4190002a0970..90eec104b39b6dd40b3937e6e95e69d0873060fb 100644 (file)
@@ -1,11 +1,17 @@
 <UserControl x:Class="HandBrakeWPF.Controls.SourceSelection"\r
-        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\r
-        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"\r
-        xmlns:cal="http://www.caliburnproject.org"\r
-        xmlns:controls="clr-namespace:HandBrakeWPF.Controls"\r
-        xmlns:Properties="clr-namespace:HandBrakeWPF.Properties" x:Name="sourcePanel"\r
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\r
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"\r
+             xmlns:cal="http://www.caliburnproject.org"\r
+             xmlns:controls="clr-namespace:HandBrakeWPF.Controls"\r
+             xmlns:Properties="clr-namespace:HandBrakeWPF.Properties"\r
+             xmlns:converters="clr-namespace:HandBrakeWPF.Converters"\r
+             x:Name="sourcePanel"\r
        >\r
 \r
+    <UserControl.Resources>\r
+        <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />\r
+    </UserControl.Resources>\r
+\r
     <Grid Height="{Binding ElementName=sourcePanel, Path=ActualHeight}">\r
 \r
         <Grid.ColumnDefinitions>\r
                 <RowDefinition Height="Auto" />\r
                 <RowDefinition Height="Auto" />\r
                 <RowDefinition Height="Auto" />\r
-                <RowDefinition Height="*" />\r
                 <RowDefinition Height="Auto" />\r
                 <RowDefinition Height="Auto" />\r
+                <RowDefinition Height="*" />\r
+                <RowDefinition Height="Auto" />\r
                 <RowDefinition Height="Auto" />\r
             </Grid.RowDefinitions>\r
 \r
                         </Button>\r
                     </DataTemplate>\r
                 </ListBox.ItemTemplate>\r
-\r
             </ListBox>\r
 \r
+            <Button Grid.Row="5"  AutomationProperties.Name="{x:Static Properties:ResourcesUI.SourceSelection_QueueArchiveRecovery}" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" \r
+                    cal:Message.Attach="[Event Click] = [Action RecoverQueue]" Visibility="{Binding QueueRecoveryArchivesExist, Converter={StaticResource BooleanToVisibilityConverter}}"\r
+                    Margin="20,15,0,0" Padding="8" HorizontalAlignment="Left" BorderBrush="DarkGray" BorderThickness="0,1,0,0">\r
+                <StackPanel Orientation="Horizontal" MinWidth="100">\r
+                    <Image Source="../Views/Images/Queue.png" Width="32" />\r
+                    <StackPanel Orientation="Vertical">\r
+                        <TextBlock Text="{x:Static Properties:ResourcesUI.SourceSelection_QueueArchiveRecovery}" VerticalAlignment="Center" Margin="5,0,0,0" />\r
+                        <TextBlock Text="{x:Static Properties:ResourcesUI.SourceSelection_QueueArchiveRecoveryDesc}" VerticalAlignment="Center" Margin="5,0,0,0" />\r
+                    </StackPanel>\r
+                </StackPanel>\r
+            </Button>\r
 \r
             <!-- Cancel Window -->\r
-            <StackPanel Grid.Row="5" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,2,10">\r
+            <StackPanel Grid.Row="7" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,2,10">\r
                 <Button cal:Message.Attach="[Event Click] = [Action CloseSourceSelection]" Content="Cancel" Padding="8,2" />\r
             </StackPanel>\r
 \r
-            <StackPanel Grid.Row="7" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,2,10">\r
+            <StackPanel Grid.Row="8" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,2,10">\r
                 <TextBlock>           \r
                     <Hyperlink x:Name="Preferences" NavigateUri="/"  RequestNavigate="OpenOptions_OnRequestNavigate" >Preferences</Hyperlink>\r
                 </TextBlock>\r
index cb17e2e41e7a5c169910813bef743b9a1d50b39e..2a73188149a8c17563c29df06ee8ca7aced25ef7 100644 (file)
@@ -92,7 +92,7 @@ namespace HandBrakeWPF.Helpers
                     }\r
                 }\r
 \r
-                CleanupFiles(removeFiles);\r
+                CleanupFiles(removeFiles, false);\r
 \r
                 return acceptedFiles;\r
             }\r
@@ -159,16 +159,25 @@ namespace HandBrakeWPF.Helpers
                     isRecovered = true;\r
 \r
                     // Cleanup\r
-                    CleanupFiles(new List<string> { file });                   \r
+                    CleanupFiles(new List<string> { file }, false);                   \r
                 }\r
 \r
                 return isRecovered;\r
             }\r
 \r
-            CleanupFiles(queueFiles);\r
+            CleanupFiles(queueFiles, true);\r
             return false;\r
         }\r
 \r
+        public static bool ArchivesExist()\r
+        {\r
+            string appDataPath = DirectoryUtilities.GetUserStoragePath(VersionHelper.IsNightly());\r
+            DirectoryInfo info = new DirectoryInfo(appDataPath);\r
+            IEnumerable<FileInfo> foundFiles = info.GetFiles("*.archive").Where(f => f.Name.StartsWith("hb_queue_recovery"));\r
+\r
+            return foundFiles.Any();\r
+        }\r
+\r
         private static List<string> GetFilesExcludingActiveProcesses(IEnumerable<FileInfo> foundFiles, List<string> filterQueueFiles)\r
         {\r
             List<string> queueFiles = new List<string>();\r
@@ -200,7 +209,7 @@ namespace HandBrakeWPF.Helpers
             return queueFiles;\r
         }\r
 \r
-        private static void CleanupFiles(List<string> removeFiles)\r
+        private static void CleanupFiles(List<string> removeFiles, bool archive)\r
         {\r
             string appDataPath = DirectoryUtilities.GetUserStoragePath(VersionHelper.IsNightly());\r
 \r
@@ -218,7 +227,51 @@ namespace HandBrakeWPF.Helpers
                 }\r
 \r
                 string fullPath = Path.Combine(appDataPath, file);\r
-                File.Delete(fullPath);\r
+\r
+                if (archive)\r
+                {\r
+                    File.Move(fullPath, fullPath + ".archive");\r
+                }\r
+                else\r
+                {\r
+                    File.Delete(fullPath);\r
+                }      \r
+            }\r
+\r
+            TidyArchiveFiles();\r
+        }\r
+\r
+        /// <summary>\r
+        /// Tidy up archive files older than 7 days.\r
+        /// Gives the user an opportunity to recover a queue file they accidentally chose not to import. \r
+        /// </summary>\r
+        private static void TidyArchiveFiles()\r
+        {\r
+            string appDataPath = DirectoryUtilities.GetUserStoragePath(VersionHelper.IsNightly());\r
+            DirectoryInfo info = new DirectoryInfo(appDataPath);\r
+            IEnumerable<FileInfo> foundFiles = info.GetFiles("*.archive").Where(f => f.Name.StartsWith("hb_queue_recovery"));\r
+\r
+            DateTime LastWeek = DateTime.Now.AddDays(-7);\r
+\r
+            foreach (FileInfo file in foundFiles)\r
+            {\r
+                if (file.CreationTime < LastWeek)\r
+                {\r
+                    string fullPath = Path.Combine(appDataPath, file.Name);\r
+                    File.Delete(fullPath);\r
+                }\r
+            }\r
+        }\r
+\r
+        public static void ResetArchives()\r
+        {\r
+            string appDataPath = DirectoryUtilities.GetUserStoragePath(VersionHelper.IsNightly());\r
+            DirectoryInfo info = new DirectoryInfo(appDataPath);\r
+            IEnumerable<FileInfo> foundFiles = info.GetFiles("*.archive").Where(f => f.Name.StartsWith("hb_queue_recovery"));\r
+            foreach (FileInfo file in foundFiles)\r
+            {\r
+                string fullPath = Path.Combine(appDataPath, file.Name);\r
+                File.Move(fullPath, fullPath.Replace(".archive", string.Empty));\r
             }\r
         }\r
     }\r
index 90cc311ab18e0df819412b728331216552f40991..7478ef537f5bc57f62c130ecfdb2f6726f0962e6 100644 (file)
@@ -2429,6 +2429,24 @@ namespace HandBrakeWPF.Properties {
             }\r
         }\r
         \r
+        /// <summary>\r
+        ///   Looks up a localized string similar to Queue Recovery.\r
+        /// </summary>\r
+        public static string SourceSelection_QueueArchiveRecovery {\r
+            get {\r
+                return ResourceManager.GetString("SourceSelection_QueueArchiveRecovery", resourceCulture);\r
+            }\r
+        }\r
+        \r
+        /// <summary>\r
+        ///   Looks up a localized string similar to A previous queue archive is available. .\r
+        /// </summary>\r
+        public static string SourceSelection_QueueArchiveRecoveryDesc {\r
+            get {\r
+                return ResourceManager.GetString("SourceSelection_QueueArchiveRecoveryDesc", resourceCulture);\r
+            }\r
+        }\r
+        \r
         /// <summary>\r
         ///   Looks up a localized string similar to Open a single video file..\r
         /// </summary>\r
index 9a136949b0bb1ee40de7d9fd306df66836208ef2..e8660a2abc36563aadaa828d5171b9fc996ac336 100644 (file)
@@ -1052,4 +1052,10 @@ This will not affect your current settings in the Subtitle tab.</value>
   <data name="Options_ExperimentalFeatures" xml:space="preserve">\r
     <value>Experimental features are ideas we are working on. These may or may not make it into a final release and may not work!</value>\r
   </data>\r
+  <data name="SourceSelection_QueueArchiveRecovery" xml:space="preserve">\r
+    <value>Queue Recovery</value>\r
+  </data>\r
+  <data name="SourceSelection_QueueArchiveRecoveryDesc" xml:space="preserve">\r
+    <value>A previous queue archive is available. </value>\r
+  </data>\r
 </root>
\ No newline at end of file
index 917fadd69a06239dfbd796ac9d0aee7fb8ed7a90..447810846dab16c04543441efcf16b9067995c87 100644 (file)
@@ -372,6 +372,8 @@ namespace HandBrakeWPF.ViewModels
             }\r
         }\r
 \r
+        public bool QueueRecoveryArchivesExist { get; set; }\r
+\r
         /// <summary>\r
         /// Gets or sets Presets.\r
         /// </summary>\r
@@ -1260,6 +1262,8 @@ namespace HandBrakeWPF.ViewModels
 \r
             // Queue Recovery\r
             bool queueRecovered = QueueRecoveryHelper.RecoverQueue(this.queueProcessor, this.errorService, StartupOptions.AutoRestartQueue, StartupOptions.QueueRecoveryIds);\r
+            this.QueueRecoveryArchivesExist = QueueRecoveryHelper.ArchivesExist();\r
+            this.NotifyOfPropertyChange(() => this.QueueRecoveryArchivesExist);\r
 \r
             // If the queue is not recovered, show the source selection window by default.\r
             if (!queueRecovered)\r
@@ -2274,6 +2278,14 @@ namespace HandBrakeWPF.ViewModels
             }\r
         }\r
 \r
+        public void RecoverQueue()\r
+        {\r
+            QueueRecoveryHelper.ResetArchives();\r
+            bool result = QueueRecoveryHelper.RecoverQueue(this.queueProcessor, this.errorService, StartupOptions.AutoRestartQueue, StartupOptions.QueueRecoveryIds);\r
+            this.QueueRecoveryArchivesExist = !result && QueueRecoveryHelper.ArchivesExist();\r
+            this.NotifyOfPropertyChange(() => this.QueueRecoveryArchivesExist);\r
+        }\r
+\r
         #endregion\r
 \r
         #region Private Methods\r