mirror of
https://github.com/joncampbell123/dosbox-x.git
synced 2025-05-09 20:01:19 +08:00
Merge pull request #5356 from maron2000/fix_chcp
Fix codepage didn't change when loading language files in some cases
This commit is contained in:
commit
d93d37c954
@ -1391,6 +1391,7 @@ Bitu DOS_LoadKeyboardLayout(const char * layoutname, int32_t codepage, const cha
|
||||
return kerrcode;
|
||||
}
|
||||
// Everything went fine, switch to new layout
|
||||
delete loaded_layout;
|
||||
loaded_layout=temp_layout;
|
||||
return KEYB_NOERROR;
|
||||
}
|
||||
@ -1405,7 +1406,7 @@ Bitu DOS_SwitchKeyboardLayout(const char* new_layout, int32_t& tried_cp) {
|
||||
loaded_layout=changed_layout;
|
||||
}
|
||||
return ret_code;
|
||||
} else return 0xff;
|
||||
} else return 0xFF;
|
||||
}
|
||||
|
||||
|
||||
@ -1418,6 +1419,7 @@ Bitu DOS_ChangeKeyboardLayout(const char* layoutname, int32_t codepage) {
|
||||
return kerrcode;
|
||||
}
|
||||
// Everything went fine, switch to new layout
|
||||
delete loaded_layout;
|
||||
loaded_layout = temp_layout;
|
||||
return KEYB_NOERROR;
|
||||
}
|
||||
|
@ -108,6 +108,7 @@ bool InitCodePage() {
|
||||
return true;
|
||||
}
|
||||
else dos.loaded_codepage = msgcodepage;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (msgcodepage>0) {
|
||||
@ -217,6 +218,7 @@ bool CheckDBCSCP(int32_t codepage) {
|
||||
else return false;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void SetKEYBCP() {
|
||||
if (IS_PC98_ARCH || IS_JEGA_ARCH || IS_DOSV || dos_kernel_disabled || !strcmp(RunningProgram, "LOADLIN")) return;
|
||||
Bitu return_code;
|
||||
@ -236,6 +238,7 @@ void SetKEYBCP() {
|
||||
}
|
||||
runRescan("-A -Q");
|
||||
}
|
||||
#endif
|
||||
|
||||
FILE *testLoadLangFile(const char *fname) {
|
||||
std::string config_path, res_path, exepath=GetDOSBoxXPath();
|
||||
@ -279,8 +282,7 @@ void LoadMessageFile(const char * 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);
|
||||
|
||||
FILE * mfile=testLoadLangFile(fname);
|
||||
/* This should never happen and since other modules depend on this use a normal printf */
|
||||
@ -292,6 +294,7 @@ void LoadMessageFile(const char * fname) {
|
||||
control->opt_lang = "";
|
||||
return;
|
||||
}
|
||||
strcpy(loaded_fname, fname);
|
||||
langname = langnote = "";
|
||||
char linein[LINE_IN_MAXLEN+1024];
|
||||
char name[LINE_IN_MAXLEN+1024], menu_name[LINE_IN_MAXLEN], mapper_name[LINE_IN_MAXLEN];
|
||||
@ -337,7 +340,10 @@ void LoadMessageFile(const char * fname) {
|
||||
}
|
||||
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?";
|
||||
if(c == dos.loaded_codepage) msgcodepage = c;
|
||||
if(c == dos.loaded_codepage) {
|
||||
msgcodepage = c;
|
||||
lastmsgcp = msgcodepage;
|
||||
}
|
||||
if(c != dos.loaded_codepage && (control->opt_langcp || uselangcp || !CHCP_changed || CheckDBCSCP(c) || !loadlang || (loadlang && systemmessagebox("DOSBox-X language file", msg.c_str(), "yesno", "question", 1)))) {
|
||||
loadlangcp = true;
|
||||
if(c == 950 && dos.loaded_codepage == 951) msgcodepage = 951; // zh_tw defaults to CP950, but CP951 is acceptable as well so keep it
|
||||
@ -404,7 +410,7 @@ void LoadMessageFile(const char * fname) {
|
||||
dos.loaded_codepage=cp;
|
||||
if (loadlangcp && msgcodepage>0) {
|
||||
const char* layoutname = DOS_GetLoadedLayout();
|
||||
if(!IS_DOSV && !IS_JEGA_ARCH && layoutname != NULL) {
|
||||
if(!IS_DOSV && !IS_JEGA_ARCH && !IS_PC98_ARCH && layoutname != NULL) {
|
||||
toSetCodePage(NULL, msgcodepage, -1);
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ extern bool shell_keyboard_flush;
|
||||
extern bool dos_shell_running_program, mountwarning, winautorun;
|
||||
extern bool startcmd, startwait, startquiet, internal_program;
|
||||
extern bool addovl, addipx, addne2k, enableime, showdbcs;
|
||||
extern bool halfwidthkana, force_conversion, gbk, uselangcp;
|
||||
extern bool halfwidthkana, force_conversion, gbk, uselangcp, chinasea;
|
||||
extern const char* RunningProgram;
|
||||
extern int enablelfn, msgcodepage, lastmsgcp;
|
||||
extern uint16_t countryNo;
|
||||
@ -69,6 +69,8 @@ Bitu call_int23 = 0;
|
||||
|
||||
std::string GetDOSBoxXPath(bool withexe=false);
|
||||
const char* DOS_GetLoadedLayout(void);
|
||||
Bitu DOS_ChangeKeyboardLayout(const char* layoutname, int32_t codepage), DOS_SwitchKeyboardLayout(const char* new_layout, int32_t& tried_cp);
|
||||
Bitu DOS_LoadKeyboardLayout(const char* layoutname, int32_t codepage, const char* codepagefile);
|
||||
int Reflect_Menu(void);
|
||||
void SetIMPosition(void);
|
||||
void SetKEYBCP();
|
||||
@ -81,6 +83,7 @@ bool SwitchLanguage(int oldcp, int newcp, bool confirm);
|
||||
void CALLBACK_DeAllocate(Bitu in), DOSBox_ConsolePauseWait();
|
||||
void GFX_SetTitle(int32_t cycles, int frameskip, Bits timing, bool paused);
|
||||
bool isDBCSCP(), InitCodePage(), isKanji1(uint8_t chr), shiftjis_lead_byte(int c), sdl_wait_on_error(), CheckDBCSCP(int32_t codepage), TTF_using(void);
|
||||
void makestdcp950table(), makeseacp951table();
|
||||
|
||||
Bitu call_shellstop = 0;
|
||||
/* Larger scope so shell_del autoexec can use it to
|
||||
@ -819,6 +822,12 @@ void showWelcome(Program *shell) {
|
||||
bool finish_prepare = false;
|
||||
void DOS_Shell::Prepare(void) {
|
||||
if (this == first_shell) {
|
||||
const char* layoutname = DOS_GetLoadedLayout();
|
||||
if(layoutname == NULL) {
|
||||
int32_t cp = dos.loaded_codepage;
|
||||
Bitu keyb_error = DOS_LoadKeyboardLayout("us", 437, "auto");
|
||||
toSetCodePage(NULL, cp, -1);
|
||||
}
|
||||
Section_prop *section = static_cast<Section_prop *>(control->GetSection("dosbox"));
|
||||
if (section->Get_bool("startbanner")&&!control->opt_fastlaunch)
|
||||
showWelcome(this);
|
||||
@ -857,33 +866,25 @@ void DOS_Shell::Prepare(void) {
|
||||
if ((section!=NULL&&!control->opt_noconfig)||control->opt_langcp) {
|
||||
char *countrystr = (char *)section->Get_string("country"), *r=strchr(countrystr, ',');
|
||||
int country = 0;
|
||||
int32_t newCP = dos.loaded_codepage;
|
||||
if((control->opt_langcp && msgcodepage > 0) || CheckDBCSCP(msgcodepage) || msgcodepage == dos.loaded_codepage) newCP = msgcodepage;
|
||||
if ((r==NULL || !*(r+1)) && !control->opt_langcp)
|
||||
country = atoi(trim(countrystr));
|
||||
else {
|
||||
else if(!msgcodepage){
|
||||
if (r!=NULL) *r=0;
|
||||
country = atoi(trim(countrystr));
|
||||
int32_t newCP = r==NULL||IS_PC98_ARCH||IS_JEGA_ARCH||IS_DOSV?dos.loaded_codepage:atoi(trim(r+1));
|
||||
newCP = r==NULL||IS_PC98_ARCH||IS_JEGA_ARCH||IS_DOSV?dos.loaded_codepage:atoi(trim(r+1));
|
||||
if (r!=NULL) *r=',';
|
||||
if (!IS_PC98_ARCH&&!IS_JEGA_ARCH) {
|
||||
if(!newCP && IS_DOSV) {
|
||||
if(IS_JDOSV) newCP = 932;
|
||||
else if(IS_PDOSV) newCP = 936;
|
||||
else if(IS_KDOSV) newCP = 949;
|
||||
else if(IS_TDOSV) newCP = 950;
|
||||
}
|
||||
if((control->opt_langcp && msgcodepage > 0 ) || CheckDBCSCP(msgcodepage)|| msgcodepage == dos.loaded_codepage) newCP = msgcodepage;
|
||||
if (newCP != dos.loaded_codepage && (!TTF_using() || (TTF_using() && isSupportedCP(newCP)))) {
|
||||
int missing = toSetCodePage(this, newCP, msgcodepage?-1:control->opt_fastlaunch?1:-2);
|
||||
//WriteOut(MSG_Get("SHELL_CMD_CHCP_ACTIVE"), dos.loaded_codepage);
|
||||
if (missing > 0) WriteOut(MSG_Get("SHELL_CMD_CHCP_MISSING"), missing);
|
||||
else if (missing < 0) WriteOut(MSG_Get("SHELL_CMD_CHCP_INVALID"), newCP);
|
||||
}
|
||||
}
|
||||
int missing = toSetCodePage(this, newCP, -1);
|
||||
}
|
||||
if (country>0&&!control->opt_noconfig) {
|
||||
countryNo = country;
|
||||
DOS_SetCountry(countryNo);
|
||||
}
|
||||
if(!chinasea)makestdcp950table();
|
||||
if(chinasea) makeseacp951table();
|
||||
runRescan("-A -Q");
|
||||
const char * extra = section->data.c_str();
|
||||
if (extra&&!control->opt_securemode&&!control->SecureMode()&&!control->opt_noconfig) {
|
||||
|
@ -128,7 +128,7 @@ const char *GetCmdName(int i) {
|
||||
}
|
||||
|
||||
extern int enablelfn, lfn_filefind_handle, file_access_tries, lastmsgcp;
|
||||
extern bool date_host_forced, usecon, outcon, rsize, autoboxdraw, dbcs_sbcs, sync_time, manualtime, inshell, noassoc, dotype, loadlang;
|
||||
extern bool date_host_forced, usecon, outcon, rsize, autoboxdraw, dbcs_sbcs, sync_time, manualtime, inshell, noassoc, dotype, loadlang, chinasea;
|
||||
extern unsigned long freec;
|
||||
extern uint8_t DOS_GetAnsiAttr(void);
|
||||
extern uint16_t countryNo, altcp_to_unicode[256];
|
||||
@ -143,6 +143,12 @@ std::string GetDOSBoxXPath(bool withexe=false);
|
||||
FILE *testLoadLangFile(const char *fname);
|
||||
Bitu DOS_ChangeCodepage(int32_t codepage, const char* codepagefile);
|
||||
bool CheckDBCSCP(int32_t codepage), SwitchLanguage(int oldcp, int newcp, bool confirm);
|
||||
void makestdcp950table(), makeseacp951table();
|
||||
#if C_OPENGL
|
||||
bool OpenGL_using(void);
|
||||
#endif
|
||||
void UpdateSDLDrawTexture();
|
||||
|
||||
static int32_t lastsetcp = 0;
|
||||
bool CHCP_changed = false;
|
||||
|
||||
@ -4532,25 +4538,29 @@ extern Bitu DOS_LoadKeyboardLayout(const char * layoutname, int32_t codepage, co
|
||||
void runRescan(const char *str), MSG_Init(), JFONT_Init(), InitFontHandle(), ShutFontHandle(), initcodepagefont(), DOSBox_SetSysMenu();
|
||||
int toSetCodePage(DOS_Shell *shell, int newCP, int opt) {
|
||||
if((TTF_using() && isSupportedCP(newCP)) || !TTF_using()) {
|
||||
int32_t oldcp = dos.loaded_codepage;
|
||||
int32_t oldcp = dos.loaded_codepage, cpbak = newCP;
|
||||
Bitu keyb_error;
|
||||
if (!CheckDBCSCP(newCP)){
|
||||
if(IS_PC98_ARCH || IS_JEGA_ARCH) newCP = 932;
|
||||
else if(IS_DOSV) {
|
||||
if(IS_JDOSV) newCP = 932;
|
||||
else if(IS_PDOSV) newCP = 936;
|
||||
else if(IS_KDOSV) newCP = 949;
|
||||
else if(IS_TDOSV) newCP = 950;
|
||||
}
|
||||
else if (!CheckDBCSCP(newCP)){
|
||||
keyb_error = DOS_ChangeCodepage(newCP, "auto");
|
||||
if (keyb_error != KEYB_NOERROR) {
|
||||
dos.loaded_codepage = oldcp;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(newCP != cpbak) LOG_MSG("SHELL: Invalid codepage %d, set to %d.", cpbak, newCP);
|
||||
dos.loaded_codepage = newCP;
|
||||
}
|
||||
int missing = 0;
|
||||
#if defined(USE_TTF)
|
||||
missing = TTF_using() ? setTTFCodePage() : 0;
|
||||
#endif
|
||||
if (!TTF_using()) initcodepagefont();
|
||||
//if (dos.loaded_codepage==437) DOS_LoadKeyboardLayout("us", 437, "auto");
|
||||
//LOG_MSG("toSetCodePage opt=%d, loadlangnew=%d", opt, loadlangnew?1:0);
|
||||
if (opt==-1) {
|
||||
MSG_Init();
|
||||
#if DOSBOXMENU_TYPE == DOSBOXMENU_HMENU
|
||||
@ -4568,8 +4578,14 @@ int toSetCodePage(DOS_Shell *shell, int newCP, int opt) {
|
||||
JFONT_Init();
|
||||
SetupDBCSTable();
|
||||
clearFontCache();
|
||||
if(newCP == 950 && !chinasea) makestdcp950table();
|
||||
if(newCP == 951 && chinasea) makeseacp951table();
|
||||
}
|
||||
if (finish_prepare) runRescan("-A -Q");
|
||||
#if C_OPENGL && DOSBOXMENU_TYPE == DOSBOXMENU_SDLDRAW
|
||||
if(OpenGL_using() && control->opt_lang.size())
|
||||
UpdateSDLDrawTexture();
|
||||
#endif
|
||||
#if defined(USE_TTF)
|
||||
if ((opt==-1||opt==-2)&&TTF_using()) {
|
||||
Section_prop * ttf_section = static_cast<Section_prop *>(control->GetSection("ttf"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user