From 2c428e071a2dae231031e1bb1222120e531299f3 Mon Sep 17 00:00:00 2001 From: otavepto <153766569+otavepto@users.noreply.github.com> Date: Thu, 25 Jan 2024 17:06:45 +0200 Subject: [PATCH] make sure mod path, if relative, would be relative to the lib itself + return utf8 string --- dll/base.cpp | 6 +++--- dll/settings_parser.cpp | 6 ++++-- helpers/common_helpers.cpp | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/dll/base.cpp b/dll/base.cpp index 573c410c..5c3cde81 100644 --- a/dll/base.cpp +++ b/dll/base.cpp @@ -31,9 +31,9 @@ void randombytes(char *buf, size_t size) std::string get_env_variable(std::string name) { - wchar_t env_variable[1024]; + wchar_t env_variable[1024]{}; DWORD ret = GetEnvironmentVariableW(utf8_decode(name).c_str(), env_variable, _countof(env_variable)); - if (ret <= 0) { + if (ret <= 0 || !env_variable[0]) { return std::string(); } @@ -221,7 +221,7 @@ std::string get_full_program_path() return env_program_path; } - std::string program_path; + std::string program_path{}; program_path = get_full_lib_path(); return program_path.substr(0, program_path.rfind(PATH_SEPARATOR)).append(PATH_SEPARATOR); } diff --git a/dll/settings_parser.cpp b/dll/settings_parser.cpp index 0058e5cb..a7f1bae2 100644 --- a/dll/settings_parser.cpp +++ b/dll/settings_parser.cpp @@ -810,7 +810,6 @@ static std::string get_mod_preview_url(const std::string &previewFileName, const static void try_parse_mods_file(class Settings *settings_client, Settings *settings_server, nlohmann::json &mod_items, const std::string &mods_folder) { - for (auto mod = mod_items.begin(); mod != mod_items.end(); ++mod) { try { std::string mod_images_fullpath = Local_Storage::get_game_settings_path() + "mod_images" + PATH_SEPARATOR + std::string(mod.key()); @@ -824,7 +823,10 @@ static void try_parse_mods_file(class Settings *settings_client, Settings *setti newMod.path = mods_folder + PATH_SEPARATOR + std::string(mod.key()); } else { // make sure the path is normalized for current OS, and absolute - newMod.path = std::filesystem::absolute(newMod.path).u8string(); + newMod.path = common_helpers::to_absolute( + newMod.path, + get_full_program_path() + ) } newMod.fileType = k_EWorkshopFileTypeCommunity; diff --git a/helpers/common_helpers.cpp b/helpers/common_helpers.cpp index 59002f98..153539b8 100644 --- a/helpers/common_helpers.cpp +++ b/helpers/common_helpers.cpp @@ -150,7 +150,7 @@ std::string common_helpers::to_absolute(const std::string &path, const std::stri std::filesystem::path(path), base.empty() ? std::filesystem::current_path() : std::filesystem::path(base) ); - return path_abs.string(); + return path_abs.u8string(); } std::wstring common_helpers::to_absolute(const std::wstring &path, const std::wstring &base)