コード例 #1
0
        private static void InitializeRegistryEntry()
        {
            //Initialize shortcut helper
            ShortcutHelper shortcut = new ShortcutHelper();

            RegisterHelper.shortcut = shortcut;

            //Initialize registry entry if needed
            try
            {
                ConfigStorage configStorage = ConfigStorage.Global;
                if (configStorage == null)
                {
                    return;
                }

                string redirectPath = configStorage.GetValue(Config.ConfigRedirectRegistryEntryKey, Config.ConfigDefaultRedirectRegistryEntryValue);
                if (redirectPath != null)
                {
                    redirectPath = redirectPath.Trim();
                }
                if (redirectPath != null && redirectPath.Length > 0)
                {
                    string fullRedirectPath = FileHelper.GetByRelativePath(redirectPath);
                    if (fullRedirectPath != null)
                    {
                        RegisterHelper.SetRedirectPath(fullRedirectPath, false);
                    }
                }

                bool setRegistryEntry = configStorage.GetBool(Config.ConfigEnableRegistryEntryKey, Config.ConfigDefaultEnableRegistryEntryValue);

                if (setRegistryEntry)
                {
                    bool hasEntry = RegisterHelper.HasEntryWithCurrentPath();
                    if (!hasEntry)
                    {
                        RegisterHelper.PutEntry();
                    }
                }

                if (!setRegistryEntry)
                {
                    bool hasEntry = RegisterHelper.HasEntry();
                    if (hasEntry)
                    {
                        RegisterHelper.RemoveEntry();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
コード例 #2
0
        public RegisterWindow()
        {
            //Initialize storages
            ConfigStorage = ConfigStorage.Global;

            //Initialize Window
            InitializeComponent();

            //Setup values
            RedirectPath = ConfigStorage.GetValue(Config.ConfigRedirectRegistryEntryKey, Config.ConfigDefaultRedirectRegistryEntryValue);
            if (RedirectPath == null)
            {
                RedirectPath = "";
            }
            RedirectPath = RedirectPath.Trim();

            //Setup elements
            TitleLabel.Content = Title;

            RedirectPathTextBox.Text = RedirectPath;

            //Setup drag behavior
            ToolbarLayout.MouseDown += (object sender, MouseButtonEventArgs args) =>
            {
                DragMove();
            };

            //Setup close behavior
            CloseButton.Click += (object sender, RoutedEventArgs args) =>
            {
                Close();
            };

            KeyDown += (object sender, KeyEventArgs args) =>
            {
                if (args.Key == Key.Return)
                {
                    args.Handled = true;

                    OnApply();
                    Close();
                }

                if (args.Key == Key.Escape)
                {
                    Close();
                }
            };

            //Setup events
            EnableButton.Click += (object sender, RoutedEventArgs args) =>
            {
                if (ConfigStorage == null)
                {
                    return;
                }

                OnApply();

                try
                {
                    ConfigStorage.SetBool(Config.ConfigEnableRegistryEntryKey, true);
                    RegisterHelper.PutEntry();

                    Update();
                } catch (Exception e)
                {
                }
            };

            DisableButton.Click += (object sender, RoutedEventArgs args) =>
            {
                if (ConfigStorage == null)
                {
                    return;
                }

                try
                {
                    ConfigStorage.SetBool(Config.ConfigEnableRegistryEntryKey, false);
                    RegisterHelper.RemoveEntry();

                    Update();
                }
                catch (Exception e)
                {
                }
            };

            AcceptButton.Click += (object sender, RoutedEventArgs args) =>
            {
                OnApply();
                Close();
            };

            //Load
            Update();
        }