Esempio n. 1
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var run = new Run(factory);

            var json = JSON.FromStream(Stream);

            run.GameName     = json.run_name as string;
            run.AttemptCount = json.run_count;

            var timingMethod = (int)(json.timer_type) == 0
                ? TimingMethod.RealTime
                : TimingMethod.GameTime;

            var segments = json.splits as IEnumerable <dynamic>;

            foreach (var segment in segments)
            {
                var segmentName = segment.name as string;
                var pbSplitTime = parseTime((int?)segment.pb_split, timingMethod);
                var bestSegment = parseTime((int?)segment.split_best, timingMethod);

                var parsedSegment = new Segment(segmentName, pbSplitTime, bestSegment);
                run.Add(parsedSegment);
            }

            return(run);
        }
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var run = new Run(factory);

            var json = JSON.FromStream(Stream);

            run.GameName = json.run_name as string;
            run.AttemptCount = json.run_count;

            var timingMethod = (int)(json.timer_type) == 0 
                ? TimingMethod.RealTime 
                : TimingMethod.GameTime;

            var segments = json.splits as IEnumerable<dynamic>;

            foreach (var segment in segments)
            {
                var segmentName = segment.name as string;
                var pbSplitTime = parseTime((int?)segment.pb_split, timingMethod);
                var bestSegment = parseTime((int?)segment.split_best, timingMethod);

                var parsedSegment = new Segment(segmentName, pbSplitTime, bestSegment);
                run.Add(parsedSegment);
            }

            return run;
        }
Esempio n. 3
0
 public void addRun()
 {
     Run.Add(new Bitmap("assets\\char\\Run (1).png"));
     Run.Add(new Bitmap("assets\\char\\Run (2).png"));
     Run.Add(new Bitmap("assets\\char\\Run (3).png"));
     Run.Add(new Bitmap("assets\\char\\Run (4).png"));
     Run.Add(new Bitmap("assets\\char\\Run (5).png"));
     Run.Add(new Bitmap("assets\\char\\Run (6).png"));
     Run.Add(new Bitmap("assets\\char\\Run (7).png"));
     Run.Add(new Bitmap("assets\\char\\Run (8).png"));
 }
Esempio n. 4
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var run = new Run(factory);

            var json = JSON.FromStream(Stream);

            run.CategoryName = json.title as string;
            run.AttemptCount = json.attempt_count;
            run.Offset       = TimeSpanParser.Parse(json.start_delay as string);

            //Best Split Times can be used for the Segment History
            //Every single best split time should be included as its own run,
            //since the best split times could be apart from each other less
            //than the best segments, so we have to assume they are from different runs.
            var attemptHistoryIndex = 1;

            var segments = json.splits as IEnumerable <dynamic>;

            foreach (var segment in segments)
            {
                var segmentName = segment.title as string;
                var pbSplitTime = parseTime(segment.time as string);
                var bestSegment = parseTime(segment.best_segment as string);

                var parsedSegment = new Segment(segmentName, pbSplitTime, bestSegment);

                var bestSplitTime = parseTime(segment.best_time as string);
                if (bestSplitTime.RealTime != null)
                {
                    run.AttemptHistory.Add(new Attempt(attemptHistoryIndex, default(Time), null, null));

                    //Insert a new run that skips to the current split
                    foreach (var alreadyInsertedSegment in run)
                    {
                        alreadyInsertedSegment.SegmentHistory.Add(attemptHistoryIndex, default(Time));
                    }

                    parsedSegment.SegmentHistory.Add(attemptHistoryIndex, bestSplitTime);

                    attemptHistoryIndex++;
                }

                run.Add(parsedSegment);
            }

            return(run);
        }
