Look for missing sound files if not found in 1 directory e.g. if not found in ~/.local look in system themes.

This commit is contained in:
Storm Dragon
2026-02-07 22:40:21 -05:00
parent c8c1922060
commit 13976b7235

View File

@@ -215,16 +215,37 @@ class SoundThemeManager:
def getSoundPath(self, themeName, soundName): def getSoundPath(self, themeName, soundName):
"""Get path to a specific sound file. """Get path to a specific sound file.
Checks for common audio file extensions: .wav, .ogg, .mp3, .flac Checks for common audio file extensions: .wav, .ogg, .mp3, .flac.
User themes are checked first, then system themes as fallback so
partial user themes can inherit missing sounds.
""" """
themePath = self.getThemePath(themeName) themePaths = []
if not themePath:
userPath = os.path.join(self.getUserSoundsDir(), themeName)
if os.path.isdir(userPath):
themePaths.append(userPath)
systemPath = os.path.join(self.getSystemSoundsDir(), themeName)
if os.path.isdir(systemPath):
themePaths.append(systemPath)
fallbackDirs = [
'/usr/share/cthulhu/sounds',
'/usr/local/share/cthulhu/sounds',
]
for fallbackDir in fallbackDirs:
fallbackPath = os.path.join(fallbackDir, themeName)
if os.path.isdir(fallbackPath) and fallbackPath not in themePaths:
themePaths.append(fallbackPath)
if not themePaths:
return None return None
for ext in ['.wav', '.ogg', '.mp3', '.flac']: for themePath in themePaths:
soundPath = os.path.join(themePath, soundName + ext) for ext in ['.wav', '.ogg', '.mp3', '.flac']:
if os.path.isfile(soundPath): soundPath = os.path.join(themePath, soundName + ext)
return soundPath if os.path.isfile(soundPath):
return soundPath
return None return None
@@ -395,4 +416,3 @@ def getManager():
from . import cthulhu from . import cthulhu
_manager = SoundThemeManager(cthulhu.cthulhuApp) _manager = SoundThemeManager(cthulhu.cthulhuApp)
return _manager return _manager