yuzu-emu
/
yuzu-mainline
Archived
1
0
Fork 0

common/file_util: Make ReadFileToString and WriteStringToFile consistent

Makes the parameter ordering consistent, and also makes the filename
parameter a std::string. A std::string would be constructed anyways with
the previous code, as IOFile's only constructor with a filepath is one
taking a std::string.

We can also make WriteStringToFile's string parameter utilize a
std::string_view for the string, making use of our previous changes to
IOFile.
This commit is contained in:
Lioncash 2019-05-23 13:52:40 -04:00
parent e3b2539986
commit 2b1fcc8a14
3 changed files with 7 additions and 7 deletions

View File

@ -762,11 +762,11 @@ std::string GetNANDRegistrationDir(bool system) {
return GetUserPath(UserPath::NANDDir) + "user/Contents/registered/"; return GetUserPath(UserPath::NANDDir) + "user/Contents/registered/";
} }
std::size_t WriteStringToFile(bool text_file, const std::string& str, const char* filename) { std::size_t WriteStringToFile(bool text_file, const std::string& filename, std::string_view str) {
return FileUtil::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size()); return IOFile(filename, text_file ? "w" : "wb").WriteString(str);
} }
std::size_t ReadFileToString(bool text_file, const char* filename, std::string& str) { std::size_t ReadFileToString(bool text_file, const std::string& filename, std::string& str) {
IOFile file(filename, text_file ? "r" : "rb"); IOFile file(filename, text_file ? "r" : "rb");
if (!file.IsOpen()) if (!file.IsOpen())

View File

@ -146,9 +146,9 @@ const std::string& GetExeDirectory();
std::string AppDataRoamingDirectory(); std::string AppDataRoamingDirectory();
#endif #endif
std::size_t WriteStringToFile(bool text_file, const std::string& str, const char* filename); std::size_t WriteStringToFile(bool text_file, const std::string& filename, std::string_view str);
std::size_t ReadFileToString(bool text_file, const char* filename, std::string& str); std::size_t ReadFileToString(bool text_file, const std::string& filename, std::string& str);
/** /**
* Splits the filename into 8.3 format * Splits the filename into 8.3 format

View File

@ -26,12 +26,12 @@ Config::Config() {
Config::~Config() = default; Config::~Config() = default;
bool Config::LoadINI(const std::string& default_contents, bool retry) { bool Config::LoadINI(const std::string& default_contents, bool retry) {
const char* location = this->sdl2_config_loc.c_str(); const std::string& location = this->sdl2_config_loc;
if (sdl2_config->ParseError() < 0) { if (sdl2_config->ParseError() < 0) {
if (retry) { if (retry) {
LOG_WARNING(Config, "Failed to load {}. Creating file from defaults...", location); LOG_WARNING(Config, "Failed to load {}. Creating file from defaults...", location);
FileUtil::CreateFullPath(location); FileUtil::CreateFullPath(location);
FileUtil::WriteStringToFile(true, default_contents, location); FileUtil::WriteStringToFile(true, location, default_contents);
sdl2_config = std::make_unique<INIReader>(location); // Reopen file sdl2_config = std::make_unique<INIReader>(location); // Reopen file
return LoadINI(default_contents, false); return LoadINI(default_contents, false);