private void OnApply() { try { string newRedirectPath = RedirectPathTextBox.Text; if (newRedirectPath == null) { newRedirectPath = ""; } newRedirectPath = newRedirectPath.Trim(); if (RedirectPath != null && !RedirectPath.Equals(newRedirectPath)) { RedirectPath = newRedirectPath; if (ConfigStorage != null) { ConfigStorage.SetValue(Config.ConfigRedirectRegistryEntryKey, newRedirectPath); } RegisterHelper.SetRedirectPath(newRedirectPath, false); if (ConfigStorage != null) { bool registryEntryEnabled = ConfigStorage.GetBool(Config.ConfigEnableRegistryEntryKey, Config.ConfigDefaultEnableRegistryEntryValue); if (registryEntryEnabled) { RegisterHelper.PutEntry(); } } } } catch (Exception e) { } }
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); } }
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(); }