Skip to content

Commit 3603b27

Browse files
committed
Merge pull request nwjs#4710 from ghostoy/issue-4681
Reordered path finding for backward compatible with nw12
2 parents 1a750fd + 935174a commit 3603b27

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/nw_package.cc

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,46 +171,52 @@ std::wstring ASCIIToWide(const std::string& ascii) {
171171
Package::Package()
172172
: path_(),
173173
self_extract_(true) {
174-
CommandLine* command_line = CommandLine::ForCurrentProcess();
175-
// LOG(INFO) << command_line->GetCommandLineString();
176-
// Try to load from the folder where the exe resides.
174+
175+
base::FilePath path;
176+
177+
// 1. try to extract self
178+
self_extract_ = true;
179+
path = GetSelfPath();
180+
if (InitFromPath(path))
181+
return;
182+
183+
// 2. try to load from the folder where the exe resides.
177184
// Note: self_extract_ is true here, otherwise a 'Invalid Package' error
178185
// would be triggered.
179-
base::FilePath path = GetSelfPath().DirName();
186+
path = GetSelfPath().DirName();
180187
#if defined(OS_MACOSX)
181188
path = path.DirName().DirName().DirName();
182189
#endif
183190
if (InitFromPath(path))
184191
return;
185192

193+
// 3. try to load from <exe-folder>/package.nw
186194
path = path.AppendASCII("package.nw");
187195
if (InitFromPath(path))
188196
return;
189197

190-
// Then see if we have arguments and extract it.
198+
// 4. see if we have arguments and extract it.
199+
CommandLine* command_line = CommandLine::ForCurrentProcess();
200+
// LOG(INFO) << command_line->GetCommandLineString();
191201
const base::CommandLine::StringVector& args = command_line->GetArgs();
192202

203+
// 4.1. try --nwapp= argument
193204
if (command_line->HasSwitch("nwapp")) {
194205
path = command_line->GetSwitchValuePath("nwapp");
195206
self_extract_ = false;
196207
if (InitFromPath(path))
197208
return;
198209
}
199210

211+
// 4.2 try first CLI argument
200212
if (args.size() > 0) {
201213
self_extract_ = false;
202214
path = FilePath(args[0]);
203215
if (InitFromPath(path))
204216
return;
205217
}
206218

207-
self_extract_ = true;
208-
// Try to extract self.
209-
path = GetSelfPath();
210-
if (InitFromPath(path))
211-
return;
212-
213-
// Finally we init with default settings.
219+
// 5. init with default settings
214220
self_extract_ = false;
215221
InitWithDefault();
216222
}

0 commit comments

Comments
 (0)