diff --git a/CMakeLists.txt b/CMakeLists.txt
index c0198e3d..19f2568b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -181,8 +181,8 @@ set (LOOT_SRC "${CMAKE_BINARY_DIR}/generated/loot_version.cpp"
"${CMAKE_SOURCE_DIR}/src/backend/masterlist.cpp"
"${CMAKE_SOURCE_DIR}/src/backend/plugin/plugin.cpp"
"${CMAKE_SOURCE_DIR}/src/backend/plugin/plugin_sorter.cpp"
+ "${CMAKE_SOURCE_DIR}/src/backend/helpers/crc.cpp"
"${CMAKE_SOURCE_DIR}/src/backend/helpers/git_helper.cpp"
- "${CMAKE_SOURCE_DIR}/src/backend/helpers/helpers.cpp"
"${CMAKE_SOURCE_DIR}/src/backend/helpers/language.cpp"
"${CMAKE_SOURCE_DIR}/src/backend/helpers/version.cpp")
@@ -196,7 +196,7 @@ set (LOOT_HEADERS "${CMAKE_SOURCE_DIR}/src/backend/metadata/condition_evaluator.
"${CMAKE_SOURCE_DIR}/src/backend/plugin/plugin.h"
"${CMAKE_SOURCE_DIR}/src/backend/plugin/plugin_sorter.h"
"${CMAKE_SOURCE_DIR}/src/backend/helpers/git_helper.h"
- "${CMAKE_SOURCE_DIR}/src/backend/helpers/helpers.h"
+ "${CMAKE_SOURCE_DIR}/src/backend/helpers/crc.h"
"${CMAKE_SOURCE_DIR}/src/backend/helpers/version.h"
"${CMAKE_SOURCE_DIR}/include/loot/api_decorator.h"
"${CMAKE_SOURCE_DIR}/include/loot/exception/error_categories.h"
@@ -225,6 +225,7 @@ set (LOOT_HEADERS "${CMAKE_SOURCE_DIR}/src/backend/metadata/condition_evaluator.
"${CMAKE_SOURCE_DIR}/include/loot/yaml/plugin_metadata.h"
"${CMAKE_SOURCE_DIR}/include/loot/yaml/set.h"
"${CMAKE_SOURCE_DIR}/include/loot/yaml/tag.h"
+ "${CMAKE_SOURCE_DIR}/include/loot/windows_encoding_converters.h"
"${CMAKE_SOURCE_DIR}/include/loot/language.h"
"${CMAKE_SOURCE_DIR}/include/loot/loot_version.h")
@@ -315,7 +316,7 @@ set (LOOT_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/backend/game/game_test.h"
"${CMAKE_SOURCE_DIR}/src/tests/backend/game/game_cache_test.h"
"${CMAKE_SOURCE_DIR}/src/tests/backend/game/load_order_handler_test.h"
"${CMAKE_SOURCE_DIR}/src/tests/backend/helpers/git_helper_test.h"
- "${CMAKE_SOURCE_DIR}/src/tests/backend/helpers/helpers_test.h"
+ "${CMAKE_SOURCE_DIR}/src/tests/backend/helpers/crc_test.h"
"${CMAKE_SOURCE_DIR}/src/tests/backend/helpers/language_test.h"
"${CMAKE_SOURCE_DIR}/src/tests/backend/helpers/version_test.h"
"${CMAKE_SOURCE_DIR}/src/tests/backend/helpers/yaml_set_helpers_test.h"
diff --git a/include/loot/windows_encoding_converters.h b/include/loot/windows_encoding_converters.h
new file mode 100644
index 00000000..1f378c4b
--- /dev/null
+++ b/include/loot/windows_encoding_converters.h
@@ -0,0 +1,60 @@
+/* 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_BACKEND_HELPERS_HELPERS
+#define LOOT_BACKEND_HELPERS_HELPERS
+
+#ifdef _WIN32
+
+#include
+
+# ifndef UNICODE
+# define UNICODE
+# endif
+# ifndef _UNICODE
+# define _UNICODE
+# endif
+# include "windows.h"
+# include "shlobj.h"
+# include "shlwapi.h"
+
+namespace loot {
+inline std::wstring ToWinWide(const std::string& str) {
+ size_t len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), 0, 0);
+ std::wstring wstr(len, 0);
+ MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), &wstr[0], len);
+ return wstr;
+}
+
+inline std::string FromWinWide(const std::wstring& wstr) {
+ size_t len = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), wstr.length(), NULL, 0, NULL, NULL);
+ std::string str(len, 0);
+ WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), wstr.length(), &str[0], len, NULL, NULL);
+ return str;
+}
+}
+
+#endif
+
+#endif
diff --git a/src/backend/game/game.cpp b/src/backend/game/game.cpp
index 26d2ad3c..68a6f4b1 100644
--- a/src/backend/game/game.cpp
+++ b/src/backend/game/game.cpp
@@ -35,7 +35,6 @@
#include "loot/exception/file_access_error.h"
#include "loot/exception/game_detection_error.h"
-#include "backend/helpers/helpers.h"
#ifdef _WIN32
# ifndef UNICODE
diff --git a/src/backend/game/game_cache.cpp b/src/backend/game/game_cache.cpp
index 65f25e87..aab860a0 100644
--- a/src/backend/game/game_cache.cpp
+++ b/src/backend/game/game_cache.cpp
@@ -30,8 +30,6 @@
#include
#include
-#include "backend/helpers/helpers.h"
-
using boost::locale::to_lower;
using std::lock_guard;
using std::mutex;
diff --git a/src/backend/helpers/helpers.cpp b/src/backend/helpers/crc.cpp
similarity index 69%
rename from src/backend/helpers/helpers.cpp
rename to src/backend/helpers/crc.cpp
index 858d1dc8..9e7b9d3f 100644
--- a/src/backend/helpers/helpers.cpp
+++ b/src/backend/helpers/crc.cpp
@@ -22,17 +22,8 @@
.
*/
-#include "backend/helpers/helpers.h"
+#include "backend/helpers/crc.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
#include
#include
#include
@@ -40,18 +31,6 @@
#include "loot/exception/file_access_error.h"
-#ifdef _WIN32
-# ifndef UNICODE
-# define UNICODE
-# endif
-# ifndef _UNICODE
-# define _UNICODE
-# endif
-# include "windows.h"
-# include "shlobj.h"
-# include "shlwapi.h"
-#endif
-
using std::string;
using std::wstring;
@@ -62,7 +41,7 @@ size_t GetStreamSize(std::istream& stream) {
stream.seekg(0, std::ios_base::end);
size_t streamSize = stream.tellg();
stream.seekg(startingPosition, std::ios_base::beg);
-
+
return streamSize;
}
@@ -91,26 +70,9 @@ uint32_t GetCrc32(const boost::filesystem::path& filename) {
uint32_t checksum = result.checksum();
BOOST_LOG_TRIVIAL(debug) << "CRC32(\"" << filename.string() << "\"): " << std::hex << checksum << std::dec;
return checksum;
-
+
} catch (std::exception& e) {
throw FileAccessError((boost::format("Unable to open \"%1%\" for CRC calculation: %2%") % filename.string() % e.what()).str());
}
}
-
-#ifdef _WIN32
-//Helper to turn UTF8 strings into strings that can be used by WinAPI.
-std::wstring ToWinWide(const std::string& str) {
- size_t len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), 0, 0);
- wstring wstr(len, 0);
- MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), &wstr[0], len);
- return wstr;
-}
-
-std::string FromWinWide(const std::wstring& wstr) {
- size_t len = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), wstr.length(), NULL, 0, NULL, NULL);
- string str(len, 0);
- WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), wstr.length(), &str[0], len, NULL, NULL);
- return str;
-}
-#endif
}
diff --git a/src/backend/helpers/helpers.h b/src/backend/helpers/crc.h
similarity index 76%
rename from src/backend/helpers/helpers.h
rename to src/backend/helpers/crc.h
index 3e419d20..40529fac 100644
--- a/src/backend/helpers/helpers.h
+++ b/src/backend/helpers/crc.h
@@ -22,23 +22,15 @@
.
*/
-#ifndef LOOT_BACKEND_HELPERS_HELPERS
-#define LOOT_BACKEND_HELPERS_HELPERS
+#ifndef LOOT_BACKEND_HELPERS_CRC
+#define LOOT_BACKEND_HELPERS_CRC
-#include
-#include
+#include
#include
namespace loot {
- //Calculate the CRC of the given file for comparison purposes.
uint32_t GetCrc32(const boost::filesystem::path& filename);
-
-#ifdef _WIN32
-std::wstring ToWinWide(const std::string& str);
-
-std::string FromWinWide(const std::wstring& wstr);
-#endif
}
#endif
diff --git a/src/backend/helpers/version.cpp b/src/backend/helpers/version.cpp
index bfacfea5..23449cd2 100644
--- a/src/backend/helpers/version.cpp
+++ b/src/backend/helpers/version.cpp
@@ -28,7 +28,7 @@
#include
#include
-#include "backend/helpers/helpers.h"
+#include "loot/windows_encoding_converters.h"
#ifdef _WIN32
# ifndef UNICODE
diff --git a/src/backend/metadata/condition_evaluator.cpp b/src/backend/metadata/condition_evaluator.cpp
index 236b36c9..9edd695b 100644
--- a/src/backend/metadata/condition_evaluator.cpp
+++ b/src/backend/metadata/condition_evaluator.cpp
@@ -28,7 +28,7 @@
#include
#include
-#include "backend/helpers/helpers.h"
+#include "backend/helpers/crc.h"
#include "loot/exception/condition_syntax_error.h"
using boost::format;
diff --git a/src/backend/metadata/condition_grammar.h b/src/backend/metadata/condition_grammar.h
index 2cb10d1f..33cff7dd 100644
--- a/src/backend/metadata/condition_grammar.h
+++ b/src/backend/metadata/condition_grammar.h
@@ -47,7 +47,6 @@
#include "loot/exception/condition_syntax_error.h"
#include "backend/game/game.h"
-#include "backend/helpers/helpers.h"
#include "backend/helpers/version.h"
#include "backend/metadata/condition_evaluator.h"
#include "backend/plugin/plugin.h"
diff --git a/src/backend/metadata/plugin_cleaning_data.cpp b/src/backend/metadata/plugin_cleaning_data.cpp
index c4cf3fb7..ac4750a5 100644
--- a/src/backend/metadata/plugin_cleaning_data.cpp
+++ b/src/backend/metadata/plugin_cleaning_data.cpp
@@ -29,7 +29,7 @@
#include
#include "backend/game/game.h"
-#include "backend/helpers/helpers.h"
+#include "backend/helpers/crc.h"
namespace loot {
PluginCleaningData::PluginCleaningData() : crc_(0), itm_(0), ref_(0), nav_(0) {}
diff --git a/src/backend/metadata/plugin_metadata.cpp b/src/backend/metadata/plugin_metadata.cpp
index 98dd70e5..d3b5291b 100644
--- a/src/backend/metadata/plugin_metadata.cpp
+++ b/src/backend/metadata/plugin_metadata.cpp
@@ -33,7 +33,6 @@
#include
#include "backend/game/game.h"
-#include "backend/helpers/helpers.h"
using std::inserter;
using std::regex;
diff --git a/src/backend/plugin/plugin.cpp b/src/backend/plugin/plugin.cpp
index 00f7cc82..6a1b0360 100644
--- a/src/backend/plugin/plugin.cpp
+++ b/src/backend/plugin/plugin.cpp
@@ -33,7 +33,7 @@
#include
#include "backend/game/game.h"
-#include "backend/helpers/helpers.h"
+#include "backend/helpers/crc.h"
#include "backend/helpers/version.h"
using libespm::FormId;
diff --git a/src/backend/plugin/plugin_sorter.cpp b/src/backend/plugin/plugin_sorter.cpp
index d1b9beec..544fc999 100644
--- a/src/backend/plugin/plugin_sorter.cpp
+++ b/src/backend/plugin/plugin_sorter.cpp
@@ -36,7 +36,6 @@
#include "loot/exception/cyclic_interaction_error.h"
#include "backend/game/game.h"
-#include "backend/helpers/helpers.h"
using std::list;
using std::string;
diff --git a/src/gui/helpers.cpp b/src/gui/helpers.cpp
index 599e2e10..13d822d9 100644
--- a/src/gui/helpers.cpp
+++ b/src/gui/helpers.cpp
@@ -24,7 +24,7 @@
#include "gui/helpers.h"
-#include "backend/helpers/helpers.h"
+#include "loot/windows_encoding_converters.h"
#ifdef _WIN32
# ifndef UNICODE
diff --git a/src/gui/loot_app.cpp b/src/gui/loot_app.cpp
index 5899438c..ea45f16c 100644
--- a/src/gui/loot_app.cpp
+++ b/src/gui/loot_app.cpp
@@ -29,7 +29,6 @@
#include
#include "gui/state/loot_paths.h"
-#include "backend/helpers/helpers.h"
#include "loot/language.h"
#include "gui/loot_handler.h"
#include "gui/loot_scheme_handler_factory.h"
diff --git a/src/gui/query/clipboard_query.h b/src/gui/query/clipboard_query.h
index a2f9e550..78a53a93 100644
--- a/src/gui/query/clipboard_query.h
+++ b/src/gui/query/clipboard_query.h
@@ -25,8 +25,8 @@ along with LOOT. If not, see
#ifndef LOOT_GUI_QUERY_CLIPBOARD_QUERY
#define LOOT_GUI_QUERY_CLIPBOARD_QUERY
-#include "backend/helpers/helpers.h"
#include "gui/query/query.h"
+#include "loot/windows_encoding_converters.h"
namespace loot {
class ClipboardQuery : public Query {
diff --git a/src/gui/state/game.cpp b/src/gui/state/game.cpp
index fb96ed57..911ba03a 100644
--- a/src/gui/state/game.cpp
+++ b/src/gui/state/game.cpp
@@ -35,7 +35,7 @@
#include "loot/exception/file_access_error.h"
#include "loot/exception/game_detection_error.h"
-#include "backend/helpers/helpers.h"
+#include "loot/windows_encoding_converters.h"
#ifdef _WIN32
# ifndef UNICODE
diff --git a/src/gui/state/game_settings.cpp b/src/gui/state/game_settings.cpp
index 6f003227..81d0cc09 100644
--- a/src/gui/state/game_settings.cpp
+++ b/src/gui/state/game_settings.cpp
@@ -28,8 +28,6 @@
#include
#include
-#include "backend/helpers/helpers.h"
-
namespace fs = boost::filesystem;
namespace loot {
diff --git a/src/gui/state/loot_paths.cpp b/src/gui/state/loot_paths.cpp
index 31148687..1a232ea9 100644
--- a/src/gui/state/loot_paths.cpp
+++ b/src/gui/state/loot_paths.cpp
@@ -28,7 +28,7 @@ Fallout: New Vegas.
#include
-#include "backend/helpers/helpers.h"
+#include "loot/windows_encoding_converters.h"
#ifdef _WIN32
# ifndef UNICODE
diff --git a/src/gui/state/loot_state.cpp b/src/gui/state/loot_state.cpp
index d8a9ca65..6e544066 100644
--- a/src/gui/state/loot_state.cpp
+++ b/src/gui/state/loot_state.cpp
@@ -35,11 +35,11 @@
#include
#include
-#include "loot/exception/game_detection_error.h"
-#include "backend/helpers/helpers.h"
-#include "loot/language.h"
#include "gui/state/loot_paths.h"
+#include "loot/exception/game_detection_error.h"
+#include "loot/language.h"
#include "loot/loot_version.h"
+#include "loot/windows_encoding_converters.h"
#ifdef _WIN32
#include
diff --git a/src/tests/backend/helpers/helpers_test.h b/src/tests/backend/helpers/crc_test.h
similarity index 92%
rename from src/tests/backend/helpers/helpers_test.h
rename to src/tests/backend/helpers/crc_test.h
index b9e59575..0eb2e878 100644
--- a/src/tests/backend/helpers/helpers_test.h
+++ b/src/tests/backend/helpers/crc_test.h
@@ -22,10 +22,10 @@ along with LOOT. If not, see
.
*/
-#ifndef LOOT_TESTS_BACKEND_HELPERS_HELPERS_TEST
-#define LOOT_TESTS_BACKEND_HELPERS_HELPERS_TEST
+#ifndef LOOT_TESTS_BACKEND_HELPERS_CRC_TEST
+#define LOOT_TESTS_BACKEND_HELPERS_CRC_TEST
-#include "backend/helpers/helpers.h"
+#include "backend/helpers/crc.h"
#include "loot/exception/file_access_error.h"
#include "tests/common_game_test_fixture.h"
diff --git a/src/tests/backend/main.cpp b/src/tests/backend/main.cpp
index a4ddb982..efc9c281 100644
--- a/src/tests/backend/main.cpp
+++ b/src/tests/backend/main.cpp
@@ -27,8 +27,8 @@
#include "tests/backend/game/game_test.h"
#include "tests/backend/game/game_cache_test.h"
#include "tests/backend/game/load_order_handler_test.h"
+#include "tests/backend/helpers/crc_test.h"
#include "tests/backend/helpers/git_helper_test.h"
-#include "tests/backend/helpers/helpers_test.h"
#include "tests/backend/helpers/language_test.h"
#include "tests/backend/helpers/version_test.h"
#include "tests/backend/helpers/yaml_set_helpers_test.h"