@@ -40,7 +40,6 @@ static Path s_confDir;
4040static Path s_crashDir; // where to place crash dumps
4141static Path s_dataDir;
4242static Path s_logDir; // where to place log files
43- static Path s_webDir;
4443
4544
4645/* ***************************************************************************
@@ -51,7 +50,7 @@ static Path s_webDir;
5150
5251// ===========================================================================
5352static Path makeAppDir (string_view path) {
54- auto out = appRootDir () / path;
53+ auto out = s_rootDir / path;
5554 return out;
5655}
5756
@@ -120,33 +119,16 @@ void ConfigAppXml::onConfigChange(const XDocument & doc) {
120119// ===========================================================================
121120static void initVars () {
122121 // Application name and version
123- fileGetCurrentDir (&s_initialDir);
124122 auto exeName = (Path) envExecPath ();
125123 if (s_appBaseName.empty ())
126124 s_appBaseName = exeName.stem ();
127125 if (!s_appVer)
128126 s_appVer = envExecVersion ();
129- if (s_appVer) {
130- Cli cli;
131- ostringstream hdr;
132- Time8601Str ds (envExecBuildTime ());
133- auto verStr = toString (s_appVer);
134- hdr << s_appBaseName
135- << " v" << verStr
136- << " (" << ds.view ().substr (0 , 10 ) << " )" ;
137- cli.header (hdr.str ())
138- .versionOpt (verStr, s_appBaseName);
139- }
140- s_appName = s_appBaseName;
141- if (s_appIndex > 1 )
142- s_appName += toChars (s_appIndex);
143- s_appSvcName = s_appName;
144- if (s_groupIndex > 1 ) {
145- s_appSvcName += ' .' ;
146- s_appSvcName += toChars (s_groupIndex);
147- }
127+ s_appIndex = 1 ;
128+ s_groupIndex = 1 ;
148129
149130 // Directories
131+ fileGetCurrentDir (&s_initialDir);
150132 s_binDir = exeName.parentPath ();
151133 if (s_appFlags.any (fAppWithFiles ) && s_binDir.stem () == " bin" ) {
152134 s_rootDir = s_binDir.parentPath ();
@@ -158,7 +140,6 @@ static void initVars() {
158140 s_crashDir = makeAppDir (" crash" );
159141 s_dataDir = makeAppDir (" data" );
160142 s_logDir = makeAppDir (" log" );
161- s_webDir = makeAppDir (" web" );
162143
163144 if (s_appFlags.any (fAppWithChdir ))
164145 fileSetCurrentDir (s_rootDir);
@@ -171,11 +152,6 @@ static void initVars() {
171152
172153// ===========================================================================
173154static void initApp () {
174- iPlatformInitialize (PlatformInit::kBeforeAppVars );
175- if (s_appFlags.all (fAppWithLogs | fAppWithConsole ))
176- logMonitor (consoleBasicLogger ());
177- iFileInitialize ();
178- initVars ();
179155 iConfigInitialize ();
180156 configMonitor (" app.xml" , &s_appXml);
181157 if (s_appFlags.any (fAppWithLogs ))
@@ -189,8 +165,6 @@ static void initApp() {
189165 iHttpRouteInitialize ();
190166 iWebAdminInitialize ();
191167
192- taskPushEvent (s_appTasks.data (), s_appTasks.size ());
193-
194168 {
195169 lock_guard lk{s_runMut};
196170 if (s_runMode == kRunStopping ) {
@@ -203,6 +177,8 @@ static void initApp() {
203177 }
204178 }
205179
180+ taskPushEvent (s_appTasks.data (), s_appTasks.size ());
181+
206182 Cli cli;
207183 if (!cli.exec ()) {
208184 // Extended parsing failed or the action completed without requesting
@@ -269,26 +245,9 @@ int Dim::appRun(
269245 s_appFlags = flags;
270246 s_appTasks.clear ();
271247
272- Cli cli;
273- if (!s_appFlags.any (fAppWithService )) {
274- s_appIndex = 1 ;
275- s_groupIndex = 1 ;
276- } else {
277- cli.opt (&s_appIndex, " app-index" , 1 )
278- .desc (" Identifies service when multiple instances "
279- " are configured." );
280- cli.opt (&s_groupIndex, " group-index" , 1 )
281- .desc (" Identifies service group when there are multiple." );
282- }
283-
284- // The command line will be validated later by the application, right now
285- // we just need the appIndex and groupIndex to process the configuration.
286- auto parseOk = cli.parse (argc, argv);
287-
288248 s_appVer = ver;
289249 s_appBaseName = baseName;
290250 s_appName.clear ();
291- s_webDir.clear ();
292251
293252 // Finish initialization and start.
294253 iPlatformInitialize (PlatformInit::kBeforeAll );
@@ -298,6 +257,44 @@ int Dim::appRun(
298257 logDefaultMonitor (consoleBasicLogger ());
299258 iTaskInitialize ();
300259 iTimerInitialize ();
260+ iPlatformInitialize (PlatformInit::kBeforeAppVars );
261+ if (s_appFlags.all (fAppWithLogs | fAppWithConsole ))
262+ logMonitor (consoleBasicLogger ());
263+ iFileInitialize ();
264+ initVars ();
265+
266+ Cli cli;
267+ if (s_appVer) {
268+ ostringstream hdr;
269+ Time8601Str ds (envExecBuildTime ());
270+ auto verStr = toString (s_appVer);
271+ hdr << s_appBaseName
272+ << " v" << verStr
273+ << " (" << ds.view ().substr (0 , 10 ) << " )" ;
274+ cli.header (hdr.str ())
275+ .versionOpt (verStr, s_appBaseName);
276+ }
277+ if (s_appFlags.any (fAppWithService )) {
278+ cli.opt (&s_appIndex, " app-index" , 1 )
279+ .desc (" Identifies service when multiple instances "
280+ " are configured." );
281+ cli.opt (&s_groupIndex, " group-index" , 1 )
282+ .desc (" Identifies service group when there are multiple." );
283+ }
284+
285+ // The command line can be validated later by the application during the
286+ // cli.exec() call in initApp(), right now we just need appIndex and
287+ // groupIndex to process the configuration.
288+ auto parseOk = cli.parse (argc, argv);
289+
290+ s_appName = s_appBaseName;
291+ if (s_appIndex > 1 )
292+ s_appName += toChars (s_appIndex);
293+ s_appSvcName = s_appName;
294+ if (s_groupIndex > 1 ) {
295+ s_appSvcName += ' .' ;
296+ s_appSvcName += toChars (s_groupIndex);
297+ }
301298
302299 if (parseOk) {
303300 taskPushEvent (initApp);
@@ -335,6 +332,7 @@ int Dim::appRun(
335332
336333// ===========================================================================
337334unsigned Dim::appIndex () {
335+ assert (!s_appName.empty ());
338336 return s_appIndex;
339337}
340338
@@ -362,6 +360,7 @@ const string & Dim::appName() {
362360
363361// ===========================================================================
364362unsigned Dim::appGroupIndex () {
363+ assert (!s_appName.empty ());
365364 return s_groupIndex;
366365}
367366
@@ -395,7 +394,7 @@ const Path & Dim::appBinDir() {
395394}
396395
397396// ===========================================================================
398- const Path & Dim::appConfigDir () {
397+ const Path & Dim::appConfDir () {
399398 assert (!s_appName.empty ());
400399 return s_confDir;
401400}
@@ -442,8 +441,8 @@ bool Dim::appCliShutdownSignaled() {
442441}
443442
444443// ===========================================================================
445- bool Dim::appConfigPath (Path * out, string_view file, bool cine) {
446- return !fileChildPath (out, appConfigDir (), file, cine);
444+ bool Dim::appConfPath (Path * out, string_view file, bool cine) {
445+ return !fileChildPath (out, appConfDir (), file, cine);
447446}
448447
449448// ===========================================================================
0 commit comments