2023-04-09 05:35:35 +00:00
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
2023-03-20 06:53:56 +00:00
|
|
|
|
#include "client.h"
|
2023-04-19 03:06:19 +00:00
|
|
|
|
#include "util.h"
|
|
|
|
|
using namespace fkShell;
|
|
|
|
|
|
2023-02-15 11:54:35 +00:00
|
|
|
|
#include "packman.h"
|
2023-04-30 10:54:23 +00:00
|
|
|
|
#ifndef Q_OS_WASM
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#include "server.h"
|
2023-04-30 10:54:23 +00:00
|
|
|
|
#else
|
|
|
|
|
#include <emscripten.h>
|
2023-01-03 15:37:14 +00:00
|
|
|
|
#endif
|
2022-01-24 02:23:08 +00:00
|
|
|
|
|
2022-12-18 04:52:52 +00:00
|
|
|
|
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
|
|
|
|
|
#include "shell.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-12-18 07:08:01 +00:00
|
|
|
|
#if defined(Q_OS_WIN32)
|
|
|
|
|
#include "applink.c"
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-03-08 04:14:02 +00:00
|
|
|
|
#ifndef FK_SERVER_ONLY
|
2023-01-03 15:37:14 +00:00
|
|
|
|
#include <QFileDialog>
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#include <QScreen>
|
|
|
|
|
#include <QSplashScreen>
|
|
|
|
|
#ifndef Q_OS_ANDROID
|
|
|
|
|
#include <QQuickStyle>
|
|
|
|
|
#endif
|
2023-03-08 04:14:02 +00:00
|
|
|
|
#include "qmlbackend.h"
|
2023-01-29 10:11:41 +00:00
|
|
|
|
#endif
|
2022-12-18 04:52:52 +00:00
|
|
|
|
|
2023-01-03 15:37:14 +00:00
|
|
|
|
#if defined(Q_OS_ANDROID) || defined(Q_OS_WASM)
|
2023-04-12 12:51:09 +00:00
|
|
|
|
static bool copyPath(const QString &srcFilePath, const QString &tgtFilePath) {
|
2022-09-14 05:01:10 +00:00
|
|
|
|
QFileInfo srcFileInfo(srcFilePath);
|
|
|
|
|
if (srcFileInfo.isDir()) {
|
|
|
|
|
QDir targetDir(tgtFilePath);
|
|
|
|
|
if (!targetDir.exists()) {
|
|
|
|
|
targetDir.cdUp();
|
|
|
|
|
if (!targetDir.mkdir(QFileInfo(tgtFilePath).fileName()))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
QDir sourceDir(srcFilePath);
|
2023-04-12 12:51:09 +00:00
|
|
|
|
QStringList fileNames =
|
|
|
|
|
sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot |
|
|
|
|
|
QDir::Hidden | QDir::System);
|
2022-09-14 05:01:10 +00:00
|
|
|
|
foreach (const QString &fileName, fileNames) {
|
2023-04-12 12:51:09 +00:00
|
|
|
|
const QString newSrcFilePath = srcFilePath + QLatin1Char('/') + fileName;
|
|
|
|
|
const QString newTgtFilePath = tgtFilePath + QLatin1Char('/') + fileName;
|
2022-09-14 05:01:10 +00:00
|
|
|
|
if (!copyPath(newSrcFilePath, newTgtFilePath))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
QFile::remove(tgtFilePath);
|
|
|
|
|
if (!QFile::copy(srcFilePath, tgtFilePath))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-03-08 04:14:02 +00:00
|
|
|
|
static void installFkAssets(const QString &src, const QString &dest) {
|
2023-03-09 05:32:09 +00:00
|
|
|
|
QFile f(dest + "/fk_ver");
|
2023-03-08 04:14:02 +00:00
|
|
|
|
if (f.exists() && f.open(QIODevice::ReadOnly)) {
|
2023-03-09 05:32:09 +00:00
|
|
|
|
auto ver = f.readLine().simplified();
|
2023-03-08 04:14:02 +00:00
|
|
|
|
if (ver == FK_VERSION) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#ifdef Q_OS_ANDROID
|
|
|
|
|
copyPath(src, dest);
|
|
|
|
|
#elif defined(Q_OS_LINUX)
|
2023-05-20 08:11:16 +00:00
|
|
|
|
system(QString("cp -r %1 %2/..").arg(src).arg(dest).toUtf8());
|
2023-03-08 04:14:02 +00:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-15 19:54:53 +00:00
|
|
|
|
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
static void prepareForLinux() {
|
2023-04-12 12:51:09 +00:00
|
|
|
|
// 如果用户执行的是 /usr/bin/FreeKill,那么这意味着 freekill 是被包管理器安装
|
|
|
|
|
// 的,所以我们就需要把资源文件都复制到 ~/.local 中,并且切换当前目录
|
|
|
|
|
// TODO: AppImage
|
2023-02-15 19:54:53 +00:00
|
|
|
|
char buf[256] = {0};
|
|
|
|
|
int len = readlink("/proc/self/exe", buf, 256);
|
2023-04-30 10:54:23 +00:00
|
|
|
|
const char *home = getenv("HOME");
|
2023-02-15 19:54:53 +00:00
|
|
|
|
if (!strcmp(buf, "/usr/bin/FreeKill")) {
|
|
|
|
|
system("mkdir -p ~/.local/share/FreeKill");
|
2023-05-19 08:23:24 +00:00
|
|
|
|
installFkAssets("/usr/share/FreeKill", QString("%1/.local/share/FreeKill").arg(home));
|
2023-04-30 10:54:23 +00:00
|
|
|
|
chdir(home);
|
2023-02-15 19:54:53 +00:00
|
|
|
|
chdir(".local/share/FreeKill");
|
|
|
|
|
} else if (!strcmp(buf, "/usr/local/bin/FreeKill")) {
|
|
|
|
|
system("mkdir -p ~/.local/share/FreeKill");
|
2023-05-19 08:23:24 +00:00
|
|
|
|
installFkAssets("/usr/local/share/FreeKill", QString("%1/.local/share/FreeKill").arg(home));
|
2023-04-30 10:54:23 +00:00
|
|
|
|
chdir(home);
|
2023-02-15 19:54:53 +00:00
|
|
|
|
chdir(".local/share/FreeKill");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-06-04 11:31:44 +00:00
|
|
|
|
static FILE *info_log = nullptr;
|
|
|
|
|
static FILE *err_log = nullptr;
|
|
|
|
|
|
2023-04-12 12:51:09 +00:00
|
|
|
|
void fkMsgHandler(QtMsgType type, const QMessageLogContext &context,
|
|
|
|
|
const QString &msg) {
|
2023-04-19 03:06:19 +00:00
|
|
|
|
auto date = QDate::currentDate();
|
2023-06-04 11:31:44 +00:00
|
|
|
|
|
|
|
|
|
FILE *file;
|
|
|
|
|
switch (type) {
|
|
|
|
|
case QtDebugMsg:
|
|
|
|
|
case QtInfoMsg:
|
|
|
|
|
file = info_log;
|
|
|
|
|
break;
|
|
|
|
|
case QtWarningMsg:
|
|
|
|
|
case QtCriticalMsg:
|
|
|
|
|
case QtFatalMsg:
|
|
|
|
|
file = err_log;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-19 03:06:19 +00:00
|
|
|
|
fprintf(stderr, "\r%02d/%02d ", date.month(), date.day());
|
|
|
|
|
fprintf(stderr, "%s ",
|
2023-04-12 12:51:09 +00:00
|
|
|
|
QTime::currentTime().toString("hh:mm:ss").toLatin1().constData());
|
2023-06-04 11:31:44 +00:00
|
|
|
|
fprintf(file, "\r%02d/%02d ", date.month(), date.day());
|
|
|
|
|
fprintf(file, "%s ",
|
|
|
|
|
QTime::currentTime().toString("hh:mm:ss").toLatin1().constData());
|
2023-04-19 03:06:19 +00:00
|
|
|
|
|
2022-12-18 13:19:35 +00:00
|
|
|
|
auto localMsg = msg.toUtf8();
|
2023-01-29 10:11:41 +00:00
|
|
|
|
auto threadName = QThread::currentThread()->objectName().toLatin1();
|
2023-04-19 03:06:19 +00:00
|
|
|
|
|
2022-12-18 04:52:52 +00:00
|
|
|
|
switch (type) {
|
|
|
|
|
case QtDebugMsg:
|
2023-04-19 16:19:48 +00:00
|
|
|
|
fprintf(stderr, "%s[D] %s\n", threadName.constData(),
|
2023-04-12 12:51:09 +00:00
|
|
|
|
localMsg.constData());
|
2023-06-04 11:31:44 +00:00
|
|
|
|
fprintf(file, "%s[D] %s\n", threadName.constData(),
|
|
|
|
|
localMsg.constData());
|
2022-12-18 04:52:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case QtInfoMsg:
|
2023-04-19 16:19:48 +00:00
|
|
|
|
fprintf(stderr, "%s[%s] %s\n", threadName.constData(),
|
2023-04-19 03:06:19 +00:00
|
|
|
|
Color("I", Green).toUtf8().constData(), localMsg.constData());
|
2023-06-04 11:31:44 +00:00
|
|
|
|
fprintf(file, "%s[%s] %s\n", threadName.constData(),
|
|
|
|
|
"I", localMsg.constData());
|
2022-12-18 04:52:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case QtWarningMsg:
|
2023-04-19 16:19:48 +00:00
|
|
|
|
fprintf(stderr, "%s[%s] %s\n", threadName.constData(),
|
2023-04-19 03:06:19 +00:00
|
|
|
|
Color("W", Yellow, Bold).toUtf8().constData(),
|
2023-04-12 12:51:09 +00:00
|
|
|
|
localMsg.constData());
|
2023-06-04 11:31:44 +00:00
|
|
|
|
fprintf(file, "%s[%s] %s\n", threadName.constData(),
|
|
|
|
|
"W", localMsg.constData());
|
2022-12-18 04:52:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case QtCriticalMsg:
|
2023-04-19 16:19:48 +00:00
|
|
|
|
fprintf(stderr, "%s[%s] %s\n", threadName.constData(),
|
2023-04-19 03:06:19 +00:00
|
|
|
|
Color("C", Red, Bold).toUtf8().constData(), localMsg.constData());
|
2023-06-04 11:31:44 +00:00
|
|
|
|
fprintf(file, "%s[%s] %s\n", threadName.constData(),
|
|
|
|
|
"C", localMsg.constData());
|
2023-03-08 04:14:02 +00:00
|
|
|
|
#ifndef FK_SERVER_ONLY
|
2023-02-15 11:54:35 +00:00
|
|
|
|
if (Backend != nullptr) {
|
2023-04-12 12:51:09 +00:00
|
|
|
|
Backend->notifyUI(
|
|
|
|
|
"ErrorDialog",
|
|
|
|
|
QString("⛔ %1/Error occured!\n %2").arg(threadName).arg(localMsg));
|
2023-02-15 11:54:35 +00:00
|
|
|
|
}
|
2023-03-08 04:14:02 +00:00
|
|
|
|
#endif
|
2022-12-18 04:52:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case QtFatalMsg:
|
2023-04-19 16:19:48 +00:00
|
|
|
|
fprintf(stderr, "%s[%s] %s\n", threadName.constData(),
|
2023-04-19 03:06:19 +00:00
|
|
|
|
Color("E", Red, Bold).toUtf8().constData(), localMsg.constData());
|
2023-06-04 11:31:44 +00:00
|
|
|
|
fprintf(file, "%s[%s] %s\n", threadName.constData(),
|
|
|
|
|
"E", localMsg.constData());
|
2022-12-18 04:52:52 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-12 12:51:09 +00:00
|
|
|
|
// FreeKill 的程序主入口。整个程序就是从这里开始执行的。
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
|
// 初始化一下各种杂项信息
|
2022-12-18 04:52:52 +00:00
|
|
|
|
QThread::currentThread()->setObjectName("Main");
|
2023-06-04 11:31:44 +00:00
|
|
|
|
if (!info_log) {
|
|
|
|
|
info_log = fopen("freekill.server.info.log", "a+");
|
|
|
|
|
if (!info_log) {
|
|
|
|
|
qFatal("Cannot open info.log");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!err_log) {
|
|
|
|
|
err_log = fopen("freekill.server.error.log", "a+");
|
|
|
|
|
if (!err_log) {
|
|
|
|
|
qFatal("Cannot open error.log");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-18 04:52:52 +00:00
|
|
|
|
qInstallMessageHandler(fkMsgHandler);
|
2022-04-30 07:27:56 +00:00
|
|
|
|
QCoreApplication *app;
|
|
|
|
|
QCoreApplication::setApplicationName("FreeKill");
|
2023-03-08 04:14:02 +00:00
|
|
|
|
QCoreApplication::setApplicationVersion(FK_VERSION);
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
2023-02-15 19:54:53 +00:00
|
|
|
|
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
|
|
|
|
|
prepareForLinux();
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-03-08 04:14:02 +00:00
|
|
|
|
#ifndef FK_CLIENT_ONLY
|
2023-04-12 12:51:09 +00:00
|
|
|
|
// 分析命令行,如果有 -s 或者 --server 就在命令行直接开服务器
|
2022-04-30 07:27:56 +00:00
|
|
|
|
QCommandLineParser parser;
|
|
|
|
|
parser.setApplicationDescription("FreeKill server");
|
|
|
|
|
parser.addVersionOption();
|
|
|
|
|
parser.addOption({{"s", "server"}, "start server at <port>", "port"});
|
2023-06-17 12:18:40 +00:00
|
|
|
|
parser.addOption({{"h", "help"}, "display help information"});
|
2022-04-30 07:27:56 +00:00
|
|
|
|
QStringList cliOptions;
|
|
|
|
|
for (int i = 0; i < argc; i++)
|
|
|
|
|
cliOptions << argv[i];
|
|
|
|
|
|
|
|
|
|
parser.parse(cliOptions);
|
2023-06-17 12:18:40 +00:00
|
|
|
|
if (parser.isSet("version")) {
|
|
|
|
|
parser.showVersion();
|
|
|
|
|
return 0;
|
|
|
|
|
} else if (parser.isSet("help")) {
|
|
|
|
|
parser.showHelp();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
|
|
|
|
bool startServer = parser.isSet("server");
|
|
|
|
|
ushort serverPort = 9527;
|
|
|
|
|
|
|
|
|
|
if (startServer) {
|
|
|
|
|
app = new QCoreApplication(argc, argv);
|
2023-04-30 10:54:23 +00:00
|
|
|
|
QTranslator translator;
|
|
|
|
|
Q_UNUSED(translator.load("zh_CN.qm"));
|
|
|
|
|
QCoreApplication::installTranslator(&translator);
|
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
|
bool ok = false;
|
|
|
|
|
if (parser.value("server").toInt(&ok) && ok)
|
|
|
|
|
serverPort = parser.value("server").toInt();
|
|
|
|
|
Server *server = new Server;
|
|
|
|
|
if (!server->listen(QHostAddress::Any, serverPort)) {
|
2022-12-18 04:52:52 +00:00
|
|
|
|
qFatal("cannot listen on port %d!\n", serverPort);
|
2022-04-30 07:27:56 +00:00
|
|
|
|
app->exit(1);
|
2022-12-18 04:52:52 +00:00
|
|
|
|
} else {
|
|
|
|
|
qInfo("Server is listening on port %d", serverPort);
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
|
|
|
|
|
// Linux 服务器的话可以启用一个 Shell 来操作服务器。
|
2022-12-18 04:52:52 +00:00
|
|
|
|
auto shell = new Shell;
|
2023-02-15 11:54:35 +00:00
|
|
|
|
Pacman = new PackMan;
|
2022-12-18 04:52:52 +00:00
|
|
|
|
shell->start();
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#endif
|
2022-01-24 02:23:08 +00:00
|
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
|
return app->exec();
|
|
|
|
|
}
|
2023-03-08 04:14:02 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef FK_SERVER_ONLY
|
2023-04-12 12:51:09 +00:00
|
|
|
|
// 根本没编译 GUI 相关的功能,直接在此退出
|
2023-03-08 04:14:02 +00:00
|
|
|
|
qFatal("This is server-only build and have no GUI support.\n\
|
|
|
|
|
Please use ./FreeKill -s to start a server in command line.");
|
2023-01-03 15:37:14 +00:00
|
|
|
|
#else
|
2023-03-08 04:14:02 +00:00
|
|
|
|
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#ifdef Q_OS_WASM
|
2023-04-30 10:54:23 +00:00
|
|
|
|
EM_ASM (
|
|
|
|
|
FS.mkdir('/assets');
|
|
|
|
|
FS.mount(IDBFS, {}, '/assets');
|
|
|
|
|
FS.chdir('/assets');
|
|
|
|
|
FS.syncfs(true, function(err) {
|
|
|
|
|
});
|
|
|
|
|
);
|
2023-01-03 15:37:14 +00:00
|
|
|
|
copyPath(":/", QDir::currentPath());
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#endif
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
2022-12-18 04:52:52 +00:00
|
|
|
|
app = new QApplication(argc, argv);
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#ifdef DESKTOP_BUILD
|
2023-01-12 14:53:22 +00:00
|
|
|
|
((QApplication *)app)->setWindowIcon(QIcon("image/icon.png"));
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#endif
|
2022-12-18 04:52:52 +00:00
|
|
|
|
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#define SHOW_SPLASH_MSG(msg) \
|
2022-12-18 04:52:52 +00:00
|
|
|
|
splash.showMessage(msg, Qt::AlignHCenter | Qt::AlignBottom);
|
|
|
|
|
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#ifdef Q_OS_ANDROID
|
|
|
|
|
// 安卓:先切换到我们安装程序的那个外部存储目录去
|
|
|
|
|
QJniObject::callStaticMethod<void>("org/notify/FreeKill/Helper", "InitView",
|
|
|
|
|
"()V");
|
|
|
|
|
QDir::setCurrent(
|
|
|
|
|
"/storage/emulated/0/Android/data/org.notify.FreeKill/files");
|
2023-03-04 22:39:03 +00:00
|
|
|
|
|
2023-04-12 12:51:09 +00:00
|
|
|
|
// 然后显示欢迎界面,并在需要时复制资源素材等
|
2022-12-18 04:52:52 +00:00
|
|
|
|
QScreen *screen = qobject_cast<QApplication *>(app)->primaryScreen();
|
|
|
|
|
QRect screenGeometry = screen->geometry();
|
|
|
|
|
int screenWidth = screenGeometry.width();
|
|
|
|
|
int screenHeight = screenGeometry.height();
|
2023-04-12 12:51:09 +00:00
|
|
|
|
QSplashScreen splash(QPixmap("assets:/res/image/splash.jpg")
|
|
|
|
|
.scaled(screenWidth, screenHeight));
|
2022-12-18 04:52:52 +00:00
|
|
|
|
splash.showFullScreen();
|
|
|
|
|
SHOW_SPLASH_MSG("Copying resources...");
|
2023-03-08 04:14:02 +00:00
|
|
|
|
installFkAssets("assets:/res", QDir::currentPath());
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#else
|
|
|
|
|
// 不是安卓,那么直接启动欢迎界面,也就是不复制东西了
|
2022-12-18 04:52:52 +00:00
|
|
|
|
QSplashScreen splash(QPixmap("image/splash.jpg"));
|
|
|
|
|
splash.show();
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#endif
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
2022-12-18 04:52:52 +00:00
|
|
|
|
SHOW_SPLASH_MSG("Loading qml files...");
|
2022-04-30 07:27:56 +00:00
|
|
|
|
QQmlApplicationEngine *engine = new QQmlApplicationEngine;
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#ifndef Q_OS_ANDROID
|
2023-01-16 13:57:05 +00:00
|
|
|
|
QQuickStyle::setStyle("Material");
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#endif
|
2023-02-15 11:54:35 +00:00
|
|
|
|
|
|
|
|
|
QTranslator translator;
|
|
|
|
|
Q_UNUSED(translator.load("zh_CN.qm"));
|
|
|
|
|
QCoreApplication::installTranslator(&translator);
|
2023-02-26 08:51:29 +00:00
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
|
QmlBackend backend;
|
|
|
|
|
backend.setEngine(engine);
|
2023-02-15 11:54:35 +00:00
|
|
|
|
|
|
|
|
|
Pacman = new PackMan;
|
2023-02-26 08:51:29 +00:00
|
|
|
|
|
2023-04-12 12:51:09 +00:00
|
|
|
|
// 向 Qml 中先定义几个全局变量
|
2023-03-20 06:53:56 +00:00
|
|
|
|
engine->rootContext()->setContextProperty("FkVersion", FK_VERSION);
|
2022-04-30 07:27:56 +00:00
|
|
|
|
engine->rootContext()->setContextProperty("Backend", &backend);
|
2023-05-26 12:53:26 +00:00
|
|
|
|
engine->rootContext()->setContextProperty("ModBackend", nullptr);
|
2023-02-15 11:54:35 +00:00
|
|
|
|
engine->rootContext()->setContextProperty("Pacman", Pacman);
|
2023-01-03 15:37:14 +00:00
|
|
|
|
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#ifdef QT_DEBUG
|
2022-04-30 07:27:56 +00:00
|
|
|
|
bool debugging = true;
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#else
|
2022-04-30 07:27:56 +00:00
|
|
|
|
bool debugging = false;
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#endif
|
2022-04-30 07:27:56 +00:00
|
|
|
|
engine->rootContext()->setContextProperty("Debugging", debugging);
|
2023-01-03 15:37:14 +00:00
|
|
|
|
|
|
|
|
|
QString system;
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#if defined(Q_OS_ANDROID)
|
2023-01-03 15:37:14 +00:00
|
|
|
|
system = "Android";
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#elif defined(Q_OS_WASM)
|
2023-01-03 15:37:14 +00:00
|
|
|
|
system = "Web";
|
2023-02-26 07:01:14 +00:00
|
|
|
|
engine->rootContext()->setContextProperty("ServerAddr", "127.0.0.1:9527");
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#elif defined(Q_OS_WIN32)
|
2023-01-03 15:37:14 +00:00
|
|
|
|
system = "Win";
|
2023-02-15 11:54:35 +00:00
|
|
|
|
::system("chcp 65001");
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#elif defined(Q_OS_LINUX)
|
2023-01-03 15:37:14 +00:00
|
|
|
|
system = "Linux";
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#else
|
2023-01-03 15:37:14 +00:00
|
|
|
|
system = "Other";
|
2023-04-12 12:51:09 +00:00
|
|
|
|
#endif
|
2023-01-03 15:37:14 +00:00
|
|
|
|
engine->rootContext()->setContextProperty("OS", system);
|
|
|
|
|
|
2023-04-12 12:51:09 +00:00
|
|
|
|
engine->rootContext()->setContextProperty(
|
|
|
|
|
"AppPath", QUrl::fromLocalFile(QDir::currentPath()));
|
|
|
|
|
|
2023-05-19 02:08:36 +00:00
|
|
|
|
engine->addImportPath(QDir::currentPath());
|
|
|
|
|
|
2023-04-12 12:51:09 +00:00
|
|
|
|
// 加载完全局变量后,就再去加载 main.qml,此时UI界面正式显示
|
2023-05-19 02:08:36 +00:00
|
|
|
|
engine->load("Fk/main.qml");
|
2023-01-03 15:37:14 +00:00
|
|
|
|
|
2023-04-12 12:51:09 +00:00
|
|
|
|
// qml 报错了就直接退出吧
|
2022-04-30 07:27:56 +00:00
|
|
|
|
if (engine->rootObjects().isEmpty())
|
|
|
|
|
return -1;
|
2022-01-24 02:23:08 +00:00
|
|
|
|
|
2023-04-12 12:51:09 +00:00
|
|
|
|
// 关闭欢迎界面,然后进入Qt主循环
|
2022-12-18 04:52:52 +00:00
|
|
|
|
splash.close();
|
2022-04-30 07:27:56 +00:00
|
|
|
|
int ret = app->exec();
|
2022-03-27 12:00:29 +00:00
|
|
|
|
|
2023-04-12 12:51:09 +00:00
|
|
|
|
// 先删除 engine
|
|
|
|
|
// 防止报一堆错 "TypeError: Cannot read property 'xxx' of null"
|
2022-04-30 07:27:56 +00:00
|
|
|
|
delete engine;
|
2023-02-15 11:54:35 +00:00
|
|
|
|
delete Pacman;
|
2022-03-27 12:00:29 +00:00
|
|
|
|
|
2023-04-30 10:54:23 +00:00
|
|
|
|
#ifdef Q_OS_WASM
|
|
|
|
|
EM_ASM (
|
|
|
|
|
FS.syncfs(function(err) {});
|
|
|
|
|
);
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-06-04 11:31:44 +00:00
|
|
|
|
if (info_log) {
|
|
|
|
|
fclose(info_log);
|
|
|
|
|
info_log = nullptr;
|
|
|
|
|
}
|
|
|
|
|
if (err_log) {
|
|
|
|
|
fclose(err_log);
|
|
|
|
|
info_log = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
|
return ret;
|
2023-03-08 04:14:02 +00:00
|
|
|
|
#endif
|
2022-01-24 02:23:08 +00:00
|
|
|
|
}
|