コード例 #1
0
        public void Save(IRun run, Stream stream, OngoingRun ongoingRun)
        {
            var regularTimeFormatter = new RegularTimeFormatter(TimeAccuracy.Hundredths);
            var shortTimeFormatter   = new ShortTimeFormatter();

            var writer = new StreamWriter(stream);

            if (!string.IsNullOrEmpty(run.GameName))
            {
                writer.Write(Escape(run.GameName));

                if (!string.IsNullOrEmpty(run.CategoryName))
                {
                    writer.Write(" - ");
                }
            }

            writer.Write(Escape(run.CategoryName));
            writer.Write(',');
            writer.WriteLine(Escape(run.AttemptCount.ToString()));

            foreach (var segment in run)
            {
                writer.Write(Escape(segment.Name));
                writer.Write(',');
                writer.Write(Escape(regularTimeFormatter.Format(segment.PersonalBestSplitTime.RealTime)));
                writer.Write(',');
                writer.WriteLine(Escape(shortTimeFormatter.Format(segment.BestSegmentTime.RealTime)));
            }

            writer.Flush();
        }
コード例 #2
0
ファイル: SerializeRunSaver.cs プロジェクト: Remag/LiveSplit
        public void Save(IRun run, Stream stream, OngoingRun ongoingRun)
        {
            var obj = (IRun)run.Clone();

            foreach (var segment in obj)
            {
                segment.SplitTime  = default(Time);
                segment.DeathCount = -1;
            }

            var formatter = new BinaryFormatter();

            formatter.Serialize(stream, obj);
        }
コード例 #3
0
ファイル: ExcelRunSaver.cs プロジェクト: Remag/LiveSplit
        public void Save(IRun run, Stream stream, OngoingRun ongoingRun)
        {
            var workbook                    = new Workbook();
            var splitsRealTimeSheet         = workbook.Sheets.AddSheet("Splits (Real Time)");
            var attemptHistoryRealTimeSheet = workbook.Sheets.AddSheet("Attempt History (Real Time)");
            var segmentHistoryRealTimeSheet = workbook.Sheets.AddSheet("Segment History (Real Time)");
            var splitsGameTimeSheet         = workbook.Sheets.AddSheet("Splits (Game Time)");
            var attemptHistoryGameTimeSheet = workbook.Sheets.AddSheet("Attempt History (Game Time)");
            var segmentHistoryGameTimeSheet = workbook.Sheets.AddSheet("Segment History (Game Time)");

            FillSplitTimesSheet(splitsRealTimeSheet, run, TimingMethod.RealTime);
            FillAttemptHistorySheet(attemptHistoryRealTimeSheet, run, TimingMethod.RealTime);
            FillSegmentHistorySheet(segmentHistoryRealTimeSheet, run, TimingMethod.RealTime);
            FillSplitTimesSheet(splitsGameTimeSheet, run, TimingMethod.GameTime);
            FillAttemptHistorySheet(attemptHistoryGameTimeSheet, run, TimingMethod.GameTime);
            FillSegmentHistorySheet(segmentHistoryGameTimeSheet, run, TimingMethod.GameTime);

            workbook.SaveToStream(stream, Codaxy.Xlio.IO.XlsxFileWriterOptions.AutoFit);
        }
コード例 #4
0
        public void Save(IRun run, Stream stream, OngoingRun ongoingRun)
        {
            var writer = new StreamWriter(stream);

            writer.Write("Title=");

            if (!string.IsNullOrEmpty(run.GameName))
            {
                writer.Write(Escape(run.GameName));

                if (!string.IsNullOrEmpty(run.CategoryName))
                {
                    writer.Write(" - ");
                }
            }

            writer.WriteLine(Escape(run.CategoryName));

            writer.Write("Attempts=");
            writer.WriteLine(Escape(run.AttemptCount.ToString()));

            writer.Write("Offset=");
            writer.WriteLine(Escape(run.Offset.TotalSeconds.ToString()));

            writer.WriteLine("Size=200,200");

            foreach (var segment in run)
            {
                writer.Write(Escape(segment.Name));
                writer.Write(",0,");
                writer.Write(Escape(segment.PersonalBestSplitTime.RealTime.HasValue ? segment.PersonalBestSplitTime.RealTime.Value.TotalSeconds.ToString() : "0"));
                writer.Write(',');
                writer.WriteLine(Escape(segment.BestSegmentTime.RealTime.HasValue ? segment.BestSegmentTime.RealTime.Value.TotalSeconds.ToString() : "0"));
            }

            writer.Write("Icons=");
            writer.Write(Enumerable.Repeat("\"\",", run.Count - 1));
            writer.WriteLine("\"\"");

            writer.Flush();
        }
コード例 #5
0
        public void Save(IRun run, Stream stream, OngoingRun ongoingRun)
        {
            dynamic document = new DynamicJsonObject();

            document.version      = "1.4";
            document.gameIcon     = CreateImageElement(run.GameIcon);
            document.gameName     = run.GameName;
            document.categoryName = run.CategoryName;
            document.offset       = run.Offset.ToString();
            document.attemptCount = run.AttemptCount.ToString();

            var runHistory = new List <DynamicJsonObject>();

            document.runHistory = runHistory;
            foreach (var historyItem in run.AttemptHistory)
            {
                runHistory.Add(historyItem.ToJson());
            }

            var segments = new List <DynamicJsonObject>();

            document.segments = segments;
            foreach (var segment in run)
            {
                dynamic segmentElement = new DynamicJsonObject();
                segmentElement.name = segment.Name;
                segmentElement.icon = CreateImageElement(segment.Icon);

                dynamic splitTimes = new DynamicJsonObject();
                foreach (var comparison in run.CustomComparisons)
                {
                    splitTimes.Properties.Add(comparison, segment.Comparisons[comparison].ToJson());
                }
                segmentElement.splitTimes = splitTimes;

                segments.Add(segmentElement);
            }

            /*
             * var segmentElement = document.CreateElement("Segments");
             * parent.AppendChild(segmentElement);
             *
             * var bf = new BinaryFormatter();
             *
             * foreach (var segment in run)
             * {
             *  var splitElement = document.CreateElement("Segment");
             *  segmentElement.AppendChild(splitElement);
             *
             *  var icon = CreateImageElement(document, "Icon", segment.Icon);
             *  splitElement.AppendChild(icon);
             *
             *  var name = document.CreateElement("Name");
             *  name.InnerText = segment.Name;
             *  splitElement.AppendChild(name);
             *
             *  var splitTimes = document.CreateElement("SplitTimes");
             *  foreach (var comparison in run.CustomComparisons)
             *  {
             *      var splitTime = document.CreateElement("SplitTime");
             *      var comparisonName = document.CreateAttribute("name");
             *      comparisonName.Value = comparison;
             *      splitTime.Attributes.Append(comparisonName);
             *      splitTime.InnerText = segment.Comparisons[comparison].ToString();
             *      splitTimes.AppendChild(splitTime);
             *  }
             *  splitElement.AppendChild(splitTimes);
             *
             *  var goldSplit = document.CreateElement("BestSegmentTime");
             *  goldSplit.InnerText = segment.BestSegmentTime.ToString();
             *  splitElement.AppendChild(goldSplit);
             *
             *  var history = document.CreateElement("SegmentHistory");
             *  foreach (var historySegment in segment.SegmentHistory)
             *  {
             *      history.AppendChild(historySegment.ToXml(document));
             *  }
             *  splitElement.AppendChild(history);
             * }*/

            var writer = new StreamWriter(stream);

            writer.Write(document.ToString());
            writer.Flush();
        }
コード例 #6
0
ファイル: XMLRunFactory.cs プロジェクト: Remag/LiveSplit
        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"]);
            run.BestDeathCount = ParseInt(parent["BestDeathCount"], -1);

            int maxAttemptIndex;

            ParseAttemptHistory(version, parent, run, out maxAttemptIndex);

            var segmentsNode = parent["Segments"];

            Segment currentParent = null;

            foreach (var segmentNode in segmentsNode.GetElementsByTagName("Segment"))
            {
                var segmentElement = segmentNode as XmlElement;

                Segment split;
                var     splitName = ParseString(segmentElement["Name"]);
                if (splitName.StartsWith("-"))
                {
                    if (currentParent == null)
                    {
                        currentParent = new Segment("");
                    }
                    split        = new Segment(splitName);
                    split.Parent = currentParent;
                }
                else if (currentParent != null)
                {
                    split         = currentParent;
                    split.Name    = splitName;
                    currentParent = null;
                }
                else
                {
                    split = new Segment(splitName);
                }
                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 bestDeaths = segmentElement["BestDeathCount"];
                if (bestDeaths != null && bestDeaths.InnerText.Length > 0)
                {
                    split.BestDeathCount = int.Parse(bestDeaths.InnerText);
                }
                var pbDeaths = segmentElement["PersonalBestDeathCount"];
                if (pbDeaths != null && pbDeaths.InnerText.Length > 0)
                {
                    split.PersonalBestDeathCount = int.Parse(pbDeaths.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 (indexedTime.Index <= maxAttemptIndex && !split.SegmentHistory.ContainsKey(indexedTime.Index))
                    {
                        split.SegmentHistory.Add(indexedTime.Index, indexedTime.Time);
                    }
                }

                run.Add(split);
            }

            if (currentParent != null)
            {
                run.Add(currentParent);
            }

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

            var ongoingNode = parent["OngoingRun"];

            if (ongoingNode != null)
            {
                run.FrozenRun = OngoingRun.ParseXml(ongoingNode);
            }

            return(run);
        }
