mirror of
https://github.com/DarkStore-3DS/DarkStore.git
synced 2026-07-03 00:39:02 +00:00
Add safety checks for low SD card space (#90)
* Some attempt. * Enable some-safety-freespace-work nightlies * Upload elf with nightly * *Derp fixes.* * Bye Bye testing things. * Revert "Upload elf with nightly" This reverts commit 303968cd78e466a3fcc010915565d8265acaa76a. * Add safety checks to fcopy Co-authored-by: StackZ <47382115+SuperSaiyajinStackZ@users.noreply.github.com>
This commit is contained in:
+27
-19
@@ -123,32 +123,40 @@ Result Title::Install(const char *ciaPath, bool updatingSelf) {
|
||||
ret = FSFILE_GetSize(fileHandle, &size);
|
||||
if (R_FAILED(ret)) {
|
||||
printf("Error in:\nFSFILE_GetSize\n");
|
||||
FSFILE_Close(fileHandle);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = AM_StartCiaInstall(media, &ciaHandle);
|
||||
if (R_FAILED(ret)) {
|
||||
printf("Error in:\nAM_StartCiaInstall\n");
|
||||
return ret;
|
||||
}
|
||||
if (getAvailableSpace() >= size) {
|
||||
ret = AM_StartCiaInstall(media, &ciaHandle);
|
||||
if (R_FAILED(ret)) {
|
||||
printf("Error in:\nAM_StartCiaInstall\n");
|
||||
FSFILE_Close(fileHandle);
|
||||
return ret;
|
||||
}
|
||||
|
||||
u32 toRead = 0x200000;
|
||||
u8 *buf = new u8[toRead];
|
||||
u32 toRead = 0x200000;
|
||||
u8 *buf = new u8[toRead];
|
||||
|
||||
if (!buf) return -1;
|
||||
if (!buf) {
|
||||
FSFILE_Close(fileHandle);
|
||||
return -1;
|
||||
}
|
||||
|
||||
installSize = size;
|
||||
do {
|
||||
FSFILE_Read(fileHandle, &bytes_read, installOffset, buf, toRead);
|
||||
FSFILE_Write(ciaHandle, &bytes_written, installOffset, buf, toRead, FS_WRITE_FLUSH);
|
||||
installOffset += bytes_read;
|
||||
} while(installOffset < installSize);
|
||||
delete[] buf;
|
||||
installSize = size;
|
||||
do {
|
||||
FSFILE_Read(fileHandle, &bytes_read, installOffset, buf, toRead);
|
||||
FSFILE_Write(ciaHandle, &bytes_written, installOffset, buf, toRead, FS_WRITE_FLUSH);
|
||||
installOffset += bytes_read;
|
||||
} while(installOffset < installSize);
|
||||
delete[] buf;
|
||||
|
||||
ret = AM_FinishCiaInstall(ciaHandle);
|
||||
if (R_FAILED(ret)) {
|
||||
printf("Error in:\nAM_FinishCiaInstall\n");
|
||||
return ret;
|
||||
ret = AM_FinishCiaInstall(ciaHandle);
|
||||
if (R_FAILED(ret)) {
|
||||
printf("Error in:\nAM_FinishCiaInstall\n");
|
||||
FSFILE_Close(fileHandle);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
ret = FSFILE_Close(fileHandle);
|
||||
|
||||
Reference in New Issue
Block a user