fs: Remove FS::WriteFile function and use it in Config::Save directly

This commit is contained in:
Joel16 2020-09-20 21:24:37 -04:00
parent dff3a6ed5e
commit 580b6d151a
3 changed files with 16 additions and 25 deletions

View File

@ -33,7 +33,6 @@ namespace FS {
Result Paste(void);
Result Move(void);
Result GetFileSize(const char path[FS_MAX_PATH], s64 *size);
Result WriteFile(const char path[FS_MAX_PATH], const void *buf, u64 size);
Result GetFreeStorageSpace(s64 *size);
Result GetTotalStorageSpace(s64 *size);
Result GetUsedStorageSpace(s64 *size);

View File

@ -4,6 +4,7 @@
#include "config.h"
#include "fs.h"
#include "log.h"
#define CONFIG_VERSION 1
@ -19,11 +20,25 @@ namespace Config {
char *buf = new char[buf_size];
u64 len = std::snprintf(buf, buf_size, config_file, CONFIG_VERSION, config.sort, config.dev_options, config.image_filename, config.cwd);
if (R_FAILED(ret = FS::WriteFile("/switch/NX-Shell/config.json", buf, len))) {
// Delete and re-create the file, we don't care about the return value here.
fsFsDeleteFile(fs, "/switch/NX-Shell/config.json");
fsFsCreateFile(fs, "/switch/NX-Shell/config.json", len, 0);
FsFile file;
if (R_FAILED(ret = fsFsOpenFile(fs, "/switch/NX-Shell/config.json", FsOpenMode_Write, &file))) {
Log::Error("fsFsOpenFile(/switch/NX-Shell/config.json) failed: 0x%x\n", ret);
delete[] buf;
return ret;
}
if (R_FAILED(ret = fsFileWrite(&file, 0, buf, len, FsWriteOption_Flush))) {
Log::Error("fsFileWrite(/switch/NX-Shell/config.json) failed: 0x%x\n", ret);
delete[] buf;
fsFileClose(&file);
return ret;
}
fsFileClose(&file);
delete[] buf;
return 0;
}

View File

@ -468,29 +468,6 @@ namespace FS {
return 0;
}
Result WriteFile(const char path[FS_MAX_PATH], const void *buf, u64 size) {
Result ret = 0;
// Delete and re-create the file, we don't care about the return value here.
fsFsDeleteFile(fs, path);
fsFsCreateFile(fs, path, size, 0);
FsFile file;
if (R_FAILED(ret = fsFsOpenFile(fs, path, FsOpenMode_Write, &file))) {
Log::Error("fsFsOpenFile(%s) failed: 0x%x\n", path, ret);
return ret;
}
if (R_FAILED(ret = fsFileWrite(&file, 0, buf, size, FsWriteOption_Flush))) {
Log::Error("fsFileWrite(%s) failed: 0x%x\n", path, ret);
fsFileClose(&file);
return ret;
}
fsFileClose(&file);
return 0;
}
Result GetFreeStorageSpace(s64 *size) {
Result ret = 0;