mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Split backend helpers.h up
windows_encoding_converters.h contains the ToWinWide/FromWinWide functions shared by the API and GUI, and crc.h contains GetCrc32().
This commit is contained in:
+4
-3
@@ -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"
|
||||
|
||||
@@ -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
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LOOT_BACKEND_HELPERS_HELPERS
|
||||
#define LOOT_BACKEND_HELPERS_HELPERS
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <string>
|
||||
|
||||
# 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
|
||||
@@ -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
|
||||
|
||||
@@ -30,8 +30,6 @@
|
||||
#include <boost/locale.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
#include "backend/helpers/helpers.h"
|
||||
|
||||
using boost::locale::to_lower;
|
||||
using std::lock_guard;
|
||||
using std::mutex;
|
||||
|
||||
@@ -22,17 +22,8 @@
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "backend/helpers/helpers.h"
|
||||
#include "backend/helpers/crc.h"
|
||||
|
||||
#include <cctype>
|
||||
#include <codecvt>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <locale>
|
||||
#include <sstream>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/crc.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/format.hpp>
|
||||
@@ -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
|
||||
}
|
||||
@@ -22,23 +22,15 @@
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LOOT_BACKEND_HELPERS_HELPERS
|
||||
#define LOOT_BACKEND_HELPERS_HELPERS
|
||||
#ifndef LOOT_BACKEND_HELPERS_CRC
|
||||
#define LOOT_BACKEND_HELPERS_CRC
|
||||
|
||||
#include <regex>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
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
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <pseudosem.h>
|
||||
|
||||
#include "backend/helpers/helpers.h"
|
||||
#include "loot/windows_encoding_converters.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
# ifndef UNICODE
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
#include "backend/helpers/helpers.h"
|
||||
#include "backend/helpers/crc.h"
|
||||
#include "loot/exception/condition_syntax_error.h"
|
||||
|
||||
using boost::format;
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
#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) {}
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
#include "backend/game/game.h"
|
||||
#include "backend/helpers/helpers.h"
|
||||
|
||||
using std::inserter;
|
||||
using std::regex;
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include <boost/locale.hpp>
|
||||
|
||||
#include "backend/game/game.h"
|
||||
#include "backend/helpers/helpers.h"
|
||||
#include "backend/helpers/crc.h"
|
||||
#include "backend/helpers/version.h"
|
||||
|
||||
using libespm::FormId;
|
||||
|
||||
@@ -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;
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "gui/helpers.h"
|
||||
|
||||
#include "backend/helpers/helpers.h"
|
||||
#include "loot/windows_encoding_converters.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
# ifndef UNICODE
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <include/cef_task.h>
|
||||
|
||||
#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"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
#include <boost/locale.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
#include "backend/helpers/helpers.h"
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace loot {
|
||||
|
||||
@@ -28,7 +28,7 @@ Fallout: New Vegas.
|
||||
|
||||
#include <boost/locale.hpp>
|
||||
|
||||
#include "backend/helpers/helpers.h"
|
||||
#include "loot/windows_encoding_converters.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
# ifndef UNICODE
|
||||
|
||||
@@ -35,11 +35,11 @@
|
||||
#include <boost/log/utility/setup/common_attributes.hpp>
|
||||
#include <boost/log/utility/setup/file.hpp>
|
||||
|
||||
#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 <windows.h>
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user