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

@ -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");
}
}

View File

@ -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;

View File

@ -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);

View File

@ -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)