Esempio n. 1
0
        public void GetPidlForDrivePath()
        {
            IntPtr pidl = default(IntPtr);

            try
            {
                // Get the default drive's path
                var drive = new DirectoryInfo(Environment.SystemDirectory).Root.Name;

                Assert.IsFalse(string.IsNullOrEmpty(drive));

                pidl = PidlManager.GetPIDLFromPath(drive);

                Assert.IsFalse(pidl == default(IntPtr));

                // Logical and physical path representation should be the same for drives
                string logicalPath   = PidlManager.GetPathFromPIDL(pidl);
                string physStorePath = PidlManager.GetPathFromPIDL(pidl, TypOfPath.PhysicalStoragePath);

                Assert.IsTrue(string.Equals(drive, physStorePath, StringComparison.CurrentCulture));
                Assert.IsTrue(string.Equals(logicalPath, physStorePath, StringComparison.CurrentCulture));

                ////Console.WriteLine("Path Retrieval via PIDL: '{0}' -> Logical Path: '{1}', Physical Path: '{2}'",
                ////                  drive, logicalPath, physStorePath);
            }
            finally
            {
                pidl = PidlManager.ILFree(pidl);
            }
        }
Esempio n. 2
0
        public void GetPidlForDirectoryPath()
        {
            // Get the default drive's path
            var drive = new DirectoryInfo(Environment.SystemDirectory).Root.Name;

            Assert.IsFalse(string.IsNullOrEmpty(drive));

            // enumerate on root directores of the default drive and
            // verify correct pidl <-> path reprentation for each directory
            foreach (var originalPath in Directory.EnumerateDirectories(drive))
            {
                IntPtr pidl = default(IntPtr);
                try
                {
                    pidl = PidlManager.GetPIDLFromPath(originalPath);

                    Assert.IsFalse(pidl == default(IntPtr));

                    string logicalPath   = PidlManager.GetPathFromPIDL(pidl);
                    string physStorePath = PidlManager.GetPathFromPIDL(pidl, TypOfPath.PhysicalStoragePath);

                    // The logical path of a special path '::{...}' will differ from
                    // its physical representation 'C:\Windows'
                    // Otherwise, both repesentations should be equal for non-special folders
                    if (ShellHelpers.IsSpecialPath(logicalPath) == ShellHelpers.SpecialPath.IsSpecialPath)
                    {
                        Assert.IsFalse(string.Equals(logicalPath, physStorePath));
                    }
                    else
                    {
                        Assert.IsTrue(string.Equals(logicalPath, physStorePath));
                    }

                    ////Console.WriteLine("Path Retrieval via PIDL: '{0}' -> Logical Path: '{1}', Physical Path: '{2}'",
                    ////    originalPath, logicalPath, physStorePath);
                }
                finally
                {
                    pidl = PidlManager.ILFree(pidl);
                }
            }
        }