Example #1
0
        public string BrowseBoot(Window owner, PresetModel preset, BootType type)
        {
            using (var dialog = new FileOpenDialog())
            {
                const string BiosFileName = "etfsboot.com";
                const string UefiFileName = "efisys.bin";

                string bootFolderPath;
                string bootFileName;
                string bootFileExtension;
                string extension;
                string clientGuid;
                string title;
                string fileName;

                if (type == BootType.Bios)
                {
                    GetFilePathInfo(preset.BiosBoot, out bootFolderPath, out bootFileName, out bootFileExtension);
                    extension  = Path.GetExtension(BiosFileName);
                    clientGuid = "E8BEE349-1A4A-4E04-B8B9-B15FF1EF9125";
                    title      = "BIOS";
                    fileName   = bootFileName ?? BiosFileName;
                }
                else if (type == BootType.Uefi)
                {
                    GetFilePathInfo(preset.UefiBoot, out bootFolderPath, out bootFileName, out bootFileExtension);
                    extension  = Path.GetExtension(UefiFileName);
                    clientGuid = "A6A65946-6FCD-4DCA-AEB1-85ABF5FE3CAE";
                    title      = "UEFI";
                    fileName   = bootFileName ?? UefiFileName;
                }
                else
                {
                    throw new InvalidOperationException("The specified boot type is not implemented.");
                }

                dialog.SetClientGuid(new Guid(clientGuid));
                dialog.SetDefaultFolder(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
                dialog.SetTitle($"{title} boot sector file");
                dialog.SetFileTypes($"Boot files (*{extension})|*{extension}|All files (*.*)|*.*");
                dialog.SetFileName(fileName);
                dialog.SetFileTypeIndex(bootFileExtension == null || bootFileExtension.Equals(extension, StringComparison.OrdinalIgnoreCase) ? 1 : 2);
                dialog.SetOkButtonLabel("Select");
                dialog.SetCancelButtonLabel("Cancel");
                dialog.SetFileNameLabel("Boot sector file :");
                dialog.DontAddToRecent = true;

                if (PathHelper.DirectoryExists(bootFolderPath))
                {
                    dialog.SetFolder(bootFolderPath);
                }

                return(dialog.ShowDialog(owner) == true?dialog.GetResult() : null);
            }
        }
        private bool ShowDialog(IntPtr owner)
        {
            IFileOpenDialog fod = null;

            try
            {
                fod = new FileOpenDialog() as IFileOpenDialog;
                fod.SetOptions(FOS.FOS_PICKFOLDERS | FOS.FOS_FORCEFILESYSTEM);

                if (!string.IsNullOrEmpty(InitialPath))
                {
                    uint attribute = 0U;
                    if ((SHILCreateFromPath(InitialPath, out IntPtr idl, ref attribute) == S_OK) &&
                        (SHCreateShellItem(IntPtr.Zero, IntPtr.Zero, idl, out IShellItem item) == S_OK))
                    {
                        fod.SetFolder(item);
                    }
                }

                if (!string.IsNullOrEmpty(Title))
                {
                    fod.SetTitle(Title);
                }

                if (fod.Show(owner) != S_OK)
                {
                    return(false);
                }

                SelectedPath = fod.GetResult().GetDisplayName(SIGDN.SIGDN_FILESYSPATH);
                return(true);
            }
            catch (COMException ce)
            {
                Debug.WriteLine($"Failed to manage open folder dialog.\r\n{ce}");
                return(false);
            }
            finally
            {
                if (fod is not null)
                {
                    Marshal.FinalReleaseComObject(fod);
                }
            }
        }
Example #3
0
        public string BrowseSource(Window owner, string source)
        {
            using (var dialog = new FileOpenDialog())
            {
                dialog.SetClientGuid(new Guid("6DD0F3B6-0F48-4F5B-8690-4866D4B9EAF2"));
                dialog.SetDefaultFolder(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
                dialog.SetTitle("Source location of the files and folders to be included in the image");
                dialog.SetOkButtonLabel("Select");
                dialog.SetCancelButtonLabel("Cancel");
                dialog.SetFileNameLabel("Source location :");
                dialog.PickFolders     = true;
                dialog.DontAddToRecent = true;

                if (PathHelper.DirectoryExists(source))
                {
                    dialog.SetFolder(source);
                }

                return(dialog.ShowDialog(owner) == true?dialog.GetResult() : null);
            }
        }
Example #4
0
        public string BrowseFile(Window owner, string filePath)
        {
            using (var dialog = new FileOpenDialog())
            {
                dialog.SetClientGuid(new Guid("1941C841-398F-486F-8542-A0B2250F406F"));
                dialog.SetDefaultFolder(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
                dialog.SetTitle("Location of the file to be computed");
                dialog.SetOkButtonLabel("Select");
                dialog.SetCancelButtonLabel("Cancel");
                dialog.SetFileNameLabel("File name :");
                dialog.DontAddToRecent = true;

                if (PathHelper.FileExists(filePath))
                {
                    dialog.SetFileName(Path.GetFileName(filePath));
                    dialog.SetFolder(Path.GetDirectoryName(filePath));
                }

                return(dialog.ShowDialog(owner) == true?dialog.GetResult() : null);
            }
        }
Example #5
0
        public bool ShowDialog(IntPtr ownerWindow)
        {
            //	オーナーウィンドウを正規化する
            ownerWindow = GetSafeOwnerWindow(ownerWindow);

            //	ダイアログインターフェースを構築
            IFileOpenDialog dlg = new FileOpenDialog() as IFileOpenDialog;              //	IUnknown::QueryInterfaceを使ってインターフェースを特定する

            try
            {
                //	フォルダ選択モードに切り替え
                dlg.SetOptions(FOS.FORCEFILESYSTEM | FOS.PICKFOLDERS);
                //	以前選択されていたフォルダを指定
                bool       setFolder = false;
                IShellItem item      = CreateItem(SelectedPath);
                if (item != null)
                {
                    dlg.SetFolder(item);
                    Marshal.ReleaseComObject(item);
                    setFolder = true;
                }
                //	まだフォルダを設定していない場合は初期フォルダを設定する
                if (!setFolder)
                {
                    item = CreateItem(InitialFolder);
                    if (item != null)
                    {
                        dlg.SetFolder(item);
                        Marshal.ReleaseComObject(item);
                    }
                }
                //	タイトル
                if (!string.IsNullOrWhiteSpace(Title))
                {
                    dlg.SetTitle(Title);
                }
                //	ショートカット追加
                foreach (var place in m_places)
                {
                    item = CreateItem(place.folder);
                    if (item != null)
                    {
                        dlg.AddPlace(item, place.fdap);
                        Marshal.ReleaseComObject(item);
                    }
                }
                //	ダイアログを表示
                var hRes = dlg.Show(ownerWindow);
                if (NativeMethods.SUCCEEDED(hRes))
                {
                    item         = dlg.GetResult();
                    SelectedPath = item.GetName(SIGDN.FILESYSPATH);
                    Marshal.ReleaseComObject(item);
                    return(true);
                }
            }
            finally
            {
                Marshal.ReleaseComObject(dlg);
            }
            return(false);
        }