1
0
mirror of https://github.com/QRouland/UTPass.git synced 2025-02-11 23:17:15 +00:00

77 lines
2.2 KiB
C++
Raw Normal View History

2025-01-10 21:33:48 +01:00
#include <QFile>
#include <QDir>
#include <QUrl>
#include <QUuid>
#include <QtCore/QStandardPaths>
2025-01-29 16:42:37 +01:00
#include <memory>
2025-01-10 21:33:48 +01:00
#include <quazip5/JlCompress.h>
//#include "passphraseprovider.h"
2025-01-10 21:33:48 +01:00
#include "utils.h"
TestsUtils::TestsUtils()
//m_passphrase_povider(std::unique_ptr<TesTPassphraseProvider>(new TesTPassphraseProvider()))
2025-01-29 16:42:37 +01:00
{}
2025-01-10 21:33:48 +01:00
2025-01-13 18:11:16 +01:00
QString TestsUtils::getTempPath()
{
2025-01-10 21:33:48 +01:00
// Get the system's temporary directory
2025-01-29 16:42:37 +01:00
QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
2025-01-10 21:33:48 +01:00
// Generate a unique UUID
QString uuid = QUuid::createUuid().toString(QUuid::WithoutBraces);
// Create a new directory using the generated UUID
QString newTempDir = tempDir + "/" + uuid;
QDir dir;
2025-01-29 16:42:37 +01:00
dir.mkpath(newTempDir);
qDebug() << "[TestUtils] TempDir : " << newTempDir;
2025-01-29 16:42:37 +01:00
return newTempDir;
2025-01-10 21:33:48 +01:00
}
bool TestsUtils::fileExists(QUrl path)
{
QString p = path.toLocalFile();
auto ret = QFileInfo::exists(p) && QFileInfo(p).isFile();
qDebug() << "[TestUtils]" << p << "is existing file :" << ret;
return ret;
}
void TestsUtils::copyFolder(QUrl sourceFolderUrl, QUrl destFolderUrl)
{
auto sourceFolder = sourceFolderUrl.toLocalFile();
auto destFolder = destFolderUrl.toLocalFile();
QDir sourceDir(sourceFolder);
if (!sourceDir.exists())
return;
QDir destDir(destFolder);
if (!destDir.exists()) {
destDir.mkdir(destFolder);
}
qDebug() << "[TestUtils]" << "Copy files from" << sourceFolder << "to" << destFolder;
QStringList files = sourceDir.entryList(QDir::Files);
for (int i = 0; i < files.count(); i++) {
QString srcName = sourceFolder + "/" + files[i];
QString destName = destFolder + "/" + files[i];
QFile::copy(srcName, destName);
qDebug() << "[TestUtils]" << "Copy file from" << srcName << "to" << destName;
}
files.clear();
files = sourceDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
for (int i = 0; i < files.count(); i++) {
QString srcName = sourceFolder + "/" + files[i];
QString destName = destFolder + "/" + files[i];
this->copyFolder(srcName, destName);
}
}
2025-01-10 21:33:48 +01:00
// QObject *TestsUtils::getTestPassphraseProvider()
// {
// return &TesTPassphraseProvider::instance();
// }
2025-01-29 16:42:37 +01:00
2025-01-10 21:33:48 +01:00