]> granicus.if.org Git - handbrake/commitdiff
WinGui: Add a new command line argument to the HandBrake GUI executable (--reset...
authorsr55 <sr55.hb@outlook.com>
Sat, 1 Mar 2014 16:44:34 +0000 (16:44 +0000)
committersr55 <sr55.hb@outlook.com>
Sat, 1 Mar 2014 16:44:34 +0000 (16:44 +0000)
Also fixed a small bug on the Add to queue button. Don't actually add an item without a destination.

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6091 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/CS/HandBrakeWPF/App.xaml.cs
win/CS/HandBrakeWPF/HandBrakeWPF.csproj
win/CS/HandBrakeWPF/Utilities/HandBrakeApp.cs [new file with mode: 0644]
win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs

index 8d76a8dd2878cea47e46893079550be29fc9bfd2..b8ddfaff17622a20350c81050730d6ecd71f97d3 100644 (file)
@@ -18,6 +18,7 @@ namespace HandBrakeWPF
 \r
     using HandBrake.ApplicationServices.Exceptions;\r
 \r
+    using HandBrakeWPF.Utilities;\r
     using HandBrakeWPF.ViewModels;\r
     using HandBrakeWPF.ViewModels.Interfaces;\r
 \r
@@ -45,7 +46,7 @@ namespace HandBrakeWPF
         protected override void OnStartup(StartupEventArgs e)\r
         {\r
             OperatingSystem OS = Environment.OSVersion;\r
-            if ((OS.Platform == PlatformID.Win32NT) && (OS.Version.Major == 5 && OS.Version.Minor == 1 ))\r
+            if ((OS.Platform == PlatformID.Win32NT) && (OS.Version.Major == 5 && OS.Version.Minor == 1))\r
             {\r
                 MessageBox.Show("Windows XP support is currently broken. It is not known if or when it will be fixed.", "Notice", MessageBoxButton.OK, MessageBoxImage.Warning);\r
                 Application.Current.Shutdown();\r
@@ -58,6 +59,13 @@ namespace HandBrakeWPF
                 MessageBox.Show("Instant HandBrake is just a prototype for toying with ideas. It may or may not work, or even be included in future builds.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);\r
             }\r
 \r
+            if (e.Args.Any(f => f.Equals("--reset")))\r
+            {\r
+                HandBrakeApp.ResetToDefaults();\r
+                Application.Current.Shutdown();\r
+                return;\r
+            }\r
+\r
             base.OnStartup(e);\r
 \r
             // If we have a file dropped on the icon, try scanning it.\r
index 8e92b7115f6129309c43a7698377861d601ae350..865b754621bcafc664efc14f96ecf1d1150f462b 100644 (file)
     <Compile Include="Services\Interfaces\IUserSettingService.cs" />\r
     <Compile Include="Services\UserSettingService.cs" />\r
     <Compile Include="Utilities\DelayedActionProcessor.cs" />\r
+    <Compile Include="Utilities\HandBrakeApp.cs" />\r
     <Compile Include="ViewModels\CountdownAlertViewModel.cs" />\r
     <Compile Include="ViewModels\Interfaces\ICountdownAlertViewModel.cs" />\r
     <Compile Include="Controls\SourceSelection.xaml.cs">\r
diff --git a/win/CS/HandBrakeWPF/Utilities/HandBrakeApp.cs b/win/CS/HandBrakeWPF/Utilities/HandBrakeApp.cs
new file mode 100644 (file)
index 0000000..bcdbfb4
--- /dev/null
@@ -0,0 +1,63 @@
+// --------------------------------------------------------------------------------------------------------------------\r
+// <copyright file="HandBrakeApp.cs" company="HandBrake Project (http://handbrake.fr)">\r
+//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
+// </copyright>\r
+// <summary>\r
+//   A general Helper class for HandBrake GUI\r
+// </summary>\r
+// --------------------------------------------------------------------------------------------------------------------\r
+\r
+namespace HandBrakeWPF.Utilities\r
+{\r
+    using System;\r
+    using System.Collections.Generic;\r
+    using System.IO;\r
+    using System.Linq;\r
+\r
+    /// <summary>\r
+    /// A general Helper class for HandBrake GUI\r
+    /// </summary>\r
+    public class HandBrakeApp\r
+    {\r
+        /// <summary>\r
+        /// The reset to defaults.\r
+        /// </summary>\r
+        public static void ResetToDefaults()\r
+        {\r
+            DeleteFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\presets.xml");\r
+            DeleteFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\user_presets.xml");\r
+            DeleteFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\settings.xml");\r
+\r
+            string tempPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\");\r
+            DirectoryInfo info = new DirectoryInfo(tempPath);\r
+            IEnumerable<FileInfo> logFiles = info.GetFiles("*.xml").Where(f => f.Name.StartsWith("hb_queue_recovery"));\r
+            foreach (FileInfo file in logFiles)\r
+            {\r
+                DeleteFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\" + file.Name);\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// The delete file.\r
+        /// </summary>\r
+        /// <param name="file">\r
+        /// The file.\r
+        /// </param>\r
+        private static void DeleteFile(string file)\r
+        {\r
+            try\r
+            {\r
+                Console.WriteLine("Trying to deleting File: {0}", file);\r
+                if (File.Exists(file))\r
+                {\r
+                    File.Delete(file);\r
+                    Console.WriteLine("File was deleted successfully");\r
+                }\r
+            }\r
+            catch (Exception exc)\r
+            {\r
+                Console.WriteLine("Unable to Delete File: {0} {1} {2}", file, Environment.NewLine, exc);\r
+            }\r
+        }\r
+    }\r
+}\r
index fb657e686384ac166ab96ea4b5b00735dcca2c04..a2ae6708b0cffeca48eb5f7f6c838a4bba927596 100644 (file)
@@ -1140,11 +1140,11 @@ namespace HandBrakeWPF.ViewModels
             if (string.IsNullOrEmpty(this.CurrentTask.Destination))\r
             {\r
                 this.errorService.ShowMessageBox(Resources.Main_SetDestination, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);\r
+                return;\r
             }\r
 \r
             QueueTask task = new QueueTask(new EncodeTask(this.CurrentTask), HBConfigurationFactory.Create());\r
-\r
-\r
+            \r
             if (!this.queueProcessor.CheckForDestinationPathDuplicates(task.Task.Destination))\r
             {\r
                 this.queueProcessor.Add(task);\r