Exemplo n.º 1
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            using (var stream = File.OpenRead(Path))
            {
                var data = new byte[4];
                stream.Read(data, 0, 4);
                if (data[0] != 0xac ||
                    data[1] != 0xed ||
                    data[2] != 0x00 ||
                    data[3] != 0x05)
                {
                    throw new NotSupportedException();
                }
            }

            var liveSplitBasePath = System.IO.Path.GetTempPath() + "LiveSplit";
            var splitsBasePath    = liveSplitBasePath + @"\Splits";
            var splitsFilePath    = splitsBasePath + @"\splits";
            var loaderPath        = liveSplitBasePath + @"\loader.jar";
            var javaPath          = GetJavaInstallationPath();

            if (!Directory.Exists(liveSplitBasePath))
            {
                Directory.CreateDirectory(liveSplitBasePath);
            }

            if (!Directory.Exists(splitsBasePath))
            {
                Directory.CreateDirectory(splitsBasePath);
            }

            if (File.Exists(loaderPath) && File.GetCreationTimeUtc(loaderPath) < new DateTime(2013, 12, 13, 20, 0, 0, 0, DateTimeKind.Utc))
            {
                File.Delete(loaderPath);
            }

            if (!File.Exists(loaderPath))
            {
                File.Create(loaderPath).Close();
                using (var memoryStream = new MemoryStream(Resources.LlanfairLoader))
                {
                    using (var stream = File.Open(loaderPath, FileMode.Create, FileAccess.Write))
                    {
                        memoryStream.CopyTo(stream);
                    }
                }
            }

            Empty(new DirectoryInfo(splitsBasePath));

            var process = Process.Start(System.IO.Path.Combine(javaPath, "bin\\javaw.exe"), string.Format("-jar \"{0}\" \"{1}\" \"{2}\"", loaderPath, Path, splitsFilePath));

            process.WaitForExit();
            process.Close();

            using (var stream = File.OpenRead(splitsFilePath))
            {
                return(ReadFromLlanfairTextFile(stream, factory));
            }
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var run = new Run(factory);

            var reader = new StreamReader(Stream);
            
            var line = reader.ReadLine();
            var titleInfo = line.Split('|');
            run.CategoryName = titleInfo[0].Substring(1);
            run.AttemptCount = int.Parse(titleInfo[1]);
            TimeSpan totalTime = TimeSpan.Zero;
            while ((line = reader.ReadLine()) != null)
            {
                if (line.Length > 0)
                {
                    var majorSplitInfo = line.Split('|');
                    totalTime += TimeSpanParser.Parse(majorSplitInfo[1]);
                    while (!reader.EndOfStream && reader.Read() == '*')
                    {
                        line = reader.ReadLine();
                        run.AddSegment(line);
                    }
                    var newTime = new Time(run.Last().PersonalBestSplitTime);
                    newTime.GameTime = totalTime;
                    run.Last().PersonalBestSplitTime = newTime;
                }
                else
                {
                    break;
                }
            }

            return run;
        }
Exemplo n.º 5
0
 public Run(IComparisonGeneratorsFactory factory)
 {
     InternalList = new List<ISegment>();
     AttemptHistory = new List<Attempt>();
     Factory = factory;
     ComparisonGenerators = Factory.Create(this).ToList();
     CustomComparisons = new List<string>() { PersonalBestComparisonName };
 }
Exemplo n.º 6
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var run = new Run(factory)
            {
                new Segment("")
            };

            return(run);
        }
 public IRun Create(IComparisonGeneratorsFactory factory)
 {
     var run = new Run(factory)
     {
         GameName = "",
         CategoryName = ""
     };
     run.AddSegment("");
     return run;
 }
Exemplo n.º 8
0
 public Run(IComparisonGeneratorsFactory factory)
 {
     InternalList         = new List <ISegment>();
     AttemptHistory       = new List <Attempt>();
     Factory              = factory;
     ComparisonGenerators = Factory.Create(this).ToList();
     CustomComparisons    = new List <string>()
     {
         PersonalBestComparisonName
     };
 }
Exemplo n.º 9
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var run = new Run(factory)
            {
                GameName     = "",
                CategoryName = ""
            };

            run.AddSegment("");
            return(run);
        }
Exemplo n.º 10
0
 public Run(IEnumerable<ISegment> collection, IComparisonGeneratorsFactory factory)
 {
     InternalList = new List<ISegment>();
     foreach (var x in collection)
     {
         InternalList.Add(x.Clone() as ISegment);
     }
     AttemptHistory = new List<Attempt>();
     Factory = factory;
     ComparisonGenerators = Factory.Create(this).ToList();
     CustomComparisons = new List<string>() { PersonalBestComparisonName };
 }
Exemplo n.º 11
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var run = new Run(factory);

            var reader = new StreamReader(Stream);

            var title = reader.ReadLine();

            run.CategoryName = title;

            var goal = reader.ReadLine();
            //TODO Store goal

            var attemptCount = reader.ReadLine();

            run.AttemptCount = Convert.ToInt32(attemptCount);

            var runsCompleted = reader.ReadLine();
            //TODO Store this somehow

            string segmentLine;

            while ((segmentLine = reader.ReadLine()) != null)
            {
                var splitted = segmentLine.Split(new[] { '-' }, 5);

                var segmentName = (splitted.Length >= 1) ? splitted[0].Replace("\"?\"", "-") : string.Empty;

                var splitTimeString = (splitted.Length >= 2) ? splitted[1] : string.Empty;
                var splitTime       = parseTime(splitTimeString);

                var bestSegment     = (splitted.Length >= 4) ? splitted[3] : string.Empty;
                var bestSegmentTime = parseTime(bestSegment);

                var   iconPath = (splitted.Length >= 5) ? splitted[4] : string.Empty;
                Image icon     = null;
                if (!string.IsNullOrWhiteSpace(iconPath))
                {
                    try
                    {
                        icon = Image.FromFile(iconPath);
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }

                run.AddSegment(segmentName, splitTime, bestSegmentTime, icon);
            }

            return(run);
        }
Exemplo n.º 12
0
 private Run(IEnumerable <ISegment> collection, IComparisonGeneratorsFactory factory, RunMetadata metadata)
 {
     InternalList         = CloneInternallList(collection);
     AttemptHistory       = new List <Attempt>();
     Factory              = factory;
     ComparisonGenerators = Factory.Create(this).ToList();
     CustomComparisons    = new List <string>()
     {
         PersonalBestComparisonName
     };
     Metadata = metadata.Clone(this);
 }
Exemplo n.º 13
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var run = new Run(factory);

            var reader = new StreamReader(Stream);

            var title = reader.ReadLine();
            run.CategoryName = title;

            var goal = reader.ReadLine();
            //TODO Store goal

            var attemptCount = reader.ReadLine();
            run.AttemptCount = Convert.ToInt32(attemptCount);

            var runsCompleted = reader.ReadLine();
            //TODO Store this somehow

            string segmentLine;
            while ((segmentLine = reader.ReadLine()) != null)
            {
                var splitted = segmentLine.Split(new[] { '-' }, 5);

                var segmentName = (splitted.Length >= 1) ? splitted[0].Replace("\"?\"", "-") : string.Empty;

                var splitTimeString = (splitted.Length >= 2) ? splitted[1] : string.Empty;
                var splitTime = parseTime(splitTimeString);

                var bestSegment = (splitted.Length >= 4) ? splitted[3] : string.Empty;
                var bestSegmentTime = parseTime(bestSegment);

                var iconPath = (splitted.Length >= 5) ? splitted[4] : string.Empty;
                Image icon = null;
                if (!string.IsNullOrWhiteSpace(iconPath))
                {
                    try
                    {
                        icon = Image.FromFile(iconPath);
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }

                run.AddSegment(segmentName, splitTime, bestSegmentTime, icon);
            }

            return run;
        }
Exemplo n.º 14
0
 public Run(IComparisonGeneratorsFactory factory)
 {
     InternalList         = new List <ISegment>();
     AttemptHistory       = new List <Attempt>();
     Factory              = factory;
     ComparisonGenerators = Factory.Create(this).ToList();
     CustomComparisons    = new List <string>()
     {
         PersonalBestComparisonName
     };
     Metadata          = new RunMetadata(this);
     CurrentDeathCount = 0;
     BestDeathCount    = -1;
 }
Exemplo n.º 15
0
 public Run(IEnumerable <ISegment> collection, IComparisonGeneratorsFactory factory)
 {
     InternalList = new List <ISegment>();
     foreach (var x in collection)
     {
         InternalList.Add(x.Clone() as ISegment);
     }
     AttemptHistory       = new List <Attempt>();
     Factory              = factory;
     ComparisonGenerators = Factory.Create(this).ToList();
     CustomComparisons    = new List <string>()
     {
         PersonalBestComparisonName
     };
 }
