diff options
-rw-r--r-- | win/CS/HandBrakeWPF/Controls/SourceSelection.xaml | 35 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs | 63 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs | 18 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Properties/ResourcesUI.resx | 6 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 12 |
5 files changed, 120 insertions, 14 deletions
diff --git a/win/CS/HandBrakeWPF/Controls/SourceSelection.xaml b/win/CS/HandBrakeWPF/Controls/SourceSelection.xaml index 84c8c6ee9..90eec104b 100644 --- a/win/CS/HandBrakeWPF/Controls/SourceSelection.xaml +++ b/win/CS/HandBrakeWPF/Controls/SourceSelection.xaml @@ -1,11 +1,17 @@ <UserControl x:Class="HandBrakeWPF.Controls.SourceSelection"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:cal="http://www.caliburnproject.org"
- xmlns:controls="clr-namespace:HandBrakeWPF.Controls"
- xmlns:Properties="clr-namespace:HandBrakeWPF.Properties" x:Name="sourcePanel"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:cal="http://www.caliburnproject.org"
+ xmlns:controls="clr-namespace:HandBrakeWPF.Controls"
+ xmlns:Properties="clr-namespace:HandBrakeWPF.Properties"
+ xmlns:converters="clr-namespace:HandBrakeWPF.Converters"
+ x:Name="sourcePanel"
>
+ <UserControl.Resources>
+ <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
+ </UserControl.Resources>
+
<Grid Height="{Binding ElementName=sourcePanel, Path=ActualHeight}">
<Grid.ColumnDefinitions>
@@ -19,9 +25,10 @@ <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
- <RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
+ <RowDefinition Height="*" />
+ <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
@@ -91,16 +98,26 @@ </Button>
</DataTemplate>
</ListBox.ItemTemplate>
-
</ListBox>
+ <Button Grid.Row="5" AutomationProperties.Name="{x:Static Properties:ResourcesUI.SourceSelection_QueueArchiveRecovery}" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
+ cal:Message.Attach="[Event Click] = [Action RecoverQueue]" Visibility="{Binding QueueRecoveryArchivesExist, Converter={StaticResource BooleanToVisibilityConverter}}"
+ Margin="20,15,0,0" Padding="8" HorizontalAlignment="Left" BorderBrush="DarkGray" BorderThickness="0,1,0,0">
+ <StackPanel Orientation="Horizontal" MinWidth="100">
+ <Image Source="../Views/Images/Queue.png" Width="32" />
+ <StackPanel Orientation="Vertical">
+ <TextBlock Text="{x:Static Properties:ResourcesUI.SourceSelection_QueueArchiveRecovery}" VerticalAlignment="Center" Margin="5,0,0,0" />
+ <TextBlock Text="{x:Static Properties:ResourcesUI.SourceSelection_QueueArchiveRecoveryDesc}" VerticalAlignment="Center" Margin="5,0,0,0" />
+ </StackPanel>
+ </StackPanel>
+ </Button>
<!-- Cancel Window -->
- <StackPanel Grid.Row="5" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,2,10">
+ <StackPanel Grid.Row="7" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,2,10">
<Button cal:Message.Attach="[Event Click] = [Action CloseSourceSelection]" Content="Cancel" Padding="8,2" />
</StackPanel>
- <StackPanel Grid.Row="7" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,2,10">
+ <StackPanel Grid.Row="8" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,2,10">
<TextBlock>
<Hyperlink x:Name="Preferences" NavigateUri="/" RequestNavigate="OpenOptions_OnRequestNavigate" >Preferences</Hyperlink>
</TextBlock>
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));
}
}
}
diff --git a/win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs b/win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs index 90cc311ab..7478ef537 100644 --- a/win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs @@ -2430,6 +2430,24 @@ namespace HandBrakeWPF.Properties { }
/// <summary>
+ /// Looks up a localized string similar to Queue Recovery.
+ /// </summary>
+ public static string SourceSelection_QueueArchiveRecovery {
+ get {
+ return ResourceManager.GetString("SourceSelection_QueueArchiveRecovery", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to A previous queue archive is available. .
+ /// </summary>
+ public static string SourceSelection_QueueArchiveRecoveryDesc {
+ get {
+ return ResourceManager.GetString("SourceSelection_QueueArchiveRecoveryDesc", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Open a single video file..
/// </summary>
public static string SourceSelection_SingleVideoFile {
diff --git a/win/CS/HandBrakeWPF/Properties/ResourcesUI.resx b/win/CS/HandBrakeWPF/Properties/ResourcesUI.resx index 9a136949b..e8660a2ab 100644 --- a/win/CS/HandBrakeWPF/Properties/ResourcesUI.resx +++ b/win/CS/HandBrakeWPF/Properties/ResourcesUI.resx @@ -1052,4 +1052,10 @@ This will not affect your current settings in the Subtitle tab.</value> <data name="Options_ExperimentalFeatures" xml:space="preserve">
<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>
</data>
+ <data name="SourceSelection_QueueArchiveRecovery" xml:space="preserve">
+ <value>Queue Recovery</value>
+ </data>
+ <data name="SourceSelection_QueueArchiveRecoveryDesc" xml:space="preserve">
+ <value>A previous queue archive is available. </value>
+ </data>
</root>
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 917fadd69..447810846 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -372,6 +372,8 @@ namespace HandBrakeWPF.ViewModels }
}
+ public bool QueueRecoveryArchivesExist { get; set; }
+
/// <summary>
/// Gets or sets Presets.
/// </summary>
@@ -1260,6 +1262,8 @@ namespace HandBrakeWPF.ViewModels // Queue Recovery
bool queueRecovered = QueueRecoveryHelper.RecoverQueue(this.queueProcessor, this.errorService, StartupOptions.AutoRestartQueue, StartupOptions.QueueRecoveryIds);
+ this.QueueRecoveryArchivesExist = QueueRecoveryHelper.ArchivesExist();
+ this.NotifyOfPropertyChange(() => this.QueueRecoveryArchivesExist);
// If the queue is not recovered, show the source selection window by default.
if (!queueRecovered)
@@ -2274,6 +2278,14 @@ namespace HandBrakeWPF.ViewModels }
}
+ public void RecoverQueue()
+ {
+ QueueRecoveryHelper.ResetArchives();
+ bool result = QueueRecoveryHelper.RecoverQueue(this.queueProcessor, this.errorService, StartupOptions.AutoRestartQueue, StartupOptions.QueueRecoveryIds);
+ this.QueueRecoveryArchivesExist = !result && QueueRecoveryHelper.ArchivesExist();
+ this.NotifyOfPropertyChange(() => this.QueueRecoveryArchivesExist);
+ }
+
#endregion
#region Private Methods
|