Skip to content

Commit

Permalink
Fix regression of loading language files at launch
Browse files Browse the repository at this point in the history
  • Loading branch information
maron2000 committed Sep 18, 2024
1 parent 645d77a commit 09e750d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
20 changes: 11 additions & 9 deletions src/dos/dos_keyboard_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ Bitu DOS_ChangeCodepage(int32_t codepage, const char* codepagefile);
void MSG_Init(), JFONT_Init(), runRescan(const char *str);
extern int tryconvertcp, toSetCodePage(DOS_Shell *shell, int newCP, int opt);
extern bool jfont_init;
extern int msgcodepage;
extern int32_t msgcodepage;
bool CheckDBCSCP(int32_t codepage);

static FILE* OpenDosboxFile(const char* name) {
uint8_t drive;
Expand Down Expand Up @@ -1392,7 +1393,8 @@ Bitu DOS_LoadKeyboardLayout(const char * layoutname, int32_t codepage, const cha
return kerrcode;
}
// Everything went fine, switch to new layout
loaded_layout=temp_layout;
delete loaded_layout;
loaded_layout=temp_layout;
return KEYB_NOERROR;
}

Expand Down Expand Up @@ -1446,8 +1448,8 @@ class DOS_KeyboardLayout: public Module_base {
DOS_KeyboardLayout(Section* configuration):Module_base(configuration){
const Section_prop* section = static_cast<Section_prop*>(configuration);
const char * layoutname=section->Get_string("keyboardlayout");
dos.loaded_codepage = GetDefaultCP(); // default codepage already initialized
int tocp=!strcmp(layoutname, "jp")||IS_JDOSV?932:(!strcmp(layoutname, "ko")||IS_KDOSV?949:(!strcmp(layoutname, "tw")||!strcmp(layoutname, "hk")||!strcmp(layoutname, "zht")||IS_TDOSV?950:(!strcmp(layoutname, "cn")||!strcmp(layoutname, "zh")||!strcmp(layoutname, "zhs")||IS_PDOSV?936:(!strcmp(layoutname, "us")?437:0))));
//dos.loaded_codepage = GetDefaultCP(); // default codepage already initialized
int32_t tocp=!strcmp(layoutname, "jp")||IS_JDOSV?932:(!strcmp(layoutname, "ko")||IS_KDOSV?949:(!strcmp(layoutname, "tw")||!strcmp(layoutname, "hk")||!strcmp(layoutname, "zht")||IS_TDOSV?950:(!strcmp(layoutname, "cn")||!strcmp(layoutname, "zh")||!strcmp(layoutname, "zhs")||IS_PDOSV?936:(!strcmp(layoutname, "us")?437:0))));
#if defined(WIN32)
if (dos.loaded_codepage == 932 && !IS_PC98_ARCH && GetKeyboardType(0) == 7 && !strcmp(layoutname, "auto")) layoutname = "jp106";
#endif
Expand All @@ -1459,7 +1461,7 @@ class DOS_KeyboardLayout: public Module_base {
DOSBox_SetSysMenu();
loaded_layout=new keyboard_layout();

Bits wants_dos_codepage = -1;
int32_t wants_dos_codepage = -1;
if (!strncmp(layoutname,"auto",4)) {
#if defined (WIN32)
WORD cur_kb_layout = LOWORD(GetKeyboardLayout(0));
Expand Down Expand Up @@ -1692,7 +1694,7 @@ class DOS_KeyboardLayout: public Module_base {

bool extract_codepage = !tocp;
if (wants_dos_codepage>0) {
if ((loaded_layout->read_codepage_file("auto", (int32_t)wants_dos_codepage)) == KEYB_NOERROR) {
if ((loaded_layout->read_codepage_file("auto", wants_dos_codepage)) == KEYB_NOERROR) {
// preselected codepage was successfully loaded
extract_codepage = false;
}
Expand Down Expand Up @@ -1727,7 +1729,6 @@ class DOS_KeyboardLayout: public Module_base {
#endif
{
dos.loaded_codepage = tocp;
MSG_Init();
DOSBox_SetSysMenu();
if (!jfont_init && isDBCSCP()) JFONT_Init();
SetupDBCSTable();
Expand All @@ -1738,9 +1739,10 @@ class DOS_KeyboardLayout: public Module_base {
#endif
}
}
if(msgcodepage) {
if(isSupportedCP(msgcodepage)) {
SwitchLanguage(dos.loaded_codepage, msgcodepage, false);
DOS_ChangeCodepage(msgcodepage, "auto");
if(!CheckDBCSCP(msgcodepage))DOS_ChangeCodepage(msgcodepage, "auto");
dos.loaded_codepage = msgcodepage;
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/dos/dos_programs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ void runBoot(const char *str), runMount(const char *str), runImgmount(const char
void getdrivezpath(std::string &path, std::string const& dirname), drivezRegister(std::string const& path, std::string const& dir, bool usecp), UpdateDefaultPrinterFont(void);
std::string GetDOSBoxXPath(bool withexe=false);
FILE *testLoadLangFile(const char *fname);
bool CheckDBCSCP(int32_t codepage);
extern int32_t msgcodepage;

#if defined(OS2)
#define INCL DOSFILEMGR
Expand Down Expand Up @@ -215,10 +217,11 @@ void SwitchLanguage(int oldcp, int newcp, bool confirm) {
if (file) {
fclose(file);
std::string msg = "You have changed the active code page to " + std::to_string(newcp) + ". Do you want to load language file " + langnew + " for this code page?";
if (!confirm || systemmessagebox("DOSBox-X language file", msg.c_str(), "yesno","question", 2)) {
if (!confirm || CheckDBCSCP(oldcp) || systemmessagebox("DOSBox-X language file", msg.c_str(), "yesno", "question", 2)) {
SetVal("dosbox", "language", langnew);
Load_Language(langnew);
msgcodepage = newcp;
lastmsgcp = newcp;
Load_Language(langnew);
}
}
}
Expand Down
35 changes: 17 additions & 18 deletions src/misc/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#endif
using namespace std;

int msgcodepage = 0, lastmsgcp = 0;
int32_t msgcodepage = 0, lastmsgcp = 0;
bool morelen = false, inmsg = false, loadlang = false;
bool uselangcp = false; // True if Language file is loaded via CONFIG -set langcp option. Use codepage specified in the language file
bool isSupportedCP(int newCP), CodePageHostToGuestUTF8(char *d/*CROSS_LEN*/,const char *s/*CROSS_LEN*/), CodePageGuestToHostUTF8(char *d/*CROSS_LEN*/,const char *s/*CROSS_LEN*/), systemmessagebox(char const * aTitle, char const * aMessage, char const * aDialogType, char const * aIconType, int aDefaultButton), OpenGL_using(void);
Expand All @@ -52,6 +52,8 @@ extern const char * RunningProgram;
Bitu DOS_ChangeKeyboardLayout(const char* layoutname, int32_t codepage);
Bitu DOS_ChangeCodepage(int32_t codepage, const char* codepagefile);
Bitu DOS_LoadKeyboardLayout(const char* layoutname, int32_t codepage, const char* codepagefile);
bool CheckDBCSCP(int32_t codepage);
void Load_Language(std::string name);

#define LINE_IN_MAXLEN 2048

Expand Down Expand Up @@ -204,23 +206,26 @@ void AddMessages() {
MSG_Add("AUTO_CYCLE_OFF","Auto cycles [off]");
}

void MSG_Init(void);
// True if specified codepage is a DBCS codepage
bool CheckDBCSCP(int32_t codepage) {
if(codepage == 932 || codepage == 936 || codepage == 949 || codepage == 950 || codepage == 951) {
LOG_MSG("CheckDBCSCP: Codepage %d true", codepage);
return true;
}
else return false;
}

void SetKEYBCP() {
if (IS_PC98_ARCH || IS_JEGA_ARCH || IS_DOSV || dos_kernel_disabled || !strcmp(RunningProgram, "LOADLIN")) return;
Bitu return_code;

if(msgcodepage == 932 || msgcodepage == 936 || msgcodepage == 949 || msgcodepage == 950 || msgcodepage == 951) {
MSG_Init();
if(CheckDBCSCP(msgcodepage)) {
dos.loaded_codepage = msgcodepage;
ShutFontHandle();
InitFontHandle();
JFONT_Init();
dos.loaded_codepage = msgcodepage;
}
else {
return_code = DOS_ChangeCodepage(858, "auto"); /* FIX_ME: Somehow requires to load codepage twice */
return_code = DOS_ChangeCodepage(msgcodepage, "auto");
if(return_code == KEYB_NOERROR) {
dos.loaded_codepage = msgcodepage;
}
if (!CheckDBCSCP(msgcodepage) && DOS_ChangeCodepage(msgcodepage, "auto") == KEYB_NOERROR){
dos.loaded_codepage = msgcodepage;
}
runRescan("-A -Q");
}
Expand Down Expand Up @@ -388,12 +393,6 @@ void LoadMessageFile(const char * fname) {
update_bindbutton_text();
dos.loaded_codepage=cp;
if (loadlangcp && msgcodepage>0 && isSupportedCP(msgcodepage) && msgcodepage != dos.loaded_codepage) {
ShutFontHandle();
if(msgcodepage == 932 || msgcodepage == 936 || msgcodepage == 949 || msgcodepage == 950 || msgcodepage == 951) {
dos.loaded_codepage = msgcodepage;
InitFontHandle();
JFONT_Init();
}
if (!IS_DOSV && !IS_JEGA_ARCH) {
#if defined(USE_TTF)
if (ttf.inUse) toSetCodePage(NULL, msgcodepage, -2); else
Expand Down
2 changes: 1 addition & 1 deletion src/shell/shell_cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4533,7 +4533,7 @@ int toSetCodePage(DOS_Shell *shell, int newCP, int opt) {
missing = TTF_using() ? setTTFCodePage() : 0;
#endif
if (!TTF_using()) initcodepagefont();
if (dos.loaded_codepage==437) DOS_LoadKeyboardLayout("us", 437, "auto");
if (dos.loaded_codepage==437 && DOS_GetLoadedLayout() == NULL) DOS_LoadKeyboardLayout("us", 437, "auto");
if (opt==-1) {
MSG_Init();
#if DOSBOXMENU_TYPE == DOSBOXMENU_HMENU
Expand Down

0 comments on commit 09e750d

Please sign in to comment.