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

Commit 10e59d7

Browse files
committed
Remember VM list sorting order
VM sorting column and order is now persistent as per issue #53 Fixed an issue with deleting multiple VMs Added a keyboard shortcut for deleting VMs
1 parent c40ad45 commit 10e59d7

File tree

3 files changed

+92
-22
lines changed

3 files changed

+92
-22
lines changed

86BoxManager/frmMain.Designer.cs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

86BoxManager/frmMain.cs

Lines changed: 88 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public struct COPYDATASTRUCT
4040
private bool closeTray = false; //Close the Manager Window to tray icon?
4141
private string hWndHex = ""; //Window handle of this window
4242
private const string ZEROID = "0000000000000000"; //Used for the id parameter of 86Box -H
43-
private int sortColumn = -1; //For column sorting's asc/desc capability
43+
private int sortColumn = 0; //The column for sorting
44+
private SortOrder sortOrder = SortOrder.Ascending; //Sorting order
4445
private int launchTimeout = 5000; //Timeout for waiting for 86Box.exe to initialize
4546
private bool logging = false; //Logging enabled for 86Box.exe (-L parameter)?
4647
private string logpath = ""; //Path to log file
@@ -226,8 +227,12 @@ private void LoadSettings()
226227
logpath = regkey.GetValue("LogPath").ToString();
227228
logging = Convert.ToBoolean(regkey.GetValue("EnableLogging"));
228229
gridlines = Convert.ToBoolean(regkey.GetValue("EnableGridLines"));
230+
sortColumn = Convert.ToInt32(regkey.GetValue("SortColumn"));
231+
sortOrder = (SortOrder)Convert.ToInt32(regkey.GetValue("SortOrder"));
229232

230233
lstVMs.GridLines = gridlines;
234+
//lstVMs.Sorting = sortOrder;
235+
VMSort(sortColumn, sortOrder);
231236
}
232237
catch (Exception ex)
233238
{
@@ -251,10 +256,14 @@ private void LoadSettings()
251256
logging = false;
252257
logpath = "";
253258
gridlines = false;
259+
sortColumn = 0;
260+
sortOrder = SortOrder.Ascending;
254261

255262
lstVMs.GridLines = false;
263+
VMSort(sortColumn, sortOrder);
256264

257265
//Defaults must also be written to the registry
266+
regkey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\86Box", true);
258267
regkey.SetValue("EXEdir", exepath, RegistryValueKind.String);
259268
regkey.SetValue("CFGdir", cfgpath, RegistryValueKind.String);
260269
regkey.SetValue("MinimizeOnVMStart", minimize, RegistryValueKind.DWord);
@@ -265,6 +274,8 @@ private void LoadSettings()
265274
regkey.SetValue("EnableLogging", logging, RegistryValueKind.DWord);
266275
regkey.SetValue("LogPath", logpath, RegistryValueKind.String);
267276
regkey.SetValue("EnableGridLines", gridlines, RegistryValueKind.DWord);
277+
regkey.SetValue("SortColumn", sortColumn, RegistryValueKind.DWord);
278+
regkey.SetValue("SortOrder", sortOrder, RegistryValueKind.DWord);
268279
}
269280
finally
270281
{
@@ -525,6 +536,8 @@ private void VMPause()
525536
btnStart.Enabled = false;
526537
btnConfigure.Enabled = false;
527538
pauseToolStripMenuItem.ToolTipText = "Resume this virtual machine";
539+
540+
VMSort(sortColumn, sortOrder);
528541
}
529542

530543
//Resumes the selected VM
@@ -540,6 +553,8 @@ private void VMResume()
540553
btnStart.Enabled = true;
541554
btnConfigure.Enabled = true;
542555
pauseToolStripMenuItem.ToolTipText = "Pause this virtual machine";
556+
557+
VMSort(sortColumn, sortOrder);
543558
}
544559

545560
//Starts the selected VM
@@ -622,6 +637,8 @@ private void VMStart()
622637
{
623638
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);
624639
}
640+
641+
VMSort(sortColumn, sortOrder);
625642
}
626643

627644
//Stops a running/paused VM
@@ -667,6 +684,8 @@ private void VMStop()
667684
{
668685
MessageBox.Show("An error occurred trying to stop the selected virtual machine.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
669686
}
687+
688+
VMSort(sortColumn, sortOrder);
670689
}
671690

672691
//Start VM if it's stopped or stop it if it's running/paused
@@ -751,6 +770,8 @@ private void VMConfigure()
751770
MessageBox.Show("This virtual machine could not be started. Please provide the following information to the developer:\n" + ex.Message + "\n" + ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
752771
}
753772
}
773+
774+
VMSort(sortColumn, sortOrder);
754775
}
755776

756777
private void resetCTRLALTDELETEToolStripMenuItem_Click(object sender, EventArgs e)
@@ -915,6 +936,7 @@ public void VMEdit(string name, string desc)
915936
regkey.Close();
916937

917938
MessageBox.Show("Virtual machine \"" + vm.Name + "\" was successfully modified. Please update its configuration so that any folder paths (e.g. for hard disk images) point to the new folder.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
939+
VMSort(sortColumn, sortOrder);
918940
}
919941

920942
private void btnDelete_Click(object sender, EventArgs e)
@@ -932,17 +954,22 @@ private void VMRemove()
932954

933955
if (result1 == DialogResult.Yes)
934956
{
957+
if(vm.Status != VM.STATUS_STOPPED)
958+
{
959+
MessageBox.Show("Virtual machine \"" + vm.Name + "\" is currently running and cannot be removed. Please stop virtual machines before attempting to remove them.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
960+
continue;
961+
}
935962
try
936963
{
937-
lstVMs.Items.Remove(lstVMs.SelectedItems[0]);
964+
lstVMs.Items.Remove(lvi);
938965
regkey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\86Box\Virtual Machines", true);
939966
regkey.DeleteValue(vm.Name);
940967
regkey.Close();
941968
}
942969
catch (Exception ex) //Catches "regkey doesn't exist" exceptions and such
943970
{
944971
MessageBox.Show("Virtual machine \"" + vm.Name + "\" could not be removed due to the following error:\n\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
945-
return;
972+
continue;
946973
}
947974

948975
DialogResult result2 = MessageBox.Show("Virtual machine \"" + vm.Name + "\" was successfully removed. Would you like to delete its files as well?", "Virtual machine removed", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
@@ -955,27 +982,28 @@ private void VMRemove()
955982
catch (UnauthorizedAccessException) //Files are read-only or protected by privileges
956983
{
957984
MessageBox.Show("86Box Manager was unable to delete the files of this virtual machine because they are read-only or you don't have sufficient privileges to delete them.\n\nMake sure the files are free for deletion, then remove them manually.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
958-
return;
985+
continue;
959986
}
960987
catch (DirectoryNotFoundException) //Directory not found
961988
{
962989
MessageBox.Show("86Box Manager was unable to delete the files of this virtual machine because they no longer exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
963-
return;
990+
continue;
964991
}
965992
catch (IOException) //Files are in use by another process
966993
{
967994
MessageBox.Show("86Box Manager was unable to delete some files of this virtual machine because they are currently in use by another process.\n\nMake sure the files are free for deletion, then remove them manually.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
968-
return;
995+
continue;
969996
}
970997
catch (Exception ex)
971998
{ //Other exceptions
972999
MessageBox.Show("The following error occurred while trying to remove the files of this virtual machine:\n\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
973-
return;
1000+
continue;
9741001
}
9751002
MessageBox.Show("Files of virtual machine \"" + vm.Name + "\" were successfully deleted.", "Virtual machine files removed", MessageBoxButtons.OK, MessageBoxIcon.Information);
9761003
}
9771004
}
9781005
}
1006+
VMSort(sortColumn, sortOrder);
9791007
}
9801008

9811009
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
@@ -1207,6 +1235,10 @@ private void lstVMs_KeyDown(object sender, KeyEventArgs e)
12071235
VMStart();
12081236
}
12091237
}
1238+
if (e.KeyCode == Keys.Delete && lstVMs.SelectedItems.Count > 0)
1239+
{
1240+
VMRemove();
1241+
}
12101242
}
12111243

12121244
private void trayIcon_MouseDoubleClick(object sender, MouseEventArgs e)
@@ -1220,7 +1252,6 @@ private void trayIcon_MouseDoubleClick(object sender, MouseEventArgs e)
12201252

12211253
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
12221254
{
1223-
//List<ListViewItem> vms = new List<ListViewItem>();
12241255
int vmCount = 0;
12251256
foreach (ListViewItem item in lstVMs.Items)
12261257
{
@@ -1340,33 +1371,62 @@ private void VMKill()
13401371
}
13411372
}
13421373
}
1374+
VMSort(sortColumn, sortOrder);
13431375
}
13441376

13451377
private void killToolStripMenuItem_Click(object sender, EventArgs e)
13461378
{
13471379
VMKill();
13481380
}
13491381

