1
0
mirror of https://github.com/QRouland/UTPass.git synced 2025-02-11 15:07:16 +00:00
UTPass/plugins/Utils/utils.cpp

59 lines
1.2 KiB
C++
Raw Normal View History

2019-09-20 21:29:39 +02:00
#include <QDir>
2025-01-20 15:46:57 +01:00
#include <QSemaphore>
2019-09-20 21:29:39 +02:00
2025-01-20 15:46:57 +01:00
#include "jobs/unzipjob.h"
2019-09-20 21:29:39 +02:00
#include "utils.h"
2025-01-20 15:46:57 +01:00
Utils::Utils():
m_sem(std::unique_ptr<QSemaphore>(new QSemaphore(1)))
{}
2019-09-20 21:29:39 +02:00
2025-01-20 15:46:57 +01:00
bool Utils::unzip(QUrl zip_url, QString dir_out_path)
{
if (!this->m_sem->tryAcquire(1, 500)) {
2019-09-20 21:29:39 +02:00
return false;
}
2025-01-20 15:46:57 +01:00
qInfo() << "Unzip path " << zip_url << " to " << dir_out_path;
auto job = new UnzipJob(zip_url, QDir(dir_out_path));
connect(job, &UnzipJob::resultReady, this, &Utils::unzipResult);
connect(job, &UnzipJob::finished, job, &QObject::deleteLater);
job->start();
return true;
2019-09-20 21:29:39 +02:00
}
2025-01-20 15:46:57 +01:00
void Utils::unzipResult(bool err)
2019-09-20 21:29:39 +02:00
{
2025-01-20 15:46:57 +01:00
qDebug() << "Unzip Result";
if (err) {
qInfo() << "Unzip Failed";
emit unzipFailed();
2025-01-20 15:46:57 +01:00
} else {
qInfo() << "Unzip Succeed";
emit unzipSucceed();
}
this->m_sem->release(1);
2019-09-20 21:29:39 +02:00
}
2025-01-17 10:40:54 +01:00
2025-01-20 15:46:57 +01:00
2025-01-20 11:23:40 +01:00
QString Utils::manifestPath()
{
2025-01-17 10:40:54 +01:00
auto path = QDir(QDir::currentPath()).filePath("manifest_.json");
2025-01-20 15:46:57 +01:00
qInfo() << "Manifest path : " << path;
2025-01-17 10:40:54 +01:00
return path;
}
bool Utils::rmFile(QUrl file_url)
{
return QFile::remove(file_url.toLocalFile());
}
bool Utils::rmDir(QUrl dir_url)
{
QDir dir(dir_url.toLocalFile());
return dir.removeRecursively();
}