mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Remove legacy temp download folder.
This commit is contained in:
parent
4add6234b6
commit
4d65df6ca2
12 changed files with 19 additions and 210 deletions
|
@ -131,11 +131,6 @@ inline const QString &cDataFile() {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const QString &cTempDir() {
|
|
||||||
static const QString res = cWorkingDir() + qsl("tdata/tdld/");
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const QRegularExpression &cRussianLetters() {
|
inline const QRegularExpression &cRussianLetters() {
|
||||||
static QRegularExpression regexp(QString::fromUtf8("[а-яА-ЯёЁ]"));
|
static QRegularExpression regexp(QString::fromUtf8("[а-яА-ЯёЁ]"));
|
||||||
return regexp;
|
return regexp;
|
||||||
|
|
|
@ -180,7 +180,7 @@ QString FileNameUnsafe(
|
||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
return File::DefaultDownloadPath(session);
|
return File::DefaultDownloadPath(session);
|
||||||
} else if (path == qsl("tmp")) {
|
} else if (path == qsl("tmp")) {
|
||||||
return cTempDir();
|
return session->local().tempDirectory();
|
||||||
} else {
|
} else {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
|
@ -502,9 +502,6 @@ void Account::forcedLogOut() {
|
||||||
void Account::loggedOut() {
|
void Account::loggedOut() {
|
||||||
_loggingOut = false;
|
_loggingOut = false;
|
||||||
Media::Player::mixer()->stopAndClear();
|
Media::Player::mixer()->stopAndClear();
|
||||||
if (const auto window = Core::App().activeWindow()) {
|
|
||||||
window->tempDirDelete(Local::ClearManagerAll);
|
|
||||||
}
|
|
||||||
destroySession();
|
destroySession();
|
||||||
Core::App().unlockTerms();
|
Core::App().unlockTerms();
|
||||||
local().reset();
|
local().reset();
|
||||||
|
|
|
@ -860,45 +860,6 @@ void MainWindow::updateControlsGeometry() {
|
||||||
if (_main) _main->checkMainSectionToLayer();
|
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) {
|
void MainWindow::placeSmallCounter(QImage &img, int size, int count, style::color bg, const QPoint &shift, style::color color) {
|
||||||
QPainter p(&img);
|
QPainter p(&img);
|
||||||
|
|
||||||
|
@ -1029,10 +990,6 @@ void MainWindow::updateIsActiveHook() {
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
if (_clearManager) {
|
|
||||||
_clearManager->stop();
|
|
||||||
_clearManager = nullptr;
|
|
||||||
}
|
|
||||||
delete trayIcon;
|
delete trayIcon;
|
||||||
delete trayIconMenu;
|
delete trayIconMenu;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,6 @@ class Widget;
|
||||||
enum class EnterPoint : uchar;
|
enum class EnterPoint : uchar;
|
||||||
} // namespace Intro
|
} // namespace Intro
|
||||||
|
|
||||||
namespace Local {
|
|
||||||
class ClearManager;
|
|
||||||
} // namespace Local
|
|
||||||
|
|
||||||
namespace Window {
|
namespace Window {
|
||||||
class MediaPreviewWidget;
|
class MediaPreviewWidget;
|
||||||
class SectionMemento;
|
class SectionMemento;
|
||||||
|
@ -70,14 +66,6 @@ public:
|
||||||
|
|
||||||
void fixOrder();
|
void fixOrder();
|
||||||
|
|
||||||
enum TempDirState {
|
|
||||||
TempDirRemoving,
|
|
||||||
TempDirExists,
|
|
||||||
TempDirEmpty,
|
|
||||||
};
|
|
||||||
TempDirState tempDirState();
|
|
||||||
void tempDirDelete(int task);
|
|
||||||
|
|
||||||
void sendPaths();
|
void sendPaths();
|
||||||
|
|
||||||
QImage iconWithCounter(int size, int count, style::color bg, style::color fg, bool smallIcon) override;
|
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 showFromTray(QSystemTrayIcon::ActivationReason reason = QSystemTrayIcon::Unknown);
|
||||||
void toggleDisplayNotifyFromTray();
|
void toggleDisplayNotifyFromTray();
|
||||||
|
|
||||||
void onClearFinished(int task, void *manager);
|
|
||||||
void onClearFailed(int task, void *manager);
|
|
||||||
|
|
||||||
void onShowAddContact();
|
void onShowAddContact();
|
||||||
void onShowNewGroup();
|
void onShowNewGroup();
|
||||||
void onShowNewChannel();
|
void onShowNewChannel();
|
||||||
|
|
||||||
signals:
|
|
||||||
void tempDirCleared(int task);
|
|
||||||
void tempDirClearFailed(int task);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
[[nodiscard]] bool skipTrayClick() const;
|
[[nodiscard]] bool skipTrayClick() const;
|
||||||
|
|
||||||
|
@ -174,8 +155,6 @@ private:
|
||||||
|
|
||||||
object_ptr<Window::Theme::WarningWidget> _testingThemeWarning = { nullptr };
|
object_ptr<Window::Theme::WarningWidget> _testingThemeWarning = { nullptr };
|
||||||
|
|
||||||
Local::ClearManager *_clearManager = nullptr;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace App {
|
namespace App {
|
||||||
|
|
|
@ -54,6 +54,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "main/main_session_settings.h"
|
#include "main/main_session_settings.h"
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
#include "storage/file_download.h"
|
#include "storage/file_download.h"
|
||||||
|
#include "storage/storage_account.h"
|
||||||
#include "calls/calls_instance.h"
|
#include "calls/calls_instance.h"
|
||||||
#include "facades.h"
|
#include "facades.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
|
@ -1367,7 +1368,7 @@ void OverlayWidget::onDownload() {
|
||||||
if (Core::App().settings().downloadPath().isEmpty()) {
|
if (Core::App().settings().downloadPath().isEmpty()) {
|
||||||
path = File::DefaultDownloadPath(session);
|
path = File::DefaultDownloadPath(session);
|
||||||
} else if (Core::App().settings().downloadPath() == qsl("tmp")) {
|
} else if (Core::App().settings().downloadPath() == qsl("tmp")) {
|
||||||
path = cTempDir();
|
path = session->local().tempDirectory();
|
||||||
} else {
|
} else {
|
||||||
path = Core::App().settings().downloadPath();
|
path = Core::App().settings().downloadPath();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1255,102 +1255,4 @@ bool readOldUserSettings(bool remove, ReadSettingsContext &context) {
|
||||||
return _readOldUserSettings(remove, context);
|
return _readOldUserSettings(remove, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ClearManagerData {
|
|
||||||
QThread *thread;
|
|
||||||
QMutex mutex;
|
|
||||||
QList<int> 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
|
} // namespace Local
|
||||||
|
|
|
@ -67,36 +67,6 @@ void moveLegacyBackground(
|
||||||
|
|
||||||
void reset();
|
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();
|
int32 oldSettingsVersion();
|
||||||
|
|
||||||
void countVoiceWaveform(not_null<Data::DocumentMedia*> media);
|
void countVoiceWaveform(not_null<Data::DocumentMedia*> media);
|
||||||
|
|
|
@ -98,6 +98,10 @@ enum { // Local Storage Keys
|
||||||
+ '/';
|
+ '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] QString LegacyTempDirectory() {
|
||||||
|
return cWorkingDir() + qsl("tdata/tdld/");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Account::Account(not_null<Main::Account*> owner, const QString &dataName)
|
Account::Account(not_null<Main::Account*> owner, const QString &dataName)
|
||||||
|
@ -105,6 +109,7 @@ Account::Account(not_null<Main::Account*> owner, const QString &dataName)
|
||||||
, _dataName(dataName)
|
, _dataName(dataName)
|
||||||
, _dataNameKey(ComputeDataNameKey(dataName))
|
, _dataNameKey(ComputeDataNameKey(dataName))
|
||||||
, _basePath(BaseGlobalPath() + ToFilePart(_dataNameKey) + QChar('/'))
|
, _basePath(BaseGlobalPath() + ToFilePart(_dataNameKey) + QChar('/'))
|
||||||
|
, _tempPath(BaseGlobalPath() + "temp_" + _dataName + QChar('/'))
|
||||||
, _databasePath(ComputeDatabasePath(dataName))
|
, _databasePath(ComputeDatabasePath(dataName))
|
||||||
, _cacheTotalSizeLimit(Database::Settings().totalSizeLimit)
|
, _cacheTotalSizeLimit(Database::Settings().totalSizeLimit)
|
||||||
, _cacheBigFileTotalSizeLimit(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) {
|
StartResult Account::legacyStart(const QByteArray &passcode) {
|
||||||
const auto result = readMapWith(MTP::AuthKeyPtr(), passcode);
|
const auto result = readMapWith(MTP::AuthKeyPtr(), passcode);
|
||||||
if (result == ReadMapResult::Failed) {
|
if (result == ReadMapResult::Failed) {
|
||||||
|
@ -552,7 +561,7 @@ void Account::reset() {
|
||||||
writeMap();
|
writeMap();
|
||||||
writeMtpData();
|
writeMtpData();
|
||||||
|
|
||||||
crl::async([base = _basePath, names = std::move(names)] {
|
crl::async([base = _basePath, temp = _tempPath, names = std::move(names)] {
|
||||||
for (const auto &name : names) {
|
for (const auto &name : names) {
|
||||||
if (!name.endsWith(qstr("map0"))
|
if (!name.endsWith(qstr("map0"))
|
||||||
&& !name.endsWith(qstr("map1"))
|
&& !name.endsWith(qstr("map1"))
|
||||||
|
@ -561,6 +570,8 @@ void Account::reset() {
|
||||||
QFile::remove(base + name);
|
QFile::remove(base + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
QDir(LegacyTempDirectory()).removeRecursively();
|
||||||
|
QDir(temp).removeRecursively();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,9 @@ public:
|
||||||
return _oldMapVersion;
|
return _oldMapVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
MTP::AuthKeyPtr peekLegacyLocalKey() const {
|
[[nodiscard]] QString tempDirectory() const;
|
||||||
|
|
||||||
|
[[nodiscard]] MTP::AuthKeyPtr peekLegacyLocalKey() const {
|
||||||
return _localKey;
|
return _localKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,6 +210,7 @@ private:
|
||||||
const QString _dataName;
|
const QString _dataName;
|
||||||
const FileKey _dataNameKey = 0;
|
const FileKey _dataNameKey = 0;
|
||||||
const QString _basePath;
|
const QString _basePath;
|
||||||
|
const QString _tempPath;
|
||||||
const QString _databasePath;
|
const QString _databasePath;
|
||||||
|
|
||||||
MTP::AuthKeyPtr _localKey;
|
MTP::AuthKeyPtr _localKey;
|
||||||
|
|
|
@ -196,8 +196,4 @@ QPoint Controller::getPointForCallPanelCenter() const {
|
||||||
: _widget.windowHandle()->screen()->geometry().center();
|
: _widget.windowHandle()->screen()->geometry().center();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::tempDirDelete(int task) {
|
|
||||||
_widget.tempDirDelete(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Window
|
} // namespace Window
|
||||||
|
|
|
@ -71,8 +71,6 @@ public:
|
||||||
|
|
||||||
QPoint getPointForCallPanelCenter() const;
|
QPoint getPointForCallPanelCenter() const;
|
||||||
|
|
||||||
void tempDirDelete(int task);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void showBox(
|
void showBox(
|
||||||
object_ptr<Ui::BoxContent> content,
|
object_ptr<Ui::BoxContent> content,
|
||||||
|
|
Loading…
Add table
Reference in a new issue