diff options
| author | 2019-05-23 13:52:40 -0400 | |
|---|---|---|
| committer | 2019-05-23 13:52:43 -0400 | |
| commit | 2b1fcc8a14d93c16ce00e1a9888e3f4f839f18f9 (patch) | |
| tree | 129596d2ff096166c68af0f39ebf6dda8d7a7ff9 | |
| parent | common/file_util: Remove unnecessary c_str() calls (diff) | |
| download | yuzu-2b1fcc8a14d93c16ce00e1a9888e3f4f839f18f9.tar.gz yuzu-2b1fcc8a14d93c16ce00e1a9888e3f4f839f18f9.tar.xz yuzu-2b1fcc8a14d93c16ce00e1a9888e3f4f839f18f9.zip | |
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.
| -rw-r--r-- | src/common/file_util.cpp | 6 | ||||
| -rw-r--r-- | src/common/file_util.h | 4 | ||||
| -rw-r--r-- | src/yuzu_cmd/config.cpp | 4 |
3 files changed, 7 insertions, 7 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index aecb66c32..8a902dd68 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp | |||
| @@ -762,11 +762,11 @@ std::string GetNANDRegistrationDir(bool system) { | |||
| 762 | return GetUserPath(UserPath::NANDDir) + "user/Contents/registered/"; | 762 | return GetUserPath(UserPath::NANDDir) + "user/Contents/registered/"; |
| 763 | } | 763 | } |
| 764 | 764 | ||
| 765 | std::size_t WriteStringToFile(bool text_file, const std::string& str, const char* filename) { | 765 | std::size_t WriteStringToFile(bool text_file, const std::string& filename, std::string_view str) { |
| 766 | return FileUtil::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size()); | 766 | return IOFile(filename, text_file ? "w" : "wb").WriteString(str); |
| 767 | } | 767 | } |
| 768 | 768 | ||
| 769 | std::size_t ReadFileToString(bool text_file, const char* filename, std::string& str) { | 769 | std::size_t ReadFileToString(bool text_file, const std::string& filename, std::string& str) { |
| 770 | IOFile file(filename, text_file ? "r" : "rb"); | 770 | IOFile file(filename, text_file ? "r" : "rb"); |
| 771 | 771 | ||
| 772 | if (!file.IsOpen()) | 772 | if (!file.IsOpen()) |
diff --git a/src/common/file_util.h b/src/common/file_util.h index 88760be2f..c325f5b49 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h | |||
| @@ -146,9 +146,9 @@ const std::string& GetExeDirectory(); | |||
| 146 | std::string AppDataRoamingDirectory(); | 146 | std::string AppDataRoamingDirectory(); |
| 147 | #endif | 147 | #endif |
| 148 | 148 | ||
| 149 | std::size_t WriteStringToFile(bool text_file, const std::string& str, const char* filename); | 149 | std::size_t WriteStringToFile(bool text_file, const std::string& filename, std::string_view str); |
| 150 | 150 | ||
| 151 | std::size_t ReadFileToString(bool text_file, const char* filename, std::string& str); | 151 | std::size_t ReadFileToString(bool text_file, const std::string& filename, std::string& str); |
| 152 | 152 | ||
| 153 | /** | 153 | /** |
| 154 | * Splits the filename into 8.3 format | 154 | * Splits the filename into 8.3 format |
diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index d0ae058fd..730956427 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp | |||
| @@ -26,12 +26,12 @@ Config::Config() { | |||
| 26 | Config::~Config() = default; | 26 | Config::~Config() = default; |
| 27 | 27 | ||
| 28 | bool Config::LoadINI(const std::string& default_contents, bool retry) { | 28 | bool Config::LoadINI(const std::string& default_contents, bool retry) { |
| 29 | const char* location = this->sdl2_config_loc.c_str(); | 29 | const std::string& location = this->sdl2_config_loc; |
| 30 | if (sdl2_config->ParseError() < 0) { | 30 | if (sdl2_config->ParseError() < 0) { |
| 31 | if (retry) { | 31 | if (retry) { |
| 32 | LOG_WARNING(Config, "Failed to load {}. Creating file from defaults...", location); | 32 | LOG_WARNING(Config, "Failed to load {}. Creating file from defaults...", location); |
| 33 | FileUtil::CreateFullPath(location); | 33 | FileUtil::CreateFullPath(location); |
| 34 | FileUtil::WriteStringToFile(true, default_contents, location); | 34 | FileUtil::WriteStringToFile(true, location, default_contents); |
| 35 | sdl2_config = std::make_unique<INIReader>(location); // Reopen file | 35 | sdl2_config = std::make_unique<INIReader>(location); // Reopen file |
| 36 | 36 | ||
| 37 | return LoadINI(default_contents, false); | 37 | return LoadINI(default_contents, false); |