From 5fe1b0be0306e72e56c567da230e282b5af5863c Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 20 Jan 2017 22:19:04 +0100 Subject: [PATCH] GUI: only clean the cache once per version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The process can take a lot of time, therefore only do it if there's a reasonable chance that files will have to be cleaned up — which is after a version change. Another piece of the fix for #1860. --- NEWS.md | 3 ++- .../main_window/main_window.cpp | 10 +++++++++- src/mkvtoolnix-gui/main_window/main_window.h | 1 + src/mkvtoolnix-gui/util/settings.cpp | 19 +++++++++++++++++++ src/mkvtoolnix-gui/util/settings.h | 2 ++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 276b818d4..84469959f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -28,7 +28,8 @@ ## Bug fixes * GUI: the cache cleanup process that's run automatically when the GUI starts - no longer blocks file identification until it is finished. Fixes #1860. + no longer blocks file identification until it is finished. Additionally the + process will only be run once per release of MKVToolNix. Fixes #1860. * GUI: certain failures during file identification that can be traced to broken installations (e.g. mkvmerge being too old) won't be stored in the cache anymore. Without this fix the GUI would still use the cached failed diff --git a/src/mkvtoolnix-gui/main_window/main_window.cpp b/src/mkvtoolnix-gui/main_window/main_window.cpp index d1db7c200..633b4c318 100644 --- a/src/mkvtoolnix-gui/main_window/main_window.cpp +++ b/src/mkvtoolnix-gui/main_window/main_window.cpp @@ -74,7 +74,7 @@ MainWindow::MainWindow(QWidget *parent) new TaskbarProgress{this}; #endif - QtConcurrent::run(Util::Cache::cleanOldCacheFiles); + runCacheCleanupOncePerVersion(); Util::InstallationChecker::checkInstallation(); } @@ -608,4 +608,12 @@ MainWindow::displayInstallationProblems(Util::InstallationChecker::Problems cons .exec(); } +void +MainWindow::runCacheCleanupOncePerVersion() + const { + Util::Settings::runOncePerVersion(Q("cacheCleanup"), []() { + QtConcurrent::run(Util::Cache::cleanOldCacheFiles); + }); +} + }} diff --git a/src/mkvtoolnix-gui/main_window/main_window.h b/src/mkvtoolnix-gui/main_window/main_window.h index 9600d3f86..9ab0007b8 100644 --- a/src/mkvtoolnix-gui/main_window/main_window.h +++ b/src/mkvtoolnix-gui/main_window/main_window.h @@ -126,6 +126,7 @@ protected: virtual boost::optional filterWheelEventForStrongFocus(QObject *watched, QEvent *event); virtual void silentlyCheckForUpdates(); + virtual void runCacheCleanupOncePerVersion() const; }; }} diff --git a/src/mkvtoolnix-gui/util/settings.cpp b/src/mkvtoolnix-gui/util/settings.cpp index 11ddbd7f2..11069279e 100644 --- a/src/mkvtoolnix-gui/util/settings.cpp +++ b/src/mkvtoolnix-gui/util/settings.cpp @@ -619,4 +619,23 @@ Settings::lastOpenDirPath() return Util::dirPath(m_lastOpenDir); } +void +Settings::runOncePerVersion(QString const &topic, + std::function worker) { + auto reg = registry(); + auto key = Q("runOncePerVersion/%1").arg(topic); + + auto lastRunInVersion = reg->value(key).toString(); + auto lastRunInVersionNumber = version_number_t{to_utf8(lastRunInVersion)}; + auto currentVersionNumber = get_current_version(); + + if ( lastRunInVersionNumber.valid + && !(lastRunInVersionNumber < currentVersionNumber)) + return; + + reg->setValue(key, Q(currentVersionNumber.to_string())); + + worker(); +} + }}} diff --git a/src/mkvtoolnix-gui/util/settings.h b/src/mkvtoolnix-gui/util/settings.h index 3e0901421..234edb2cc 100644 --- a/src/mkvtoolnix-gui/util/settings.h +++ b/src/mkvtoolnix-gui/util/settings.h @@ -188,6 +188,8 @@ public: static void change(std::function worker); static std::unique_ptr registry(); + static void runOncePerVersion(QString const &topic, std::function worker); + static QString exeWithPath(QString const &exe); static void migrateFromRegistry();