Exemplo n.º 16
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var run = new Run(factory);

            var reader = new StreamReader(Stream);

            var title = reader.ReadLine();

            run.CategoryName = title;

            var goal = reader.ReadLine();
            //TODO Store goal

            var attemptCount = reader.ReadLine();

            run.AttemptCount = Convert.ToInt32(attemptCount);

            var runsCompleted = reader.ReadLine();
            //TODO Store this somehow

            string segmentLine;

            while ((segmentLine = reader.ReadLine()) != null)
            {
                //Parse the Segment Line from right to left, as dashes in the
                //title are not escaped. Therefore we can't just split it by
                //the dashes. FaceSplit itself does that, but LiveSplit fixes
                //that bug.
                var index           = segmentLine.LastIndexOf('-');
                var bestSegment     = segmentLine.Substring(index + 1);
                var bestSegmentTime = parseTime(bestSegment);

                segmentLine = segmentLine.Substring(0, index);
                index       = segmentLine.LastIndexOf('-');
                //Ignore Segment Time

                segmentLine = segmentLine.Substring(0, index);
                index       = segmentLine.LastIndexOf('-');
                var splitTimeString = segmentLine.Substring(index + 1);
                var splitTime       = parseTime(splitTimeString);

                var segmentName = segmentLine.Substring(0, index);

                run.AddSegment(segmentName, splitTime, bestSegmentTime);
            }

            return(run);
        }
Exemplo n.º 17
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;
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var run = new Run(factory);

            var reader = new StreamReader(Stream);

            var title = reader.ReadLine();
            run.CategoryName = title;

            var goal = reader.ReadLine();
            //TODO Store goal

            var attemptCount = reader.ReadLine();
            run.AttemptCount = Convert.ToInt32(attemptCount);

            var runsCompleted = reader.ReadLine();
            //TODO Store this somehow

            string segmentLine;
            while ((segmentLine = reader.ReadLine()) != null)
            {
                //Parse the Segment Line from right to left, as dashes in the 
                //title are not escaped. Therefore we can't just split it by
                //the dashes. FaceSplit itself does that, but LiveSplit fixes 
                //that bug.
                var index = segmentLine.LastIndexOf('-');
                var bestSegment = segmentLine.Substring(index + 1);
                var bestSegmentTime = parseTime(bestSegment);

                segmentLine = segmentLine.Substring(0, index);
                index = segmentLine.LastIndexOf('-');
                //Ignore Segment Time

                segmentLine = segmentLine.Substring(0, index);
                index = segmentLine.LastIndexOf('-');
                var splitTimeString = segmentLine.Substring(index + 1);
                var splitTime = parseTime(splitTimeString);

                var segmentName = segmentLine.Substring(0, index);

                run.AddSegment(segmentName, splitTime, bestSegmentTime);
            }

            return run;
        }
Exemplo n.º 20
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            foreach (var runFactory in RunFactories)
            {
                try
                {
                    if (Stream != null)
                    {
                        Stream.Seek(0, SeekOrigin.Begin);
                    }

                    runFactory.Value(Stream, FilePath);
                    var run = runFactory.Key.Create(factory);
                    return(run);
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
            }

            throw new ArgumentException();
        }
Exemplo n.º 21
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            foreach (var runFactory in RunFactories)
            {
                try
                {
                    Stream?.Seek(0, SeekOrigin.Begin);

                    runFactory.Value(Stream, FilePath);
                    var run = runFactory.Key.Create(factory);
                    if (run.Count < 1)
                    {
                        throw new Exception("Run factory created a run without at least one segment");
                    }
                    return(run);
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
            }

            throw new ArgumentException();
        }
Exemplo n.º 22
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var run = new Run(factory);

            var reader = new StreamReader(Stream);

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

            run.CategoryName = titleInfo[0].Substring(1);
            run.AttemptCount = Int32.Parse(titleInfo[1]);
            TimeSpan totalTime = TimeSpan.Zero;

            while ((line = reader.ReadLine()) != null)
            {
                if (line.Length > 0)
                {
                    var majorSplitInfo = line.Split('|');
                    totalTime += TimeSpanParser.Parse(majorSplitInfo[1]);
                    while (!reader.EndOfStream && reader.Read() == (int)('*'))
                    {
                        line = reader.ReadLine();
                        run.AddSegment(line);
                    }
                    var newTime = new Time(run.Last().PersonalBestSplitTime);
                    newTime.GameTime = totalTime;
                    run.Last().PersonalBestSplitTime = newTime;
                }
                else
                {
                    break;
                }
            }

            return(run);
        }
