forked from EnderHDMC/MHWISaveEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
83 lines (68 loc) · 2.53 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
#include "gui/mhwisaveeditor.h"
#include <QApplication>
#include <QTranslator>
#include <QLocale>
#include <QDir>
#include "data/BitmapDB.h"
#include "data/EquipmentDB.h"
#include "data/ItemDB.h"
#include "data/SmithyDB.h"
#include "platform/platform.h"
static void MessagePrintLog(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
static QString logPath = Paths::GetDataPath() + "/MHWISaveEditor.log";
static QFile logFile(logPath);
if (!logFile.isOpen()) logFile.open(QIODevice::WriteOnly);
static QTextStream logger(&logFile);
QString typeStr = "None";
FILE* output = stdout;
switch (type) {
case QtDebugMsg: typeStr = "Debug"; output = stderr; break;
case QtWarningMsg: typeStr = "Warning"; output = stderr; break;
case QtCriticalMsg: typeStr = "Critical"; output = stderr; break;
case QtFatalMsg: typeStr = "Fatal"; output = stderr; break;
case QtInfoMsg: typeStr = "Info"; output = stdout; break;
}
QByteArray printMessage = QString("%1: %2\n").arg(typeStr).arg(msg).toLocal8Bit();
fprintf(output, "%s", printMessage.constData());
logger << printMessage;
logger.flush();
}
int main(int argc, char* argv[])
{
QCoreApplication::setOrganizationName("EnderHDMC");
QCoreApplication::setOrganizationDomain("enderhdmc.github.io");
QCoreApplication::setApplicationName("MHWI Save Editor");
Settings* settings = settings->GetInstance();
bool debugger = Settings::DebuggerPresent();
bool showConsole = settings->GetShowConsole();
if (!debugger) qInstallMessageHandler(MessagePrintLog);
if (!debugger && showConsole) Platform::OpenConsole();
qInfo("Debugger present: %d", debugger);
settings->LogReadPath();
QApplication a(argc, argv);
QDir::setCurrent(qApp->applicationDirPath());
qInfo("Current path: %s", qUtf8Printable(QDir::currentPath()));
ItemDB* itemDB = new ItemDB();
EquipmentDB* equipmentDB = equipmentDB->GetInstance();
SmithyDB* smithyDB = smithyDB->GetInstance();
BitmapDB* bitmapDB = new BitmapDB(itemDB, equipmentDB);
QString uiLanguage = settings->GetUiLanguage();
QTranslator translator;
if (!uiLanguage.isEmpty()) {
QString trFile = "mhwisaveeditor_" + uiLanguage + ".qm";
QString translationPath = Paths::GetResourcesPath("translations/");
if (translator.load(translationPath + trFile)) {
a.installTranslator(&translator);
}
}
MHWISaveEditor w;
w.LoadResources(itemDB, bitmapDB);
w.show();
int ret = a.exec();
delete bitmapDB;
equipmentDB->Free();
smithyDB->Free();
delete itemDB;
return ret;
}