2022-05-10 23:57:47 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
2023-04-20 20:35:10 +01:00
|
|
|
* PolyMC - Minecraft Launcher
|
|
|
|
* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
|
|
|
|
*
|
|
|
|
* 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-05-10 23:57:47 +01:00
|
|
|
|
2022-04-13 23:16:36 +01:00
|
|
|
#pragma once
|
|
|
|
|
2022-04-13 23:23:12 +01:00
|
|
|
#include "modplatform/ModIndex.h"
|
|
|
|
|
2022-04-13 23:16:36 +01:00
|
|
|
#include <QString>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QVariant>
|
|
|
|
|
|
|
|
class QDir;
|
|
|
|
|
2022-04-16 02:37:10 +01:00
|
|
|
// Mod from launcher/minecraft/mod/Mod.h
|
|
|
|
class Mod;
|
|
|
|
|
2022-04-16 17:27:29 +01:00
|
|
|
namespace Packwiz {
|
|
|
|
|
2022-05-18 09:46:07 +01:00
|
|
|
auto getRealIndexName(QDir& index_dir, QString normalized_index_name, bool should_match = false) -> QString;
|
|
|
|
|
2022-04-16 17:27:29 +01:00
|
|
|
class V1 {
|
2022-04-13 23:16:36 +01:00
|
|
|
public:
|
|
|
|
struct Mod {
|
2023-04-20 20:35:10 +01:00
|
|
|
QString slug {};
|
|
|
|
QString name {};
|
|
|
|
QString filename {};
|
2022-04-13 23:16:36 +01:00
|
|
|
// FIXME: make side an enum
|
2023-04-20 20:35:10 +01:00
|
|
|
QString side {"both"};
|
2022-04-13 23:16:36 +01:00
|
|
|
|
|
|
|
// [download]
|
2023-04-20 20:35:10 +01:00
|
|
|
QString mode {};
|
|
|
|
QUrl url {};
|
|
|
|
QString hash_format {};
|
|
|
|
QString hash {};
|
2022-04-13 23:16:36 +01:00
|
|
|
|
|
|
|
// [update]
|
2023-04-20 20:35:10 +01:00
|
|
|
ModPlatform::ResourceProvider provider {};
|
|
|
|
QVariant file_id {};
|
|
|
|
QVariant project_id {};
|
2022-04-16 02:37:10 +01:00
|
|
|
|
|
|
|
public:
|
2022-04-17 15:40:41 +01:00
|
|
|
// This is a totally heuristic, but should work for now.
|
2022-06-19 18:26:15 +01:00
|
|
|
auto isValid() const -> bool { return !slug.isEmpty() && !project_id.isNull(); }
|
2022-04-17 15:40:41 +01:00
|
|
|
|
|
|
|
// Different providers can use different names for the same thing
|
|
|
|
// Modrinth-specific
|
|
|
|
auto mod_id() -> QVariant& { return project_id; }
|
|
|
|
auto version() -> QVariant& { return file_id; }
|
2022-04-13 23:16:36 +01:00
|
|
|
};
|
|
|
|
|
2022-05-07 23:39:00 +01:00
|
|
|
/* Generates the object representing the information in a mod.pw.toml file via
|
2022-04-16 02:37:10 +01:00
|
|
|
* its common representation in the launcher, when downloading mods.
|
|
|
|
* */
|
2022-04-13 23:16:36 +01:00
|
|
|
static auto createModFormat(QDir& index_dir, ModPlatform::IndexedPack& mod_pack, ModPlatform::IndexedVersion& mod_version) -> Mod;
|
2022-05-07 23:39:00 +01:00
|
|
|
/* Generates the object representing the information in a mod.pw.toml file via
|
2022-06-19 18:26:15 +01:00
|
|
|
* its common representation in the launcher, plus a necessary slug.
|
2022-04-16 02:37:10 +01:00
|
|
|
* */
|
2022-06-19 18:26:15 +01:00
|
|
|
static auto createModFormat(QDir& index_dir, ::Mod& internal_mod, QString slug) -> Mod;
|
2022-04-13 23:16:36 +01:00
|
|
|
|
|
|
|
/* Updates the mod index for the provided mod.
|
|
|
|
* This creates a new index if one does not exist already
|
|
|
|
* TODO: Ask the user if they want to override, and delete the old mod's files, or keep the old one.
|
|
|
|
* */
|
|
|
|
static void updateModIndex(QDir& index_dir, Mod& mod);
|
2022-04-14 01:25:08 +01:00
|
|
|
|
2022-06-19 18:26:15 +01:00
|
|
|
/* Deletes the metadata for the mod with the given slug. If the metadata doesn't exist, it does nothing. */
|
|
|
|
static void deleteModIndex(QDir& index_dir, QString& mod_slug);
|
2022-04-15 02:02:41 +01:00
|
|
|
|
2022-06-11 21:19:34 +01:00
|
|
|
/* Deletes the metadata for the mod with the given id. If the metadata doesn't exist, it does nothing. */
|
|
|
|
static void deleteModIndex(QDir& index_dir, QVariant& mod_id);
|
|
|
|
|
2022-06-19 18:26:15 +01:00
|
|
|
/* Gets the metadata for a mod with a particular file name.
|
2022-04-14 01:25:08 +01:00
|
|
|
* If the mod doesn't have a metadata, it simply returns an empty Mod object.
|
|
|
|
* */
|
2022-06-19 18:26:15 +01:00
|
|
|
static auto getIndexForMod(QDir& index_dir, QString slug) -> Mod;
|
2022-06-11 21:19:34 +01:00
|
|
|
|
|
|
|
/* Gets the metadata for a mod with a particular id.
|
|
|
|
* If the mod doesn't have a metadata, it simply returns an empty Mod object.
|
|
|
|
* */
|
|
|
|
static auto getIndexForMod(QDir& index_dir, QVariant& mod_id) -> Mod;
|
2022-04-13 23:16:36 +01:00
|
|
|
};
|
2022-04-16 17:27:29 +01:00
|
|
|
|
2023-04-20 20:35:10 +01:00
|
|
|
} // namespace Packwiz
|