Пример #1
0
        private void AddNewItem()
        {
            NewItem newItem = new NewItem();

            this.InsertItem(newItem, 0);
            newItem.AddNewItem += (sender, e) =>
            {
                using (NewLnkFileDialog dlg = new NewLnkFileDialog())
                {
                    dlg.FileFilter = $"{AppString.Dialog.Program}|*.exe;*.bat;*.cmd;*.vbs;*.vbe;*.js;*.jse;*.wsf";
                    if (dlg.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    string lnkPath = $@"{SendToPath}\{ObjectPath.RemoveIllegalChars(dlg.ItemText)}.lnk";
                    lnkPath = ObjectPath.GetNewPathWithIndex(lnkPath, ObjectPath.PathType.File);
                    using (ShellLink shellLink = new ShellLink(lnkPath))
                    {
                        shellLink.TargetPath       = dlg.ItemFilePath;
                        shellLink.WorkingDirectory = Path.GetDirectoryName(dlg.ItemFilePath);
                        shellLink.Arguments        = dlg.Arguments;
                        shellLink.Save();
                    }
                    DesktopIni.SetLocalizedFileNames(lnkPath, dlg.ItemText);
                    this.InsertItem(new SendToItem(lnkPath), 2);
                }
            };
        }
Пример #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();
                    }
                }
            };
        }