Skip to content

Commit

Permalink
Get drive size from destination drive, not current (#211)
Browse files Browse the repository at this point in the history
- Fixes #210
  • Loading branch information
Epicpkmn11 authored Jan 13, 2023
1 parent 24d3a0a commit 2212ee5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
21 changes: 21 additions & 0 deletions arm9/source/driveOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,27 @@ const char* getDrivePath(void) {
return "";
}

Drive getDriveFromPath(const char *path) {
Drive destDrive = currentDrive;
if(strncmp(path, "sd:", 3) == 0) {
return Drive::sdCard;
} else if(strncmp(path, "fat:", 4) == 0) {
return Drive::flashcard;
} else if(strncmp(path, "ram:", 4)) {
return Drive::ramDrive;
} else if(strncmp(path, "nand:", 5)) {
return Drive::nand;
} else if(strncmp(path, "photo:", 6)) {
return Drive::nandPhoto;
} else if(strncmp(path, "nitro:", 6)) {
return Drive::nitroFS;
} else if(strncmp(path, "img:", 4)) {
return Drive::fatImg;
}

return currentDrive;
}

void fixLabel(char* label) {
for (int i = strlen(label) - 1; i >= 0; i--) {
if(label[i] != ' ') {
Expand Down
1 change: 1 addition & 0 deletions arm9/source/driveOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extern u64 imgSize;
extern u32 ramdSize;

extern const char* getDrivePath(void);
extern Drive getDriveFromPath(const char *path);

extern bool nandFound(void);
extern bool photoFound(void);
Expand Down
4 changes: 2 additions & 2 deletions arm9/source/fileOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ bool fcopy(const char *sourcePath, const char *destinationPath) {
getDirectoryContents(dirContents);

// Check that everything will fit
if(dirSize(dirContents) > driveSizeFree(currentDrive)) {
if(dirSize(dirContents) > driveSizeFree(getDriveFromPath(destinationPath))) {
font->clear(false);
font->printf(0, 0, false, Alignment::left, Palette::white, (STR_FILE_TOO_BIG + "\n\n" + STR_A_OK).c_str(), sourcePath);
font->update(false);
Expand Down Expand Up @@ -258,7 +258,7 @@ bool fcopy(const char *sourcePath, const char *destinationPath) {
}

// Check that the file will fit
if((u64)fsize > driveSizeFree(currentDrive)) {
if((u64)fsize > driveSizeFree(getDriveFromPath(destinationPath))) {
font->clear(false);
font->printf(0, 0, false, Alignment::left, Palette::white, (STR_FILE_TOO_BIG + "\n\n" + STR_A_OK).c_str(), sourcePath);
font->update(false);
Expand Down

0 comments on commit 2212ee5

Please sign in to comment.