Remove Boost.Iostreams usage

It's still required by libespm, but using Boost.Filesystem's file
streams has the same unicode path handling benefits without breaking
platform line ending handling.

Unlike the standard library or Boost.Filesystem file streams,
Boost.Iostreams file streams throw if they can't be opened, so a
couple of new checks are added for that.
This commit is contained in:
Oliver Hamlet
2015-12-05 08:51:14 +00:00
parent 3ddd11a9c0
commit b8af63d9eb
14 changed files with 24 additions and 62 deletions
-1
View File
@@ -121,7 +121,6 @@ set (LOOT_HEADERS "${CMAKE_SOURCE_DIR}/src/backend/metadata/condition_grammar.h"
"${CMAKE_SOURCE_DIR}/src/backend/helpers/git_helper.h"
"${CMAKE_SOURCE_DIR}/src/backend/helpers/helpers.h"
"${CMAKE_SOURCE_DIR}/src/backend/helpers/language.h"
"${CMAKE_SOURCE_DIR}/src/backend/helpers/streams.h"
"${CMAKE_SOURCE_DIR}/src/backend/helpers/version.h"
"${CMAKE_SOURCE_DIR}/src/backend/helpers/yaml_set_helpers.h"
"${CMAKE_SOURCE_DIR}/src/backend/globals.h"
+3 -3
View File
@@ -26,7 +26,6 @@
#include "../backend/game/game.h"
#include "../backend/globals.h"
#include "../backend/error.h"
#include "../backend/helpers/streams.h"
#include "../backend/plugin_sorter.h"
#include <yaml-cpp/yaml.h>
@@ -40,6 +39,7 @@
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/log/core.hpp>
const unsigned int loot_ok = loot::error::ok;
@@ -822,9 +822,9 @@ LOOT_API unsigned int loot_write_minimal_list(loot_db db, const char * const out
boost::filesystem::path p(outputFile);
try {
loot::ofstream out(p);
boost::filesystem::ofstream out(p);
if (out.fail())
return c_error(loot_error_invalid_args, "Couldn't open output file.");
return c_error(loot_error_file_write_fail, "Couldn't open output file.");
out << yout.c_str();
out.close();
}
-1
View File
@@ -26,7 +26,6 @@
#include "../globals.h"
#include "../helpers/helpers.h"
#include "../error.h"
#include "../helpers/streams.h"
#include <thread>
-1
View File
@@ -26,7 +26,6 @@
#include "../globals.h"
#include "../helpers/helpers.h"
#include "../error.h"
#include "../helpers/streams.h"
#include <thread>
+2 -3
View File
@@ -24,17 +24,16 @@
#include "helpers.h"
#include "../error.h"
#include "streams.h"
#include <boost/spirit/include/karma.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/crc.hpp>
#include <boost/log/trivial.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/format.hpp>
#include <boost/locale.hpp>
#include <cstring>
#include <iostream>
#include <cctype>
#include <cstdio>
#include <ctime>
@@ -68,7 +67,7 @@ namespace loot {
uint32_t GetCrc32(const fs::path& filename) {
uint32_t chksum = 0;
try {
loot::ifstream ifile(filename, ios::binary);
fs::ifstream ifile(filename, ios::binary);
BOOST_LOG_TRIVIAL(trace) << "Calculating CRC for: " << filename.string();
boost::crc_32_type result;
if (ifile) {
-36
View File
@@ -1,36 +0,0 @@
/* LOOT
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
Fallout: New Vegas.
Copyright (C) 2013-2015 WrinklyNinja
This file is part of LOOT.
LOOT is free software: you can redistribute
it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
LOOT is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LOOT. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef __LOOT_STREAMS__
#define __LOOT_STREAMS__
#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
namespace loot {
typedef boost::iostreams::stream< boost::iostreams::file_descriptor_sink > ofstream;
typedef boost::iostreams::stream< boost::iostreams::file_descriptor_source > ifstream;
typedef boost::iostreams::stream< boost::iostreams::file_descriptor > fstream;
}
#endif
+6 -3
View File
@@ -25,9 +25,9 @@
#include "metadata_list.h"
#include "globals.h"
#include "error.h"
#include "helpers/streams.h"
#include <boost/algorithm/string.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/log/trivial.hpp>
using namespace std;
@@ -40,7 +40,10 @@ namespace loot {
BOOST_LOG_TRIVIAL(debug) << "Loading file: " << filepath;
loot::ifstream in(filepath);
boost::filesystem::ifstream in(filepath);
if (!in.good())
throw error(error::path_read_fail, "Cannot open " + filepath.string());
YAML::Node metadataList = YAML::Load(in);
in.close();
@@ -70,7 +73,7 @@ namespace loot {
<< YAML::Key << "globals" << YAML::Value << messages
<< YAML::EndMap;
loot::ofstream uout(filepath);
boost::filesystem::ofstream uout(filepath);
uout << yout.c_str();
uout.close();
}
-1
View File
@@ -25,7 +25,6 @@
#include "game/game.h"
#include "error.h"
#include "plugin_sorter.h"
#include "helpers/streams.h"
#include "helpers/helpers.h"
#include <cstdlib>
+3 -3
View File
@@ -28,8 +28,8 @@
#include "../backend/globals.h"
#include "../backend/helpers/helpers.h"
#include "../backend/helpers/language.h"
#include "../backend/helpers/streams.h"
#include <boost/filesystem/fstream.hpp>
#include <boost/format.hpp>
#include <boost/locale.hpp>
#include <boost/log/core.hpp>
@@ -71,7 +71,7 @@ namespace loot {
}
if (fs::exists(g_path_settings)) {
try {
loot::ifstream in(g_path_settings);
fs::ifstream in(g_path_settings);
_settings = YAML::Load(in);
in.close();
}
@@ -271,7 +271,7 @@ namespace loot {
yout.SetIndent(2);
yout << _settings;
loot::ofstream out(loot::g_path_settings);
fs::ofstream out(loot::g_path_settings);
out << yout.c_str();
out.close();
}
+1 -1
View File
@@ -651,7 +651,7 @@ TEST_F(OblivionAPIOperationsTest, WriteMinimalList) {
EXPECT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
EXPECT_EQ(loot_ok, loot_write_minimal_list(db, outputFile.c_str(), false));
loot::ifstream in(outputFile);
boost::filesystem::ifstream in(outputFile);
std::string line;
while (std::getline(in, line)) {
EXPECT_FALSE(boost::contains(line, "- \"-\""));
@@ -127,7 +127,7 @@ TEST_F(LoadOrderHandler, SetLoadOrder) {
EXPECT_NO_THROW(loh.SetLoadOrder(loadOrder));
std::list<std::string> actual;
loot::ifstream in(localPath / "loadorder.txt");
boost::filesystem::ifstream in(localPath / "loadorder.txt");
while (in) {
std::string line;
std::getline(in, line);
+1 -1
View File
@@ -101,7 +101,7 @@ class IsFileDifferent : public ::testing::Test {
ASSERT_TRUE(boost::filesystem::exists(parentRepoRoot / "CONTRIBUTING.md.copy"));
// Edit CONTRIBUTING.md
loot::ofstream out(parentRepoRoot / "CONTRIBUTING.md");
boost::filesystem::ofstream out(parentRepoRoot / "CONTRIBUTING.md");
out.close();
}
+1 -1
View File
@@ -139,7 +139,7 @@ TEST_F(Masterlist, GetInfo_Edited) {
ASSERT_TRUE(masterlist.Update(masterlistPath,
"https://github.com/loot/testing-metadata.git",
"master"));
loot::ofstream out(masterlistPath);
boost::filesystem::ofstream out(masterlistPath);
out.close();
loot::Masterlist::Info info = masterlist.GetInfo(masterlistPath, false);
+6 -6
View File
@@ -25,12 +25,12 @@ along with LOOT. If not, see
#ifndef LOOT_TEST_FIXTURES
#define LOOT_TEST_FIXTURES
#include "backend/helpers/streams.h"
#include "printers.h"
#include <gtest/gtest.h>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
class GameTest : public ::testing::Test {
protected:
@@ -72,7 +72,7 @@ protected:
ASSERT_TRUE(boost::filesystem::exists(dataPath / "Blank - Master Dependent.esm.ghost"));
// Write out an empty file.
loot::ofstream out(dataPath / "EmptyFile.esm");
boost::filesystem::ofstream out(dataPath / "EmptyFile.esm");
out.close();
ASSERT_TRUE(boost::filesystem::exists(dataPath / "EmptyFile.esm"));
@@ -163,7 +163,7 @@ protected:
}
// Set Oblivion's active plugins to a known list before running the test.
loot::ofstream activePlugins(localPath / "plugins.txt");
boost::filesystem::ofstream activePlugins(localPath / "plugins.txt");
activePlugins
<< "Oblivion.esm" << std::endl
<< "Blank.esm" << std::endl;
@@ -183,7 +183,7 @@ protected:
};
inline void GenerateMasterlist() {
loot::ofstream masterlist(masterlistPath);
boost::filesystem::ofstream masterlist(masterlistPath);
masterlist
<< "plugins:" << std::endl
<< " - name: Oblivion.esm" << std::endl
@@ -268,7 +268,7 @@ protected:
ASSERT_TRUE(boost::filesystem::exists(dataPath / "Skyrim.esm"));
// Set Skyrim's load order to a known list before running the test.
loot::ofstream loadOrder(localPath / "loadorder.txt");
boost::filesystem::ofstream loadOrder(localPath / "loadorder.txt");
loadOrder
<< "Skyrim.esm" << std::endl
<< "Blank.esm" << std::endl
@@ -284,7 +284,7 @@ protected:
loadOrder.close();
// Set Skyrim's active plugins to a known list before running the test.
loot::ofstream activePlugins(localPath / "plugins.txt");
boost::filesystem::ofstream activePlugins(localPath / "plugins.txt");
activePlugins
<< "Blank.esm" << std::endl
<< "Blank - Different Master Dependent.esp" << std::endl;