From 29c2771f5e295189ff279f6cd242b8972b7e58d7 Mon Sep 17 00:00:00 2001 From: Vlad Date: Mon, 12 Dec 2022 07:30:58 +0300 Subject: [PATCH] Fix 'Language' menu exception (#400) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …if config file is not created --- data/cdata/ui_scripts/patches/language.lua | 12 ++++++++---- src/client/component/filesystem.cpp | 7 +++++++ src/client/steam/interfaces/apps.hpp | 3 --- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/data/cdata/ui_scripts/patches/language.lua b/data/cdata/ui_scripts/patches/language.lua index 66cc6159..e9f2219e 100644 --- a/data/cdata/ui_scripts/patches/language.lua +++ b/data/cdata/ui_scripts/patches/language.lua @@ -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, diff --git a/src/client/component/filesystem.cpp b/src/client/component/filesystem.cpp index cc619613..98029d0e 100644 --- a/src/client/component/filesystem.cpp +++ b/src/client/component/filesystem.cpp @@ -14,6 +14,8 @@ #include #include +#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()) diff --git a/src/client/steam/interfaces/apps.hpp b/src/client/steam/interfaces/apps.hpp index 554c461b..9b716cec 100644 --- a/src/client/steam/interfaces/apps.hpp +++ b/src/client/steam/interfaces/apps.hpp @@ -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();