Exemplo n.º 23
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            using (var stream = File.OpenRead(Path))
            {
                var data = new byte[4];
                stream.Read(data, 0, 4);
                if (data[0] != 0xac
                    || data[1] != 0xed
                    || data[2] != 0x00
                    || data[3] != 0x05)
                    throw new NotSupportedException();
            }

            var liveSplitBasePath = System.IO.Path.GetTempPath() + "LiveSplit";
            var splitsBasePath = liveSplitBasePath + @"\Splits";
            var splitsFilePath = splitsBasePath + @"\splits";
            var loaderPath = liveSplitBasePath + @"\loader.jar";
            var javaPath = GetJavaInstallationPath();

            if (!Directory.Exists(liveSplitBasePath))
                Directory.CreateDirectory(liveSplitBasePath);

            if (!Directory.Exists(splitsBasePath))
                Directory.CreateDirectory(splitsBasePath);

            if (File.Exists(loaderPath) && File.GetCreationTimeUtc(loaderPath) < new DateTime(2013, 12, 13, 20, 0, 0, 0, DateTimeKind.Utc))
            {
                File.Delete(loaderPath);
            }

            if (!File.Exists(loaderPath))
            {
                File.Create(loaderPath).Close();
                using (var memoryStream = new MemoryStream(Resources.LlanfairLoader))
                {
                    using (var stream = File.Open(loaderPath, FileMode.Create, FileAccess.Write))
                    {
                        memoryStream.CopyTo(stream);
                    }
                }
            }

            Empty(new DirectoryInfo(splitsBasePath));

            var process = Process.Start(System.IO.Path.Combine(javaPath, "bin\\javaw.exe"), string.Format("-jar \"{0}\" \"{1}\" \"{2}\"", loaderPath, Path, splitsFilePath));
            process.WaitForExit();
            process.Close();

            using (var stream = File.OpenRead(splitsFilePath))
            {
                return ReadFromLlanfairTextFile(stream, factory);
            }
        }
Exemplo n.º 24
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);
        }
Exemplo n.º 25
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;
        }
Exemplo n.º 26
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var chapters = new Dictionary<string, string[]>()
            {
                { 
                    "Chapter 1 - The Courtesy Call",
                    new []
                    {
                        "sp_a1_intro1",
                        "sp_a1_intro2",
                        "sp_a1_intro3",
                        "sp_a1_intro4",
                        "sp_a1_intro5",
                        "sp_a1_intro6",
                        "sp_a1_intro7",
                        "sp_a1_wakeup",
                        "sp_a2_intro"
                    }
                },
                {
                    "Chapter 2 - The Cold Boot",
                    new []
                    {
                        "sp_a2_laser_intro",
                        "sp_a2_laser_stairs",
                        "sp_a2_dual_lasers",
                        "sp_a2_laser_over_goo",
                        "sp_a2_catapult_intro",
                        "sp_a2_trust_fling",
                        "sp_a2_pit_flings",
                        "sp_a2_fizzler_intro"
                    }
                },
                {
                    "Chapter 3 - The Return",
                    new []
                    {
                        "sp_a2_sphere_peek",
                        "sp_a2_ricochet",
                        "sp_a2_bridge_intro",
                        "sp_a2_bridge_the_gap",
                        "sp_a2_turret_intro",
                        "sp_a2_laser_relays",
                        "sp_a2_turret_blocker",
                        "sp_a2_laser_vs_turret",
                        "sp_a2_pull_the_rug",
                    }
                },
                {
                    "Chapter 4 - The Surprise",
                    new []
                    {
                        "sp_a2_column_blocker",
                        "sp_a2_laser_chaining",
                        "sp_a2_triple_laser",
                        "sp_a2_bts1",
                        "sp_a2_bts2",
                    }
                },
                {
                    "Chapter 5 - The Escape",
                    new []
                    {
                        "sp_a2_bts3",
                        "sp_a2_bts4",
                        "sp_a2_bts5",
                        "sp_a2_bts6",
                        "sp_a2_core",
                    }
                },
                {
                    "Chapter 6 - The Fall",
                    new []
                    {
                        "sp_a3_00",
                        "sp_a3_01",
                        "sp_a3_03",
                        "sp_a3_jump_intro",
                        "sp_a3_bomb_flings",
                        "sp_a3_crazy_box",
                        "sp_a3_transition01",
                    }
                },
                {
                    "Chapter 7 - The Reunion",
                    new []
                    {
                        "sp_a3_speed_ramp",
                        "sp_a3_speed_flings",
                        "sp_a3_portal_intro",
                        "sp_a3_end",
                    }
                },
                {
                    "Chapter 8 - The Itch",
                    new []
                    {
                        "sp_a4_intro",
                        "sp_a4_tb_intro",
                        "sp_a4_tb_trust_drop",
                        "sp_a4_tb_wall_button",
                        "sp_a4_tb_polarity",
                        "sp_a4_tb_catch",
                        "sp_a4_stop_the_box",
                        "sp_a4_laser_catapult",
                        "sp_a4_laser_platform",
                        "sp_a4_speed_tb_catch",
                        "sp_a4_jump_polarity",
                    }
                },
                {
                    "Chapter 9 - The Part Where...",
                    new []
                    {
                        "sp_a4_finale1",
                        "sp_a4_finale2",
                        "sp_a4_finale3",
                        "sp_a4_finale4",
                        //"sp_a5_credits",
                    }
                }
            };

            var run = new Run(factory);

            run.GameName = "Portal 2";
            run.CategoryName = "Any%";

            var reader = new StreamReader(Stream);

            var lines = reader
                .ReadToEnd()
                .Split('\n')
                .Select(x => x.Replace("\r", ""))
                .Skip(1)
                .Select(x => x.Split(','))
                .ToArray();

            var aggregateTicks = 0;

            foreach (var chapter in chapters)
            {
                foreach (var map in chapter.Value)
                {
                    //Force it to break, if the splits aren't there
                    lines.First(x => x[0] == map); 

                    foreach (var mapLine in lines.Where(x => x[0] == map))
                    {
                        var mapTicks = int.Parse(mapLine[2], CultureInfo.InvariantCulture)
                                      - int.Parse(mapLine[1], CultureInfo.InvariantCulture);
                        aggregateTicks += mapTicks;
                    }
                }

                var timeSpan = TimeSpan.FromSeconds(aggregateTicks / 60.0);
                var chapterTime = new Time(timeSpan, timeSpan);

                run.AddSegment(chapter.Key, chapterTime);
            }

            return run;
        }
