Common/FileUtil: Make WriteStringToFile consistent with ReadFileToString
Makes the parameter ordering consistent and less error-prone.
This commit is contained in:
parent
992c8bfc4e
commit
eb475025b8
|
@ -887,7 +887,7 @@ std::string GetThemeDir(const std::string& theme_name)
|
||||||
return GetSysDirectory() + THEMES_DIR "/" DEFAULT_THEME_DIR "/";
|
return GetSysDirectory() + THEMES_DIR "/" DEFAULT_THEME_DIR "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WriteStringToFile(const std::string& str, const std::string& filename)
|
bool WriteStringToFile(const std::string& filename, const std::string& str)
|
||||||
{
|
{
|
||||||
return File::IOFile(filename, "wb").WriteBytes(str.data(), str.size());
|
return File::IOFile(filename, "wb").WriteBytes(str.data(), str.size());
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,7 +198,7 @@ std::string GetBundleDirectory();
|
||||||
std::string GetExePath();
|
std::string GetExePath();
|
||||||
std::string GetExeDirectory();
|
std::string GetExeDirectory();
|
||||||
|
|
||||||
bool WriteStringToFile(const std::string& str, const std::string& filename);
|
bool WriteStringToFile(const std::string& filename, const std::string& str);
|
||||||
bool ReadFileToString(const std::string& filename, std::string& str);
|
bool ReadFileToString(const std::string& filename, std::string& str);
|
||||||
|
|
||||||
// To deal with Windows being dumb at unicode:
|
// To deal with Windows being dumb at unicode:
|
||||||
|
|
|
@ -141,7 +141,7 @@ bool SaveBinary(const std::vector<u16>& code, const std::string& filename)
|
||||||
{
|
{
|
||||||
const std::string buffer = CodeToBinaryStringBE(code);
|
const std::string buffer = CodeToBinaryStringBE(code);
|
||||||
|
|
||||||
return File::WriteStringToFile(buffer, filename);
|
return File::WriteStringToFile(filename, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DumpDSPCode(const u8* code_be, int size_in_bytes, u32 crc)
|
bool DumpDSPCode(const u8* code_be, int size_in_bytes, u32 crc)
|
||||||
|
@ -166,7 +166,7 @@ bool DumpDSPCode(const u8* code_be, int size_in_bytes, u32 crc)
|
||||||
if (!Disassemble(code, true, text))
|
if (!Disassemble(code, true, text))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return File::WriteStringToFile(text, text_file);
|
return File::WriteStringToFile(text_file, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace DSP
|
} // namespace DSP
|
||||||
|
|
|
@ -265,7 +265,7 @@ void GameFile::DownloadDefaultCover()
|
||||||
if (!response)
|
if (!response)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
File::WriteStringToFile(std::string(response->begin(), response->end()), png_path);
|
File::WriteStringToFile(png_path, std::string(response->begin(), response->end()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameFile::DefaultCoverChanged()
|
bool GameFile::DefaultCoverChanged()
|
||||||
|
|
|
@ -255,7 +255,7 @@ bool DownloadContent(const std::vector<TodoList::DownloadOp>& to_download,
|
||||||
std::optional<std::string> maybe_decompressed = GzipInflate(contents);
|
std::optional<std::string> maybe_decompressed = GzipInflate(contents);
|
||||||
if (!maybe_decompressed)
|
if (!maybe_decompressed)
|
||||||
return false;
|
return false;
|
||||||
std::string decompressed = std::move(*maybe_decompressed);
|
const std::string decompressed = std::move(*maybe_decompressed);
|
||||||
|
|
||||||
// Check that the downloaded contents have the right hash.
|
// Check that the downloaded contents have the right hash.
|
||||||
Manifest::Hash contents_hash = ComputeHash(decompressed);
|
Manifest::Hash contents_hash = ComputeHash(decompressed);
|
||||||
|
@ -265,8 +265,8 @@ bool DownloadContent(const std::vector<TodoList::DownloadOp>& to_download,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string out = temp_path + DIR_SEP + hash_filename;
|
const std::string out = temp_path + DIR_SEP + hash_filename;
|
||||||
if (!File::WriteStringToFile(decompressed, out))
|
if (!File::WriteStringToFile(out, decompressed))
|
||||||
{
|
{
|
||||||
fprintf(log_fp, "Could not write cache file %s.\n", out.c_str());
|
fprintf(log_fp, "Could not write cache file %s.\n", out.c_str());
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -217,7 +217,7 @@ static void PrintResults(const std::string& input_name, const std::string& outpu
|
||||||
if (output_name.empty())
|
if (output_name.empty())
|
||||||
printf("%s", results.c_str());
|
printf("%s", results.c_str());
|
||||||
else
|
else
|
||||||
File::WriteStringToFile(results, output_name.c_str());
|
File::WriteStringToFile(output_name, results);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool PerformDisassembly(const std::string& input_name, const std::string& output_name)
|
static bool PerformDisassembly(const std::string& input_name, const std::string& output_name)
|
||||||
|
@ -237,7 +237,7 @@ static bool PerformDisassembly(const std::string& input_name, const std::string&
|
||||||
if (output_name.empty())
|
if (output_name.empty())
|
||||||
printf("%s", text.c_str());
|
printf("%s", text.c_str());
|
||||||
else
|
else
|
||||||
File::WriteStringToFile(text, output_name);
|
File::WriteStringToFile(output_name, text);
|
||||||
|
|
||||||
printf("Disassembly completed successfully!\n");
|
printf("Disassembly completed successfully!\n");
|
||||||
return true;
|
return true;
|
||||||
|
@ -314,7 +314,7 @@ static bool PerformAssembly(const std::string& input_name, const std::string& ou
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string header = CodesToHeader(codes, files);
|
const std::string header = CodesToHeader(codes, files);
|
||||||
File::WriteStringToFile(header, output_header_name + ".h");
|
File::WriteStringToFile(output_header_name + ".h", header);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -334,12 +334,12 @@ static bool PerformAssembly(const std::string& input_name, const std::string& ou
|
||||||
if (!output_name.empty())
|
if (!output_name.empty())
|
||||||
{
|
{
|
||||||
const std::string binary_code = DSP::CodeToBinaryStringBE(code);
|
const std::string binary_code = DSP::CodeToBinaryStringBE(code);
|
||||||
File::WriteStringToFile(binary_code, output_name);
|
File::WriteStringToFile(output_name, binary_code);
|
||||||
}
|
}
|
||||||
if (!output_header_name.empty())
|
if (!output_header_name.empty())
|
||||||
{
|
{
|
||||||
const std::string header = CodeToHeader(code, input_name);
|
const std::string header = CodeToHeader(code, input_name);
|
||||||
File::WriteStringToFile(header, output_header_name + ".h");
|
File::WriteStringToFile(output_header_name + ".h", header);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue