private bool IsFileIncluded(WIN32_FIND_DATAW findData)
        {
            if (findData.cFileName.EndsWith(".lnk", StringComparison.OrdinalIgnoreCase) && dereferenceLinks)
            {
                // Do not search shortcuts recursively.
                if (!searchData.isShortcut && shellLink.Load(Path.Combine(searchData.path, findData.cFileName)))
                {
                    bool   isDirectory;
                    string target = ResolveShortcutTarget(shellLink.Path, out isDirectory);

                    if (!string.IsNullOrEmpty(target))
                    {
                        if (isDirectory)
                        {
                            // If the shortcut target is a directory, add it to the search list.
                            searchDirectories.Enqueue(new SearchData(target, true));
                        }
                        else if (FileMatchesFilter(target))
                        {
                            shellLinkTarget = target;
                            return(true);
                        }
                    }
                }
            }
            else if (FileMatchesFilter(findData.cFileName))
            {
                if (needsPathDiscoveryDemand)
                {
                    DoDemand(searchData.path);
                    needsPathDiscoveryDemand = false;
                }
                shellLinkTarget = null;

                return(true);
            }

            return(false);
        }
Example #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();
                    }
                }
            };
        }
Example #3
0
 public static IntPtr getLinkLocation(string path, Boolean resolve)
 {
     using (ShellLink link = new ShellLink())
     {
         link.Load(path);
         if (resolve)
         {
             link.Resolve();
         }
         return link.GetIDList();
     }
 }
Example #4
0
 public static string getLinkLocation(string path )
 {
     using (ShellLink link = new ShellLink())
     {
         link.Load(path);
         return link.GetPath();
     }
 }