Skip to content

Commit ccaf8e2

Browse files
mikekilburnrogerwang
authored andcommitted
Expand Windows psudovars (ex; %APPDATA%) passed in chromium-args in the same
way as when passed as command line parameters. This is the only way to set the user-data-dir to the users roaming folder without creating a separate launcher which isnt 100% fool proof since users can still run nw.exe directly.
1 parent b2bfa2e commit ccaf8e2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/nw_package.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
#include "third_party/node-nw/deps/uv/include/uv.h"
4747
#include "ui/base/resource/resource_bundle.h"
4848

49+
#if defined(OS_WIN)
50+
#include <windows.h>
51+
#endif
52+
4953
using base::CommandLine;
5054

5155
namespace base {
@@ -463,6 +467,19 @@ void Package::ReadChromiumArgs() {
463467
if (!got_env)
464468
return;
465469

470+
// Expand Windows psudovars (ex; %APPDATA%) passed in chromium-args in the same way as when
471+
// passed as command line parameters.
472+
#if defined(OS_WIN)
473+
TCHAR szEnvPath[MAX_PATH];
474+
std::wstring ws;
475+
ws.assign( args.begin(), args.end());
476+
if (ExpandEnvironmentStrings(ws.c_str(), szEnvPath,MAX_PATH) != 0) {
477+
std::wstring ws_out = szEnvPath;
478+
args = std::string(ws_out.begin(), ws_out.end());
479+
} else {
480+
ReportError("Failed to expand chromium args",args.c_str());
481+
}
482+
#endif
466483
args = env_args + kChromiumArgsSeparator + args;
467484

468485
std::vector<std::string> chromium_args;

0 commit comments

Comments
 (0)