diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0dc7442f..da2572c9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -223,6 +223,7 @@ set (LOOT_HEADERS "${CMAKE_SOURCE_DIR}/src/backend/app/loot_paths.h"
"${CMAKE_SOURCE_DIR}/include/loot/error_categories.h"
"${CMAKE_SOURCE_DIR}/include/loot/exception/condition_syntax_error.h"
"${CMAKE_SOURCE_DIR}/include/loot/exception/cyclic_interaction_error.h"
+ "${CMAKE_SOURCE_DIR}/include/loot/exception/file_access_error.h"
"${CMAKE_SOURCE_DIR}/include/loot/exception/game_detection_error.h"
"${CMAKE_SOURCE_DIR}/include/loot/exception/git_state_error.h"
"${CMAKE_SOURCE_DIR}/include/loot/game_type.h"
@@ -286,6 +287,7 @@ set (LOOT_API_HEADERS "${CMAKE_SOURCE_DIR}/include/loot/api.h"
"${CMAKE_SOURCE_DIR}/include/loot/error_categories.h"
"${CMAKE_SOURCE_DIR}/include/loot/exception/condition_syntax_error.h"
"${CMAKE_SOURCE_DIR}/include/loot/exception/cyclic_interaction_error.h"
+ "${CMAKE_SOURCE_DIR}/include/loot/exception/file_access_error.h"
"${CMAKE_SOURCE_DIR}/include/loot/exception/game_detection_error.h"
"${CMAKE_SOURCE_DIR}/include/loot/exception/git_state_error.h"
"${CMAKE_SOURCE_DIR}/include/loot/game_type.h"
diff --git a/docs/api/reference.rst b/docs/api/reference.rst
index 5199b84f..0450adb7 100644
--- a/docs/api/reference.rst
+++ b/docs/api/reference.rst
@@ -55,6 +55,9 @@ Classes
.. doxygenclass:: loot::ConditionSyntaxError
:members:
+.. doxygenclass:: loot::FileAccessError
+ :members:
+
.. doxygenclass:: loot::Error
:members:
diff --git a/include/loot/api.h b/include/loot/api.h
index f01e8c54..c27a9fa9 100644
--- a/include/loot/api.h
+++ b/include/loot/api.h
@@ -34,6 +34,7 @@
#include "loot/error_categories.h"
#include "loot/exception/condition_syntax_error.h"
#include "loot/exception/cyclic_interaction_error.h"
+#include "loot/exception/file_access_error.h"
#include "loot/exception/game_detection_error.h"
#include "loot/exception/git_state_error.h"
#include "loot/game_type.h"
diff --git a/include/loot/error.h b/include/loot/error.h
index 0462ffb3..da96e8c6 100644
--- a/include/loot/error.h
+++ b/include/loot/error.h
@@ -46,17 +46,11 @@ public:
* failed, but its failure was not fatal to the task being performed.
*/
ok = 0,
- /** An error was encountered when writing a file. */
- path_write_fail = 2,
- /** An error was encountered when reading a file. */
- path_read_fail = 3,
/**
* An error was encountered when attempting to evaluate a metadata
* condition.
*/
condition_eval_fail = 4,
- /** A path could not be found. */
- path_not_found = 9,
};
/**
diff --git a/include/loot/exception/file_access_error.h b/include/loot/exception/file_access_error.h
new file mode 100644
index 00000000..af4ab237
--- /dev/null
+++ b/include/loot/exception/file_access_error.h
@@ -0,0 +1,41 @@
+/* LOOT
+
+ A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
+ Fallout: New Vegas.
+
+ Copyright (C) 2012-2016 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
+ .
+ */
+
+#ifndef LOOT_EXCEPTION_FILE_ACCESS_ERROR
+#define LOOT_EXCEPTION_FILE_ACCESS_ERROR
+
+#include
+
+namespace loot {
+/**
+ * @brief An exception class thrown if an error is encountered while reading or
+ * writing a file.
+ */
+class FileAccessError : public std::runtime_error {
+public:
+ using std::runtime_error::runtime_error;
+};
+}
+
+#endif
diff --git a/resources/l10n/template.pot b/resources/l10n/template.pot
index efb6640e..7ebb30fb 100644
--- a/resources/l10n/template.pot
+++ b/resources/l10n/template.pot
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: LOOT 0.10.0\n"
"Report-Msgid-Bugs-To: https://github.com/loot/loot/issues\n"
-"POT-Creation-Date: 2016-10-07 21:03+0100\n"
+"POT-Creation-Date: 2016-10-07 21:09+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME \n"
"Language-Team: LANGUAGE \n"
@@ -648,15 +648,15 @@ msgstr ""
msgid "None of the supported games were detected."
msgstr ""
-#: src/backend/game/game.cpp:61
+#: src/backend/game/game.cpp:62
msgid "Invalid game ID supplied."
msgstr ""
-#: src/backend/game/game.cpp:68
+#: src/backend/game/game.cpp:69
msgid "Game path could not be detected."
msgstr ""
-#: src/backend/game/game.cpp:78
+#: src/backend/game/game.cpp:79
msgid "Could not create LOOT folder for game. Details:"
msgstr ""
@@ -724,11 +724,11 @@ msgstr ""
msgid "Unknown: Git repository missing"
msgstr ""
-#: src/backend/helpers/helpers.cpp:81
+#: src/backend/helpers/helpers.cpp:82
msgid "Unable to open \"%1%\" for CRC calculation."
msgstr ""
-#: src/backend/helpers/helpers.cpp:122 src/backend/helpers/helpers.cpp:125
+#: src/backend/helpers/helpers.cpp:123 src/backend/helpers/helpers.cpp:126
msgid "Failed to open file in its default application."
msgstr ""
diff --git a/src/api/api_database.cpp b/src/api/api_database.cpp
index 2a5a401c..354dcf87 100644
--- a/src/api/api_database.cpp
+++ b/src/api/api_database.cpp
@@ -28,6 +28,7 @@
#include
#include "loot/error.h"
+#include "loot/exception/file_access_error.h"
#include "backend/game/game.h"
#include "backend/plugin/plugin_sorter.h"
@@ -50,14 +51,14 @@ void ApiDatabase::LoadLists(const std::string& masterlistPath,
if (boost::filesystem::exists(masterlistPath)) {
temp.Load(masterlistPath);
} else {
- throw Error(Error::Code::path_not_found, std::string("The given masterlist path does not exist: ") + masterlistPath);
+ throw FileAccessError("The given masterlist path does not exist: " + masterlistPath);
}
if (!userlistPath.empty()) {
if (boost::filesystem::exists(userlistPath)) {
userTemp.Load(userlistPath);
} else {
- throw Error(Error::Code::path_not_found, std::string("The given userlist path does not exist: ") + userlistPath);
+ throw FileAccessError("The given userlist path does not exist: " + userlistPath);
}
}
@@ -219,7 +220,7 @@ void ApiDatabase::WriteMinimalList(const std::string& outputFile, const bool ove
throw std::invalid_argument("Output directory does not exist.");
if (boost::filesystem::exists(outputFile) && !overwrite)
- throw Error(Error::Code::path_write_fail, "Output file exists but overwrite is not set to true.");
+ throw FileAccessError("Output file exists but overwrite is not set to true.");
Masterlist temp = game_.GetMasterlist();
std::unordered_set minimalPlugins;
@@ -239,7 +240,7 @@ void ApiDatabase::WriteMinimalList(const std::string& outputFile, const bool ove
boost::filesystem::path p(outputFile);
boost::filesystem::ofstream out(p);
if (out.fail())
- throw Error(Error::Code::path_write_fail, "Couldn't open output file.");
+ throw FileAccessError("Couldn't open output file.");
out << yout.c_str();
out.close();
}
diff --git a/src/backend/game/game.cpp b/src/backend/game/game.cpp
index 1bfb6cc8..805877a4 100644
--- a/src/backend/game/game.cpp
+++ b/src/backend/game/game.cpp
@@ -33,6 +33,7 @@
#include "backend/app/loot_paths.h"
#include "loot/error.h"
+#include "loot/exception/file_access_error.h"
#include "loot/exception/game_detection_error.h"
#include "backend/helpers/helpers.h"
@@ -75,7 +76,7 @@ void Game::Init(bool createFolder, const boost::filesystem::path& gameLocalAppDa
fs::create_directories(LootPaths::getLootDataPath() / FolderName());
} catch (fs::filesystem_error& e) {
BOOST_LOG_TRIVIAL(error) << "Could not create LOOT folder for game. Details: " << e.what();
- throw Error(Error::Code::path_write_fail, translate("Could not create LOOT folder for game. Details:").str() + " " + e.what());
+ throw FileAccessError(translate("Could not create LOOT folder for game. Details:").str() + " " + e.what());
}
}
diff --git a/src/backend/helpers/helpers.cpp b/src/backend/helpers/helpers.cpp
index bd458027..aeedd1fb 100644
--- a/src/backend/helpers/helpers.cpp
+++ b/src/backend/helpers/helpers.cpp
@@ -41,6 +41,7 @@
#include
#include "loot/error.h"
+#include "loot/exception/file_access_error.h"
#ifdef _WIN32
# ifndef UNICODE
@@ -78,7 +79,7 @@ uint32_t GetCrc32(const boost::filesystem::path& filename) {
throw std::exception();
} catch (std::exception&) {
BOOST_LOG_TRIVIAL(error) << "Unable to open \"" << filename.string() << "\" for CRC calculation.";
- throw Error(Error::Code::path_read_fail, (boost::format(translate("Unable to open \"%1%\" for CRC calculation.")) % filename.string()).str());
+ throw FileAccessError((boost::format(translate("Unable to open \"%1%\" for CRC calculation.")) % filename.string()).str());
}
BOOST_LOG_TRIVIAL(debug) << "CRC32(\"" << filename.string() << "\"): " << std::hex << chksum << std::dec;
return chksum;
diff --git a/src/backend/metadata_list.cpp b/src/backend/metadata_list.cpp
index 08441a18..fe59e321 100644
--- a/src/backend/metadata_list.cpp
+++ b/src/backend/metadata_list.cpp
@@ -29,6 +29,7 @@
#include
#include "loot/error.h"
+#include "loot/exception/file_access_error.h"
#include "backend/game/game.h"
namespace loot {
@@ -39,7 +40,7 @@ void MetadataList::Load(const boost::filesystem::path& filepath) {
boost::filesystem::ifstream in(filepath);
if (!in.good())
- throw Error(Error::Code::path_read_fail, "Cannot open " + filepath.string());
+ throw FileAccessError("Cannot open " + filepath.string());
YAML::Node metadataList = YAML::Load(in);
in.close();
@@ -49,10 +50,8 @@ void MetadataList::Load(const boost::filesystem::path& filepath) {
PluginMetadata plugin(node.as());
if (plugin.IsRegexPlugin())
regexPlugins_.push_back(plugin);
- else {
- if (!plugins_.insert(plugin).second)
- throw Error(Error::Code::path_read_fail, "More than one entry exists for \"" + plugin.Name() + "\"");
- }
+ else if (!plugins_.insert(plugin).second)
+ throw FileAccessError("More than one entry exists for \"" + plugin.Name() + "\"");
}
}
if (metadataList["globals"])
diff --git a/src/tests/backend/helpers/helpers_test.h b/src/tests/backend/helpers/helpers_test.h
index a85ba53f..6cf4e7d5 100644
--- a/src/tests/backend/helpers/helpers_test.h
+++ b/src/tests/backend/helpers/helpers_test.h
@@ -28,6 +28,7 @@ along with LOOT. If not, see
#include "backend/helpers/helpers.h"
#include "loot/error.h"
+#include "loot/exception/file_access_error.h"
#include "tests/common_game_test_fixture.h"
namespace loot {
@@ -44,7 +45,7 @@ INSTANTIATE_TEST_CASE_P(,
GameType::tes5));
TEST_P(GetCrc32Test, gettingTheCrcOfAMissingFileShouldThrow) {
- EXPECT_THROW(GetCrc32(dataPath / missingEsp), Error);
+ EXPECT_THROW(GetCrc32(dataPath / missingEsp), FileAccessError);
}
TEST_P(GetCrc32Test, gettingTheCrcOfAFileShouldReturnTheCorrectValue) {