Skip to content
This repository was archived by the owner on Aug 23, 2025. It is now read-only.

Commit 14152fb

Browse files
committed
Preliminary 1.3.3 commit
Fixed issue #37 Added missing "VM not found" error for -S parameter Code clean up Updated copyright year to include 2019 Please note: this is not the final 1.3.3 commit, there are some further registry related changes that need to be done
1 parent ff566ea commit 14152fb

File tree

5 files changed

+114
-91
lines changed

5 files changed

+114
-91
lines changed

86BoxManager/Program.cs

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ public struct COPYDATASTRUCT
4949
static void Main()
5050
{
5151
const string name = "86Box Manager";
52-
bool firstInstance;
5352

5453
//Use a mutex to check if this is the first instance of Manager
55-
mutex = new Mutex(true, name, out firstInstance);
54+
mutex = new Mutex(true, name, out bool firstInstance);
5655

5756
//If it's not, we need to restore and focus the existing window, as well as pass on any potential command line arguments
5857
if (!firstInstance)
@@ -94,47 +93,6 @@ static void Main()
9493
Application.SetCompatibleTextRenderingDefault(false);
9594
Application.Run(new frmMain());
9695
}
97-
98-
/*
99-
//Check if Manager is already running
100-
Process[] pname = Process.GetProcessesByName("86manager");
101-
if (pname.Length > 1)
102-
{
103-
//Find the window of the first instance and restore it
104-
IntPtr hWnd = FindWindow(null, "86Box Manager");
105-
ShowWindow(hWnd, ShowWindowEnum.Show);
106-
ShowWindow(hWnd, ShowWindowEnum.Restore);
107-
SetForegroundWindow(hWnd);
108-
109-
//If the second instance was started with the -S command line argument for starting a VM, we must send
110-
//the arguments to the first instance
111-
if (args.Length == 3 && args[1] == "-S" && args[2] != null)
112-
{
113-
CopyDataStruct DataStruct = new CopyDataStruct();
114-
DataStruct.ID = "1";
115-
DataStruct.Data = args[2];
116-
DataStruct.Length = DataStruct.Data.Length;
117-
if (!hWnd.Equals(IntPtr.Zero))
118-
{
119-
SendMessage(hWnd, WM_COPYDATA, 0, ref DataStruct);
120-
}
121-
}
122-
}
123-
else
124-
{ //Then check if any instances of 86Box are already running and warn the user
125-
pname = Process.GetProcessesByName("86box");
126-
if (pname.Length > 0)
127-
{
128-
DialogResult result = MessageBox.Show("At least one instance of 86box is already running. It's not recommended that you run 86Box.exe directly outside of Manager. Do you want to continue at your own risk?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
129-
if (result == DialogResult.No)
130-
{
131-
return;
132-
}
133-
}
134-
Application.EnableVisualStyles();
135-
Application.SetCompatibleTextRenderingDefault(false);
136-
Application.Run(new frmMain());
137-
}*/
13896
}
13997
}
14098
}

86BoxManager/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
//
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
34-
[assembly: AssemblyVersion("1.3.2.0")]
35-
[assembly: AssemblyFileVersion("1.3.2.0")]
34+
[assembly: AssemblyVersion("1.3.3.0")]
35+
[assembly: AssemblyFileVersion("1.3.3.0")]

86BoxManager/dlgSettings.cs

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ private void txt_TextChanged(object sender, EventArgs e)
6161
}
6262
else
6363
{
64-
settingsChanged = CheckForChanges(); //true;
64+
settingsChanged = CheckForChanges();
6565
btnOK.Enabled = true;
6666
}
6767
}
6868

69+
//TODO: Rewrite
6970
//Save the settings to the registry
7071
private void SaveSettings()
7172
{
@@ -94,21 +95,32 @@ private void SaveSettings()
9495
}
9596
}
9697

