}
}
+ /// <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..
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.
/// <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>
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");
}
{
storagePath = directory;
}
- }
+ }
// Return what path we figured out to use.
return storagePath;