-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
132 lines (99 loc) · 4.33 KB
/
main.cpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <QCommandLineParser>
#include <QCoreApplication>
#include <QDir>
#include <QFileInfo>
#include <QGuiApplication>
#include "pushquickview.h"
#ifdef Q_OS_WIN
# define PATH_SEPARATOR ";"
#else
# define PATH_SEPARATOR ":"
#endif
#ifdef Q_OS_WIN
#include <QStandardPaths>
#include <dbghelp.h>
#include <qt_windows.h>
#include <tchar.h>
static TCHAR miniDumpApplicationName[_MAX_PATH];
static TCHAR miniDumpPath[_MAX_PATH];
static LONG WINAPI miniDumpExceptionFilter(PEXCEPTION_POINTERS exceptionPointers)
{
if (IsDebuggerPresent())
return EXCEPTION_CONTINUE_SEARCH;
HMODULE dbgHelp = LoadLibrary(TEXT("dbghelp.dll"));
if (dbgHelp == NULL)
return EXCEPTION_EXECUTE_HANDLER;
HANDLE file = CreateFile(miniDumpPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (file == INVALID_HANDLE_VALUE)
return EXCEPTION_EXECUTE_HANDLER;
typedef BOOL (WINAPI *LPMINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD ProcessId, HANDLE hFile, MINIDUMP_TYPE DumpType, CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, CONST PMINIDUMP_USER_STREAM_INFORMATION UserEncoderParam, CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
LPMINIDUMPWRITEDUMP miniDumpWriteDump = (LPMINIDUMPWRITEDUMP)GetProcAddress(dbgHelp, "MiniDumpWriteDump");
if (!miniDumpWriteDump)
return EXCEPTION_EXECUTE_HANDLER;
MINIDUMP_EXCEPTION_INFORMATION mei;
mei.ThreadId = GetCurrentThreadId();
mei.ExceptionPointers = exceptionPointers;
mei.ClientPointers = TRUE;
BOOL writeDump = miniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), file, MiniDumpNormal, exceptionPointers ? &mei : NULL, NULL, NULL);
CloseHandle(file);
FreeLibrary(dbgHelp);
if (writeDump)
{
TCHAR message[_MAX_PATH * 2];
lstrcpy(message, miniDumpApplicationName);
lstrcat(message, TEXT(" just crashed. Crash information was saved to the file '"));
lstrcat(message, miniDumpPath);
lstrcat(message, TEXT("', please send it to the developers for debugging."));
MessageBox(NULL, message, miniDumpApplicationName, MB_OK);
}
return EXCEPTION_EXECUTE_HANDLER;
}
#endif
int main(int argc, char *argv[])
{
{
QCoreApplication app(argc, argv);
QDir::setCurrent(app.applicationDirPath());
}
qputenv("QML2_IMPORT_PATH", "Push2/qml" PATH_SEPARATOR "Qt/qml");
qputenv("QT_PLUGIN_PATH", "Qt/plugins");
QGuiApplication app(argc, argv);
app.setApplicationName("Push2Qml");
#ifdef Q_OS_WIN
lstrcpy(miniDumpApplicationName, reinterpret_cast<LPCWSTR>(app.applicationName().utf16()));
QString miniDumpDir;
miniDumpDir = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
miniDumpDir += "/Crash Dumps";
QDir(miniDumpDir).mkpath("...");
lstrcpy(miniDumpPath, reinterpret_cast<LPCWSTR>(
QDir::toNativeSeparators(miniDumpDir
+ "/" + QFileInfo(qApp->applicationFilePath()).completeBaseName() + ".dmp"
).utf16()));
SetUnhandledExceptionFilter(miniDumpExceptionFilter);
#endif
QCommandLineParser parser;
parser.setApplicationDescription("Ableton Push 2 QML Runner");
parser.addHelpOption();
QCommandLineOption ditherOption("dither",
QCoreApplication::translate("main", "Dither graphics when rendering to BGR565."));
parser.addOption(ditherOption);
parser.addPositionalArgument("filename",
QCoreApplication::translate("main", "The file to open (defaults to PushDisplay.qml in"
" the same directory as this application if it exists"
" for Ableton Push 1 emulation)."));
parser.process(app);
QString filename;
if (!parser.positionalArguments().empty())
filename = QDir::fromNativeSeparators(parser.positionalArguments().first());
else
filename = app.applicationDirPath() + "/PushDisplay.qml";
if (!QFileInfo(filename).exists())
parser.showHelp(0);
PushQuickView w(QUrl::fromLocalFile(filename));
w.setDithering(parser.isSet("dither"));
if (!w.isOpen()) {
qCritical("Unable to open Push 2 display");
return 1;
}
return app.exec();
}