<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
}\r
}\r
\r
- CleanupFiles(removeFiles);\r
+ CleanupFiles(removeFiles, false);\r
\r
return acceptedFiles;\r
}\r
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
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
}\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
}\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
<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
}\r
}\r
\r
+ public bool QueueRecoveryArchivesExist { get; set; }\r
+\r
/// <summary>\r
/// Gets or sets Presets.\r
/// </summary>\r
\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
}\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