Skip to content

Commit fad754a

Browse files
committed
Improve fatGetAliasPath to support directories with . in the name, and extensions less than 3 chars.
Fixes #2630
1 parent 71aaad9 commit fad754a

File tree

8 files changed

+82
-54
lines changed

8 files changed

+82
-54
lines changed

quickmenu/arm9/source/main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,15 +2513,15 @@ int dsClassicMenu(void) {
25132513
char sfnPrv[62];
25142514
char sfnBnr[62];
25152515
if (ms().secondaryDevice && !bs().b4dsMode && ms().dsiWareToSD && sdFound()) {
2516-
fatGetAliasPath("sd:/", "sd:/_nds/TWiLightMenu/tempDSiWare.dsi", sfnSrl);
2517-
fatGetAliasPath("sd:/", "sd:/_nds/TWiLightMenu/tempDSiWare.pub", sfnPub);
2518-
fatGetAliasPath("sd:/", "sd:/_nds/TWiLightMenu/tempDSiWare.prv", sfnPrv);
2519-
fatGetAliasPath("sd:/", "sd:/_nds/TWiLightMenu/tempDSiWare.bnr", sfnBnr);
2516+
fatGetAliasPath("sd:/_nds/TWiLightMenu/tempDSiWare.dsi", sfnSrl);
2517+
fatGetAliasPath("sd:/_nds/TWiLightMenu/tempDSiWare.pub", sfnPub);
2518+
fatGetAliasPath("sd:/_nds/TWiLightMenu/tempDSiWare.prv", sfnPrv);
2519+
fatGetAliasPath("sd:/_nds/TWiLightMenu/tempDSiWare.bnr", sfnBnr);
25202520
} else {
2521-
fatGetAliasPath(ms().secondaryDevice ? "fat:/" : "sd:/", ms().dsiWareSrlPath.c_str(), sfnSrl);
2522-
fatGetAliasPath(ms().secondaryDevice ? "fat:/" : "sd:/", ms().dsiWarePubPath.c_str(), sfnPub);
2523-
fatGetAliasPath(ms().secondaryDevice ? "fat:/" : "sd:/", ms().dsiWarePrvPath.c_str(), sfnPrv);
2524-
fatGetAliasPath(ms().secondaryDevice ? "fat:/" : "sd:/", ms().dsiWareBnrPath.c_str(), sfnBnr);
2521+
fatGetAliasPath(ms().dsiWareSrlPath.c_str(), sfnSrl);
2522+
fatGetAliasPath(ms().dsiWarePubPath.c_str(), sfnPub);
2523+
fatGetAliasPath(ms().dsiWarePrvPath.c_str(), sfnPrv);
2524+
fatGetAliasPath(ms().dsiWareBnrPath.c_str(), sfnBnr);
25252525
}
25262526

25272527
const char *bootstrapinipath = sdFound() ? BOOTSTRAP_INI : BOOTSTRAP_INI_FC;

romsel_aktheme/arm9/source/main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,15 +1567,15 @@ int akTheme(void) {
15671567
char sfnPrv[62];
15681568
char sfnBnr[62];
15691569
if (ms().secondaryDevice && !bs().b4dsMode && ms().dsiWareToSD && sdFound()) {
1570-
fatGetAliasPath("sd:/", "sd:/_nds/TWiLightMenu/tempDSiWare.dsi", sfnSrl);
1571-
fatGetAliasPath("sd:/", "sd:/_nds/TWiLightMenu/tempDSiWare.pub", sfnPub);
1572-
fatGetAliasPath("sd:/", "sd:/_nds/TWiLightMenu/tempDSiWare.prv", sfnPrv);
1573-
fatGetAliasPath("sd:/", "sd:/_nds/TWiLightMenu/tempDSiWare.bnr", sfnBnr);
1570+
fatGetAliasPath("sd:/_nds/TWiLightMenu/tempDSiWare.dsi", sfnSrl);
1571+
fatGetAliasPath("sd:/_nds/TWiLightMenu/tempDSiWare.pub", sfnPub);
1572+
fatGetAliasPath("sd:/_nds/TWiLightMenu/tempDSiWare.prv", sfnPrv);
1573+
fatGetAliasPath("sd:/_nds/TWiLightMenu/tempDSiWare.bnr", sfnBnr);
15741574
} else {
1575-
fatGetAliasPath(ms().secondaryDevice ? "fat:/" : "sd:/", ms().dsiWareSrlPath.c_str(), sfnSrl);
1576-
fatGetAliasPath(ms().secondaryDevice ? "fat:/" : "sd:/", ms().dsiWarePubPath.c_str(), sfnPub);
1577-
fatGetAliasPath(ms().secondaryDevice ? "fat:/" : "sd:/", ms().dsiWarePrvPath.c_str(), sfnPrv);
1578-
fatGetAliasPath(ms().secondaryDevice ? "fat:/" : "sd:/", ms().dsiWareBnrPath.c_str(), sfnBnr);
1575+
fatGetAliasPath(ms().dsiWareSrlPath.c_str(), sfnSrl);
1576+
fatGetAliasPath(ms().dsiWarePubPath.c_str(), sfnPub);
1577+
fatGetAliasPath(ms().dsiWarePrvPath.c_str(), sfnPrv);
1578+
fatGetAliasPath(ms().dsiWareBnrPath.c_str(), sfnBnr);
15791579
}
15801580

15811581
const char *bootstrapinipath = sdFound() ? BOOTSTRAP_INI : BOOTSTRAP_INI_FC;

romsel_dsimenutheme/arm9/source/fileBrowse.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,9 +1236,9 @@ void launchInternetBrowser(const vector<DirEntry>& dirContents) {
12361236
fadeType = false; // Fade to white
12371237
}
12381238

1239-
fatGetAliasPath(ms().secondaryDevice ? "fat:/" : "sd:/", ms().internetBrowserPath.c_str(), sfnSrl);
1240-
fatGetAliasPath(ms().secondaryDevice ? "fat:/" : "sd:/", savepathPub.c_str(), sfnPub);
1241-
fatGetAliasPath(ms().secondaryDevice ? "fat:/" : "sd:/", savepathPrv.c_str(), sfnPrv);
1239+
fatGetAliasPath(ms().internetBrowserPath.c_str(), sfnSrl);
1240+
fatGetAliasPath(savepathPub.c_str(), sfnPub);
1241+
fatGetAliasPath(savepathPrv.c_str(), sfnPrv);
12421242
} else {
12431243
createSaveFile(savepath.c_str(), false, browserTid);
12441244
}

romsel_dsimenutheme/arm9/source/main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,15 +1592,15 @@ int dsiMenuTheme(void) {
15921592
char sfnPrv[62];
15931593
char sfnBnr[62];
15941594
if (ms().secondaryDevice && !bs().b4dsMode && ms().dsiWareToSD && sdFound()) {
1595-
fatGetAliasPath("sd:/", "sd:/_nds/TWiLightMenu/tempDSiWare.dsi", sfnSrl);
1596-
fatGetAliasPath("sd:/", "sd:/_nds/TWiLightMenu/tempDSiWare.pub", sfnPub);
1597-
fatGetAliasPath("sd:/", "sd:/_nds/TWiLightMenu/tempDSiWare.prv", sfnPrv);
1598-
fatGetAliasPath("sd:/", "sd:/_nds/TWiLightMenu/tempDSiWare.bnr", sfnBnr);
1595+
fatGetAliasPath("sd:/_nds/TWiLightMenu/tempDSiWare.dsi", sfnSrl);
1596+
fatGetAliasPath("sd:/_nds/TWiLightMenu/tempDSiWare.pub", sfnPub);
1597+
fatGetAliasPath("sd:/_nds/TWiLightMenu/tempDSiWare.prv", sfnPrv);
1598+
fatGetAliasPath("sd:/_nds/TWiLightMenu/tempDSiWare.bnr", sfnBnr);
15991599
} else {
1600-
fatGetAliasPath(ms().secondaryDevice ? "fat:/" : "sd:/", ms().dsiWareSrlPath.c_str(), sfnSrl);
1601-
fatGetAliasPath(ms().secondaryDevice ? "fat:/" : "sd:/", ms().dsiWarePubPath.c_str(), sfnPub);
1602-
fatGetAliasPath(ms().secondaryDevice ? "fat:/" : "sd:/", ms().dsiWarePrvPath.c_str(), sfnPrv);
1603-
fatGetAliasPath(ms().secondaryDevice ? "fat:/" : "sd:/", ms().dsiWareBnrPath.c_str(), sfnBnr);
1600+
fatGetAliasPath(ms().dsiWareSrlPath.c_str(), sfnSrl);
1601+
fatGetAliasPath(ms().dsiWarePubPath.c_str(), sfnPub);
1602+
fatGetAliasPath(ms().dsiWarePrvPath.c_str(), sfnPrv);
1603+
fatGetAliasPath(ms().dsiWareBnrPath.c_str(), sfnBnr);
16041604
}
16051605

16061606
const char *bootstrapinipath = sdFound() ? BOOTSTRAP_INI : BOOTSTRAP_INI_FC;

romsel_r4theme/arm9/source/main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,15 +1757,15 @@ int r4Theme(void) {
17571757
char sfnPrv[62];
17581758
char sfnBnr[62];
17591759
if (ms().secondaryDevice && !bs().b4dsMode && ms().dsiWareToSD && sdFound()) {
1760-
fatGetAliasPath("sd:/", "sd:/_nds/TWiLightMenu/tempDSiWare.dsi", sfnSrl);
1761-
fatGetAliasPath("sd:/", "sd:/_nds/TWiLightMenu/tempDSiWare.pub", sfnPub);
1762-
fatGetAliasPath("sd:/", "sd:/_nds/TWiLightMenu/tempDSiWare.prv", sfnPrv);
1763-
fatGetAliasPath("sd:/", "sd:/_nds/TWiLightMenu/tempDSiWare.bnr", sfnBnr);
1760+
fatGetAliasPath("sd:/_nds/TWiLightMenu/tempDSiWare.dsi", sfnSrl);
1761+
fatGetAliasPath("sd:/_nds/TWiLightMenu/tempDSiWare.pub", sfnPub);
1762+
fatGetAliasPath("sd:/_nds/TWiLightMenu/tempDSiWare.prv", sfnPrv);
1763+
fatGetAliasPath("sd:/_nds/TWiLightMenu/tempDSiWare.bnr", sfnBnr);
17641764
} else {
1765-
fatGetAliasPath(ms().secondaryDevice ? "fat:/" : "sd:/", ms().dsiWareSrlPath.c_str(), sfnSrl);
1766-
fatGetAliasPath(ms().secondaryDevice ? "fat:/" : "sd:/", ms().dsiWarePubPath.c_str(), sfnPub);
1767-
fatGetAliasPath(ms().secondaryDevice ? "fat:/" : "sd:/", ms().dsiWarePrvPath.c_str(), sfnPrv);
1768-
fatGetAliasPath(ms().secondaryDevice ? "fat:/" : "sd:/", ms().dsiWareBnrPath.c_str(), sfnBnr);
1765+
fatGetAliasPath(ms().dsiWareSrlPath.c_str(), sfnSrl);
1766+
fatGetAliasPath(ms().dsiWarePubPath.c_str(), sfnPub);
1767+
fatGetAliasPath(ms().dsiWarePrvPath.c_str(), sfnPrv);
1768+
fatGetAliasPath(ms().dsiWareBnrPath.c_str(), sfnBnr);
17691769
}
17701770

17711771
const char *bootstrapinipath = sdFound() ? BOOTSTRAP_INI : BOOTSTRAP_INI_FC;

title/arm9/source/main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,15 +1074,15 @@ void lastRunROM()
10741074
}
10751075
rename("sd:/_nds/TWiLightMenu/tempDSiWare.bnr.bak", "sd:/_nds/TWiLightMenu/tempDSiWare.bnr");
10761076
}
1077-
fatGetAliasPath("sd:/", "sd:/_nds/TWiLightMenu/tempDSiWare.dsi", sfnSrl);
1078-
fatGetAliasPath("sd:/", "sd:/_nds/TWiLightMenu/tempDSiWare.pub", sfnPub);
1079-
fatGetAliasPath("sd:/", "sd:/_nds/TWiLightMenu/tempDSiWare.prv", sfnPrv);
1080-
fatGetAliasPath("sd:/", "sd:/_nds/TWiLightMenu/tempDSiWare.bnr", sfnBnr);
1077+
fatGetAliasPath("sd:/_nds/TWiLightMenu/tempDSiWare.dsi", sfnSrl);
1078+
fatGetAliasPath("sd:/_nds/TWiLightMenu/tempDSiWare.pub", sfnPub);
1079+
fatGetAliasPath("sd:/_nds/TWiLightMenu/tempDSiWare.prv", sfnPrv);
1080+
fatGetAliasPath("sd:/_nds/TWiLightMenu/tempDSiWare.bnr", sfnBnr);
10811081
} else {
1082-
fatGetAliasPath(ms().previousUsedDevice ? "fat:/" : "sd:/", ms().dsiWareSrlPath.c_str(), sfnSrl);
1083-
fatGetAliasPath(ms().previousUsedDevice ? "fat:/" : "sd:/", ms().dsiWarePubPath.c_str(), sfnPub);
1084-
fatGetAliasPath(ms().previousUsedDevice ? "fat:/" : "sd:/", ms().dsiWarePrvPath.c_str(), sfnPrv);
1085-
fatGetAliasPath(ms().previousUsedDevice ? "fat:/" : "sd:/", ms().dsiWareBnrPath.c_str(), sfnBnr);
1082+
fatGetAliasPath(ms().dsiWareSrlPath.c_str(), sfnSrl);
1083+
fatGetAliasPath(ms().dsiWarePubPath.c_str(), sfnPub);
1084+
fatGetAliasPath(ms().dsiWarePrvPath.c_str(), sfnPrv);
1085+
fatGetAliasPath(ms().dsiWareBnrPath.c_str(), sfnBnr);
10861086
}
10871087

