summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsr55 <[email protected]>2019-03-09 21:09:06 +0000
committersr55 <[email protected]>2019-03-09 21:14:23 +0000
commit033edbf0ef660ec02f219d7ef429463d732015c0 (patch)
tree4e62ccefed9e711a4f8c1ec0c72e32dcc23e72d4
parentc332cf6f061948c2f03c908faca59fa05d1aead4 (diff)
WinGui: Add some error checking into the Portable mode to guide users when there are problems with probable.ini
-rw-r--r--win/CS/HandBrakeWPF/App.xaml.cs6
-rw-r--r--win/CS/HandBrakeWPF/Properties/Resources.Designer.cs31
-rw-r--r--win/CS/HandBrakeWPF/Properties/Resources.resx13
-rw-r--r--win/CS/HandBrakeWPF/Utilities/Portable.cs88
4 files changed, 115 insertions, 23 deletions
diff --git a/win/CS/HandBrakeWPF/App.xaml.cs b/win/CS/HandBrakeWPF/App.xaml.cs
index e6b063eac..7aa538137 100644
--- a/win/CS/HandBrakeWPF/App.xaml.cs
+++ b/win/CS/HandBrakeWPF/App.xaml.cs
@@ -97,7 +97,11 @@ namespace HandBrakeWPF
// Portable Mode
if (Portable.IsPortable())
{
- Portable.Initialise();
+ if(!Portable.Initialise())
+ {
+ Application.Current.Shutdown();
+ return;
+ }
}
// Setup the UI Language
diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
index afb24dd5f..14d2c2732 100644
--- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
+++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
@@ -3423,6 +3423,37 @@ namespace HandBrakeWPF.Properties {
}
/// <summary>
+ /// Looks up a localized string similar to Portable Mode: Unable to read portable.ini. There may be an error in this file. Please retry using portable.ini.template as a guide..
+ /// </summary>
+ public static string Portable_IniFileError {
+ get {
+ return ResourceManager.GetString("Portable_IniFileError", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Portable Mode: Unable to create Storage directory. Please check the path is correct and is writable.
+ ///
+ /// {0}.
+ /// </summary>
+ public static string Portable_StorageNotWritable {
+ get {
+ return ResourceManager.GetString("Portable_StorageNotWritable", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Portable Mode: Unable to create TMP directory. Please check the path is correct and is writable.
+ ///
+ /// {0}.
+ /// </summary>
+ public static string Portable_TmpNotWritable {
+ get {
+ return ResourceManager.GetString("Portable_TmpNotWritable", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Change the behaviour of the audio track selection for this preset.
///This will not affect your current settings in the Audio tab..
/// </summary>
diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx
index 21de9c96c..066b249ab 100644
--- a/win/CS/HandBrakeWPF/Properties/Resources.resx
+++ b/win/CS/HandBrakeWPF/Properties/Resources.resx
@@ -1925,4 +1925,17 @@ Time Remaining: {5}, Elapsed: {6:d\:hh\:mm\:ss} {7}</value>
<data name="QueueView_DeleteSelected" xml:space="preserve">
<value>Delete Selected</value>
</data>
+ <data name="Portable_TmpNotWritable" xml:space="preserve">
+ <value>Portable Mode: Unable to create TMP directory. Please check the path is correct and is writable.
+
+ {0}</value>
+ </data>
+ <data name="Portable_StorageNotWritable" xml:space="preserve">
+ <value>Portable Mode: Unable to create Storage directory. Please check the path is correct and is writable.
+
+ {0}</value>
+ </data>
+ <data name="Portable_IniFileError" xml:space="preserve">
+ <value>Portable Mode: Unable to read portable.ini. There may be an error in this file. Please retry using portable.ini.template as a guide.</value>
+ </data>
</root> \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/Utilities/Portable.cs b/win/CS/HandBrakeWPF/Utilities/Portable.cs
index 243f8e5f2..2cfbce6e9 100644
--- a/win/CS/HandBrakeWPF/Utilities/Portable.cs
+++ b/win/CS/HandBrakeWPF/Utilities/Portable.cs
@@ -12,6 +12,7 @@ namespace HandBrakeWPF.Utilities
using System;
using System.Collections.Generic;
using System.IO;
+ using System.Windows;
/// <summary>
/// This class is responsible for reading the Portable.ini file that allows HandBrake to be run out of a directory.
@@ -24,50 +25,93 @@ namespace HandBrakeWPF.Utilities
/// <summary>
/// Initializes a new instance of the <see cref="Portable"/> class.
/// </summary>
- public static void Initialise()
+ public static bool Initialise()
{
if (!IsPortable())
{
- return; // Nothing to do.
+ return true;
}
// Read the INI file
if (File.Exists(portableFile))
{
- using (StreamReader fileReader = new StreamReader(portableFile))
+ try
{
- string line;
- while ((line = fileReader.ReadLine()) != null)
+ using (StreamReader fileReader = new StreamReader(portableFile))
{
- line = line.Trim();
-
- if (line.StartsWith("#"))
+ string line;
+ while ((line = fileReader.ReadLine()) != null)
{
- continue; // Ignore Comments
- }
-
- string[] setting = line.Split('=');
- if (setting.Length == 2)
- {
- keyPairs.Add(setting[0].Trim(), setting[1].Trim());
+ line = line.Trim();
+
+ if (line.StartsWith("#"))
+ {
+ continue; // Ignore Comments
+ }
+
+ string[] setting = line.Split('=');
+ if (setting.Length == 2)
+ {
+ keyPairs.Add(setting[0].Trim(), setting[1].Trim());
+ }
}
}
}
+ catch
+ {
+ MessageBox.Show(
+ HandBrakeWPF.Properties.Resources.Portable_IniFileError,
+ Properties.Resources.Error,
+ MessageBoxButton.OK,
+ MessageBoxImage.Error);
+ return false;
+ }
}
// Create any missing directories
- if (!Directory.Exists(GetTempDirectory()))
+ string tmpDir = GetTempDirectory();
+ if (!string.IsNullOrEmpty(tmpDir) && !Directory.Exists(tmpDir))
{
- Directory.CreateDirectory(GetTempDirectory());
+ try
+ {
+ Directory.CreateDirectory(tmpDir);
+ }
+ catch (Exception)
+ {
+ MessageBox.Show(
+ string.Format(Properties.Resources.Portable_TmpNotWritable, tmpDir),
+ Properties.Resources.Error,
+ MessageBoxButton.OK,
+ MessageBoxImage.Error);
+ return false;
+ }
}
- if (!Directory.Exists(GetStorageDirectory()))
+ string stroageDir = GetStorageDirectory();
+ if (!Directory.Exists(stroageDir))
{
- Directory.CreateDirectory(GetStorageDirectory());
+ try
+ {
+ Directory.CreateDirectory(stroageDir);
+ }
+ catch (Exception)
+ {
+ MessageBox.Show(
+ string.Format(HandBrakeWPF.Properties.Resources.Portable_StorageNotWritable, stroageDir),
+ Properties.Resources.Error,
+ MessageBoxButton.OK,
+ MessageBoxImage.Error);
+ return false;
+ }
}
// Setup environment variables for this instance.
- Environment.SetEnvironmentVariable("TMP", GetTempDirectory());
+ if (!string.IsNullOrEmpty(tmpDir))
+ {
+ Environment.SetEnvironmentVariable("TMP", GetTempDirectory());
+ }
+
+ return true;
}
/// <summary>
@@ -101,7 +145,7 @@ namespace HandBrakeWPF.Utilities
string directory = keyPairs["storage.dir"];
// If "cwd", then treat that as Current Working Directory.
- if (directory == "cwd")
+ if (!string.IsNullOrEmpty(directory) && directory == "cwd")
{
storagePath = Path.Combine(Environment.CurrentDirectory, "storage");
}
@@ -111,7 +155,7 @@ namespace HandBrakeWPF.Utilities
{
storagePath = directory;
}
- }
+ }
// Return what path we figured out to use.
return storagePath;