Skip to content

Commit

Permalink
添加了配置文件版本校准功能
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost-him committed Sep 21, 2024
1 parent a7a9266 commit a36a795
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions controller/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ void Controller::init()

SettingWindowConfigure config = buildClassWithJson(configure);

// 验证当前的配置文件是否正确
if (config.configVersion != getConfigVersion()) {
QMessageBox::critical(nullptr, "错误", "当前配置文件的版本与程序所需版本不匹配。请打开程序目录,删除[Config.json]文件后重新运行本程序");
exit(1);
}

uiController.initUI(config);

ChineseConvertPinyin& pinyin = ChineseConvertPinyin::getInstance();
Expand Down
11 changes: 8 additions & 3 deletions controller/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ QPixmap getFileIcon(const QString& filePath) {

QJsonObject getDefaultConfigJson() {
QJsonObject jsonObject;

jsonObject["configVersion"] = getConfigVersion();
jsonObject["isAutoStart"] = false;
jsonObject["searchStartMenu"] = true;
jsonObject["searchRegistry"] = false;
Expand Down Expand Up @@ -89,7 +89,7 @@ void createFile(const QString &path, const QString &defaultContent) {

QJsonObject buildJsonWithClass(const SettingWindowConfigure& config) {
QJsonObject json;

json["configVersion"] = config.configVersion;
json["isAutoStart"] = config.isAutoStart;
json["searchStartMenu"] = config.isSearchStartMenu;
json["searchRegistry"] = config.isSearchRegistry;
Expand Down Expand Up @@ -131,7 +131,7 @@ QJsonObject buildJsonWithClass(const SettingWindowConfigure& config) {
SettingWindowConfigure buildClassWithJson(const QJsonObject &json)
{
SettingWindowConfigure ret;

ret.configVersion = json["configVersion"].toInt();
ret.isAutoStart = json["isAutoStart"].toBool();
ret.isSearchStartMenu = json["searchStartMenu"].toBool();
ret.isSearchRegistry = json["searchRegistry"].toBool();
Expand Down Expand Up @@ -165,6 +165,11 @@ SettingWindowConfigure buildClassWithJson(const QJsonObject &json)
return ret;
}

int getConfigVersion()
{
return 1;
}

QString getProgramVersion()
{
return "ZeroLaunch 0.8.1";
Expand Down
4 changes: 3 additions & 1 deletion controller/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct SettingWindowConfigure {
double stableBias;
QString note;
};

int configVersion; // 当前配置文件的版本
bool isSearchStartMenu;
bool isAutoStart;
bool isPreLoadResource;
Expand Down Expand Up @@ -57,6 +57,8 @@ SettingWindowConfigure buildClassWithJson(const QJsonObject& json);

QString getProgramVersion();

int getConfigVersion();

QString GetShellDirectory(int type);

QString getDefaultItemPlaceHolder();
Expand Down
1 change: 1 addition & 0 deletions ui/settingwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ void SettingWindow::on_btnConfirm_clicked()
{
SettingWindowConfigure configure;

configure.configVersion = getConfigVersion();
configure.isAutoStart = ui->boxAutoStart->isChecked();
configure.isSearchStartMenu = ui->boxSearchStartMenu->isChecked();
configure.isSearchRegistry = ui->boxSearchRegistry->isChecked();
Expand Down

0 comments on commit a36a795

Please sign in to comment.