Skip to content
This repository has been archived by the owner on Apr 5, 2021. It is now read-only.

Fix self updating #35

Merged
merged 1 commit into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions source/cia.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
#include "cia.h"

extern bool updatingSelf;


static Result CIA_LaunchTitle(u64 titleId, FS_MediaType mediaType) {
Result ret = 0;
u8 param[0x300];
u8 hmac[0x20];

if (R_FAILED(ret = APT_PrepareToDoApplicationJump(0, titleId, mediaType))) {
printf("Error In:\nAPT_PrepareToDoApplicationJump");
return ret;
}
if (R_FAILED(ret = APT_DoApplicationJump(param, sizeof(param), hmac))) {
printf("Error In:\nAPT_DoApplicationJump");
return ret;
}

return 0;
}

Result deletePrevious(u64 titleid, FS_MediaType media)
{
Result ret = 0;
Expand Down Expand Up @@ -71,9 +91,11 @@ Result installCia(const char * ciaPath)

media = getTitleDestination(info.titleID);

ret = deletePrevious(info.titleID, media);
if (R_FAILED(ret))
return ret;
if(!updatingSelf) {
ret = deletePrevious(info.titleID, media);
if (R_FAILED(ret))
return ret;
}

ret = FSFILE_GetSize(fileHandle, &size);
if (R_FAILED(ret)) {
Expand Down Expand Up @@ -105,6 +127,11 @@ Result installCia(const char * ciaPath)
printf("Error in:\nFSFILE_Close\n");
return ret;
}

if (updatingSelf) {
if (R_FAILED(ret = CIA_LaunchTitle(info.titleID, MEDIATYPE_SD)))
return ret;
}

return 0;
}
6 changes: 4 additions & 2 deletions source/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,8 @@ void updateSelf(bool nightly) {
}

displayBottomMsg("Installing TWiLight Menu++ Updater CIA...\n"
"(Nightly)");
"(Nightly)\n\n\n\n\n\n\n\n\n\n"
"The app will reboot when done.");
installCia("/TWiLightMenu-Updater-nightly.cia");

deleteFile("sdmc:/TWiLightMenu-Updater-nightly.cia");
Expand All @@ -739,7 +740,8 @@ void updateSelf(bool nightly) {
}

displayBottomMsg("Installing TWiLight Menu++ Updater CIA...\n"
"(Release)");
"(Release)\n\n\n\n\n\n\n\n\n\n"
"The app will reboot when done.");
installCia("/TWiLightMenu-Updater-release.cia");

deleteFile("sdmc:/TWiLightMenu-Updater-release.cia");
Expand Down
5 changes: 5 additions & 0 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
static touchPosition touch;

bool dspfirmfound = false;
bool updatingSelf = false;
static bool musicPlaying = false;

// Music and sound effects.
Expand Down Expand Up @@ -490,7 +491,9 @@ int main()
sfx_select->stop();
sfx_select->play();
}
updatingSelf = true;
updateSelf(false);
updatingSelf = false;
} else {
if(dspfirmfound) {
sfx_wrong->stop();
Expand All @@ -504,7 +507,9 @@ int main()
sfx_select->stop();
sfx_select->play();
}
updatingSelf = true;
updateSelf(true);
updatingSelf = false;
} else {
if(dspfirmfound) {
sfx_wrong->stop();
Expand Down