98+
//TODO: Rewrite
9799
//Read the settings from the registry
98100
private void LoadSettings()
99101
{
100102
try
101103
{
102-
RegistryKey regkey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\86Box"); //Open the key as read only
104+
RegistryKey regkey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\86Box", false); //Open the key as read only
105+
106+
//If the key doesn't exist yet, fallback to defaults
103107
if (regkey == null)
104-
{ //Key doesn't exist yet, fallback to defaults
108+
{
109+
MessageBox.Show("86Box Manager settings could not be loaded. This is normal if you're running 86Box Manager for the first time. Default values will be used.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
110+
111+
//Create the key and reopen it for write access
105112
Registry.CurrentUser.CreateSubKey(@"SOFTWARE\86Box");
113+
regkey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\86Box", true);
114+
regkey.CreateSubKey("Virtual Machines");
115+
106116
txtCFGdir.Text = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\86Box VMs";
107117
txtEXEdir.Text = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + @"\86Box";
108118
cbxMinimize.Checked = false;
109119
cbxShowConsole.Checked = true;
110120
cbxMinimizeTray.Checked = false;
111121
cbxCloseTray.Checked = false;
122+
123+
SaveSettings(); //This will write the default values to the registry
112124
}
113125
else
114126
{
@@ -118,17 +130,18 @@ private void LoadSettings()
118130
cbxShowConsole.Checked = Convert.ToBoolean(regkey.GetValue("ShowConsole"));
119131
cbxMinimizeTray.Checked = Convert.ToBoolean(regkey.GetValue("MinimizeToTray"));
120132
cbxCloseTray.Checked = Convert.ToBoolean(regkey.GetValue("CloseToTray"));
121-
122-
//This line is needed because storing the values into the textboxes (above code) triggers textchanged event
123-
settingsChanged = false;
124-
125-
regkey.Close();
126133
}
134+
135+
regkey.Close();
127136
}
128137
catch (Exception ex)
129138
{
130139
txtCFGdir.Text = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\86Box Virtual Machines";
131140
txtEXEdir.Text = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + @"\86Box";
141+
cbxMinimize.Checked = false;
142+
cbxShowConsole.Checked = true;
143+
cbxMinimizeTray.Checked = false;
144+
cbxCloseTray.Checked = false;
132145
}
133146
}
134147

@@ -168,12 +181,12 @@ private void btnBrowse2_Click(object sender, EventArgs e)
168181

169182
private void cbxMinimize_CheckedChanged(object sender, EventArgs e)
170183
{
171-
settingsChanged = CheckForChanges();//true;
184+
settingsChanged = CheckForChanges();
172185
}
173186

174187
private void cbxShowConsole_CheckedChanged(object sender, EventArgs e)
175188
{
176-
settingsChanged = CheckForChanges();//true;
189+
settingsChanged = CheckForChanges();
177190
}
178191

179192
private void btnDefaults_Click(object sender, EventArgs e)
@@ -184,44 +197,62 @@ private void btnDefaults_Click(object sender, EventArgs e)
184197
//Resets the settings to their default values
185198
private void ResetSettings()
186199
{
187-
try
200+
RegistryKey regkey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE", true);
201+
202+
if(regkey != null)
188203
{
189-
RegistryKey regkey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE", true); //Open the key as read only
190-
Registry.CurrentUser.DeleteSubKeyTree(@"86Box");
204+
txtCFGdir.Text = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\86Box VMs\";
205+
txtEXEdir.Text = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + @"\86Box\";
206+
cbxMinimize.Checked = false;
207+
cbxShowConsole.Checked = true;
208+
cbxMinimizeTray.Checked = false;
209+
cbxCloseTray.Checked = false;
210+
211+
regkey.SetValue("EXEdir", txtEXEdir.Text, RegistryValueKind.String);
212+
regkey.SetValue("CFGdir", txtCFGdir.Text, RegistryValueKind.String);
213+
regkey.SetValue("MinimizeOnVMStart", cbxMinimize.Checked, RegistryValueKind.DWord);
214+
regkey.SetValue("ShowConsole", cbxShowConsole.Checked, RegistryValueKind.DWord);
215+
regkey.SetValue("MinimizeToTray", cbxMinimizeTray.Checked, RegistryValueKind.DWord);
216+
regkey.SetValue("CloseToTray", cbxCloseTray.Checked, RegistryValueKind.DWord);
191217
}
192-
catch (Exception ex) {/*Do nothing, key doesn't exist anyway*/}
193218

194-
txtCFGdir.Text = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\86Box VMs";
195-
txtEXEdir.Text = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + @"\86Box";
196-
cbxMinimize.Checked = false;
197-
cbxShowConsole.Checked = true;
198-
cbxMinimizeTray.Checked = false;
199-
cbxCloseTray.Checked = false;
219+
regkey.Close();
200220
}
201221

202222
private void cbxCloseTray_CheckedChanged(object sender, EventArgs e)
203223
{
204-
settingsChanged = CheckForChanges();//true;
224+
settingsChanged = CheckForChanges();
205225
}
206226

207227
private void cbxMinimizeTray_CheckedChanged(object sender, EventArgs e)
208228
{
209-
settingsChanged = CheckForChanges();//true;
229+
settingsChanged = CheckForChanges();
210230
}
211231

212232
//Checks if all controls match the currently saved settings to determine if any changes were made
213233
private bool CheckForChanges()
214234
{
215235
RegistryKey regkey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\86Box");
216236

217-
btnApply.Enabled = (txtEXEdir.Text != regkey.GetValue("EXEdir").ToString() ||
218-
txtCFGdir.Text != regkey.GetValue("CFGdir").ToString() ||
219-
cbxMinimize.Checked != Convert.ToBoolean(regkey.GetValue("MinimizeOnVMStart")) ||
220-
cbxShowConsole.Checked != Convert.ToBoolean(regkey.GetValue("ShowConsole")) ||
221-
cbxMinimizeTray.Checked != Convert.ToBoolean(regkey.GetValue("MinimizeToTray")) ||
222-
cbxCloseTray.Checked != Convert.ToBoolean(regkey.GetValue("CloseToTray")));
237+
try
238+
{
239+
btnApply.Enabled = (txtEXEdir.Text != regkey.GetValue("EXEdir").ToString() ||
240+
txtCFGdir.Text != regkey.GetValue("CFGdir").ToString() ||
241+
cbxMinimize.Checked != Convert.ToBoolean(regkey.GetValue("MinimizeOnVMStart")) ||
242+
cbxShowConsole.Checked != Convert.ToBoolean(regkey.GetValue("ShowConsole")) ||
243+
cbxMinimizeTray.Checked != Convert.ToBoolean(regkey.GetValue("MinimizeToTray")) ||
244+
cbxCloseTray.Checked != Convert.ToBoolean(regkey.GetValue("CloseToTray")));
223245

224-
return btnApply.Enabled;
246+
return btnApply.Enabled;
247+
}
248+
catch(Exception ex)
249+
{
250+
return true; //For now let's just return true if anything goes wrong
251+
}
252+
finally
253+
{
254+
regkey.Close();
255+
}
225256
}
226257
}
227258
}

