Get rid of createDirectory and make fileWrite handle directory tree creation

This commit is contained in:
Aurora 2016-08-30 16:56:19 +02:00
parent 7f93733107
commit f221915a95
4 changed files with 19 additions and 18 deletions

View File

@ -56,14 +56,10 @@ void writeConfig(const char *configPath, u32 configTemp)
configData.formatVersionMajor = CONFIG_VERSIONMAJOR; configData.formatVersionMajor = CONFIG_VERSIONMAJOR;
configData.formatVersionMinor = CONFIG_VERSIONMINOR; configData.formatVersionMinor = CONFIG_VERSIONMINOR;
if(!fileWrite(&configData, configPath, sizeof(cfgData)))
{
createDirectory("luma");
if(!fileWrite(&configData, configPath, sizeof(cfgData))) if(!fileWrite(&configData, configPath, sizeof(cfgData)))
error("Error writing the configuration file"); error("Error writing the configuration file");
} }
} }
}
void configMenu(bool oldPinStatus) void configMenu(bool oldPinStatus)
{ {

View File

@ -64,7 +64,9 @@ bool fileWrite(const void *buffer, const char *path, u32 size)
{ {
FIL file; 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; unsigned int written;
f_write(&file, buffer, size, &written); f_write(&file, buffer, size, &written);
@ -72,8 +74,21 @@ bool fileWrite(const void *buffer, const char *path, u32 size)
return true; 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) void fileDelete(const char *path)
@ -81,11 +96,6 @@ void fileDelete(const char *path)
f_unlink(path); f_unlink(path);
} }
void createDirectory(const char *path)
{
f_mkdir(path);
}
void loadPayload(u32 pressed) void loadPayload(u32 pressed)
{ {
const char *pattern; const char *pattern;

View File

@ -33,6 +33,5 @@ u32 fileRead(void *dest, const char *path);
u32 getFileSize(const char *path); u32 getFileSize(const char *path);
bool fileWrite(const void *buffer, const char *path, u32 size); bool fileWrite(const void *buffer, const char *path, u32 size);
void fileDelete(const char *path); void fileDelete(const char *path);
void createDirectory(const char *path);
void loadPayload(u32 pressed); void loadPayload(u32 pressed);
u32 firmRead(void *dest, u32 firmType); u32 firmRead(void *dest, u32 firmType);

View File

@ -95,13 +95,9 @@ void newPin(bool allowSkipping)
computePinHash(tmp, enteredPassword, (PIN_LENGTH + 15) / 16); computePinHash(tmp, enteredPassword, (PIN_LENGTH + 15) / 16);
memcpy(pin.hash, tmp, 32); memcpy(pin.hash, tmp, 32);
if(!fileWrite(&pin, "/luma/pin.bin", sizeof(PINData)))
{
createDirectory("luma");
if(!fileWrite(&pin, "/luma/pin.bin", sizeof(PINData))) if(!fileWrite(&pin, "/luma/pin.bin", sizeof(PINData)))
error("Error writing the PIN file"); error("Error writing the PIN file");
} }
}
bool verifyPin(void) bool verifyPin(void)
{ {