mirror of
https://github.com/rvtr/GodMode9i.git
synced 2025-11-02 00:11:07 -04:00
Add trimming existing NDS ROMs (#104)
This commit is contained in:
parent
2e83467ab5
commit
d5b96dcb0b
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "date.h"
|
#include "date.h"
|
||||||
#include "file_browse.h"
|
#include "file_browse.h"
|
||||||
|
#include "ndsheaderbanner.h"
|
||||||
|
|
||||||
#define copyBufSize 0x8000
|
#define copyBufSize 0x8000
|
||||||
#define shaChunkSize 0x10000
|
#define shaChunkSize 0x10000
|
||||||
@ -102,6 +103,26 @@ 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 = (isDSiMode() && (ndsCardHeader.unitCode != 0) && (ndsCardHeader.twlRomSize > 0))
|
||||||
|
? ndsCardHeader.twlRomSize : ndsCardHeader.romSize + 0x88;
|
||||||
|
|
||||||
|
truncate(fileName, romSize);
|
||||||
|
|
||||||
|
return romSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void dirCopy(DirEntry* entry, int i, const char *destinationPath, const char *sourcePath) {
|
void dirCopy(DirEntry* entry, int i, const char *destinationPath, const char *sourcePath) {
|
||||||
std::vector<DirEntry> dirContents;
|
std::vector<DirEntry> dirContents;
|
||||||
dirContents.clear();
|
dirContents.clear();
|
||||||
|
|||||||
@ -24,6 +24,7 @@ extern void printBytesAlign(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(DirEntry* entry);
|
void changeFileAttribs(DirEntry* entry);
|
||||||
|
|
||||||
|
|||||||
@ -228,6 +228,8 @@ FileOperation fileBrowse_A(DirEntry* entry, char path[PATH_MAX]) {
|
|||||||
printf(" Mount NitroFS\n");
|
printf(" Mount NitroFS\n");
|
||||||
assignedOp[++maxCursors] = FileOperation::ndsInfo;
|
assignedOp[++maxCursors] = FileOperation::ndsInfo;
|
||||||
printf(" Show NDS file info\n");
|
printf(" Show NDS file info\n");
|
||||||
|
assignedOp[++maxCursors] = FileOperation::trimNds;
|
||||||
|
printf(" Trim NDS file\n");
|
||||||
}
|
}
|
||||||
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"}))
|
||||||
{
|
{
|
||||||
@ -382,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;
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user