forked from ascendedguard/sc2replay-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Renaming replay files
ascendedguard edited this page Mar 8, 2011
·
3 revisions
The following example shows how to read in a replay and loop through the player names in order to properly rename the file. See below for example output, project setup, and potential issues with this program.
An example of the program output is renaming "exampleFile.SC2replay" into "Trouble vs Ascend (ZvZ).SC2Replay"
using System.IO;
using System.Text;
namespace Starcraft2.ReplayParser.Examples.Renamer
{
class Program
{
static void Main()
{
const string inputFile = @"C:\Users\Will\Documents\exampleFile.SC2replay";
Replay replay = Replay.Parse(inputFile);
string replayFolder = Path.GetDirectoryName(inputFile);
string newFilename = Path.Combine(replayFolder, GenerateReplayName(replay));
File.Move(inputFile, newFilename);
}
public static string GenerateReplayName(Replay replay)
{
var playerNames = new StringBuilder();
var races = new StringBuilder();
int team = replay.Players[0].Team;
foreach (PlayerDetails player in replay.Players)
{
if (player.Team != team)
{
// We've switched to another team.
team = player.Team;
playerNames.Append("vs ");
races.Append("v");
}
playerNames.Append(player.Name);
playerNames.Append(" ");
races.Append(player.Race[0]);
}
return string.Format("{0}({1}).SC2Replay", playerNames, races);
}
}
}
Example Output: An example file, "exampleFile.SC2replay", is renamed into "Trouble vs Ascend (ZvZ).SC2Replay"
Setup: To compile the application, a reference to Starcraft2.ReplayParser.dll was added with it's DLL requirement, MpqLib.dll, added to the same directory. Only Starcraft2.ReplayParser.dll needs to be referenced, it's dependency should be copied automatically.