mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-08 12:24:09 +00:00
Compare commits
2 commits
ced6b41892
...
e10c65ae86
Author | SHA1 | Date | |
---|---|---|---|
e10c65ae86 | |||
75c6322ec6 |
|
@ -44,42 +44,42 @@ struct CFParser {
|
||||||
cf_parser *operator->() { return &cfp; }
|
cf_parser *operator->() { return &cfp; }
|
||||||
};
|
};
|
||||||
|
|
||||||
static OBSTheme *ParseThemeMeta(const QString &path)
|
static optional<OBSTheme> ParseThemeMeta(const QString &path)
|
||||||
{
|
{
|
||||||
QFile themeFile(path);
|
QFile themeFile(path);
|
||||||
if (!themeFile.open(QIODeviceBase::ReadOnly))
|
if (!themeFile.open(QIODeviceBase::ReadOnly))
|
||||||
return nullptr;
|
return nullopt;
|
||||||
|
|
||||||
OBSTheme *meta = nullptr;
|
OBSTheme meta;
|
||||||
const QByteArray data = themeFile.readAll();
|
const QByteArray data = themeFile.readAll();
|
||||||
CFParser cfp;
|
CFParser cfp;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!cf_parser_parse(cfp, data.constData(), QT_TO_UTF8(path)))
|
if (!cf_parser_parse(cfp, data.constData(), QT_TO_UTF8(path)))
|
||||||
return nullptr;
|
return nullopt;
|
||||||
|
|
||||||
if (cf_token_is(cfp, "@") || cf_go_to_token(cfp, "@", nullptr)) {
|
if (cf_token_is(cfp, "@") || cf_go_to_token(cfp, "@", nullptr)) {
|
||||||
while (cf_next_token(cfp)) {
|
while (cf_next_token(cfp)) {
|
||||||
if (cf_token_is(cfp, "OBSThemeMeta"))
|
if (cf_token_is(cfp, "OBSThemeMeta")) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (!cf_go_to_token(cfp, "@", nullptr))
|
if (!cf_go_to_token(cfp, "@", nullptr))
|
||||||
return nullptr;
|
return nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!cf_token_is(cfp, "OBSThemeMeta"))
|
||||||
|
return nullopt;
|
||||||
|
|
||||||
if (!cf_next_token(cfp))
|
if (!cf_next_token(cfp))
|
||||||
return nullptr;
|
return nullopt;
|
||||||
|
|
||||||
if (!cf_token_is(cfp, "{"))
|
if (!cf_token_is(cfp, "{"))
|
||||||
return nullptr;
|
return nullopt;
|
||||||
|
|
||||||
meta = new OBSTheme();
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (!cf_next_token(cfp)) {
|
if (!cf_next_token(cfp))
|
||||||
delete meta;
|
return nullopt;
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = cf_token_is_type(cfp, CFTOKEN_NAME, "name",
|
ret = cf_token_is_type(cfp, CFTOKEN_NAME, "name",
|
||||||
nullptr);
|
nullptr);
|
||||||
|
@ -93,10 +93,8 @@ static OBSTheme *ParseThemeMeta(const QString &path)
|
||||||
if (ret != PARSE_SUCCESS)
|
if (ret != PARSE_SUCCESS)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!cf_next_token(cfp)) {
|
if (!cf_next_token(cfp))
|
||||||
delete meta;
|
return nullopt;
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = cf_token_is_type(cfp, CFTOKEN_STRING, "value",
|
ret = cf_token_is_type(cfp, CFTOKEN_STRING, "value",
|
||||||
";");
|
";");
|
||||||
|
@ -109,39 +107,34 @@ static OBSTheme *ParseThemeMeta(const QString &path)
|
||||||
|
|
||||||
if (str) {
|
if (str) {
|
||||||
if (name == "dark")
|
if (name == "dark")
|
||||||
meta->isDark = strcmp(str, "true") == 0;
|
meta.isDark = strcmp(str, "true") == 0;
|
||||||
else if (name == "extends")
|
else if (name == "extends")
|
||||||
meta->extends = str;
|
meta.extends = str;
|
||||||
else if (name == "author")
|
else if (name == "author")
|
||||||
meta->author = str;
|
meta.author = str;
|
||||||
else if (name == "id")
|
else if (name == "id")
|
||||||
meta->id = str;
|
meta.id = str;
|
||||||
else if (name == "name")
|
else if (name == "name")
|
||||||
meta->name = str;
|
meta.name = str;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cf_go_to_token(cfp, ";", nullptr)) {
|
if (!cf_go_to_token(cfp, ";", nullptr))
|
||||||
delete meta;
|
return nullopt;
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (meta) {
|
auto filepath = filesystem::u8path(path.toStdString());
|
||||||
auto filepath = filesystem::u8path(path.toStdString());
|
meta.isBaseTheme = filepath.extension() == ".obt";
|
||||||
meta->isBaseTheme = filepath.extension() == ".obt";
|
meta.filename = filepath.stem();
|
||||||
meta->filename = filepath.stem();
|
|
||||||
|
|
||||||
if (meta->id.isEmpty() || meta->name.isEmpty() ||
|
if (meta.id.isEmpty() || meta.name.isEmpty() ||
|
||||||
(!meta->isBaseTheme && meta->extends.isEmpty())) {
|
(!meta.isBaseTheme && meta.extends.isEmpty())) {
|
||||||
/* Theme is invalid */
|
/* Theme is invalid */
|
||||||
delete meta;
|
return nullopt;
|
||||||
meta = nullptr;
|
} else {
|
||||||
} else {
|
meta.location = absolute(filepath);
|
||||||
meta->location = absolute(filepath);
|
meta.isHighContrast = path.endsWith(".oha");
|
||||||
meta->isHighContrast = path.endsWith(".oha");
|
meta.isVisible = !path.contains("System");
|
||||||
meta->isVisible = !path.contains("System");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return meta;
|
return meta;
|
||||||
|
@ -417,7 +410,6 @@ static vector<OBSThemeVariable> ParseThemeVariables(const char *themeData)
|
||||||
void OBSApp::FindThemes()
|
void OBSApp::FindThemes()
|
||||||
{
|
{
|
||||||
string themeDir;
|
string themeDir;
|
||||||
unique_ptr<OBSTheme> theme;
|
|
||||||
|
|
||||||
QStringList filters;
|
QStringList filters;
|
||||||
filters << "*.obt" // OBS Base Theme
|
filters << "*.obt" // OBS Base Theme
|
||||||
|
@ -428,7 +420,7 @@ void OBSApp::FindThemes()
|
||||||
GetDataFilePath("themes/", themeDir);
|
GetDataFilePath("themes/", themeDir);
|
||||||
QDirIterator it(QString::fromStdString(themeDir), filters, QDir::Files);
|
QDirIterator it(QString::fromStdString(themeDir), filters, QDir::Files);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
theme.reset(ParseThemeMeta(it.next()));
|
auto theme = ParseThemeMeta(it.next());
|
||||||
if (theme && !themes.contains(theme->id))
|
if (theme && !themes.contains(theme->id))
|
||||||
themes[theme->id] = std::move(*theme);
|
themes[theme->id] = std::move(*theme);
|
||||||
}
|
}
|
||||||
|
@ -440,7 +432,7 @@ void OBSApp::FindThemes()
|
||||||
QDir::Files);
|
QDir::Files);
|
||||||
|
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
theme.reset(ParseThemeMeta(it.next()));
|
auto theme = ParseThemeMeta(it.next());
|
||||||
if (theme && !themes.contains(theme->id))
|
if (theme && !themes.contains(theme->id))
|
||||||
themes[theme->id] = std::move(*theme);
|
themes[theme->id] = std::move(*theme);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue