Get rid of createDirectory and make fileWrite handle directory tree creation
This commit is contained in:
parent
7f93733107
commit
f221915a95
@ -56,14 +56,10 @@ void writeConfig(const char *configPath, u32 configTemp)
|
||||
configData.formatVersionMajor = CONFIG_VERSIONMAJOR;
|
||||
configData.formatVersionMinor = CONFIG_VERSIONMINOR;
|
||||
|
||||
if(!fileWrite(&configData, configPath, sizeof(cfgData)))
|
||||
{
|
||||
createDirectory("luma");
|
||||
if(!fileWrite(&configData, configPath, sizeof(cfgData)))
|
||||
error("Error writing the configuration file");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void configMenu(bool oldPinStatus)
|
||||
{
|
||||
|
24
source/fs.c
24
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;
|
||||
|
@ -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);
|
@ -95,13 +95,9 @@ void newPin(bool allowSkipping)
|
||||
computePinHash(tmp, enteredPassword, (PIN_LENGTH + 15) / 16);
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
bool verifyPin(void)
|
||||
{
|
||||
|
Reference in New Issue
Block a user