-
-
Notifications
You must be signed in to change notification settings - Fork 565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Identify zip file contents #576
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
64c51a7
feat: add initial support for parseing datapacks
Ryex 25e23e5
fix: force add of ignored testdata files
Ryex 878614f
feat: add a `ModUtils::validate`
Ryex ccfe605
feat: add shaderpack validation
Ryex eb31a95
feat: worldSave parsing and validation
Ryex a7c9b2f
feat: validate world saves
Ryex cfce54f
fix: update parse tests
Ryex 8422e3a
feat: zip resource validation check for flame
Ryex 78984ee
feat: support installing worlds during flame pack import.
Ryex b2082bf
fix: explicit QFileInfo converison for qt6
Ryex 3691f3a
fix: cleanup and suggested changes
Ryex c470f05
refactor: use std::filesystem::rename insted of copy and then moving.
Ryex 7f43842
refactor: add an `identify` function to make easy to reuse
Ryex 0ebf04a
fix newlines
Ryex File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// SPDX-FileCopyrightText: 2022 Rachel Powers <508861+Ryex@users.noreply.github.com> | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
/* | ||
* Prism Launcher - Minecraft Launcher | ||
* Copyright (C) 2022 Rachel Powers <508861+Ryex@users.noreply.github.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/>. | ||
*/ | ||
|
||
#include "DataPack.h" | ||
|
||
#include <QDebug> | ||
#include <QMap> | ||
#include <QRegularExpression> | ||
|
||
#include "Version.h" | ||
|
||
// Values taken from: | ||
// https://minecraft.fandom.com/wiki/Tutorials/Creating_a_data_pack#%22pack_format%22 | ||
static const QMap<int, std::pair<Version, Version>> s_pack_format_versions = { | ||
{ 4, { Version("1.13"), Version("1.14.4") } }, { 5, { Version("1.15"), Version("1.16.1") } }, | ||
{ 6, { Version("1.16.2"), Version("1.16.5") } }, { 7, { Version("1.17"), Version("1.17.1") } }, | ||
{ 8, { Version("1.18"), Version("1.18.1") } }, { 9, { Version("1.18.2"), Version("1.18.2") } }, | ||
{ 10, { Version("1.19"), Version("1.19.3") } }, | ||
}; | ||
|
||
void DataPack::setPackFormat(int new_format_id) | ||
{ | ||
QMutexLocker locker(&m_data_lock); | ||
|
||
if (!s_pack_format_versions.contains(new_format_id)) { | ||
qWarning() << "Pack format '" << new_format_id << "' is not a recognized data pack id!"; | ||
} | ||
|
||
m_pack_format = new_format_id; | ||
} | ||
|
||
void DataPack::setDescription(QString new_description) | ||
{ | ||
QMutexLocker locker(&m_data_lock); | ||
|
||
m_description = new_description; | ||
} | ||
|
||
std::pair<Version, Version> DataPack::compatibleVersions() const | ||
{ | ||
if (!s_pack_format_versions.contains(m_pack_format)) { | ||
return { {}, {} }; | ||
} | ||
|
||
return s_pack_format_versions.constFind(m_pack_format).value(); | ||
} | ||
|
||
std::pair<int, bool> DataPack::compare(const Resource& other, SortType type) const | ||
{ | ||
auto const& cast_other = static_cast<DataPack const&>(other); | ||
|
||
switch (type) { | ||
default: { | ||
auto res = Resource::compare(other, type); | ||
if (res.first != 0) | ||
return res; | ||
} | ||
case SortType::PACK_FORMAT: { | ||
auto this_ver = packFormat(); | ||
auto other_ver = cast_other.packFormat(); | ||
|
||
if (this_ver > other_ver) | ||
return { 1, type == SortType::PACK_FORMAT }; | ||
if (this_ver < other_ver) | ||
return { -1, type == SortType::PACK_FORMAT }; | ||
} | ||
} | ||
return { 0, false }; | ||
} | ||
|
||
bool DataPack::applyFilter(QRegularExpression filter) const | ||
{ | ||
if (filter.match(description()).hasMatch()) | ||
return true; | ||
|
||
if (filter.match(QString::number(packFormat())).hasMatch()) | ||
return true; | ||
|
||
if (filter.match(compatibleVersions().first.toString()).hasMatch()) | ||
return true; | ||
if (filter.match(compatibleVersions().second.toString()).hasMatch()) | ||
return true; | ||
|
||
return Resource::applyFilter(filter); | ||
} | ||
|
||
bool DataPack::valid() const | ||
{ | ||
return m_pack_format != 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// SPDX-FileCopyrightText: 2022 Rachel Powers <508861+Ryex@users.noreply.github.com> | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
/* | ||
* Prism Launcher - Minecraft Launcher | ||
* Copyright (C) 2022 Rachel Powers <508861+Ryex@users.noreply.github.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/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "Resource.h" | ||
|
||
#include <QMutex> | ||
|
||
class Version; | ||
|
||
/* TODO: | ||
* | ||
* Store localized descriptions | ||
* */ | ||
|
||
class DataPack : public Resource { | ||
Q_OBJECT | ||
public: | ||
using Ptr = shared_qobject_ptr<Resource>; | ||
|
||
DataPack(QObject* parent = nullptr) : Resource(parent) {} | ||
DataPack(QFileInfo file_info) : Resource(file_info) {} | ||
|
||
/** Gets the numerical ID of the pack format. */ | ||
[[nodiscard]] int packFormat() const { return m_pack_format; } | ||
/** Gets, respectively, the lower and upper versions supported by the set pack format. */ | ||
[[nodiscard]] std::pair<Version, Version> compatibleVersions() const; | ||
|
||
/** Gets the description of the data pack. */ | ||
[[nodiscard]] QString description() const { return m_description; } | ||
|
||
/** Thread-safe. */ | ||
void setPackFormat(int new_format_id); | ||
|
||
/** Thread-safe. */ | ||
void setDescription(QString new_description); | ||
|
||
bool valid() const override; | ||
|
||
[[nodiscard]] auto compare(Resource const& other, SortType type) const -> std::pair<int, bool> override; | ||
[[nodiscard]] bool applyFilter(QRegularExpression filter) const override; | ||
|
||
protected: | ||
mutable QMutex m_data_lock; | ||
|
||
/* The 'version' of a data pack, as defined in the pack.mcmeta file. | ||
* See https://minecraft.fandom.com/wiki/Data_pack#pack.mcmeta | ||
*/ | ||
int m_pack_format = 0; | ||
|
||
/** The data pack's description, as defined in the pack.mcmeta file. | ||
*/ | ||
QString m_description; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
// SPDX-FileCopyrightText: 2022 Rachel Powers <508861+Ryex@users.noreply.github.com> | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
/* | ||
* Prism Launcher - Minecraft Launcher | ||
* Copyright (C) 2022 Rachel Powers <508861+Ryex@users.noreply.github.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/>. | ||
*/ | ||
|
||
#include "ShaderPack.h" | ||
|
||
#include "minecraft/mod/tasks/LocalShaderPackParseTask.h" | ||
|
||
void ShaderPack::setPackFormat(ShaderPackFormat new_format) | ||
{ | ||
QMutexLocker locker(&m_data_lock); | ||
|
||
m_pack_format = new_format; | ||
} | ||
|
||
bool ShaderPack::valid() const | ||
{ | ||
return m_pack_format != ShaderPackFormat::INVALID; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
No trivial switch statements