コード例 #7
0
ファイル: XMLRunSaver.cs プロジェクト: Remag/LiveSplit
        public void Save(IRun run, Stream stream, OngoingRun ongoingRun)
        {
            var document = new XmlDocument();

            XmlNode docNode = document.CreateXmlDeclaration("1.0", "UTF-8", null);

            document.AppendChild(docNode);

            var parent = document.CreateElement("Run");

            parent.Attributes.Append(ToAttribute(document, "version", "1.7.0"));
            document.AppendChild(parent);

            CreateSetting(document, parent, "GameIcon", run.GameIcon);
            CreateSetting(document, parent, "GameName", run.GameName);
            CreateSetting(document, parent, "CategoryName", run.CategoryName);

            var metadata = document.CreateElement("Metadata");

            var runElement = document.CreateElement("Run");

            runElement.Attributes.Append(ToAttribute(document, "id", run.Metadata.RunID));
            metadata.AppendChild(runElement);

            var platform = ToElement(document, "Platform", run.Metadata.PlatformName);

            platform.Attributes.Append(ToAttribute(document, "usesEmulator", run.Metadata.UsesEmulator));
            metadata.AppendChild(platform);

            CreateSetting(document, metadata, "Region", run.Metadata.RegionName);

            var variables = document.CreateElement("Variables");

            foreach (var variable in run.Metadata.VariableValueNames)
            {
                var variableElement = ToElement(document, "Variable", variable.Value);
                variableElement.Attributes.Append(ToAttribute(document, "name", variable.Key));
                variables.AppendChild(variableElement);
            }
            metadata.AppendChild(variables);
            parent.AppendChild(metadata);

            CreateSetting(document, parent, "Offset", run.Offset);
            CreateSetting(document, parent, "AttemptCount", run.AttemptCount);
            CreateSetting(document, parent, "BestDeathCount", run.BestDeathCount);

            var runHistory = document.CreateElement("AttemptHistory");

            foreach (var attempt in run.AttemptHistory)
            {
                runHistory.AppendChild(attempt.ToXml(document));
            }
            parent.AppendChild(runHistory);

            var segmentElement = document.CreateElement("Segments");

            parent.AppendChild(segmentElement);

            var bf = new BinaryFormatter();

            foreach (var segment in run)
            {
                var splitElement = document.CreateElement("Segment");
                segmentElement.AppendChild(splitElement);

                CreateSetting(document, splitElement, "Name", segment.Name);
                CreateSetting(document, splitElement, "Icon", segment.Icon);

                var splitTimes = document.CreateElement("SplitTimes");
                foreach (var comparison in run.CustomComparisons)
                {
                    var splitTime = segment.Comparisons[comparison].ToXml(document, "SplitTime");
                    splitTime.Attributes.Append(ToAttribute(document, "name", comparison));
                    splitTimes.AppendChild(splitTime);
                }
                splitElement.AppendChild(splitTimes);

                splitElement.AppendChild(segment.BestSegmentTime.ToXml(document, "BestSegmentTime"));

                var bestDeaths = document.CreateElement("BestDeathCount");
                bestDeaths.InnerText = segment.BestDeathCount.ToString();
                splitElement.AppendChild(bestDeaths);

                var pbDeaths = document.CreateElement("PersonalBestDeathCount");
                pbDeaths.InnerText = segment.PersonalBestDeathCount.ToString();
                splitElement.AppendChild(pbDeaths);

                var history = document.CreateElement("SegmentHistory");
                foreach (var historySegment in segment.SegmentHistory)
                {
                    var indexedTime = new IndexedTime(historySegment.Value, historySegment.Key);
                    history.AppendChild(indexedTime.ToXml(document));
                }
                splitElement.AppendChild(history);
            }

            var autoSplitterSettings = document.CreateElement("AutoSplitterSettings");

            if (run.IsAutoSplitterActive())
            {
                autoSplitterSettings.InnerXml = run.AutoSplitter.Component.GetSettings(document).InnerXml;
            }
            parent.AppendChild(autoSplitterSettings);

            if (ongoingRun != null)
            {
                parent.AppendChild(ongoingRun.ToXml(document));
            }

            document.Save(stream);
        }