Ejemplo n.º 1
0
        public string ImportAsComparison(IRun run, Form form = null)
        {
            var splitDialog = new OpenFileDialog();

            var result = splitDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                var filePath = splitDialog.FileName;

                using (var stream = File.OpenRead(filePath))
                {
                    var runFactory = new StandardFormatsRunFactory();
                    var comparisonGeneratorsFactory = new StandardComparisonGeneratorsFactory();

                    runFactory.Stream   = stream;
                    runFactory.FilePath = filePath;

                    var imported = runFactory.Create(comparisonGeneratorsFactory);

                    var comparisonName = Path.GetFileNameWithoutExtension(splitDialog.FileName);
                    result = InputBox.Show(form, "Enter Comparison Name", "Name:", ref comparisonName);
                    if (result != DialogResult.Cancel)
                    {
                        return(run.AddComparisonWithNameInput(imported, comparisonName, form));
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        public IRun DownloadRunByUri(Uri uri, bool patchRun)
        {
            var id          = uri.LocalPath;
            var splitsIORun = GetV4RunById(id);
            var program     = splitsIORun.run.program as string;
            var downloadUri = GetSiteUri($"{id}/download/{program}");

            var request = WebRequest.Create(downloadUri);

            using (var response = request.GetResponse())
                using (var stream = response.GetResponseStream())
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        stream.CopyTo(memoryStream);
                        memoryStream.Seek(0, SeekOrigin.Begin);

                        var runFactory = new StandardFormatsRunFactory();

                        runFactory.Stream   = memoryStream;
                        runFactory.FilePath = null;

                        var run = runFactory.Create(new StandardComparisonGeneratorsFactory());
                        if (patchRun)
                        {
                            PatchRun(run, splitsIORun.run.srdc_id);
                        }
                        return(run);
                    }
                }
        }
Ejemplo n.º 3
0
        private static IRun LoadRunFromURL(string url, Form form = null)
        {
            try
            {
                var runFactory = new StandardFormatsRunFactory();
                var comparisonGeneratorsFactory = new StandardComparisonGeneratorsFactory();

                var uri  = new Uri(url);
                var host = uri.Host.ToLowerInvariant();
                if (host == "splits.io")
                {
                    return(SplitsIO.Instance.DownloadRunByUri(uri, true));
                }
                if (host == "www.speedrun.com" || host == "speedrun.com")
                {
                    var speedrunComRun = SpeedrunCom.Client.Runs.GetRunFromSiteUri(url);
                    if (speedrunComRun != null && speedrunComRun.SplitsAvailable)
                    {
                        var run = speedrunComRun.GetRun();
                        run.PatchRun(speedrunComRun);
                        return(run);
                    }
                }

                var request = WebRequest.Create(uri);

                using (var response = request.GetResponse())
                    using (var stream = response.GetResponseStream())
                        using (var memoryStream = new MemoryStream())
                        {
                            stream.CopyTo(memoryStream);
                            memoryStream.Seek(0, SeekOrigin.Begin);

                            runFactory.Stream   = memoryStream;
                            runFactory.FilePath = null;

                            try
                            {
                                return(runFactory.Create(comparisonGeneratorsFactory));
                            }
                            catch (Exception ex)
                            {
                                Log.Error(ex);
                                MessageBox.Show(form, "The selected file was not recognized as a splits file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                MessageBox.Show(form, "The splits file couldn't be downloaded.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(null);
        }
Ejemplo n.º 4
0
        private IRun LoadRunFromURL(string url, Form form = null)
        {
            try
            {
                var runFactory = new StandardFormatsRunFactory();
                var comparisonGeneratorsFactory = new StandardComparisonGeneratorsFactory();

                var uri = new Uri(url);
                if (uri.Host.ToLowerInvariant() == "splits.io" &&
                    uri.LocalPath.Length > 0 &&
                    !uri.LocalPath.Substring(1).Contains('/'))
                {
                    uri = new Uri(string.Format("{0}/download/livesplit", url));
                }
                if (uri.Host.ToLowerInvariant() == "ge.tt" &&
                    uri.LocalPath.Length > 0 &&
                    !uri.LocalPath.Substring(1).Contains('/'))
                {
                    uri = new Uri(string.Format("http://ge.tt/api/1/files{0}/0/blob?download", uri.LocalPath));
                }

                var request = WebRequest.Create(uri);
                using (var stream = request.GetResponse().GetResponseStream())
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        stream.CopyTo(memoryStream);
                        memoryStream.Seek(0, SeekOrigin.Begin);

                        runFactory.Stream   = memoryStream;
                        runFactory.FilePath = null;

                        try
                        {
                            return(runFactory.Create(comparisonGeneratorsFactory));
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex);
                            MessageBox.Show(form, "The selected file was not recognized as a splits file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                MessageBox.Show(form, "The splits file couldn't be downloaded.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(null);
        }
Ejemplo n.º 5
0
        public ISettings Create()
        {
            var document = new XmlDocument();

            document.Load(Stream);
            var settings = new StandardSettingsFactory().Create();

            var parent  = document["Settings"];
            var version = SettingsHelper.ParseAttributeVersion(parent);

            var keyStart = parent["SplitKey"];

            if (!string.IsNullOrEmpty(keyStart.InnerText))
            {
                settings.SplitKey = new KeyOrButton(keyStart.InnerText);
            }
            else
            {
                settings.SplitKey = null;
            }

            var keyReset = parent["ResetKey"];

            if (!string.IsNullOrEmpty(keyReset.InnerText))
            {
                settings.ResetKey = new KeyOrButton(keyReset.InnerText);
            }
            else
            {
                settings.ResetKey = null;
            }

            var keySkip = parent["SkipKey"];

            if (!string.IsNullOrEmpty(keySkip.InnerText))
            {
                settings.SkipKey = new KeyOrButton(keySkip.InnerText);
            }
            else
            {
                settings.SkipKey = null;
            }

            var keyUndo = parent["UndoKey"];

            if (!string.IsNullOrEmpty(keyUndo.InnerText))
            {
                settings.UndoKey = new KeyOrButton(keyUndo.InnerText);
            }
            else
            {
                settings.UndoKey = null;
            }

            settings.GlobalHotkeysEnabled = SettingsHelper.ParseBool(parent["GlobalHotkeysEnabled"]);
            settings.WarnOnReset          = SettingsHelper.ParseBool(parent["WarnOnReset"], settings.WarnOnReset);
            settings.DoubleTapPrevention  = SettingsHelper.ParseBool(parent["DoubleTapPrevention"], settings.DoubleTapPrevention);
            settings.LastTimingMethod     = SettingsHelper.ParseEnum <TimingMethod>(parent["LastTimingMethod"], settings.LastTimingMethod);
            settings.SimpleSumOfBest      = SettingsHelper.ParseBool(parent["SimpleSumOfBest"], settings.SimpleSumOfBest);
            settings.LastComparison       = SettingsHelper.ParseString(parent["LastComparison"], settings.LastComparison);
            settings.DeactivateHotkeysForOtherPrograms = SettingsHelper.ParseBool(parent["DeactivateHotkeysForOtherPrograms"], settings.DeactivateHotkeysForOtherPrograms);
            settings.HotkeyDelay      = SettingsHelper.ParseFloat(parent["HotkeyDelay"], settings.HotkeyDelay);
            settings.AgreedToSRLRules = SettingsHelper.ParseBool(parent["AgreedToSRLRules"], settings.AgreedToSRLRules);

            var recentLayouts = parent["RecentLayouts"];

            foreach (var layoutNode in recentLayouts.GetElementsByTagName("LayoutPath"))
            {
                var layoutElement = layoutNode as XmlElement;
                settings.RecentLayouts.Add(layoutElement.InnerText);
            }

            if (version > new Version(1, 0, 0, 0))
            {
                var keyPause = parent["PauseKey"];
                if (!string.IsNullOrEmpty(keyPause.InnerText))
                {
                    settings.PauseKey = new KeyOrButton(keyPause.InnerText);
                }
                else
                {
                    settings.PauseKey = null;
                }

                var keyToggle = parent["ToggleGlobalHotkeys"];
                if (!string.IsNullOrEmpty(keyToggle.InnerText))
                {
                    settings.ToggleGlobalHotkeys = new KeyOrButton(keyToggle.InnerText);
                }
                else
                {
                    settings.ToggleGlobalHotkeys = null;
                }
            }

            if (version >= new Version(1, 3))
            {
                var switchComparisonPrevious = parent["SwitchComparisonPrevious"];
                if (!string.IsNullOrEmpty(switchComparisonPrevious.InnerText))
                {
                    settings.SwitchComparisonPrevious = new KeyOrButton(switchComparisonPrevious.InnerText);
                }
                else
                {
                    settings.SwitchComparisonPrevious = null;
                }
                var switchComparisonNext = parent["SwitchComparisonNext"];
                if (!string.IsNullOrEmpty(switchComparisonNext.InnerText))
                {
                    settings.SwitchComparisonNext = new KeyOrButton(switchComparisonNext.InnerText);
                }
                else
                {
                    settings.SwitchComparisonNext = null;
                }

                settings.RaceViewer = RaceViewer.FromName(parent["RaceViewer"].InnerText);
            }

            if (version >= new Version(1, 4))
            {
                var activeAutoSplitters = parent["ActiveAutoSplitters"];
                foreach (var splitter in activeAutoSplitters.GetElementsByTagName("AutoSplitter").OfType <XmlElement>())
                {
                    settings.ActiveAutoSplitters.Add(splitter.InnerText);
                }
            }

            var recentSplits = parent["RecentSplits"];

            if (version >= new Version(1, 6))
            {
                foreach (var generatorNode in parent["ComparisonGeneratorStates"].ChildNodes.OfType <XmlElement>())
                {
                    settings.ComparisonGeneratorStates[generatorNode.GetAttribute("name")] = Boolean.Parse(generatorNode.InnerText);
                }

                foreach (var splitNode in recentSplits.GetElementsByTagName("SplitsFile"))
                {
                    var    splitElement = splitNode as XmlElement;
                    string gameName     = splitElement.GetAttribute("gameName");
                    string categoryName = splitElement.GetAttribute("categoryName");
                    var    path         = splitElement.InnerText;

                    var recentSplitsFile = new RecentSplitsFile(path, gameName, categoryName);
                    settings.RecentSplits.Add(recentSplitsFile);
                }
            }
            else
            {
                var comparisonsFactory = new StandardComparisonGeneratorsFactory();
                var runFactory         = new StandardFormatsRunFactory();

                foreach (var splitNode in recentSplits.GetElementsByTagName("SplitsPath"))
                {
                    var splitElement = splitNode as XmlElement;
                    var path         = splitElement.InnerText;

                    try
                    {
                        using (var stream = File.OpenRead(path))
                        {
                            runFactory.FilePath = path;
                            runFactory.Stream   = stream;
                            var run = runFactory.Create(comparisonsFactory);

                            var recentSplitsFile = new RecentSplitsFile(path, run.GameName, run.CategoryName);
                            settings.RecentSplits.Add(recentSplitsFile);
                        }
                    }
                    catch { }
                }
            }

            return(settings);
        }
Ejemplo n.º 6
0
        public ISettings Create()
        {
            var document = new XmlDocument();

            document.Load(Stream);
            var settings = new StandardSettingsFactory().Create();

            var parent  = document["Settings"];
            var version = ParseAttributeVersion(parent);

            settings.WarnOnReset      = ParseBool(parent["WarnOnReset"], settings.WarnOnReset);
            settings.SimpleSumOfBest  = ParseBool(parent["SimpleSumOfBest"], settings.SimpleSumOfBest);
            settings.LastComparison   = ParseString(parent["LastComparison"], settings.LastComparison);
            settings.AgreedToSRLRules = ParseBool(parent["AgreedToSRLRules"], settings.AgreedToSRLRules);

            var recentLayouts = parent["RecentLayouts"];

            foreach (var layoutNode in recentLayouts.GetElementsByTagName("LayoutPath"))
            {
                var layoutElement = layoutNode as XmlElement;
                settings.RecentLayouts.Add(layoutElement.InnerText);
            }

            if (version >= new Version(1, 3))
            {
                settings.RaceViewer = RaceViewer.FromName(parent["RaceViewer"].InnerText);
            }

            if (version >= new Version(1, 4))
            {
                var activeAutoSplitters = parent["ActiveAutoSplitters"];
                foreach (var splitter in activeAutoSplitters.GetElementsByTagName("AutoSplitter").OfType <XmlElement>())
                {
                    settings.ActiveAutoSplitters.Add(splitter.InnerText);
                }
            }

            var recentSplits = parent["RecentSplits"];

            if (version >= new Version(1, 6))
            {
                foreach (var generatorNode in parent["ComparisonGeneratorStates"].ChildNodes.OfType <XmlElement>())
                {
                    var comparisonName = generatorNode.GetAttribute("name");
                    if (settings.ComparisonGeneratorStates.ContainsKey(comparisonName))
                    {
                        settings.ComparisonGeneratorStates[comparisonName] = bool.Parse(generatorNode.InnerText);
                    }
                }

                foreach (var splitNode in recentSplits.GetElementsByTagName("SplitsFile"))
                {
                    var    splitElement = splitNode as XmlElement;
                    string gameName     = splitElement.GetAttribute("gameName");
                    string categoryName = splitElement.GetAttribute("categoryName");

                    var method = TimingMethod.RealTime;
                    if (version >= new Version(1, 6, 1))
                    {
                        method = (TimingMethod)Enum.Parse(typeof(TimingMethod), splitElement.GetAttribute("lastTimingMethod"));
                    }

                    var hotkeyProfile = HotkeyProfile.DefaultHotkeyProfileName;
                    if (version >= new Version(1, 8))
                    {
                        hotkeyProfile = splitElement.GetAttribute("lastHotkeyProfile");
                    }

                    var path = splitElement.InnerText;

                    var recentSplitsFile = new RecentSplitsFile(path, method, hotkeyProfile, gameName, categoryName);
                    settings.RecentSplits.Add(recentSplitsFile);
                }
            }
            else
            {
                var comparisonsFactory = new StandardComparisonGeneratorsFactory();
                var runFactory         = new StandardFormatsRunFactory();

                foreach (var splitNode in recentSplits.GetElementsByTagName("SplitsPath"))
                {
                    var splitElement = splitNode as XmlElement;
                    var path         = splitElement.InnerText;

                    try
                    {
                        using (var stream = File.OpenRead(path))
                        {
                            runFactory.FilePath = path;
                            runFactory.Stream   = stream;
                            var run = runFactory.Create(comparisonsFactory);

                            var recentSplitsFile = new RecentSplitsFile(path, run, TimingMethod.RealTime, HotkeyProfile.DefaultHotkeyProfileName);
                            settings.RecentSplits.Add(recentSplitsFile);
                        }
                    }
                    catch { }
                }
            }

            if (version >= new Version(1, 8))
            {
                settings.HotkeyProfiles.Clear();
                foreach (var hotkeyProfileNode in parent["HotkeyProfiles"].ChildNodes.OfType <XmlElement>())
                {
                    var hotkeyProfileName = hotkeyProfileNode.GetAttribute("name");
                    settings.HotkeyProfiles[hotkeyProfileName] = HotkeyProfile.FromXml(hotkeyProfileNode, version);
                }
            }
            else
            {
                var hotkeyProfile = HotkeyProfile.FromXml(parent, version);
                settings.HotkeyProfiles[HotkeyProfile.DefaultHotkeyProfileName] = hotkeyProfile;
            }

            LoadDrift(parent);

            return(settings);
        }