[platform] making Windows launcher check and set path variables (AppData/LocalAppData)

GitOrigin-RevId: f693a7f10a206135df486e4c590bd0ad27ac57d4
This commit is contained in:
Roman Shevchenko
2020-01-27 20:37:52 +00:00
committed by intellij-monorepo-bot
parent 4829584d9f
commit d1cee35b46
4 changed files with 21 additions and 3 deletions
Executable → Regular
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
@@ -1165,6 +1165,20 @@ std::wstring GetCurrentDirectoryAsString()
return std::wstring(buffer.data(), sizeWithoutTerminatingZero);
}
static void SetPathVariable(const wchar_t *varName, REFKNOWNFOLDERID rfId)
{
wchar_t env_var_buffer[1];
if (GetEnvironmentVariableW(varName, env_var_buffer, 1) == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)
{
wchar_t *path = NULL;
if (SHGetKnownFolderPath(rfId, KF_FLAG_DONT_VERIFY, NULL, &path) == S_OK)
{
SetEnvironmentVariableW(varName, path);
CoTaskMemFree(path);
}
}
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
@@ -1187,6 +1201,10 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
return 0;
}
// ensures path variables are defined
SetPathVariable(L"APPDATA", FOLDERID_RoamingAppData);
SetPathVariable(L"LOCALAPPDATA", FOLDERID_LocalAppData);
//it's OK to return 0 here, because the control is transferred to the first instance
int exitCode = CheckSingleInstance();
if (exitCode != -1) return exitCode;
+3 -3
View File
@@ -9,8 +9,10 @@
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>
#include <Windows.h>
#include <ShellAPI.h>
#include <Shlobj.h>
#include <Knownfolders.h>
// C RunTime Header Files
#include <stdio.h>
@@ -24,5 +26,3 @@
#include <vector>
#include <string>
#include <sstream>
// TODO: reference additional headers your program requires here