86BoxManager/frmMain.cs

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ private void frmMain_Load(object sender, EventArgs e)
6565
lvi.Focused = true;
6666
VMStart();
6767
}
68+
else
69+
{
70+
MessageBox.Show("The virtual machine \"" + Program.args[2] + "\" could not be found. It may have been removed or the specified name is incorrect.", "Virtual machine not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
71+
}
6872
}
6973
}
7074

@@ -187,37 +191,63 @@ private void btnEdit_Click(object sender, EventArgs e)
187191
//Load the settings from the registry
188192
private void LoadSettings()
189193
{
194+
regkey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\86Box", true);
195+
196+
//Try to load the settings from registry, if it fails fallback to default values
190197
try
191198
{
192-
regkey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\86Box");
193199
exepath = regkey.GetValue("EXEdir").ToString();
194200
cfgpath = regkey.GetValue("CFGdir").ToString();
201+
minimize = Convert.ToBoolean(regkey.GetValue("MinimizeOnVMStart"));
202+
showConsole = Convert.ToBoolean(regkey.GetValue("ShowConsole"));
203+
minimizeTray = Convert.ToBoolean(regkey.GetValue("MinimizeToTray"));
204+
closeTray = Convert.ToBoolean(regkey.GetValue("CloseToTray"));
205+
}
206+
catch(Exception ex)
207+
{
208+
MessageBox.Show("86Box Manager settings could not be loaded. This is normal if you're running 86Box Manager for the first time. Default values will be used.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
195209

196-
//This check is necessary in case the tailing backslash is not present!
210+
//If the key doesn't exist, create it and then reopen it
211+
if (regkey == null)
212+
{
213+
Registry.CurrentUser.CreateSubKey(@"SOFTWARE\86Box");
214+
regkey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\86Box", true);
215+
}
216+
217+
cfgpath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\86Box VMs\";
218+
exepath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + @"\86Box\";
219+
minimize = false;
220+
showConsole = true;
221+
minimizeTray = false;
222+
closeTray = false;
223+
224+
//Defaults must also be written to the registry
225+
regkey.SetValue("EXEdir", exepath, RegistryValueKind.String);
226+
regkey.SetValue("CFGdir", cfgpath, RegistryValueKind.String);
227+
regkey.SetValue("MinimizeOnVMStart", minimize, RegistryValueKind.DWord);
228+
regkey.SetValue("ShowConsole", showConsole, RegistryValueKind.DWord);
229+
regkey.SetValue("MinimizeToTray", minimizeTray, RegistryValueKind.DWord);
230+
regkey.SetValue("CloseToTray", closeTray, RegistryValueKind.DWord);
231+
232+
regkey.CreateSubKey("Virtual Machines");
233+
}
234+
finally
235+
{
236+
//To make sure there's a trailing backslash at the end, as other cude using these strings expects it!
197237
if (!exepath.EndsWith(@"\"))
198238
{
199239
exepath += @"\";
200240
}
201-
202241
if (!cfgpath.EndsWith(@"\"))
203242
{
204243
cfgpath += @"\";
205244
}
206-
207-
minimize = Convert.ToBoolean(regkey.GetValue("MinimizeOnVMStart"));
208-
showConsole = Convert.ToBoolean(regkey.GetValue("ShowConsole"));
209-
minimizeTray = Convert.ToBoolean(regkey.GetValue("MinimizeToTray"));
210-
closeTray = Convert.ToBoolean(regkey.GetValue("CloseToTray"));
211-
}
212-
catch (Exception ex) //Bad settings, retry
213-
{
214-
MessageBox.Show("86Box Manager settings are missing or corrupted. This is normal if you're running 86Box Manager for the first time. Please (re)configure the settings now.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
215-
dlgSettings dlg = new dlgSettings();
216-
dlg.ShowDialog();
217-
LoadSettings();
218245
}
246+
247+
regkey.Close();
219248
}
220249

250+
//TODO: Rewrite
221251
//Load the VMs from the registry
222252
private void LoadVMs()
223253
{
@@ -526,6 +556,10 @@ private void VMStart()
526556
}
527557
}
528558
}
559+
catch(Win32Exception ex)
560+
{
561+
MessageBox.Show("Cannot find 86Box.exe. Make sure your settings are correct and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
562+
}
529563
catch (Exception ex)
530564
{
531565
MessageBox.Show("An error has occurred. Please provide the following information to the developer:\n" + ex.Message + "\n" + ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
@@ -1003,7 +1037,7 @@ protected override void WndProc(ref Message m)
10031037
}
10041038
else
10051039
{
1006-
MessageBox.Show("The virtual machine \"" + ds.Data + "\" could not be found. It may have been removed or the specified name is invalid.", "Virtual machine not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
1040+
MessageBox.Show("The virtual machine \"" + ds.Data + "\" could not be found. It may have been removed or the specified name is incorrect.", "Virtual machine not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
10071041
}
10081042
}
10091043
base.WndProc(ref m);

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 David Simunič
3+
Copyright (c) 2018-2019 David Simunič
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)