Пример #1
0
        private void LoadWinXItems()
        {
            string[] dirPaths = Directory.GetDirectories(WinXPath);
            Array.Reverse(dirPaths);
            bool sortable = AppConfig.WinXSortable;
            bool sorted   = false;

            foreach (string dirPath in dirPaths)
            {
                WinXGroupItem groupItem = new WinXGroupItem(dirPath);
                this.AddItem(groupItem);
                string[] lnkPaths;
                if (sortable)
                {
                    lnkPaths = GetSortedPaths(dirPath, out bool flag);
                    if (flag)
                    {
                        sorted = true;
                    }
                }
                else
                {
                    lnkPaths = Directory.GetFiles(dirPath, "*.lnk");
                    Array.Reverse(lnkPaths);
                }
                foreach (string path in lnkPaths)
                {
                    WinXItem winXItem = new WinXItem(path, groupItem);
                    winXItem.BtnMoveDown.Visible = winXItem.BtnMoveUp.Visible = sortable;
                    this.AddItem(winXItem);
                }
                groupItem.IsFold = true;
            }
            if (sorted)
            {
                ExplorerRestarter.Show();
                MessageBoxEx.Show(AppString.Message.WinXSorted);
            }
        }
Пример #2
0
        private void AddNewItem()
        {
            NewItem newItem = new NewItem();

            this.AddItem(newItem);
            PictureButton btnCreateDir = new PictureButton(AppImage.NewFolder);

            MyToolTip.SetToolTip(btnCreateDir, AppString.Tip.CreateGroup);
            newItem.AddCtr(btnCreateDir);
            btnCreateDir.MouseDown += (sender, e) => CreateNewGroup();
            newItem.AddNewItem     += (sender, e) =>
            {
                using (NewLnkFileDialog dlg1 = new NewLnkFileDialog())
                {
                    if (dlg1.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    using (SelectDialog dlg2 = new SelectDialog())
                    {
                        dlg2.Title = AppString.Dialog.SelectGroup;
                        dlg2.Items = GetGroupNames();
                        if (dlg2.ShowDialog() != DialogResult.OK)
                        {
                            return;
                        }
                        string dirName    = dlg2.Selected;
                        string dirPath    = $@"{WinXPath}\{dirName}";
                        string itemText   = dlg1.ItemText;
                        string targetPath = dlg1.ItemFilePath;
                        string arguments  = dlg1.Arguments;
                        string workDir    = Path.GetDirectoryName(targetPath);
                        string extension  = Path.GetExtension(targetPath).ToLower();
                        string fileName   = Path.GetFileNameWithoutExtension(targetPath);
                        int    count      = Directory.GetFiles(dirPath, "*.lnk").Length;
                        string index      = (count + 1).ToString().PadLeft(2, '0');
                        string lnkName    = $"{index} - {fileName}.lnk";
                        string lnkPath    = $@"{dirPath}\{lnkName}";
                        using (ShellLink shellLink = new ShellLink(lnkPath))
                        {
                            if (extension == ".lnk")
                            {
                                File.Copy(targetPath, lnkPath);
                                shellLink.Load();
                            }
                            else
                            {
                                shellLink.TargetPath       = targetPath;
                                shellLink.Arguments        = arguments;
                                shellLink.WorkingDirectory = workDir;
                            }
                            shellLink.Description = itemText;
                            shellLink.Save();
                        }
                        DesktopIni.SetLocalizedFileNames(lnkPath, itemText);
                        foreach (MyListItem ctr in this.Controls)
                        {
                            if (ctr is WinXGroupItem groupItem && groupItem.Text == dirName)
                            {
                                WinXItem item = new WinXItem(lnkPath, groupItem)
                                {
                                    Visible = !groupItem.IsFold
                                };
                                item.BtnMoveDown.Visible = item.BtnMoveUp.Visible = AppConfig.WinXSortable;
                                this.InsertItem(item, this.GetItemIndex(groupItem) + 1);
                                break;
                            }
                        }
                        WinXHasher.HashLnk(lnkPath);
                        ExplorerRestarter.Show();
                    }
                }
            };
        }