2019-10-18 19:01:51 +00:00
# include <filesystem>
# include "ui/MainApplication.hpp"
# include "ui/mainPage.hpp"
# include "ui/netInstPage.hpp"
2019-10-25 01:33:41 +00:00
# include "util/util.hpp"
2019-10-18 19:01:51 +00:00
# include "netInstall.hpp"
# define COLOR(hex) pu::ui::Color::FromHex(hex)
namespace inst : : ui {
extern MainApplication * mainApp ;
std : : vector < std : : string > ourUrls ;
netInstPage : : netInstPage ( ) : Layout : : Layout ( ) {
this - > SetBackgroundColor ( COLOR ( " #670000FF " ) ) ;
2019-10-27 03:36:45 +00:00
this - > SetBackgroundImage ( " romfs:/background.jpg " ) ;
this - > topRect = Rectangle : : New ( 0 , 0 , 1280 , 93 , COLOR ( " #170909FF " ) ) ;
this - > infoRect = Rectangle : : New ( 0 , 93 , 1280 , 60 , COLOR ( " #17090980 " ) ) ;
this - > botRect = Rectangle : : New ( 0 , 660 , 1280 , 60 , COLOR ( " #17090980 " ) ) ;
this - > titleImage = Image : : New ( 0 , 0 , " romfs:/logo.png " ) ;
this - > pageInfoText = TextBlock : : New ( 10 , 109 , " " , 30 ) ;
2019-10-18 19:01:51 +00:00
this - > pageInfoText - > SetColor ( COLOR ( " #FFFFFFFF " ) ) ;
2019-10-29 01:00:50 +00:00
this - > butText = TextBlock : : New ( 10 , 678 , " " , 24 ) ;
2019-10-27 03:36:45 +00:00
this - > butText - > SetColor ( COLOR ( " #FFFFFFFF " ) ) ;
this - > menu = pu : : ui : : elm : : Menu : : New ( 0 , 153 , 1280 , COLOR ( " #FFFFFF00 " ) , 84 , ( 506 / 84 ) ) ;
2019-10-23 01:33:13 +00:00
this - > menu - > SetOnFocusColor ( COLOR ( " #00000033 " ) ) ;
2019-10-27 03:36:45 +00:00
this - > menu - > SetScrollbarColor ( COLOR ( " #17090980 " ) ) ;
this - > Add ( this - > topRect ) ;
this - > Add ( this - > infoRect ) ;
this - > Add ( this - > botRect ) ;
this - > Add ( this - > titleImage ) ;
this - > Add ( this - > butText ) ;
2019-10-18 19:01:51 +00:00
this - > Add ( this - > pageInfoText ) ;
2019-10-23 01:33:13 +00:00
this - > Add ( this - > menu ) ;
2019-10-18 19:01:51 +00:00
}
2019-10-23 01:33:13 +00:00
void netInstPage : : startNetwork ( ) {
2019-10-24 19:53:54 +00:00
this - > pageInfoText - > SetText ( " " ) ;
2019-10-29 01:00:50 +00:00
this - > butText - > SetText ( " \ue0e1 Cancel \ue0e3 Install From URL " ) ;
2019-10-23 01:33:13 +00:00
this - > menu - > SetVisible ( false ) ;
this - > menu - > ClearItems ( ) ;
2019-10-21 01:10:27 +00:00
mainApp - > LoadLayout ( mainApp - > netinstPage ) ;
ourUrls = netInstStuff : : OnSelected ( ) ;
2019-10-23 01:33:13 +00:00
if ( ! ourUrls . size ( ) ) {
2019-10-24 19:53:54 +00:00
mainApp - > LoadLayout ( mainApp - > mainPage ) ;
2019-10-21 01:10:27 +00:00
return ;
2019-10-26 21:00:55 +00:00
} else if ( ourUrls [ 0 ] = = " supplyUrl " ) {
Result rc = 0 ;
SwkbdConfig kbd ;
char tmpoutstr [ 128 ] = { 0 } ;
rc = swkbdCreate ( & kbd , 0 ) ;
if ( R_SUCCEEDED ( rc ) ) {
swkbdConfigMakePresetDefault ( & kbd ) ;
2019-10-27 03:36:45 +00:00
swkbdConfigSetGuideText ( & kbd , " Enter the location of a NSP! URL must be HTTP. " ) ;
2019-10-26 21:00:55 +00:00
swkbdConfigSetInitialText ( & kbd , " http:// " ) ;
rc = swkbdShow ( & kbd , tmpoutstr , sizeof ( tmpoutstr ) ) ;
swkbdClose ( & kbd ) ;
2019-10-27 03:36:45 +00:00
if ( R_SUCCEEDED ( rc ) & & tmpoutstr [ 0 ] ! = 0 ) {
2019-10-26 21:00:55 +00:00
ourUrls [ 0 ] = tmpoutstr ;
2019-10-27 03:36:45 +00:00
netInstPage : : startInstall ( true ) ;
2019-10-26 21:00:55 +00:00
return ;
} else {
mainApp - > LoadLayout ( mainApp - > mainPage ) ;
return ;
2019-10-27 21:16:42 +00:00
}
2019-10-26 21:00:55 +00:00
}
2019-10-23 01:33:13 +00:00
} else {
2019-10-27 03:36:45 +00:00
this - > pageInfoText - > SetText ( " Select a NSP to install! " ) ;
2019-10-29 01:00:50 +00:00
this - > butText - > SetText ( " \ue0e0 Install NSP \ue0e1 Cancel " ) ;
2019-10-23 01:33:13 +00:00
for ( auto & url : ourUrls ) {
2019-10-28 23:47:49 +00:00
pu : : String itm = inst : : util : : shortenString ( inst : : util : : formatUrlString ( url ) , 64 , true ) ;
2019-10-23 01:33:13 +00:00
auto ourEntry = pu : : ui : : elm : : MenuItem : : New ( itm ) ;
ourEntry - > SetColor ( COLOR ( " #FFFFFFFF " ) ) ;
2019-10-27 03:36:45 +00:00
ourEntry - > SetIcon ( " romfs:/package-down.png " ) ;
2019-10-23 01:33:13 +00:00
this - > menu - > AddItem ( ourEntry ) ;
}
2019-10-21 01:10:27 +00:00
}
2019-10-23 01:33:13 +00:00
this - > menu - > SetVisible ( true ) ;
return ;
}
2019-10-27 03:36:45 +00:00
void netInstPage : : startInstall ( bool urlMode ) {
2019-10-23 01:33:13 +00:00
std : : string ourUrl = ourUrls [ this - > menu - > GetSelectedIndex ( ) ] ;
2019-10-28 23:47:49 +00:00
int dialogResult = mainApp - > CreateShowDialog ( " Where should " + inst : : util : : shortenString ( inst : : util : : formatUrlString ( ourUrl ) , 64 , true ) + " be installed to? " , " Press B to cancel " , { " SD Card " , " Internal Storage " } , false ) ;
2019-10-27 03:36:45 +00:00
if ( dialogResult = = - 1 & & ! urlMode ) return ;
else if ( dialogResult = = - 1 & & urlMode ) {
mainApp - > LoadLayout ( mainApp - > mainPage ) ;
return ;
}
2019-10-24 19:53:54 +00:00
netInstStuff : : installNspLan ( ourUrl , dialogResult ) ;
2019-10-21 01:10:27 +00:00
return ;
}
2019-10-18 19:01:51 +00:00
void netInstPage : : onInput ( u64 Down , u64 Up , u64 Held , pu : : ui : : Touch Pos ) {
if ( Down & KEY_B ) {
mainApp - > LoadLayout ( mainApp - > mainPage ) ;
}
2019-10-23 01:33:13 +00:00
if ( Down & KEY_A ) {
2019-10-27 03:36:45 +00:00
if ( this - > menu - > IsVisible ( ) ) startInstall ( false ) ;
2019-10-23 01:33:13 +00:00
}
2019-10-18 19:01:51 +00:00
}
}