mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 06:35:14 +00:00
Remove legacy temp download folder.
This commit is contained in:
@@ -1255,102 +1255,4 @@ bool readOldUserSettings(bool remove, ReadSettingsContext &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
|
||||
|
Reference in New Issue
Block a user