Changed a number of stream operations to open files in binary mode to always get proper Unix line breaks

This commit is contained in:
Leon Styhre 2023-08-10 23:02:36 +02:00
parent b218c4806b
commit de4bd7341f
4 changed files with 16 additions and 13 deletions

View file

@ -155,9 +155,10 @@ void CollectionSystemsManager::saveCustomCollection(SystemData* sys)
#if defined(_WIN64)
configFileIn.open(
Utils::String::stringToWideString(getCustomCollectionConfigPath(name)).c_str());
Utils::String::stringToWideString(getCustomCollectionConfigPath(name)).c_str(),
std::ios::binary);
#else
configFileIn.open(getCustomCollectionConfigPath(name));
configFileIn.open(getCustomCollectionConfigPath(name), std::ios::binary);
#endif
for (std::string gameEntry; getline(configFileIn, gameEntry);) {
std::string gamePath {Utils::String::replace(gameEntry, "%ROMPATH%", rompath)};
@ -187,9 +188,10 @@ void CollectionSystemsManager::saveCustomCollection(SystemData* sys)
#if defined(_WIN64)
configFileOut.open(
Utils::String::stringToWideString(getCustomCollectionConfigPath(name)).c_str());
Utils::String::stringToWideString(getCustomCollectionConfigPath(name)).c_str(),
std::ios::binary);
#else
configFileOut.open(getCustomCollectionConfigPath(name));
configFileOut.open(getCustomCollectionConfigPath(name), std::ios::binary);
#endif
for (auto it = fileGameEntries.cbegin(); it != fileGameEntries.cend(); ++it)
@ -1035,9 +1037,9 @@ void CollectionSystemsManager::reactivateCustomCollectionEntry(FileData* game)
std::string path {getCustomCollectionConfigPath(it->first)};
if (Utils::FileSystem::exists(path)) {
#if defined(_WIN64)
std::ifstream input(Utils::String::stringToWideString(path).c_str());
std::ifstream input {Utils::String::stringToWideString(path).c_str(), std::ios::binary};
#else
std::ifstream input(path);
std::ifstream input {path, std::ios::binary};
#endif
for (std::string gameKey; getline(input, gameKey);) {
if (gameKey == gamePath) {
@ -1283,9 +1285,9 @@ void CollectionSystemsManager::populateCustomCollection(CollectionSystemData* sy
// Get configuration for this custom collection.
#if defined(_WIN64)
std::ifstream input(Utils::String::stringToWideString(path).c_str());
std::ifstream input {Utils::String::stringToWideString(path).c_str(), std::ios::binary};
#else
std::ifstream input(path);
std::ifstream input {path, std::ios::binary};
#endif
// Get all files map.

View file

@ -726,9 +726,10 @@ void GuiOrphanedDataCleanup::cleanupCollections()
std::ifstream configFileSource;
#if defined(_WIN64)
configFileSource.open(Utils::String::stringToWideString(collectionFile).c_str());
configFileSource.open(Utils::String::stringToWideString(collectionFile).c_str(),
std::ios::binary);
#else
configFileSource.open(collectionFile);
configFileSource.open(collectionFile, std::ios::binary);
#endif
if (!configFileSource.good()) {
LOG(LogError) << "Couldn't open custom collection configuration file \""

View file

@ -146,7 +146,7 @@ bool TheGamesDBJSONRequestResources::saveResource(HttpReq* req,
ensureScrapersResourcesDir();
std::ofstream fout {file_name};
std::ofstream fout {file_name, std::ios::binary};
fout << req->getContent();
fout.close();
loadResource(resource, resource_name, file_name);
@ -165,7 +165,7 @@ int TheGamesDBJSONRequestResources::loadResource(std::unordered_map<int, std::st
const std::string& resource_name,
const std::string& file_name)
{
std::ifstream fin {file_name};
std::ifstream fin {file_name, std::ios::binary};
if (!fin.good())
return 1;

View file

@ -275,7 +275,7 @@ namespace Utils
Utils::Platform::runSystemCommand("flatpak-spawn --host which " + *it + "/" +
executable + " > " + tempFile + " 2>/dev/null");
std::ifstream tempFileStream;
tempFileStream.open(tempFile);
tempFileStream.open(tempFile, std::ios::binary);
getline(tempFileStream, emulatorPath);
tempFileStream.close();