aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/aoapplication.h4
-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
5 files changed, 40 insertions, 24 deletions
diff --git a/include/aoapplication.h b/include/aoapplication.h
index 0c61d7b5..24a09eca 100644
--- a/include/aoapplication.h
+++ b/include/aoapplication.h
@@ -167,6 +167,7 @@ public:
QString get_sfx(QString p_sfx, QString p_misc="", QString p_character="");
QString get_case_sensitive_path(QString p_file);
QString get_real_path(const VPath &vpath);
+ QString get_real_suffixed_path(const VPath &vpath, const QStringList &suffixes);
void invalidate_lookup_cache();
////// Functions for reading and writing files //////
@@ -355,9 +356,6 @@ public:
// Returns the sfx with p_identifier from courtroom_sounds.ini in the current theme path
QString get_court_sfx(QString p_identifier, QString p_misc="");
- // Find the correct suffix for a given file
- QString get_suffix(VPath file_to_check, QStringList suffixes);
-
// Figure out if we can opus this or if we should fall back to wav
QString get_sfx_suffix(VPath sound_to_check);
diff --git a/src/aobutton.cpp b/src/aobutton.cpp
index fb9da7d3..242fe79a 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 1613a7d1..456aee8a 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 b1a5e48e..f79f7bf8 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 c92287fb..9c463417 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