From 388ac179f81029f5bcd0766d7cfed2700003eaaa Mon Sep 17 00:00:00 2001 From: Gerrit 'Geaz' Gazic Date: Sun, 3 May 2020 14:43:15 +0200 Subject: [PATCH] Change Edge/Chromium user data folder Previously the code passed a nullptr to the creation of the Edge/Chromium Webview. This defaults the webview to create a user data folder in the folder of the calling executable. In case of an installed application, the executing user may not have the permissions to do this. This commit changes the default user data folder to "%APPDATA%/[EXECUTABLE_NAME]". Fixes #362 --- webview.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/webview.h b/webview.h index 20ebe0793..08c04f1f9 100644 --- a/webview.h +++ b/webview.h @@ -737,8 +737,12 @@ using browser_engine = cocoa_wkwebview_engine; #define WIN32_LEAN_AND_MEAN #include +#include +#include +#include #pragma comment(lib, "user32.lib") +#pragma comment(lib, "Shlwapi.lib") // EdgeHTML headers and libs #include @@ -848,8 +852,17 @@ class edge_chromium : public browser { CoInitializeEx(nullptr, 0); std::atomic_flag flag = ATOMIC_FLAG_INIT; flag.test_and_set(); + + char currentExePath[MAX_PATH]; + GetModuleFileNameA(NULL, currentExePath, MAX_PATH); + char* currentExeName = PathFindFileNameA(currentExePath); + + std::wstring_convert> wideCharConverter; + std::wstring userDataFolder = wideCharConverter.from_bytes(std::getenv("APPDATA")); + std::wstring currentExeNameW = wideCharConverter.from_bytes(currentExeName); + HRESULT res = CreateWebView2EnvironmentWithDetails( - nullptr, nullptr, nullptr, + nullptr, (userDataFolder + L"/" + currentExeNameW).c_str(), nullptr, new webview2_com_handler(wnd, [&](IWebView2WebView *webview) { m_webview = webview; flag.clear();