30 static std::string
getFullPath(
const std::string &fileName,
const std::string &exename) {
36 return exepath + fileName;
38 return exepath +
"addons/" + fileName;
42 return FILESDIR + (
"/" + fileName);
44 return FILESDIR + (
"/addons/" + fileName);
49 static std::string
parseAddonInfo(
AddonInfo& addoninfo,
const picojson::value &json,
const std::string &fileName,
const std::string &exename) {
50 const std::string& json_error = picojson::get_last_error();
51 if (!json_error.empty()) {
52 return "Loading " + fileName +
" failed. " + json_error;
54 if (!json.is<picojson::object>())
55 return "Loading " + fileName +
" failed. JSON is not an object.";
58 const picojson::object& obj = json.get<picojson::object>();
60 const auto it = obj.find(
"args");
61 if (it != obj.cend()) {
62 const auto& val = it->second;
63 if (!val.is<picojson::array>())
64 return "Loading " + fileName +
" failed. 'args' must be an array.";
65 for (
const picojson::value &v : val.get<picojson::array>()) {
66 if (!v.is<std::string>())
67 return "Loading " + fileName +
" failed. 'args' entry is not a string.";
68 addoninfo.
args +=
" " + v.get<std::string>();
74 const auto it = obj.find(
"ctu");
75 if (it != obj.cend()) {
76 const auto& val = it->second;
79 return "Loading " + fileName +
" failed. 'ctu' must be a boolean.";
80 addoninfo.
ctu = val.get<
bool>();
83 addoninfo.
ctu =
false;
88 const auto it = obj.find(
"python");
89 if (it != obj.cend()) {
90 const auto& val = it->second;
92 if (!val.is<std::string>()) {
93 return "Loading " + fileName +
" failed. 'python' must be a string.";
95 addoninfo.
python = val.get<std::string>();
103 const auto it = obj.find(
"executable");
104 if (it != obj.cend()) {
105 const auto& val = it->second;
106 if (!val.is<std::string>())
107 return "Loading " + fileName +
" failed. 'executable' must be a string.";
108 const std::string e = val.get<std::string>();
116 const auto it = obj.find(
"script");
117 if (it == obj.cend())
118 return "Loading " + fileName +
" failed. 'script' is missing.";
120 const auto& val = it->second;
121 if (!val.is<std::string>())
122 return "Loading " + fileName +
" failed. 'script' must be a string.";
124 return addoninfo.
getAddonInfo(val.get<std::string>(), exename);
128 if (fileName[0] ==
'{') {
129 picojson::value json;
130 const std::string err = picojson::parse(json, fileName);
134 if (fileName.find(
'.') == std::string::npos)
140 return "Did not find addon " + fileName;
142 std::string::size_type pos1 =
scriptFile.rfind(
'/');
143 if (pos1 == std::string::npos)
147 std::string::size_type pos2 =
scriptFile.rfind(
'.');
149 pos2 = std::string::npos;
158 return "Failed to open addon " + fileName;
160 std::ifstream fin(fileName);
162 return "Failed to open " + fileName;
165 if (
name.find(
'/') != std::string::npos)
168 picojson::value json;
static std::string getFullPath(const std::string &fileName, const std::string &exename)
static std::string parseAddonInfo(AddonInfo &addoninfo, const picojson::value &json, const std::string &fileName, const std::string &exename)
static bool isFile(const std::string &path)
Checks if given path is a file.
static std::string fromNativeSeparators(std::string path)
Convert path to use internal path separators.
static std::string getPathFromFilename(const std::string &filename)
Lookup the path part from a filename (e.g., '/tmp/a.h' -> '/tmp/', 'a.h' -> '')
std::string getAddonInfo(const std::string &fileName, const std::string &exename)
bool endsWith(const std::string &str, char c)