From b6ce0b3d3bd6346b7e3ab860b1e9abb3bb35ceea Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Mon, 26 Aug 2013 21:32:05 +0200 Subject: [PATCH] Fix some unicode bugs (open file dialog) --- Windows/W32Util/ShellUtil.cpp | 27 +++++++++++---------------- Windows/W32Util/ShellUtil.h | 8 ++++---- Windows/WndMainWindow.cpp | 10 +++++----- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/Windows/W32Util/ShellUtil.cpp b/Windows/W32Util/ShellUtil.cpp index a941ab8ea1..54cf473020 100644 --- a/Windows/W32Util/ShellUtil.cpp +++ b/Windows/W32Util/ShellUtil.cpp @@ -36,8 +36,8 @@ namespace W32Util //--------------------------------------------------------------------------------------------------- // function WinBrowseForFileName //--------------------------------------------------------------------------------------------------- - bool BrowseForFileName (bool _bLoad, HWND _hParent, const char *_pTitle, - const char *_pInitialFolder,const char *_pFilter,const char *_pExtension, + bool BrowseForFileName (bool _bLoad, HWND _hParent, const wchar_t *_pTitle, + const wchar_t *_pInitialFolder,const wchar_t *_pFilter,const wchar_t *_pExtension, std::string& _strFileName) { wchar_t szFile [MAX_PATH+1] = {0}; @@ -48,18 +48,18 @@ namespace W32Util ZeroMemory (&ofn,sizeof (ofn)); ofn.lStructSize = sizeof (OPENFILENAME); - ofn.lpstrInitialDir = ConvertUTF8ToWString(_pInitialFolder).c_str(); - ofn.lpstrFilter = ConvertUTF8ToWString(_pFilter).c_str(); + ofn.lpstrInitialDir = _pInitialFolder; + ofn.lpstrFilter = _pFilter; ofn.nMaxFile = sizeof (szFile); ofn.lpstrFile = szFile; ofn.lpstrFileTitle = szFileTitle; ofn.nMaxFileTitle = sizeof (szFileTitle); - ofn.lpstrDefExt = ConvertUTF8ToWString(_pExtension).c_str(); + ofn.lpstrDefExt = _pExtension; ofn.hwndOwner = _hParent; ofn.Flags = OFN_NOCHANGEDIR | OFN_EXPLORER | OFN_HIDEREADONLY; if (_strFileName.size () != 0) - ofn.lpstrFile = (wchar_t *)_strFileName.c_str(); + wcscpy(ofn.lpstrFile, ConvertUTF8ToWString(_strFileName).c_str()); if (((_bLoad) ? GetOpenFileName(&ofn) : GetSaveFileName (&ofn))) { @@ -70,8 +70,8 @@ namespace W32Util return false; } - std::vector BrowseForFileNameMultiSelect(bool _bLoad, HWND _hParent, const char *_pTitle, - const char *_pInitialFolder,const char *_pFilter,const char *_pExtension) + std::vector BrowseForFileNameMultiSelect(bool _bLoad, HWND _hParent, const wchar_t *_pTitle, + const wchar_t *_pInitialFolder,const wchar_t *_pFilter,const wchar_t *_pExtension) { wchar_t szFile [MAX_PATH+1+2048*2] = {0}; wchar_t szFileTitle [MAX_PATH+1] = {0}; @@ -81,13 +81,13 @@ namespace W32Util ZeroMemory (&ofn,sizeof (ofn)); ofn.lStructSize = sizeof (OPENFILENAME); - ofn.lpstrInitialDir = ConvertUTF8ToWString(_pInitialFolder).c_str(); - ofn.lpstrFilter = ConvertUTF8ToWString(_pFilter).c_str(); + ofn.lpstrInitialDir = _pInitialFolder; + ofn.lpstrFilter = _pFilter; ofn.nMaxFile = sizeof (szFile); ofn.lpstrFile = szFile; ofn.lpstrFileTitle = szFileTitle; ofn.nMaxFileTitle = sizeof (szFileTitle); - ofn.lpstrDefExt = ConvertUTF8ToWString(_pExtension).c_str(); + ofn.lpstrDefExt = _pExtension; ofn.hwndOwner = _hParent; ofn.Flags = OFN_NOCHANGEDIR | OFN_EXPLORER | OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT ; @@ -116,10 +116,5 @@ namespace W32Util } else return std::vector(); // empty vector; - } - - - - } \ No newline at end of file diff --git a/Windows/W32Util/ShellUtil.h b/Windows/W32Util/ShellUtil.h index a598440a19..8d55f33553 100644 --- a/Windows/W32Util/ShellUtil.h +++ b/Windows/W32Util/ShellUtil.h @@ -7,9 +7,9 @@ namespace W32Util { std::string BrowseForFolder(HWND parent, char *title); - bool BrowseForFileName (bool _bLoad, HWND _hParent, const char *_pTitle, - const char *_pInitialFolder,const char *_pFilter,const char *_pExtension, + bool BrowseForFileName (bool _bLoad, HWND _hParent, const wchar_t*_pTitle, + const wchar_t *_pInitialFolder,const wchar_t *_pFilter,const wchar_t*_pExtension, std::string& _strFileName); - std::vector BrowseForFileNameMultiSelect(bool _bLoad, HWND _hParent, const char *_pTitle, - const char *_pInitialFolder,const char *_pFilter,const char *_pExtension); + std::vector BrowseForFileNameMultiSelect(bool _bLoad, HWND _hParent, const wchar_t*_pTitle, + const wchar_t*_pInitialFolder,const wchar_t*_pFilter,const wchar_t*_pExtension); } \ No newline at end of file diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index 637dc5ff95..f6b58bd57a 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -414,7 +414,7 @@ namespace MainWindow NativeMessageReceived("boot", dir.c_str()); } } - else if (W32Util::BrowseForFileName(true, GetHWND(), "Load File", defaultPath.size() ? defaultPath.c_str() : 0, filter.c_str(),"*.pbp;*.elf;*.iso;*.cso;",fn)) + else if (W32Util::BrowseForFileName(true, GetHWND(), L"Load File", defaultPath.size() ? ConvertUTF8ToWString(defaultPath).c_str() : 0, ConvertUTF8ToWString(filter).c_str(), L"*.pbp;*.elf;*.iso;*.cso;",fn)) { if (globalUIState == UISTATE_INGAME || globalUIState == UISTATE_PAUSEMENU) { Core_EnableStepping(false); @@ -736,14 +736,14 @@ namespace MainWindow break; case ID_FILE_LOADSTATEFILE: - if (W32Util::BrowseForFileName(true, hWnd, "Load state",0,"Save States (*.ppst)\0*.ppst\0All files\0*.*\0\0","ppst",fn)) { + if (W32Util::BrowseForFileName(true, hWnd, L"Load state",0,L"Save States (*.ppst)\0*.ppst\0All files\0*.*\0\0",L"ppst",fn)) { SetCursor(LoadCursor(0, IDC_WAIT)); SaveState::Load(fn, SaveStateActionFinished); } break; case ID_FILE_SAVESTATEFILE: - if (W32Util::BrowseForFileName(false, hWnd, "Save state",0,"Save States (*.ppst)\0*.ppst\0All files\0*.*\0\0","ppst",fn)) { + if (W32Util::BrowseForFileName(false, hWnd, L"Save state",0,L"Save States (*.ppst)\0*.ppst\0All files\0*.*\0\0",L"ppst",fn)) { SetCursor(LoadCursor(0, IDC_WAIT)); SaveState::Save(fn, SaveStateActionFinished); } @@ -951,7 +951,7 @@ namespace MainWindow break; case ID_DEBUG_LOADMAPFILE: - if (W32Util::BrowseForFileName(true, hWnd, "Load .MAP",0,"Maps\0*.map\0All files\0*.*\0\0","map",fn)) { + if (W32Util::BrowseForFileName(true, hWnd, L"Load .MAP",0,L"Maps\0*.map\0All files\0*.*\0\0",L"map",fn)) { symbolMap.LoadSymbolMap(fn.c_str()); if (disasmWindow[0]) @@ -963,7 +963,7 @@ namespace MainWindow break; case ID_DEBUG_SAVEMAPFILE: - if (W32Util::BrowseForFileName(false, hWnd, "Save .MAP",0,"Maps\0*.map\0All files\0*.*\0\0","map",fn)) + if (W32Util::BrowseForFileName(false, hWnd, L"Save .MAP",0,L"Maps\0*.map\0All files\0*.*\0\0",L"map",fn)) symbolMap.SaveSymbolMap(fn.c_str()); break;