Skip to content

Commit

Permalink
Refactored registry operations to avoid unhandled exceptions and sile…
Browse files Browse the repository at this point in the history
…nt fallbacks

The first check when loading settings on startup can now prevent the app from loading if registry cannot be used.
Also added some additional checks further in the code to prevent other unhandled exceptions or silent fallbacks.
Also removed leftover .NET Core conditional comments.
  • Loading branch information
daviunic committed Dec 28, 2022
1 parent 02bb956 commit c3f8472
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 154 deletions.
6 changes: 2 additions & 4 deletions 86BoxManager/FolderSelectDialog.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if !NETCOREAPP // Not required for .NET Core builds
using System;
using System;
using System.Reflection;
using System.Windows.Forms;

Expand Down Expand Up @@ -108,5 +107,4 @@ private class WindowWrapper : IWin32Window
public IntPtr Handle { get { return _handle; } }
}
}
}
#endif
}
20 changes: 0 additions & 20 deletions 86BoxManager/dlgAddVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,6 @@ private void txtName_TextChanged(object sender, EventArgs e)
}
}

// .NET Core implements the better Vista-style folder browse dialog in the stock FolderBrowserDialog
#if NETCOREAPP
private void btnBrowse_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog
{
RootFolder = Environment.SpecialFolder.MyComputer,
Description = "Select a folder where your virtual machines (configs, nvr folders, etc.) will be located",
UseDescriptionForTitle = true
};

if (dialog.ShowDialog() == DialogResult.OK)
{
txtImportPath.Text = dialog.SelectedPath;
txtName.Text = Path.GetFileName(dialog.SelectedPath);
}
}
// A custom class is required for Vista-style folder dialogs under the original .NET Framework
#else
private void btnBrowse_Click(object sender, EventArgs e)
{
FolderSelectDialog dialog = new FolderSelectDialog
Expand All @@ -104,7 +85,6 @@ private void btnBrowse_Click(object sender, EventArgs e)
txtName.Text = Path.GetFileName(dialog.FileName);
}
}
#endif

private void cbxImport_CheckedChanged(object sender, EventArgs e)
{
Expand Down
44 changes: 2 additions & 42 deletions 86BoxManager/dlgSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ private void LoadSettings()
}
catch (Exception ex)
{
MessageBox.Show("86Box Manager settings could not be loaded, because an error occured trying to load the registry keys and/or values. Make sure you have the required permissions and try again. Default values will be used now.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);

txtCFGdir.Text = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\86Box VMs";
txtEXEdir.Text = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + @"\86Box";
cbxMinimize.Checked = false;
Expand All @@ -234,47 +236,6 @@ private void LoadSettings()
}
}

// .NET Core implements the better Vista-style folder browse dialog in the stock FolderBrowserDialog
#if NETCOREAPP
private void btnBrowse1_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog
{
RootFolder = Environment.SpecialFolder.MyComputer,
Description = "Select a folder where 86Box program files and the roms folder are located",
UseDescriptionForTitle = true
};

if (dialog.ShowDialog() == DialogResult.OK)
{
txtEXEdir.Text = dialog.SelectedPath;
if (!txtEXEdir.Text.EndsWith(@"\")) //Just in case
{
txtEXEdir.Text += @"\";
}
}
}

private void btnBrowse2_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog
{
RootFolder = Environment.SpecialFolder.MyComputer,
Description = "Select a folder where your virtual machines (configs, nvr folders, etc.) will be located",
UseDescriptionForTitle = true
};

if (dialog.ShowDialog() == DialogResult.OK)
{
txtCFGdir.Text = dialog.SelectedPath;
if (!txtCFGdir.Text.EndsWith(@"\")) //Just in case
{
txtCFGdir.Text += @"\";
}
}
}
// A custom class is required for Vista-style folder dialogs under the original .NET Framework
#else
private void btnBrowse1_Click(object sender, EventArgs e)
{
FolderSelectDialog dialog = new FolderSelectDialog
Expand Down Expand Up @@ -310,7 +271,6 @@ private void btnBrowse2_Click(object sender, EventArgs e)
}
}
}
#endif

private void btnDefaults_Click(object sender, EventArgs e)
{
Expand Down
Loading

0 comments on commit c3f8472

Please sign in to comment.