private void SetPropertiesFromDialogResult(NativeFolderBrowserDialog dialog)
        {
            dialog.GetResults(out IShellItemArray resultsArray);

            DirectoryNames.Clear();

            resultsArray.GetCount(out uint count);
            for (uint i = 0; i < count; i++)
            {
                resultsArray.GetItemAt(i, out IShellItem result);

                HResult hr = result.GetDisplayName(NativeMethods.SIGDN.SIGDN_DESKTOPABSOLUTEPARSING, out IntPtr ppszName);

                if (hr == HResult.Ok && ppszName != IntPtr.Zero)
                {
                    DirectoryNames.Add(Marshal.PtrToStringAuto(ppszName));
                }

                Marshal.FreeCoTaskMem(ppszName);
            }

            if (DirectoryNames.Count > 0)
            {
                DirectoryName = DirectoryNames[0];
            }
        }
示例#2
0
        private void goToRoot()
        {
            clearPaths();

            foreach (var drive in DriveInfo.GetDrives())
            {
                if (drive.IsReady == false)
                {
                    continue;
                }

                Paths.Add(drive.Name);
                DirectoryNames.Add(drive.Name);
            }
        }
        public DialogResult ShowDialog()
        {
            DialogResult result;

            // Windows Vista is version 6.0
            if (Environment.OSVersion.Platform == PlatformID.Win32NT &&
                Environment.OSVersion.Version >= new Version(6, 0))
            {
                using var d = new VistaFolderBrowserDialog { InitialDirectory = InitialDirectory, MultiSelect = true };

                if (d.ShowDialog() == DialogResult.OK)
                {
                    DirectoryName = d.DirectoryName;
                    DirectoryNames.Clear();
                    foreach (string dir in d.DirectoryNames)
                    {
                        DirectoryNames.Add(dir);
                    }
                    result = DialogResult.OK;
                }
                else
                {
                    result = DialogResult.Cancel;
                }
            }
            else
            {
                // Fallback for pre-Vista, probably won't ever be hit seeing as we require Windows 7 or above,
                // and even if we went back to .NET 4.6 we would still require Vista. But hey.
                using var d = new FolderBrowserDialog { SelectedPath = InitialDirectory, ShowNewFolderButton = true };

                if (d.ShowDialog() == DialogResult.OK)
                {
                    DirectoryName = d.SelectedPath;
                    DirectoryNames.Clear();
                    DirectoryNames.Add(d.SelectedPath);
                    result = DialogResult.OK;
                }
                else
                {
                    result = DialogResult.Cancel;
                }
            }

            return(result);
        }
示例#4
0
        public bool ChangeDir(string path)
        {
            try
            {
                var directories = Directory.GetDirectories(path);

                Path = path;

                clearPaths();

                foreach (var dir in directories)
                {
                    Paths.Add(dir.ToString());
                    var dirName = new DirectoryInfo(dir).Name;
                    DirectoryNames.Add(dirName);
                }
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }