Disk Config dialog: small refactor

This commit is contained in:
tomcw 2017-06-03 18:21:27 +01:00
parent 13aee80bd5
commit d81cb0d533

View File

@ -215,62 +215,63 @@ void CPageDisk::EnableDisk(HWND hWnd, BOOL bEnable)
void CPageDisk::HandleHDDCombo(HWND hWnd, UINT driveSelected, UINT comboSelected) void CPageDisk::HandleHDDCombo(HWND hWnd, UINT driveSelected, UINT comboSelected)
{ {
if (!IsDlgButtonChecked(hWnd, IDC_HDD_ENABLE))
return;
// Search from "select hard drive" // Search from "select hard drive"
DWORD dwOpenDialogIndex = (DWORD)SendDlgItemMessage(hWnd, comboSelected, CB_FINDSTRINGEXACT, -1, (LPARAM)&m_defaultHDDOptions[0]); DWORD dwOpenDialogIndex = (DWORD)SendDlgItemMessage(hWnd, comboSelected, CB_FINDSTRINGEXACT, -1, (LPARAM)&m_defaultHDDOptions[0]);
DWORD dwComboSelection = (DWORD)SendDlgItemMessage(hWnd, comboSelected, CB_GETCURSEL, 0, 0); DWORD dwComboSelection = (DWORD)SendDlgItemMessage(hWnd, comboSelected, CB_GETCURSEL, 0, 0);
if (IsDlgButtonChecked(hWnd, IDC_HDD_ENABLE))
SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, -1, 0); // Set to "empty" item
if (dwComboSelection == dwOpenDialogIndex)
{ {
SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, -1, 0); // Set to "empty" item EnableHDD(hWnd, FALSE); // Prevent multiple Selection dialogs to be triggered
bool bRes = HD_Select(driveSelected);
EnableHDD(hWnd, TRUE);
if (dwComboSelection == dwOpenDialogIndex) if (!bRes)
{ {
EnableHDD(hWnd, FALSE); // Prevent multiple Selection dialogs to be triggered if (SendDlgItemMessage(hWnd, comboSelected, CB_GETCOUNT, 0, 0) == 3) // If there's already a HDD...
bool bRes = HD_Select(driveSelected); SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, 0, 0); // then reselect it in the ComboBox
EnableHDD(hWnd, TRUE); return;
}
if (!bRes) // Add hard drive name as item 0 and select it
{ if (dwOpenDialogIndex > 0)
if (SendDlgItemMessage(hWnd, comboSelected, CB_GETCOUNT, 0, 0) == 3) // If there's already a disk... {
SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, 0, 0); // then reselect it in the ComboBox // Remove old item first
return; SendDlgItemMessage(hWnd, comboSelected, CB_DELETESTRING, 0, 0);
} }
// Add hard drive name as item 0 and select it SendDlgItemMessage(hWnd, comboSelected, CB_INSERTSTRING, 0, (LPARAM)HD_GetFullName(driveSelected));
if (dwOpenDialogIndex > 0) SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, 0, 0);
// If the HD was in the other combo, remove now
DWORD comboOther = (comboSelected == IDC_COMBO_HDD1) ? IDC_COMBO_HDD2 : IDC_COMBO_HDD1;
DWORD duplicated = (DWORD)SendDlgItemMessage(hWnd, comboOther, CB_FINDSTRINGEXACT, -1, (LPARAM)HD_GetFullName(driveSelected));
if (duplicated != CB_ERR)
{
SendDlgItemMessage(hWnd, comboOther, CB_DELETESTRING, duplicated, 0);
SendDlgItemMessage(hWnd, comboOther, CB_SETCURSEL, -1, 0);
}
}
else if (dwComboSelection == (dwOpenDialogIndex+1))
{
if (dwComboSelection > 1)
{
UINT uCommand = (driveSelected == 0) ? IDC_COMBO_HDD1 : IDC_COMBO_HDD2;
if (RemovalConfirmation(uCommand))
{ {
// Remove old item first // Unplug selected disk
HD_Unplug(driveSelected);
// Remove drive from list
SendDlgItemMessage(hWnd, comboSelected, CB_DELETESTRING, 0, 0); SendDlgItemMessage(hWnd, comboSelected, CB_DELETESTRING, 0, 0);
} }
else
SendDlgItemMessage(hWnd, comboSelected, CB_INSERTSTRING, 0, (LPARAM)HD_GetFullName(driveSelected));
SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, 0, 0);
// If the HD was in the other combo, remove now
DWORD comboOther = (comboSelected == IDC_COMBO_HDD1) ? IDC_COMBO_HDD2 : IDC_COMBO_HDD1;
DWORD duplicated = (DWORD)SendDlgItemMessage(hWnd, comboOther, CB_FINDSTRINGEXACT, -1, (LPARAM)HD_GetFullName(driveSelected));
if (duplicated != CB_ERR)
{ {
SendDlgItemMessage(hWnd, comboOther, CB_DELETESTRING, duplicated, 0); SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, 0, 0);
SendDlgItemMessage(hWnd, comboOther, CB_SETCURSEL, -1, 0);
}
}
else if (dwComboSelection == (dwOpenDialogIndex+1))
{
if (dwComboSelection > 1)
{
UINT uCommand = (driveSelected == 0) ? IDC_COMBO_HDD1 : IDC_COMBO_HDD2;
if (RemovalConfirmation(uCommand))
{
// Unplug selected disk
HD_Unplug(driveSelected);
// Remove drive from list
SendDlgItemMessage(hWnd, comboSelected, CB_DELETESTRING, 0, 0);
}
else
{
SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, 0, 0);
}
} }
} }
} }