2019-10-23 00:14:37 +02:00
# include <cstring>
# include <sstream>
2019-10-26 03:00:13 +02:00
# include <filesystem>
2019-10-30 02:58:53 +01:00
2019-10-23 00:14:37 +02:00
# include "install/install_nsp.hpp"
# include "nx/fs.hpp"
# include "util/file_util.hpp"
# include "util/title_util.hpp"
# include "util/error.hpp"
# include "ui/MainApplication.hpp"
2019-10-30 02:58:53 +01:00
# include "nspInstall.hpp"
2019-10-29 00:47:49 +01:00
# include "util/config.hpp"
# include "util/util.hpp"
2019-10-23 00:14:37 +02:00
namespace inst : : ui {
extern MainApplication * mainApp ;
2019-10-27 04:36:45 +01:00
void setTopInstInfoText ( std : : string ourText ) {
2019-10-24 21:53:54 +02:00
mainApp - > instpage - > pageInfoText - > SetText ( ourText ) ;
2019-10-23 00:14:37 +02:00
mainApp - > CallForRender ( ) ;
}
2019-10-27 04:36:45 +01:00
void setInstInfoText ( std : : string ourText ) {
mainApp - > instpage - > installInfoText - > SetText ( ourText ) ;
mainApp - > CallForRender ( ) ;
}
2019-10-25 03:33:41 +02:00
void setInstBarPerc ( double ourPercent ) {
mainApp - > instpage - > installBar - > SetVisible ( true ) ;
mainApp - > instpage - > installBar - > SetProgress ( ourPercent ) ;
mainApp - > CallForRender ( ) ;
}
2019-10-23 00:14:37 +02:00
void loadMainMenu ( ) {
mainApp - > LoadLayout ( mainApp - > mainPage ) ;
}
2019-10-24 21:53:54 +02:00
void loadInstallScreen ( ) {
mainApp - > instpage - > pageInfoText - > SetText ( " " ) ;
2019-10-27 04:36:45 +01:00
mainApp - > instpage - > installInfoText - > SetText ( " " ) ;
2019-10-25 03:33:41 +02:00
mainApp - > instpage - > installBar - > SetProgress ( 0 ) ;
mainApp - > instpage - > installBar - > SetVisible ( false ) ;
2019-10-31 16:56:16 +01:00
if ( inst : : config : : gayMode ) mainApp - > instpage - > awooImage - > SetVisible ( false ) ;
else mainApp - > instpage - > awooImage - > SetVisible ( true ) ;
2019-10-24 21:53:54 +02:00
mainApp - > LoadLayout ( mainApp - > instpage ) ;
mainApp - > CallForRender ( ) ;
}
2019-10-23 00:14:37 +02:00
}
namespace nspInstStuff {
FsStorageId m_destStorageId = FsStorageId_SdCard ;
2019-10-24 21:53:54 +02:00
void installNspFromFile ( std : : string ourNsp , int whereToInstall )
2019-10-23 00:14:37 +02:00
{
2019-10-26 03:00:13 +02:00
appletLockExit ( ) ;
2019-10-24 21:53:54 +02:00
inst : : ui : : loadInstallScreen ( ) ;
2019-10-23 00:14:37 +02:00
std : : vector < std : : string > installList ;
2019-10-26 03:00:13 +02:00
bool nspInstalled = false ;
2019-10-23 00:14:37 +02:00
installList . push_back ( ourNsp ) ;
2019-10-23 03:33:13 +02:00
if ( whereToInstall ) m_destStorageId = FsStorageId_NandUser ;
2019-10-23 00:14:37 +02:00
for ( unsigned int i = 0 ; i < installList . size ( ) ; i + + )
{
std : : string path = " @Sdcard:// " + installList [ i ] ;
try
{
2019-10-27 04:36:45 +01:00
inst : : ui : : setTopInstInfoText ( " Installing " + ourNsp + " ... " ) ;
2019-10-23 00:14:37 +02:00
nx : : fs : : IFileSystem fileSystem ;
fileSystem . OpenFileSystemWithId ( path , FsFileSystemType_ApplicationPackage , 0 ) ;
tin : : install : : nsp : : SimpleFileSystem simpleFS ( fileSystem , " / " , path + " / " ) ;
2019-10-26 07:58:32 +02:00
tin : : install : : nsp : : NSPInstallTask task ( simpleFS , m_destStorageId , inst : : config : : ignoreReqVers ) ;
2019-10-23 00:14:37 +02:00
2019-10-31 16:56:16 +01:00
printf ( " Preparing installation \n " ) ;
2019-10-24 21:53:54 +02:00
inst : : ui : : setInstInfoText ( " Preparing installation... " ) ;
2019-10-23 00:14:37 +02:00
task . Prepare ( ) ;
task . Begin ( ) ;
2019-10-26 03:00:13 +02:00
nspInstalled = true ;
2019-10-23 00:14:37 +02:00
}
catch ( std : : exception & e )
{
printf ( " Failed to install NSP " ) ;
printf ( " %s " , e . what ( ) ) ;
fprintf ( stdout , " %s " , e . what ( ) ) ;
2019-10-29 00:47:49 +01:00
inst : : ui : : mainApp - > CreateShowDialog ( " Failed to install NSP! " , " Partially installed NSP contents can be removed from the System Settings applet. \n \n " + ( std : : string ) e . what ( ) , { " OK " } , true ) ;
2019-10-23 00:14:37 +02:00
}
}
2019-10-29 00:47:49 +01:00
if ( nspInstalled ) if ( inst : : ui : : mainApp - > CreateShowDialog ( inst : : util : : shortenString ( ourNsp , 64 , true ) + " installed! Delete NSP from SD card? " , " " , { " No " , " Yes " } , false ) = = 1 ) std : : filesystem : : remove ( " sdmc:/ " + ourNsp ) ;
2019-10-26 03:00:13 +02:00
2019-10-23 00:14:37 +02:00
printf ( " Done " ) ;
2019-10-26 03:00:13 +02:00
appletUnlockExit ( ) ;
2019-10-23 03:33:13 +02:00
inst : : ui : : loadMainMenu ( ) ;
2019-10-24 21:53:54 +02:00
return ;
2019-10-23 00:14:37 +02:00
}
}