diff --git a/source/config.c b/source/config.c index b0fed6a..7518ae4 100644 --- a/source/config.c +++ b/source/config.c @@ -57,11 +57,7 @@ void writeConfig(const char *configPath, u32 configTemp) configData.formatVersionMinor = CONFIG_VERSIONMINOR; if(!fileWrite(&configData, configPath, sizeof(cfgData))) - { - createDirectory("luma"); - if(!fileWrite(&configData, configPath, sizeof(cfgData))) - error("Error writing the configuration file"); - } + error("Error writing the configuration file"); } } diff --git a/source/fs.c b/source/fs.c index f318026..f428bbe 100644 --- a/source/fs.c +++ b/source/fs.c @@ -64,7 +64,9 @@ bool fileWrite(const void *buffer, const char *path, u32 size) { FIL file; - if(f_open(&file, path, FA_WRITE | FA_OPEN_ALWAYS) == FR_OK) + FRESULT result = f_open(&file, path, FA_WRITE | FA_OPEN_ALWAYS); + + if(result == FR_OK) { unsigned int written; f_write(&file, buffer, size, &written); @@ -72,8 +74,21 @@ bool fileWrite(const void *buffer, const char *path, u32 size) return true; } + else if(result == FR_NO_PATH) + { + char folder[256]; - return false; + for(u32 i = 1; path[i] != 0; i++) + if(path[i] == '/') + { + memcpy(folder, path, i); + folder[i] = 0; + f_mkdir(folder); + } + + return fileWrite(buffer, path, size); + } + else return false; } void fileDelete(const char *path) @@ -81,11 +96,6 @@ void fileDelete(const char *path) f_unlink(path); } -void createDirectory(const char *path) -{ - f_mkdir(path); -} - void loadPayload(u32 pressed) { const char *pattern; diff --git a/source/fs.h b/source/fs.h index 7e7d9a9..d74f24f 100644 --- a/source/fs.h +++ b/source/fs.h @@ -33,6 +33,5 @@ u32 fileRead(void *dest, const char *path); u32 getFileSize(const char *path); bool fileWrite(const void *buffer, const char *path, u32 size); void fileDelete(const char *path); -void createDirectory(const char *path); void loadPayload(u32 pressed); u32 firmRead(void *dest, u32 firmType); \ No newline at end of file diff --git a/source/pin.c b/source/pin.c index 0f52200..e46a1d3 100644 --- a/source/pin.c +++ b/source/pin.c @@ -96,11 +96,7 @@ void newPin(bool allowSkipping) memcpy(pin.hash, tmp, 32); if(!fileWrite(&pin, "/luma/pin.bin", sizeof(PINData))) - { - createDirectory("luma"); - if(!fileWrite(&pin, "/luma/pin.bin", sizeof(PINData))) - error("Error writing the PIN file"); - } + error("Error writing the PIN file"); } bool verifyPin(void)