mirror of https://github.com/PCSX2/pcsx2.git
gsdx:windows: Handle shader dialog filenames properly
The shader dialog filename handling code had several buffer overflows and also did not handle non-English filenames well. Fix the filename handling by storing them as UTF-8 in the ini and converting them to/from UTF-16 as necessary, and also fix the buffer overflows.
This commit is contained in:
parent
dedd860d40
commit
d81f236910
|
@ -27,8 +27,6 @@
|
|||
#include "resource.h"
|
||||
#include "GSSetting.h"
|
||||
#include <algorithm>
|
||||
#include <locale>
|
||||
#include <codecvt>
|
||||
|
||||
GSSettingsDlg::GSSettingsDlg()
|
||||
: GSDialog(IDD_CONFIG)
|
||||
|
@ -397,12 +395,10 @@ void GSShaderDlg::OnInit()
|
|||
// External FX shader
|
||||
CheckDlgButton(m_hWnd, IDC_SHADER_FX, theApp.GetConfigB("shaderfx"));
|
||||
|
||||
std::string tmp = theApp.GetConfigS("shaderfx_glsl");
|
||||
std::wstring wsTmp(tmp.begin(), tmp.end());
|
||||
SendMessage(GetDlgItem(m_hWnd, IDC_SHADER_FX_EDIT), WM_SETTEXT, 0, (LPARAM)wsTmp.c_str());
|
||||
tmp = theApp.GetConfigS("shaderfx_conf");
|
||||
wsTmp = std::wstring(tmp.begin(), tmp.end());
|
||||
SendMessage(GetDlgItem(m_hWnd, IDC_SHADER_FX_CONF_EDIT), WM_SETTEXT, 0, (LPARAM)wsTmp.c_str());
|
||||
std::wstring filename = convert_utf8_to_utf16(theApp.GetConfigS("shaderfx_glsl"));
|
||||
SendMessage(GetDlgItem(m_hWnd, IDC_SHADER_FX_EDIT), WM_SETTEXT, 0, (LPARAM)filename.c_str());
|
||||
filename = convert_utf8_to_utf16(theApp.GetConfigS("shaderfx_conf"));
|
||||
SendMessage(GetDlgItem(m_hWnd, IDC_SHADER_FX_CONF_EDIT), WM_SETTEXT, 0, (LPARAM)filename.c_str());
|
||||
|
||||
// FXAA shader
|
||||
CheckDlgButton(m_hWnd, IDC_FXAA, theApp.GetConfigB("fxaa"));
|
||||
|
@ -525,15 +521,14 @@ bool GSShaderDlg::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
|
|||
const int shader_fx_length = (int)SendMessage(GetDlgItem(m_hWnd, IDC_SHADER_FX_EDIT), WM_GETTEXTLENGTH, 0, 0);
|
||||
const int shader_fx_conf_length = (int)SendMessage(GetDlgItem(m_hWnd, IDC_SHADER_FX_CONF_EDIT), WM_GETTEXTLENGTH, 0, 0);
|
||||
const int length = std::max(shader_fx_length, shader_fx_conf_length) + 1;
|
||||
std::unique_ptr<char[]> buffer(new char[length]);
|
||||
char* output = new char[length];
|
||||
std::unique_ptr<wchar_t[]> buffer = std::make_unique<wchar_t[]>(length);
|
||||
|
||||
SendMessage(GetDlgItem(m_hWnd, IDC_SHADER_FX_EDIT), WM_GETTEXT, (WPARAM)length, (LPARAM)buffer.get());
|
||||
wcstombs(output, (wchar_t*)buffer.get(), length);
|
||||
theApp.SetConfig("shaderfx_glsl", output); // Not really glsl only ;)
|
||||
std::string output = convert_utf16_to_utf8(buffer.get());
|
||||
theApp.SetConfig("shaderfx_glsl", output.c_str()); // Not really glsl only ;)
|
||||
SendMessage(GetDlgItem(m_hWnd, IDC_SHADER_FX_CONF_EDIT), WM_GETTEXT, (WPARAM)length, (LPARAM)buffer.get());
|
||||
wcstombs(output, (wchar_t*)buffer.get(), length);
|
||||
theApp.SetConfig("shaderfx_conf", output);
|
||||
output = convert_utf16_to_utf8(buffer.get());
|
||||
theApp.SetConfig("shaderfx_conf", output.c_str());
|
||||
|
||||
EndDialog(m_hWnd, id);
|
||||
} break;
|
||||
|
|
Loading…
Reference in New Issue