Skip to content

Commit a6385bf

Browse files
author
Calvin Fuchs
committed
adding option to remove mac specific files
1 parent 8821ce8 commit a6385bf

2 files changed

Lines changed: 144 additions & 18 deletions

File tree

source/cpr/cpr.c

Lines changed: 124 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
#include "../utils/utils.h"
1616
#include "../fs/fsutils.h"
1717

18+
#include <unistd.h>
19+
#include <sys/types.h>
20+
// #include <dirent.h>
21+
// #include <stdio.h>
22+
#include <string.h>
23+
#include <sys/stat.h>
24+
1825
void _DeleteFileSimple(char *thing){
1926
//char *thing = CombinePaths(path, entry.name);
2027
int res = f_unlink(thing);
@@ -28,6 +35,114 @@ void _RenameFileSimple(char *sourcePath, char *destPath){
2835
DrawError(newErrCode(res));
2936
}
3037
}
38+
ErrCode_t _FolderDelete(const char *path){
39+
int res = 0;
40+
ErrCode_t ret = newErrCode(0);
41+
u32 x, y;
42+
gfx_con_getpos(&x, &y);
43+
Vector_t fileVec = ReadFolder(path, &res);
44+
if (res){
45+
ret = newErrCode(res);
46+
}
47+
else {
48+
vecDefArray(FSEntry_t *, fs, fileVec);
49+
for (int i = 0; i < fileVec.count && !ret.err; i++){
50+
char *temp = CombinePaths(path, fs[i].name);
51+
if (fs[i].isDir){
52+
ret = _FolderDelete(temp);
53+
}
54+
else {
55+
res = f_unlink(temp);
56+
if (res){
57+
ret = newErrCode(res);
58+
}
59+
}
60+
free(temp);
61+
}
62+
}
63+
if (!ret.err){
64+
res = f_unlink(path);
65+
if (res)
66+
ret = newErrCode(res);
67+
}
68+
clearFileVector(&fileVec);
69+
return ret;
70+
}
71+
int _StartsWith(const char *a, const char *b)
72+
{
73+
if(strncmp(a, b, strlen(b)) == 0) return 1;
74+
return 0;
75+
}
76+
77+
int listdir(char *path, u32 hos_folder)
78+
{
79+
FRESULT res;
80+
DIR dir;
81+
u32 dirLength = 0;
82+
static FILINFO fno;
83+
84+
// Open directory.
85+
res = f_opendir(&dir, path);
86+
if (res != FR_OK)
87+
return res;
88+
89+
dirLength = strlen(path);
90+
for (;;)
91+
{
92+
// Clear file or folder path.
93+
path[dirLength] = 0;
94+
// Read a directory item.
95+
res = f_readdir(&dir, &fno);
96+
// Break on error or end of dir.
97+
if (res != FR_OK || fno.fname[0] == 0)
98+
break;
99+
// Skip official Nintendo dir if started from root.
100+
if (!hos_folder && !strcmp(fno.fname, "Nintendo"))
101+
continue;
102+
103+
// // Set new directory or file.
104+
memcpy(&path[dirLength], "/", 1);
105+
memcpy(&path[dirLength + 1], fno.fname, strlen(fno.fname) + 1);
106+
// gfx_printf("THING: %s\n", fno.fname);
107+
// gfx_printf("Path: %s\n", dir);
108+
// Is it a directory?
109+
if (fno.fattrib & AM_DIR)
110+
{
111+
if (
112+
strcmp(fno.fname, ".Trash") == 0 ||
113+
strcmp(fno.fname, ".Trashes") == 0 ||
114+
strcmp(fno.fname, ".DS_Store") == 0 ||
115+
strcmp(fno.fname, ".Spotlight-V100") == 0 ||
116+
strcmp(fno.fname, ".apDisk") == 0 ||
117+
strcmp(fno.fname, ".VolumeIcon.icns") == 0 ||
118+
strcmp(fno.fname, ".fseventsd") == 0 ||
119+
strcmp(fno.fname, ".TemporaryItems") == 0
120+
) {
121+
_FolderDelete(path);
122+
}
123+
124+
// Enter the directory.
125+
listdir(path, 0);
126+
if (res != FR_OK)
127+
break;
128+
} else {
129+
if (
130+
strcmp(fno.fname, ".DS_Store") == 0 ||
131+
strcmp(fno.fname, ".Spotlight-V100") == 0 ||
132+
strcmp(fno.fname, ".apDisk") == 0 ||
133+
strcmp(fno.fname, ".VolumeIcon.icns") == 0 ||
134+
strcmp(fno.fname, ".fseventsd") == 0 ||
135+
strcmp(fno.fname, ".TemporaryItems") == 0 ||
136+
_StartsWith(fno.fname, "._")
137+
) {
138+
_DeleteFileSimple(path);
139+
}
140+
}
141+
}
142+
f_closedir(&dir);
143+
free(path);
144+
return res;
145+
}
31146

