GUI: only clean the cache once per version

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.
This commit is contained in:
Moritz Bunkus 2017-01-20 22:19:04 +01:00
parent 830c64ee3a
commit 5fe1b0be03
5 changed files with 33 additions and 2 deletions

View File

@ -28,7 +28,8 @@
## Bug fixes ## Bug fixes
* GUI: the cache cleanup process that's run automatically when the GUI starts * 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 * 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 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 cache anymore. Without this fix the GUI would still use the cached failed

View File

@ -74,7 +74,7 @@ MainWindow::MainWindow(QWidget *parent)
new TaskbarProgress{this}; new TaskbarProgress{this};
#endif #endif
QtConcurrent::run(Util::Cache::cleanOldCacheFiles); runCacheCleanupOncePerVersion();
Util::InstallationChecker::checkInstallation(); Util::InstallationChecker::checkInstallation();
} }
@ -608,4 +608,12 @@ MainWindow::displayInstallationProblems(Util::InstallationChecker::Problems cons
.exec(); .exec();
} }
void
MainWindow::runCacheCleanupOncePerVersion()
const {
Util::Settings::runOncePerVersion(Q("cacheCleanup"), []() {
QtConcurrent::run(Util::Cache::cleanOldCacheFiles);
});
}
}} }}

View File

@ -126,6 +126,7 @@ protected:
virtual boost::optional<bool> filterWheelEventForStrongFocus(QObject *watched, QEvent *event); virtual boost::optional<bool> filterWheelEventForStrongFocus(QObject *watched, QEvent *event);
virtual void silentlyCheckForUpdates(); virtual void silentlyCheckForUpdates();
virtual void runCacheCleanupOncePerVersion() const;
}; };
}} }}

View File

@ -619,4 +619,23 @@ Settings::lastOpenDirPath()
return Util::dirPath(m_lastOpenDir); return Util::dirPath(m_lastOpenDir);
} }
void
Settings::runOncePerVersion(QString const &topic,
std::function<void()> 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();
}
}}} }}}

View File

@ -188,6 +188,8 @@ public:
static void change(std::function<void(Settings &)> worker); static void change(std::function<void(Settings &)> worker);
static std::unique_ptr<QSettings> registry(); static std::unique_ptr<QSettings> registry();
static void runOncePerVersion(QString const &topic, std::function<void()> worker);
static QString exeWithPath(QString const &exe); static QString exeWithPath(QString const &exe);
static void migrateFromRegistry(); static void migrateFromRegistry();