diff --git a/Editor/AGS.Editor/Components/AudioComponent.cs b/Editor/AGS.Editor/Components/AudioComponent.cs index f41d18f31f..81dd3bf502 100644 --- a/Editor/AGS.Editor/Components/AudioComponent.cs +++ b/Editor/AGS.Editor/Components/AudioComponent.cs @@ -4,6 +4,7 @@ using System.Text; using System.Linq; using AGS.Types; +using System.Windows.Forms; namespace AGS.Editor.Components { @@ -13,6 +14,7 @@ class AudioComponent : BaseComponentWithFolders, IPr private const string COMPILED_AUDIO_FILENAME_PREFIX = "au"; private const string COMMAND_ADD_AUDIO = "AddAudioClipCmd"; private const string COMMAND_REIMPORT_ALL = "ReimportAllAudioClipCmd"; + private const string COMMAND_REPLACE_AUDIO_SOURCE_FOLDER = "ReplaceAudioClipSourceFolderCmd"; private const string COMMAND_PROPERTIES = "PropertiesAudioClip"; private const string COMMAND_RENAME = "RenameAudioClip"; private const string COMMAND_REIMPORT = "ReimportAudioClip"; @@ -114,6 +116,10 @@ protected override void ItemCommandClick(string controlID) { CommandForceReimportOfAllAudioClips(); } + else if (controlID == COMMAND_REPLACE_AUDIO_SOURCE_FOLDER) + { + CommandReplaceSourceFolderForAudioClips(); + } else if (controlID == COMMAND_RENAME) { _guiController.ProjectTree.BeginLabelEdit(this, _rightClickedID); @@ -508,7 +514,7 @@ private void UpdateScoreSound(IList allAudio) private void UpdateViewFrameSounds(IList allAudio, ViewFolder views) { - foreach (View view in views.Views) + foreach (AGS.Types.View view in views.Views) { foreach (ViewLoop loop in view.Loops) { @@ -702,6 +708,53 @@ public void ReplaceAudioClipSource(AudioClip clip) } } + private void CommandReplaceSourceFolderForAudioClips() + { + var allAudioClips = _agsEditor.CurrentGame.RootAudioClipFolder.AllItemsFlat; + string firstFoundSourceFile = null; + AudioClip foundClip = allAudioClips.Where(s => !string.IsNullOrEmpty(s.SourceFileName)).FirstOrDefault(); + if (foundClip != null) + firstFoundSourceFile = foundClip.SourceFileName; + + if (string.IsNullOrEmpty(firstFoundSourceFile)) + { + Factory.GUIController.ShowMessage("None of the audio clips has a source filename.", MessageBoxIcon.Warning); + return; + } + + string parentDir = Path.GetDirectoryName(firstFoundSourceFile); + var replaceDirs = ReplaceFolderDialog.Show("Replace audio clip(s) source path", + "Please choose which part of the parent path should be replaced and provide a replacement. Relative paths will be assumed relative to your game's project folder.", + parentDir, parentDir, Factory.AGSEditor.CurrentGame.DirectoryPath); + + if (replaceDirs == null || replaceDirs.Item1 == replaceDirs.Item2) + return; + + int itemCount = 0; + foreach (var clip in allAudioClips) + { + if (string.IsNullOrEmpty(clip.SourceFileName)) + continue; + + string newPath; + if (Utilities.ReplacePathBaseProjectRelative(clip.SourceFileName, replaceDirs.Item1, replaceDirs.Item2, out newPath)) + { + clip.SourceFileName = newPath; + itemCount++; + } + } + + if (itemCount > 0) + { + Factory.GUIController.ShowMessage($"{itemCount} audio clip(s) had their source paths updated.", MessageBoxIcon.Information); + Factory.GUIController.RefreshPropertyGrid(); + } + else + { + Factory.GUIController.ShowMessage($"No audio clips with the matching old paths found, no changes were made.", MessageBoxIcon.Information); + } + } + private void AddAudioClipToListIfFileNeedsToBeCopiedFromSource(AudioClip clip, PreCompileGameEventArgs evArgs, List filesToCopy, List fileNamesToUpdate) { string compiledFileName = clip.CacheFileName; @@ -909,6 +962,7 @@ protected override void AddNewItemCommandsToFolderContextMenu(string controlID, { menu.Add(new MenuCommand(COMMAND_ADD_AUDIO, "Add audio file(s)...", null)); menu.Add(new MenuCommand(COMMAND_REIMPORT_ALL, "Force reimport all file(s)", null)); + menu.Add(new MenuCommand(COMMAND_REPLACE_AUDIO_SOURCE_FOLDER, "Replace source paths for audio clips...", null)); } protected override void AddExtraCommandsToFolderContextMenu(string controlID, IList menu)