32147
int _fix_attributes(char *path, u32 *total, u32 hos_folder, u32 check_first_run){
33148
FRESULT res;
@@ -286,7 +401,15 @@ void m_entry_deleteBootFlags(){
286401
hidWait();
287402
}
288403

289-
void m_entry_fixMacSpecialFolders(char *path){
404+
405+
406+
void m_entry_fixMacSpecialFolders(){
407+
gfx_clearscreen();
408+
gfx_printf("\n\n-- Fix mac folders (this can take some time, please wait.)\n\n");
409+
listdir("/", 0);
410+
gfx_printf("\n\rDone, press a key to proceed.");
411+
hidWait();
412+
290413
// browse path
291414
// list files & folders
292415
// if file -> delete

source/tegraexplorer/mainmenu.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ enum {
3737
FixAIOUpdaterBoot,
3838
FixArchiveBitA,
3939
FixArchiveBitN,
40-
// FixMacSpecialFolders,
41-
FixAll,
40+
// FixAll,
41+
MainConvenience,
42+
FixMacSpecialFolders,
4243
MainOther,
4344
MainViewStillNoBootInfo,
4445
MainViewCredits,
@@ -51,18 +52,28 @@ enum {
5152
};
5253

5354
MenuEntry_t mainMenuEntries[] = {
54-
[MainExplore] = {.optionUnion = COLORTORGB(COLOR_WHITE) | SKIPBIT, .name = "-- Tools --"},
55+
[MainExplore] = {.optionUnion = COLORTORGB(COLOR_WHITE) | SKIPBIT, .name = "-- Bootfixes --"},
5556
[DeleteBootFlags] = {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Disable automatic sysmodule startup"},
5657
[DeleteThemes] = {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Delete installed themes"},
5758
[FixClingWrap] = {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Fix ClingWrap"},
5859
[FixAIOUpdaterBoot] = {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Fix Switch-AiO-Updater update"},
5960
[FixArchiveBitA] = {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Fix archive bit (all folders except nintendo)"},
6061
[FixArchiveBitN] = {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Fix archive bit (nintendo folder)"},
61-
// [FixMacSpecialFolders] = {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Remove special folders created by Mac"},
62-
[FixAll] = {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Try everything"},
63-
[MainOther] = {.optionUnion = COLORTORGB(COLOR_GREEN) | SKIPBIT, .name = "\n-- Other --"},
62+
// [FixAll] = {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Try everything"},
6463

64+
[MainConvenience] = {.optionUnion = COLORTORGB(COLOR_WHITE) | SKIPBIT, .name = "\n-- Convenience --"},
65+
[FixMacSpecialFolders] = {.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Remove special folders created by Mac"},
6566

67+
[MainOther] = {.optionUnion = COLORTORGB(COLOR_WHITE) | SKIPBIT, .name = "\n-- Other --"},
68+
[MainViewStillNoBootInfo] = {.optionUnion = COLORTORGB(COLOR_YELLOW), .name = "My switch still does not boot"},
69+
[MainViewCredits] = {.optionUnion = COLORTORGB(COLOR_YELLOW), .name = "Credits"},
70+
71+
[MainExit] = {.optionUnion = COLORTORGB(COLOR_WHITE) | SKIPBIT, .name = "\n-- Exit --"},
72+
[MainPowerOff] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Power off"},
73+
[MainRebootRCM] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Reboot to RCM"},
74+
// [MainRebootNormal] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Reboot normally"},
75+
[MainRebootHekate] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Reboot to bootloader/update.bin"},
76+
[MainRebootAMS] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Reboot to atmosphere/reboot_payload.bin"}
6677

6778

6879
// [MainBrowseSd] = {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Browse SD"},
@@ -73,15 +84,7 @@ MenuEntry_t mainMenuEntries[] = {
7384
// [MainPartitionSd] = {.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Partition the sd"},
7485
// [MainDumpFw] = {.optionUnion = COLORTORGB(COLOR_BLUE), .name = "Dump Firmware"},
7586
// [MainViewKeys] = {.optionUnion = COLORTORGB(COLOR_YELLOW), .name = "View dumped keys"},
76-
[MainOther] = {.optionUnion = COLORTORGB(COLOR_WHITE) | SKIPBIT, .name = "\n-- Other --"},
77-
[MainViewStillNoBootInfo] = {.optionUnion = COLORTORGB(COLOR_YELLOW), .name = "My switch still does not boot"},
78-
[MainViewCredits] = {.optionUnion = COLORTORGB(COLOR_YELLOW), .name = "Credits"},
79-
[MainExit] = {.optionUnion = COLORTORGB(COLOR_WHITE) | SKIPBIT, .name = "\n-- Exit --"},
80-
[MainPowerOff] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Power off"},
81-
[MainRebootRCM] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Reboot to RCM"},
82-
// [MainRebootNormal] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Reboot normally"},
83-
[MainRebootHekate] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Reboot to bootloader/update.bin"},
84-
[MainRebootAMS] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Reboot to atmosphere/reboot_payload.bin"}
87+
8588
};
8689

8790
void HandleSD(){
@@ -132,8 +135,8 @@ menuPaths mainMenuPaths[] = {
132135
[FixAIOUpdaterBoot] = m_entry_fixAIOUpdate,
133136
[FixArchiveBitA] = archBitHelperA,
134137
[FixArchiveBitN] = archBitHelperN,
135-
// [FixMacSpecialFolders] = m_entry_fixMacSpecialFolders,
136-
[FixAll] = m_entry_fixAll,
138+
[FixMacSpecialFolders] = m_entry_fixMacSpecialFolders,
139+
// [FixAll] = m_entry_fixAll,
137140
[MainViewStillNoBootInfo] = m_entry_stillNoBootInfo,
138141
[MainRebootHekate] = RebootToHekate,
139142
[MainRebootRCM] = reboot_rcm,

0 commit comments

Comments
 (0)