Exemplo n.º 27
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;
        }
Exemplo n.º 28
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var formatter = new BinaryFormatter();

            return(formatter.Deserialize(Stream) as IRun);
        }
Exemplo n.º 29
0
        protected IRun ReadFromLlanfairTextFile(Stream stream, IComparisonGeneratorsFactory factory)
        {
            var run = new Run(factory);

            using (var reader = new StreamReader(stream))
            {
                var line = reader.ReadLine();
                var titleInfo = line.Split(',');
                run.GameName = Unescape(titleInfo[0]);
                run.CategoryName = Unescape(titleInfo[1]);
                run.AttemptCount = int.Parse(Unescape(titleInfo[2]));
                while ((line = reader.ReadLine()) != null)
                {
                    if (line.Length > 0)
                    {
                        var splitInfo = line.Split(',');
                        Time pbSplitTime = default(Time);
                        Time goldTime = default(Time);

                        try
                        {
                            pbSplitTime.RealTime = TimeSpan.Parse(Unescape(splitInfo[1]));
                        }
                        catch
                        {
                            try
                            {
                                pbSplitTime.RealTime = TimeSpan.Parse(Unescape("0:" + splitInfo[1]));
                            }
                            catch
                            {
                                pbSplitTime.RealTime = TimeSpan.Parse(Unescape("0:0:" + splitInfo[1]));
                            }
                        }

                        try
                        {
                            goldTime.RealTime = TimeSpan.Parse(Unescape(splitInfo[2]));
                        }
                        catch
                        {
                            try
                            {
                                goldTime.RealTime = TimeSpan.Parse(Unescape("0:" + splitInfo[2]));
                            }
                            catch
                            {
                                goldTime.RealTime = TimeSpan.Parse(Unescape("0:0:" + splitInfo[2]));
                            }
                        }

                        if (pbSplitTime.RealTime == TimeSpan.Zero)
                            pbSplitTime.RealTime = null;

                        if (goldTime.RealTime == TimeSpan.Zero)
                            goldTime.RealTime = null;

                        var realIconPath = "";
                        if (splitInfo.Length > 3)
                            realIconPath = Unescape(splitInfo[3]);
                        Image icon = null;
                        if (realIconPath.Length > 0)
                        {
                            try
                            {
                                using (var imageStream = File.OpenRead(realIconPath))
                                {
                                    icon = Image.FromStream(imageStream);
                                }
                            }
                            catch (Exception e)
                            {
                                Log.Error(e);
                            }
                        }
                        run.AddSegment(Unescape(splitInfo[0]), pbSplitTime, goldTime, icon);
                    }
                }
            }

            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);
            }
        }
