-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
98 lines (76 loc) · 2.22 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
/*
* homm3-wallpaper, live HOMM3 wallpaper
* Copyright (C) 2022 i.Dark_Templar <darktemplar@dark-templar-archives.net>
*
* Subject to terms and condition provided in LICENSE.txt
*
*/
#include <stdio.h>
#include <inttypes.h>
#include <filesystem>
#include <map>
#include <memory>
#include <stdexcept>
#include <tuple>
#include <utility>
#include <QtGui/QGuiApplication>
#include <QtQml/QQmlApplicationEngine>
#include <QtQml/QQmlContext>
#include "def_file.h"
#include "homm3_image_provider.h"
#include "homm3map.h"
#include "homm3singleton.h"
#include "lod_archive.h"
#include "vcmi/CBinaryReader.h"
#include "vcmi/CFileInputStream.h"
int main(int argc, char **argv)
{
try
{
if (argc < 3)
{
fprintf(stderr,
"ERROR: not enough arguments\n"
"\n"
"USAGE: %s map archive [archive ...]\n"
"\twhere archive is usually H3sprite.lod and H3ab_spr.lod\n",
argv[0]);
return -1;
}
{
std::map<std::string, std::tuple<std::string, LodEntry> > lod_entries;
for (int i = 2; i < argc; ++i)
{
CFileInputStream file_stream{std::filesystem::path(argv[i])};
CBinaryReader reader(&file_stream);
std::vector<LodEntry> files = read_lod_archive_header(reader);
for (auto iter = files.begin(); iter != files.end(); ++iter)
{
lod_entries[iter->name] = std::tie(argv[i], *iter);
}
}
Homm3MapSingleton::getInstance()->lod_entries = std::move(lod_entries);
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QGuiApplication app(argc, argv);
qmlRegisterType<Homm3Map>("homm3mapprivate", 1, 0, "Homm3Map");
QQmlApplicationEngine engine;
engine.addImageProvider(QStringLiteral("homm3"), new Homm3ImageProvider);
engine.rootContext()->setContextProperty(QStringLiteral("map_name"), QString::fromLocal8Bit(argv[1]));
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) {
if ((!obj) && (url == objUrl)) {
QCoreApplication::exit(-1);
}
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}
catch (const std::exception &e)
{
printf("Caught exception: %s\n", e.what());
}
return -1;
}