예제 #1
0
        public async Task <HotkeyProfile> DeleteProfileAsync(int profileNum)
        {
            int profileIdx = profileNum - 1;

            HotkeyProfile deletedProfile = Profiles[profileIdx];

            List <Task <bool> > tasks = new List <Task <bool> >();

            foreach (var profile in Profiles)
            {
                tasks.Add(_jsonSavefileManager.DeleteIfExistsAsync($"profile{profile.ProfileNum}"));
            }

            await Task.WhenAll(tasks).ConfigureAwait(false);

            Profiles.RemoveAt(profileIdx);

            for (int i = profileIdx; i < ProfileCount; i++)
            {
                Profiles[i].ProfileNum -= 1;
            }

            await SaveAllProfileAsync().ConfigureAwait(false);

            return(deletedProfile);
        }
예제 #2
0
        public Task HandleAsync(ProfileDeletedEvent message, CancellationToken cancellationToken)
        {
            Profile = null;
            TriggerHotkeyPairs.Clear();

            return(Task.CompletedTask);
        }
예제 #3
0
        /// <summary>
        /// On the first activation, activates default profile. (profile1)
        /// </summary>
        /// <returns>Activated profile</returns>
        private async Task ActivateAsync(int profileNum)
        {
            _currentHookingProfile = _profileManager.FindProfileOrDefault(profileNum);

            var switchKeys = _profileSwitchKeyTable.SwitchKeyTable[_currentHookingProfile.ProfileNum - 1];

            for (int i = 1; i <= _profileManager.ProfileCount; i++)
            {
                if (i == _currentHookingProfile.ProfileNum)
                {
                    continue;
                }

                _swtichKeys.Add(switchKeys[i - 1], i);
            }

            foreach (var hotkey in _currentHookingProfile.Hotkeys)
            {
                _profileHotkeys.Add(hotkey.Trigger.Key, hotkey);
            }

            var registeredKeys = CreateRegisteredKeyDictionary();

            _keyboardHooker.StartHook(registeredKeys);

            await _eventAggregator.PublishOnUIThreadAsync(new HookStateChangeEvent
            {
                HookState     = HookState.Hooking,
                HotkeyProfile = _currentHookingProfile
            });
        }
예제 #4
0
        private void SetTriggerHotkeyPairs(HotkeyProfile profile)
        {
            TriggerHotkeyPairs.Clear();

            foreach (var hotkey in profile.Hotkeys)
            {
                TriggerHotkeyPairs.Add(hotkey.Trigger.Key, hotkey);
            }
        }
예제 #5
0
        public Task HandleAsync(ProfileChangedEvent message, CancellationToken cancellationToken)
        {
            //HACK : Profiel = message.Profile가 먼저 실행되면 왜인지는 모르겠으나, OnProfileChanged가 먼저 fire되면서
            //다소 이상한 동작을 함.
            SetTriggerHotkeyPairs(message.Profile);

            Profile = message.Profile;

            return(Task.CompletedTask);
        }
예제 #6
0
        public ProfileSwitchKeyTableRowModel(ProfileSwitchKeyTableManager profileSwitchKeyTable, HotkeyProfile profile, int profileCount)
        {
            _profileSwitchKeyTable = profileSwitchKeyTable;
            _profile = profile;

            for (int i = 1; i <= profileCount; i++)
            {
                SwitchKeyCells.Add(new SwitchKeyCellModel(profileSwitchKeyTable, profile.ProfileNum, i));
            }
        }
예제 #7
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            AppDomain.CurrentDomain.ProcessExit += (o, e) => OnExit();
            HotkeyProfile.CreateAll(false);
            KeyHandler.StartInput();

            Application.Run();
        }
예제 #8
0
        public HotkeyProfile CreateNewProfile(string profileName = null)
        {
            HotkeyProfile profile = new HotkeyProfile
            {
                ProfileNum  = ProfileCount + 1,
                ProfileName = profileName
            };

            Profiles.Add(profile);

            return(profile);
        }
예제 #9
0
        void DoSplit()
        {
            // make split times accurate
            _timer.CurrentState.SetGameTime(this.GameTime);

            HotkeyProfile profile = _timer.CurrentState.Settings.HotkeyProfiles[_timer.CurrentState.CurrentHotkeyProfile];
            bool          before  = profile.DoubleTapPrevention;

            profile.DoubleTapPrevention = false;
            _timer.Split();
            profile.DoubleTapPrevention = before;
        }
예제 #10
0
        public async Task InitializeAsync()
        {
            for (int i = 0; i < MAX_PROFILE_NUM; i++)
            {
                HotkeyProfile profile = await LoadProfileFromFileAsync(i + 1).ConfigureAwait(false);

                if (profile == null)
                {
                    break;
                }

                Profiles.Add(profile);
            }
        }
예제 #11
0
        // what is this?
        // for the stanley parable the precision of splits needs to be near-perfect so some endings must have an end offset
        // however because endoffsetticks was only meant to be used at the end of a run, that means
        // when using it mid-run the timer will go back into the past to split then never get bumped forward again,
        // losing a few ticks

        void DoSplitandRevertOffset()
        {
            // make split times accurate
            _timer.CurrentState.SetGameTime(this.GameTime);

            HotkeyProfile profile = _timer.CurrentState.Settings.HotkeyProfiles[_timer.CurrentState.CurrentHotkeyProfile];
            bool          before  = profile.DoubleTapPrevention;

            profile.DoubleTapPrevention = false;
            _timer.CurrentState.SetGameTime(this.GameTime - TimeSpan.FromSeconds(_tickOffset * _intervalPerTick));
            _timer.Split();
            _timer.CurrentState.SetGameTime(this.GameTime);
            profile.DoubleTapPrevention = before;
        }
예제 #12
0
        private async Task DeactivateAsync()
        {
            _keyboardHooker.StopHook();

            _lastHookedProfileNum = _currentHookingProfile.ProfileNum;

            //Delete cache for case where user modified profile hotkeys while deactivated
            _profileHotkeys.Clear();
            _swtichKeys.Clear();
            _currentHookingProfile = null;

            //Only enables activation key
            _keyboardHooker.StartHook(_activationKey, null);

            await _eventAggregator.PublishOnUIThreadAsync(new HookStateChangeEvent
            {
                HookState = HookState.UnHooking,
            });
        }
예제 #13
0
 public ProfileStateModel(HotkeyProfile profile, IAsyncJsonFileManager jsonSavefileManager)
 {
     Profile = profile;
     _jsonSavefileManager = jsonSavefileManager;
 }
예제 #14
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);
        }
예제 #15
0
 public async Task SaveProfileAsync(HotkeyProfile profile)
 {
     await _jsonSavefileManager.SaveAsync(profile, $"profile{profile.ProfileNum}").ConfigureAwait(false);
 }