1350-
//Handles the click event for the listview column headers, allowing to sort the items by columns
1351-
private void lstVMs_ColumnClick(object sender, ColumnClickEventArgs e)
1382+
//Sort the VM list by specified column and order
1383+
private void VMSort(int column, SortOrder order)
13521384
{
1353-
//Sorting a different column than the currently sorted one => sort by that one ascending
1354-
if (e.Column != sortColumn)
1385+
const string ascArrow = " ▲";
1386+
const string descArrow = " ▼";
1387+
1388+
lstVMs.SelectedItems.Clear(); //Just in case so we don't end up with weird selection glitches
1389+
1390+
//Remove the arrows from the current column text if they exist
1391+
if (sortColumn > -1 && (lstVMs.Columns[sortColumn].Text.EndsWith(ascArrow) || lstVMs.Columns[sortColumn].Text.EndsWith(descArrow)))
13551392
{
1356-
sortColumn = e.Column;
1357-
lstVMs.Sorting = SortOrder.Ascending;
1393+
lstVMs.Columns[sortColumn].Text = lstVMs.Columns[sortColumn].Text.Substring(0, lstVMs.Columns[sortColumn].Text.Length - 2);
13581394
}
1359-
//Sorting the same column => change the order from ascending to descending or vice versa
1360-
else
1395+
1396+
//Then append the appropriate arrow to the new column text
1397+
if (order == SortOrder.Ascending)
13611398
{
1362-
if (lstVMs.Sorting == SortOrder.Ascending)
1363-
lstVMs.Sorting = SortOrder.Descending;
1364-
else
1365-
lstVMs.Sorting = SortOrder.Ascending;
1399+
lstVMs.Columns[column].Text += ascArrow;
1400+
}
1401+
else if (order == SortOrder.Descending)
1402+
{
1403+
lstVMs.Columns[column].Text += descArrow;
13661404
}
13671405

1406+
sortColumn = column;
1407+
sortOrder = order;
1408+
lstVMs.Sorting = sortOrder;
13681409
lstVMs.Sort();
1369-
lstVMs.ListViewItemSorter = new _86boxManager.ListViewItemComparer(e.Column, lstVMs.Sorting);
1410+
lstVMs.ListViewItemSorter = new ListViewItemComparer(sortColumn, sortOrder);
1411+
1412+
//Save the new column and order to the registry
1413+
regkey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\86Box", true);
1414+
regkey.SetValue("SortColumn", sortColumn, RegistryValueKind.DWord);
1415+
regkey.SetValue("SortOrder", sortOrder, RegistryValueKind.DWord);
1416+
regkey.Close();
1417+
}
1418+
1419+
//Handles the click event for the listview column headers, allowing to sort the items by columns
1420+
private void lstVMs_ColumnClick(object sender, ColumnClickEventArgs e)
1421+
{
1422+
if(lstVMs.Sorting == SortOrder.Ascending)
1423+
{
1424+
VMSort(e.Column, SortOrder.Descending);
1425+
}
1426+
else if(lstVMs.Sorting == SortOrder.Descending || lstVMs.Sorting == SortOrder.None)
1427+
{
1428+
VMSort(e.Column, SortOrder.Ascending);
1429+
}
13701430
}
13711431

13721432
private void wipeToolStripMenuItem_Click(object sender, EventArgs e)
@@ -1384,15 +1444,21 @@ private void VMWipe()
13841444
DialogResult = MessageBox.Show("Wiping a virtual machine deletes its configuration and nvr files. You'll have to reconfigure the virtual machine (and the BIOS if applicable).\n\n Are you sure you wish to wipe the virtual machine \"" + vm.Name + "\"?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
13851445
if (DialogResult == DialogResult.Yes)
13861446
{
1447+
if(vm.Status != VM.STATUS_STOPPED)
1448+
{
1449+
MessageBox.Show("The virtual machine \"" + vm.Name + "\" is currently running and cannot be wiped. Please stop virtual machines before attempting to wipe them.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Error);
1450+
continue;
1451+
}
13871452
try
13881453
{
13891454
System.IO.File.Delete(vm.Path + @"\86box.cfg");
13901455
Directory.Delete(vm.Path + @"\nvr", true);
1391-
MessageBox.Show("The virtual machine \"" + vm.Name + "\" was successfully wiped.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ;
1456+
MessageBox.Show("The virtual machine \"" + vm.Name + "\" was successfully wiped.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
13921457
}
13931458
catch (Exception ex)
13941459
{
13951460
MessageBox.Show("An error occurred trying to wipe the virtual machine \"" + vm.Name + "\".", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
1461+
continue;
13961462
}
13971463
}
13981464
}

86BoxManager/frmMain.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6781,6 +6781,9 @@
67816781
////////////////////////////////////////////////////////
67826782
</value>
67836783
</data>
6784+
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
6785+
<value>429, 17</value>
6786+
</metadata>
67846787
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
67856788
<value>79</value>
67866789
</metadata>

0 commit comments

Comments
 (0)