-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
75 lines (63 loc) · 1.96 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
#include <exception>
#include <QApplication>
#include <QDir>
#include <QFile>
#include <QMessageBox>
#include <QSettings>
#include <QString>
#include <QTextStream>
#include "httpdownload.hpp"
#include "mainwindow.h"
#include "init.h"
void logToFile(QtMsgType msgType, const QMessageLogContext& ctx, const QString& msg)
{
QString type;
switch (msgType) {
case QtDebugMsg:
type = "Debug";
break;
case QtWarningMsg:
type = "Warning";
break;
case QtCriticalMsg:
type = "Critical";
break;
case QtFatalMsg:
type = "Fatal";
break;
}
const QString text = QString("[%1] (%2): %3").arg(ctx.category).arg(type).arg(msg);
QFile outFile("log.txt");
outFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append);
QTextStream ts(&outFile);
ts << text << endl;
}
int main(int argc, char *argv[]) try
{
// Create config
QSettings config("config.ini", QSettings::IniFormat);
vfg::config::merge(config, vfg::config::getDefaultSettings());
if(config.value("enable_logging", false).toBool()) {
qInstallMessageHandler(logToFile);
}
// Write scripts
QDir current;
current.mkdir("scripts");
QFile::copy(":/scripts/imagemagick.ini", "scripts/imagemagick.ini");
QFile::copy(":/scripts/gifsicle.ini", "scripts/gifsicle.ini");
QFile::copy(":/scripts/x264.ini", "scripts/x264.ini");
QFile::copy(":/scripts/d2v_template.avs", "scripts/d2v_template.avs");
QFile::copy(":/scripts/default_template.avs", "scripts/default_template.avs");
const QString appName = "ScreenPicker 3.0 (beta) rev1";
QApplication a(argc, argv);
a.setApplicationName(appName);
a.setApplicationDisplayName(appName);
a.setApplicationVersion(appName);
MainWindow w;
w.show();
return a.exec();
}
catch(const std::exception& ex) {
QMessageBox::critical(nullptr, QApplication::tr("Critical error"), QString(ex.what()));
return 0;
}