private void ParseAttemptHistory(Version version, XmlElement parent, IRun run) { if (version >= new Version(1, 5, 0)) { var attemptHistory = parent["AttemptHistory"]; foreach (var attemptNode in attemptHistory.GetElementsByTagName("Attempt")) { var attempt = Attempt.ParseXml(attemptNode as XmlElement); run.AttemptHistory.Add(attempt); } } else if (version >= new Version(1, 4, 1)) { var runHistory = parent["RunHistory"]; foreach (var runHistoryNode in runHistory.GetElementsByTagName("Time")) { var indexedTime = IndexedTimeHelper.ParseXml(runHistoryNode as XmlElement); var attempt = new Attempt(indexedTime.Index, indexedTime.Time, null, null); run.AttemptHistory.Add(attempt); } } else { var runHistory = parent["RunHistory"]; foreach (var runHistoryNode in runHistory.GetElementsByTagName("Time")) { var indexedTime = IndexedTimeHelper.ParseXmlOld(runHistoryNode as XmlElement); var attempt = new Attempt(indexedTime.Index, indexedTime.Time, null, null); run.AttemptHistory.Add(attempt); } } }
public IRun Create(IComparisonGeneratorsFactory factory) { var document = new XmlDocument(); document.Load(Stream); var run = new Run(factory); var parent = document["Run"]; var version = parent.HasAttribute("version") ? Version.Parse(parent.Attributes["version"].Value) : new Version(1, 0, 0, 0); run.GameIcon = GetImageFromElement(parent["GameIcon"]); run.GameName = parent["GameName"].InnerText; run.CategoryName = parent["CategoryName"].InnerText; run.Offset = TimeSpan.Parse(parent["Offset"].InnerText); run.AttemptCount = Int32.Parse(parent["AttemptCount"].InnerText); var runHistory = parent["RunHistory"]; foreach (var runHistoryNode in runHistory.GetElementsByTagName("Time")) { run.RunHistory.Add(version >= new Version(1, 4, 1) ? IndexedTimeHelper.ParseXml(runHistoryNode as XmlElement) : IndexedTimeHelper.ParseXmlOld(runHistoryNode as XmlElement)); } var segmentsNode = parent["Segments"]; foreach (var segmentNode in segmentsNode.GetElementsByTagName("Segment")) { var segmentElement = segmentNode as XmlElement; var nameElement = segmentElement["Name"]; var split = new Segment(nameElement.InnerText); var iconElement = segmentElement["Icon"]; split.Icon = GetImageFromElement(iconElement); if (version >= new Version(1, 3)) { var splitTimes = segmentElement["SplitTimes"]; foreach (var comparisonNode in splitTimes.GetElementsByTagName("SplitTime")) { var comparisonElement = comparisonNode as XmlElement; var comparisonName = comparisonElement.Attributes["name"].InnerText; if (comparisonElement.InnerText.Length > 0) { split.Comparisons[comparisonName] = version >= new Version(1, 4, 1) ? Time.FromXml(comparisonElement) : Time.ParseText(comparisonElement.InnerText); } if (!run.CustomComparisons.Contains(comparisonName)) { run.CustomComparisons.Add(comparisonName); } } } else { var pbSplit = segmentElement["PersonalBestSplitTime"]; if (pbSplit.InnerText.Length > 0) { split.Comparisons[Run.PersonalBestComparisonName] = version >= new Version(1, 4, 1) ? Time.FromXml(pbSplit) : Time.ParseText(pbSplit.InnerText); } } var goldSplit = segmentElement["BestSegmentTime"]; if (goldSplit.InnerText.Length > 0) { split.BestSegmentTime = version >= new Version(1, 4, 1) ? Time.FromXml(goldSplit) : Time.ParseText(goldSplit.InnerText); } var history = segmentElement["SegmentHistory"]; foreach (var historyNode in history.GetElementsByTagName("Time")) { split.SegmentHistory.Add(version >= new Version(1, 4, 1) ? IndexedTimeHelper.ParseXml(historyNode as XmlElement) : IndexedTimeHelper.ParseXmlOld(historyNode as XmlElement)); } run.Add(split); } if (version >= new Version(1, 4, 2)) { run.AutoSplitterSettings = parent["AutoSplitterSettings"]; var gameName = document.CreateAttribute("gameName"); gameName.Value = run.GameName; run.AutoSplitterSettings.Attributes.Append(gameName); } if (!String.IsNullOrEmpty(FilePath)) { run.FilePath = FilePath; } return(run); }
public IRun Create(IComparisonGeneratorsFactory factory) { var document = new XmlDocument(); document.Load(Stream); var run = new Run(factory); var parent = document["Run"]; var version = SettingsHelper.ParseAttributeVersion(parent); if (version >= new Version(1, 6)) { var metadata = parent["Metadata"]; run.Metadata.RunID = metadata["Run"].GetAttribute("id"); run.Metadata.PlatformName = metadata["Platform"].InnerText; run.Metadata.UsesEmulator = bool.Parse(metadata["Platform"].GetAttribute("usesEmulator")); run.Metadata.RegionName = metadata["Region"].InnerText; foreach (var variableNode in metadata["Variables"].ChildNodes.OfType <XmlElement>()) { run.Metadata.VariableValueNames.Add(variableNode.GetAttribute("name"), variableNode.InnerText); } } run.GameIcon = SettingsHelper.GetImageFromElement(parent["GameIcon"]); run.GameName = SettingsHelper.ParseString(parent["GameName"]); run.CategoryName = SettingsHelper.ParseString(parent["CategoryName"]); run.Offset = SettingsHelper.ParseTimeSpan(parent["Offset"]); run.AttemptCount = SettingsHelper.ParseInt(parent["AttemptCount"]); ParseAttemptHistory(version, parent, run); var segmentsNode = parent["Segments"]; foreach (var segmentNode in segmentsNode.GetElementsByTagName("Segment")) { var segmentElement = segmentNode as XmlElement; var split = new Segment(SettingsHelper.ParseString(segmentElement["Name"])); split.Icon = SettingsHelper.GetImageFromElement(segmentElement["Icon"]); if (version >= new Version(1, 3)) { var splitTimes = segmentElement["SplitTimes"]; foreach (var comparisonNode in splitTimes.GetElementsByTagName("SplitTime")) { var comparisonElement = comparisonNode as XmlElement; var comparisonName = comparisonElement.GetAttribute("name"); if (comparisonElement.InnerText.Length > 0) { split.Comparisons[comparisonName] = version >= new Version(1, 4, 1) ? Time.FromXml(comparisonElement) : Time.ParseText(comparisonElement.InnerText); } if (!run.CustomComparisons.Contains(comparisonName)) { run.CustomComparisons.Add(comparisonName); } } } else { var pbSplit = segmentElement["PersonalBestSplitTime"]; if (pbSplit.InnerText.Length > 0) { split.Comparisons[Run.PersonalBestComparisonName] = version >= new Version(1, 4, 1) ? Time.FromXml(pbSplit) : Time.ParseText(pbSplit.InnerText); } } var goldSplit = segmentElement["BestSegmentTime"]; if (goldSplit.InnerText.Length > 0) { split.BestSegmentTime = version >= new Version(1, 4, 1) ? Time.FromXml(goldSplit) : Time.ParseText(goldSplit.InnerText); } var history = segmentElement["SegmentHistory"]; foreach (var historyNode in history.GetElementsByTagName("Time")) { split.SegmentHistory.Add(version >= new Version(1, 4, 1) ? IndexedTimeHelper.ParseXml(historyNode as XmlElement) : IndexedTimeHelper.ParseXmlOld(historyNode as XmlElement)); } run.Add(split); } if (version >= new Version(1, 4, 2)) { var newXmlDoc = new XmlDocument(); newXmlDoc.InnerXml = parent["AutoSplitterSettings"].OuterXml; run.AutoSplitterSettings = newXmlDoc.FirstChild as XmlElement; run.AutoSplitterSettings.Attributes.Append(SettingsHelper.ToAttribute(newXmlDoc, "gameName", run.GameName)); } if (!string.IsNullOrEmpty(FilePath)) { run.FilePath = FilePath; } return(run); }