Skip to content

Commit

Permalink
Check free space before starting the queue.
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Rohloff <[email protected]>
  • Loading branch information
V10lator committed Oct 1, 2022
1 parent 07b6653 commit 581b826
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 13 deletions.
1 change: 1 addition & 0 deletions include/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extern "C"
bool initFS() __attribute__((__cold__));
void deinitFS() __attribute__((__cold__));
NUSDEV getUSB();
bool checkFreeSpace(NUSDEV dlDev, uint64_t size);

#ifdef __cplusplus
}
Expand Down
13 changes: 13 additions & 0 deletions src/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <file.h>
#include <filesystem.h>
#include <utils.h>
#include <menu/utils.h>

#include <coreinit/filesystem_fsa.h>

Expand Down Expand Up @@ -67,3 +68,15 @@ NUSDEV getUSB()
{
return usb;
}

bool checkFreeSpace(NUSDEV dlDev, uint64_t size)
{
uint64_t freeSpace;
const char *nd = dlDev == NUSDEV_USB01 ? NUSDIR_USB1 : (dlDev == NUSDEV_USB02 ? NUSDIR_USB2 : (dlDev == NUSDEV_SD ? NUSDIR_SD : NUSDIR_MLC));
if(FSGetFreeSpaceSize(__wut_devoptab_fs_client, getCmdBlk(), (char *)nd, &freeSpace, FS_ERROR_FLAG_ALL) == FS_STATUS_OK && size > freeSpace)
{
showNoSpaceOverlay(dlDev);
return false;
}
return true;
}
12 changes: 0 additions & 12 deletions src/menu/predownloadMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,18 +385,6 @@ static bool addToOpQueue(const TitleEntry *entry, const char *titleVer, const ch
return ret;
}

static bool checkFreeSpace(NUSDEV dlDev, uint64_t size)
{
uint64_t freeSpace;
const char *nd = dlDev == NUSDEV_USB01 ? NUSDIR_USB1 : (dlDev == NUSDEV_USB02 ? NUSDIR_USB2 : (dlDev == NUSDEV_SD ? NUSDIR_SD : NUSDIR_MLC));
if(FSGetFreeSpaceSize(__wut_devoptab_fs_client, getCmdBlk(), (char *)nd, &freeSpace, FS_ERROR_FLAG_ALL) == FS_STATUS_OK && size > freeSpace)
{
showNoSpaceOverlay(dlDev);
return false;
}
return true;
}

bool predownloadMenu(const TitleEntry *entry)
{
MCPTitleListType titleList __attribute__((__aligned__(0x40)));
Expand Down
44 changes: 43 additions & 1 deletion src/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,49 @@ static inline void removeFQ(TitleData *title)
bool proccessQueue()
{
TitleData *title;
uint64_t sizes[3] = { 0, 0, 0 };

forEachListEntry(titleQueue, title)
{
for(uint16_t i = 0; i < title->tmd->num_contents; ++i)
{
if(title->inst)
sizes[title->toUSB ? 0 : 2] += title->tmd->contents[i].size;

if(title->keepFiles)
{
int j = title->dlDev & NUSDEV_USB ? 0 : (title->dlDev & NUSDEV_SD ? 1 : 2);
if((title->tmd->contents[i].type & 0x0003) == 0x0003)
sizes[j] += 20;

sizes[j] += title->tmd->contents[i].size;
}
}
}

for(int i = 0; i < 3; ++i)
{
if(sizes[i] != 0)
{
NUSDEV toCheck;
switch(i)
{
case 0:
toCheck = getUSB();
break;
case 1:
toCheck = NUSDEV_SD;
break;
default:
toCheck = NUSDEV_MLC;
}

if(!checkFreeSpace(toCheck, sizes[i]))
return false;

}
}

TitleData *last = NULL;
forEachListEntry(titleQueue, title)
{
Expand All @@ -67,7 +110,6 @@ bool proccessQueue()
last = title;
}

removeFQ(last);
return true;
}

Expand Down

0 comments on commit 581b826

Please sign in to comment.