mirror of
https://github.com/joncampbell123/dosbox-x.git
synced 2025-10-19 11:23:16 +08:00
Fix loading language files by CONFIG command
This commit is contained in:
@@ -106,7 +106,7 @@ public:
|
|||||||
bool opt_showrt = false;
|
bool opt_showrt = false;
|
||||||
bool opt_nomenu = false;
|
bool opt_nomenu = false;
|
||||||
bool opt_prerun = false;
|
bool opt_prerun = false;
|
||||||
bool opt_langcp = false;
|
bool opt_langcp = false; // True if command line option -langcp is specified, always use codepage specified by the language file
|
||||||
bool opt_debug = false;
|
bool opt_debug = false;
|
||||||
bool opt_nogui = false;
|
bool opt_nogui = false;
|
||||||
bool opt_nolog = false;
|
bool opt_nolog = false;
|
||||||
|
@@ -40,7 +40,8 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int msgcodepage = 0, lastmsgcp = 0;
|
int msgcodepage = 0, lastmsgcp = 0;
|
||||||
bool morelen = false, inmsg = false, loadlang = false, uselangcp = false;
|
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);
|
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);
|
||||||
void InitFontHandle(void), ShutFontHandle(void), refreshExtChar(void), SetIME(void), runRescan(const char *str), menu_update_dynamic(void), menu_update_autocycle(void), update_bindbutton_text(void), set_eventbutton_text(const char *eventname, const char *buttonname), JFONT_Init(), DOSBox_SetSysMenu(), UpdateSDLDrawTexture(), makestdcp950table(), makeseacp951table();
|
void InitFontHandle(void), ShutFontHandle(void), refreshExtChar(void), SetIME(void), runRescan(const char *str), menu_update_dynamic(void), menu_update_autocycle(void), update_bindbutton_text(void), set_eventbutton_text(const char *eventname, const char *buttonname), JFONT_Init(), DOSBox_SetSysMenu(), UpdateSDLDrawTexture(), makestdcp950table(), makeseacp951table();
|
||||||
std::string langname = "", langnote = "", GetDOSBoxXPath(bool withexe=false);
|
std::string langname = "", langnote = "", GetDOSBoxXPath(bool withexe=false);
|
||||||
@@ -203,16 +204,19 @@ void AddMessages() {
|
|||||||
MSG_Add("AUTO_CYCLE_OFF","Auto cycles [off]");
|
MSG_Add("AUTO_CYCLE_OFF","Auto cycles [off]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MSG_Init(void);
|
||||||
void SetKEYBCP() {
|
void SetKEYBCP() {
|
||||||
if (IS_PC98_ARCH || IS_JEGA_ARCH || IS_DOSV || dos_kernel_disabled || !strcmp(RunningProgram, "LOADLIN")) return;
|
if (IS_PC98_ARCH || IS_JEGA_ARCH || IS_DOSV || dos_kernel_disabled || !strcmp(RunningProgram, "LOADLIN")) return;
|
||||||
Bitu return_code;
|
Bitu return_code;
|
||||||
|
|
||||||
if(msgcodepage == 932 || msgcodepage == 936 || msgcodepage == 949 || msgcodepage == 950 || msgcodepage == 951) {
|
if(msgcodepage == 932 || msgcodepage == 936 || msgcodepage == 949 || msgcodepage == 950 || msgcodepage == 951) {
|
||||||
|
MSG_Init();
|
||||||
InitFontHandle();
|
InitFontHandle();
|
||||||
JFONT_Init();
|
JFONT_Init();
|
||||||
dos.loaded_codepage = msgcodepage;
|
dos.loaded_codepage = msgcodepage;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
return_code = DOS_ChangeCodepage(858, "auto"); /* FIX_ME: Somehow requires to load codepage twice */
|
||||||
return_code = DOS_ChangeCodepage(msgcodepage, "auto");
|
return_code = DOS_ChangeCodepage(msgcodepage, "auto");
|
||||||
if(return_code == KEYB_NOERROR) {
|
if(return_code == KEYB_NOERROR) {
|
||||||
dos.loaded_codepage = msgcodepage;
|
dos.loaded_codepage = msgcodepage;
|
||||||
@@ -255,13 +259,17 @@ FILE *testLoadLangFile(const char *fname) {
|
|||||||
return mfile;
|
return mfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char loaded_fname[LINE_IN_MAXLEN + 1024];
|
||||||
void LoadMessageFile(const char * fname) {
|
void LoadMessageFile(const char * fname) {
|
||||||
if (!fname) return;
|
if (!fname) return;
|
||||||
if(*fname=='\0') return;//empty string=no languagefile
|
if(*fname=='\0') return;//empty string=no languagefile
|
||||||
|
if (!strcmp(fname, loaded_fname)){
|
||||||
|
//LOG_MSG("Message file %s already loaded.",fname);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
strcpy(loaded_fname, fname);
|
||||||
|
LOG(LOG_MISC,LOG_DEBUG)("Loading message file %s",loaded_fname);
|
||||||
|
|
||||||
LOG(LOG_MISC,LOG_DEBUG)("Loading message file %s",fname);
|
|
||||||
|
|
||||||
lastmsgcp = 0;
|
|
||||||
FILE * mfile=testLoadLangFile(fname);
|
FILE * mfile=testLoadLangFile(fname);
|
||||||
/* This should never happen and since other modules depend on this use a normal printf */
|
/* This should never happen and since other modules depend on this use a normal printf */
|
||||||
if (!mfile) {
|
if (!mfile) {
|
||||||
@@ -272,7 +280,6 @@ void LoadMessageFile(const char * fname) {
|
|||||||
control->opt_lang = "";
|
control->opt_lang = "";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
msgcodepage = 0;
|
|
||||||
langname = langnote = "";
|
langname = langnote = "";
|
||||||
char linein[LINE_IN_MAXLEN+1024];
|
char linein[LINE_IN_MAXLEN+1024];
|
||||||
char name[LINE_IN_MAXLEN+1024], menu_name[LINE_IN_MAXLEN], mapper_name[LINE_IN_MAXLEN];
|
char name[LINE_IN_MAXLEN+1024], menu_name[LINE_IN_MAXLEN], mapper_name[LINE_IN_MAXLEN];
|
||||||
@@ -281,6 +288,7 @@ void LoadMessageFile(const char * fname) {
|
|||||||
name[0]=0;string[0]=0;
|
name[0]=0;string[0]=0;
|
||||||
morelen=inmsg=true;
|
morelen=inmsg=true;
|
||||||
bool res=true;
|
bool res=true;
|
||||||
|
bool loadlangcp = false;
|
||||||
int cp=dos.loaded_codepage;
|
int cp=dos.loaded_codepage;
|
||||||
if (!dos.loaded_codepage) res=InitCodePage();
|
if (!dos.loaded_codepage) res=InitCodePage();
|
||||||
while(fgets(linein, LINE_IN_MAXLEN+1024, mfile)) {
|
while(fgets(linein, LINE_IN_MAXLEN+1024, mfile)) {
|
||||||
@@ -296,7 +304,6 @@ void LoadMessageFile(const char * fname) {
|
|||||||
parser++;
|
parser++;
|
||||||
}
|
}
|
||||||
*writer=0;
|
*writer=0;
|
||||||
|
|
||||||
/* New string name */
|
/* New string name */
|
||||||
if (linein[0]==':') {
|
if (linein[0]==':') {
|
||||||
string[0]=0;
|
string[0]=0;
|
||||||
@@ -309,22 +316,24 @@ void LoadMessageFile(const char * fname) {
|
|||||||
int c = atoi(r+1);
|
int c = atoi(r+1);
|
||||||
if(!isSupportedCP(c)) {
|
if(!isSupportedCP(c)) {
|
||||||
LOG_MSG("Language file: Invalid codepage :DOSBOX-X:CODEPAGE:%d", c);
|
LOG_MSG("Language file: Invalid codepage :DOSBOX-X:CODEPAGE:%d", c);
|
||||||
|
loadlangcp = false;
|
||||||
}
|
}
|
||||||
else if((!res || control->opt_langcp || uselangcp) && c > 0){
|
else if (((IS_PC98_ARCH||IS_JEGA_ARCH) && c!=437 && c!=932 && !systemmessagebox("DOSBox-X language file", "You have specified a language file which uses a code page incompatible with the Japanese PC-98 or JEGA/AX system.\n\nAre you sure to use the language file for this machine type?", "yesno","question", 2)) || (((IS_JDOSV && c!=932) || (IS_PDOSV && c!=936) || (IS_KDOSV && c!=949) || (IS_TDOSV && c!=950 && c!=951)) && c!=437 && !systemmessagebox("DOSBox-X language file", "You have specified a language file which uses a code page incompatible with the current DOS/V system.\n\nAre you sure to use the language file for this system type?", "yesno","question", 2))) {
|
||||||
if (((IS_PC98_ARCH||IS_JEGA_ARCH) && c!=437 && c!=932 && !systemmessagebox("DOSBox-X language file", "You have specified a language file which uses a code page incompatible with the Japanese PC-98 or JEGA/AX system.\n\nAre you sure to use the language file for this machine type?", "yesno","question", 2)) || (((IS_JDOSV && c!=932) || (IS_PDOSV && c!=936) || (IS_KDOSV && c!=949) || (IS_TDOSV && c!=950 && c!=951)) && c!=437 && !systemmessagebox("DOSBox-X language file", "You have specified a language file which uses a code page incompatible with the current DOS/V system.\n\nAre you sure to use the language file for this system type?", "yesno","question", 2))) {
|
|
||||||
fclose(mfile);
|
fclose(mfile);
|
||||||
dos.loaded_codepage = cp;
|
dos.loaded_codepage = cp;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
std::string msg = "The specified language file uses code page " + std::to_string(c) + ". Do you want to change to this code page accordingly?";
|
std::string msg = "The specified language file uses code page " + std::to_string(c) + ". Do you want to change to this code page accordingly?";
|
||||||
if (loadlang && !control->opt_langcp && !uselangcp && c != 437 && GetDefaultCP() == 437 && systemmessagebox("DOSBox-X language file", msg.c_str(), "yesno", "question", 1)) control->opt_langcp = true;
|
if(c != dos.loaded_codepage && (control->opt_langcp || uselangcp || !loadlang || (loadlang && systemmessagebox("DOSBox-X language file", msg.c_str(), "yesno", "question", 1)))){
|
||||||
else control->opt_langcp = true;
|
loadlangcp = true;
|
||||||
msgcodepage = c;
|
msgcodepage = c;
|
||||||
dos.loaded_codepage = c;
|
dos.loaded_codepage = c;
|
||||||
if (c == 950 && !chinasea) makestdcp950table();
|
if (c == 950 && !chinasea) makestdcp950table();
|
||||||
if (c == 951 && chinasea) makeseacp951table();
|
if (c == 951 && chinasea) makeseacp951table();
|
||||||
}
|
|
||||||
lastmsgcp = c;
|
lastmsgcp = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (!strcmp(p, "LANGUAGE"))
|
} else if (!strcmp(p, "LANGUAGE"))
|
||||||
langname = r+1;
|
langname = r+1;
|
||||||
else if (!strcmp(p, "REMARK"))
|
else if (!strcmp(p, "REMARK"))
|
||||||
@@ -378,15 +387,14 @@ void LoadMessageFile(const char * fname) {
|
|||||||
menu_update_autocycle();
|
menu_update_autocycle();
|
||||||
update_bindbutton_text();
|
update_bindbutton_text();
|
||||||
dos.loaded_codepage=cp;
|
dos.loaded_codepage=cp;
|
||||||
if ((control->opt_langcp || uselangcp) && msgcodepage>0 && isSupportedCP(msgcodepage) && msgcodepage != dos.loaded_codepage) {
|
if (loadlangcp && msgcodepage>0 && isSupportedCP(msgcodepage) && msgcodepage != dos.loaded_codepage) {
|
||||||
ShutFontHandle();
|
ShutFontHandle();
|
||||||
if(msgcodepage == 932 || msgcodepage == 936 || msgcodepage == 949 || msgcodepage == 950 || msgcodepage == 951) {
|
if(msgcodepage == 932 || msgcodepage == 936 || msgcodepage == 949 || msgcodepage == 950 || msgcodepage == 951) {
|
||||||
dos.loaded_codepage = msgcodepage;
|
dos.loaded_codepage = msgcodepage;
|
||||||
InitFontHandle();
|
InitFontHandle();
|
||||||
JFONT_Init();
|
JFONT_Init();
|
||||||
dos.loaded_codepage = cp;
|
|
||||||
}
|
}
|
||||||
if (uselangcp && !IS_DOSV && !IS_JEGA_ARCH) {
|
if (!IS_DOSV && !IS_JEGA_ARCH) {
|
||||||
#if defined(USE_TTF)
|
#if defined(USE_TTF)
|
||||||
if (ttf.inUse) toSetCodePage(NULL, msgcodepage, -2); else
|
if (ttf.inUse) toSetCodePage(NULL, msgcodepage, -2); else
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user