Esempio n. 5
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var run = new Run(factory);

            var json = JSON.FromStream(Stream);

            run.CategoryName = json.title as string;
            run.AttemptCount = json.attempt_count;
            run.Offset = TimeSpanParser.Parse(json.start_delay as string);

            //Best Split Times can be used for the Segment History
            //Every single best split time should be included as its own run, 
            //since the best split times could be apart from each other less 
            //than the best segments, so we have to assume they are from different runs.
            var attemptHistoryIndex = 1;

            var segments = json.splits as IEnumerable<dynamic>;

            foreach (var segment in segments)
            {
                var segmentName = segment.title as string;
                var pbSplitTime = parseTime(segment.time as string);
                var bestSegment = parseTime(segment.best_segment as string);

                var parsedSegment = new Segment(segmentName, pbSplitTime, bestSegment);

                var bestSplitTime = parseTime(segment.best_time as string);
                if (bestSplitTime.RealTime != null)
                {
                    run.AttemptHistory.Add(new Attempt(attemptHistoryIndex, default(Time), null, null));

                    //Insert a new run that skips to the current split
                    foreach (var alreadyInsertedSegment in run)
                    {
                        alreadyInsertedSegment.SegmentHistory.Add(attemptHistoryIndex, default(Time));
                    }

                    parsedSegment.SegmentHistory.Add(attemptHistoryIndex, bestSplitTime);

                    attemptHistoryIndex++;
                }

                run.Add(parsedSegment);
            }

            return run;
        }
            private IEnumerable <Run> FindOrderedRuns(int maxRunLength)
            {
                Run run = null;

                var originalIndex = 0;

                foreach (var request in _operation._requests)
                {
                    if (run == null)
                    {
                        run = new Run();
                        run.Add(request, originalIndex);
                    }
                    else if (run.RequestType == request.RequestType)
                    {
                        if (run.Count == maxRunLength)
                        {
                            yield return(run);

                            run = new Run();
                        }
                        run.Add(request, originalIndex);
                    }
                    else
                    {
                        yield return(run);

                        run = new Run();
                        run.Add(request, originalIndex);
                    }

                    originalIndex++;
                }

                if (run != null)
                {
                    yield return(run);
                }
            }
Esempio n. 7
0
        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)
        {
            LiveSplitCore.ParseRunResult result = null;
            if (Stream is FileStream)
            {
                var handle = (Stream as FileStream).SafeFileHandle;
                if (!handle.IsInvalid)
                {
                    result = LiveSplitCore.Run.ParseFileHandle((long)handle.DangerousGetHandle(), FilePath, !string.IsNullOrEmpty(FilePath));
                }
            }
            if (result == null)
            {
                result = LiveSplitCore.Run.Parse(Stream, FilePath, !string.IsNullOrEmpty(FilePath));
            }

            if (!result.ParsedSuccessfully())
            {
                throw new Exception();
            }

            var timerKind = result.TimerKind();

            using (var lscRun = result.Unwrap())
            {
                var run = new Run(factory);

                var metadata = lscRun.Metadata();
                run.Metadata.RunID        = metadata.RunId();
                run.Metadata.PlatformName = metadata.PlatformName();
                run.Metadata.UsesEmulator = metadata.UsesEmulator();
                run.Metadata.RegionName   = metadata.RegionName();
                using (var iter = metadata.SpeedrunComVariables())
                {
                    LiveSplitCore.RunMetadataSpeedrunComVariableRef variable;
                    while ((variable = iter.Next()) != null)
                    {
                        run.Metadata.VariableValueNames.Add(variable.Name(), variable.Value());
                    }
                }

                run.GameIcon     = ParseImage(lscRun.GameIconPtr(), lscRun.GameIconLen());
                run.GameName     = lscRun.GameName();
                run.CategoryName = lscRun.CategoryName();
                run.Offset       = ParseTimeSpan(lscRun.Offset());
                run.AttemptCount = (int)lscRun.AttemptCount();

                var attemptsCount = lscRun.AttemptHistoryLen();
                for (var i = 0; i < attemptsCount; ++i)
                {
                    var attempt = lscRun.AttemptHistoryIndex(i);
                    run.AttemptHistory.Add(new Attempt(
                                               attempt.Index(),
                                               ParseTime(attempt.Time()),
                                               ParseOptionalAtomicDateTime(attempt.Started()),
                                               ParseOptionalAtomicDateTime(attempt.Ended()),
                                               ParseOptionalTimeSpan(attempt.PauseTime())
                                               ));
                }

                var customComparisonsCount = lscRun.CustomComparisonsLen();
                for (var i = 0; i < customComparisonsCount; ++i)
                {
                    var comparison = lscRun.CustomComparison(i);
                    if (!run.CustomComparisons.Contains(comparison))
                    {
                        run.CustomComparisons.Add(comparison);
                    }
                }

                var segmentCount = lscRun.Len();
                for (var i = 0; i < segmentCount; ++i)
                {
                    var segment = lscRun.Segment(i);
                    var split   = new Segment(segment.Name())
                    {
                        Icon            = ParseImage(segment.IconPtr(), segment.IconLen()),
                        BestSegmentTime = ParseTime(segment.BestSegmentTime()),
                    };

                    foreach (var comparison in run.CustomComparisons)
                    {
                        split.Comparisons[comparison] = ParseTime(segment.Comparison(comparison));
                    }

                    using (var iter = segment.SegmentHistory().Iter())
                    {
                        LiveSplitCore.SegmentHistoryElementRef element;
                        while ((element = iter.Next()) != null)
                        {
                            split.SegmentHistory.Add(element.Index(), ParseTime(element.Time()));
                        }
                    }

                    run.Add(split);
                }

                var document = new XmlDocument();
                document.LoadXml($"<AutoSplitterSettings>{lscRun.AutoSplitterSettings()}</AutoSplitterSettings>");
                run.AutoSplitterSettings = document.FirstChild as XmlElement;
                run.AutoSplitterSettings.Attributes.Append(ToAttribute(document, "gameName", run.GameName));

                if (timerKind == "LiveSplit" && !string.IsNullOrEmpty(FilePath))
                {
                    run.FilePath = FilePath;
                }

                if (run.Count < 1)
                {
                    throw new Exception("Run factory created a run without at least one segment");
                }

                return(run);
            }
        }
        private IEnumerable<Run> FindOrderedRuns()
        {
            Run run = null;

            var originalIndex = 0;
            foreach (var request in _requests)
            {
                if (run == null)
                {
                    run = new Run();
                    run.Add(request, originalIndex);
                }
                else if (run.RequestType == request.RequestType)
                {
                    if (run.Count == _maxBatchCount)
                    {
                        yield return run;
                        run = new Run();
                    }
                    run.Add(request, originalIndex);
                }
                else
                {
                    yield return run;
                    run = new Run();
                    run.Add(request, originalIndex);
                }

                originalIndex++;
            }

            if (run != null)
            {
                yield return run;
            }
        }
Esempio n. 10
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var document = new XmlDocument();

            document.Load(Stream);

            var run     = new Run(factory);
            var parent  = document["Run"];
            var version = 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     = GetImageFromElement(parent["GameIcon"]);
            run.GameName     = ParseString(parent["GameName"]);
            run.CategoryName = ParseString(parent["CategoryName"]);
            run.Offset       = ParseTimeSpan(parent["Offset"]);
            run.AttemptCount = 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(ParseString(segmentElement["Name"]));
                split.Icon = 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"))
                {
                    var          node = historyNode as XmlElement;
                    IIndexedTime indexedTime;
                    if (version >= new Version(1, 4, 1))
                    {
                        indexedTime = ParseXml(node);
                    }
                    else
                    {
                        indexedTime = ParseXmlOld(node);
                    }

                    if (!split.SegmentHistory.ContainsKey(indexedTime.Index))
                    {
                        split.SegmentHistory.Add(indexedTime.Index, indexedTime.Time);
                    }
                }

                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(ToAttribute(newXmlDoc, "gameName", run.GameName));
            }

            if (!string.IsNullOrEmpty(FilePath))
            {
                run.FilePath = FilePath;
            }

            return(run);
        }
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            string path = "";
            if (!string.IsNullOrEmpty(Path))
                path = System.IO.Path.GetDirectoryName(Path);

            var run = new Run(factory);

            var reader = new StreamReader(Stream);

            var line = reader.ReadLine();
            var titleInfo = line.Split('\t');
            run.AttemptCount = int.Parse(titleInfo[0]);
            run.Offset = TimeSpanParser.Parse(titleInfo[1]);
            if (!string.IsNullOrEmpty(path))
            {
                try
                {
                    run.GameIcon = Image.FromFile(System.IO.Path.Combine(path, titleInfo[2]));
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
            }

            line = reader.ReadLine();
            titleInfo = line.Split('\t');
            run.CategoryName = titleInfo[0];
            var comparisons = titleInfo.Skip(2).ToArray();

            while ((line = reader.ReadLine()) != null)
            {
                if (line.Length <= 0 || string.IsNullOrWhiteSpace(line))
                    continue;

                var segment = new Segment("");

                var segmentInfo = line.Split('\t');

                segment.Name = segmentInfo[0];
                Time newBestSegment = new Time();
                newBestSegment.RealTime = parseTimeNullable(segmentInfo[1]);
                segment.BestSegmentTime = newBestSegment;
                Time pbTime = new Time();
                for (var i = 0; i < comparisons.Length; ++i)
                {
                    Time newComparison = new Time(segment.Comparisons[comparisons[i]]);
                    newComparison.RealTime = pbTime.RealTime = parseTimeNullable(segmentInfo[i + 2]);
                    segment.Comparisons[comparisons[i]] = newComparison;
                }
                segment.PersonalBestSplitTime = pbTime;

                line = reader.ReadLine();

                if (line.Length > 0 && !string.IsNullOrWhiteSpace(line) && !string.IsNullOrEmpty(path))
                {
                    try
                    {
                        segment.Icon = Image.FromFile(System.IO.Path.Combine(path, line.Split('\t')[0]));
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }

                run.Add(segment);
            }

            parseHistory(run);

            foreach (var comparison in comparisons)
                run.CustomComparisons.Add(comparison);

            return run;
        }
Esempio n. 12
0
        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"))
                {
                    var node = historyNode as XmlElement;
                    IIndexedTime indexedTime;
                    if (version >= new Version(1, 4, 1))
                        indexedTime = IndexedTimeHelper.ParseXml(node);
                    else
                        indexedTime = IndexedTimeHelper.ParseXmlOld(node);

                    if (!split.SegmentHistory.ContainsKey(indexedTime.Index))
                        split.SegmentHistory.Add(indexedTime.Index, indexedTime.Time);
                }

                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;
        }
Esempio n. 13
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            string path = "";

            if (!string.IsNullOrEmpty(Path))
            {
                path = System.IO.Path.GetDirectoryName(Path);
            }

            var run = new Run(factory);

            var reader = new StreamReader(Stream);

            var line      = reader.ReadLine();
            var titleInfo = line.Split('\t');

            run.AttemptCount = int.Parse(titleInfo[0]);
            run.Offset       = TimeSpanParser.Parse(titleInfo[1]);
            if (!string.IsNullOrEmpty(path))
            {
                try
                {
                    run.GameIcon = Image.FromFile(System.IO.Path.Combine(path, titleInfo[2]));
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
            }

            line             = reader.ReadLine();
            titleInfo        = line.Split('\t');
            run.CategoryName = titleInfo[0];
            var comparisons = titleInfo.Skip(2).ToArray();

            while ((line = reader.ReadLine()) != null)
            {
                if (line.Length <= 0 || string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                var segment = new Segment("");

                var segmentInfo = line.Split('\t');

                segment.Name = segmentInfo[0];
                Time newBestSegment = new Time();
                newBestSegment.RealTime = parseTimeNullable(segmentInfo[1]);
                segment.BestSegmentTime = newBestSegment;
                Time pbTime = new Time();
                for (var i = 0; i < comparisons.Length; ++i)
                {
                    Time newComparison = new Time(segment.Comparisons[comparisons[i]]);
                    newComparison.RealTime = pbTime.RealTime = parseTimeNullable(segmentInfo[i + 2]);
                    segment.Comparisons[comparisons[i]] = newComparison;
                }
                segment.PersonalBestSplitTime = pbTime;

                line = reader.ReadLine();

                if (line.Length > 0 && !string.IsNullOrWhiteSpace(line) && !string.IsNullOrEmpty(path))
                {
                    try
                    {
                        segment.Icon = Image.FromFile(System.IO.Path.Combine(path, line.Split('\t')[0]));
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }

                run.Add(segment);
            }

            parseHistory(run);

            foreach (var comparison in comparisons)
            {
                run.CustomComparisons.Add(comparison);
            }

            return(run);
        }
Esempio n. 14
0
        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);

            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;
        }