public static int GetIndexFromFilename(string filename) { var match = Regex.Match(filename, "^(normal|soft|drum)-(hit(normal|whistle|finish|clap)|slidertick|sliderslide)"); var remainder = filename.Substring(match.Index + match.Length); int index = 0; if (!string.IsNullOrEmpty(remainder)) { FileFormatHelper.TryParseInt(remainder, out index); } return(index); }
public List <CustomIndex> GetCustomIndices(SampleGeneratingArgsComparer comparer = null) { if (comparer == null) { comparer = new SampleGeneratingArgsComparer(); } var customIndices = new Dictionary <int, CustomIndex>(); foreach (var kvp in this) { var name = Path.GetFileNameWithoutExtension(kvp.Key); if (name == null) { continue; } var match = Regex.Match(name, "^(normal|soft|drum)-hit(normal|whistle|finish|clap)"); if (!match.Success) { continue; } var hitsound = match.Value; var remainder = name.Substring(match.Index + match.Length); int index = 1; if (!string.IsNullOrEmpty(remainder)) { if (!FileFormatHelper.TryParseInt(remainder, out index)) { continue; } } if (customIndices.ContainsKey(index)) { customIndices[index].Samples[hitsound] = new HashSet <SampleGeneratingArgs>(kvp.Value); } else { var ci = new CustomIndex(index, comparer); customIndices.Add(index, ci); ci.Samples[hitsound] = new HashSet <SampleGeneratingArgs>(kvp.Value, comparer); } } return(customIndices.Values.ToList()); }
private static string MergeMapsets(MapsetMergerVm arg, BackgroundWorker worker, DoWorkEventArgs _) { int mapsetsMerged = 0; int indexStart = 1; ResolveDuplicateNames(arg.Mapsets); var usedNames = new HashSet <string>(); foreach (var mapset in arg.Mapsets) { var subf = mapset.Name; var prefix = mapset.Name + " - "; var beatmaps = LoadBeatmaps(mapset); var storyboards = LoadStoryboards(mapset); // All hitsound indices in the beatmaps. Old index to new index var indices = new Dictionary <int, int>(); // All hitsound files with custom indices var usedHsFiles = new HashSet <string>(); // All explicitly referenced audio files like filename hs, SB samples var usedOtherHsFiles = new HashSet <string>(); // All explicitly referenced image files like storyboard files, background var usedImageFiles = new HashSet <string>(); // All explicitly referenced video files var usedVideoFiles = new HashSet <string>(); // We have to ignore files which are not possible to reference in a distinguishing way // such as beatmap skin files and the spinnerspin and spinnerbonus files. StoryBoard sharedSb = null; if (arg.MoveSbToBeatmap) { sharedSb = storyboards.FirstOrDefault()?.Item2; if (sharedSb != null) { GetUsedFilesAndUpdateReferences(sharedSb, subf, usedOtherHsFiles, usedImageFiles, usedVideoFiles); } } else { foreach (var storyboardTuple in storyboards) { var storyboard = storyboardTuple.Item2; GetUsedFilesAndUpdateReferences(storyboard, subf, usedOtherHsFiles, usedImageFiles, usedVideoFiles); // Save storyboard in new location with unique filename Editor.SaveFile(Path.Combine(arg.ExportPath, prefix + Path.GetFileName(storyboardTuple.Item1)), storyboard.GetLines()); } } // Find all used files and change references foreach (var beatmapTuple in beatmaps) { var beatmap = beatmapTuple.Item2; GetUsedFilesAndUpdateReferences(beatmap, subf, ref indexStart, indices, usedHsFiles, usedOtherHsFiles, usedImageFiles, usedVideoFiles); if (sharedSb != null) { beatmap.StoryBoard.StoryboardLayerBackground = sharedSb.StoryboardLayerBackground; beatmap.StoryBoard.StoryboardLayerForeground = sharedSb.StoryboardLayerForeground; beatmap.StoryBoard.StoryboardLayerFail = sharedSb.StoryboardLayerFail; beatmap.StoryBoard.StoryboardLayerPass = sharedSb.StoryboardLayerPass; beatmap.StoryBoard.StoryboardLayerOverlay = sharedSb.StoryboardLayerOverlay; beatmap.StoryBoard.StoryboardSoundSamples = sharedSb.StoryboardSoundSamples; } // Save beatmap in new location with unique diffname var diffname = beatmap.Metadata["Version"].Value; if (usedNames.Contains(diffname)) { diffname = prefix + diffname; } usedNames.Add(diffname); beatmap.Metadata["Version"].Value = diffname; Editor.SaveFile(Path.Combine(arg.ExportPath, beatmap.GetFileName()), beatmap.GetLines()); } // Save assets in new location foreach (var filename in usedHsFiles) { var filepath = FindAssetFile(filename, mapset.Path, AudioExtensions); if (filepath == null) { continue; } var ext = Path.GetExtension(filepath); var extLess = Path.GetFileNameWithoutExtension(filepath); var match = Regex.Match(extLess, "^(normal|soft|drum)-(hit(normal|whistle|finish|clap)|slidertick|sliderslide)"); var remainder = extLess.Substring(match.Index + match.Length); int index = 1; if (!string.IsNullOrWhiteSpace(remainder) && !FileFormatHelper.TryParseInt(remainder, out index)) { continue; } var newFilename = indices[index] == 1 ? extLess.Substring(0, match.Length) + ext : extLess.Substring(0, match.Length) + indices[index] + ext; var newFilepath = Path.Combine(arg.ExportPath, newFilename); Directory.CreateDirectory(Path.GetDirectoryName(newFilepath)); File.Copy(filepath, newFilepath, true); } foreach (var filename in usedOtherHsFiles) { SaveAsset(filename, mapset.Path, subf, arg.ExportPath, AudioExtensions2); } foreach (var filename in usedImageFiles) { SaveAsset(filename, mapset.Path, subf, arg.ExportPath, ImageExtensions); } foreach (var filename in usedVideoFiles) { SaveAsset(filename, mapset.Path, subf, arg.ExportPath, VideoExtensions, true); } UpdateProgressBar(worker, ++mapsetsMerged * 100 / arg.Mapsets.Count); } // Make an accurate message var message = $"Successfully merged {mapsetsMerged} {(mapsetsMerged == 1 ? "mapset" : "mapsets")}!"; return(message); }