Exemplo n.º 31
0
        protected IRun ReadFromLlanfairTextFile(Stream stream, IComparisonGeneratorsFactory factory)
        {
            var run = new Run(factory);

            using (var reader = new StreamReader(stream))
            {
                var line      = reader.ReadLine();
                var titleInfo = line.Split(',');
                run.GameName     = Unescape(titleInfo[0]);
                run.CategoryName = Unescape(titleInfo[1]);
                run.AttemptCount = int.Parse(Unescape(titleInfo[2]));
                while ((line = reader.ReadLine()) != null)
                {
                    if (line.Length > 0)
                    {
                        var  splitInfo   = line.Split(',');
                        Time pbSplitTime = default(Time);
                        Time goldTime    = default(Time);

                        try
                        {
                            pbSplitTime.RealTime = TimeSpan.Parse(Unescape(splitInfo[1]));
                        }
                        catch
                        {
                            try
                            {
                                pbSplitTime.RealTime = TimeSpan.Parse(Unescape("0:" + splitInfo[1]));
                            }
                            catch
                            {
                                pbSplitTime.RealTime = TimeSpan.Parse(Unescape("0:0:" + splitInfo[1]));
                            }
                        }

                        try
                        {
                            goldTime.RealTime = TimeSpan.Parse(Unescape(splitInfo[2]));
                        }
                        catch
                        {
                            try
                            {
                                goldTime.RealTime = TimeSpan.Parse(Unescape("0:" + splitInfo[2]));
                            }
                            catch
                            {
                                goldTime.RealTime = TimeSpan.Parse(Unescape("0:0:" + splitInfo[2]));
                            }
                        }

                        if (pbSplitTime.RealTime == TimeSpan.Zero)
                        {
                            pbSplitTime.RealTime = null;
                        }

                        if (goldTime.RealTime == TimeSpan.Zero)
                        {
                            goldTime.RealTime = null;
                        }

                        var realIconPath = "";
                        if (splitInfo.Length > 3)
                        {
                            realIconPath = Unescape(splitInfo[3]);
                        }
                        Image icon = null;
                        if (realIconPath.Length > 0)
                        {
                            try
                            {
                                using (var imageStream = File.OpenRead(realIconPath))
                                {
                                    icon = Image.FromStream(imageStream);
                                }
                            }
                            catch (Exception e)
                            {
                                Log.Error(e);
                            }
                        }
                        run.AddSegment(Unescape(splitInfo[0]), pbSplitTime, goldTime, icon);
                    }
                }
            }

            return(run);
        }
Exemplo n.º 32
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var run = new Run(factory);

            var iconsList = new List <Image>();

            var reader = new StreamReader(Stream);

            var oldRunExists = false;

            string line;

            while ((line = reader.ReadLine()) != null)
            {
                if (line.Length > 0)
                {
                    if (line.StartsWith("Title="))
                    {
                        run.CategoryName = line.Substring("Title=".Length);
                    }
                    else if (line.StartsWith("Attempts="))
                    {
                        run.AttemptCount = Int32.Parse(line.Substring("Attempts=".Length));
                    }
                    else if (line.StartsWith("Offset="))
                    {
                        run.Offset = new TimeSpan(0, 0, 0, 0, -Int32.Parse(line.Substring("Offset=".Length)));
                    }
                    else if (line.StartsWith("Size="))
                    {
                        //Ignore
                    }
                    else if (line.StartsWith("Icons="))
                    {
                        var iconsString = line.Substring("Icons=".Length);
                        iconsList.Clear();
                        foreach (var iconPath in iconsString.Split(','))
                        {
                            var   realIconPath = iconPath.Substring(1, iconPath.Length - 2);
                            Image icon         = null;
                            if (realIconPath.Length > 0)
                            {
                                try
                                {
                                    icon = Image.FromFile(realIconPath);
                                }
                                catch (Exception e)
                                {
                                    Log.Error(e);
                                }
                            }
                            iconsList.Add(icon);
                        }
                    }
                    else //must be a split Kappa
                    {
                        var  splitInfo   = line.Split(',');
                        Time pbSplitTime = new Time();
                        Time goldTime    = new Time();
                        Time oldRunTime  = new Time();
                        pbSplitTime.RealTime = TimeSpan.FromSeconds(Convert.ToDouble(splitInfo[2], CultureInfo.InvariantCulture.NumberFormat));
                        goldTime.RealTime    = TimeSpan.FromSeconds(Convert.ToDouble(splitInfo[3], CultureInfo.InvariantCulture.NumberFormat));
                        oldRunTime.RealTime  = TimeSpan.FromSeconds(Convert.ToDouble(splitInfo[1], CultureInfo.InvariantCulture.NumberFormat));

                        if (pbSplitTime.RealTime == TimeSpan.Zero)
                        {
                            pbSplitTime.RealTime = null;
                        }

                        if (goldTime.RealTime == TimeSpan.Zero)
                        {
                            goldTime.RealTime = null;
                        }

                        if (oldRunTime.RealTime == TimeSpan.Zero)
                        {
                            oldRunTime.RealTime = null;
                        }
                        else
                        {
                            oldRunExists = true;
                        }

                        run.AddSegment(splitInfo[0], pbSplitTime, goldTime);
                        run.Last().Comparisons["Old Run"] = oldRunTime;
                    }
                }
            }

            if (oldRunExists)
            {
                run.CustomComparisons.Add("Old Run");
            }


            for (var i = 0; i < iconsList.Count; ++i)
            {
                run[i].Icon = iconsList[i];
            }

            return(run);
        }
