@@ -171,46 +171,52 @@ std::wstring ASCIIToWide(const std::string& ascii) {
171
171
Package::Package ()
172
172
: path_(),
173
173
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.
177
184
// Note: self_extract_ is true here, otherwise a 'Invalid Package' error
178
185
// would be triggered.
179
- base::FilePath path = GetSelfPath ().DirName ();
186
+ path = GetSelfPath ().DirName ();
180
187
#if defined(OS_MACOSX)
181
188
path = path.DirName ().DirName ().DirName ();
182
189
#endif
183
190
if (InitFromPath (path))
184
191
return ;
185
192
193
+ // 3. try to load from <exe-folder>/package.nw
186
194
path = path.AppendASCII (" package.nw" );
187
195
if (InitFromPath (path))
188
196
return ;
189
197
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();
191
201
const base::CommandLine::StringVector& args = command_line->GetArgs ();
192
202
203
+ // 4.1. try --nwapp= argument
193
204
if (command_line->HasSwitch (" nwapp" )) {
194
205
path = command_line->GetSwitchValuePath (" nwapp" );
195
206
self_extract_ = false ;
196
207
if (InitFromPath (path))
197
208
return ;
198
209
}
199
210
211
+ // 4.2 try first CLI argument
200
212
if (args.size () > 0 ) {
201
213
self_extract_ = false ;
202
214
path = FilePath (args[0 ]);
203
215
if (InitFromPath (path))
204
216
return ;
205
217
}
206
218
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
214
220
self_extract_ = false ;
215
221
InitWithDefault ();
216
222
}
0 commit comments