diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index 22f8df849b..7eed3f08f4 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -935,14 +935,14 @@ std::string GetThemeDir(const std::string& theme_name) return dir; } -bool WriteStringToFile(bool text_file, const std::string &str, const char *filename) +bool WriteStringToFile(const std::string &str, const char *filename) { - return File::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size()); + return File::IOFile(filename, "wb").WriteBytes(str.data(), str.size()); } -bool ReadFileToString(bool text_file, const char *filename, std::string &str) +bool ReadFileToString(const char *filename, std::string &str) { - File::IOFile file(filename, text_file ? "r" : "rb"); + File::IOFile file(filename, "rb"); auto const f = file.GetHandle(); if (!f) @@ -952,29 +952,6 @@ bool ReadFileToString(bool text_file, const char *filename, std::string &str) str.resize(GetSize(f)); bool retval = file.ReadArray(&str[0], str.size(), &read_size); - // On Windows, reading a text file automatically translates \r\n to \n. - // This means we will read less characters than the expected size of the - // file. In that case, ignore the return value and count ourselves. -#ifdef _WIN32 - if (text_file) - { - size_t count = 0; - for (size_t i = 0; i < read_size; ++i) - { - if (str[i] == '\n') - count += 2; - else - count += 1; - } - - if (count != str.size()) - return false; - - str.resize(read_size); - return true; - } -#endif - return retval; } diff --git a/Source/Core/Common/Src/FileUtil.h b/Source/Core/Common/Src/FileUtil.h index 43482ffb32..b39135fa41 100644 --- a/Source/Core/Common/Src/FileUtil.h +++ b/Source/Core/Common/Src/FileUtil.h @@ -143,8 +143,8 @@ std::string GetBundleDirectory(); std::string &GetExeDirectory(); #endif -bool WriteStringToFile(bool text_file, const std::string &str, const char *filename); -bool ReadFileToString(bool text_file, const char *filename, std::string &str); +bool WriteStringToFile(const std::string &str, const char *filename); +bool ReadFileToString(const char *filename, std::string &str); // simple wrapper for cstdlib file functions to // hopefully will make error checking easier diff --git a/Source/Core/Core/Src/Boot/Boot.cpp b/Source/Core/Core/Src/Boot/Boot.cpp index 97888c995c..7691421623 100644 --- a/Source/Core/Core/Src/Boot/Boot.cpp +++ b/Source/Core/Core/Src/Boot/Boot.cpp @@ -151,7 +151,7 @@ bool CBoot::Load_BS2(const std::string& _rBootROMFilename) // Load the whole ROM dump std::string data; - if (!File::ReadFileToString(false, _rBootROMFilename.c_str(), data)) + if (!File::ReadFileToString(_rBootROMFilename.c_str(), data)) return false; u32 ipl_hash = HashAdler32((const u8*)data.data(), data.size()); diff --git a/Source/Core/Core/Src/DSP/DSPCodeUtil.cpp b/Source/Core/Core/Src/DSP/DSPCodeUtil.cpp index e769723b1d..afaaa7d22e 100644 --- a/Source/Core/Core/Src/DSP/DSPCodeUtil.cpp +++ b/Source/Core/Core/Src/DSP/DSPCodeUtil.cpp @@ -206,7 +206,7 @@ void BinaryStringBEToCode(const std::string &str, std::vector &code) bool LoadBinary(const char *filename, std::vector &code) { std::string buffer; - if (!File::ReadFileToString(false, filename, buffer)) + if (!File::ReadFileToString(filename, buffer)) return false; BinaryStringBEToCode(buffer, code); @@ -217,7 +217,7 @@ bool SaveBinary(const std::vector &code, const char *filename) { std::string buffer; CodeToBinaryStringBE(code, buffer); - if (!File::WriteStringToFile(false, buffer, filename)) + if (!File::WriteStringToFile(buffer, filename)) return false; return true; } diff --git a/Source/Core/Core/Src/DSP/assemble.cpp b/Source/Core/Core/Src/DSP/assemble.cpp index a8ddebf113..7ae9346f29 100644 --- a/Source/Core/Core/Src/DSP/assemble.cpp +++ b/Source/Core/Core/Src/DSP/assemble.cpp @@ -99,7 +99,7 @@ bool DSPAssembler::Assemble(const char *text, std::vector &code, std::vecto if (line_numbers) line_numbers->clear(); const char *fname = "tmp.asm"; - if (!File::WriteStringToFile(true, text, fname)) + if (!File::WriteStringToFile(text, fname)) return false; InitPass(1); if (!AssembleFile(fname, 1)) diff --git a/Source/Core/Core/Src/GeckoCode.cpp b/Source/Core/Core/Src/GeckoCode.cpp index c791eeb31d..5e4102474f 100644 --- a/Source/Core/Core/Src/GeckoCode.cpp +++ b/Source/Core/Core/Src/GeckoCode.cpp @@ -145,7 +145,7 @@ bool InstallCodeHandler() u32 codelist_location = 0x800028B8; // Debugger on location (0x800022A8 = Debugger off, using codehandleronly.bin) std::string data; std::string _rCodeHandlerFilename = File::GetSysDirectory() + GECKO_CODE_HANDLER; - if (!File::ReadFileToString(false, _rCodeHandlerFilename.c_str(), data)) + if (!File::ReadFileToString(_rCodeHandlerFilename.c_str(), data)) return false; // Install code handler diff --git a/Source/Core/Core/Src/HW/DSPLLE/DSPLLETools.cpp b/Source/Core/Core/Src/HW/DSPLLE/DSPLLETools.cpp index c2ee99f5ee..d0f50834a2 100644 --- a/Source/Core/Core/Src/HW/DSPLLE/DSPLLETools.cpp +++ b/Source/Core/Core/Src/HW/DSPLLE/DSPLLETools.cpp @@ -55,7 +55,7 @@ bool DumpDSPCode(const u8 *code_be, int size_in_bytes, u32 crc) if (!disasm.Disassemble(0, code, 0x0000, text)) return false; - return File::WriteStringToFile(true, text, txtFile); + return File::WriteStringToFile(text, txtFile); } // TODO make this useful :p diff --git a/Source/Core/DiscIO/Src/VolumeDirectory.cpp b/Source/Core/DiscIO/Src/VolumeDirectory.cpp index b949932b0b..f9f8f00ea8 100644 --- a/Source/Core/DiscIO/Src/VolumeDirectory.cpp +++ b/Source/Core/DiscIO/Src/VolumeDirectory.cpp @@ -287,7 +287,7 @@ bool CVolumeDirectory::SetApploader(const std::string& _rApploader) if (!_rApploader.empty()) { std::string data; - if (!File::ReadFileToString(false, _rApploader.c_str(), data)) + if (!File::ReadFileToString(_rApploader.c_str(), data)) { PanicAlertT("Apploader unable to load from file"); return false; @@ -320,7 +320,7 @@ void CVolumeDirectory::SetDOL(const std::string& _rDOL) if (!_rDOL.empty()) { std::string data; - File::ReadFileToString(false, _rDOL.c_str(), data); + File::ReadFileToString(_rDOL.c_str(), data); m_DOLSize = data.size(); m_DOL = new u8[m_DOLSize]; copy(data.begin(), data.end(), m_DOL); diff --git a/Source/Core/VideoBackends/OGL/Src/PostProcessing.cpp b/Source/Core/VideoBackends/OGL/Src/PostProcessing.cpp index 5d7fff3110..84fb0c4d1c 100644 --- a/Source/Core/VideoBackends/OGL/Src/PostProcessing.cpp +++ b/Source/Core/VideoBackends/OGL/Src/PostProcessing.cpp @@ -157,7 +157,7 @@ void ApplyShader() // Fallback to shared user dir path = File::GetSysDirectory() + SHADERS_DIR DIR_SEP + g_ActiveConfig.sPostProcessingShader + ".glsl"; } - if(!File::ReadFileToString(true, path.c_str(), code)) { + if(!File::ReadFileToString(path.c_str(), code)) { ERROR_LOG(VIDEO, "Post-processing shader not found: %s", path.c_str()); return; } diff --git a/Source/Core/VideoCommon/Src/Debugger.cpp b/Source/Core/VideoCommon/Src/Debugger.cpp index 85a9ba61f6..321fed8291 100644 --- a/Source/Core/VideoCommon/Src/Debugger.cpp +++ b/Source/Core/VideoCommon/Src/Debugger.cpp @@ -108,7 +108,7 @@ void GFXDebuggerBase::DumpPixelShader(const char* path) } File::CreateEmptyFile(filename); - File::WriteStringToFile(true, output, filename); + File::WriteStringToFile(output, filename); } void GFXDebuggerBase::DumpVertexShader(const char* path) @@ -117,7 +117,7 @@ void GFXDebuggerBase::DumpVertexShader(const char* path) sprintf(filename, "%sdump_vs.txt", path); File::CreateEmptyFile(filename); -/// File::WriteStringToFile(true, GenerateVertexShaderCode(g_nativeVertexFmt->m_components, g_ActiveConfig.backend_info.APIType), filename); +/// File::WriteStringToFile(GenerateVertexShaderCode(g_nativeVertexFmt->m_components, g_ActiveConfig.backend_info.APIType), filename); } void GFXDebuggerBase::DumpPixelShaderConstants(const char* path) diff --git a/Source/Core/VideoCommon/Src/OpenCL/OCLTextureDecoder.cpp b/Source/Core/VideoCommon/Src/OpenCL/OCLTextureDecoder.cpp index 211244c457..daea0bfca1 100644 --- a/Source/Core/VideoCommon/Src/OpenCL/OCLTextureDecoder.cpp +++ b/Source/Core/VideoCommon/Src/OpenCL/OCLTextureDecoder.cpp @@ -140,7 +140,7 @@ void TexDecoder_OpenCL_Initialize() { std::string code; filename = File::GetSysDirectory() + OPENCL_DIR DIR_SEP "TextureDecoder.cl"; - if (!File::ReadFileToString(true, filename.c_str(), code)) + if (!File::ReadFileToString(filename.c_str(), code)) { ERROR_LOG(VIDEO, "Failed to load OpenCL code %s - file is missing?", filename.c_str()); return; diff --git a/Source/DSPTool/Src/DSPTool.cpp b/Source/DSPTool/Src/DSPTool.cpp index f5dcb18694..9f38b1347b 100644 --- a/Source/DSPTool/Src/DSPTool.cpp +++ b/Source/DSPTool/Src/DSPTool.cpp @@ -72,8 +72,8 @@ bool SuperTrip(const char *asm_code) std::string text2; Disassemble(code1, true, &text1); Disassemble(code2, true, &text2); - File::WriteStringToFile(true, text1, "code1.txt"); - File::WriteStringToFile(true, text2, "code2.txt"); + File::WriteStringToFile(text1, "code1.txt"); + File::WriteStringToFile(text2, "code2.txt"); */ return true; } @@ -126,7 +126,7 @@ void RunAsmTests() /* std::vector code; std::string text_orig; - File::ReadFileToString(false, "testdata/dsp_test.S", &text_orig); + File::ReadFileToString("testdata/dsp_test.S", &text_orig); if (!Assemble(text_orig.c_str(), &code)) { printf("SuperTrip: First assembly failed\n"); @@ -168,15 +168,15 @@ void RunAsmTests() RoundTrip(rand_code); - if (File::ReadFileToString(true, "C:/devkitPro/examples/wii/asndlib/dsptest/dsp_test.ds", &dsp_test)) + if (File::ReadFileToString("C:/devkitPro/examples/wii/asndlib/dsptest/dsp_test.ds", &dsp_test)) SuperTrip(dsp_test.c_str()); - //.File::ReadFileToString(true, "C:/devkitPro/trunk/libogc/libasnd/dsp_mixer/dsp_mixer.s", &dsp_test); + //.File::ReadFileToString("C:/devkitPro/trunk/libogc/libasnd/dsp_mixer/dsp_mixer.s", &dsp_test); // This is CLOSE to working. Sorry about the local path btw. This is preliminary code. */ std::string dsp_test; - if (File::ReadFileToString(true, "Testdata/dsp_test.s", dsp_test)) + if (File::ReadFileToString("Testdata/dsp_test.s", dsp_test)) fail = fail || !SuperTrip(dsp_test.c_str()); if (!fail) printf("All passed!\n"); @@ -288,9 +288,9 @@ int main(int argc, const char *argv[]) // Two binary inputs, let's diff. std::string binary_code; std::vector code1, code2; - File::ReadFileToString(false, input_name.c_str(), binary_code); + File::ReadFileToString(input_name.c_str(), binary_code); BinaryStringBEToCode(binary_code, code1); - File::ReadFileToString(false, output_name.c_str(), binary_code); + File::ReadFileToString(output_name.c_str(), binary_code); BinaryStringBEToCode(binary_code, code2); Compare(code1, code2); return 0; @@ -301,7 +301,7 @@ int main(int argc, const char *argv[]) std::string dumpfile, results; std::vector reg_vector; - File::ReadFileToString(false, input_name.c_str(), dumpfile); + File::ReadFileToString(input_name.c_str(), dumpfile); BinaryStringBEToCode(dumpfile, reg_vector); results.append("Start:\n"); @@ -362,7 +362,7 @@ int main(int argc, const char *argv[]) } if (!output_name.empty()) - File::WriteStringToFile(true, results, output_name.c_str()); + File::WriteStringToFile(results, output_name.c_str()); else printf("%s", results.c_str()); return 0; @@ -377,12 +377,12 @@ int main(int argc, const char *argv[]) } std::string binary_code; std::vector code; - File::ReadFileToString(false, input_name.c_str(), binary_code); + File::ReadFileToString(input_name.c_str(), binary_code); BinaryStringBEToCode(binary_code, code); std::string text; Disassemble(code, true, text); if (!output_name.empty()) - File::WriteStringToFile(true, text, output_name.c_str()); + File::WriteStringToFile(text, output_name.c_str()); else printf("%s", text.c_str()); } @@ -394,7 +394,7 @@ int main(int argc, const char *argv[]) return 1; } std::string source; - if (File::ReadFileToString(true, input_name.c_str(), source)) + if (File::ReadFileToString(input_name.c_str(), source)) { if(multiple) { @@ -429,7 +429,7 @@ int main(int argc, const char *argv[]) for (int i = 0; i < lines; i++) { - if (!File::ReadFileToString(true, files[i].c_str(), currentSource)) + if (!File::ReadFileToString(files[i].c_str(), currentSource)) { printf("ERROR reading %s, skipping...\n", files[i].c_str()); lines--; @@ -450,7 +450,7 @@ int main(int argc, const char *argv[]) CodesToHeader(codes, &files, lines, output_header_name.c_str(), header); - File::WriteStringToFile(true, header, (output_header_name + ".h").c_str()); + File::WriteStringToFile(header, (output_header_name + ".h").c_str()); delete[] codes; } @@ -471,13 +471,13 @@ int main(int argc, const char *argv[]) { std::string binary_code; CodeToBinaryStringBE(code, binary_code); - File::WriteStringToFile(false, binary_code, output_name.c_str()); + File::WriteStringToFile(binary_code, output_name.c_str()); } if (!output_header_name.empty()) { std::string header; CodeToHeader(code, input_name, output_header_name.c_str(), header); - File::WriteStringToFile(true, header, (output_header_name + ".h").c_str()); + File::WriteStringToFile(header, (output_header_name + ".h").c_str()); } } }