From 4bf955462f87e4ede6de48b549e5055d4e11b812 Mon Sep 17 00:00:00 2001 From: Petr Mironychev <9195189+Palm1r@users.noreply.github.com> Date: Mon, 27 Jan 2025 00:54:49 +0100 Subject: [PATCH] feat: Update dialog offer open plugin folder --- settings/PluginUpdater.cpp | 15 +++++++++++---- settings/UpdateDialog.cpp | 32 +++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/settings/PluginUpdater.cpp b/settings/PluginUpdater.cpp index 43ee1a4..0c437cb 100644 --- a/settings/PluginUpdater.cpp +++ b/settings/PluginUpdater.cpp @@ -159,11 +159,19 @@ void PluginUpdater::handleDownloadFinished() return; } - QString downloadPath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); + QString downloadPath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + + QDir::separator() + "QodeAssist_v" + m_lastUpdateInfo.version; + QDir().mkpath(downloadPath); + + QString filePath = downloadPath + QDir::separator() + m_lastUpdateInfo.fileName; + + if (QFile::exists(filePath)) { + emit downloadError(tr("Update file already exists: %1").arg(filePath)); + reply->deleteLater(); + return; + } - QString filePath = downloadPath + "/" + m_lastUpdateInfo.fileName; QFile file(filePath); - if (!file.open(QIODevice::WriteOnly)) { emit downloadError(tr("Could not save the update file")); reply->deleteLater(); @@ -174,7 +182,6 @@ void PluginUpdater::handleDownloadFinished() file.close(); emit downloadFinished(filePath); - reply->deleteLater(); } diff --git a/settings/UpdateDialog.cpp b/settings/UpdateDialog.cpp index 0e6df79..21000cd 100644 --- a/settings/UpdateDialog.cpp +++ b/settings/UpdateDialog.cpp @@ -19,6 +19,11 @@ #include "UpdateDialog.hpp" +#include +#include +#include +#include + namespace QodeAssist { UpdateDialog::UpdateDialog(QWidget *parent) @@ -166,7 +171,32 @@ void UpdateDialog::updateProgress(qint64 received, qint64 total) void UpdateDialog::handleDownloadFinished(const QString &path) { m_progress->setVisible(false); - QMessageBox::information(this, tr("Update Successful"), tr("Update has been downloaded.")); + + QMessageBox msgBox(this); + msgBox.setWindowTitle(tr("Update Downloaded")); + msgBox.setText(tr("The update has been downloaded successfully.\n" + "Would you like to close Qt Creator now and open the plugin folder?")); + msgBox.setInformativeText(tr("To complete the update:\n\n" + "1. Close Qt Creator completely\n" + "2. Navigate to the plugin folder\n" + "3. Remove the old version of QodeAssist plugin\n" + "4. Install plugin as usual via About plugin menu")); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::Yes); + msgBox.setIcon(QMessageBox::Information); + + if (msgBox.exec() == QMessageBox::Yes) { + const auto pluginSpecs = ExtensionSystem::PluginManager::plugins(); + for (const ExtensionSystem::PluginSpec *spec : pluginSpecs) { + if (spec->name() == QLatin1String("QodeAssist")) { + const auto pluginPath = spec->filePath().path(); + QFileInfo fileInfo(pluginPath); + QDesktopServices::openUrl(QUrl::fromLocalFile(fileInfo.absolutePath())); + Core::ICore::exit(); + break; + } + } + } accept(); }