aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/aobutton.cpp9
-rw-r--r--src/debug_functions.cpp1
-rw-r--r--src/path_functions.cpp33
-rw-r--r--src/text_file_functions.cpp17
4 files changed, 39 insertions, 21 deletions
diff --git a/src/aobutton.cpp b/src/aobutton.cpp
index fb9da7d..242fe79 100644
--- a/src/aobutton.cpp
+++ b/src/aobutton.cpp
@@ -20,13 +20,8 @@ void AOButton::set_image(QString p_path, QString p_misc)
{
movie->stop();
QString p_image;
- // Check if the user wants animated themes
- if (ao_app->get_animated_theme())
- // We want an animated image
- p_image = ao_app->get_image(p_path, ao_app->current_theme, ao_app->get_subtheme(), ao_app->default_theme, p_misc);
- else
- // Grab a static variant of the image
- p_image = ao_app->get_image_path(ao_app->get_asset_paths(p_path, ao_app->current_theme, ao_app->get_subtheme(), ao_app->default_theme, p_misc), true);
+ p_image = ao_app->get_image(p_path, ao_app->current_theme, ao_app->get_subtheme(),
+ ao_app->default_theme, p_misc, "", "", !ao_app->get_animated_theme());
if (p_image.isEmpty()) {
this->setIcon(QIcon());
this->setIconSize(this->size());
diff --git a/src/debug_functions.cpp b/src/debug_functions.cpp
index 1613a7d..456aee8 100644
--- a/src/debug_functions.cpp
+++ b/src/debug_functions.cpp
@@ -1,4 +1,5 @@
#include <QCoreApplication>
+#include <QElapsedTimer>
#include <QMessageBox>
#include <QTimer>
#include <functional>
diff --git a/src/path_functions.cpp b/src/path_functions.cpp
index b1a5e48..f79f7bf 100644
--- a/src/path_functions.cpp
+++ b/src/path_functions.cpp
@@ -246,6 +246,39 @@ QString AOApplication::get_real_path(const VPath &vpath) {
return QString();
}
+// Special case of get_real_path where multiple suffixes need to be tried
+// on each mount path.
+QString AOApplication::get_real_suffixed_path(const VPath &vpath,
+ const QStringList &suffixes) {
+ // Try cache first
+ QString phys_path = asset_lookup_cache.value(vpath);
+ if (!phys_path.isEmpty() && exists(phys_path)) {
+ return phys_path;
+ }
+
+ // Cache miss; try each suffix on all known mount paths
+ QStringList bases = get_mount_paths();
+ bases.push_front(get_base_path());
+
+ for (const QString &base : bases) {
+ for (const QString &suffix : suffixes) {
+ QDir baseDir(base);
+ const QString path = baseDir.absoluteFilePath(vpath.toQString() + suffix);
+ if (!path.startsWith(baseDir.absolutePath())) {
+ qWarning() << "invalid path" << path << "(path is outside vfs)";
+ break;
+ }
+ if (exists(get_case_sensitive_path(path))) {
+ asset_lookup_cache.insert(vpath, path);
+ return path;
+ }
+ }
+ }
+
+ // File or directory not found
+ return QString();
+}
+
void AOApplication::invalidate_lookup_cache() {
asset_lookup_cache.clear();
}
diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp
index c92287f..9c46341 100644
--- a/src/text_file_functions.cpp
+++ b/src/text_file_functions.cpp
@@ -495,32 +495,21 @@ QString AOApplication::get_court_sfx(QString p_identifier, QString p_misc)
return "";
}
-QString AOApplication::get_suffix(VPath path_to_check, QStringList suffixes) {
- for (const QString &suffix : suffixes) {
- QString path = get_real_path(VPath(path_to_check.toQString() + suffix));
- if (!path.isEmpty())
- return path;
- }
-
- return QString();
-}
-
QString AOApplication::get_sfx_suffix(VPath sound_to_check)
{
- return get_suffix(sound_to_check, { "", ".opus", ".ogg", ".mp3", ".wav" });
+ return get_real_suffixed_path(sound_to_check,
+ { "", ".opus", ".ogg", ".mp3", ".wav" });
}
QString AOApplication::get_image_suffix(VPath path_to_check, bool static_image)
{
QStringList suffixes { "" };
- // A better method would to actually use AOImageReader and see if these images have more than 1 frame.
- // However, that might not be performant.
if (!static_image) {
suffixes.append({ ".webp", ".apng", ".gif" });
}
suffixes.append(".png");
- return get_suffix(path_to_check, suffixes);
+ return get_real_suffixed_path(path_to_check, suffixes);
}
// returns whatever is to the right of "search_line =" within target_tag and