10881088
CIniFile bootstrapini((useTempDSiWare || sys().isRunFromSD()) ? BOOTSTRAP_INI : BOOTSTRAP_INI_FC);

universal/arm9/include/fat_ext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ extern "C" {
1212
/*
1313
Get Alias Name
1414
*/
15-
extern void fatGetAliasName (const char* drive, const char* name, char *alias);
15+
// extern void fatGetAliasName (const char* drive, const char* name, char *alias);
1616

1717
/*
1818
Get Alias Path
1919
*/
20-
extern void fatGetAliasPath (const char* drive, const char* path, char *alias);
20+
extern void fatGetAliasPath (const char* path, char *alias);
2121

2222
#ifdef __cplusplus
2323
}

universal/arm9/source/libfat_ext.c

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,24 @@ static int fatGetAlias (const char* drive, const char* name, const char* nameEnd
7676
break;
7777
}
7878
}
79+
int extLen = 1;
7980
alias[i] = '.';
80-
alias[i+1] = entry.entryData[8];
81-
alias[i+2] = entry.entryData[9];
82-
alias[i+3] = entry.entryData[10];
83-
alias[i+4] = '\0';
84-
resultLen = i+4;
81+
for (extLen = 1; extLen <= 3; extLen++) {
82+
const int pos = 7+extLen;
83+
if (entry.entryData[pos] == ' ') {
84+
break;
85+
} else {
86+
alias[i+extLen] = entry.entryData[pos];
87+
}
88+
}
89+
const int pos = i+extLen;
90+
if (_FAT_directory_isDirectory(&entry)) {
91+
alias[pos] = '\x2F';
92+
resultLen = pos+1;
93+
} else {
94+
alias[pos] = '\0';
95+
resultLen = pos;
96+
}
8597
} else {
8698
for (i = 0; i <= 8; i++) {
8799
if (entry.entryData[i] == ' ') {
@@ -99,17 +111,33 @@ static int fatGetAlias (const char* drive, const char* name, const char* nameEnd
99111
return resultLen;
100112
}
101113

102-
void fatGetAliasName (const char* drive, const char* name, char *alias) {
114+
/* void fatGetAliasName (const char* drive, const char* name, char *alias) {
103115
fatGetAlias (drive, name, NULL, alias);
104-
}
116+
} */
117+
118+
void fatGetAliasPath (const char* path, char *alias) {
119+
if (access(path, F_OK) != 0) {
120+
alias[0] = '\0';
121+
return;
122+
}
123+
124+
int drivelen = 0;
125+
for (int i = 0; i < strlen(path); i++) {
126+
if (path[i] == '\x2F') {
127+
drivelen = i+1;
128+
break;
129+
}
130+
}
131+
132+
char drive[8] = {0};
133+
tonccpy(drive, path, drivelen);
105134

106-
void fatGetAliasPath (const char* drive, const char* path, char *alias) {
107135
char dirBak[PATH_MAX];
108136
getcwd(dirBak, PATH_MAX);
109137
chdir(drive);
110138

111139
char name[128];
112-
int len = (int)strlen(drive);
140+
int len = drivelen;
113141
int lfnLen = len;
114142
if (path[0] == '\x2F') {
115143
len = 1;

0 commit comments

Comments
 (0)