示例#1
0
        private void OnBuildDriveButtonMenu(object sender, EventArgs e)
        {
            try
            {
                System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();

                tsbDrives.DropDownItems.Clear();
                ilDrives.Images.Clear();

                foreach (System.IO.DriveInfo di in drives)
                {
                    string name = string.Empty;
                    string label = string.Empty;
                    string format = string.Empty;
                    string freeSpace = string.Empty;
                    string ready = string.Empty;

                    try { name = di.Name.ToUpperInvariant(); }
                    catch { }

                    try { label = di.VolumeLabel; }
                    catch { }

                    try { format = di.DriveFormat; }
                    catch { }

                    try { freeSpace = ((double)(di.AvailableFreeSpace) / (1024 * 1024)).ToString("F"); }
                    catch { }

                    try { ready = (di.IsReady) ? Translator.Translate("TXT_READY") : Translator.Translate("TXT_NOT_READY"); }
                    catch { }

                    if (string.IsNullOrEmpty(name))
                        name = Translator.Translate("TXT_NO_NAME");
                    if (string.IsNullOrEmpty(label))
                        label = Translator.Translate("TXT_NO_LABEL");
                    if (string.IsNullOrEmpty(format))
                        format = Translator.Translate("TXT_FORMAT_UNKNOWN");
                    if (string.IsNullOrEmpty(freeSpace))
                        freeSpace = "0";
                    if (string.IsNullOrEmpty(ready))
                        ready = Translator.Translate("TXT_NOT_READY");

                    ilDrives.Images.Add(ImageProvider.GetIcon(name, false));

                    OPMToolStripDropDownMenuItem tsi = new OPMToolStripDropDownMenuItem(tsbDrives);
                    tsi.ImageScaling = ToolStripItemImageScaling.None;

                    // "{0}    [{1}][{2}][{3} MB free][{4}]"
                    tsi.Text = Translator.Translate("TXT_DRIVE_DESC_FORMAT", name, label, format, freeSpace, ready);
                    
                    tsi.Tag = name;
                    tsi.Image = ilDrives.Images[ilDrives.Images.Count - 1];

                    tsbDrives.DropDownItems.Add(tsi);
                }
            }
            catch(Exception ex)
            {
                ErrorDispatcher.DispatchError(ex);
            }
        }
示例#2
0
        private void OnBuildFavoritesMenu(object sender, EventArgs e)
        {
            try
            {
                ToolStripDropDownItem tsmi = sender as ToolStripDropDownItem;
                if (tsmi == null || tsmi.DropDownItems == null || tsmi.DropDownItems.Count < 2) 
                    return;

                ilFavorites.Images.Clear();

                // Clear favorites items
                List<ToolStripItem> itemsToClear = new List<ToolStripItem>();
                foreach (ToolStripItem child in tsmi.DropDownItems)
                {
                    if ((child as ToolStripSeparator) != null || child.Tag != null)
                        continue;

                    itemsToClear.Add(child);
                }

                foreach (ToolStripItem itemToClear in itemsToClear)
                {
                    tsmi.DropDownItems.Remove(itemToClear);
                }

                List<string> favPaths = ProTONEConfig.GetFavoriteFolders("FavoriteFolders");
                if (favPaths != null && favPaths.Count > 0)
                {
                    foreach (string path in favPaths)
                    {
                        if (Directory.Exists(path))
                        {
                            OPMToolStripDropDownMenuItem tsi = new OPMToolStripDropDownMenuItem(tsbFavorites);
                            tsi.Text = path;
                            tsi.Click += new EventHandler(OnFavoriteChosen);
                            tsi.Image = ilFavorites.Images[GetIcon(path)];
                            tsi.ImageScaling = ToolStripItemImageScaling.None;

                            tsmi.DropDownItems.Add(tsi);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorDispatcher.DispatchError(ex);
            }
        }