From 4d65df6ca2cb98069915a62e87f14cf09741c620 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 23 Jun 2020 20:02:15 +0400 Subject: [PATCH] Remove legacy temp download folder. --- Telegram/SourceFiles/config.h | 5 - Telegram/SourceFiles/data/data_document.cpp | 2 +- Telegram/SourceFiles/main/main_account.cpp | 3 - Telegram/SourceFiles/mainwindow.cpp | 43 -------- Telegram/SourceFiles/mainwindow.h | 21 ---- .../media/view/media_view_overlay_widget.cpp | 3 +- Telegram/SourceFiles/storage/localstorage.cpp | 98 ------------------- Telegram/SourceFiles/storage/localstorage.h | 30 ------ .../SourceFiles/storage/storage_account.cpp | 13 ++- .../SourceFiles/storage/storage_account.h | 5 +- .../SourceFiles/window/window_controller.cpp | 4 - .../SourceFiles/window/window_controller.h | 2 - 12 files changed, 19 insertions(+), 210 deletions(-) diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index a9dfb398a..defe4723a 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -131,11 +131,6 @@ inline const QString &cDataFile() { return res; } -inline const QString &cTempDir() { - static const QString res = cWorkingDir() + qsl("tdata/tdld/"); - return res; -} - inline const QRegularExpression &cRussianLetters() { static QRegularExpression regexp(QString::fromUtf8("[а-яА-ЯёЁ]")); return regexp; diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index 0c7087576..8d198bd3a 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -180,7 +180,7 @@ QString FileNameUnsafe( if (path.isEmpty()) { return File::DefaultDownloadPath(session); } else if (path == qsl("tmp")) { - return cTempDir(); + return session->local().tempDirectory(); } else { return path; } diff --git a/Telegram/SourceFiles/main/main_account.cpp b/Telegram/SourceFiles/main/main_account.cpp index 31af4a8aa..c125f3e68 100644 --- a/Telegram/SourceFiles/main/main_account.cpp +++ b/Telegram/SourceFiles/main/main_account.cpp @@ -502,9 +502,6 @@ void Account::forcedLogOut() { void Account::loggedOut() { _loggingOut = false; Media::Player::mixer()->stopAndClear(); - if (const auto window = Core::App().activeWindow()) { - window->tempDirDelete(Local::ClearManagerAll); - } destroySession(); Core::App().unlockTerms(); local().reset(); diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index c36afaeb4..f0a5feec2 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -860,45 +860,6 @@ void MainWindow::updateControlsGeometry() { if (_main) _main->checkMainSectionToLayer(); } -MainWindow::TempDirState MainWindow::tempDirState() { - if (_clearManager && _clearManager->hasTask(Local::ClearManagerDownloads)) { - return TempDirRemoving; - } - return QDir(cTempDir()).exists() ? TempDirExists : TempDirEmpty; -} - -void MainWindow::tempDirDelete(int task) { - if (_clearManager) { - if (_clearManager->addTask(task)) { - return; - } else { - _clearManager->stop(); - _clearManager = nullptr; - } - } - _clearManager = new Local::ClearManager(); - _clearManager->addTask(task); - connect(_clearManager, SIGNAL(succeed(int,void*)), this, SLOT(onClearFinished(int,void*))); - connect(_clearManager, SIGNAL(failed(int,void*)), this, SLOT(onClearFailed(int,void*))); - _clearManager->start(); -} - -void MainWindow::onClearFinished(int task, void *manager) { - if (manager && manager == _clearManager) { - _clearManager->stop(); - _clearManager = nullptr; - } - emit tempDirCleared(task); -} - -void MainWindow::onClearFailed(int task, void *manager) { - if (manager && manager == _clearManager) { - _clearManager->stop(); - _clearManager = nullptr; - } - emit tempDirClearFailed(task); -} - void MainWindow::placeSmallCounter(QImage &img, int size, int count, style::color bg, const QPoint &shift, style::color color) { QPainter p(&img); @@ -1029,10 +990,6 @@ void MainWindow::updateIsActiveHook() { } MainWindow::~MainWindow() { - if (_clearManager) { - _clearManager->stop(); - _clearManager = nullptr; - } delete trayIcon; delete trayIconMenu; } diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index be8006a8c..33f0c69cc 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -20,10 +20,6 @@ class Widget; enum class EnterPoint : uchar; } // namespace Intro -namespace Local { -class ClearManager; -} // namespace Local - namespace Window { class MediaPreviewWidget; class SectionMemento; @@ -70,14 +66,6 @@ public: void fixOrder(); - enum TempDirState { - TempDirRemoving, - TempDirExists, - TempDirEmpty, - }; - TempDirState tempDirState(); - void tempDirDelete(int task); - void sendPaths(); QImage iconWithCounter(int size, int count, style::color bg, style::color fg, bool smallIcon) override; @@ -134,17 +122,10 @@ public slots: void showFromTray(QSystemTrayIcon::ActivationReason reason = QSystemTrayIcon::Unknown); void toggleDisplayNotifyFromTray(); - void onClearFinished(int task, void *manager); - void onClearFailed(int task, void *manager); - void onShowAddContact(); void onShowNewGroup(); void onShowNewChannel(); -signals: - void tempDirCleared(int task); - void tempDirClearFailed(int task); - private: [[nodiscard]] bool skipTrayClick() const; @@ -174,8 +155,6 @@ private: object_ptr _testingThemeWarning = { nullptr }; - Local::ClearManager *_clearManager = nullptr; - }; namespace App { diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 76cd24a4d..c9ff58589 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -54,6 +54,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session_settings.h" #include "layout.h" #include "storage/file_download.h" +#include "storage/storage_account.h" #include "calls/calls_instance.h" #include "facades.h" #include "app.h" @@ -1367,7 +1368,7 @@ void OverlayWidget::onDownload() { if (Core::App().settings().downloadPath().isEmpty()) { path = File::DefaultDownloadPath(session); } else if (Core::App().settings().downloadPath() == qsl("tmp")) { - path = cTempDir(); + path = session->local().tempDirectory(); } else { path = Core::App().settings().downloadPath(); } diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 5e0eaa0a1..61e25b9db 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -1255,102 +1255,4 @@ bool readOldUserSettings(bool remove, ReadSettingsContext &context) { return _readOldUserSettings(remove, context); } -struct ClearManagerData { - QThread *thread; - QMutex mutex; - QList tasks; - bool working; -}; - -ClearManager::ClearManager() : data(new ClearManagerData()) { - data->thread = new QThread(); - data->working = true; -} - -bool ClearManager::addTask(int task) { - QMutexLocker lock(&data->mutex); - if (!data->working) return false; - - if (!data->tasks.isEmpty() && (data->tasks.at(0) == ClearManagerAll)) return true; - if (task == ClearManagerAll) { - data->tasks.clear(); - } else { - for (int32 i = 0, l = data->tasks.size(); i < l; ++i) { - if (data->tasks.at(i) == task) return true; - } - } - data->tasks.push_back(task); - return true; -} - -bool ClearManager::hasTask(ClearManagerTask task) { - QMutexLocker lock(&data->mutex); - if (data->tasks.isEmpty()) return false; - if (data->tasks.at(0) == ClearManagerAll) return true; - for (int32 i = 0, l = data->tasks.size(); i < l; ++i) { - if (data->tasks.at(i) == task) return true; - } - return false; -} - -void ClearManager::start() { - moveToThread(data->thread); - connect(data->thread, SIGNAL(started()), this, SLOT(onStart())); - connect(data->thread, SIGNAL(finished()), data->thread, SLOT(deleteLater())); - connect(data->thread, SIGNAL(finished()), this, SLOT(deleteLater())); - data->thread->start(); -} - -void ClearManager::stop() { - { - QMutexLocker lock(&data->mutex); - data->tasks.clear(); - } - auto thread = data->thread; - thread->quit(); - thread->wait(); -} - -ClearManager::~ClearManager() { - delete data; -} - -void ClearManager::onStart() { - while (true) { - int task = 0; - bool result = false; - { - QMutexLocker lock(&data->mutex); - if (data->tasks.isEmpty()) { - data->working = false; - break; - } - task = data->tasks.at(0); - } - switch (task) { - case ClearManagerAll: { - result = QDir(cTempDir()).removeRecursively(); - } break; - case ClearManagerDownloads: - result = QDir(cTempDir()).removeRecursively(); - break; - } - { - QMutexLocker lock(&data->mutex); - if (!data->tasks.isEmpty() && data->tasks.at(0) == task) { - data->tasks.pop_front(); - } - if (data->tasks.isEmpty()) { - data->working = false; - } - if (result) { - emit succeed(task, data->working ? 0 : this); - } else { - emit failed(task, data->working ? 0 : this); - } - if (!data->working) break; - } - } -} - } // namespace Local diff --git a/Telegram/SourceFiles/storage/localstorage.h b/Telegram/SourceFiles/storage/localstorage.h index 576a718db..87417776c 100644 --- a/Telegram/SourceFiles/storage/localstorage.h +++ b/Telegram/SourceFiles/storage/localstorage.h @@ -67,36 +67,6 @@ void moveLegacyBackground( void reset(); -enum ClearManagerTask { - ClearManagerAll = 0xFFFF, - ClearManagerDownloads = 0x01, -}; - -struct ClearManagerData; -class ClearManager : public QObject { - Q_OBJECT - -public: - ClearManager(); - bool addTask(int task); - bool hasTask(ClearManagerTask task); - void start(); - void stop(); - -signals: - void succeed(int task, void *manager); - void failed(int task, void *manager); - -private slots: - void onStart(); - -private: - ~ClearManager(); - - ClearManagerData *data; - -}; - int32 oldSettingsVersion(); void countVoiceWaveform(not_null media); diff --git a/Telegram/SourceFiles/storage/storage_account.cpp b/Telegram/SourceFiles/storage/storage_account.cpp index 1c278befd..651505cc6 100644 --- a/Telegram/SourceFiles/storage/storage_account.cpp +++ b/Telegram/SourceFiles/storage/storage_account.cpp @@ -98,6 +98,10 @@ enum { // Local Storage Keys + '/'; } +[[nodiscard]] QString LegacyTempDirectory() { + return cWorkingDir() + qsl("tdata/tdld/"); +} + } // namespace Account::Account(not_null owner, const QString &dataName) @@ -105,6 +109,7 @@ Account::Account(not_null owner, const QString &dataName) , _dataName(dataName) , _dataNameKey(ComputeDataNameKey(dataName)) , _basePath(BaseGlobalPath() + ToFilePart(_dataNameKey) + QChar('/')) +, _tempPath(BaseGlobalPath() + "temp_" + _dataName + QChar('/')) , _databasePath(ComputeDatabasePath(dataName)) , _cacheTotalSizeLimit(Database::Settings().totalSizeLimit) , _cacheBigFileTotalSizeLimit(Database::Settings().totalSizeLimit) @@ -120,6 +125,10 @@ Account::~Account() { } } +QString Account::tempDirectory() const { + return _tempPath; +} + StartResult Account::legacyStart(const QByteArray &passcode) { const auto result = readMapWith(MTP::AuthKeyPtr(), passcode); if (result == ReadMapResult::Failed) { @@ -552,7 +561,7 @@ void Account::reset() { writeMap(); writeMtpData(); - crl::async([base = _basePath, names = std::move(names)] { + crl::async([base = _basePath, temp = _tempPath, names = std::move(names)] { for (const auto &name : names) { if (!name.endsWith(qstr("map0")) && !name.endsWith(qstr("map1")) @@ -561,6 +570,8 @@ void Account::reset() { QFile::remove(base + name); } } + QDir(LegacyTempDirectory()).removeRecursively(); + QDir(temp).removeRecursively(); }); } diff --git a/Telegram/SourceFiles/storage/storage_account.h b/Telegram/SourceFiles/storage/storage_account.h index 6c65fd408..c0a7a4a9b 100644 --- a/Telegram/SourceFiles/storage/storage_account.h +++ b/Telegram/SourceFiles/storage/storage_account.h @@ -63,7 +63,9 @@ public: return _oldMapVersion; } - MTP::AuthKeyPtr peekLegacyLocalKey() const { + [[nodiscard]] QString tempDirectory() const; + + [[nodiscard]] MTP::AuthKeyPtr peekLegacyLocalKey() const { return _localKey; } @@ -208,6 +210,7 @@ private: const QString _dataName; const FileKey _dataNameKey = 0; const QString _basePath; + const QString _tempPath; const QString _databasePath; MTP::AuthKeyPtr _localKey; diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index f03b2a026..962558fb1 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -196,8 +196,4 @@ QPoint Controller::getPointForCallPanelCenter() const { : _widget.windowHandle()->screen()->geometry().center(); } -void Controller::tempDirDelete(int task) { - _widget.tempDirDelete(task); -} - } // namespace Window diff --git a/Telegram/SourceFiles/window/window_controller.h b/Telegram/SourceFiles/window/window_controller.h index 32401d17b..32c4445f6 100644 --- a/Telegram/SourceFiles/window/window_controller.h +++ b/Telegram/SourceFiles/window/window_controller.h @@ -71,8 +71,6 @@ public: QPoint getPointForCallPanelCenter() const; - void tempDirDelete(int task); - private: void showBox( object_ptr content,