Correctly calculate install size

It's now correct down to the byte, before you could cause the menu to error if you installed something within 16KiB or so of the limit
This commit is contained in:
Pk11 2022-01-14 16:31:00 -06:00
parent c8c99fa06c
commit 4ad2d28847
3 changed files with 19 additions and 8 deletions

View File

@ -447,10 +447,14 @@ bool install(char* fpath, bool systemTitle)
//get install size
iprintf("Install Size: ");
swiWaitForVBlank();
u32 clusterSize = getDsiClusterSize();
unsigned long long fileSize = getRomSize(fpath);
unsigned long long installSize = fileSize + _getSaveDataSize(h);
if (tmdFound) installSize += 708;
if ((fileSize % clusterSize) != 0)
fileSize += clusterSize - (fileSize % clusterSize);
//file + saves + TMD (rounded up to cluster size)
unsigned long long installSize = fileSize + _getSaveDataSize(h) + clusterSize;
if (tmdFound) installSize += clusterSize; //ticket, rounded up to cluster size
printBytes(installSize);
iprintf("\n");

View File

@ -514,10 +514,7 @@ unsigned long long getDsiSize()
unsigned long long getDsiFree()
{
u32 blockSize = 0;
struct statvfs st;
if (statvfs("nand:/", &st) == 0)
blockSize = st.f_bsize;
u32 blockSize = getDsiClusterSize();
//Get free space by subtracting file sizes in nand folders
unsigned long long size = getDsiSize();
@ -534,4 +531,13 @@ unsigned long long getDsiFree()
}
return size;
}
}
u32 getDsiClusterSize()
{
struct statvfs st;
if (statvfs(sdnandMode ? "sd:/" : "nand:/", &st) == 0)
return st.f_bsize;
return 0;
}

View File

@ -42,6 +42,7 @@ unsigned long long getSDCardFree();
//internal storage
unsigned long long getDsiSize();
unsigned long long getDsiFree();
u32 getDsiClusterSize();
#define getDsiUsed() (getDSIStorageSize() - getDSIStorageFree())
#endif