aboutsummaryrefslogtreecommitdiff
path: root/src/path_functions.cpp
diff options
context:
space:
mode:
authorCrystalwarrior <Varsash@Gmail.com>2022-07-26 00:54:11 +0300
committerGitHub <noreply@github.com>2022-07-26 00:54:11 +0300
commitf8c2b1a2f06d2c2f99fa9eaa7b2334524823aac5 (patch)
tree2c1895467a4c9eb681c99ac82d187b15c67f8567 /src/path_functions.cpp
parent0dac3cc2c017e8c785cb00c340ea37e050eb6366 (diff)
Part 2 of #713: merge get_real_suffixed_path into get_real_path (#717)
* Fix get_real_suffixed_path existing, causing the previous PR to not function on suffixed... anything Fix suffixes ignoring a case where a suffixed path is already provided, causing that pre-suffixed filepath to fail to find anything * Fix image paths being used as sound effects and vice versa Better check for sfx and image absolute paths which double-checks the absolute path we got is *actually a valid file format* Co-authored-by: stonedDiscord <Tukz@gmx.de> Co-authored-by: Salanto <62221668+Salanto@users.noreply.github.com>
Diffstat (limited to 'src/path_functions.cpp')
-rw-r--r--src/path_functions.cpp58
1 files changed, 12 insertions, 46 deletions
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();
}