Skip to content

Commit

Permalink
run MountDevice when returning to device selection
Browse files Browse the repository at this point in the history
this allows the user to check usb drive readiness for file write without returning to loader or restarting the Wii.

also add affirmative usb drive file write ready message.

It also fixes a bug where having initially no usb drive for file write inserted and then inserting a valid usb drive and backing out to device selection, then coming back in to game selection would show the file system warning/error.
  • Loading branch information
jmlee337 committed Oct 19, 2023
1 parent 20b5158 commit 4ef16dc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
14 changes: 14 additions & 0 deletions loader/source/global.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,17 @@ const WCHAR *MountDevice(BYTE pdrv)
// Could not mount the filesystem.
free(devices[pdrv]);
devices[pdrv] = NULL;

if (pdrv == DEV_USB)
{
usb_attached = 0;
}
}
}
else if (pdrv == DEV_USB)
{
usb_attached = 0;
}

return (devices[pdrv] ? devInitInfo[pdrv].devNameFF : NULL);
}
Expand All @@ -631,6 +640,11 @@ int UnmountDevice(BYTE pdrv)
// Free the FatFS object.
free(devices[pdrv]);
devices[pdrv] = 0;

if (pdrv == DEV_USB)
{
usb_attached = 0;
}
}

// Shut down the device driver.
Expand Down
43 changes: 30 additions & 13 deletions loader/source/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,29 +847,33 @@ static void Menu_GameSelection_Redraw(MenuCtx *ctx)
break;
}
}
PrintFormat(MENU_SIZE, BLACK, MENU_POS_X, SettingY(usbStatusY), "Restart Slippi Nintendont");
PrintFormat(MENU_SIZE, BLACK, MENU_POS_X, SettingY(usbStatusY + 1), "to check again or start");
PrintFormat(MENU_SIZE, BLACK, MENU_POS_X, SettingY(usbStatusY + 2), "game to try anyway.");
PrintFormat(MENU_SIZE, BLACK, MENU_POS_X, SettingY(usbStatusY), "Press start to check again");
}

// Warn the user if they're running low on USB disk space
if ((ncfg->UseUSB == 0) && (usb_attached == 1) && (ncfg->Config & (NIN_CFG_SLIPPI_FILE_WRITE)))
{
int lowUsbWarnThreshold = 500;
int lowUsbErrorThreshold = 50;

if ((usb_replays_left < lowUsbWarnThreshold) && (usb_replays_left > lowUsbErrorThreshold))
PrintFormat(MENU_SIZE, ORANGE, MENU_POS_X, SettingY(11),"[!] WARNING, LOW USB SPACE");
if (usb_replays_left <= lowUsbErrorThreshold)
PrintFormat(MENU_SIZE, RED, MENU_POS_X, SettingY(11),"[!] WARNING, LOW USB SPACE");

if (usb_replays_left < lowUsbWarnThreshold) {
// Warn the user if they're running low on USB disk space
if (usb_replays_left < lowUsbWarnThreshold)
{
if (usb_replays_left <= lowUsbErrorThreshold)
PrintFormat(MENU_SIZE, RED, MENU_POS_X, SettingY(11),"[!] WARNING, LOW USB SPACE");
else
PrintFormat(MENU_SIZE, ORANGE, MENU_POS_X, SettingY(11),"[!] WARNING, LOW USB SPACE");

PrintFormat(MENU_SIZE, BLACK, MENU_POS_X, SettingY(12), "Your USB drive is running");
PrintFormat(MENU_SIZE, BLACK, MENU_POS_X, SettingY(13), "low on free space. There ");
PrintFormat(MENU_SIZE, BLACK, MENU_POS_X, SettingY(14), "should be enough space for");
PrintFormat(MENU_SIZE, BLACK, MENU_POS_X, SettingY(15), "about %d more replays.",
(int)usb_replays_left);
}
else
{
PrintFormat(MENU_SIZE, GREEN, MENU_POS_X, SettingY(11), "READY");
PrintFormat(MENU_SIZE, BLACK, MENU_POS_X, SettingY(12), "USB drive ready to write");
PrintFormat(MENU_SIZE, BLACK, MENU_POS_X, SettingY(13), "Slippi replays.");
}
}
}
}
Expand Down Expand Up @@ -1809,8 +1813,21 @@ bool Menu_DeviceSelection(void)
if (FPAD_OK(0))
{
int ret = Menu_GameSelection();
if (ret & 2) res = true;
if (ret & 1) break;
if (ret == 0)
{
// We provide error messages when USB file write is set but no
// USB drive is ready and advise the user to return to device
// selection to check again.
// Therefore attempt to Mount USB when returning to device
// selection to keep error messages up to date.
ShowMessageScreen("Checking storage devices...");
MountDevice(DEV_USB);
}
else
{
if (ret & 2) res = true;
if (ret & 1) break;
}
redraw = true;
}
// Return to the loader
Expand Down

0 comments on commit 4ef16dc

Please sign in to comment.