-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
97 lines (87 loc) · 3.29 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
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickStyle>
#include <QLocale>
#include <QTranslator>
#include <QQmlContext>
#include <QDir>
#include <QCoreApplication>
#include <QQuickWindow>
#include "game_version_manager.h"
#include "user_manager.h"
#ifdef Q_OS_ANDROID
#include <QtAndroid>
bool checkPermission() {
QtAndroid::PermissionResult r = QtAndroid::checkPermission("android.permission.WRITE_EXTERNAL_STORAGE");
if(r == QtAndroid::PermissionResult::Denied) {
QtAndroid::requestPermissionsSync( QStringList() << "android.permission.WRITE_EXTERNAL_STORAGE" );
r = QtAndroid::checkPermission("android.permission.WRITE_EXTERNAL_STORAGE");
if(r == QtAndroid::PermissionResult::Denied) {
return false;
}
}
return true;
}
bool checkPermission2() {
QtAndroid::PermissionResult r = QtAndroid::checkPermission("android.permission.READ_EXTERNAL_STORAGE");
if(r == QtAndroid::PermissionResult::Denied) {
QtAndroid::requestPermissionsSync( QStringList() << "android.permission.READ_EXTERNAL_STORAGE" );
r = QtAndroid::checkPermission("android.permission.READ_EXTERNAL_STORAGE");
if(r == QtAndroid::PermissionResult::Denied) {
return false;
}
}
return true;
}
#endif
int main(int argc, char *argv[])
{
#ifdef Q_OS_ANDROID
checkPermission();
checkPermission2();
#endif
//qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard")); //Qt virtualkeyboard
QQuickStyle::setStyle("Material");
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::VulkanRhi);//MUCH FASTER!!!
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
//check&create game dir
QDir game_dir;
if(!game_dir.exists(".minecraft")) game_dir.mkpath(".minecraft");
//load user list
user_manager user_manager;
user_manager.read_file();
//load checker
checker checker;
//load game version list
game_version_manager game_version_manager;
//game_version_manager.start();
//get new game list
install_new_game install_new_game;
install_new_game.checker_p = &checker;
install_new_game.game_version_manager_p = &game_version_manager;
QGuiApplication app(argc, argv);
QTranslator translator;
const QStringList uiLanguages = QLocale::system().uiLanguages();
for (const QString &locale : uiLanguages) {
const QString baseName = "MCinaBox_Qt_" + QLocale(locale).name();
if (translator.load(":/i18n/" + baseName)) {
app.installTranslator(&translator);
break;
}
}
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("game_version_manager",&game_version_manager);
engine.rootContext()->setContextProperty("checker",&checker);
engine.rootContext()->setContextProperty("user_manager",&user_manager);
engine.rootContext()->setContextProperty("install_new_game",&install_new_game);
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();
}