Merge remote-tracking branch 'upstream/master' into bitmap-mode-and-cleanup

This commit is contained in:
Pk11 2021-08-08 07:35:15 -05:00
commit 974cfcca11
4 changed files with 30 additions and 1 deletions

View File

@ -8,6 +8,7 @@
#include "date.h" #include "date.h"
#include "file_browse.h" #include "file_browse.h"
#include "font.h" #include "font.h"
#include "ndsheaderbanner.h"
#define copyBufSize 0x8000 #define copyBufSize 0x8000
#define shaChunkSize 0x10000 #define shaChunkSize 0x10000
@ -105,6 +106,25 @@ bool calculateSHA1(const char *fileName, u8 *sha1) {
return true; return true;
} }
int trimNds(const char *fileName) {
FILE *file = fopen(fileName, "rb");
if(file) {
sNDSHeaderExt ndsCardHeader;
fread(&ndsCardHeader, 1, sizeof(ndsCardHeader), file);
fclose(file);
u32 romSize = ((ndsCardHeader.unitCode != 0) && (ndsCardHeader.twlRomSize > 0))
? ndsCardHeader.twlRomSize : ndsCardHeader.romSize + 0x88;
truncate(fileName, romSize);
return romSize;
}
return -1;
}
void dirCopy(const DirEntry &entry, int i, const char *destinationPath, const char *sourcePath) { void dirCopy(const DirEntry &entry, int i, const char *destinationPath, const char *sourcePath) {
std::vector<DirEntry> dirContents; std::vector<DirEntry> dirContents;
dirContents.clear(); dirContents.clear();

View File

@ -23,6 +23,7 @@ extern std::string getBytes(int bytes);
extern off_t getFileSize(const char *fileName); extern off_t getFileSize(const char *fileName);
extern bool calculateSHA1(const char *fileName, u8 *sha1); extern bool calculateSHA1(const char *fileName, u8 *sha1);
extern int trimNds(const char *fileName);
extern int fcopy(const char *sourcePath, const char *destinationPath); extern int fcopy(const char *sourcePath, const char *destinationPath);
void changeFileAttribs(const DirEntry *entry); void changeFileAttribs(const DirEntry *entry);

View File

@ -191,6 +191,7 @@ FileOperation fileBrowse_A(DirEntry* entry, char path[PATH_MAX]) {
if(extension(entry->name, {"nds", "dsi", "ids", "app"})) { if(extension(entry->name, {"nds", "dsi", "ids", "app"})) {
operations.push_back(FileOperation::mountNitroFS); operations.push_back(FileOperation::mountNitroFS);
operations.push_back(FileOperation::ndsInfo); operations.push_back(FileOperation::ndsInfo);
operations.push_back(FileOperation::trimNds);
} else if(extension(entry->name, {"sav", "sav1", "sav2", "sav3", "sav4", "sav5", "sav6", "sav7", "sav8", "sav9"})) { } else if(extension(entry->name, {"sav", "sav1", "sav2", "sav3", "sav4", "sav5", "sav6", "sav7", "sav8", "sav9"})) {
operations.push_back(FileOperation::restoreSave); operations.push_back(FileOperation::restoreSave);
} else if(extension(entry->name, {"img", "sd"})) { } else if(extension(entry->name, {"img", "sd"})) {
@ -236,6 +237,9 @@ FileOperation fileBrowse_A(DirEntry* entry, char path[PATH_MAX]) {
case FileOperation::ndsInfo: case FileOperation::ndsInfo:
font->print(3, row++, false, "Show NDS file info"); font->print(3, row++, false, "Show NDS file info");
break; break;
case FileOperation::trimNds:
font->print(3, row++, false, "Trim NDS file");
break;
case FileOperation::restoreSave: case FileOperation::restoreSave:
font->print(3, row++, false, "Restore save"); font->print(3, row++, false, "Restore save");
break; break;
@ -380,6 +384,9 @@ FileOperation fileBrowse_A(DirEntry* entry, char path[PATH_MAX]) {
} case FileOperation::ndsInfo: { } case FileOperation::ndsInfo: {
ndsInfo(entry->name.c_str()); ndsInfo(entry->name.c_str());
break; break;
} case FileOperation::trimNds: {
entry->size = trimNds(entry->name.c_str());
break;
} case FileOperation::showInfo: { } case FileOperation::showInfo: {
changeFileAttribs(entry); changeFileAttribs(entry);
break; break;

View File

@ -38,6 +38,8 @@ enum class FileOperation {
bootFile, bootFile,
bootstrapFile, bootstrapFile,
mountNitroFS, mountNitroFS,
ndsInfo,
trimNds,
mountImg, mountImg,
restoreSave, restoreSave,
showInfo, showInfo,
@ -45,7 +47,6 @@ enum class FileOperation {
copyFatOut, copyFatOut,
calculateSHA1, calculateSHA1,
hexEdit, hexEdit,
ndsInfo,
}; };
bool extension(const std::string &filename, const std::vector<std::string> &extensions); bool extension(const std::string &filename, const std::vector<std::string> &extensions);