Skip to content

Commit ec57822

Browse files
OmniTroidclaude
andcommitted
Fix getCachedPath to try file suffixes like resolveOrDownload
- getCachedPath now accepts suffixes parameter to try multiple extensions - Pass suffixes from get_real_path to getCachedPath for consistent lookup - Fixes issue where cached files with extensions weren't found Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 5a2274c commit ec57822

3 files changed

Lines changed: 22 additions & 14 deletions

File tree

src/path_functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ QString AOApplication::get_real_path(const VPath &vpath, const QStringList &suff
425425
// Check webcache if local file not found
426426
if (Options::getInstance().webcacheEnabled() && !m_serverdata.get_asset_url().isEmpty())
427427
{
428-
QString cached = m_webcache->getCachedPath(vpath.toQString());
428+
QString cached = m_webcache->getCachedPath(vpath.toQString(), suffixes);
429429
if (!cached.isEmpty())
430430
{
431431
asset_lookup_cache.insert(qHash(vpath), cached);

src/webcache.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ QString WebCache::cacheSubdir() const
8787
return subdir;
8888
}
8989

90-
QString WebCache::getCachedPath(const QString &relativePath) const
90+
QString WebCache::getCachedPath(const QString &relativePath, const QStringList &suffixes) const
9191
{
9292
if (relativePath.isEmpty())
9393
{
@@ -100,21 +100,28 @@ QString WebCache::getCachedPath(const QString &relativePath) const
100100
return QString();
101101
}
102102

103-
// Use lowercase path for cache lookup (no percent-encoding in local paths)
104-
QString lowerPath = lowercasePath(relativePath);
105-
QString localPath = cacheDir() + subdir + lowerPath;
106-
107-
if (!file_exists(localPath))
103+
// Try each suffix
104+
QStringList effectiveSuffixes = suffixes.isEmpty() ? QStringList{""} : suffixes;
105+
for (const QString &suffix : effectiveSuffixes)
108106
{
109-
return QString();
110-
}
107+
// Use lowercase path for cache lookup (no percent-encoding in local paths)
108+
QString lowerPath = lowercasePath(relativePath + suffix);
109+
QString localPath = cacheDir() + subdir + lowerPath;
111110

112-
if (isExpired(localPath))
113-
{
114-
return QString();
111+
if (!file_exists(localPath))
112+
{
113+
continue;
114+
}
115+
116+
if (isExpired(localPath))
117+
{
118+
continue;
119+
}
120+
121+
return localPath;
115122
}
116123

117-
return localPath;
124+
return QString();
118125
}
119126

120127
bool WebCache::isExpired(const QString &localPath) const

src/webcache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ class WebCache : public QObject
2323
/**
2424
* @brief Returns the cached file path if it exists and is not expired.
2525
* @param relativePath The virtual path relative to the base (e.g., "sounds/music/song.mp3")
26+
* @param suffixes List of file extensions to try (e.g., {".png", ".webp"})
2627
* @return The absolute path to the cached file, or empty string if not cached/expired.
2728
*/
28-
QString getCachedPath(const QString &relativePath) const;
29+
QString getCachedPath(const QString &relativePath, const QStringList &suffixes = {""}) const;
2930

3031
/**
3132
* @brief Check cache and initiate async download if file is missing or expired.

0 commit comments

Comments
 (0)