diff options
author | sr55 <[email protected]> | 2012-02-18 22:09:26 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2012-02-18 22:09:26 +0000 |
commit | 68395c181bbf629c33607829aa971cf12c19c29d (patch) | |
tree | 6fae1b33a36a3a16ac70ce11b33de868fd152597 /win/CS/HandBrakeWPF/Helpers | |
parent | be861eb1e625b3e903d76bf60cdfb4bae8f8b1df (diff) |
WinGui: (WPF) General work hooking up various aspects of the new WPF UI, bug fixes and improvements.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4456 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrakeWPF/Helpers')
-rw-r--r-- | win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs | 133 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Helpers/UpdateCheckHelper.cs | 60 |
2 files changed, 193 insertions, 0 deletions
diff --git a/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs b/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs new file mode 100644 index 000000000..32e999e7b --- /dev/null +++ b/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs @@ -0,0 +1,133 @@ +// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="QueueRecoveryHelper.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Defines the QueueRecoveryHelper type.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Helpers
+{
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Linq;
+ using System.Windows;
+ using System.Xml.Serialization;
+
+ using HandBrake.ApplicationServices.Model;
+ using HandBrake.ApplicationServices.Services.Interfaces;
+ using HandBrake.ApplicationServices.Utilities;
+
+ using HandBrakeWPF.Services.Interfaces;
+
+ /// <summary>
+ /// Queue Recovery Helper
+ /// </summary>
+ public class QueueRecoveryHelper
+ {
+ /// <summary>
+ /// Check if the queue recovery file contains records.
+ /// If it does, it means the last queue did not complete before HandBrake closed.
+ /// So, return a boolean if true.
+ /// </summary>
+ /// <returns>
+ /// True if there is a queue to recover.
+ /// </returns>
+ public static List<string> CheckQueueRecovery()
+ {
+ try
+ {
+ XmlSerializer Ser = new XmlSerializer(typeof(List<QueueTask>));
+ string tempPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\");
+ List<string> queueFiles = new List<string>();
+ List<string> removeFiles = new List<string>();
+
+ DirectoryInfo info = new DirectoryInfo(tempPath);
+ IEnumerable<FileInfo> logFiles = info.GetFiles("*.xml").Where(f => f.Name.StartsWith("hb_queue_recovery"));
+ foreach (FileInfo file in logFiles)
+ {
+ using (FileStream strm = new FileStream(file.FullName, FileMode.Open, FileAccess.Read))
+ {
+ List<QueueTask> list = Ser.Deserialize(strm) as List<QueueTask>;
+ if (list != null && list.Count == 0)
+ {
+ removeFiles.Add(file.FullName);
+ }
+
+ if (list != null && list.Count != 0)
+ {
+ List<QueueTask> tasks = list.Where(l => l.Status != QueueItemStatus.Completed).ToList();
+ if (tasks.Count != 0)
+ {
+ queueFiles.Add(file.Name);
+ }
+ }
+ }
+ }
+
+ // Cleanup old/unused queue files for now.
+ if (!GeneralUtilities.IsMultiInstance)
+ {
+ foreach (string file in removeFiles)
+ {
+ File.Delete(file);
+ }
+ }
+
+ return queueFiles;
+ }
+ catch (Exception exc)
+ {
+ return new List<string>(); // Keep quiet about the error.
+ }
+ }
+
+ /// <summary>
+ /// Recover a queue from file.
+ /// </summary>
+ /// <param name="encodeQueue">
+ /// The encode Queue.
+ /// </param>
+ /// <param name="errorService">
+ /// The error Service.
+ /// </param>
+ public static void RecoverQueue(IQueueProcessor encodeQueue, IErrorService errorService)
+ {
+ string appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\");
+ List<string> queueFiles = CheckQueueRecovery();
+ MessageBoxResult result = MessageBoxResult.None;
+ if (queueFiles.Count == 1)
+ {
+ result = errorService.ShowMessageBox(
+ "HandBrake has detected unfinished items on the queue from the last time the application was launched. Would you like to recover these?",
+ "Queue Recovery Possible", MessageBoxButton.YesNo, MessageBoxImage.Question);
+ }
+ else if (queueFiles.Count > 1)
+ {
+ result = MessageBox.Show(
+ "HandBrake has detected multiple unfinished queue files. These will be from multiple instances of HandBrake running. Would you like to recover all unfinished jobs?",
+ "Queue Recovery Possible", MessageBoxButton.YesNo, MessageBoxImage.Question);
+ }
+
+ if (result == MessageBoxResult.Yes)
+ {
+ foreach (string file in queueFiles)
+ {
+ encodeQueue.QueueManager.RestoreQueue(appDataPath + file); // Start Recovery
+ }
+ }
+ else
+ {
+ if (GeneralUtilities.IsMultiInstance) return; // Don't tamper with the files if we are multi instance
+
+ foreach (string file in queueFiles)
+ {
+ if (File.Exists(Path.Combine(appDataPath, file)))
+ File.Delete(Path.Combine(appDataPath, file));
+ }
+ }
+ }
+ }
+}
diff --git a/win/CS/HandBrakeWPF/Helpers/UpdateCheckHelper.cs b/win/CS/HandBrakeWPF/Helpers/UpdateCheckHelper.cs new file mode 100644 index 000000000..11917e771 --- /dev/null +++ b/win/CS/HandBrakeWPF/Helpers/UpdateCheckHelper.cs @@ -0,0 +1,60 @@ +// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="UpdateCheckHelper.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Update Check Helper
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Helpers
+{
+ using System;
+ using System.Windows;
+
+ using Caliburn.Micro;
+
+ using HandBrake.ApplicationServices.Model.General;
+ using HandBrake.ApplicationServices.Services;
+
+ using HandBrakeWPF.Services.Interfaces;
+
+ /// <summary>
+ /// Update Check Helper
+ /// </summary>
+ public class UpdateCheckHelper
+ {
+ /// <summary>
+ /// Handle the Update Check Finishing.
+ /// </summary>
+ /// <param name="result">
+ /// The result.
+ /// </param>
+ public static void UpdateCheckDoneMenu(IAsyncResult result)
+ {
+ // Make sure it's running on the calling thread
+ IErrorService errorService = IoC.Get<IErrorService>();
+ try
+ {
+ // Get the information about the new build, if any, and close the window
+ UpdateCheckInformation info = UpdateService.EndCheckForUpdates(result);
+
+ if (info.NewVersionAvailable)
+ {
+ errorService.ShowMessageBox(
+ "A New Update is Available", "Update available!", MessageBoxButton.OK, MessageBoxImage.Information);
+ }
+ else
+ {
+ errorService.ShowMessageBox(
+ "There is no new version at this time.", "No Updates", MessageBoxButton.OK, MessageBoxImage.Information);
+ }
+ return;
+ }
+ catch (Exception ex)
+ {
+ errorService.ShowError("Unable to check for updates", "Please try again later, the update service may currently be down.", ex);
+ }
+ }
+ }
+}
|