public static void RenameAndRestructureReplays(ReplayType type, FolderStructureFormat format, String rootPath) { HashSet<String> versions = DatabaseHandler.GetDistinctWarcraft3ReplayAttributes("Version")[0]; FileHandler.CreateReplayFolderStructure(versions, format, rootPath); rootPath = Path.Combine(rootPath, "ReplayParser.NET"); if (format == FolderStructureFormat.Default) { //we have to re-parse all of the replays to get the associated information var result = ParserHandler.ParseWarcraft3Replays(DatabaseHandler.GetWarcraft3ReplayPaths().ToList()); List<String> oldPaths = new List<String>(result.Count); HashSet<String> newPaths = new HashSet<String>(); for (int i = 0; i < result.Count; i++) { StringBuilder sb = new StringBuilder(); foreach (var team in result[i].teams) { foreach (var player in team.Value) { sb.Append(player.Name); sb.Append("("); sb.Append(Warcraft3DataConverter.ConvertShortRace(player.RaceFlag)); sb.Append(") ").Append(","); } //removing the last comma sb.Remove(sb.Length - 2, 2); sb.Append(" v "); } sb.Remove(sb.Length - 3, 3); oldPaths.Add(result[i].Path); String path = Path.Combine(rootPath, String.Concat("1.", result[i].replayHeader.GameVersion)); path = Path.Combine(path, sb.ToString().Replace("|", "")); String proposedPath = String.Concat(path, ".w3g"); //duplicate handling int j = 1; while (newPaths.Contains(proposedPath)) proposedPath = String.Concat(path, j++, ".w3g"); newPaths.Add(proposedPath); } FileHandler.RenameFiles(oldPaths, newPaths.ToList()); DatabaseHandler.UpdateWarcraft3ReplayNames(oldPaths, newPaths.ToList()); } }
public static void CreateReplayFolderStructure(HashSet<String> versions, FolderStructureFormat format, String rootPath) { //simply separate by version number if (format == FolderStructureFormat.Default) { rootPath = Path.Combine(rootPath, "ReplayParser.NET"); Directory.CreateDirectory(rootPath); //we don't need to check if the folder already exists, if it //does, the function call will ignore it foreach (String version in versions) Directory.CreateDirectory(Path.Combine(rootPath, String.Concat("1.", version))); } //adding in gametype else if (format == FolderStructureFormat.Extended) { rootPath = Path.Combine(rootPath, "ReplayParser.NET"); Directory.CreateDirectory(rootPath); //we don't need to check if the folder already exists, if it //does, the function call will ignore it foreach (String version in versions) { String versionRoot = Path.Combine(rootPath, String.Concat("1.", version)); Directory.CreateDirectory(versionRoot); Directory.CreateDirectory(Path.Combine(versionRoot, "1v1")); Directory.CreateDirectory(Path.Combine(versionRoot, "2v2")); Directory.CreateDirectory(Path.Combine(versionRoot, "3v3")); Directory.CreateDirectory(Path.Combine(versionRoot, "4v4")); Directory.CreateDirectory(Path.Combine(versionRoot, "FFA")); Directory.CreateDirectory(Path.Combine(versionRoot, "Custom")); } } //invalid formats else { throw new ArgumentException(); } }