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);
            }
        }