simplified code in cat packs
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
35ccfdb799
commit
1e9a596908
@ -61,22 +61,12 @@ QString BasicCatPack::path()
|
|||||||
|
|
||||||
JsonCatPack::JsonCatPack(QFileInfo& manifestInfo) : BasicCatPack(manifestInfo.dir().dirName())
|
JsonCatPack::JsonCatPack(QFileInfo& manifestInfo) : BasicCatPack(manifestInfo.dir().dirName())
|
||||||
{
|
{
|
||||||
QString path = FS::PathCombine("catpacks", m_id);
|
QString path = manifestInfo.path();
|
||||||
|
|
||||||
if (!FS::ensureFolderPathExists(path)) {
|
|
||||||
themeWarningLog() << "couldn't create folder for catpack!";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (manifestInfo.exists() && manifestInfo.isFile()) {
|
|
||||||
try {
|
try {
|
||||||
auto doc = Json::requireDocument(manifestInfo.absoluteFilePath(), "CatPack JSON file");
|
auto doc = Json::requireDocument(manifestInfo.absoluteFilePath(), "CatPack JSON file");
|
||||||
const auto root = doc.object();
|
const auto root = doc.object();
|
||||||
m_name = Json::requireString(root, "name", "Catpack name");
|
m_name = Json::requireString(root, "name", "Catpack name");
|
||||||
auto id = Json::ensureString(root, "id", "", "Catpack ID");
|
m_defaultPath = FS::PathCombine(path, Json::requireString(root, "default", "Default Cat"));
|
||||||
if (!id.isEmpty())
|
|
||||||
m_id = id;
|
|
||||||
m_defaultPath = FS::PathCombine(path, Json::requireString(root, "default", "Deafult Cat"));
|
|
||||||
auto variants = Json::ensureArray(root, "variants", QJsonArray(), "Catpack Variants");
|
auto variants = Json::ensureArray(root, "variants", QJsonArray(), "Catpack Variants");
|
||||||
for (auto v : variants) {
|
for (auto v : variants) {
|
||||||
auto variant = Json::ensureObject(v, QJsonObject(), "Cat variant");
|
auto variant = Json::ensureObject(v, QJsonObject(), "Cat variant");
|
||||||
@ -86,12 +76,9 @@ JsonCatPack::JsonCatPack(QFileInfo& manifestInfo) : BasicCatPack(manifestInfo.di
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (const Exception& e) {
|
} catch (const Exception& e) {
|
||||||
themeWarningLog() << "Couldn't load catpack json: " << e.cause();
|
themeWarningLog() << "Couldn't load catpack json:" << e.cause();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
themeDebugLog() << "No catpack json present.";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString JsonCatPack::path()
|
QString JsonCatPack::path()
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
#include <QImageReader>
|
||||||
#include "ui/themes/BrightTheme.h"
|
#include "ui/themes/BrightTheme.h"
|
||||||
#include "ui/themes/CatPack.h"
|
#include "ui/themes/CatPack.h"
|
||||||
#include "ui/themes/CustomTheme.h"
|
#include "ui/themes/CustomTheme.h"
|
||||||
@ -179,13 +180,17 @@ void ThemeManager::initializeCatPacks()
|
|||||||
for (auto [id, name] : defaultCats) {
|
for (auto [id, name] : defaultCats) {
|
||||||
addCatPack(std::unique_ptr<CatPack>(new BasicCatPack(id, name)));
|
addCatPack(std::unique_ptr<CatPack>(new BasicCatPack(id, name)));
|
||||||
}
|
}
|
||||||
QDir catpacksDir("./catpacks/");
|
QDir catpacksDir("catpacks");
|
||||||
QString catpacksFolder = catpacksDir.absoluteFilePath("");
|
QString catpacksFolder = catpacksDir.absoluteFilePath("");
|
||||||
themeDebugLog() << "CatPacks Folder Path: " << catpacksFolder;
|
themeDebugLog() << "CatPacks Folder Path:" << catpacksFolder;
|
||||||
|
|
||||||
auto loadFiles = [this](QDir dir) {
|
QStringList supportedImageFormats;
|
||||||
|
for (auto format : QImageReader::supportedImageFormats()) {
|
||||||
|
supportedImageFormats.append("*." + format);
|
||||||
|
}
|
||||||
|
auto loadFiles = [this, supportedImageFormats](QDir dir) {
|
||||||
// Load image files directly
|
// Load image files directly
|
||||||
QDirIterator ImageFileIterator(dir.absoluteFilePath(""), { "*.png", "*.gif", "*.jpg", "*.apng", "*.jxl", "*.avif" }, QDir::Files);
|
QDirIterator ImageFileIterator(dir.absoluteFilePath(""), supportedImageFormats, QDir::Files);
|
||||||
while (ImageFileIterator.hasNext()) {
|
while (ImageFileIterator.hasNext()) {
|
||||||
QFile customCatFile(ImageFileIterator.next());
|
QFile customCatFile(ImageFileIterator.next());
|
||||||
QFileInfo customCatFileInfo(customCatFile);
|
QFileInfo customCatFileInfo(customCatFile);
|
||||||
@ -200,7 +205,7 @@ void ThemeManager::initializeCatPacks()
|
|||||||
while (directoryIterator.hasNext()) {
|
while (directoryIterator.hasNext()) {
|
||||||
QDir dir(directoryIterator.next());
|
QDir dir(directoryIterator.next());
|
||||||
QFileInfo manifest(dir.absoluteFilePath("catpack.json"));
|
QFileInfo manifest(dir.absoluteFilePath("catpack.json"));
|
||||||
if (manifest.exists()) {
|
if (manifest.isFile()) {
|
||||||
// Load background manifest
|
// Load background manifest
|
||||||
themeDebugLog() << "Loading background manifest from:" << manifest.absoluteFilePath();
|
themeDebugLog() << "Loading background manifest from:" << manifest.absoluteFilePath();
|
||||||
addCatPack(std::unique_ptr<CatPack>(new JsonCatPack(manifest)));
|
addCatPack(std::unique_ptr<CatPack>(new JsonCatPack(manifest)));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user