|
| 1 | +// #include <utils/util.h> |
| 2 | +// #include "tools.h" |
| 3 | +#include <storage/nx_sd.h> |
| 4 | +#include "../fs/readers/folderReader.h" |
| 5 | +#include "../fs/fstypes.h" |
| 6 | +#include "../fs/fscopy.h" |
| 7 | +#include <utils/sprintf.h> |
| 8 | +#include <stdlib.h> |
| 9 | +#include <string.h> |
| 10 | +#include "../gfx/gfx.h" |
| 11 | +#include "../gfx/gfxutils.h" |
| 12 | +#include "../gfx/menu.h" |
| 13 | +#include "../hid/hid.h" |
| 14 | +// #include "utils.h" |
| 15 | +#include "../utils/utils.h" |
| 16 | +#include "../fs/fsutils.h" |
| 17 | + |
| 18 | +void _DeleteFileSimple(char *thing){ |
| 19 | + //char *thing = CombinePaths(path, entry.name); |
| 20 | + int res = f_unlink(thing); |
| 21 | + if (res) |
| 22 | + DrawError(newErrCode(res)); |
| 23 | + free(thing); |
| 24 | +} |
| 25 | +void _RenameFileSimple(char *sourcePath, char *destPath){ |
| 26 | + int res = f_rename(sourcePath, destPath); |
| 27 | + if (res){ |
| 28 | + DrawError(newErrCode(res)); |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +int _fix_attributes(char *path, u32 *total, u32 hos_folder, u32 check_first_run){ |
| 33 | + FRESULT res; |
| 34 | + DIR dir; |
| 35 | + u32 dirLength = 0; |
| 36 | + static FILINFO fno; |
| 37 | + |
| 38 | + if (check_first_run) |
| 39 | + { |
| 40 | + // Read file attributes. |
| 41 | + res = f_stat(path, &fno); |
| 42 | + if (res != FR_OK) |
| 43 | + return res; |
| 44 | + |
| 45 | + // Check if archive bit is set. |
| 46 | + if (fno.fattrib & AM_ARC) |
| 47 | + { |
| 48 | + *(u32 *)total = *(u32 *)total + 1; |
| 49 | + f_chmod(path, 0, AM_ARC); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + // Open directory. |
| 54 | + res = f_opendir(&dir, path); |
| 55 | + if (res != FR_OK) |
| 56 | + return res; |
| 57 | + |
| 58 | + dirLength = strlen(path); |
| 59 | + for (;;) |
| 60 | + { |
| 61 | + // Clear file or folder path. |
| 62 | + path[dirLength] = 0; |
| 63 | + |
| 64 | + // Read a directory item. |
| 65 | + res = f_readdir(&dir, &fno); |
| 66 | + |
| 67 | + // Break on error or end of dir. |
| 68 | + if (res != FR_OK || fno.fname[0] == 0) |
| 69 | + break; |
| 70 | + |
| 71 | + // Skip official Nintendo dir if started from root. |
| 72 | + if (!hos_folder && !strcmp(fno.fname, "Nintendo")) |
| 73 | + continue; |
| 74 | + |
| 75 | + // Set new directory or file. |
| 76 | + memcpy(&path[dirLength], "/", 1); |
| 77 | + memcpy(&path[dirLength + 1], fno.fname, strlen(fno.fname) + 1); |
| 78 | + |
| 79 | + // Check if archive bit is set. |
| 80 | + if (fno.fattrib & AM_ARC) |
| 81 | + { |
| 82 | + *total = *total + 1; |
| 83 | + f_chmod(path, 0, AM_ARC); |
| 84 | + } |
| 85 | + |
| 86 | + // Is it a directory? |
| 87 | + if (fno.fattrib & AM_DIR) |
| 88 | + { |
| 89 | + // Set archive bit to NCA folders. |
| 90 | + if (hos_folder && !strcmp(fno.fname + strlen(fno.fname) - 4, ".nca")) |
| 91 | + { |
| 92 | + *total = *total + 1; |
| 93 | + f_chmod(path, AM_ARC, AM_ARC); |
| 94 | + } |
| 95 | + |
| 96 | + // Enter the directory. |
| 97 | + res = _fix_attributes(path, total, hos_folder, 0); |
| 98 | + if (res != FR_OK) |
| 99 | + break; |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + f_closedir(&dir); |
| 104 | + |
| 105 | + return res; |
| 106 | +} |
| 107 | + |
| 108 | + |
| 109 | +void m_entry_fixArchiveBit(u32 type){ |
| 110 | + gfx_clearscreen(); |
| 111 | + gfx_printf("\n\n-- Fix Archive Bits\n\n"); |
| 112 | + |
| 113 | + char path[256]; |
| 114 | + char label[16]; |
| 115 | + |
| 116 | + u32 total = 0; |
| 117 | + if (sd_mount()) |
| 118 | + { |
| 119 | + switch (type) |
| 120 | + { |
| 121 | + case 0: |
| 122 | + strcpy(path, "/"); |
| 123 | + strcpy(label, "SD Card"); |
| 124 | + break; |
| 125 | + case 1: |
| 126 | + default: |
| 127 | + strcpy(path, "/Nintendo"); |
| 128 | + strcpy(label, "Nintendo folder"); |
| 129 | + break; |
| 130 | + } |
| 131 | + |
| 132 | + gfx_printf("Traversing all %s files!\nThis may take some time...\n\n", label); |
| 133 | + _fix_attributes(path, &total, type, type); |
| 134 | + gfx_printf("%kTotal archive bits cleared: %d!%k", 0xFF96FF00, total, 0xFFCCCCCC); |
| 135 | + |
| 136 | + gfx_printf("\n\n Done, press a key to proceed."); |
| 137 | + hidWait(); |
| 138 | + } |
| 139 | +} |
| 140 | + |
| 141 | + |
| 142 | +void m_entry_fixAIOUpdate(){ |
| 143 | + gfx_clearscreen(); |
| 144 | + gfx_printf("\n\n-- Fix broken Switch-AiO-Updater update.\n\n"); |
| 145 | + |
| 146 | + char *aio_fs_path = CpyStr("sd:/atmosphere/fusee-secondary.bin.aio"); |
| 147 | + char *aio_p_path = CpyStr("sd:/sept/payload.bin.aio"); |
| 148 | + char *aio_strt_path = CpyStr("sd:/atmosphere/stratosphere.romfs.aio"); |
| 149 | + |
| 150 | + char *o_fs_path = CpyStr("sd:/atmosphere/fusee-secondary.bin"); |
| 151 | + char *o_p_path = CpyStr("sd:/sept/payload.bin"); |
| 152 | + char *o_strt_path = CpyStr("sd:/atmosphere/stratosphere.romfs"); |
| 153 | + |
| 154 | + if (FileExists(aio_fs_path)) { |
| 155 | + gfx_printf("Detected aio updated fusee-secondary file -> replacing original\n\n"); |
| 156 | + if (FileExists(o_fs_path)) { |
| 157 | + _DeleteFileSimple(o_fs_path); |
| 158 | + } |
| 159 | + _RenameFileSimple(aio_fs_path, o_fs_path); |
| 160 | + } |
| 161 | + free(aio_fs_path); |
| 162 | + free(o_fs_path); |
| 163 | + |
| 164 | + if (FileExists(aio_p_path)) { |
| 165 | + gfx_printf("Detected aio updated paload file -> replacing original\n\n"); |
| 166 | + if (FileExists(o_p_path)) { |
| 167 | + _DeleteFileSimple(o_p_path); |
| 168 | + } |
| 169 | + _RenameFileSimple(aio_p_path, o_p_path); |
| 170 | + } |
| 171 | + free(aio_p_path); |
| 172 | + free(o_p_path); |
| 173 | + |
| 174 | + if (FileExists(aio_strt_path)) { |
| 175 | + gfx_printf("Detected aio updated stratosphere file -> replacing original\n\n"); |
| 176 | + if (FileExists(o_strt_path)) { |
| 177 | + _DeleteFileSimple(o_strt_path); |
| 178 | + } |
| 179 | + _RenameFileSimple(aio_strt_path, o_strt_path); |
| 180 | + } |
| 181 | + free(aio_strt_path); |
| 182 | + free(o_strt_path); |
| 183 | + |
| 184 | + |
| 185 | + gfx_printf("\n\n Done, press a key to proceed."); |
| 186 | + hidWait(); |
| 187 | +} |
| 188 | + |
| 189 | +void m_entry_fixClingWrap(){ |
| 190 | + gfx_clearscreen(); |
| 191 | + gfx_printf("\n\n-- Fixing ClingWrap.\n\n"); |
| 192 | + char *bpath = CpyStr("sd:/_b0otloader"); |
| 193 | + char *bopath = CpyStr("sd:/bootloader"); |
| 194 | + char *kpath = CpyStr("sd:/atmosphere/_k1ps"); |
| 195 | + char *kopath = CpyStr("sd:/atmosphere/kips"); |
| 196 | + |
| 197 | + char *ppath = CpyStr("sd:/bootloader/_patchesCW.ini"); |
| 198 | + char *popath = CpyStr("sd:/atmosphere/patches.ini"); |
| 199 | + |
| 200 | + if (FileExists(bpath)) { |
| 201 | + if (FileExists(bopath)) { |
| 202 | + FolderDelete(bopath); |
| 203 | + } |
| 204 | + int res = f_rename(bpath, bopath); |
| 205 | + if (res){ |
| 206 | + DrawError(newErrCode(res)); |
| 207 | + } |
| 208 | + gfx_printf("-- Fixed Bootloader\n"); |
| 209 | + } |
| 210 | + |
| 211 | + if (FileExists(kpath)) { |
| 212 | + if (FileExists(kopath)) { |
| 213 | + FolderDelete(kopath); |
| 214 | + } |
| 215 | + int res = f_rename(kpath, kopath); |
| 216 | + if (res){ |
| 217 | + DrawError(newErrCode(res)); |
| 218 | + } |
| 219 | + gfx_printf("-- Fixed kips\n"); |
| 220 | + } |
| 221 | + |
| 222 | + if (FileExists(ppath)) { |
| 223 | + if (FileExists(popath)) { |
| 224 | + _DeleteFileSimple(popath); |
| 225 | + } |
| 226 | + _RenameFileSimple(ppath,popath); |
| 227 | + gfx_printf("-- Fixed patches.ini\n"); |
| 228 | + } |
| 229 | + |
| 230 | + free(bpath); |
| 231 | + free(bopath); |
| 232 | + free(kpath); |
| 233 | + free(kopath); |
| 234 | + free(ppath); |
| 235 | + free(popath); |
| 236 | + |
| 237 | + gfx_printf("\n\n Done, press a key to proceed."); |
| 238 | + hidWait(); |
| 239 | +} |
| 240 | + |
| 241 | +void _deleteTheme(char* basePath, char* folderId){ |
| 242 | + char *path = CombinePaths(basePath, folderId); |
| 243 | + if (FileExists(path)) { |
| 244 | + gfx_printf("-- Theme found: %s\n", path); |
| 245 | + FolderDelete(path); |
| 246 | + } |
| 247 | + free(path); |
| 248 | +} |
| 249 | + |
| 250 | +void m_entry_deleteInstalledThemes(){ |
| 251 | + gfx_clearscreen(); |
| 252 | + gfx_printf("\n\n-- Deleting installed themes.\n\n"); |
| 253 | + _deleteTheme("sd:/atmosphere/contents", "0100000000001000"); |
| 254 | + _deleteTheme("sd:/atmosphere/contents", "0100000000001007"); |
| 255 | + _deleteTheme("sd:/atmosphere/contents", "0100000000001013"); |
| 256 | + |
| 257 | + gfx_printf("\n\n Done, press a key to proceed."); |
| 258 | + hidWait(); |
| 259 | +} |
| 260 | + |
| 261 | +void m_entry_deleteBootFlags(){ |
| 262 | + gfx_clearscreen(); |
| 263 | + gfx_printf("\n\n-- Disabling automatic sysmodule startup.\n\n"); |
| 264 | + char *storedPath = CpyStr("sd:/atmosphere/contents"); |
| 265 | + int readRes = 0; |
| 266 | + Vector_t fileVec = ReadFolder(storedPath, &readRes); |
| 267 | + if (readRes){ |
| 268 | + clearFileVector(&fileVec); |
| 269 | + DrawError(newErrCode(readRes)); |
| 270 | + } else { |
| 271 | + vecDefArray(FSEntry_t*, fsEntries, fileVec); |
| 272 | + for (int i = 0; i < fileVec.count; i++){ |
| 273 | + |
| 274 | + char *suf = "/flags/boot2.flag"; |
| 275 | + char *flagPath = CombinePaths(storedPath, fsEntries[i].name); |
| 276 | + flagPath = CombinePaths(flagPath, suf); |
| 277 | + |
| 278 | + if (FileExists(flagPath)) { |
| 279 | + gfx_printf("Deleting: %s\n", flagPath); |
| 280 | + _DeleteFileSimple(flagPath); |
| 281 | + } |
| 282 | + free(flagPath); |
| 283 | + } |
| 284 | + } |
| 285 | + gfx_printf("\n\n Done, press a key to proceed."); |
| 286 | + hidWait(); |
| 287 | +} |
| 288 | + |
| 289 | +void m_entry_fixMacSpecialFolders(char *path){ |
| 290 | + // browse path |
| 291 | + // list files & folders |
| 292 | + // if file -> delete |
| 293 | + // if folder !== nintendo |
| 294 | + // if folder m_entry_fixMacSpecialFolders with new path |
| 295 | +} |
| 296 | + |
| 297 | +void m_entry_stillNoBootInfo(){ |
| 298 | + gfx_clearscreen(); |
| 299 | + gfx_printf("\n\n-- My switch still does not boot.\n\n"); |
| 300 | + |
| 301 | + gfx_printf("%kDo you have a gamecard inserted?\n", COLOR_WHITE); |
| 302 | + gfx_printf("Try taking it out and reboot.\n\n"); |
| 303 | + |
| 304 | + gfx_printf("%kDid you recently update Atmosphere/DeepSea?\n", COLOR_WHITE); |
| 305 | + gfx_printf("Insert your sdcard into a computer, delete 'atmosphere', 'bootloader' & 'sept', download your preffered CFW and put the files back on your switch.\n\n"); |
| 306 | + |
| 307 | + gfx_printf("%kDid you just buy a new SD-card?\n", COLOR_WHITE); |
| 308 | + gfx_printf("Make sure its not a fake card.\n\n"); |
| 309 | + |
| 310 | + gfx_printf("\n\n Done, press a key to proceed."); |
| 311 | + hidWait(); |
| 312 | +} |
| 313 | + |
| 314 | +void m_entry_ViewCredits(){ |
| 315 | + gfx_clearscreen(); |
| 316 | + gfx_printf("\nCommon Problem Resolver v%d.%d.%d\nBy Team Neptune\n\nBased on TegraExplorer by SuchMemeManySkill,\nLockpick_RCM & Hekate, from shchmue & CTCaer\n\n\n", LP_VER_MJ, LP_VER_MN, LP_VER_BF); |
| 317 | + hidWait(); |
| 318 | +} |
| 319 | + |
| 320 | +void m_entry_fixAll(){ |
| 321 | + gfx_clearscreen(); |
| 322 | + m_entry_deleteBootFlags(); |
| 323 | + m_entry_deleteInstalledThemes(); |
| 324 | + m_entry_fixClingWrap(); |
| 325 | + m_entry_fixAIOUpdate(); |
| 326 | + |
| 327 | + |
| 328 | + m_entry_stillNoBootInfo(); |
| 329 | +} |
0 commit comments