Settings: more specific read and write mode
For each filesystem interaction be more specific if we want to read from the file or write to it. Doing a non-creating read on the loading of the settings file, otherwise an empty file could be created, and when reading that empty file for the initial settings I would expect an error (or random data) when reading.
This commit is contained in:
parent
dd47ba9782
commit
5613449bfb
|
@ -26,7 +26,7 @@ void Settings::LoadSettingsFromFile() {
|
|||
SettingsData bufferSettings;
|
||||
lfs_file_t settingsFile;
|
||||
|
||||
if ( fs.FileOpen(&settingsFile, "/settings.dat", LFS_O_RDWR | LFS_O_CREAT) != LFS_ERR_OK) {
|
||||
if ( fs.FileOpen(&settingsFile, "/settings.dat", LFS_O_RDONLY) != LFS_ERR_OK) {
|
||||
return;
|
||||
}
|
||||
fs.FileRead(&settingsFile, reinterpret_cast<uint8_t*>(&bufferSettings), sizeof(settings));
|
||||
|
@ -39,7 +39,7 @@ void Settings::LoadSettingsFromFile() {
|
|||
void Settings::SaveSettingsToFile() {
|
||||
lfs_file_t settingsFile;
|
||||
|
||||
if ( fs.FileOpen(&settingsFile, "/settings.dat", LFS_O_RDWR | LFS_O_CREAT) != LFS_ERR_OK) {
|
||||
if ( fs.FileOpen(&settingsFile, "/settings.dat", LFS_O_WRONLY | LFS_O_CREAT) != LFS_ERR_OK) {
|
||||
return;
|
||||
}
|
||||
fs.FileWrite(&settingsFile, reinterpret_cast<uint8_t*>(&settings), sizeof(settings));
|
||||
|
|
Loading…
Reference in a new issue