make sure mod path, if relative, would be relative to the lib itself + return utf8 string

This commit is contained in:
otavepto 2024-01-25 17:06:45 +02:00
parent 0e4b6e85e0
commit 2c428e071a
3 changed files with 8 additions and 6 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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)