Beispiel #1
0
 private void Disk_Clicked(object sender, EventArgs e)
 {
     try
     {
         ToolStripRadioButtonMenuItem disk = (ToolStripRadioButtonMenuItem)sender;
         if (currentDisk.InstanceName == (string)disk.Tag)
         {
             return;
         }
         string tmp = currentDisk.InstanceName;
         if (worker != null)
         {
             worker.CancelAsync();
         }
         if (currentDisk != null)
         {
             currentDisk.Dispose();
         }
         currentDisk = new PhysicalDisk((string)disk.Tag);
         Settings.Default.LastSelectedDrive = currentDisk.InstanceName;
         Settings.Default.Save();
         logger.Info(string.Format("Changed to {0}", currentDisk.InstanceName));
     }
     catch (Exception exception)
     {
         logger.Error(exception);
         Shutdown();
     }
 }
Beispiel #2
0
        protected override void OnCheckedChanged(EventArgs e)
        {
            base.OnCheckedChanged(e);

            // If this item is no longer in the checked state or if its
            // parent has not yet been initialized, do nothing.
            if (!Checked || this.Parent == null)
            {
                return;
            }

            // Clear the checked state for all siblings.
            foreach (ToolStripItem item in Parent.Items)
            {
                ToolStripRadioButtonMenuItem radioItem =
                    item as ToolStripRadioButtonMenuItem;

                if (radioItem != null && radioItem != this && radioItem.Checked)
                {
                    radioItem.Checked = false;

                    // Only one item can be selected at a time,
                    // so there is no need to continue.
                    return;
                }
            }
        }
Beispiel #3
0
        private void UpdateIntervalItem_Clicked(object sender, EventArgs e)
        {
            try
            {
                ToolStripRadioButtonMenuItem updateIntervalItem = (ToolStripRadioButtonMenuItem)sender;
                int updateInterval = (int)updateIntervalItem.Tag;
                Settings.Default.UpdateInterval = updateInterval;
                Settings.Default.Save();

                logger.Info(string.Format("Update interval is changed to {0:#,0}ms.", updateInterval));
            }
            catch (Exception exception)
            {
                logger.Error(exception);
                if (Exit_Clicked != null)
                {
                    Exit_Clicked(this, e);
                }
            }
        }
Beispiel #4
0
        public ContextMenuStrip Create(ref PhysicalDisk currentDisk)
        {
            try
            {
                ToolStripMenuItem disks         = new ToolStripMenuItem(Resources.SelectDisk);
                List <string>     instanceNames = PhysicalDisk.GetPerformableDiskInstanceNames(IgnoreDriveType);

                foreach (string instanceName in instanceNames)
                {
                    ToolStripRadioButtonMenuItem disk = new ToolStripRadioButtonMenuItem(Regex.Replace(instanceName, @"\d\s", ""));
                    disk.Click += Disk_Clicked;
                    disk.Tag    = instanceName;

                    if ((string.IsNullOrEmpty(Settings.Default.LastSelectedDrive) && disks.DropDownItems.Count == 0) ||
                        (Settings.Default.LastSelectedDrive == instanceName))
                    {
                        disk.Checked = true;
                        currentDisk  = new PhysicalDisk(instanceName);
                    }

                    disks.DropDownItems.Add(disk);
                }

                if (disks.DropDownItems.Count > 0 &&
                    instanceNames.Count > 0 &&
                    string.IsNullOrEmpty(currentDisk.InstanceName))
                {
                    ((ToolStripRadioButtonMenuItem)disks.DropDownItems[0]).Checked = true;
                    currentDisk = new PhysicalDisk(instanceNames[0]);
                    Settings.Default.LastSelectedDrive = currentDisk.InstanceName;
                    Settings.Default.Save();
                }

                ToolStripMenuItem interval = new ToolStripMenuItem(Resources.UpdateInterval);

                for (int i = 100; i <= 1000; i += 100)
                {
                    ToolStripRadioButtonMenuItem updateIntervalItem = new ToolStripRadioButtonMenuItem(string.Format("{0:#,0}", i));
                    updateIntervalItem.Checked = i == Settings.Default.UpdateInterval;
                    updateIntervalItem.Tag     = i;
                    updateIntervalItem.Click  += UpdateIntervalItem_Clicked;
                    interval.DropDownItems.Add(updateIntervalItem);
                }

                ToolStripMenuItem ignoreDriveType = new ToolStripMenuItem(Resources.IgnoreDriveType);
                ignoreDriveType.Checked = Settings.Default.IgnoreDriveType;
                ignoreDriveType.Click  += IgnoreDriveType_Clicked;

                ToolStripMenuItem allowMultipleInstances = new ToolStripMenuItem(Resources.AllowMultipleInstances);
                allowMultipleInstances.Checked = Settings.Default.AllowMutipleInstances;
                allowMultipleInstances.Click  += AllowMultipleInstances_Clicked;

                //ToolStripMenuItem addShortcutToStartup = new ToolStripMenuItem(Resources.AddShortcutToStartup);
                //addShortcutToStartup.Checked = Settings.Default.AddShortcutToStartup;
                //addShortcutToStartup.Click += AddShortcutToStartup_Clicked;
                //if (addShortcutToStartup.Checked) AutoStart.CreateStartupShortcut(); else AutoStart.RemoveStartupShortcut();

                ToolStripMenuItem addRunKeyToRegistry = new ToolStripMenuItem(Resources.AddRunKeyToRegistry);
                addRunKeyToRegistry.Checked = Settings.Default.AddRunKeyToRegistry;
                addRunKeyToRegistry.Click  += AddRunKeyToRegistry_Clicked;
                if (addRunKeyToRegistry.Checked)
                {
                    AutoStart.CreateRunKey();
                }
                else
                {
                    AutoStart.RemoveRunKey();
                }

                ToolStripMenuItem settings = new ToolStripMenuItem(Resources.Settings);
                settings.DropDownItems.AddRange(new ToolStripItem[] { interval, ignoreDriveType, allowMultipleInstances, addRunKeyToRegistry });

                ToolStripMenuItem exit = new ToolStripMenuItem(Resources.Exit);
                exit.Click += Exit_Clicked;

                ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
                contextMenuStrip.Items.AddRange(new ToolStripItem[] { disks, settings, new ToolStripSeparator(), exit });

                return(contextMenuStrip);
            }
            catch
            {
                throw;
            }
        }