File: main.cpp

package info (click to toggle)
dyssol 1.5.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,204 kB
  • sloc: cpp: 53,870; sh: 85; python: 59; makefile: 11
file content (71 lines) | stat: -rw-r--r-- 1,543 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* Copyright (c) 2020, Dyssol Development Team.
 * Copyright (c) 2024, DyssolTEC GmbH.
 * All rights reserved. This file is part of Dyssol. See LICENSE file for license information. */

#include "Dyssol.h"
#include <QApplication>

#ifdef _MSC_VER
// Print message to the VS Output window.
void VSDebugOutput(const std::string& _message)
{
	OutputDebugStringA(_message.c_str());
}
#endif

void HandleException(const std::exception_ptr& _exceptionPtr)
{
	try
	{
		if (_exceptionPtr)
			std::rethrow_exception(_exceptionPtr);
	}
	catch (const std::exception& e)
	{
		const std::string message = "Unknown unhandled exception caught: '" + std::string{ e.what() } + "'\n";
		std::cout << message;
#ifdef _MSC_VER
		VSDebugOutput(message);
#endif
	}
}

int main(int argc, char* argv[])
{
	Q_INIT_RESOURCE(Resources);

	int nExitCode = 0;

	do
	{
		QApplication a(argc, argv);
		QApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton);
		qRegisterMetaTypeStreamOperators<QList<bool>>("QList<bool>");
		QStringList args = a.arguments();

		for (int i = 0; i < args.size(); ++i)
			std::cout << args[i].toStdString() << std::endl;

		Dyssol w;

		std::exception_ptr exceptionPtr;
		try
		{
			w.InitializeConnections();
			w.show();
			if (args.size() == 2)
				w.OpenFromCommandLine(args[1]);
			else
				w.OpenDyssol();
			nExitCode = a.exec();
		}
		catch(...)
		{
			exceptionPtr = std::current_exception(); // capture current exception
		}
		HandleException(exceptionPtr);
	}
	while (nExitCode == Dyssol::EXIT_CODE_REBOOT);

	return 0;
}