mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-06 02:56:19 +02:00
Merge pull request #6816 from thedax/win32-Unicode
Win32: Use wide strings to parse some command-line arguments, and convert them to proper UTF-8 for others.
This commit is contained in:
commit
64bc2b7bdb
3 files changed
+65
-26
No files matched your search
+5
-2
@@ -694,8 +694,11 @@ std::map<std::string, std::pair<std::string, int>> GetLangValuesMapping() {
|
||||
}
|
||||
|
||||
void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
|
||||
iniFilename_ = FindConfigFile(iniFileName != NULL ? iniFileName : "ppsspp.ini");
|
||||
controllerIniFilename_ = FindConfigFile(controllerIniFilename != NULL ? controllerIniFilename : "controls.ini");
|
||||
const bool useIniFilename = iniFileName != nullptr && strlen(iniFileName) > 0;
|
||||
iniFilename_ = FindConfigFile(useIniFilename ? iniFileName : "ppsspp.ini");
|
||||
|
||||
const bool useControllerIniFilename = controllerIniFilename != nullptr && strlen(controllerIniFilename) > 0;
|
||||
controllerIniFilename_ = FindConfigFile(useControllerIniFilename ? controllerIniFilename : "controls.ini");
|
||||
|
||||
INFO_LOG(LOADER, "Loading config: %s", iniFilename_.c_str());
|
||||
bSaveSettings = true;
|
||||
|
||||
+23
-1
@@ -27,6 +27,8 @@ static recursive_mutex emuThreadLock;
|
||||
static HANDLE emuThread;
|
||||
static volatile long emuThreadReady;
|
||||
|
||||
extern std::vector<std::wstring> GetWideCmdLine();
|
||||
|
||||
enum EmuThreadStatus : long
|
||||
{
|
||||
THREAD_NONE = 0,
|
||||
@@ -89,7 +91,27 @@ unsigned int WINAPI TheThread(void *)
|
||||
|
||||
Host *oldHost = host;
|
||||
|
||||
NativeInit(__argc, (const char **)__argv, "1234", "1234", "1234");
|
||||
// Convert the command-line arguments to Unicode, then to proper UTF-8
|
||||
// (the benefit being that we don't have to pollute the UI project with win32 ifdefs and lots of Convert<whatever>To<whatever>).
|
||||
// This avoids issues with PPSSPP inadvertently destroying paths with Unicode glyphs
|
||||
// (using the ANSI args resulted in Japanese/Chinese glyphs being turned into question marks, at least for me..).
|
||||
// -TheDax
|
||||
std::vector<std::wstring> wideArgs = GetWideCmdLine();
|
||||
std::vector<std::string> argsUTF8;
|
||||
for (auto& string : wideArgs)
|
||||
{
|
||||
argsUTF8.push_back(ConvertWStringToUTF8(string));
|
||||
}
|
||||
|
||||
std::vector<const char *> args;
|
||||
|
||||
for (auto& string: argsUTF8)
|
||||
{
|
||||
args.push_back(string.c_str());
|
||||
}
|
||||
|
||||
NativeInit(static_cast<int>(args.size()), &args[0], "1234", "1234", "1234");
|
||||
|
||||
Host *nativeHost = host;
|
||||
host = oldHost;
|
||||
|
||||
|
||||
+37
-23
@@ -334,6 +334,16 @@ void MakePPSSPPDPIAware()
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::wstring> GetWideCmdLine() {
|
||||
wchar_t **wargv;
|
||||
int wargc = -1;
|
||||
wargv = CommandLineToArgvW(GetCommandLineW(), &wargc);
|
||||
|
||||
std::vector<std::wstring> wideArgs(wargv, wargv + wargc);
|
||||
|
||||
return wideArgs;
|
||||
}
|
||||
|
||||
int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow)
|
||||
{
|
||||
setCurrentThreadName("Main");
|
||||
@@ -385,23 +395,29 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin
|
||||
|
||||
osName = GetWindowsVersion() + " " + GetWindowsSystemArchitecture();
|
||||
|
||||
const char *configFilename = NULL;
|
||||
const char *configOption = "--config=";
|
||||
char configFilename[MAX_PATH] = { 0 };
|
||||
const std::wstring configOption = L"--config=";
|
||||
|
||||
const char *controlsConfigFilename = NULL;
|
||||
const char *controlsOption = "--controlconfig=";
|
||||
char controlsConfigFilename[MAX_PATH] = { 0 };
|
||||
const std::wstring controlsOption = L"--controlconfig=";
|
||||
|
||||
for (int i = 1; i < __argc; ++i)
|
||||
std::vector<std::wstring> wideArgs = GetWideCmdLine();
|
||||
|
||||
for (size_t i = 1; i < wideArgs.size(); ++i)
|
||||
{
|
||||
if (__argv[i][0] == '\0')
|
||||
if (wideArgs[i][0] == L'\0')
|
||||
continue;
|
||||
if (__argv[i][0] == '-')
|
||||
{
|
||||
if (!strncmp(__argv[i], configOption, strlen(configOption)) && strlen(__argv[i]) > strlen(configOption)) {
|
||||
configFilename = __argv[i] + strlen(configOption);
|
||||
if (wideArgs[i][0] == L'-') {
|
||||
if (wideArgs[i].find(configOption) != std::wstring::npos && wideArgs[i].size() > configOption.size()) {
|
||||
const std::wstring tempWide = wideArgs[i].substr(configOption.size());
|
||||
const std::string tempStr = ConvertWStringToUTF8(tempWide);
|
||||
std::strncpy(configFilename, tempStr.c_str(), MAX_PATH);
|
||||
}
|
||||
if (!strncmp(__argv[i], controlsOption, strlen(controlsOption)) && strlen(__argv[i]) > strlen(controlsOption)) {
|
||||
controlsConfigFilename = __argv[i] + strlen(controlsOption);
|
||||
|
||||
if (wideArgs[i].find(controlsOption) != std::wstring::npos && wideArgs[i].size() > controlsOption.size()) {
|
||||
const std::wstring tempWide = wideArgs[i].substr(configOption.size());
|
||||
const std::string tempStr = ConvertWStringToUTF8(tempWide);
|
||||
std::strncpy(configFilename, tempStr.c_str(), MAX_PATH);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -420,32 +436,30 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin
|
||||
bool debugLogLevel = false;
|
||||
|
||||
// The rest is handled in NativeInit().
|
||||
for (int i = 1; i < __argc; ++i)
|
||||
for (size_t i = 1; i < wideArgs.size(); ++i)
|
||||
{
|
||||
if (__argv[i][0] == '\0')
|
||||
if (wideArgs[i][0] == L'\0')
|
||||
continue;
|
||||
|
||||
if (__argv[i][0] == '-')
|
||||
{
|
||||
switch (__argv[i][1])
|
||||
{
|
||||
case 'l':
|
||||
if (wideArgs[i][0] == L'-') {
|
||||
switch (wideArgs[i][1]) {
|
||||
case L'l':
|
||||
showLog = true;
|
||||
g_Config.bEnableLogging = true;
|
||||
break;
|
||||
case 's':
|
||||
case L's':
|
||||
g_Config.bAutoRun = false;
|
||||
g_Config.bSaveSettings = false;
|
||||
break;
|
||||
case 'd':
|
||||
case L'd':
|
||||
debugLogLevel = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!strncmp(__argv[i], "--fullscreen", strlen("--fullscreen")))
|
||||
if (wideArgs[i] == L"--fullscreen")
|
||||
g_Config.bFullScreen = true;
|
||||
|
||||
if (!strncmp(__argv[i], "--windowed", strlen("--windowed")))
|
||||
if (wideArgs[i] == L"--windowed")
|
||||
g_Config.bFullScreen = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user