Simplified TAR code

This commit is contained in:
d0k3 2017-11-17 16:25:30 +01:00
parent 20d2772056
commit 45b7a75af0
5 changed files with 13 additions and 13 deletions

View File

@ -123,7 +123,7 @@ u32 LoadKeyDb(const char* path_db, AesKeyInfo* keydb, u32 bsize) {
} else { } else {
// check for hardcoded key database // check for hardcoded key database
u64 aeskeydb_bin_size = 0; u64 aeskeydb_bin_size = 0;
void* aeskeydb_bin = FindVTarFileInfo(VRAM0_AESKEY_DB, &aeskeydb_bin_size, NULL); void* aeskeydb_bin = FindVTarFileInfo(VRAM0_AESKEY_DB, &aeskeydb_bin_size);
fsize = (aeskeydb_bin_size <= bsize) ? aeskeydb_bin_size : 0; fsize = (aeskeydb_bin_size <= bsize) ? aeskeydb_bin_size : 0;
if (fsize) memcpy(keydb, aeskeydb_bin, aeskeydb_bin_size); if (fsize) memcpy(keydb, aeskeydb_bin, aeskeydb_bin_size);

View File

@ -1589,7 +1589,7 @@ u32 HomeMoreMenu(char* current_path) {
int hsrestore = ((CheckHealthAndSafetyInject("1:") == 0) || (CheckHealthAndSafetyInject("4:") == 0)) ? (int) ++n_opt : -1; int hsrestore = ((CheckHealthAndSafetyInject("1:") == 0) || (CheckHealthAndSafetyInject("4:") == 0)) ? (int) ++n_opt : -1;
int clock = ++n_opt; int clock = ++n_opt;
int sysinfo = ++n_opt; int sysinfo = ++n_opt;
int readme = (FindVTarFileInfo(VRAM0_README_MD, NULL, NULL)) ? (int) ++n_opt : -1; int readme = (FindVTarFileInfo(VRAM0_README_MD, NULL)) ? (int) ++n_opt : -1;
if (sdformat > 0) optionstr[sdformat - 1] = "SD format menu"; if (sdformat > 0) optionstr[sdformat - 1] = "SD format menu";
if (bonus > 0) optionstr[bonus - 1] = "Bonus drive setup"; if (bonus > 0) optionstr[bonus - 1] = "Bonus drive setup";
@ -1704,7 +1704,7 @@ u32 HomeMoreMenu(char* current_path) {
} }
else if (user_select == readme) { // Display GodMode9 readme else if (user_select == readme) { // Display GodMode9 readme
u64 README_md_size; u64 README_md_size;
char* README_md = FindVTarFileInfo(VRAM0_README_MD, &README_md_size, NULL); char* README_md = FindVTarFileInfo(VRAM0_README_MD, &README_md_size);
MemToCViewer(README_md, README_md_size, "GodMode9 ReadMe Table of Contents"); MemToCViewer(README_md, README_md_size, "GodMode9 ReadMe Table of Contents");
return 0; return 0;
} else return 1; } else return 1;
@ -1713,7 +1713,7 @@ u32 HomeMoreMenu(char* current_path) {
} }
u32 SplashInit(const char* modestr) { u32 SplashInit(const char* modestr) {
void* splash = FindVTarFileInfo(VRAM0_SPLASH_QLZ, NULL, NULL); void* splash = FindVTarFileInfo(VRAM0_SPLASH_QLZ, NULL);
const char* namestr = FLAVOR " " VERSION; const char* namestr = FLAVOR " " VERSION;
const char* loadstr = "booting..."; const char* loadstr = "booting...";
const u32 pos_xb = 10; const u32 pos_xb = 10;
@ -1723,7 +1723,7 @@ u32 SplashInit(const char* modestr) {
ClearScreenF(true, true, COLOR_STD_BG); ClearScreenF(true, true, COLOR_STD_BG);
if (splash) QlzDecompress(TOP_SCREEN, splash, 0); if (splash) QlzDecompress(TOP_SCREEN, splash, 0);
else DrawStringF(TOP_SCREEN, 10, 10, COLOR_STD_FONT, COLOR_TRANSPARENT, "(splash not found)"); else DrawStringF(TOP_SCREEN, 10, 10, COLOR_STD_FONT, COLOR_TRANSPARENT, "(" VRAM0_SPLASH_QLZ " not found)");
if (modestr) DrawStringF(TOP_SCREEN, SCREEN_WIDTH_TOP - 10 - GetDrawStringWidth(modestr), if (modestr) DrawStringF(TOP_SCREEN, SCREEN_WIDTH_TOP - 10 - GetDrawStringWidth(modestr),
SCREEN_HEIGHT - 10 - GetDrawStringHeight(modestr), COLOR_STD_FONT, COLOR_TRANSPARENT, modestr); SCREEN_HEIGHT - 10 - GetDrawStringHeight(modestr), COLOR_STD_FONT, COLOR_TRANSPARENT, modestr);
@ -2309,7 +2309,7 @@ u32 ScriptRunner(int entrypoint) {
// get script from VRAM0 TAR // get script from VRAM0 TAR
u64 autorun_gm9_size = 0; u64 autorun_gm9_size = 0;
void* autorun_gm9 = FindVTarFileInfo(VRAM0_AUTORUN_GM9, &autorun_gm9_size, NULL); void* autorun_gm9 = FindVTarFileInfo(VRAM0_AUTORUN_GM9, &autorun_gm9_size);
if (autorun_gm9 && autorun_gm9_size) { if (autorun_gm9 && autorun_gm9_size) {
// copy script to script buffer and run it // copy script to script buffer and run it

View File

@ -32,7 +32,7 @@ u32 ValidateTarHeader(void* tardata, void* tardata_end) {
return 1; return 1;
// type can only be standard file or dir // type can only be standard file or dir
if ((tar->ftype != '0') && (tar->ftype != '5')) if (tar->ftype && (tar->ftype != '0') && (tar->ftype != '5'))
return 1; return 1;
// checksum // checksum
@ -70,13 +70,13 @@ void* NextTarEntry(void* tardata, void* tardata_end) {
return data; return data;
} }
void* FindTarFileInfo(void* tardata, void* tardata_end, const char* fname, u64* fsize, bool* is_dir) { void* FindTarFileInfo(void* tardata, void* tardata_end, const char* fname, u64* fsize) {
while (tardata && (tardata < tardata_end)) { while (tardata && (tardata < tardata_end)) {
TarHeader* tar = tardata; TarHeader* tar = tardata;
if (ValidateTarHeader(tardata, tardata_end) != 0) break; if (ValidateTarHeader(tardata, tardata_end) != 0) break;
if ((strncasecmp(tar->fname, fname, 100) == 0) && (tar->ftype == '0')) if ((strncasecmp(tar->fname, fname, 100) == 0) && (!tar->ftype || (tar->ftype == '0')))
return GetTarFileInfo(tardata, NULL, fsize, is_dir); return GetTarFileInfo(tardata, NULL, fsize, NULL);
tardata = ((u8*) tardata) + sizeof(TarHeader) + align(ReadAsciiOctal(tar->fsize, 12), 512); tardata = ((u8*) tardata) + sizeof(TarHeader) + align(ReadAsciiOctal(tar->fsize, 12), 512);
} }

View File

@ -32,4 +32,4 @@ typedef struct {
u32 ValidateTarHeader(void* tardata, void* tardata_end); u32 ValidateTarHeader(void* tardata, void* tardata_end);
void* GetTarFileInfo(void* tardata, char* fname, u64* fsize, bool* is_dir); void* GetTarFileInfo(void* tardata, char* fname, u64* fsize, bool* is_dir);
void* NextTarEntry(void* tardata, void* tardata_end); void* NextTarEntry(void* tardata, void* tardata_end);
void* FindTarFileInfo(void* tardata, void* tardata_end, const char* fname, u64* fsize, bool* is_dir); void* FindTarFileInfo(void* tardata, void* tardata_end, const char* fname, u64* fsize);

View File

@ -34,5 +34,5 @@
#define GetVTarFileInfo(tardata, fname, fsize, is_dir) \ #define GetVTarFileInfo(tardata, fname, fsize, is_dir) \
GetTarFileInfo(tardata, fname, fsize, is_dir) GetTarFileInfo(tardata, fname, fsize, is_dir)
#define FindVTarFileInfo(fname, fsize, is_dir) \ #define FindVTarFileInfo(fname, fsize) \
FindTarFileInfo(TARDATA, TARDATA_END, fname, fsize, is_dir) FindTarFileInfo(TARDATA, TARDATA_END, fname, fsize)