diff options
author | sr55 <[email protected]> | 2011-03-31 20:11:30 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2011-03-31 20:11:30 +0000 |
commit | 3c4b07d3cfb12d0d3318b37f790c0d7f872a68ab (patch) | |
tree | ea699a2a4066423ef18ba63f4cfe4eedb49023b7 /win/CS | |
parent | b08d9e92f647fc005397b96d37853cb4a36910f3 (diff) |
WinGui:
- Add code to attempt an automatic recovery if config files get corrupted.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3893 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS')
-rw-r--r-- | win/CS/Functions/Main.cs | 51 | ||||
-rw-r--r-- | win/CS/Program.cs | 30 | ||||
-rw-r--r-- | win/CS/frmMain.Designer.cs | 4 |
3 files changed, 59 insertions, 26 deletions
diff --git a/win/CS/Functions/Main.cs b/win/CS/Functions/Main.cs index e0537817b..c436f4336 100644 --- a/win/CS/Functions/Main.cs +++ b/win/CS/Functions/Main.cs @@ -13,6 +13,7 @@ namespace Handbrake.Functions using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
+ using System.Threading;
using System.Windows.Forms;
using System.Xml.Serialization;
@@ -220,7 +221,7 @@ namespace Handbrake.Functions case 2: // Always M4V
destinationFilename += ".m4v";
break;
- }
+ }
}
else if (mainWindow.drop_format.SelectedIndex == 1)
destinationFilename += ".mkv";
@@ -273,7 +274,7 @@ namespace Handbrake.Functions hash = SHA1.Create().ComputeHash(stream);
}
string base64Hash = Convert.ToBase64String(hash);
-
+
// Compare the hash with the last known hash. If it's the same, return.
if (Properties.Settings.Default.CliExeHash == base64Hash)
{
@@ -283,12 +284,12 @@ namespace Handbrake.Functions // It's not the same, so start the CLI to get it's version data.
Process cliProcess = new Process();
ProcessStartInfo handBrakeCli = new ProcessStartInfo("HandBrakeCLI.exe", " -u -v0")
- {
- UseShellExecute = false,
- RedirectStandardError = true,
- RedirectStandardOutput = true,
- CreateNoWindow = true
- };
+ {
+ UseShellExecute = false,
+ RedirectStandardError = true,
+ RedirectStandardOutput = true,
+ CreateNoWindow = true
+ };
cliProcess.StartInfo = handBrakeCli;
try
@@ -332,16 +333,14 @@ namespace Handbrake.Functions }
Properties.Settings.Default.CliExeHash = base64Hash;
-
Properties.Settings.Default.Save();
}
catch (Exception e)
{
- Properties.Settings.Default.hb_build = 0;
- Properties.Settings.Default.CliExeHash = null;
- Properties.Settings.Default.Save();
-
ShowExceptiowWindow("Unable to retrieve version information from the CLI.", e.ToString());
+ // Probably corrupted config. Delete config and let the user restart.
+ RecoverFromCorruptedLocalApplicationConfig();
+ Application.Exit();
}
}
@@ -499,5 +498,31 @@ namespace Handbrake.Functions return "Unknown";
}
+
+ /// <summary>
+ /// Remove the Local Applicaiton Data.
+ /// This should only be used if something bad happens which corrupts the data.
+ /// </summary>
+ public static void RecoverFromCorruptedLocalApplicationConfig()
+ {
+ try
+ {
+ MessageBox.Show(
+ "HandBrake has attempted to recover from a corrupted config file. \nYou may neeed to reset your preferences.\n\n Please restart HandBrake",
+ "Warning",
+ MessageBoxButtons.OK,
+ MessageBoxIcon.Warning);
+
+ string directory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\HandBrake";
+ if (Directory.Exists(directory))
+ {
+ File.SetAttributes(directory, FileAttributes.Normal);
+ Directory.Delete(directory, true);
+ }
+ }
+ catch (Exception)
+ {
+ }
+ }
}
}
\ No newline at end of file diff --git a/win/CS/Program.cs b/win/CS/Program.cs index f8a9c8683..ec23be6ca 100644 --- a/win/CS/Program.cs +++ b/win/CS/Program.cs @@ -57,18 +57,26 @@ namespace Handbrake }
// Attempt to upgrade / keep the users settings between versions
- if (Settings.Default.UpdateRequired)
+ try
{
- Settings.Default.Upgrade();
- // Reset some settings
- Settings.Default.UpdateRequired = false;
- Settings.Default.CliExeHash = null;
- Settings.Default.hb_build = 0;
- Settings.Default.hb_platform = null;
- Settings.Default.hb_version = null;
-
- // Re-detect the CLI version data.
- Functions.Main.SetCliVersionData();
+ if (Settings.Default.UpdateRequired)
+ {
+ Settings.Default.Upgrade();
+ // Reset some settings
+ Settings.Default.UpdateRequired = false;
+ Settings.Default.CliExeHash = null;
+ Settings.Default.hb_build = 0;
+ Settings.Default.hb_platform = null;
+ Settings.Default.hb_version = null;
+
+ // Re-detect the CLI version data.
+ Functions.Main.SetCliVersionData();
+ }
+ }
+ catch (Exception)
+ {
+ Functions.Main.RecoverFromCorruptedLocalApplicationConfig();
+ return;
}
// Check were not running on a screen that's going to cause some funnies to happen.
diff --git a/win/CS/frmMain.Designer.cs b/win/CS/frmMain.Designer.cs index 1171afa78..a7b228b72 100644 --- a/win/CS/frmMain.Designer.cs +++ b/win/CS/frmMain.Designer.cs @@ -698,7 +698,7 @@ namespace Handbrake // mnu_killCLI
//
this.mnu_killCLI.Name = "mnu_killCLI";
- this.mnu_killCLI.Size = new System.Drawing.Size(138, 22);
+ this.mnu_killCLI.Size = new System.Drawing.Size(152, 22);
this.mnu_killCLI.Text = "Cancel Scan";
this.mnu_killCLI.Visible = false;
this.mnu_killCLI.Click += new System.EventHandler(this.mnu_killCLI_Click);
@@ -707,7 +707,7 @@ namespace Handbrake //
this.mnu_exit.Name = "mnu_exit";
this.mnu_exit.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.F4)));
- this.mnu_exit.Size = new System.Drawing.Size(138, 22);
+ this.mnu_exit.Size = new System.Drawing.Size(152, 22);
this.mnu_exit.Text = "E&xit";
this.mnu_exit.Click += new System.EventHandler(this.mnu_exit_Click);
//
|