1 Commits

View File

@@ -215,16 +215,37 @@ class SoundThemeManager:
def getSoundPath(self, themeName, soundName):
"""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)
if not themePath:
themePaths = []
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
for ext in ['.wav', '.ogg', '.mp3', '.flac']:
soundPath = os.path.join(themePath, soundName + ext)
if os.path.isfile(soundPath):
return soundPath
for themePath in themePaths:
for ext in ['.wav', '.ogg', '.mp3', '.flac']:
soundPath = os.path.join(themePath, soundName + ext)
if os.path.isfile(soundPath):
return soundPath
return None
@@ -395,4 +416,3 @@ def getManager():
from . import cthulhu
_manager = SoundThemeManager(cthulhu.cthulhuApp)
return _manager