mirror of
https://github.com/N64Recomp/N64ModernRuntime.git
synced 2026-05-10 19:01:53 +00:00
Add checks for required fields existing in manifest
This commit is contained in:
parent
52b365f42c
commit
729155f0f1
2 changed files with 34 additions and 7 deletions
|
|
@ -64,9 +64,9 @@ namespace recomp {
|
|||
|
||||
std::string mod_id;
|
||||
|
||||
int major_version;
|
||||
int minor_version;
|
||||
int patch_version;
|
||||
int major_version = -1;
|
||||
int minor_version = -1;
|
||||
int patch_version = -1;
|
||||
|
||||
// These are all relative to the base path for loose mods or inside the zip for zipped mods.
|
||||
std::string binary_path;
|
||||
|
|
|
|||
|
|
@ -142,16 +142,20 @@ enum class ManifestField {
|
|||
Invalid,
|
||||
};
|
||||
|
||||
const std::string mod_id_key = "id";
|
||||
const std::string major_version_key = "major_version";
|
||||
const std::string minor_version_key = "minor_version";
|
||||
const std::string patch_version_key = "patch_version";
|
||||
const std::string binary_path_key = "binary";
|
||||
const std::string binary_syms_path_key = "binary_syms";
|
||||
const std::string rom_patch_path_key = "rom_patch";
|
||||
const std::string rom_patch_syms_path_key = "rom_patch_syms";
|
||||
|
||||
std::unordered_map<std::string, ManifestField> field_map {
|
||||
{ "id", ManifestField::Id },
|
||||
{ "major_version", ManifestField::MajorVersion },
|
||||
{ "minor_version", ManifestField::MinorVersion },
|
||||
{ "patch_version", ManifestField::PatchVersion },
|
||||
{ mod_id_key, ManifestField::Id },
|
||||
{ major_version_key, ManifestField::MajorVersion },
|
||||
{ minor_version_key, ManifestField::MinorVersion },
|
||||
{ patch_version_key, ManifestField::PatchVersion },
|
||||
{ binary_path_key, ManifestField::BinaryPath },
|
||||
{ binary_syms_path_key, ManifestField::BinarySymsPath },
|
||||
{ rom_patch_path_key, ManifestField::RomPatchPath },
|
||||
|
|
@ -271,6 +275,29 @@ bool validate_file_exists(const recomp::mods::ModManifest& manifest, const std::
|
|||
|
||||
bool validate_manifest(const recomp::mods::ModManifest& manifest, recomp::mods::ModLoadError& error, std::string& error_param) {
|
||||
using namespace recomp::mods;
|
||||
|
||||
// Check for required fields.
|
||||
if (manifest.mod_id.empty()) {
|
||||
error = ModLoadError::MissingManifestField;
|
||||
error_param = mod_id_key;
|
||||
return false;
|
||||
}
|
||||
if (manifest.major_version == -1) {
|
||||
error = ModLoadError::MissingManifestField;
|
||||
error_param = major_version_key;
|
||||
return false;
|
||||
}
|
||||
if (manifest.minor_version == -1) {
|
||||
error = ModLoadError::MissingManifestField;
|
||||
error_param = minor_version_key;
|
||||
return false;
|
||||
}
|
||||
if (manifest.patch_version == -1) {
|
||||
error = ModLoadError::MissingManifestField;
|
||||
error_param = patch_version_key;
|
||||
return false;
|
||||
}
|
||||
|
||||
// If either a binary file or binary symbol file is provided, the other must be as well.
|
||||
if (manifest.binary_path.empty() != manifest.binary_syms_path.empty()) {
|
||||
error = ModLoadError::MissingManifestField;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue