Fix audio file deletion: Correct path resolution for file deletion
Critical bug fix for audio deletion: Issue: - deleteSelectedAudio() was passing category and filename to deleteAudio() - deleteAudio() expects full file path as first parameter - This caused deletion attempts on directory paths like 'C:\Users\drew\webGame\background' - Result: ENOENT errors trying to delete directories instead of files Fix: - Look up full audio file path from storage before calling deleteAudio() - Handle both string and object audio storage formats - Pass correct audioPath parameter to deleteAudio(audioPath, category) - Enhanced removeAudioFromStorage() to handle both storage formats properly Changes: - deleteSelectedAudio(): Find full path from storage before deletion - removeAudioFromStorage(): Support both string paths and object formats - Proper error handling when audio file not found in storage - Maintains backward compatibility with different storage formats Now audio deletion works correctly: Finds correct file paths from storage Deletes actual audio files from disk Removes storage references properly No more ENOENT directory deletion errors
This commit is contained in:
parent
4e8e08c51e
commit
b4709e4f66
23
game.js
23
game.js
|
|
@ -2068,12 +2068,24 @@ ${usagePercent > 85 ? '⚠️ Storage getting full - consider deleting some imag
|
||||||
|
|
||||||
if (isDesktop && this.fileManager) {
|
if (isDesktop && this.fileManager) {
|
||||||
// Desktop mode - delete actual file
|
// Desktop mode - delete actual file
|
||||||
const success = await this.fileManager.deleteAudio(category, filename);
|
// Need to find the full audio file path from storage
|
||||||
|
const customAudio = this.dataManager.get('customAudio') || { background: [], ambient: [], effects: [] };
|
||||||
|
const audioFile = customAudio[category].find(audio =>
|
||||||
|
(typeof audio === 'string' && audio.includes(filename)) ||
|
||||||
|
(typeof audio === 'object' && (audio.filename === filename || audio.name === filename))
|
||||||
|
);
|
||||||
|
|
||||||
|
if (audioFile) {
|
||||||
|
const audioPath = typeof audioFile === 'string' ? audioFile : audioFile.path;
|
||||||
|
const success = await this.fileManager.deleteAudio(audioPath, category);
|
||||||
if (success) {
|
if (success) {
|
||||||
deletedCount++;
|
deletedCount++;
|
||||||
} else {
|
} else {
|
||||||
console.error(`Failed to delete audio file: ${filename}`);
|
console.error(`Failed to delete audio file: ${filename}`);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.error(`Audio file not found in storage: ${filename}`);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Web mode - remove from storage only
|
// Web mode - remove from storage only
|
||||||
this.removeAudioFromStorage(category, filename);
|
this.removeAudioFromStorage(category, filename);
|
||||||
|
|
@ -2091,7 +2103,14 @@ ${usagePercent > 85 ? '⚠️ Storage getting full - consider deleting some imag
|
||||||
removeAudioFromStorage(category, filename) {
|
removeAudioFromStorage(category, filename) {
|
||||||
const customAudio = this.dataManager.get('customAudio') || { background: [], ambient: [], effects: [] };
|
const customAudio = this.dataManager.get('customAudio') || { background: [], ambient: [], effects: [] };
|
||||||
if (customAudio[category]) {
|
if (customAudio[category]) {
|
||||||
customAudio[category] = customAudio[category].filter(audio => audio.filename !== filename);
|
customAudio[category] = customAudio[category].filter(audio => {
|
||||||
|
if (typeof audio === 'string') {
|
||||||
|
return !audio.includes(filename);
|
||||||
|
} else if (typeof audio === 'object') {
|
||||||
|
return audio.filename !== filename && audio.name !== filename;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
this.dataManager.set('customAudio', customAudio);
|
this.dataManager.set('customAudio', customAudio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue