diff --git a/Telegram/SourceFiles/boxes/local_storage_box.cpp b/Telegram/SourceFiles/boxes/local_storage_box.cpp index be110cc61a..cca8d2d777 100644 --- a/Telegram/SourceFiles/boxes/local_storage_box.cpp +++ b/Telegram/SourceFiles/boxes/local_storage_box.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/shadow.h" #include "ui/widgets/continuous_sliders.h" #include "ui/effects/radial_animation.h" +#include "ui/emoji_config.h" #include "storage/localstorage.h" #include "storage/cache/storage_cache_database.h" #include "data/data_session.h" @@ -316,6 +317,7 @@ void LocalStorageBox::clearByTag(uint8 tag) { _db->clearByTag(tag); } else { _db->clear(); + Ui::Emoji::ClearIrrelevantCache(); } } diff --git a/Telegram/SourceFiles/ui/emoji_config.cpp b/Telegram/SourceFiles/ui/emoji_config.cpp index 9791fcb3a4..5c84ceb9bf 100644 --- a/Telegram/SourceFiles/ui/emoji_config.cpp +++ b/Telegram/SourceFiles/ui/emoji_config.cpp @@ -65,11 +65,14 @@ QString CacheFileFolder() { return cWorkingDir() + "tdata/emoji"; } +QString CacheFileNameMask(int size) { + return "cache_" + QString::number(size) + '_'; +} + QString CacheFilePath(int size, int index) { return CacheFileFolder() - + "/cache_" - + QString::number(size) - + '_' + + '/' + + CacheFileNameMask(size) + QString::number(index); } @@ -323,6 +326,23 @@ void Clear() { InstanceLarge = nullptr; } +void ClearIrrelevantCache() { + Expects(SizeNormal > 0); + Expects(SizeLarge > 0); + + crl::async([] { + const auto folder = CacheFileFolder(); + const auto list = QDir(folder).entryList(QDir::Files); + const auto good1 = CacheFileNameMask(SizeNormal); + const auto good2 = CacheFileNameMask(SizeLarge); + for (const auto &name : list) { + if (!name.startsWith(good1) && !name.startsWith(good2)) { + QFile(folder + '/' + name).remove(); + } + } + }); +} + int GetSizeNormal() { Expects(SizeNormal > 0); diff --git a/Telegram/SourceFiles/ui/emoji_config.h b/Telegram/SourceFiles/ui/emoji_config.h index c277b8f2ad..361bdd99fb 100644 --- a/Telegram/SourceFiles/ui/emoji_config.h +++ b/Telegram/SourceFiles/ui/emoji_config.h @@ -18,6 +18,8 @@ constexpr auto kRecentLimit = 42; void Init(); void Clear(); +void ClearIrrelevantCache(); + int GetSizeNormal(); int GetSizeLarge();