From bc177f49982e128d89fee03d9ab8ae7ac92a5cd8 Mon Sep 17 00:00:00 2001 From: w3irDv <170813473+w3irDv@users.noreply.github.com> Date: Sun, 26 May 2024 13:07:57 +0200 Subject: [PATCH 1/2] fix shared content installation flow --- source/wad/wad.cpp | 14 ++++++++++++-- source/wad/wad.h | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/source/wad/wad.cpp b/source/wad/wad.cpp index 06a1ed96..92343894 100644 --- a/source/wad/wad.cpp +++ b/source/wad/wad.cpp @@ -322,7 +322,7 @@ bool Wad::InstallContents(const char *installpath) // Install content if(content->type == 0x8001) { // shared content - int result = CheckContentMap(installpath, content, filepath); + int result = UpdateContentMap(installpath, content, filepath); if(result == 1) // exists already, skip file continue; @@ -448,6 +448,16 @@ int Wad::CheckContentMap(const char *installpath, tmd_content *content, char *fi return 1; // content exists already } + // Content does not exists + return 0; +} + +int Wad::UpdateContentMap(const char *installpath, tmd_content *content, char *filepath) +{ + int result = CheckContentMap(installpath,content,filepath); + if ( result != 0 ) + return result; // content already exists or error + // Content does not exists, append it. u32 next_entry = content_map_size; u8 *tmp = (u8 *) realloc(content_map, (next_entry + 1) * sizeof(map_entry_t)); @@ -461,7 +471,7 @@ int Wad::CheckContentMap(const char *installpath, tmd_content *content, char *fi content_map = tmp; content_map_size++; - map = (map_entry_t *) content_map; + map_entry_t *map = (map_entry_t *) content_map; char name[9]; sprintf(name, "%08x", (unsigned int)next_entry); memcpy(map[next_entry].name, name, 8); diff --git a/source/wad/wad.h b/source/wad/wad.h index dab23006..740efa51 100644 --- a/source/wad/wad.h +++ b/source/wad/wad.h @@ -49,6 +49,7 @@ public: private: bool InstallContents(const char *installpath); int CheckContentMap(const char *installpath, tmd_content *content, char *filepath); + int UpdateContentMap(const char *installpath, tmd_content *content, char *filepath); bool WriteFile(const char *filepath, u8 *buffer, u32 len); bool SetTitleUID(const char *intallpath, const u64 &tid); From 2d8980ed7ed1f80e5e9e5db9af0eaa37857118bb Mon Sep 17 00:00:00 2001 From: w3irDv <170813473+w3irDv@users.noreply.github.com> Date: Sun, 26 May 2024 18:59:29 +0200 Subject: [PATCH 2/2] defer updating content.map until shared content is succesfully installed --- source/wad/wad.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/source/wad/wad.cpp b/source/wad/wad.cpp index 92343894..19c7ba81 100644 --- a/source/wad/wad.cpp +++ b/source/wad/wad.cpp @@ -322,13 +322,14 @@ bool Wad::InstallContents(const char *installpath) // Install content if(content->type == 0x8001) { // shared content - int result = UpdateContentMap(installpath, content, filepath); + int result = CheckContentMap(installpath, content, filepath); if(result == 1) // exists already, skip file continue; else if(result < 0) // failure return false; // else it does not exist...install it + snprintf(filepath, sizeof(filepath), "%s/shared1/%08x.app", installpath, (unsigned int)content_map_size); } else { // private content @@ -419,6 +420,16 @@ bool Wad::InstallContents(const char *installpath) ShowError(tr("File read/write error.")); return false; } + + if(content->type == 0x8001) { + // shared content installed ok. It's time to update content.map + int result = UpdateContentMap(installpath, content, filepath); + if(result == 1) // exists already, skip file + continue; + + else if(result < 0) // failure + return false; + } } return true; @@ -482,8 +493,6 @@ int Wad::UpdateContentMap(const char *installpath, tmd_content *content, char *f if(!WriteFile(filepath, content_map, content_map_size * sizeof(map_entry_t))) return -1; - snprintf(filepath, 1024, "%s/shared1/%08x.app", installpath, (unsigned int)next_entry); - return 0; }