mirror of
https://gitlab.com/Theopse/fbi-i18n-zh.git
synced 2025-09-14 04:39:47 +08:00
Remove invalid characters from save export/import paths.
This commit is contained in:
parent
3eb14100ef
commit
aae1572945
@ -510,4 +510,28 @@ const char* util_get_display_size_units(u64 size) {
|
||||
}
|
||||
|
||||
return "B";
|
||||
}
|
||||
|
||||
void util_escape_file_name(char* out, const char* in, size_t size) {
|
||||
static const char reservedChars[] = {'<', '>', ':', '"', '/', '\\', '|', '?', '*'};
|
||||
|
||||
for(u32 i = 0; i < size; i++) {
|
||||
bool reserved = false;
|
||||
for(u32 j = 0; j < sizeof(reservedChars); j++) {
|
||||
if(in[i] == reservedChars[j]) {
|
||||
reserved = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(reserved) {
|
||||
out[i] = '_';
|
||||
} else {
|
||||
out[i] = in[i];
|
||||
}
|
||||
|
||||
if(in[i] == '\0') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -72,4 +72,6 @@ Result util_ref_archive(FS_Archive archive);
|
||||
Result util_close_archive(FS_Archive archive);
|
||||
|
||||
double util_get_display_size(u64 size);
|
||||
const char* util_get_display_size_units(u64 size);
|
||||
const char* util_get_display_size_units(u64 size);
|
||||
|
||||
void util_escape_file_name(char* out, const char* in, size_t size);
|
@ -65,8 +65,11 @@ static Result action_export_twl_save_open_dst(void* data, u32 index, void* initi
|
||||
FS_Archive sdmcArchive = 0;
|
||||
if(R_SUCCEEDED(res = FSUSER_OpenArchive(&sdmcArchive, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, "")))) {
|
||||
if(R_SUCCEEDED(res = util_ensure_dir(sdmcArchive, "/fbi/")) && R_SUCCEEDED(res = util_ensure_dir(sdmcArchive, "/fbi/save/"))) {
|
||||
char gameName[0x10] = {'\0'};
|
||||
util_escape_file_name(gameName, exportData->title->productCode, sizeof(gameName));
|
||||
|
||||
char path[FILE_PATH_MAX];
|
||||
snprintf(path, sizeof(path), "/fbi/save/%s.sav", exportData->title->productCode);
|
||||
snprintf(path, sizeof(path), "/fbi/save/%s.sav", gameName);
|
||||
|
||||
FS_Path* fsPath = util_make_path_utf8(path);
|
||||
if(fsPath != NULL) {
|
||||
|
@ -39,8 +39,11 @@ static Result action_import_twl_save_open_src(void* data, u32 index, u32* handle
|
||||
|
||||
Result res = 0;
|
||||
|
||||
char gameName[0x10] = {'\0'};
|
||||
util_escape_file_name(gameName, importData->title->productCode, sizeof(gameName));
|
||||
|
||||
char path[FILE_PATH_MAX];
|
||||
snprintf(path, sizeof(path), "/fbi/save/%s.sav", importData->title->productCode);
|
||||
snprintf(path, sizeof(path), "/fbi/save/%s.sav", gameName);
|
||||
|
||||
FS_Path* fsPath = util_make_path_utf8(path);
|
||||
if(fsPath != NULL) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user