Esempio n. 1
0
        public override ObservableCollection <INavTreeItem> GetMyChildren()
        {
            ObservableCollection <INavTreeItem> childrenList = new ObservableCollection <INavTreeItem>()
            {
            };
            INavTreeItem item1;
            string       fn = "";

            // This does not work yet properly: know the folder, note also desktop.ini present
            // 1) Localisation of name and path
            // 2) How is the order specified, cannot find documentation

            // If not Windows7, no children. I cannot test this now.
            if (!Utils.TestCurrentOs.IsWindows7())
            {
                return(childrenList);
            }

            // tmp hack, fixed filename.
            // (**) Non Windows 7: Specify fn= your own favorites folder and put some Drive/Folder shortcuts in this folder
            Environment.SpecialFolder s = Environment.SpecialFolder.UserProfile;
            fn = Environment.GetFolderPath(s);
            fn = fn + "\\Links";

            try
            {
                // For favorites we always return files!!
                DirectoryInfo di = new DirectoryInfo(fn);
                if (!di.Exists)
                {
                    return(childrenList);
                }

                string fileResolvedShortCut;

                foreach (FileInfo file in di.GetFiles())
                {
                    if (file.Name.ToUpper().EndsWith(".LNK"))
                    {
                        // tmp hack: resolve link to display icons instead of link-icons
                        fileResolvedShortCut = FolderPlaneUtils.ResolveIfShortCut(file.FullName);
                        if (fileResolvedShortCut != "")
                        {
                            FileInfo fileNs = new FileInfo(fileResolvedShortCut);

                            // to do localisation, names??
                            item1 = new FileItem();
                            item1.FullPathName = fileNs.FullName;
                            item1.FriendlyName = (fileNs.Name != "") ? fileNs.Name : fileNs.ToString();

                            childrenList.Add(item1);
                        }
                    }
                }
            }
            catch
            {
            }
            return(childrenList);
        }
Esempio n. 2
0
        public void SetFolderPlane(string path, bool clear = false)
        {
            if (!Directory.Exists(path))
            {
                path = "";
            }
            FullPathName = path;

            // If not valid path Clear items and return
            if ((path == null) || (path == ""))
            {
                FolderPlaneItems.Clear();
                return;
            }

            if (clear)
            {
                FolderPlaneItems.Clear();
            }

            bool isDrive = FolderPlaneUtils.IsDrive(path);

            if (isDrive)
            {
                FriendlyName = path;

                DriveInfo     drive = new DriveInfo(path);
                DirectoryInfo di    = new DirectoryInfo(((DriveInfo)drive).RootDirectory.Name);

                GetFoldersAndFiles(di);
                return;
            }

            bool isFolder = FolderPlaneUtils.IsFolder(path);

            if (isFolder)
            {
                // Get friendlyname, last foldername
                string[] folders = path.Split('\\');
                string   str     = folders[folders.Length - 1];
                FriendlyName = FolderPlaneUtils.MyShortFriendlyName(str);

                DirectoryInfo di = new DirectoryInfo(path);

                GetFoldersAndFiles(di);
                return;
            }
        }
Esempio n. 3
0
        public static string ResolveShortCut(string path)
        {
            if (FolderPlaneUtils.IsLink(path))
            {
                // First working solution chosen to resolve link
                // For using IWshRuntimeLibrary add reference, Com tab, choose Microsoft Shell Controls and Automation
                // Question: must we dispose shell, I assume this is a Managed wrapper around com

                IWshRuntimeLibrary.WshShell     shell = new IWshRuntimeLibrary.WshShell();
                IWshRuntimeLibrary.IWshShortcut link  = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(path);

                string target = link.TargetPath;
                return(target);
            }

            // If not found, keep original path
            return(path);
        }