From 9740686f675789e1dd5807adad03eacd9fc739ec Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 16 Jun 2020 23:51:44 +0200 Subject: [PATCH] [platform] saner and simpler "--help" handling in Windows launcher (IDEA-243130) GitOrigin-RevId: 7f1360a7cc25323a41f04803f4745be801a0fdc6 --- .../WinLauncher/WinLauncher/WinLauncher.cpp | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/native/WinLauncher/WinLauncher/WinLauncher.cpp b/native/WinLauncher/WinLauncher/WinLauncher.cpp index 4c2fca0a848f..c44ce4f547fa 100644 --- a/native/WinLauncher/WinLauncher/WinLauncher.cpp +++ b/native/WinLauncher/WinLauncher/WinLauncher.cpp @@ -715,24 +715,6 @@ jobjectArray ArgsToJavaArray(std::vector args) return result; } -void PrintUsage() -{ - char fullPath[_MAX_PATH]; - GetModuleFileNameA(NULL, fullPath, _MAX_PATH); - std::string::size_type pos = std::string(fullPath).find_last_of("\\/"); - std::string fileName = std::string(fullPath).substr(pos+1); - - std::stringstream buf; - buf << "Usage:\n "; - buf << fileName + " -h | -? | --help\n "; - buf << fileName + " [project_dir]\n "; - buf << fileName + " [-l|--line line] [project_dir|--temp-project] file[:line]\n "; - buf << fileName + " diff \n "; - buf << fileName + " merge [base] "; - std::string title = "Command line options."; - MessageBoxA(NULL, buf.str().c_str(), title.c_str(), MB_OK); -} - bool isNumber(std::string line) { char* p; @@ -749,14 +731,6 @@ std::vector ParseCommandLine(LPCWSTR commandLine) std::vector result; for (int i = 1; i < numArgs; i++) { - if ((wcscmp(L"-h", argv[i]) == 0) || - (wcscmp(L"-?", argv[i]) == 0) || - (wcscmp(L"--help", argv[i]) == 0)) - { - PrintUsage(); - std::exit(0); - } - std::wstring arg(argv[i]); std::string command(arg.begin(), arg.end()); // IDEA-230983 @@ -1162,6 +1136,24 @@ static void SetPathVariable(const wchar_t *varName, REFKNOWNFOLDERID rfId) } } +void PrintUsage() +{ + char fullPath[_MAX_PATH]; + GetModuleFileNameA(NULL, fullPath, _MAX_PATH); + std::string::size_type pos = std::string(fullPath).find_last_of("\\/"); + std::string fileName = std::string(fullPath).substr(pos+1); + + std::stringstream buf; + buf << "Usage:\n "; + buf << fileName + " -h | -? | --help\n "; + buf << fileName + " [project_dir]\n "; + buf << fileName + " [-l|--line line] [project_dir|--temp-project] file[:line]\n "; + buf << fileName + " diff \n "; + buf << fileName + " merge [base] "; + + MessageBoxA(NULL, buf.str().c_str(), "Command-line Options", MB_OK); +} + int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, @@ -1184,6 +1176,15 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, return 0; } + for (int i = 1; i < __argc; i++) + { + if (wcscmp(L"-h", __wargv[i]) == 0 || wcscmp(L"-?", __wargv[i]) == 0 || wcscmp(L"--help", __wargv[i]) == 0) + { + PrintUsage(); + return 0; + } + } + // ensures path variables are defined SetPathVariable(L"APPDATA", FOLDERID_RoamingAppData); SetPathVariable(L"LOCALAPPDATA", FOLDERID_LocalAppData); @@ -1226,4 +1227,4 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, CloseHandle(hFileMapping); return hookExitCode; -} +} \ No newline at end of file