Exemplo n.º 33
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var run = new Run(factory);

            var reader = new StreamReader(Stream);
            
            var line = reader.ReadLine();
            var titleInfo = line.Split(',');
            //Title Stuff here, do later
            run.CategoryName = Unescape(titleInfo[0]);
            run.AttemptCount = int.Parse(titleInfo[1]);
            while ((line = reader.ReadLine()) != null)
            {
                if (line.Length > 0)
                {
                    var splitInfo = line.Split(',');
                    Time pbSplitTime = new Time();
                    Time goldTime = new Time();

                    try
                    {
                        pbSplitTime.RealTime = TimeSpan.Parse(splitInfo[1]);
                    }
                    catch
                    {
                        try
                        {
                            pbSplitTime.RealTime = TimeSpan.Parse("0:" + splitInfo[1]);
                        }
                        catch
                        {
                            pbSplitTime.RealTime = TimeSpan.Parse("0:0:" + splitInfo[1]);
                        }
                    }

                    try
                    {
                        goldTime.RealTime = TimeSpan.Parse(splitInfo[2]);
                    }
                    catch 
                    {
                        try
                        {
                            goldTime.RealTime = TimeSpan.Parse("0:" + splitInfo[2]);
                        }
                        catch
                        {
                            goldTime.RealTime = TimeSpan.Parse("0:0:" + splitInfo[2]);
                        }
                    }

                    if (pbSplitTime.RealTime == TimeSpan.Zero)
                        pbSplitTime.RealTime = null;

                    if (goldTime.RealTime == TimeSpan.Zero)
                        goldTime.RealTime = null;

                    var realIconPath = "";
                    if (splitInfo.Length > 3)
                        realIconPath = Unescape(splitInfo[3]);
                    Image icon = null;
                    if (realIconPath.Length > 0)
                    {
                        try
                        {
                            using (var stream = File.OpenRead(realIconPath))
                            {
                                icon = Image.FromStream(stream);
                            }
                        }
                        catch (Exception e)
                        {
                            Log.Error(e);
                        }
                    }
                    run.AddSegment(Unescape(splitInfo[0]), pbSplitTime, goldTime, icon);
                }
                else
                {
                    break;
                }
            }

            return run;
        }
Exemplo n.º 34
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);
        }
Exemplo n.º 35
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;
        }
Exemplo n.º 36
0
 public IRun Create(IComparisonGeneratorsFactory factory)
 {
     var formatter = new BinaryFormatter();
     return formatter.Deserialize(Stream) as IRun;
 }
Exemplo n.º 37
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var run = new Run(factory);

            var iconsList = new List<Image>();

            var reader = new StreamReader(Stream);

            var oldRunExists = false;

            string line;
            while ((line = reader.ReadLine()) != null)
            {
                if (line.Length > 0)
                {
                    if (line.StartsWith("Title="))
                    {
                        run.CategoryName = line.Substring("Title=".Length);
                    }
                    else if (line.StartsWith("Attempts="))
                    {
                        run.AttemptCount = int.Parse(line.Substring("Attempts=".Length));
                    }
                    else if (line.StartsWith("Offset="))
                    {
                        run.Offset = new TimeSpan(0, 0, 0, 0, -int.Parse(line.Substring("Offset=".Length)));
                    }
                    else if (line.StartsWith("Size="))
                    {
                        //Ignore
                    }
                    else if (line.StartsWith("Icons="))
                    {
                        var iconsString = line.Substring("Icons=".Length);
                        iconsList.Clear();
                        foreach (var iconPath in iconsString.Split(','))
                        {
                            var realIconPath = iconPath.Substring(1, iconPath.Length - 2);
                            Image icon = null;
                            if (realIconPath.Length > 0) 
                            {
                                try
                                {
                                    icon = Image.FromFile(realIconPath);
                                }
                                catch (Exception e)
                                {
                                    Log.Error(e);
                                }
                            }
                            iconsList.Add(icon);
                        }
                    }
                    else //must be a split Kappa
                    {
                        var splitInfo = line.Split(',');
                        Time pbSplitTime = new Time();
                        Time goldTime = new Time();
                        Time oldRunTime = new Time();
                        pbSplitTime.RealTime = TimeSpan.FromSeconds(Convert.ToDouble(splitInfo[2], CultureInfo.InvariantCulture.NumberFormat));
                        goldTime.RealTime = TimeSpan.FromSeconds(Convert.ToDouble(splitInfo[3], CultureInfo.InvariantCulture.NumberFormat));
                        oldRunTime.RealTime = TimeSpan.FromSeconds(Convert.ToDouble(splitInfo[1], CultureInfo.InvariantCulture.NumberFormat));

                        if (pbSplitTime.RealTime == TimeSpan.Zero)
                            pbSplitTime.RealTime = null;

                        if (goldTime.RealTime == TimeSpan.Zero)
                            goldTime.RealTime = null;

                        if (oldRunTime.RealTime == TimeSpan.Zero)
                            oldRunTime.RealTime = null;
                        else
                            oldRunExists = true;
                            
                        run.AddSegment(splitInfo[0], pbSplitTime, goldTime);
                        run.Last().Comparisons["Old Run"] = oldRunTime;
                    }
                }
            }

            if (oldRunExists)
                run.CustomComparisons.Add("Old Run");


            for (var i = 0; i < iconsList.Count; ++i)
            {
                run[i].Icon = iconsList[i];
            }

            return run;
        }
Exemplo n.º 38
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);
        }
Exemplo n.º 39
0
        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var chapters = new Dictionary <string, string[]>()
            {
                {
                    "Chapter 1 - The Courtesy Call",
                    new []
                    {
                        "sp_a1_intro1",
                        "sp_a1_intro2",
                        "sp_a1_intro3",
                        "sp_a1_intro4",
                        "sp_a1_intro5",
                        "sp_a1_intro6",
                        "sp_a1_intro7",
                        "sp_a1_wakeup",
                        "sp_a2_intro"
                    }
                },
                {
                    "Chapter 2 - The Cold Boot",
                    new []
                    {
                        "sp_a2_laser_intro",
                        "sp_a2_laser_stairs",
                        "sp_a2_dual_lasers",
                        "sp_a2_laser_over_goo",
                        "sp_a2_catapult_intro",
                        "sp_a2_trust_fling",
                        "sp_a2_pit_flings",
                        "sp_a2_fizzler_intro"
                    }
                },
                {
                    "Chapter 3 - The Return",
                    new []
                    {
                        "sp_a2_sphere_peek",
                        "sp_a2_ricochet",
                        "sp_a2_bridge_intro",
                        "sp_a2_bridge_the_gap",
                        "sp_a2_turret_intro",
                        "sp_a2_laser_relays",
                        "sp_a2_turret_blocker",
                        "sp_a2_laser_vs_turret",
                        "sp_a2_pull_the_rug",
                    }
                },
                {
                    "Chapter 4 - The Surprise",
                    new []
                    {
                        "sp_a2_column_blocker",
                        "sp_a2_laser_chaining",
                        "sp_a2_triple_laser",
                        "sp_a2_bts1",
                        "sp_a2_bts2",
                    }
                },
                {
                    "Chapter 5 - The Escape",
                    new []
                    {
                        "sp_a2_bts3",
                        "sp_a2_bts4",
                        "sp_a2_bts5",
                        "sp_a2_bts6",
                        "sp_a2_core",
                    }
                },
                {
                    "Chapter 6 - The Fall",
                    new []
                    {
                        "sp_a3_00",
                        "sp_a3_01",
                        "sp_a3_03",
                        "sp_a3_jump_intro",
                        "sp_a3_bomb_flings",
                        "sp_a3_crazy_box",
                        "sp_a3_transition01",
                    }
                },
                {
                    "Chapter 7 - The Reunion",
                    new []
                    {
                        "sp_a3_speed_ramp",
                        "sp_a3_speed_flings",
                        "sp_a3_portal_intro",
                        "sp_a3_end",
                    }
                },
                {
                    "Chapter 8 - The Itch",
                    new []
                    {
                        "sp_a4_intro",
                        "sp_a4_tb_intro",
                        "sp_a4_tb_trust_drop",
                        "sp_a4_tb_wall_button",
                        "sp_a4_tb_polarity",
                        "sp_a4_tb_catch",
                        "sp_a4_stop_the_box",
                        "sp_a4_laser_catapult",
                        "sp_a4_laser_platform",
                        "sp_a4_speed_tb_catch",
                        "sp_a4_jump_polarity",
                    }
                },
                {
                    "Chapter 9 - The Part Where...",
                    new []
                    {
                        "sp_a4_finale1",
                        "sp_a4_finale2",
                        "sp_a4_finale3",
                        "sp_a4_finale4",
                        //"sp_a5_credits",
                    }
                }
            };

            var run = new Run(factory);

            run.GameName     = "Portal 2";
            run.CategoryName = "Any%";

            var reader = new StreamReader(Stream);

            var lines = reader
                        .ReadToEnd()
                        .Split('\n')
                        .Select(x => x.Replace("\r", ""))
                        .Skip(1)
                        .Select(x => x.Split(','))
                        .ToArray();

            var aggregateTicks = 0;

            foreach (var chapter in chapters)
            {
                foreach (var map in chapter.Value)
                {
                    //Force it to break, if the splits aren't there
                    lines.First(x => x[0] == map);

                    foreach (var mapLine in lines.Where(x => x[0] == map))
                    {
                        var mapTicks = int.Parse(mapLine[2], CultureInfo.InvariantCulture)
                                       - int.Parse(mapLine[1], CultureInfo.InvariantCulture);
                        aggregateTicks += mapTicks;
                    }
                }

                var timeSpan    = TimeSpan.FromSeconds(aggregateTicks / 60.0);
                var chapterTime = new Time(timeSpan, timeSpan);

                run.AddSegment(chapter.Key, chapterTime);
            }

            return(run);
        }