-
Notifications
You must be signed in to change notification settings - Fork 12
/
ExtensionLoader.h
95 lines (82 loc) · 3.02 KB
/
ExtensionLoader.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
95
/*
* 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 EXTENSION_LOADER_H
#define EXTENSION_LOADER_H
#include <vector>
#include "Extension.h"
#include "Util.h"
namespace ExtensionLoader
{
extern const char* DEFAULT_SECTION_NAME;
extern const char* BEGIN_SCRIPT_SIGNATURE;
extern const char* BEGIN_SCRIPT_COMMANDS_AND_OTPIONS;
extern const char* POST_SCRIPT_SIGNATURE;
extern const char* SCAN_SCRIPT_SIGNATURE;
extern const char* QUEUE_SCRIPT_SIGNATURE;
extern const char* SCHEDULER_SCRIPT_SIGNATURE;
extern const char* FEED_SCRIPT_SIGNATURE;
extern const char* END_SCRIPT_SIGNATURE;
extern const char* QUEUE_EVENTS_SIGNATURE;
extern const char* TASK_TIME_SIGNATURE;
extern const char* DEFINITION_SIGNATURE;
extern const int BEGIN_SCRIPT_COMMANDS_AND_OTPIONS_LEN;
extern const int BEGIN_SINGNATURE_LEN;
extern const int QUEUE_EVENTS_SIGNATURE_LEN;
extern const int TASK_TIME_SIGNATURE_LEN;
extern const int DEFINITION_SIGNATURE_LEN;
namespace V1
{
bool Load(Extension::Script& script, const char* location, const char* rootDir);
void ParseOptionsAndCommands(
std::ifstream& file,
std::vector<ManifestFile::Option>& options,
std::vector<ManifestFile::Command>& commands
);
std::vector<ManifestFile::SelectOption>
GetSelectOptions(const std::vector<std::string>& opts, bool isDashDelim);
ManifestFile::SelectOption GetSelectOpt(const std::string& val, bool canBeNum);
void RemoveTailAndTrim(std::string& str, const char* tail);
void BuildDisplayName(Extension::Script& script);
std::pair<std::vector<std::string>, std::string>
ExtractElements(const std::string& str);
template <typename T>
void ParseSectionAndSet(T& opt, std::string sectionName, const std::string& line, size_t sepPos)
{
opt.name = line.substr(1, sepPos - 1);
Util::Trim(opt.name);
ManifestFile::Section section{};
section.name = std::move(sectionName);
size_t digitPos = opt.name.find("1.");
if (digitPos != std::string::npos)
{
section.prefix = opt.name.substr(0, digitPos);
section.multi = true;
opt.name = opt.name.substr(digitPos + 2);
}
opt.section = std::move(section);
opt.displayName = opt.name;
}
}
namespace V2
{
bool Load(Extension::Script& script, const char* location, const char* rootDir);
}
Extension::Kind GetScriptKind(const std::string& line);
}
#endif