2022-05-10 23:57:47 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
|
|
|
* PolyMC - Minecraft Launcher
|
|
|
|
* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
|
2022-06-12 12:50:58 +01:00
|
|
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
2022-05-10 23:57:47 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 3.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2022-04-13 23:16:36 +01:00
|
|
|
|
2022-05-10 23:57:47 +01:00
|
|
|
#include "LocalModUpdateTask.h"
|
2022-04-13 23:16:36 +01:00
|
|
|
|
2022-04-17 14:19:23 +01:00
|
|
|
#include "Application.h"
|
2022-04-13 23:16:36 +01:00
|
|
|
#include "FileSystem.h"
|
2022-04-16 17:27:29 +01:00
|
|
|
#include "minecraft/mod/MetadataHandler.h"
|
2022-04-13 23:16:36 +01:00
|
|
|
|
2022-06-04 15:01:10 +01:00
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2022-04-15 02:02:41 +01:00
|
|
|
LocalModUpdateTask::LocalModUpdateTask(QDir index_dir, ModPlatform::IndexedPack& mod, ModPlatform::IndexedVersion& mod_version)
|
|
|
|
: m_index_dir(index_dir), m_mod(mod), m_mod_version(mod_version)
|
2022-04-13 23:16:36 +01:00
|
|
|
{
|
|
|
|
// Ensure a '.index' folder exists in the mods folder, and create it if it does not
|
2022-04-15 02:02:41 +01:00
|
|
|
if (!FS::ensureFolderPathExists(index_dir.path())) {
|
2022-04-13 23:16:36 +01:00
|
|
|
emitFailed(QString("Unable to create index for mod %1!").arg(m_mod.name));
|
|
|
|
}
|
2022-06-04 15:01:10 +01:00
|
|
|
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
SetFileAttributesA(index_dir.path().toStdString().c_str(), FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED);
|
|
|
|
#endif
|
2022-04-13 23:16:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocalModUpdateTask::executeTask()
|
|
|
|
{
|
|
|
|
setStatus(tr("Updating index for mod:\n%1").arg(m_mod.name));
|
|
|
|
|
2022-06-11 21:19:34 +01:00
|
|
|
auto old_metadata = Metadata::get(m_index_dir, m_mod.addonId);
|
2022-06-10 20:43:01 +01:00
|
|
|
if (old_metadata.isValid()) {
|
|
|
|
emit hasOldMod(old_metadata.name, old_metadata.filename);
|
2022-06-19 18:26:15 +01:00
|
|
|
if (m_mod.slug.isEmpty())
|
|
|
|
m_mod.slug = old_metadata.slug;
|
2022-06-10 20:43:01 +01:00
|
|
|
}
|
|
|
|
|
2022-04-16 17:27:29 +01:00
|
|
|
auto pw_mod = Metadata::create(m_index_dir, m_mod, m_mod_version);
|
2022-06-19 18:26:15 +01:00
|
|
|
if (pw_mod.isValid()) {
|
|
|
|
Metadata::update(m_index_dir, pw_mod);
|
|
|
|
emitSucceeded();
|
|
|
|
} else {
|
|
|
|
qCritical() << "Tried to update an invalid mod!";
|
|
|
|
emitFailed(tr("Invalid metadata"));
|
|
|
|
}
|
2022-04-13 23:16:36 +01:00
|
|
|
}
|
|
|
|
|
2022-04-20 00:19:51 +01:00
|
|
|
auto LocalModUpdateTask::abort() -> bool
|
2022-04-13 23:16:36 +01:00
|
|
|
{
|
|
|
|
emitAborted();
|
|
|
|
return true;
|
|
|
|
}
|