MCPcopy Create free account
hub / github.com/LibrePCB/LibrePCB / runApplication

Function runApplication

apps/librepcb/main.cpp:224–272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

222 ******************************************************************************/
223
224static 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()

Callers 1

mainFunction · 0.85

Calls 9

openWorkspaceFunction · 0.85
translateFunction · 0.85
QStringClass · 0.85
toNativeMethod · 0.80
FilePathClass · 0.50
containsMethod · 0.45
isEmptyMethod · 0.45
setPathMethod · 0.45

Tested by

no test coverage detected