Fix 'Language' menu exception (#400)

…if config file is not created
This commit is contained in:
Vlad 2022-12-12 07:30:58 +03:00 committed by GitHub
parent e883a16d0c
commit f79a7d5537
3 changed files with 15 additions and 7 deletions

View File

@ -1,14 +1,14 @@
local available_languages = {"english", "english_safe", "french", "german", "italian", "polish", "portuguese",
"russian", "spanish", "simplified_chinese", "traditional_chinese", "japanese_partial",
"korean"}
local current_language = "english"
local current_language = "LANGUAGE"
LUI.UIButtonText.IsOffsetedLanguage = function()
return false
end
function get_current_language()
current_language = game:getcurrentgamelanguage()
function get_user_language()
user_language = game:getcurrentgamelanguage()
end
function set_language(value)
@ -22,7 +22,11 @@ function does_zone_folder_exists(language)
return io.directoryexists("zone/" .. language)
end
get_current_language()
get_user_language()
if user_language ~= "" and does_zone_folder_exists(user_language) then
current_language = user_language
end
LUI.addmenubutton("pc_controls", {
index = 4,

View File

@ -14,6 +14,8 @@
#include <utils/hook.hpp>
#include <utils/properties.hpp>
#define LANGUAGE_FILE "players2/default/language"
namespace filesystem
{
namespace
@ -57,6 +59,11 @@ namespace filesystem
const auto code = game::SEH_GetCurrentLanguageName();
if (!::utils::io::file_exists(LANGUAGE_FILE) or ::utils::io::file_size(LANGUAGE_FILE) == 0)
{
::utils::io::write_file(LANGUAGE_FILE, code);
}
paths.push_back(path);
if (is_fallback_lang())

View File

@ -25,9 +25,6 @@ namespace steam
strcpy_s(language, sizeof(language), content.data());
return;
}
// default to english if no file is found
strcpy_s(language, sizeof(language), "english");
}
virtual bool BIsSubscribed();