-
Notifications
You must be signed in to change notification settings - Fork 12
/
ManifestFile.h
94 lines (83 loc) · 2.81 KB
/
ManifestFile.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* This file is part of nzbget. See <https://nzbget.com>.
*
* Copyright (C) 2023 Denis <denis@nzbget.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; either version 2 of the License, or
* (at your option) any later version.
*
* 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/>.
*/
#ifndef MANIFEST_FILE_H
#define MANIFEST_FILE_H
#include <string>
#include <vector>
#include <boost/variant2.hpp>
#include "Json.h"
#include "Util.h"
namespace ManifestFile
{
using SelectOption = boost::variant2::variant<double, std::string>;
extern const char* MANIFEST_FILE;
extern const char* DEFAULT_SECTION_NAME;
struct Section
{
bool multi;
std::string name;
std::string prefix;
};
struct Option
{
Section section;
std::string name;
std::string displayName;
std::vector<std::string> description;
SelectOption value;
std::vector<SelectOption> select;
};
struct Command
{
Section section;
std::string name;
std::string displayName;
std::string action;
std::vector<std::string> description;
};
struct Manifest
{
std::string author;
std::string main;
std::string kind;
std::string name;
std::string homepage;
std::string displayName;
std::string version;
std::string license;
std::string about;
std::string queueEvents;
std::string taskTime;
std::vector<std::string> description;
std::vector<std::string> requirements;
std::vector<Option> options;
std::vector<Command> commands;
};
bool Load(Manifest& manifest, const char* directory);
bool ValidateAndSet(const Json::JsonObject& json, Manifest& manifest);
bool ValidateCommandsAndSet(const Json::JsonObject& json, std::vector<Command>& commands);
bool ValidateOptionsAndSet(const Json::JsonObject& json, std::vector<Option>& options);
bool ValidateSectionsAndSet(const Json::JsonObject& json, std::vector<Option>& options, std::vector<Command>& commands);
bool ValidateTxtAndSet(const Json::JsonObject& json, std::vector<std::string>& property, const char* propName);
bool CheckKeyAndSet(const Json::JsonObject& json, const char* key, std::string& property);
bool CheckKeyAndSet(const Json::JsonObject& json, const char* key, std::string& property, std::string defValue);
bool CheckKeyAndSet(const Json::JsonObject& json, const char* key, SelectOption& property);
bool CheckKeyAndSet(const Json::JsonObject& json, const char* key, bool& property);
};
#endif