blob: 8767a48e19311277ca440baa8f5cb115b8b3b205 (
plain)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
// Copyright 2018 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "UICommon/ResourcePack/Manifest.h"
#include <picojson.h>
namespace ResourcePack
{
Manifest::Manifest(const std::string& json)
{
picojson::value out;
auto error = picojson::parse(out, json);
if (!error.empty())
{
m_error = "Failed to parse manifest.";
m_valid = false;
return;
}
// Required fields
picojson::value& name = out.get("name");
picojson::value& version = out.get("version");
picojson::value& id = out.get("id");
// Optional fields
picojson::value& authors = out.get("authors");
picojson::value& description = out.get("description");
picojson::value& website = out.get("website");
picojson::value& compressed = out.get("compressed");
if (!name.is<std::string>() || !id.is<std::string>() || !version.is<std::string>())
{
m_error = "Some objects have a bad type.";
m_valid = false;
return;
}
m_name = name.to_str();
m_version = version.to_str();
m_id = id.to_str();
if (authors.is<picojson::array>())
{
std::string author_list;
for (const auto& o : authors.get<picojson::array>())
{
author_list += o.to_str() + ", ";
}
if (!author_list.empty())
m_authors = author_list.substr(0, author_list.size() - 2);
}
if (description.is<std::string>())
m_description = description.to_str();
if (website.is<std::string>())
m_website = website.to_str();
if (compressed.is<bool>())
m_compressed = compressed.get<bool>();
}
bool Manifest::IsValid() const
{
return m_valid;
}
const std::string& Manifest::GetName() const
{
return m_name;
}
const std::string& Manifest::GetVersion() const
{
return m_version;
}
const std::string& Manifest::GetID() const
{
return m_id;
}
const std::string& Manifest::GetError() const
{
return m_error;
}
const std::optional<std::string>& Manifest::GetAuthors() const
{
return m_authors;
}
const std::optional<std::string>& Manifest::GetDescription() const
{
return m_description;
}
const std::optional<std::string>& Manifest::GetWebsite() const
{
return m_website;
}
bool Manifest::IsCompressed() const
{
return m_compressed;
}
} // namespace ResourcePack
|