-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
150 lines (139 loc) · 4.97 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
This file is part of the SaveState2snes software
Copyright (C) 2017 Sylvain "Skarsnik" Colinet <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "savestate2snesw.h"
#include "trainingtimer.h"
#include <QApplication>
#include <QMessageBox>
#include "firsttimedialog.h"
#include "shortcuteditdialog.h"
static QTextStream logfile;
static QTextStream lowlogfile;
static QTextStream cout(stdout);
bool dontLogNext = false;
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QByteArray localMsg = msg.toLocal8Bit();
QTextStream* log = &logfile;
//cout << msg;
if (dontLogNext)
return ;
QString logString = QString("%6 %5 - %7: %1 \t(%2:%3, %4)").arg(localMsg.constData()).arg(context.file).arg(context.line).arg(context.function).arg(context.category, 20).arg(QDateTime::currentDateTime().toString(Qt::ISODate));
if (QString(context.category).left(8) == "LowLevel")
{
//cout << "log is lowlevel. Writing to lowlevelfile";
log = &lowlogfile;
}
switch (type)
{
case QtDebugMsg:
*log << logString.arg("Debug");
break;
case QtCriticalMsg:
*log << logString.arg("Critical");
break;
case QtWarningMsg:
*log << logString.arg("Warning");
break;
case QtFatalMsg:
*log << logString.arg("Fatal");
*log<< "\n"; log->flush();
QMessageBox::critical(NULL, QObject::tr("Critical error"), msg);
qApp->exit(1);
break;
case QtInfoMsg:
*log << logString.arg("Info");
break;
}
*log << "\n";
log->flush();
#ifdef QT_DEBUG
if (QString(context.category) == "Telnet")
{
//cout << "Writing to lowlevelfile";
lowlogfile << logString.arg("MSG");
lowlogfile << "\n";
lowlogfile.flush();
}
#endif
if (log != &lowlogfile)
{
//cout << logString;
cout << QString("%1 : %2").arg(context.category, 20).arg(msg) << "\n";
cout.flush();
}
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QDir("/").mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
QFile mlog(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/log.txt");
QFile mlowlog(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/loglow.txt");
logfile.setDevice(&mlog);
lowlogfile.setDevice(&mlowlog);
if (mlog.open(QIODevice::WriteOnly | QIODevice::Text))
{
#ifdef QT_DEBUG
mlowlog.open(QIODevice::WriteOnly | QIODevice::Text);
#endif
qInstallMessageHandler(myMessageOutput);
}
QApplication::setApplicationName("Savestate2SNES");
QSettings settings("skarsnik.nyo.fr", "SaveState2SNES");
QTranslator translator;
QString locale = QLocale::system().name().split('_').first();
translator.load(a.applicationDirPath() + "/i18n/savestate2snes_" + locale + ".qm");
// This is only defined in the PRO file
#ifdef GIT_TAG_VERSION
QString plop(GIT_TAG_VERSION);
plop.remove(0, 1); // Remove the v
QApplication::setApplicationVersion(QVersionNumber::fromString(plop).toString());
#else
QApplication::setApplicationVersion("0.99");
#endif
QLoggingCategory::setFilterRules("EmuNWAccessClient.debug=true\nUSB2SNES.debug=false");
a.installTranslator(&translator);
if (!settings.contains("lastSaveStateDir"))
{
FirstTimeDialog diag;
if (diag.exec() == QDialog::Rejected)
return 1;
settings.setValue("lastSaveStateDir", diag.savePath);
settings.setValue("mode", diag.selectedMode());
}
/*USB2snes* usb2snes = new USB2snes();
QObject::connect(usb2snes, &USB2snes::stateChanged, [=]{
if (usb2snes->state() == USB2snes::Ready)
{
QByteArray prev;
while (true)
{
QByteArray b = usb2snes->getAddress(0xFE1000, 0x16);
if (b != prev)
{
qDebug() << "changed" << b.toHex(' ');
if (b.at(0xC) == 0xF)
qDebug() << "State ended?";
}
prev = b;
}
}
;});
usb2snes->connect();*/
Savestate2snesw w;
w.show();
/*TrainingTimer pt;
pt.show();*/
return a.exec();
}