public static void LoadCSV(Statistic stats, bool overview = false, Tournament2 tournament = null) { string path, file, overviewList, line; string[] url, lines; int countOfLists; bool win = true; List <Statistic> statistics; List <string> lists, players, output; lists = new List <string>(); players = new List <string>(); statistics = new List <Statistic>(); Gtk.FileChooserDialog dlg = new Gtk.FileChooserDialog("Statistik laden", null, Gtk.FileChooserAction.Open, "Abbrechen", Gtk.ResponseType.Cancel, "Öffnen", Gtk.ResponseType.Ok); Gtk.FileFilter filter = new Gtk.FileFilter(); filter.Name = "TXT-Datei"; filter.AddPattern("*.txt"); int response = dlg.Run(); if (response == -5) { path = dlg.Filename; } else { return; } using (StreamReader sr = new StreamReader(path)) { file = sr.ReadToEnd(); } if (file.Contains('\n')) { lines = file.Split('\n'); for (int i = 0; i < lines.Length; i++) { if (lines[i] != "") { lines[i] = lines[i].Remove(lines[i].LastIndexOf('\r')); } } } else { lines = file.Split('\r'); } countOfLists = lines[1].Split('\t').Length - 1; statistics.Add(stats); for (int i = 1; i < countOfLists; i++) { statistics.Add(Update.LoadContents()); } for (int j = 1; j < lines.Length; j++) { if (lines[j] != "") { url = lines[j].Split('\t'); players.Add(url[0]); for (int i = 1; i <= countOfLists; i++) { if (url[i] != "") { if (url[i].StartsWith("\"") && url[i].EndsWith("\"")) { url[i] = url[i].Substring(url[i].IndexOf("\"") + 1, url[i].LastIndexOf("\"") - 1); } else if (url[i].StartsWith("\"")) { url[i] = url[i].Substring(url[i].IndexOf("\"") + 1); } else if (url[i].EndsWith("\"")) { url[i] = url[i].Substring(0, url[i].LastIndexOf("\"") - 2); } } if (url[i] == "") { overviewList = ""; } else { overviewList = statistics[i - 1].Parse(url[i], true, overview); } lists.Add(overviewList); //Aktuell nur für die erste Liste, da die Turnierverwaltung noch nicht //mit Escalation klar kommt. if (tournament != null && overviewList != "" && i == 1) { int trenner = overviewList.IndexOf(';'); int trenner2 = overviewList.IndexOf(';', trenner + 1); tournament.AddInfos(url[0], Int32.Parse(overviewList.Substring(trenner + 1, trenner2 - trenner - 1)), url[i]); } } } } if (countOfLists > 1) { MessageBox.Show("Es wurden mehrere Listen pro Spieler ermittelt.\nWähle einen Speicherort aus.\nAnschließend wird die erste Liste angezeigt."); Gtk.FileChooserDialog slg = new Gtk.FileChooserDialog("Listen speichern", null, Gtk.FileChooserAction.Save, "Abbrechen", Gtk.ResponseType.Cancel, "Speichern", Gtk.ResponseType.Ok); filter = new Gtk.FileFilter(); filter.Name = "TXM Statistik Datei"; filter.AddPattern("*.txmstats"); slg.AddFilter(filter); response = slg.Run(); if (response == -5) { path = slg.Filename; } else { return; } for (int i = 0; i < countOfLists; i++) { statistics[i].Path = path.Substring(0, path.LastIndexOf('.')) + " " + (i + 1) + path.Substring(path.LastIndexOf('.'), path.Length - path.LastIndexOf('.')); Serialize(statistics[i], true); } } if (overview) { MessageBox.Show("Gib bitte den Speicherort für die\nÜbersichtsliste(n) an."); Gtk.FileChooserDialog slg = new Gtk.FileChooserDialog("Listen speichern", null, Gtk.FileChooserAction.Save, "Abbrechen", Gtk.ResponseType.Cancel, "Speichern", Gtk.ResponseType.Ok); filter = new Gtk.FileFilter(); filter.Name = "CSV-Datei"; filter.AddPattern("*.csv"); slg.AddFilter(filter); response = slg.Run(); if (response == -5) { path = slg.Filename; } else { return; } output = new List <string>(); line = "Spieler;Fraktion;Punkte;Liste"; output.Add(line); for (int i = 0; i < players.Count; i++) { url = lines[i + 1].Split('\t'); line = players[i] + ";"; for (int j = 0; j < countOfLists; j++) { line += lists[i * countOfLists + j] + ";"; } output.Add(line); } using (System.IO.StreamWriter f = new System.IO.StreamWriter(path)) { foreach (string s in output) { f.WriteLine(s); } } if (countOfLists == 1) { path = path.Substring(0, path.LastIndexOf('.')) + "_statistik.csv"; Export(statistics[0], true, false, path); } else { for (int i = 0; i < countOfLists; i++) { string p = statistics[i].Path.Substring(0, path.LastIndexOf('.') + 2) + ".csv"; Export(statistics[i], true, false, p); } } } }