diff --git a/src/corednshome_zh-CN.ts b/src/corednshome_zh-CN.ts index 69a221c..7176d24 100644 --- a/src/corednshome_zh-CN.ts +++ b/src/corednshome_zh-CN.ts @@ -569,58 +569,69 @@ 停止CoreDNS - + Export Corefile 导出Corefile - + Corefile exported Corefile已导出 - + Configurations have been exported to %1. 配置被导出到%1。 - + Exporting failed 导出失败 - + Exporting configurations to %1 failed. 导出配置到%1失败。 - + About CoreDNS Home About CoreDNS GUI 关于CoreDNS家用特供 - + GUI configuration tool for <a href="https://github.com/missdeer/coredns_custom_build">custom build CoreDNS</a>.<br>Homepage: <a href="https://github.com/missdeer/corednshome">https://github.com/missdeer/corednshome</a> 用于<a href="https://github.com/missdeer/coredns_custom_build">自行编译的CoreDNS</a>的图形用户界面的配置工具。<br>主页:<a href="https://github.com/missdeer/corednshome">https://github.com/missdeer/corednshome</a> - - - + + + + Error 错误 - + Invalid CoreDNS binary URL %1 无效的CoreDNS二进制文件URL %1 - + Saving package to %1 failed. 保存包到%1失败。 + + + Saving CoreDNS binary to %1 failed. + 保存CoreDNS二进制文件到%1失败。 + + + + Updating CoreDNS binary failed. + 更新CoreDNS二进制文件失败。 + Opening package %1 failed. 打开包%1失败。 @@ -630,17 +641,16 @@ 保存%\coredns.exe.manifest失败。 - Saving coredns binary to %1 failed. - 保存CoreDNS二进制文件到%1失败。 + 保存CoreDNS二进制文件到%1失败。 - + Notice 提醒 - + Updating CoreDNS binary finished. 更新CoreDNS二进制文件结束。 @@ -652,28 +662,28 @@ QObject - - + + Critial error 紧急错误 - + Could not get program path to elevate privileges. 找不到适用于该权限的程序路径。 - + Failed to create authorization reference. 创建权限认证引用失败。 - + Critical error 紧急错误 - + SSL not supported, exit now. 不支持SSL,立即退出。 diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1c544a6..c96d329 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -15,6 +15,7 @@ #include "donatedialog.h" #include "networkreplyhelper.h" +#include "scopedguard.h" #include "settings.h" #include "ui_mainwindow.h" @@ -663,6 +664,7 @@ void MainWindow::on_cbResolveGoogleDomainByChinaDNS_stateChanged(int state) void MainWindow::on_actionUpdateCoreDNSBinary_triggered() { + ui->actionUpdateCoreDNSBinary->setEnabled(false); #if defined(Q_OS_WIN) # if defined(_WIN64) QUrl u("https://cdn.jsdelivr.net/gh/missdeer/corednshome@master/info/win64.txt"); @@ -700,6 +702,7 @@ void MainWindow::onInfoRequestFinished() if (!u.isValid()) { QMessageBox::warning(this, tr("Error"), tr("Invalid CoreDNS binary URL %1").arg(u.toString()), QMessageBox::Ok); + ui->actionUpdateCoreDNSBinary->setEnabled(true); return; } @@ -720,6 +723,7 @@ void MainWindow::onInfoRequestFinished() if (!f->open(QIODevice::WriteOnly | QIODevice::Truncate)) { QMessageBox::warning(this, tr("Error"), tr("Saving package to %1 failed.").arg(QDir::toNativeSeparators(pkgPath)), QMessageBox::Ok); + ui->actionUpdateCoreDNSBinary->setEnabled(true); return; } @@ -739,13 +743,15 @@ void MainWindow::onArtifactRequestFinished() f->close(); f->deleteLater(); + ScopedGuard sg([this] { ui->actionUpdateCoreDNSBinary->setEnabled(true); }); + auto pkgPath = f->fileName(); QZipReader pkgReader(pkgPath); auto path = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation); auto fileNameList = pkgReader.fileInfoList(); + bool gotBinary = false; for (auto &fi : fileNameList) { - qDebug() << fi.filePath; #if defined(Q_OS_WIN) if (fi.filePath.endsWith("coredns.exe")) { @@ -758,18 +764,22 @@ void MainWindow::onArtifactRequestFinished() if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) { QMessageBox::warning( - this, tr("Error"), tr("Saving coredns binary to %1 failed.").arg(QDir::toNativeSeparators(path)), QMessageBox::Ok); + this, tr("Error"), tr("Saving CoreDNS binary to %1 failed.").arg(QDir::toNativeSeparators(path)), QMessageBox::Ok); continue; } QByteArray ba = pkgReader.fileData(fi.filePath); - qDebug() << ba.length(); f.write(ba); f.close(); + gotBinary = true; } } if (pkgReader.isReadable()) pkgReader.close(); + QFile::remove(pkgPath); - QMessageBox::information(this, tr("Notice"), tr("Updating CoreDNS binary finished."), QMessageBox::Ok); + if (gotBinary) + QMessageBox::information(this, tr("Notice"), tr("Updating CoreDNS binary finished."), QMessageBox::Ok); + else + QMessageBox::warning(this, tr("Error"), tr("Updating CoreDNS binary failed."), QMessageBox::Ok); }