Skip to content

Commit

Permalink
Try to mount WFS drives once even if now USBStorageDevice is connected
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed May 3, 2024
1 parent 67dfdd1 commit b2ae87a
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions source/StorageUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,21 @@ void initExternalStorage() {
// the lib before actually using it.
return;
}
int connectedStorage = 0;
if ((connectedStorage = numberUSBStorageDevicesConnected()) <= 0) {
nn::spm::Initialize();
InitEmptyExternalStorage();
nn::spm::Finalize();
return;
int numConnectedStorage;
int maxTries = 1200; // Wait up to 20 seconds, like the Wii U Menu
if ((numConnectedStorage = numberUSBStorageDevicesConnected()) <= 0) {
maxTries = 1; // Only try once if no USBStorageDrive is connected
} else {
DEBUG_FUNCTION_LINE("Connected StorageDevices = %d", numConnectedStorage);
}

DEBUG_FUNCTION_LINE("Connected StorageDevices = %d", connectedStorage);

nn::spm::Initialize();

nn::spm::StorageListItem items[0x20];
int tries = 0;
bool found = false;

while (tries < 1200) { // Wait up to 20 seconds, like the Wii U Menu
while (tries < maxTries) {
int32_t numItems = nn::spm::GetStorageList(items, 0x20);

DEBUG_FUNCTION_LINE("Number of items: %d", numItems);
Expand All @@ -127,15 +125,17 @@ void initExternalStorage() {
}
}
}
if (found || (connectedStorage == numItems)) {
if (found || (numConnectedStorage == numItems)) {
DEBUG_FUNCTION_LINE("Found all expected items, breaking.");
break;
}
OSSleepTicks(OSMillisecondsToTicks(16));
tries++;
}
if (!found) {
DEBUG_FUNCTION_LINE("USB Storage is connected but either it doesn't have a WFS partition or we ran into a timeout.");
if (numConnectedStorage > 0) {
DEBUG_FUNCTION_LINE("USB Storage is connected but either it doesn't have a WFS partition or we ran into a timeout.");
}
InitEmptyExternalStorage();
}

Expand Down

0 comments on commit b2ae87a

Please sign in to comment.