2026-07-09 09:17:30 +00:00
|
|
|
#include "FileHelper.h"
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
bool FileHelper::createDir(const QString &path)
|
|
|
|
|
{
|
|
|
|
|
QDir dir(path);
|
|
|
|
|
if (!dir.exists())
|
|
|
|
|
return dir.mkpath(".");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FileHelper::copyFileOverwrite(const QString &src, const QString &dst)
|
|
|
|
|
{
|
|
|
|
|
if (QFile::exists(dst))
|
|
|
|
|
{
|
|
|
|
|
if (!QFile::remove(dst))
|
|
|
|
|
{
|
2026-07-10 00:38:23 -07:00
|
|
|
qDebug() << "Cannot remove the old file:" << dst;
|
2026-07-09 09:17:30 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QFile::copy(src, dst);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FileHelper::isProcessRunning(const QString &exeName)
|
|
|
|
|
{
|
|
|
|
|
QProcess process;
|
|
|
|
|
process.start("tasklist");
|
|
|
|
|
process.waitForFinished();
|
|
|
|
|
QString output = process.readAllStandardOutput();
|
|
|
|
|
return output.contains(exeName, Qt::CaseInsensitive);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FileHelper::killProcess(const QString &exeName)
|
|
|
|
|
{
|
|
|
|
|
if (!isProcessRunning(exeName))
|
|
|
|
|
return true;
|
|
|
|
|
QProcess process;
|
|
|
|
|
process.start("taskkill /f /im " + exeName);
|
|
|
|
|
process.waitForFinished(1000);
|
|
|
|
|
return !isProcessRunning(exeName);
|
2026-07-10 00:38:23 -07:00
|
|
|
}
|