Skip to content

Commit 793ee04

Browse files
committed
Use and modify NETBEANS_USERDIR in Windows launcher
1 parent e13fa29 commit 793ee04

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

nb/ide.launcher/windows/nblauncher.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
using namespace std;
3535

3636
const char *NbLauncher::NBEXEC_FILE_PATH = NBEXEC_DLL;
37+
const char *ENV_NETBEANS_USERDIR="NETBEANS_USERDIR";
3738
const char *NbLauncher::OPT_NB_DEFAULT_USER_DIR = "netbeans_default_userdir=";
3839
const char *NbLauncher::OPT_NB_DEFAULT_CACHE_DIR = "netbeans_default_cachedir=";
3940
const char *NbLauncher::OPT_NB_DEFAULT_OPTIONS = "netbeans_default_options=";
@@ -82,13 +83,26 @@ int NbLauncher::start(int argc, char *argv[]) {
8283
return -1;
8384
}
8485

85-
parseConfigFile((baseDir + "\\etc\\" + getAppName() + ".conf").c_str());
86+
bool skipUserDir = false;
87+
char *userDirViaEnv = getenv(ENV_NETBEANS_USERDIR);
88+
if (userDirViaEnv != NULL) {
89+
logMsg("NbLauncher::using NETBEANS_USERDIR env variable (%s)", userDirViaEnv);
90+
string udve = userDirViaEnv;
91+
if (udve == "nope") {
92+
skipUserDir = true;
93+
userDirViaEnv = NULL;
94+
} else {
95+
userDir = userDirViaEnv;
96+
}
97+
}
98+
99+
parseConfigFile((baseDir + "\\etc\\" + getAppName() + ".conf").c_str(), userDirViaEnv == NULL);
86100

87101
if (!parseArgs(argc, argv)) {
88102
return -1;
89103
}
90104
string oldUserDir = userDir;
91-
parseConfigFile((userDir + "\\etc\\" + getAppName() + ".conf").c_str());
105+
parseConfigFile((userDir + "\\etc\\" + getAppName() + ".conf").c_str(), userDirViaEnv == NULL);
92106
userDir = oldUserDir;
93107

94108
addExtraClusters();
@@ -114,6 +128,13 @@ int NbLauncher::start(int argc, char *argv[]) {
114128
if (!userDir.empty()) {
115129
newArgs.add(ARG_NAME_USER_DIR);
116130
newArgs.add(userDir.c_str());
131+
if (!skipUserDir) {
132+
string toSet = ENV_NETBEANS_USERDIR;
133+
toSet = toSet + "=" + userDir;
134+
putenv(toSet.c_str());
135+
136+
137+
}
117138
}
118139
if (!defUserDirRoot.empty()) {
119140
newArgs.add(ARG_DEFAULT_USER_DIR_ROOT);
@@ -460,7 +481,7 @@ bool NbLauncher::getOption(char *&str, const char *opt) {
460481
return false;
461482
}
462483

463-
bool NbLauncher::parseConfigFile(const char* path) {
484+
bool NbLauncher::parseConfigFile(const char* path, const bool searchUserDir) {
464485
logMsg("parseConfigFile(%s)", path);
465486
FILE *file = fopen(path, "r");
466487
if (!file) {
@@ -474,7 +495,7 @@ bool NbLauncher::parseConfigFile(const char* path) {
474495
if (*str == '#') {
475496
continue;
476497
}
477-
if (getOption(str, getDefUserDirOptName())) {
498+
if (searchUserDir && getOption(str, getDefUserDirOptName())) {
478499
findUserDir(str);
479500
logMsg("User dir: %s", userDir.c_str());
480501
} else if (getOption(str, getDefCacheDirOptName())) {

nb/ide.launcher/windows/nblauncher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class NbLauncher {
8080
NbLauncher(const NbLauncher& orig);
8181
bool readClusterFile();
8282
bool parseArgs(int argc, char *argv[]);
83-
bool parseConfigFile(const char* path);
83+
bool parseConfigFile(const char* path, const bool searchUserDir);
8484
bool getOption(char *&str, const char *opt);
8585
void addCluster(const char *cl);
8686
void addExtraClusters();

0 commit comments

Comments
 (0)