From 98780ba603c5c76359c29210fec00efc192f55bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 28 Nov 2024 11:07:38 +0100 Subject: [PATCH] Theme: Avoid checking the ui_atlas multiple times --- Common/File/VFS/VFS.h | 7 +++++++ UI/Theme.cpp | 18 ++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Common/File/VFS/VFS.h b/Common/File/VFS/VFS.h index a3dc73e2e3..87ef02dffb 100644 --- a/Common/File/VFS/VFS.h +++ b/Common/File/VFS/VFS.h @@ -56,6 +56,7 @@ public: // Filter support is optional but nice to have virtual bool GetFileInfo(const char *path, File::FileInfo *info) = 0; + virtual std::string toString() const = 0; }; @@ -72,6 +73,12 @@ public: bool GetFileInfo(const char *filename, File::FileInfo *fileInfo); bool GetFileListing(const char *path, std::vector *listing, const char *filter = nullptr) override; + // Shortcut for cleaner code + bool Exists(const char *path) { + File::FileInfo info{}; + return GetFileInfo(path, &info); + } + private: struct VFSEntry { const char *prefix; diff --git a/UI/Theme.cpp b/UI/Theme.cpp index b8704ced91..f71cf13e08 100644 --- a/UI/Theme.cpp +++ b/UI/Theme.cpp @@ -140,14 +140,20 @@ static void LoadThemeInfo(const std::vector &directories) { std::string tmpPath; section.Get("UIAtlas", &tmpPath, ""); if (!tmpPath.empty()) { - tmpPath = (path / tmpPath).ToString(); - - File::FileInfo tmpInfo; - if (g_VFS.GetFileInfo((tmpPath + ".meta").c_str(), &tmpInfo) && g_VFS.GetFileInfo((tmpPath + ".zim").c_str(), &tmpInfo)) { - info.sUIAtlas = tmpPath; + if (tmpPath == "../ui_atlas") { + // Do nothing. + } else { + // WARNING: Note that the below appears to be entirely broken. ..-navigation doesn't work on zip VFS. + INFO_LOG(Log::System, "Checking %s", tmpPath.c_str()); + tmpPath = (path / tmpPath).ToString(); + if (g_VFS.Exists((tmpPath + ".meta").c_str()) && g_VFS.Exists((tmpPath + ".zim").c_str())) { + // INFO_LOG(Log::System, "%s exists", tmpPath.c_str()); + info.sUIAtlas = tmpPath; + } else { + INFO_LOG(Log::System, "%s.meta/zim doesn't exist, not overriding atlas", tmpPath.c_str()); + } } } - appendTheme(info); } }