Fix Linux needs dialog messages in UTF8, not guest codepage

This commit is contained in:
maron2000 2025-04-24 12:44:45 +09:00
parent df425f676b
commit 9da348e845
2 changed files with 42 additions and 0 deletions

View File

@ -786,6 +786,8 @@ void MenuBrowseImageFile(char drive, bool arc, bool boot, bool multiple) {
#endif
}
bool CodePageGuestToHostUTF8(char *d/*CROSS_LEN*/,const char *s/*CROSS_LEN*/) ;
void MenuBrowseFolder(char drive, std::string const& drive_type) {
std::string str(1, drive);
if (Drives[drive-'A']) {
@ -803,7 +805,15 @@ void MenuBrowseFolder(char drive, std::string const& drive_type) {
std::string title = formatString(MSG_Get("PROGRAM_MOUNT_SELECT_DRIVE"), str.c_str(),MSG_Get(msg_key.c_str()));
if(drive_type=="CDROM")
title += "\n" + std::string(MSG_Get("PROGRAM_MOUNT_CDROM_SUPPORT"));
#ifdef LINUX
size_t aMessageLength = strlen(title.c_str());
char *lMessage = (char *)malloc((aMessageLength * 2 + 1) * sizeof(char));
CodePageGuestToHostUTF8(lMessage, title.c_str()) ;
char const * lTheSelectFolderName = tinyfd_selectFolderDialog(lMessage, NULL);
free(lMessage);
#else
char const * lTheSelectFolderName = tinyfd_selectFolderDialog(title.c_str(), NULL);
#endif
if (lTheSelectFolderName) {
MountHelper(drive,GetNewStr(lTheSelectFolderName).c_str(),drive_type);
std::string drive_warn = formatString(MSG_Get("PROGRAM_MOUNT_SUCCESS"), std::string(1, drive).c_str(), lTheSelectFolderName);

View File

@ -1096,19 +1096,51 @@ void GFX_SetTitle(int32_t cycles, int frameskip, Bits timing, bool paused) {
}
bool warn_on_mem_write = false;
bool CodePageGuestToHostUTF8(char *d/*CROSS_LEN*/,const char *s/*CROSS_LEN*/) ;
#ifdef LINUX
std::string replaceNewlineWithEscaped(const std::string& input) {
std::string output;
size_t i = 0;
while (i < input.length()) {
if (input[i] == '\\') {
if(input[i+1] != 'n') output += '\\'; // "\n" needs to be escaped to "\\n"
}
else {
output += input[i];
i++;
}
}
return output;
}
#endif
bool systemmessagebox(char const * aTitle, char const * aMessage, char const * aDialogType, char const * aIconType, int aDefaultButton) {
#if !defined(HX_DOS)
if(!aMessage) aMessage = "";
std::string lDialogString(aMessage);
std::replace(lDialogString.begin(), lDialogString.end(), '\"', ' ');
#ifdef LINUX
size_t aMessageLength = strlen(aMessage);
char *lMessage = (char *)malloc((aMessageLength * 2 + 1) * sizeof(char)); // DBCS may expand to 3 to 4 bytes when converted to UTF-8
lDialogString = replaceNewlineWithEscaped(lDialogString); // String may include "\n" which needs to be escaped to "\\n"
CodePageGuestToHostUTF8(lMessage, lDialogString.c_str());
#endif
bool fs=sdl.desktop.fullscreen;
if (fs) GFX_SwitchFullScreen();
MAPPER_ReleaseAllKeys();
GFX_LosingFocus();
GFX_ReleaseMouse();
#ifdef LINUX
bool ret=tinyfd_messageBox(aTitle, lMessage, aDialogType, aIconType, aDefaultButton);
free(lMessage);
#else
bool ret=tinyfd_messageBox(aTitle, lDialogString.c_str(), aDialogType, aIconType, aDefaultButton);
#endif
MAPPER_ReleaseAllKeys();
GFX_LosingFocus();
if (fs&&!sdl.desktop.fullscreen) GFX_SwitchFullScreen();