06-16-20, 11:07 PM
|
#10
|
A Firelord
Join Date: Mar 2008
Posts: 463
|
Originally Posted by Adapt
I wrote a small .net application to do it. Here is the meat of the code - not elegant, and specific to the addon I made, but does the job.
Use at your own risk, I take no responsibility.
Code:
private void Button_ParseFile(object sender, RoutedEventArgs e)
{
string fileToParse = SelectFile("Select file to parse", "lua", "lua files(*.lua) | *.lua");
if (fileToParse == null) return;
string[] lines = File.ReadAllLines(fileToParse);
// Regexes
Regex TotalXPRegex = new Regex(@"(\d+)");
Regex CreatureRegex = new Regex(@".* = ""(.+)""");
Regex MinimapZoneRegex = new Regex(@".* = ""(.+)""");
Regex ZoneRegex = new Regex(@".* = ""(.+)""");
Regex LevelRegex = new Regex(@"(\d+)");
Regex TimeStampRegex = new Regex(@".* = ""(.+)""");
Regex QuestOrCreature = new Regex(@".* = ""(.+)""");
Regex XPGainedRegex = new Regex(@"(\d+)");
Regex EndOfIndividualGainRegex = new Regex(@"-- \[\d+\]");
var records = new List<XPLogger> { };
var record = new XPLogger();
foreach (string line in lines)
{
if (line.Contains("[\"Total XP\"]"))
{
Match match = TotalXPRegex.Match(line);
record.TotalXP = Int16.Parse(match.Groups[1].Value);
continue;
}
if (line.Contains("[\"Creature\"]"))
{
Match match = CreatureRegex.Match(line);
record.Creature = match.Groups[1].Value;
continue;
}
if (line.Contains("[\"Minimap Zone\"]"))
{
Match match = MinimapZoneRegex.Match(line);
record.MinimapZone = match.Groups[1].Value;
continue;
}
if (line.Contains("[\"Zone\"]"))
{
Match match = ZoneRegex.Match(line);
record.Zone = match.Groups[1].Value;
continue;
}
if (line.Contains("[\"Level\"]"))
{
Match match = LevelRegex.Match(line);
record.Level = Int16.Parse(match.Groups[1].Value);
continue;
}
if (line.Contains("[\"Timestamp\"]"))
{
Match match = TimeStampRegex.Match(line);
record.TimeStamp = match.Groups[1].Value;
continue;
}
if (line.Contains("[\"Quest or Creature\"]"))
{
Match match = QuestOrCreature.Match(line);
record.QuestOrCreature = match.Groups[1].Value;
continue;
}
if (line.Contains("[\"XP Gained\"]"))
{
Match match = XPGainedRegex.Match(line);
record.XPGained = Int16.Parse(match.Groups[1].Value);
continue;
}
if (EndOfIndividualGainRegex.IsMatch(line))
{
records.Add(record);
record = new XPLogger();
}
}
string newFile = SaveFile("Select file to output", "csv", "csv files(*.csv) | *.csv");
if (newFile == null) return;
using (var writer = new StreamWriter(newFile))
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
{
csv.WriteRecords(records);
}
}
|
Thanks!!!!
|
|
|