Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add loader error messages if no usb device is mounted for slippi file write #40

Open
wants to merge 6 commits into
base: slippi
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions loader/source/diskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ DSTATUS disk_initialize (
if (!disk_isInit[pdrv]) {
if (!driver[pdrv]->startup())
return STA_NOINIT;

// Device initialized.
disk_isInit[pdrv] = true;
}
if (!driver[pdrv]->isInserted())
return STA_NODISK;
Expand All @@ -95,9 +98,6 @@ DSTATUS disk_initialize (
// NOTE: endOfPartition isn't usable, since this is a
// per-disk cache, not per-partition. Use UINT_MAX-1.
cache[pdrv] = _FAT_cache_constructor(4, 64, driver[pdrv], UINT_MAX-1, sectorSize[pdrv]);

// Device initialized.
disk_isInit[pdrv] = true;
return 0;
}

Expand Down
14 changes: 14 additions & 0 deletions loader/source/global.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,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 @@ -624,6 +633,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
74 changes: 64 additions & 10 deletions loader/source/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "../../common/config/MeleeCodes.h"
#include "ff_utf8.h"
#include "ShowGameInfo.h"
#include "diskio.h"

static u8 meleeCodeSelectionIndices[MELEE_CODES_LINE_ITEM_COUNT];
static u8 devState = DEV_OK;
Expand Down Expand Up @@ -825,24 +826,64 @@ static void Menu_GameSelection_Redraw(MenuCtx *ctx)
PrintFormat(DEFAULT_SIZE, (ncfg->Config & (NIN_CFG_SLIPPI_REPLAYS)) ? GREEN : RED, MENU_POS_X+320+(24*10),
gamelist_y, "%-3s", (ncfg->Config & (NIN_CFG_SLIPPI_REPLAYS)) ? "ON" : "OFF");

if ((ncfg->UseUSB == 0) && (usb_attached != 1) && (ncfg->Config & (NIN_CFG_SLIPPI_REPLAYS)))
{
int usbStatusY;
switch (disk_status(ncfg->UseUSB ? DEV_SD : DEV_USB)) {
case STA_NODISK: {
PrintFormat(MENU_SIZE, RED, MENU_POS_X, SettingY(11), "[!] NO WRITE DEVICE");
PrintFormat(MENU_SIZE, BLACK, MENU_POS_X, SettingY(12), "Please insert a USB drive");
PrintFormat(MENU_SIZE, BLACK, MENU_POS_X, SettingY(13), "to write Slippi replays.");
usbStatusY = 15;
break;
}
case STA_NOINIT: {
PrintFormat(MENU_SIZE, RED, MENU_POS_X, SettingY(11), "[!] INTERNAL ERROR");
PrintFormat(MENU_SIZE, BLACK, MENU_POS_X, SettingY(12), "Unable to check USB drive");
PrintFormat(MENU_SIZE, BLACK, MENU_POS_X, SettingY(13), "There may be a non-Slippi");
PrintFormat(MENU_SIZE, BLACK, MENU_POS_X, SettingY(14), "problem in this Wii's");
PrintFormat(MENU_SIZE, BLACK, MENU_POS_X, SettingY(15), "hardware or software.");
usbStatusY = 17;
break;
}
default: {
PrintFormat(MENU_SIZE, ORANGE, MENU_POS_X, SettingY(11), "[!] WRITE DEVICE FORMAT");
PrintFormat(MENU_SIZE, BLACK, MENU_POS_X, SettingY(12), "Please format USB drive");
PrintFormat(MENU_SIZE, BLACK, MENU_POS_X, SettingY(13), "as FAT32 or exFAT (exFAT");
PrintFormat(MENU_SIZE, BLACK, MENU_POS_X, SettingY(14), "recommended) to write");
PrintFormat(MENU_SIZE, BLACK, MENU_POS_X, SettingY(15), "Slippi replays.");
usbStatusY = 16;
break;
}
}
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 ((usb_attached == 1) && (ncfg->Config & (NIN_CFG_SLIPPI_REPLAYS)))
if ((ncfg->UseUSB == 0) && (usb_attached == 1) && (ncfg->Config & (NIN_CFG_SLIPPI_REPLAYS)))
{
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 @@ -1813,8 +1854,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
Loading