Fix MSVC warnings

The size_t to int conversion is unavoidable, but at least it's now explicit.
This commit is contained in:
Oliver Hamlet
2022-02-06 17:45:06 +00:00
parent 3d8a6453a4
commit 5cf9b0dd4c
3 changed files with 58 additions and 45 deletions
+4 -4
View File
@@ -25,12 +25,11 @@
#include "api/game/game.h"
#include <algorithm>
#include <boost/algorithm/string.hpp>
#include <cmath>
#include <map>
#include <thread>
#include <boost/algorithm/string.hpp>
#include "api/api_database.h"
#include "api/helpers/logging.h"
#include "api/sorting/plugin_sort.h"
@@ -128,9 +127,9 @@ void Game::LoadPlugins(const std::vector<std::string>& plugins,
threadsToUse = ::std::max(threadsToUse, (size_t)1);
// Divide the plugins up by thread.
unsigned int pluginsPerThread = ceil((double)sizeMap.size() / threadsToUse);
vector<vector<string>> pluginGroups(threadsToUse);
if (logger) {
auto pluginsPerThread = sizeMap.size() / threadsToUse;
logger->info(
"Loading {} plugins using {} threads, with up to {} plugins per "
"thread.",
@@ -224,7 +223,8 @@ std::vector<std::string> Game::SortPlugins(
void Game::LoadCurrentLoadOrderState() {
loadOrderHandler_->LoadCurrentState();
conditionEvaluator_->RefreshActivePluginsState(loadOrderHandler_->GetActivePlugins());
conditionEvaluator_->RefreshActivePluginsState(
loadOrderHandler_->GetActivePlugins());
}
bool Game::IsPluginActive(const std::string& pluginName) const {
+29 -34
View File
@@ -32,26 +32,26 @@ using std::string;
namespace loot {
unsigned int mapGameId(GameType gameType) {
switch (gameType) {
case GameType::tes3:
return LIBLO_GAME_TES3;
case GameType::tes4:
return LIBLO_GAME_TES4;
case GameType::tes5:
return LIBLO_GAME_TES5;
case GameType::tes5se:
return LIBLO_GAME_TES5SE;
case GameType::tes5vr:
return LIBLO_GAME_TES5VR;
case GameType::fo3:
return LIBLO_GAME_FO3;
case GameType::fonv:
return LIBLO_GAME_FNV;
case GameType::fo4:
return LIBLO_GAME_FO4;
case GameType::fo4vr:
return LIBLO_GAME_FO4VR;
default:
return (unsigned int)-1;
case GameType::tes3:
return LIBLO_GAME_TES3;
case GameType::tes4:
return LIBLO_GAME_TES4;
case GameType::tes5:
return LIBLO_GAME_TES5;
case GameType::tes5se:
return LIBLO_GAME_TES5SE;
case GameType::tes5vr:
return LIBLO_GAME_TES5VR;
case GameType::fo3:
return LIBLO_GAME_FO3;
case GameType::fonv:
return LIBLO_GAME_FNV;
case GameType::fo4:
return LIBLO_GAME_FO4;
case GameType::fo4vr:
return LIBLO_GAME_FO4VR;
default:
return (unsigned int)-1;
}
}
@@ -77,8 +77,10 @@ void LoadOrderHandler::Init(const GameType& gameType,
gh_ = nullptr;
}
int ret = lo_create_handle(
&gh_, mapGameId(gameType), gamePath.u8string().c_str(), gameLocalDataPath);
int ret = lo_create_handle(&gh_,
mapGameId(gameType),
gamePath.u8string().c_str(),
gameLocalDataPath);
HandleError("create a game handle", ret);
}
@@ -136,8 +138,7 @@ std::vector<std::string> LoadOrderHandler::GetActivePlugins() const {
char** pluginArr;
size_t pluginArrSize;
unsigned int ret =
lo_get_active_plugins(gh_, &pluginArr, &pluginArrSize);
unsigned int ret = lo_get_active_plugins(gh_, &pluginArr, &pluginArrSize);
HandleError("get active plugins", ret);
@@ -174,23 +175,17 @@ void LoadOrderHandler::SetLoadOrder(
logger->info("Setting load order.");
}
size_t pluginArrSize = loadOrder.size();
char** pluginArr = new char*[pluginArrSize];
int i = 0;
std::vector<const char*> plugins;
plugins.reserve(loadOrder.size());
for (const auto& plugin : loadOrder) {
if (logger) {
logger->info("\t\t{}", plugin);
}
pluginArr[i] = new char[plugin.length() + 1];
strcpy(pluginArr[i], plugin.c_str());
++i;
plugins.push_back(plugin.c_str());
}
unsigned int ret = lo_set_load_order(gh_, pluginArr, pluginArrSize);
for (size_t i = 0; i < pluginArrSize; i++) delete[] pluginArr[i];
delete[] pluginArr;
unsigned int ret = lo_set_load_order(gh_, plugins.data(), plugins.size());
HandleError("set the load order", ret);
+25 -7
View File
@@ -126,28 +126,46 @@ std::optional<std::string> ExtractVersion(const std::string& text) {
#ifdef _WIN32
std::wstring ToWinWide(const std::string& str) {
size_t len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), 0, 0);
size_t len = MultiByteToWideChar(
CP_UTF8, 0, str.c_str(), static_cast<int>(str.length()), 0, 0);
if (len == 0) {
return std::wstring();
}
std::wstring wstr(len, 0);
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), &wstr[0], len);
MultiByteToWideChar(CP_UTF8,
0,
str.c_str(),
static_cast<int>(str.length()),
&wstr[0],
static_cast<int>(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);
size_t len = WideCharToMultiByte(CP_UTF8,
0,
wstr.c_str(),
static_cast<int>(wstr.length()),
NULL,
0,
NULL,
NULL);
if (len == 0) {
return std::string();
}
std::string str(len, 0);
WideCharToMultiByte(
CP_UTF8, 0, wstr.c_str(), wstr.length(), &str[0], len, NULL, NULL);
WideCharToMultiByte(CP_UTF8,
0,
wstr.c_str(),
static_cast<int>(wstr.length()),
&str[0],
static_cast<int>(len),
NULL,
NULL);
return str;
}
#endif
@@ -185,7 +203,7 @@ std::string NormalizeFilename(const std::string& filename) {
return std::string();
}
CharUpperBuffW(&wideString[0], wideString.length());
CharUpperBuffW(&wideString[0], static_cast<int>(wideString.length()));
return FromWinWide(wideString);
#else
std::string normalizedFilename;