104 lines
3.8 KiB
C++
104 lines
3.8 KiB
C++
#include "mainwindow.h"
|
|
|
|
#include <QApplication>
|
|
#include <QCommandLineOption>
|
|
#include <QCommandLineParser>
|
|
#include <QDir>
|
|
#include <QFileInfo>
|
|
#include <QIcon>
|
|
#include <QMessageBox>
|
|
#include <QObject>
|
|
|
|
#include "AuthView.h"
|
|
#include "SingleInstanceManager.h"
|
|
#include "Version.h"
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
QApplication app(argc, argv);
|
|
app.setApplicationName(QStringLiteral("ParkingSpaceGuideApp"));
|
|
app.setApplicationVersion(QString::fromLatin1(GetParkingSpaceGuideVersion()));
|
|
app.setWindowIcon(QIcon(":/common/resource/logo.png"));
|
|
|
|
QCommandLineParser parser;
|
|
parser.setApplicationDescription(QObject::tr("停机引导程序"));
|
|
parser.addHelpOption();
|
|
parser.addVersionOption();
|
|
|
|
const QCommandLineOption simulateDirectoryOption(
|
|
QStringList{QStringLiteral("s"),
|
|
QStringLiteral("simulate-dir"),
|
|
QStringLiteral("sim-dir")},
|
|
QObject::tr("从目录中的多帧 TXT 和 BMP 数据运行仿真。"),
|
|
QObject::tr("目录"));
|
|
const QCommandLineOption simulationIntervalOption(
|
|
QStringList{QStringLiteral("sim-interval"),
|
|
QStringLiteral("sim-interval-ms")},
|
|
QObject::tr("仿真检测周期(毫秒),默认 100。"),
|
|
QObject::tr("毫秒"),
|
|
QStringLiteral("100"));
|
|
const QCommandLineOption simulationLoopOption(
|
|
QStringList{QStringLiteral("sim-loop")},
|
|
QObject::tr("循环回放整个多帧仿真目录。"));
|
|
parser.addOption(simulateDirectoryOption);
|
|
parser.addOption(simulationIntervalOption);
|
|
parser.addOption(simulationLoopOption);
|
|
parser.process(app);
|
|
|
|
ParkingSpaceGuideSimulationOptions simulationOptions;
|
|
simulationOptions.enabled = parser.isSet(simulateDirectoryOption);
|
|
simulationOptions.loop = parser.isSet(simulationLoopOption);
|
|
if (simulationOptions.enabled) {
|
|
const QFileInfo directoryInfo(parser.value(simulateDirectoryOption));
|
|
if (!directoryInfo.exists() || !directoryInfo.isDir()) {
|
|
QMessageBox::critical(
|
|
nullptr,
|
|
QObject::tr("仿真参数错误"),
|
|
QObject::tr("仿真数据目录不存在或不是目录:\n%1")
|
|
.arg(directoryInfo.absoluteFilePath()));
|
|
return 2;
|
|
}
|
|
|
|
bool intervalValid = false;
|
|
const int intervalMs = parser.value(simulationIntervalOption)
|
|
.toInt(&intervalValid);
|
|
if (!intervalValid || intervalMs < 1 || intervalMs > 60000) {
|
|
QMessageBox::critical(
|
|
nullptr,
|
|
QObject::tr("仿真参数错误"),
|
|
QObject::tr("--sim-interval 必须是 1 到 60000 之间的毫秒数。"));
|
|
return 2;
|
|
}
|
|
|
|
simulationOptions.dataDirectory = QDir::cleanPath(
|
|
directoryInfo.absoluteFilePath());
|
|
simulationOptions.frameIntervalMs = intervalMs;
|
|
} else if (parser.isSet(simulationIntervalOption) ||
|
|
parser.isSet(simulationLoopOption)) {
|
|
QMessageBox::critical(
|
|
nullptr,
|
|
QObject::tr("仿真参数错误"),
|
|
QObject::tr("--sim-interval 和 --sim-loop 必须与 --simulate-dir 一起使用。"));
|
|
return 2;
|
|
}
|
|
|
|
SingleInstanceManager instanceManager("ParkingSpaceGuideApp_SingleInstance_Key");
|
|
if (instanceManager.isAnotherInstanceRunning()) {
|
|
QMessageBox messageBox;
|
|
messageBox.setWindowTitle(QObject::tr("应用已运行"));
|
|
messageBox.setText(QObject::tr("停机引导程序已在运行。"));
|
|
messageBox.addButton(QObject::tr("确定"), QMessageBox::AcceptRole);
|
|
messageBox.exec();
|
|
return 0;
|
|
}
|
|
|
|
if (!AuthView::CheckAndShow(nullptr)) {
|
|
return 0;
|
|
}
|
|
|
|
MainWindow window(simulationOptions);
|
|
window.show();
|
|
|
|
return app.exec();
|
|
}
|