Replaced QFile::remove with FS::deletePath
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
5099061a5c
commit
031a9f4738
@ -389,20 +389,15 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
|
||||
{
|
||||
static const QString baseLogFile = BuildConfig.LAUNCHER_NAME + "-%0.log";
|
||||
static const QString logBase = FS::PathCombine("logs", baseLogFile);
|
||||
auto moveFile = [](const QString& oldName, const QString& newName) {
|
||||
QFile::remove(newName);
|
||||
QFile::copy(oldName, newName);
|
||||
QFile::remove(oldName);
|
||||
};
|
||||
if (FS::ensureFolderPathExists("logs")) { // if this did not fail
|
||||
for (auto i = 0; i <= 4; i++)
|
||||
if (auto oldName = baseLogFile.arg(i);
|
||||
QFile::exists(oldName)) // do not pointlessly delete new files if the old ones are not there
|
||||
moveFile(oldName, logBase.arg(i));
|
||||
FS::move(oldName, logBase.arg(i));
|
||||
}
|
||||
|
||||
for (auto i = 4; i > 0; i--)
|
||||
moveFile(logBase.arg(i - 1), logBase.arg(i));
|
||||
FS::move(logBase.arg(i - 1), logBase.arg(i));
|
||||
|
||||
logFile = std::unique_ptr<QFile>(new QFile(logBase.arg(0)));
|
||||
if (!logFile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <QFile>
|
||||
|
||||
#include "BaseInstaller.h"
|
||||
#include "FileSystem.h"
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
|
||||
BaseInstaller::BaseInstaller() {}
|
||||
@ -42,7 +43,7 @@ bool BaseInstaller::add(MinecraftInstance* to)
|
||||
|
||||
bool BaseInstaller::remove(MinecraftInstance* from)
|
||||
{
|
||||
return QFile::remove(filename(from->instanceRoot()));
|
||||
return FS::deletePath(filename(from->instanceRoot()));
|
||||
}
|
||||
|
||||
QString BaseInstaller::filename(const QString& root) const
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include "FileSystem.h"
|
||||
|
||||
InstanceCreationTask::InstanceCreationTask() = default;
|
||||
|
||||
@ -47,7 +48,7 @@ void InstanceCreationTask::executeTask()
|
||||
if (!QFile::exists(path))
|
||||
continue;
|
||||
qDebug() << "Removing" << path;
|
||||
if (!QFile::remove(path)) {
|
||||
if (!FS::deletePath(path)) {
|
||||
qCritical() << "Couldn't remove the old conflicting files.";
|
||||
emitFailed(tr("Failed to remove old conflicting files."));
|
||||
return;
|
||||
|
@ -122,7 +122,7 @@ bool compressDirFiles(QString fileCompressed, QString dir, QFileInfoList files,
|
||||
QuaZip zip(fileCompressed);
|
||||
QDir().mkpath(QFileInfo(fileCompressed).absolutePath());
|
||||
if (!zip.open(QuaZip::mdCreate)) {
|
||||
QFile::remove(fileCompressed);
|
||||
FS::deletePath(fileCompressed);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ bool compressDirFiles(QString fileCompressed, QString dir, QFileInfoList files,
|
||||
|
||||
zip.close();
|
||||
if (zip.getZipError() != 0) {
|
||||
QFile::remove(fileCompressed);
|
||||
FS::deletePath(fileCompressed);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -143,7 +143,7 @@ bool createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<M
|
||||
{
|
||||
QuaZip zipOut(targetJarPath);
|
||||
if (!zipOut.open(QuaZip::mdCreate)) {
|
||||
QFile::remove(targetJarPath);
|
||||
FS::deletePath(targetJarPath);
|
||||
qCritical() << "Failed to open the minecraft.jar for modding";
|
||||
return false;
|
||||
}
|
||||
@ -161,7 +161,7 @@ bool createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<M
|
||||
if (mod->type() == ResourceType::ZIPFILE) {
|
||||
if (!mergeZipFiles(&zipOut, mod->fileinfo(), addedFiles)) {
|
||||
zipOut.close();
|
||||
QFile::remove(targetJarPath);
|
||||
FS::deletePath(targetJarPath);
|
||||
qCritical() << "Failed to add" << mod->fileinfo().fileName() << "to the jar.";
|
||||
return false;
|
||||
}
|
||||
@ -170,7 +170,7 @@ bool createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<M
|
||||
auto filename = mod->fileinfo();
|
||||
if (!JlCompress::compressFile(&zipOut, filename.absoluteFilePath(), filename.fileName())) {
|
||||
zipOut.close();
|
||||
QFile::remove(targetJarPath);
|
||||
FS::deletePath(targetJarPath);
|
||||
qCritical() << "Failed to add" << mod->fileinfo().fileName() << "to the jar.";
|
||||
return false;
|
||||
}
|
||||
@ -193,7 +193,7 @@ bool createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<M
|
||||
|
||||
if (!compressDirFiles(&zipOut, parent_dir, files)) {
|
||||
zipOut.close();
|
||||
QFile::remove(targetJarPath);
|
||||
FS::deletePath(targetJarPath);
|
||||
qCritical() << "Failed to add" << mod->fileinfo().fileName() << "to the jar.";
|
||||
return false;
|
||||
}
|
||||
@ -201,7 +201,7 @@ bool createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<M
|
||||
} else {
|
||||
// Make sure we do not continue launching when something is missing or undefined...
|
||||
zipOut.close();
|
||||
QFile::remove(targetJarPath);
|
||||
FS::deletePath(targetJarPath);
|
||||
qCritical() << "Failed to add unknown mod type" << mod->fileinfo().fileName() << "to the jar.";
|
||||
return false;
|
||||
}
|
||||
@ -209,7 +209,7 @@ bool createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<M
|
||||
|
||||
if (!mergeZipFiles(&zipOut, QFileInfo(sourceJarPath), addedFiles, [](const QString key) { return !key.contains("META-INF"); })) {
|
||||
zipOut.close();
|
||||
QFile::remove(targetJarPath);
|
||||
FS::deletePath(targetJarPath);
|
||||
qCritical() << "Failed to insert minecraft.jar contents.";
|
||||
return false;
|
||||
}
|
||||
@ -217,7 +217,7 @@ bool createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<M
|
||||
// Recompress the jar
|
||||
zipOut.close();
|
||||
if (zipOut.getZipError() != 0) {
|
||||
QFile::remove(targetJarPath);
|
||||
FS::deletePath(targetJarPath);
|
||||
qCritical() << "Failed to finalize minecraft.jar!";
|
||||
return false;
|
||||
}
|
||||
@ -499,10 +499,10 @@ auto ExportToZipTask::exportZip() -> ZipResult
|
||||
void ExportToZipTask::finish()
|
||||
{
|
||||
if (m_build_zip_future.isCanceled()) {
|
||||
QFile::remove(m_output_path);
|
||||
FS::deletePath(m_output_path);
|
||||
emitAborted();
|
||||
} else if (auto result = m_build_zip_future.result(); result.has_value()) {
|
||||
QFile::remove(m_output_path);
|
||||
FS::deletePath(m_output_path);
|
||||
emitFailed(result.value());
|
||||
} else {
|
||||
emitSucceeded();
|
||||
|
@ -322,7 +322,7 @@ const MMCIcon* IconList::icon(const QString& key) const
|
||||
|
||||
bool IconList::deleteIcon(const QString& key)
|
||||
{
|
||||
return iconFileExists(key) && QFile::remove(icon(key)->getFilePath());
|
||||
return iconFileExists(key) && FS::deletePath(icon(key)->getFilePath());
|
||||
}
|
||||
|
||||
bool IconList::trashIcon(const QString& key)
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include "BaseEntity.h"
|
||||
|
||||
#include "FileSystem.h"
|
||||
#include "Json.h"
|
||||
#include "net/ApiDownload.h"
|
||||
#include "net/HttpMetaCache.h"
|
||||
@ -83,8 +84,7 @@ bool Meta::BaseEntity::loadLocalFile()
|
||||
} catch (const Exception& e) {
|
||||
qDebug() << QString("Unable to parse file %1: %2").arg(fname, e.cause());
|
||||
// just make sure it's gone and we never consider it again.
|
||||
QFile::remove(fname);
|
||||
return false;
|
||||
return !FS::deletePath(fname);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -336,7 +336,7 @@ bool Component::revert()
|
||||
bool result = true;
|
||||
// just kill the file and reload
|
||||
if (QFile::exists(filename)) {
|
||||
result = QFile::remove(filename);
|
||||
result = FS::deletePath(filename);
|
||||
}
|
||||
if (result) {
|
||||
// file gone...
|
||||
|
@ -839,7 +839,7 @@ bool PackProfile::installCustomJar_internal(QString filepath)
|
||||
|
||||
QFileInfo jarInfo(finalPath);
|
||||
if (jarInfo.exists()) {
|
||||
if (!QFile::remove(finalPath)) {
|
||||
if (!FS::deletePath(finalPath)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ bool ResourceFolderModel::installResource(QString original_path)
|
||||
case ResourceType::ZIPFILE:
|
||||
case ResourceType::LITEMOD: {
|
||||
if (QFile::exists(new_path) || QFile::exists(new_path + QString(".disabled"))) {
|
||||
if (!QFile::remove(new_path)) {
|
||||
if (!FS::deletePath(new_path)) {
|
||||
qCritical() << "Cleaning up new location (" << new_path << ") was unsuccessful!";
|
||||
return false;
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ void PackInstallTask::deleteExistingFiles()
|
||||
|
||||
// Delete the files
|
||||
for (const auto& item : filesToDelete) {
|
||||
QFile::remove(item);
|
||||
FS::deletePath(item);
|
||||
}
|
||||
}
|
||||
|
||||
@ -987,7 +987,7 @@ bool PackInstallTask::extractMods(const QMap<QString, VersionMod>& toExtract,
|
||||
// the copy from the Configs.zip
|
||||
QFileInfo fileInfo(to);
|
||||
if (fileInfo.exists()) {
|
||||
if (!QFile::remove(to)) {
|
||||
if (!FS::deletePath(to)) {
|
||||
qWarning() << "Failed to delete" << to;
|
||||
return false;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ void createOverrides(const QString& name, const QString& parent_folder, const QS
|
||||
{
|
||||
QString file_path(FS::PathCombine(parent_folder, name + ".txt"));
|
||||
if (QFile::exists(file_path))
|
||||
QFile::remove(file_path);
|
||||
FS::deletePath(file_path);
|
||||
|
||||
FS::ensureFilePathExists(file_path);
|
||||
|
||||
|
@ -352,15 +352,10 @@ PrismUpdaterApp::PrismUpdaterApp(int& argc, char** argv) : QApplication(argc, ar
|
||||
FS::ensureFolderPathExists(FS::PathCombine(m_dataPath, "logs"));
|
||||
static const QString baseLogFile = BuildConfig.LAUNCHER_NAME + "Updater" + (m_checkOnly ? "-CheckOnly" : "") + "-%0.log";
|
||||
static const QString logBase = FS::PathCombine(m_dataPath, "logs", baseLogFile);
|
||||
auto moveFile = [](const QString& oldName, const QString& newName) {
|
||||
QFile::remove(newName);
|
||||
QFile::copy(oldName, newName);
|
||||
QFile::remove(oldName);
|
||||
};
|
||||
|
||||
if (FS::ensureFolderPathExists("logs")) { // enough history to track both launches of the updater during a portable install
|
||||
moveFile(logBase.arg(1), logBase.arg(2));
|
||||
moveFile(logBase.arg(0), logBase.arg(1));
|
||||
FS::move(logBase.arg(1), logBase.arg(2));
|
||||
FS::move(logBase.arg(0), logBase.arg(1));
|
||||
}
|
||||
|
||||
logFile = std::unique_ptr<QFile>(new QFile(logBase.arg(0)));
|
||||
@ -924,7 +919,7 @@ bool PrismUpdaterApp::callAppImageUpdate()
|
||||
|
||||
void PrismUpdaterApp::clearUpdateLog()
|
||||
{
|
||||
QFile::remove(m_updateLogPath);
|
||||
FS::deletePath(m_updateLogPath);
|
||||
}
|
||||
|
||||
void PrismUpdaterApp::logUpdate(const QString& msg)
|
||||
|
Loading…
Reference in New Issue
Block a user