diff --git a/source/cia.c b/source/cia.c index 727688c..8c76590 100644 --- a/source/cia.c +++ b/source/cia.c @@ -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; @@ -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)) { @@ -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; } diff --git a/source/download.cpp b/source/download.cpp index 5997cd1..c50745a 100755 --- a/source/download.cpp +++ b/source/download.cpp @@ -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"); @@ -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"); diff --git a/source/main.cpp b/source/main.cpp index f59e5e2..9de56fb 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -20,6 +20,7 @@ static touchPosition touch; bool dspfirmfound = false; +bool updatingSelf = false; static bool musicPlaying = false; // Music and sound effects. @@ -490,7 +491,9 @@ int main() sfx_select->stop(); sfx_select->play(); } + updatingSelf = true; updateSelf(false); + updatingSelf = false; } else { if(dspfirmfound) { sfx_wrong->stop(); @@ -504,7 +507,9 @@ int main() sfx_select->stop(); sfx_select->play(); } + updatingSelf = true; updateSelf(true); + updatingSelf = false; } else { if(dspfirmfound) { sfx_wrong->stop();