コード例 #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 static void SetUpdateInterval(long updateInterval)
        {
            ConfigStorage storage = ConfigStorage.Global;

            if (storage == null)
            {
                return;
            }

            storage.SetValue(Config.ConfigIntervalKey, updateInterval.ToString());
        }
コード例 #3
0
        //Static access methods
        public static long GetUpdateInterval()
        {
            ConfigStorage storage = ConfigStorage.Global;

            if (storage == null)
            {
                return(default(long));
            }

            long   defaultInterval       = Config.ConfigDefaultIntervalValue;
            string stringDefaultInterval = defaultInterval.ToString();

            string value = storage.GetValue(Config.ConfigIntervalKey, stringDefaultInterval);

            if (value == null)
            {
                return(default(long));
            }

            try
            {
                return(long.Parse(value));
            }
            catch (Exception e)
            {
            }

            try
            {
                return((long)int.Parse(value));
            }
            catch (Exception e)
            {
            }
            return(default(long));
        }
コード例 #4
0
        public ManagerWindow()
        {
            //Initialize
            StartHelper.Initialize();

            //Initialize storages
            ConfigStorage = ConfigStorage.Global;
            TaskStorage   = TaskStorage.Global;

            //Initialize Window
            InitializeComponent();

            //Hide window on startup
            Hide();

            //Create context menu for notify icon
            ContextMenu contextMenu = new ContextMenu();

            bool hasExitOption = false;

            if (ConfigStorage != null)
            {
                hasExitOption = ConfigStorage.GetBool(Config.ConfigEnableExitOptionKey, Config.ConfigDefaultEnableExitOptionValue);
            }

            if (hasExitOption)
            {
                MenuItem menuExitItem = new MenuItem();
                menuExitItem.Text   = "Exit";
                menuExitItem.Click += (object sender, EventArgs e) =>
                {
                    if (IconHelper != null)
                    {
                        IconHelper.Destroy();
                    }
                    if (BackgroundTask != null)
                    {
                        BackgroundTask.Stop();
                    }

                    //Exit application
                    if (System.Windows.Forms.Application.MessageLoop)
                    {
                        // WinForms app
                        System.Windows.Forms.Application.Exit();
                    }
                    else
                    {
                        // Console app
                        Environment.Exit(1);
                    }
                };
                contextMenu.MenuItems.Add(menuExitItem);
            }

            //Create notification icon in taskbar
            NotifyIconHelper.Data data = new NotifyIconHelper.Data();
            data.ContextMenu = contextMenu;

            if (ConfigStorage != null)
            {
                data.ShowAlways     = ConfigStorage.GetBool(Config.ConfigShowIconAlwaysKey, Config.ConfigDefaultShowIconAlwaysValue);
                data.DestroyOnClose = false;

                data.NoClickEvent = !ConfigStorage.GetBool(Config.ConfigEnableGuiKey, Config.ConfigDefaultEnableGuiValue);
                data.NoMenu       = false;

                data.NoBalloonTip = !ConfigStorage.GetBool(Config.ConfigEnableBalloonTipKey, Config.ConfigDefaultEnableBalloonTipValue);
            }

            data.Icon            = Properties.Resources.ic_application;
            data.BalloonTipTitle = Title;
            data.BalloonTipText  = "The app has been minimised. Click the tray icon to show.";
            data.Text            = Title;

            IconHelper = new NotifyIconHelper(this, data);
            IconHelper.Create();

            //Create background worker
            BackgroundTask = new BackgroundTask();
            BackgroundTask.Start();

            //Setup controls
            SetupControls();
        }
コード例 #5
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();
        }
コード例 #6
0
 public BackgroundTask() : base(ConfigStorage.GetUpdateInterval())
 {
 }