mirror of
https://github.com/rvtr/GodMode9i.git
synced 2025-11-02 00:11:07 -04:00
Ask before trimming ROMs (#156)
* Ask before trimming ROMs * Fix unwanted key repeat
This commit is contained in:
parent
4b16b7a011
commit
bef9eacf22
@ -129,14 +129,43 @@ int trimNds(const char *fileName) {
|
|||||||
sNDSHeaderExt ndsCardHeader;
|
sNDSHeaderExt ndsCardHeader;
|
||||||
|
|
||||||
fread(&ndsCardHeader, 1, sizeof(ndsCardHeader), file);
|
fread(&ndsCardHeader, 1, sizeof(ndsCardHeader), file);
|
||||||
|
|
||||||
|
fseek(file, 0, SEEK_END);
|
||||||
|
u32 fileSize = ftell(file);
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
u32 romSize = ((ndsCardHeader.unitCode != 0) && (ndsCardHeader.twlRomSize > 0))
|
u32 romSize = ((ndsCardHeader.unitCode != 0) && (ndsCardHeader.twlRomSize > 0))
|
||||||
? ndsCardHeader.twlRomSize : ndsCardHeader.romSize + 0x88;
|
? ndsCardHeader.twlRomSize : ndsCardHeader.romSize + 0x88;
|
||||||
|
|
||||||
truncate(fileName, romSize);
|
if(fileSize == romSize) {
|
||||||
|
font->clear(false);
|
||||||
|
font->print(0, 0, false, STR_FILE_ALREADY_TRIMMED + "\n\n" + STR_A_OK);
|
||||||
|
font->update(false);
|
||||||
|
|
||||||
return romSize;
|
do {
|
||||||
|
swiWaitForVBlank();
|
||||||
|
scanKeys();
|
||||||
|
} while(!(keysDown() & KEY_A));
|
||||||
|
} else {
|
||||||
|
font->clear(false);
|
||||||
|
font->printf(0, 0, false, Alignment::left, Palette::white, (STR_TRIM_TO_N_BYTES + "\n\n" + STR_A_YES_B_NO).c_str(), getBytes(romSize).c_str());
|
||||||
|
font->update(false);
|
||||||
|
|
||||||
|
u16 pressed;
|
||||||
|
do {
|
||||||
|
scanKeys();
|
||||||
|
pressed = keysDown();
|
||||||
|
swiWaitForVBlank();
|
||||||
|
} while(!(pressed & (KEY_A | KEY_B)));
|
||||||
|
|
||||||
|
if(pressed & KEY_A) {
|
||||||
|
truncate(fileName, romSize);
|
||||||
|
fileSize = romSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@ -459,21 +459,21 @@ FileOperation fileBrowse_A(DirEntry* entry, char path[PATH_MAX]) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
keysDownRepeat(); // prevent unwanted key repeat
|
||||||
return operations[optionOffset];
|
return operations[optionOffset];
|
||||||
}
|
} else if (pressed & KEY_B) {
|
||||||
if (pressed & KEY_B) {
|
|
||||||
return FileOperation::none;
|
return FileOperation::none;
|
||||||
}
|
}
|
||||||
#ifdef SCREENSWAP
|
#ifdef SCREENSWAP
|
||||||
// Swap screens
|
// Swap screens
|
||||||
if (pressed & KEY_TOUCH) {
|
else if (pressed & KEY_TOUCH) {
|
||||||
screenSwapped = !screenSwapped;
|
screenSwapped = !screenSwapped;
|
||||||
screenSwapped ? lcdMainOnBottom() : lcdMainOnTop();
|
screenSwapped ? lcdMainOnBottom() : lcdMainOnTop();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Make a screenshot
|
// Make a screenshot
|
||||||
if ((held & KEY_R) && (pressed & KEY_L)) {
|
else if ((held & KEY_R) && (pressed & KEY_L)) {
|
||||||
screenshot();
|
screenshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -717,14 +717,9 @@ std::string browseForFile (void) {
|
|||||||
screenOffset = 0;
|
screenOffset = 0;
|
||||||
fileOffset = 0;
|
fileOffset = 0;
|
||||||
}
|
}
|
||||||
} else if(getOp == FileOperation::showInfo) {
|
|
||||||
for (int i = 0; i < 15; i++) swiWaitForVBlank();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (entry->isDirectory && (held & KEY_R) && (pressed & KEY_A)) { // Directory options
|
||||||
|
|
||||||
// Directory options
|
|
||||||
if (entry->isDirectory && (held & KEY_R) && (pressed & KEY_A)) {
|
|
||||||
if (entry->name == "..") {
|
if (entry->name == "..") {
|
||||||
screenMode = 0;
|
screenMode = 0;
|
||||||
return "null";
|
return "null";
|
||||||
@ -736,9 +731,7 @@ std::string browseForFile (void) {
|
|||||||
for (int i = 0; i < 15; i++) swiWaitForVBlank();
|
for (int i = 0; i < 15; i++) swiWaitForVBlank();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (pressed & KEY_B) {
|
||||||
|
|
||||||
if (pressed & KEY_B) {
|
|
||||||
if (strcmp(path, getDrivePath()) == 0) {
|
if (strcmp(path, getDrivePath()) == 0) {
|
||||||
screenMode = 0;
|
screenMode = 0;
|
||||||
return "null";
|
return "null";
|
||||||
@ -748,10 +741,7 @@ std::string browseForFile (void) {
|
|||||||
getDirectoryContents (dirContents);
|
getDirectoryContents (dirContents);
|
||||||
screenOffset = 0;
|
screenOffset = 0;
|
||||||
fileOffset = 0;
|
fileOffset = 0;
|
||||||
}
|
} else if ((held & KEY_R) && (pressed & KEY_X) && (entry->name != ".." && driveWritable(currentDrive))) { // Rename file/folder
|
||||||
|
|
||||||
// Rename file/folder
|
|
||||||
if ((held & KEY_R) && (pressed & KEY_X) && (entry->name != ".." && driveWritable(currentDrive))) {
|
|
||||||
pressed = 0;
|
pressed = 0;
|
||||||
|
|
||||||
std::string newName = kbdGetString(STR_RENAME_TO, -1, entry->name);
|
std::string newName = kbdGetString(STR_RENAME_TO, -1, entry->name);
|
||||||
@ -776,10 +766,7 @@ std::string browseForFile (void) {
|
|||||||
getDirectoryContents(dirContents);
|
getDirectoryContents(dirContents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if ((pressed & KEY_X) && (entry->name != ".." && driveWritable(currentDrive))) { // Delete action
|
||||||
|
|
||||||
// Delete action
|
|
||||||
if ((pressed & KEY_X) && (entry->name != ".." && driveWritable(currentDrive))) {
|
|
||||||
font->clear(false);
|
font->clear(false);
|
||||||
int selections = std::count_if(dirContents.begin(), dirContents.end(), [](const DirEntry &x){ return x.selected; });
|
int selections = std::count_if(dirContents.begin(), dirContents.end(), [](const DirEntry &x){ return x.selected; });
|
||||||
if (entry->selected && selections > 1) {
|
if (entry->selected && selections > 1) {
|
||||||
@ -855,10 +842,7 @@ std::string browseForFile (void) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if ((held & KEY_R) && (pressed & KEY_Y) && driveWritable(currentDrive)) { // Create new folder
|
||||||
|
|
||||||
// Create new folder
|
|
||||||
if ((held & KEY_R) && (pressed & KEY_Y) && driveWritable(currentDrive)) {
|
|
||||||
pressed = 0;
|
pressed = 0;
|
||||||
|
|
||||||
std::string newName = kbdGetString(STR_NAME_FOR_NEW_FOLDER);
|
std::string newName = kbdGetString(STR_NAME_FOR_NEW_FOLDER);
|
||||||
@ -883,10 +867,7 @@ std::string browseForFile (void) {
|
|||||||
getDirectoryContents (dirContents);
|
getDirectoryContents (dirContents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if ((pressed & KEY_L && !(held & KEY_R)) && entry->name != "..") { // Add to selection
|
||||||
|
|
||||||
// Add to selection
|
|
||||||
if ((pressed & KEY_L && !(held & KEY_R)) && entry->name != "..") {
|
|
||||||
bool select = !entry->selected;
|
bool select = !entry->selected;
|
||||||
entry->selected = select;
|
entry->selected = select;
|
||||||
while(held & KEY_L) {
|
while(held & KEY_L) {
|
||||||
@ -941,9 +922,7 @@ std::string browseForFile (void) {
|
|||||||
fileBrowse_drawBottomScreen(entry);
|
fileBrowse_drawBottomScreen(entry);
|
||||||
showDirectoryContents(dirContents, fileOffset, screenOffset);
|
showDirectoryContents(dirContents, fileOffset, screenOffset);
|
||||||
}
|
}
|
||||||
}
|
} else if (pressed & KEY_Y) {
|
||||||
|
|
||||||
if (pressed & KEY_Y) {
|
|
||||||
// Copy
|
// Copy
|
||||||
if (!clipboardOn) {
|
if (!clipboardOn) {
|
||||||
if (entry->name != "..") {
|
if (entry->name != "..") {
|
||||||
@ -965,27 +944,22 @@ std::string browseForFile (void) {
|
|||||||
} else if (driveWritable(currentDrive) && fileBrowse_paste(path)) {
|
} else if (driveWritable(currentDrive) && fileBrowse_paste(path)) {
|
||||||
getDirectoryContents (dirContents);
|
getDirectoryContents (dirContents);
|
||||||
}
|
}
|
||||||
}
|
} else if ((pressed & KEY_SELECT) && !clipboardUsed) {
|
||||||
|
|
||||||
if ((pressed & KEY_SELECT) && !clipboardUsed) {
|
|
||||||
clipboardOn = !clipboardOn;
|
clipboardOn = !clipboardOn;
|
||||||
}
|
} if (pressed & KEY_START) { // START menu
|
||||||
|
|
||||||
// START menu
|
|
||||||
if (pressed & KEY_START) {
|
|
||||||
startMenu();
|
startMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SCREENSWAP
|
#ifdef SCREENSWAP
|
||||||
// Swap screens
|
// Swap screens
|
||||||
if (pressed & KEY_TOUCH) {
|
else if (pressed & KEY_TOUCH) {
|
||||||
screenSwapped = !screenSwapped;
|
screenSwapped = !screenSwapped;
|
||||||
screenSwapped ? lcdMainOnBottom() : lcdMainOnTop();
|
screenSwapped ? lcdMainOnBottom() : lcdMainOnTop();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Make a screenshot
|
// Make a screenshot
|
||||||
if ((held & KEY_R) && (pressed & KEY_L)) {
|
else if ((held & KEY_R) && (pressed & KEY_L)) {
|
||||||
if(screenshot())
|
if(screenshot())
|
||||||
getDirectoryContents(dirContents);
|
getDirectoryContents(dirContents);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,8 @@ STRING(COULD_NOT_ALLOCATE_BUFFER, "Could not allocate buffer")
|
|||||||
STRING(COULD_NOT_OPEN_FILE_READING, "Could not open file for reading")
|
STRING(COULD_NOT_OPEN_FILE_READING, "Could not open file for reading")
|
||||||
STRING(CALCULATING_SHA1, "Calculating SHA1 hash of:\n%s")
|
STRING(CALCULATING_SHA1, "Calculating SHA1 hash of:\n%s")
|
||||||
STRING(N_OF_N_BYTES_PROCESSED, "%d/%d bytes processed")
|
STRING(N_OF_N_BYTES_PROCESSED, "%d/%d bytes processed")
|
||||||
|
STRING(FILE_ALREADY_TRIMMED, "This file is already trimmed.")
|
||||||
|
STRING(TRIM_TO_N_BYTES, "Trim file to %s?")
|
||||||
STRING(RUNNING_X_WITH_N_PARAMETERS, "Running %s with %d parameters")
|
STRING(RUNNING_X_WITH_N_PARAMETERS, "Running %s with %d parameters")
|
||||||
STRING(START_FAILED_ERROR_N, "Start failed. Error %d")
|
STRING(START_FAILED_ERROR_N, "Start failed. Error %d")
|
||||||
STRING(HEADER_TITLE, "Header Title: %s")
|
STRING(HEADER_TITLE, "Header Title: %s")
|
||||||
|
|||||||
@ -30,6 +30,8 @@ COULD_NOT_ALLOCATE_BUFFER=Could not allocate buffer
|
|||||||
COULD_NOT_OPEN_FILE_READING=Could not open file for reading
|
COULD_NOT_OPEN_FILE_READING=Could not open file for reading
|
||||||
CALCULATING_SHA1=Calculating SHA1 hash of:\n%s
|
CALCULATING_SHA1=Calculating SHA1 hash of:\n%s
|
||||||
N_OF_N_BYTES_PROCESSED=%d/%d bytes processed
|
N_OF_N_BYTES_PROCESSED=%d/%d bytes processed
|
||||||
|
FILE_ALREADY_TRIMMED=This file is already trimmed.
|
||||||
|
TRIM_TO_N_BYTES=Trim file to %s?
|
||||||
RUNNING_X_WITH_N_PARAMETERS=Running %s with %d parameters
|
RUNNING_X_WITH_N_PARAMETERS=Running %s with %d parameters
|
||||||
START_FAILED_ERROR_N=Start failed. Error %d
|
START_FAILED_ERROR_N=Start failed. Error %d
|
||||||
HEADER_TITLE=Header Title: %s
|
HEADER_TITLE=Header Title: %s
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user