@@ -30,7 +30,7 @@ bool setsysInternetTimeSyncIsOn() {
3030 }
3131
3232 bool internetTimeSyncIsOn ;
33- rs = setsysGetFlag ( 60 , & internetTimeSyncIsOn );
33+ rs = setsysIsUserSystemClockAutomaticCorrectionEnabled ( & internetTimeSyncIsOn );
3434 setsysExit ();
3535 if (R_FAILED (rs )) {
3636 printf ("Unable to detect if Internet time sync is enabled, %x\n" , rs );
@@ -40,6 +40,40 @@ bool setsysInternetTimeSyncIsOn() {
4040 return internetTimeSyncIsOn ;
4141}
4242
43+ Result enableSetsysInternetTimeSync () {
44+ Result rs = setsysInitialize ();
45+ if (R_FAILED (rs )) {
46+ printf ("setsysInitialize failed, %x\n" , rs );
47+ return rs ;
48+ }
49+
50+ rs = setsysSetUserSystemClockAutomaticCorrectionEnabled (true);
51+ setsysExit ();
52+ if (R_FAILED (rs )) {
53+ printf ("Unable to enable Internet time sync: %x\n" , rs );
54+ }
55+
56+ return rs ;
57+ }
58+
59+ /*
60+
61+ Type | SYNC | User | Local | Network
62+ =======|======|======|=======|========
63+ User | | | |
64+ -------+------+------+-------+--------
65+ Menu | | * | X |
66+ -------+------+------+-------+--------
67+ System | | | | X
68+ -------+------+------+-------+--------
69+ User | ON | | |
70+ -------+------+------+-------+--------
71+ Menu | ON | | |
72+ -------+------+------+-------+--------
73+ System | ON | * | * | X
74+
75+ */
76+ TimeServiceType __nx_time_service_type = TimeServiceType_System ;
4377bool setNetworkSystemClock (time_t time ) {
4478 Result rs = timeSetCurrentTime (TimeType_NetworkSystemClock , (uint64_t )time );
4579 if (R_FAILED (rs )) {
@@ -68,11 +102,67 @@ int consoleExitWithMsg(char* msg) {
68102 return 0 ;
69103}
70104
105+ bool toggleHBMenuPath (char * curPath ) {
106+ const char * HB_MENU_NRO_PATH = "sdmc:/hbmenu.nro" ;
107+ const char * HB_MENU_BAK_PATH = "sdmc:/hbmenu.nro.bak" ;
108+ const char * DEFAULT_RESTORE_PATH = "sdmc:/switch/switch-time.nro" ;
109+
110+ printf ("\n\n" );
111+
112+ Result rs ;
113+ if (strcmp (curPath , HB_MENU_NRO_PATH ) == 0 ) {
114+ // restore hbmenu
115+ rs = access (HB_MENU_BAK_PATH , F_OK );
116+ if (R_FAILED (rs )) {
117+ printf ("could not find %s to restore. failed: 0x%x" , HB_MENU_BAK_PATH , rs );
118+ consoleExitWithMsg ("" );
119+ return false;
120+ }
121+
122+ rs = rename (curPath , DEFAULT_RESTORE_PATH );
123+ if (R_FAILED (rs )) {
124+ printf ("fsFsRenameFile(%s, %s) failed: 0x%x" , curPath , DEFAULT_RESTORE_PATH , rs );
125+ consoleExitWithMsg ("" );
126+ return false;
127+ }
128+ rs = rename (HB_MENU_BAK_PATH , HB_MENU_NRO_PATH );
129+ if (R_FAILED (rs )) {
130+ printf ("fsFsRenameFile(%s, %s) failed: 0x%x" , HB_MENU_BAK_PATH , HB_MENU_NRO_PATH , rs );
131+ consoleExitWithMsg ("" );
132+ return false;
133+ }
134+ } else {
135+ // replace hbmenu
136+ rs = rename (HB_MENU_NRO_PATH , HB_MENU_BAK_PATH );
137+ if (R_FAILED (rs )) {
138+ printf ("fsFsRenameFile(%s, %s) failed: 0x%x" , HB_MENU_NRO_PATH , HB_MENU_BAK_PATH , rs );
139+ consoleExitWithMsg ("" );
140+ return false;
141+ }
142+ rs = rename (curPath , HB_MENU_NRO_PATH );
143+ if (R_FAILED (rs )) {
144+ printf ("fsFsRenameFile(%s, %s) failed: 0x%x" , curPath , HB_MENU_NRO_PATH , rs );
145+ rename (HB_MENU_BAK_PATH , HB_MENU_NRO_PATH ); // hbmenu already moved, try to move it back
146+ consoleExitWithMsg ("" );
147+ return false;
148+ }
149+ }
150+
151+ printf ("Quick launch toggled\n\n" );
152+
153+ return true;
154+ }
155+
71156int main (int argc , char * argv []) {
72157 consoleInit (NULL );
73- printf ("SwitchTime v0.1.0 \n\n" );
158+ printf ("SwitchTime v0.1.1 \n\n" );
74159
75160 if (!setsysInternetTimeSyncIsOn ()) {
161+ // printf("Trying setsysSetUserSystemClockAutomaticCorrectionEnabled...\n");
162+ // if (R_FAILED(enableSetsysInternetTimeSync())) {
163+ // return consoleExitWithMsg("Internet time sync is not enabled. Please enable it in System Settings.");
164+ // }
165+ // doesn't work without rebooting? not worth it
76166 return consoleExitWithMsg ("Internet time sync is not enabled. Please enable it in System Settings." );
77167 }
78168
@@ -93,6 +183,11 @@ int main(int argc, char* argv[]) {
93183 consoleExit (NULL );
94184 return 0 ; // return to hbmenu
95185 }
186+ if (kDown & KEY_L ) {
187+ if (!toggleHBMenuPath (argv [0 ])) {
188+ return 0 ;
189+ }
190+ }
96191
97192 time_t currentTime ;
98193 Result rs = timeGetCurrentTime (TimeType_UserSystemClock , (u64 * )& currentTime );
0 commit comments