aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/courtroom.cpp17
-rw-r--r--src/path_functions.cpp58
-rw-r--r--src/text_file_functions.cpp26
3 files changed, 37 insertions, 64 deletions
diff --git a/src/courtroom.cpp b/src/courtroom.cpp
index 1884c7c8..fdb16132 100644
--- a/src/courtroom.cpp
+++ b/src/courtroom.cpp
@@ -4695,22 +4695,9 @@ void Courtroom::set_effects_dropdown()
ui_effects_dropdown->show();
ui_effects_dropdown->addItems(effectslist);
- // ICON-MAKING HELL
- QString p_effect = ao_app->read_char_ini(current_char, "effects", "Options");
- VPath custom_path("misc/" + p_effect + "/icons/");
- VPath theme_path = ao_app->get_theme_path("effects/icons/");
- VPath default_path = ao_app->get_theme_path("effects/icons/", "default");
+ // Make the icons
for (int i = 0; i < ui_effects_dropdown->count(); ++i) {
- VPath entry = VPath(ui_effects_dropdown->itemText(i));
- QString iconpath = ao_app->get_image_suffix(custom_path + entry);
- if (!file_exists(iconpath)) {
- iconpath = ao_app->get_image_suffix(theme_path + entry);
- if (!file_exists(iconpath)) {
- iconpath = ao_app->get_image_suffix(default_path + entry);
- if (!file_exists(iconpath))
- continue;
- }
- }
+ QString iconpath = ao_app->get_effect("icons/" + ui_effects_dropdown->itemText(i), current_char, "");
ui_effects_dropdown->setItemIcon(i, QIcon(iconpath));
}
diff --git a/src/path_functions.cpp b/src/path_functions.cpp
index 4e031d8f..45920d50 100644
--- a/src/path_functions.cpp
+++ b/src/path_functions.cpp
@@ -334,11 +334,15 @@ QString AOApplication::get_case_sensitive_path(QString p_file)
#endif
}
-QString AOApplication::get_real_path(const VPath &vpath) {
+QString AOApplication::get_real_path(const VPath &vpath,
+ const QStringList &suffixes) {
// Try cache first
QString phys_path = asset_lookup_cache.value(qHash(vpath));
if (!phys_path.isEmpty() && exists(phys_path)) {
- return phys_path;
+ for (const QString &suffix : suffixes) { // make sure cached asset is the right type
+ if (phys_path.endsWith(suffix, Qt::CaseInsensitive))
+ return phys_path;
+ }
}
// Cache miss; try all known mount paths
@@ -355,50 +359,6 @@ QString AOApplication::get_real_path(const VPath &vpath) {
// content 1
// base
for (const QString &base : bases) {
- QDir baseDir(base);
- QString path = baseDir.absoluteFilePath(vpath.toQString());
- if (!path.startsWith(baseDir.absolutePath())) {
- qWarning() << "invalid path" << path << "(path is outside vfs)";
- break;
- }
- path = get_case_sensitive_path(path);
- if (exists(path)) {
- asset_lookup_cache.insert(qHash(vpath), path);
- unsigned int cache_size = asset_lookup_cache.size();
- if (is_power_2(cache_size))
- qDebug() << "lookup cache has reached" << cache_size << "entries";
- return path;
- }
- }
-
- // Not found in mount paths; check if the file is remote
- QString remotePath = vpath.toQString();
- if (remotePath.startsWith("http:") || remotePath.startsWith("https:")) {
- return remotePath;
- }
-
- // File or directory not found
- 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(qHash(vpath));
- if (!phys_path.isEmpty() && exists(phys_path)) {
- for (const QString &suffix : suffixes) { // make sure cached asset is the right type
- if (phys_path.endsWith(suffix, Qt::CaseInsensitive))
- 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);
QString path = baseDir.absoluteFilePath(vpath.toQString() + suffix);
@@ -417,6 +377,12 @@ QString AOApplication::get_real_suffixed_path(const VPath &vpath,
}
}
+ // Not found in mount paths; check if the file is remote
+ QString remotePath = vpath.toQString();
+ if (remotePath.startsWith("http:") || remotePath.startsWith("https:")) {
+ return remotePath;
+ }
+
// File or directory not found
return QString();
}
diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp
index dc95dc34..ee6db6b9 100644
--- a/src/text_file_functions.cpp
+++ b/src/text_file_functions.cpp
@@ -544,8 +544,18 @@ QString AOApplication::get_court_sfx(QString p_identifier, QString p_misc)
QString AOApplication::get_sfx_suffix(VPath sound_to_check)
{
- return get_real_suffixed_path(sound_to_check,
- {".opus", ".ogg", ".mp3", ".wav", ".mid", ".midi", ".xm", ".it", ".s3m", ".mod", ".mtm", ".umx" });
+ QStringList suffixes = {".opus", ".ogg", ".mp3", ".wav", ".mid", ".midi", ".xm", ".it", ".s3m", ".mod", ".mtm", ".umx" };
+ // Check if we were provided a direct filepath with a suffix already
+ QString path = sound_to_check.toQString();
+ // Loop through our suffixes
+ for (const QString &suffix : suffixes) {
+ // If our VPath ends with a valid suffix
+ if (path.endsWith(suffix, Qt::CaseInsensitive))
+ // Return that as the path
+ return get_real_path(sound_to_check);
+ }
+ // Otherwise, ignore the provided suffix and check our own
+ return get_real_path(sound_to_check, suffixes);
}
QString AOApplication::get_image_suffix(VPath path_to_check, bool static_image)
@@ -556,7 +566,17 @@ QString AOApplication::get_image_suffix(VPath path_to_check, bool static_image)
}
suffixes.append(".png");
- return get_real_suffixed_path(path_to_check, suffixes);
+ // Check if we were provided a direct filepath with a suffix already
+ QString path = path_to_check.toQString();
+ // Loop through our suffixes
+ for (const QString &suffix : suffixes) {
+ // If our VPath ends with a valid suffix
+ if (path.endsWith(suffix, Qt::CaseInsensitive))
+ // Return that as the path
+ return get_real_path(path_to_check);
+ }
+ // Otherwise, ignore the provided suffix and check our own
+ return get_real_path(path_to_check, suffixes);
}
// returns whatever is to the right of "search_line =" within target_tag and