Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix for a crash where env vars are messed up (happened on my machine!)

  • Loading branch information...
commit e7002697c83d8df852ea14fbe23f065548a83937 1 parent ba70a11
@philc authored
View
2  InstallPad.csproj
@@ -85,7 +85,7 @@
<DependentUpon>AppListErrorDialog.cs</DependentUpon>
</Compile>
<Compile Include="src\ControlList.cs">
- <SubType>Component</SubType>
+ <SubType>UserControl</SubType>
</Compile>
<Compile Include="src\ControlList.Designer.cs">
<DependentUpon>ControlList.cs</DependentUpon>
View
21 src/InstallPad.cs
@@ -133,8 +133,22 @@ private void InstallPad_Load(object sender, EventArgs e)
BuildContextMenuEntries();
// Restore form position etc. from the installpad config file
- LoadConfigFile();
-
+ // Depending upon where we bomb out, this may or may not be recoverable.
+ // E.g. if the static initializer for Preferences fails because the user
+ // has messed up system environment variables, then we should exit.
+ try
+ {
+ LoadConfigFile();
+ }
+ catch (Exception ex)
+ {
+ string message = (ex is TypeInitializationException &&
+ ex.InnerException!=null) ?
+ ex.InnerException.InnerException.Message : ex.Message;
+ MessageBox.Show(message);
+ System.Windows.Forms.Application.Exit();
+ return;
+ }
// Should be externalized
string errorMessage = "Error creating temporary folder for downloaded files: ";
@@ -409,6 +423,9 @@ void InstallPad_FormClosing(object sender, FormClosingEventArgs e)
writer = new StreamWriter(InstallPadApp.ConfigFilePath);
writer.Write(formPosition);
}
+ // We can get here if InstallPad.form_load had a problem,
+ // so just eat exceptions rather than throwing more of them.
+ catch (Exception ex) { }
finally
{
if (writer != null)
View
3  src/InstallPadApp.cs
@@ -23,7 +23,8 @@ namespace InstallPad
partial class InstallPadApp
{
#region Fields and Ctor
- private static string appListFile = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "applist.xml");
+ private static string appListFile =
+ Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "applist.xml");
private static ApplicationList appList = null;
private static Preferences preferences = new Preferences();
View
15 src/Preferences.cs
@@ -53,11 +53,16 @@ static Preferences()
{
// If these every become dynamic, we can just build this map every time we need it.
Dictionary<string, string> defaults = new Dictionary<string, string>();
-
- defaults.Add("DownloadTo", Path.GetFullPath(
- Path.Combine(Environment.GetEnvironmentVariable("TEMP"), @"InstallPad\")));
- defaults.Add("InstallationRoot", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
-
+ try
+ {
+ defaults.Add("DownloadTo", Path.GetFullPath(
+ Path.Combine(Environment.GetEnvironmentVariable("TEMP"), @"InstallPad\")));
+ defaults.Add("InstallationRoot", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
+ }
+ catch (Exception e) {
+ throw new Exception("We were unable to find the full path of either your temp folder " +
+ "or your program files folder. This might be due to some bad environment variables.",e);
+ }
return defaults;
}
Please sign in to comment.
Something went wrong with that request. Please try again.