| 222 | ******************************************************************************/ |
| 223 | |
| 224 | static int runApplication() noexcept { |
| 225 | // For deployment testing purposes, exit the application now if the flag |
| 226 | // '--exit-after-startup' is passed. This shall be done *before* any user |
| 227 | // interaction (e.g. message box) to make it working headless. |
| 228 | const char* exitFlagName = "--exit-after-startup"; |
| 229 | if (qApp->arguments().contains(exitFlagName)) { |
| 230 | qInfo().nospace() << "Exit requested by flag '" << exitFlagName << "'."; |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | // If the file format is unstable (e.g. for nightly builds), ask to abort now. |
| 235 | // This warning *must* come that early to be really sure that no files are |
| 236 | // overwritten with unstable content! |
| 237 | if (!isFileFormatStableOrAcceptUnstable()) { |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | // Get the path of the workspace to open. By default, open the recently used |
| 242 | // workspace stored in the user settings. |
| 243 | FilePath path = Workspace::getMostRecentlyUsedWorkspacePath(); |
| 244 | qDebug() << "Recently used workspace:" << path.toNative(); |
| 245 | |
| 246 | // If the workspace path is specified by environment variable, use this one. |
| 247 | const char* wsEnvVarName = "LIBREPCB_WORKSPACE"; |
| 248 | QString wsEnvStr = qgetenv(wsEnvVarName); |
| 249 | if (!wsEnvStr.isEmpty()) { |
| 250 | qInfo() << "Workspace path overridden by" << wsEnvVarName |
| 251 | << "environment variable:" << wsEnvStr; |
| 252 | path.setPath(wsEnvStr); |
| 253 | } |
| 254 | |
| 255 | // If creating or opening a workspace failed, allow to choose another |
| 256 | // workspace path until it succeeds or the user aborts. |
| 257 | while (true) { |
| 258 | try { |
| 259 | return openWorkspace(path); // can throw |
| 260 | } catch (const UserCanceled& e) { |
| 261 | return 0; // User canceled -> exit application. |
| 262 | } catch (const Exception& e) { |
| 263 | QMessageBox::critical( |
| 264 | nullptr, QApplication::translate("Workspace", "Error"), |
| 265 | QString(QApplication::translate( |
| 266 | "Workspace", "Could not open the workspace \"%1\":")) |
| 267 | .arg(path.toNative()) % |
| 268 | "\n\n" % e.getMsg()); |
| 269 | path = FilePath(); // Make sure the workspace selector wizard is shown. |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | /******************************************************************************* |
| 275 | * isFileFormatStableOrAcceptUnstable() |
no test coverage detected