summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF
diff options
context:
space:
mode:
author[email protected] <sr55>2016-01-29 21:21:07 +0000
committer[email protected] <sr55>2016-01-29 21:21:07 +0000
commit8343b1cacf87f673a7e0b82c6cd1449d9c529edc (patch)
treed953661f4cecf1d7bf2e5f8f00a1767ce40d72e7 /win/CS/HandBrakeWPF
parentdb29f87dc3bf3909d263491390d0f56418616e26 (diff)
WinGui: Allow the Nightly build and Release version to be run side-by-side. The nightly build will store the config and presets file in a "Nightly" sub directory. If this directory doesn't exist, it'll create it and try port the release versions to it.
Diffstat (limited to 'win/CS/HandBrakeWPF')
-rw-r--r--win/CS/HandBrakeWPF/HandBrakeWPF.csproj1
-rw-r--r--win/CS/HandBrakeWPF/Services/Presets/PresetService.cs15
-rw-r--r--win/CS/HandBrakeWPF/Services/UserSettingService.cs23
-rw-r--r--win/CS/HandBrakeWPF/Utilities/DirectoryUtilities.cs41
4 files changed, 76 insertions, 4 deletions
diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
index 7504dfe21..4d09ded8f 100644
--- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
+++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
@@ -240,6 +240,7 @@
<Compile Include="Utilities\Interfaces\INotifyPropertyChangedEx.cs" />
<Compile Include="Utilities\Output\CsvHelper.cs" />
<Compile Include="Utilities\PropertyChangedBase.cs" />
+ <Compile Include="Utilities\DirectoryUtilities.cs" />
<Compile Include="Utilities\Win7.cs" />
<Compile Include="ViewModels\CountdownAlertViewModel.cs" />
<Compile Include="ViewModels\Interfaces\ICountdownAlertViewModel.cs" />
diff --git a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs
index 9b470cb06..79d35e2ab 100644
--- a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs
+++ b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs
@@ -45,7 +45,7 @@ namespace HandBrakeWPF.Services.Presets
public const int ForcePresetReset = 2;
public static string UserPresetCatgoryName = "User Presets";
- private readonly string presetFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\presets.json";
+ private readonly string presetFile = Path.Combine(DirectoryUtilities.GetUserStoragePath(VersionHelper.IsNightly()), "presets.json");
private readonly ObservableCollection<Preset> presets = new ObservableCollection<Preset>();
private readonly IErrorService errorService;
private readonly IUserSettingService userSettingService;
@@ -495,8 +495,17 @@ namespace HandBrakeWPF.Services.Presets
// If we don't have a presets file. Create one for first load.
if (!File.Exists(this.presetFile))
{
- this.UpdateBuiltInPresets();
- return; // Update built-in presets stores the presets locally, so just return.
+ // If this is a nightly, and we don't have a presets file, try port the main version if it exists.
+ string releasePresetFile = Path.Combine(DirectoryUtilities.GetUserStoragePath(false), "presets.json");
+ if (VersionHelper.IsNightly() && File.Exists(releasePresetFile))
+ {
+ File.Copy(releasePresetFile, DirectoryUtilities.GetUserStoragePath(true));
+ }
+ else
+ {
+ this.UpdateBuiltInPresets();
+ return; // Update built-in presets stores the presets locally, so just return.
+ }
}
// Otherwise, we already have a file, so lets try load it.
diff --git a/win/CS/HandBrakeWPF/Services/UserSettingService.cs b/win/CS/HandBrakeWPF/Services/UserSettingService.cs
index 612999a3a..acff3209a 100644
--- a/win/CS/HandBrakeWPF/Services/UserSettingService.cs
+++ b/win/CS/HandBrakeWPF/Services/UserSettingService.cs
@@ -15,8 +15,11 @@ namespace HandBrakeWPF.Services
using System.Reflection;
using System.Xml.Serialization;
+ using HandBrake.ApplicationServices.Utilities;
+
using HandBrakeWPF.Properties;
using HandBrakeWPF.Services.Interfaces;
+ using HandBrakeWPF.Utilities;
using GeneralApplicationException = HandBrakeWPF.Exceptions.GeneralApplicationException;
using SettingChangedEventArgs = HandBrakeWPF.EventArgs.SettingChangedEventArgs;
@@ -29,7 +32,7 @@ namespace HandBrakeWPF.Services
/// <summary>
/// The Settings File
/// </summary>
- private readonly string settingsFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\settings.xml";
+ private readonly string settingsFile = Path.Combine(DirectoryUtilities.GetUserStoragePath(VersionHelper.IsNightly()), "settings.xml");
/// <summary>
/// The XML Serializer
@@ -151,6 +154,24 @@ namespace HandBrakeWPF.Services
this.userSettings = data;
}
}
+ else if (VersionHelper.IsNightly() && File.Exists(Path.Combine(DirectoryUtilities.GetUserStoragePath(false), "settings.xml")))
+ {
+ // Port the release versions config to the nightly.
+ string releasePresetFile = Path.Combine(DirectoryUtilities.GetUserStoragePath(false), "settings.xml");
+
+ if (!Directory.Exists(DirectoryUtilities.GetUserStoragePath(true)))
+ {
+ Directory.CreateDirectory(DirectoryUtilities.GetUserStoragePath(true));
+ }
+
+ File.Copy(releasePresetFile, Path.Combine(DirectoryUtilities.GetUserStoragePath(true), "settings.xml"));
+
+ using (StreamReader reader = new StreamReader(this.settingsFile))
+ {
+ Collections.SerializableDictionary<string, object> data = (Collections.SerializableDictionary<string, object>)this.serializer.Deserialize(reader);
+ this.userSettings = data;
+ }
+ }
else
{
this.userSettings = new Collections.SerializableDictionary<string, object>();
diff --git a/win/CS/HandBrakeWPF/Utilities/DirectoryUtilities.cs b/win/CS/HandBrakeWPF/Utilities/DirectoryUtilities.cs
new file mode 100644
index 000000000..242a2188f
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Utilities/DirectoryUtilities.cs
@@ -0,0 +1,41 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="DirectoryUtilities.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 DirectoryUtilities type.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Utilities
+{
+ using System;
+ using System.IO;
+
+ /// <summary>
+ /// The directory utilities.
+ /// </summary>
+ public class DirectoryUtilities
+ {
+ /// <summary>
+ /// The get user storage path.
+ /// </summary>
+ /// <param name="isNightly">
+ /// The is nightly.
+ /// </param>
+ /// <returns>
+ /// The <see cref="string"/>.
+ /// </returns>
+ public static string GetUserStoragePath(bool isNightly)
+ {
+ if (isNightly)
+ {
+ return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "HandBrake", "Nightly");
+ }
+ else
+ {
+ return Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "HandBrake");
+ }
+ }
+ }
+}