private void OnOutputPathButtonClick(object sender, RoutedEventArgs e)
        {
            string path = string.Empty;

            if (CommonFileDialog.IsPlatformSupported)
            {
                using (CommonOpenFileDialog dialog = new CommonOpenFileDialog())
                {
                    dialog.IsFolderPicker = true;
                    dialog.Multiselect = false;
                    dialog.DefaultDirectory = this.OutputPathBox.Text;
                    if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
                    {
                        path = dialog.FileName;
                    }
                }
            }
            else
            {
                using (FolderBrowserDialog dialog = new FolderBrowserDialog())
                {
                    dialog.RootFolder = Environment.SpecialFolder.MyMusic;
                    if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        path = dialog.SelectedPath;
                    }
                }
            }

            extractor.OutputPath = path;
        }
Exemple #2
0
        private void ChooseDataPath()
        {
            var dialog = new CommonOpenFileDialog
            {
                IsFolderPicker = true,
                InitialDirectory = Settings.Default.DataPath
            };

            var result = dialog.ShowDialog();
            if (result == CommonFileDialogResult.Ok)
            {
                var particleDir = Path.Combine(dialog.FileName, "art", "meshes", "Particle");
                if (!Directory.Exists(particleDir))
                {
                    MessageBox.Show("The chosen data directory does not seem to be valid.\n"
                                    + "Couldn't find subdirectory art\\meshes\\Particle.",
                        "Invalid Data Directory");
                    return;
                }

                Settings.Default.DataPath = dialog.FileName;
                Settings.Default.Save();
                PreviewControl.DataPath = dialog.FileName;
            }
        }
        private async void ImportImages()
        {
            var dialog = new CommonOpenFileDialog();
            dialog.Filters.Add(new CommonFileDialogFilter("Images", "png,gif,jpg,jpeg,bmp"));

            dialog.Title = "Select Images";
            dialog.EnsureFileExists = true;
            dialog.EnsurePathExists = true;
            dialog.EnsureReadOnly = false;
            dialog.EnsureValidNames = true;
            dialog.Multiselect = true;
            dialog.ShowPlacesList = true;

            if (dialog.ShowDialog() != CommonFileDialogResult.Ok)
                return;

            var images = dialog.FileNames
                .Where(p => System.IO.File.Exists(p))
                .Select(p => PromptImage(new BitmapImage(new Uri(p)), p))
                .Where(m => m != null)
                .ToList();
            
            var reporter = new Progress<ProgressDialogState>();
            var stopwatch = new Stopwatch();
            var progress = ProgressDialog.Open(reporter, stopwatch);

            stopwatch.Start();
            await _importer.AddImagesAsync(images, reporter);
            stopwatch.Stop();
            progress.Close();

            RefreshSheet();
        }
Exemple #4
0
        public static string BrowseForFolder(string startingPath)
        {
            string initialDirectory = _lastDirectory ?? startingPath;
            string ret = null;

            try
            {
                var cfd = new CommonOpenFileDialog
                {
                    InitialDirectory = initialDirectory,
                    IsFolderPicker = true
                };

                if (cfd.ShowDialog() == CommonFileDialogResult.Ok)
                {
                    ret = cfd.FileName;
                }
            }
            catch (System.PlatformNotSupportedException)
            {
                var fd = new System.Windows.Forms.FolderBrowserDialog
                {
                    SelectedPath = initialDirectory
                };

                if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    ret = fd.SelectedPath;
                }
            }

            _lastDirectory = ret;
            return ret;
        }
 public string ShowFolderBrowserDialog()
 {
     using (CommonOpenFileDialog dialog = new CommonOpenFileDialog { IsFolderPicker = true })
     {
         return dialog.ShowDialog() == CommonFileDialogResult.Ok ? dialog.FileName : null;
     }
 }
        private void OpenFileDialogCustomizationClicked(object sender, RoutedEventArgs e)
        {
            CommonOpenFileDialog openFileDialog = new CommonOpenFileDialog();
            currentFileDialog = openFileDialog;

            ApplyOpenDialogSettings(openFileDialog);
            
            // set the 'allow multi-select' flag
            openFileDialog.Multiselect = true;

            openFileDialog.EnsureFileExists = true;

            AddOpenFileDialogCustomControls(openFileDialog);

            CommonFileDialogResult result = openFileDialog.ShowDialog();
            if (result == CommonFileDialogResult.Ok)
            {
                string output = "";
                foreach (string fileName in openFileDialog.FileNames)
                {
                    output += fileName + Environment.NewLine;
                }
                
                output += Environment.NewLine + GetCustomControlValues();

                MessageBox.Show(output, "Files Chosen", MessageBoxButton.OK, MessageBoxImage.Information );
            }
        }
        private void btnOpen_Click( object sender, RoutedEventArgs e )
        {
            CommonOpenFileDialog openDialog = new CommonOpenFileDialog();
              openDialog.ShowPlacesList = true;
              openDialog.Multiselect = false;
              openDialog.IsFolderPicker = false;
              openDialog.AddToMostRecentlyUsedList = true;
              openDialog.Filters.Add( new CommonFileDialogFilter( "PNG images", "*.png" ) );
              if ( openDialog.ShowDialog( this ) == CommonFileDialogResult.Ok ) {
            soureFilePath = openDialog.FileName;
            // get comment meta
            using ( FileStream fileStream = new FileStream( soureFilePath, FileMode.Open, FileAccess.Read ) ) {
              pngReader = new PngReader( fileStream );
              // 参考自Hjg.Pngcs的SampleCustomChunk项目
              // get last line: this forces loading all chunks
              pngReader.ReadChunksOnly();
              tblkComment.Text = pngReader.GetMetadata().GetTxtForKey( Key_SemanticInfo );
              pngReader.End();
              fileStream.Close();
            }

            image.BeginInit();
            image.Source = new BitmapImage( new Uri( soureFilePath ) );
            image.EndInit();
              }
        }
Exemple #8
0
        public static GameLocationInfo GetGameLocation(FFXIIIGamePart gamePart)
        {
            try
            {
                using (RegistryKey localMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
                using (RegistryKey registryKey = localMachine.OpenSubKey(GetSteamRegistyPath(gamePart)))
                {
                    if (registryKey == null)
                        throw Exceptions.CreateException("Запись в реестре не обнаружена.");

                    GameLocationInfo result = new GameLocationInfo((string)registryKey.GetValue(GameLocationSteamRegistryProvider.SteamGamePathTag));
                    result.Validate();

                    return result;
                }
            }
            catch
            {
                return Application.Current.Dispatcher.Invoke(() =>
                {
                    using (CommonOpenFileDialog dlg = new CommonOpenFileDialog(String.Format("Укажите каталог Final Fantasy XIII-{0}...", (int)gamePart)))
                    {
                        dlg.IsFolderPicker = true;
                        if (dlg.ShowDialog() != CommonFileDialogResult.Ok)
                            throw new OperationCanceledException();

                        GameLocationInfo result = new GameLocationInfo(dlg.FileName);
                        result.Validate();

                        return result;
                    }
                });
            }
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //var dialog = new System.Windows.Forms.FolderBrowserDialog();
            //System.Windows.Forms.DialogResult result = dialog.ShowDialog();

            //// Configure open file dialog box
            //Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            //dlg.FileName = "Document"; // Default file name
            //dlg.DefaultExt = ".txt"; // Default file extension
            //dlg.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension

            //// Show open file dialog box
            //Nullable<bool> result = dlg.ShowDialog();

            //// Process open file dialog box results
            //if (result == true)
            //{
            //    // Open document
            //    string filename = dlg.FileName;
            //}

            //Check to see if the user is >Vista
            if (CommonFileDialog.IsPlatformSupported)
            {
                var dialog = new CommonOpenFileDialog();
                dialog.IsFolderPicker = true;
                CommonFileDialogResult result = dialog.ShowDialog();
                if (result == CommonFileDialogResult.Ok)
                {
                    dirName = dialog.FileName;
                    textbox.Text = dirName;
                }
            }
        }
        public void SelectFiles()
        {
            if (CommonFileDialog.IsPlatformSupported)
            {
                var commonOpenFileDialog = new CommonOpenFileDialog("Select the audio files that you want to link to the zune social")
                                               {
                                                   Multiselect = true,
                                                   EnsureFileExists = true
                                               };

                commonOpenFileDialog.Filters.Add(new CommonFileDialogFilter("Audio Files", "*.mp3;*.wma;*.m4a"));
                commonOpenFileDialog.Filters.Add(new CommonFileDialogFilter("MP3 Files", "*.mp3"));
                commonOpenFileDialog.Filters.Add(new CommonFileDialogFilter("WMA Files", "*.wma"));
                commonOpenFileDialog.Filters.Add(new CommonFileDialogFilter("Mpeg4 Files", "*.m4a"));

                if (commonOpenFileDialog.ShowDialog() == CommonFileDialogResult.OK)
                    ReadFiles(commonOpenFileDialog.FileNames);
            }
            else
            {
                var ofd = new OpenFileDialog {
                    Multiselect = true,
                    Filter = "Audio files .mp3,.wma,.m4a |*.mp3;*.wma;*.m4a",
                    AutoUpgradeEnabled = true,
                    Title = "Select the audio files that you want to link to the zune social",
                    CheckFileExists = true
                };

                if (ofd.ShowDialog() == DialogResult.OK)
                    ReadFiles(ofd.FileNames);
            }
        }
        // MainWindow newMain; // Global Declaration
        //// Run directory processing on a new thread
        //public async Task<string> getDirectory(MainWindow mainWindow)
        //{
        //    newMain = mainWindow;
        //}
        ///////////////////////////////////////////////////////
        // Select Directory Button Handler
        // - Gets full path including sub-directories
        //
        // - Uses       string path = new DirButton().selectDirectory();
        // - Output     returns {string} path (selected in dialog)
        ///////////////////////////////////////////////////////
        public string selectDirectory()
        {
            // Define new MainWindow object (for reference)
            var mainWindow = ((MainWindow)System.Windows.Application.Current.MainWindow);

            // Begin Windows Dialog .DLL Extension usage
            var dlg = new CommonOpenFileDialog();
            var currentDirectory = "";
            dlg.Title = "Select Music Directory";
            dlg.IsFolderPicker = true;
            dlg.InitialDirectory = currentDirectory;
            dlg.AddToMostRecentlyUsedList = false;
            dlg.AllowNonFileSystemItems = false;
            dlg.DefaultDirectory = currentDirectory;
            dlg.EnsureFileExists = true;
            dlg.EnsurePathExists = true;
            dlg.EnsureReadOnly = false;
            dlg.EnsureValidNames = true;
            dlg.Multiselect = false;
            dlg.ShowPlacesList = true;

            if (dlg.ShowDialog() == CommonFileDialogResult.Ok)
            {
                string folder = dlg.FileName;

                //mainWindow.FileText.Text = folder;

                return folder;
            }
            else
            {
                return null;
            }
        }
Exemple #12
0
        public string SelectDirectoryDialog(string defaultPath, string title = null)
        {
            var dlg = new CommonOpenFileDialog()
            {
                Title = "",
                IsFolderPicker = true,
                InitialDirectory = defaultPath,
                AddToMostRecentlyUsedList = false,
                AllowNonFileSystemItems = false,
                DefaultDirectory = defaultPath,
                EnsureFileExists = true,
                EnsurePathExists = true,
                EnsureReadOnly = false,
                EnsureValidNames = true,
                Multiselect = false,
                ShowPlacesList = true
            };

            if (dlg.ShowDialog() == CommonFileDialogResult.Ok)
            {
                return dlg.FileName;
            }

            return null;
        }
        // Lets the user choose and upload an image from file to the blob storage.
        // The file is saved under the name "User[id]img".
        // The method then calls the GetImage() method to display the uploaded image.
        private async void BtnUserImage_Click(object sender, RoutedEventArgs e)
        {
            var cofd = new CommonOpenFileDialog();
            cofd.Filters.Add(new CommonFileDialogFilter("JPEG Files", "*.jpg"));
            cofd.Filters.Add(new CommonFileDialogFilter("PNG Files", "*.png"));

            if (cofd.ShowDialog() == CommonFileDialogResult.Ok)
            {
                try
                {
                    string name = "User" + selectedUID + "img";
                    CloudBlockBlob blockBlob = (App.Current as App).blobcontainer.GetBlockBlobReference(name);
                    blockBlob.Properties.ContentType = "image/jpg";
                    using (var fileStream = System.IO.File.OpenRead(cofd.FileName))
                    {
                        await blockBlob.UploadFromStreamAsync(fileStream);
                        {
                            GetImage();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + ex.InnerException, "uploading or downloading image error");
                }
            }
        }
        private async void SelectRepoButtonClick(object sender, RoutedEventArgs e)
        {
            using (var dialog = new CommonOpenFileDialog())
            {
                dialog.IsFolderPicker = true;

                if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
                {
                    commandFactory = new CommandFactory(resultCommandMapper, dialog.FileName);
                    var statusCommand = commandFactory.GetCommand<StatusResult>();
                    statusCommand.Execute();

                    if (statusCommand.Result.ExecutionResult == ExecutionResult.NoRepository)
                    {
                        commandFactory = null;
                        MessageBox.Show("The selected file contains no git repository.", "Error!", MessageBoxButton.OK);
                    }
                    else
                    {
                        currentBranch.Text = "Current branch: " + statusCommand.Result.CurrentBranch;
                    }

                    await ListNormalCommits();
                }
            }
        }
Exemple #15
0
        private void browseSmfPath_Click(object sender, EventArgs e)
        {
            // Get us a new FolderBrowserDialog
            CommonOpenFileDialog fb = new CommonOpenFileDialog();
            fb.IsFolderPicker = true;
            fb.Title = "Please select the directory that your environment resides in.";
            fb.EnsurePathExists = true;
            CommonFileDialogResult rs = fb.ShowDialog();

            if (rs == CommonFileDialogResult.Cancel)
                return;

            // Get the path.
            string s = fb.FileName;
            if (Directory.Exists(s))
            {
                smfPath.Text = s;

                if (File.Exists(s + "/index.php"))
                {
                    string contents = File.ReadAllText(s + "/index.php");

                    Match match = Regex.Match(contents, @"'SMF ([^']*)'");
                    if (match.Success)
                        dsmfver.Text = match.Groups[1].Value;
                    else
                        dsmfver.Text = "(unknown)";
                }
                else
                    dsmfver.Text = "(unknown)";
            }
        }
Exemple #16
0
 private void BtnBrowse_click(object sender, RoutedEventArgs e)
 {
     var dialog = new CommonOpenFileDialog();
     dialog.IsFolderPicker = true;
     CommonFileDialogResult result = dialog.ShowDialog();
     if (result == CommonFileDialogResult.Ok)
     {
         TextPath.Text = dialog.FileName;
     }
 }
 private void SelectScreenFolder(object sender, RoutedEventArgs e)
 {
     using (var folderdialog = new CommonOpenFileDialog())
     {
         folderdialog.IsFolderPicker = true;
         folderdialog.InitialDirectory = Config.Current.ScreenShotFolder;
         if (folderdialog.ShowDialog() == CommonFileDialogResult.Ok)
             Config.Current.ScreenShotFolder = folderdialog.FileName;
     }
 }
 private void Button_Click_2(object sender, RoutedEventArgs e)
 {
     var d = new CommonOpenFileDialog();
     d.IsFolderPicker = true;	//set to false if need to select files
     d.Title = "选择保存位置:";
     var result = d.ShowDialog();
     if (result == CommonFileDialogResult.Ok)
     {
         this.tbDstFile.Text = d.FileName;
     }
 }
        private void btnBrowseFile_Click(object sender, RoutedEventArgs e)
        {
            CommonOpenFileDialog cfd = new CommonOpenFileDialog();
            cfd.AllowNonFileSystemItems = true;
            cfd.EnsureReadOnly = true;

            if (cfd.ShowDialog() == CommonFileDialogResult.Ok)
            {
                StartWatcher(cfd.FileAsShellObject);
            }
        }
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     var dialog = new CommonOpenFileDialog();
     dialog.IsFolderPicker = true;
     CommonFileDialogResult result = dialog.ShowDialog();
     if (result == CommonFileDialogResult.Ok)
     {
         _outputDir = dialog.FileName;
         CreateIcons();
     }
 }
        public string OpenFileDialog(bool IsFolderPicker)
        {
            string fileName = string.Empty;
            var dialog = new CommonOpenFileDialog();
            dialog.IsFolderPicker = IsFolderPicker;
            CommonFileDialogResult dialogResult = dialog.ShowDialog();
            if (dialogResult == CommonFileDialogResult.Ok)
                fileName = dialog.FileName;

            return fileName;
        }
Exemple #22
0
 private void OnOpenFile(object unused1, RoutedEventArgs unused2)
 {
     this.JumpList.KnownCategoryToDisplay = JumpListKnownCategoryType.Recent;
     CommonOpenFileDialog cfd = new CommonOpenFileDialog();
     cfd.ShowDialog();
     //The only purpose of this method is to record the fact that a selection
     //has been made in a common file dialog. If there's a file type association
     //for this application, then the selected file will be added to this
     //application's Recent and Frequent system lists, which can then be used
     //to populate the Recent and/or Frequent jump list destination categories.
 }
Exemple #23
0
        public Task<string> ShowOpenFileDialogAsync(string title, string defaultExtension, params Tuple<string, string>[] extensions)
        {
            var tcs = new TaskCompletionSource<string>();

            _dispatcherService.CurrentDispatcher.BeginInvoke(new Action(() =>
            {
                var result = string.Empty;

                // Create a CommonOpenFileDialog to select source file
                CommonOpenFileDialog cfd = new CommonOpenFileDialog
                {
                    AllowNonFileSystemItems = true,
                    EnsureReadOnly = true,
                    EnsurePathExists = true,
                    EnsureFileExists = true,
                    DefaultExtension = defaultExtension,
                    Multiselect = false, // One file at a time
                    Title = title ?? "Select File",
                };

                if ((extensions != null) && (extensions.Any()))
                {
                    foreach (var ext in extensions)
                    {
                        cfd.Filters.Add(new CommonFileDialogFilter(ext.Item1, ext.Item2));
                    }
                }

                if (cfd.ShowDialog() == CommonFileDialogResult.Ok)
                {
                    ShellObject selectedObj = null;

                    try
                    {
                        // Try to get the selected item 
                        selectedObj = cfd.FileAsShellObject;
                    }
                    catch
                    {
                        //MessageBox.Show("Could not create a ShellObject from the selected item");
                    }

                    if (selectedObj != null)
                    {
                        // Get the file name
                        result = selectedObj.ParsingName;
                    }
                }

                tcs.SetResult(result);
            }));

            return tcs.Task;
        }
Exemple #24
0
 private void selectDoelMap_Click(object sender, RoutedEventArgs e)
 {
     CodePack.CommonOpenFileDialog dialog = new CodePack.CommonOpenFileDialog();
     //dialog.InitialDirectory = "C:\\Users\\mathi\\Documents\\testomgeving"; //!
     dialog.IsFolderPicker = true;
     if (dialog.ShowDialog() == CodePack.CommonFileDialogResult.Ok)
     {
         _doelPad     = dialog.FileName;
         doelMap.Text = dialog.FileName;
     }
 }
        public async Task<string> Run(
            string title = null,
            string initialDirectory = null,
            IEnumerable<CommonFileDialogFilter> filters = null,
            bool folderPicker = false)
        {
            if (!CommonOpenFileDialog.IsPlatformSupported)
            {
                return null;
            }

            string filePath = null;

            using (var dialog = new CommonOpenFileDialog())
            {
                dialog.IsFolderPicker = folderPicker;
                dialog.Title = title;
                dialog.InitialDirectory = MakeInitialDirectoryPath(initialDirectory);
                filters?.ToList().ForEach(f => dialog.Filters.Add(f));
                dialog.EnsureValidNames = true;
                dialog.EnsurePathExists = false;
                dialog.EnsureFileExists = false;
                dialog.Multiselect = false;

                var handle =
                    (HwndSource.FromVisual(this.Window) as HwndSource)?.Handle;
                var result =
                    await this.Window.Dispatcher.InvokeAsync(
                        () =>
                            handle.HasValue ?
                                dialog.ShowDialog(handle.Value) : dialog.ShowDialog());
                if (result != CommonFileDialogResult.Ok)
                {
                    return null;
                }

                filePath = Path.GetFullPath(dialog.FileName);
            }

            return filePath;
        }
        private async void DoBrowseAvatar()
        {
            var dialog = new Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog();
            var result = dialog.ShowDialog();

            if (result == CommonFileDialogResult.Ok)
            {
                var base64String = Convert.ToBase64String(await File.ReadAllBytesAsync(dialog.FileName));
                Avatar         = base64String;
                _isAvatarDirty = true;
            }
        }
        string PathingBrowser(bool isFolder)
        {
            var dialog = new CommonOpenFileDialog();

            if (isFolder)
                dialog.IsFolderPicker = true;

            var result = dialog.ShowDialog();
            if (result == CommonFileDialogResult.Ok)
                return dialog.FileName;

            return null;
        }
Exemple #28
0
        private void SaveCmdExecuted(object sender, RoutedEventArgs e)
        {
            // Set up a folder browser
            var folderbrowserDialog = new Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog();

            folderbrowserDialog.IsFolderPicker = true;
            // DialogResult result = dlg.ShowDialog();
            if (folderbrowserDialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                OutputDirectory = folderbrowserDialog.FileName;
            }
            lblOutputFilePath.Content = OutputDirectory;
        }
        private void btnBoxesPath_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new CommonOpenFileDialog
            {
                Multiselect = false,
                IsFolderPicker = true
            };

            if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                txtBoxesPath.Text = dialog.FileName;
            }
        }
Exemple #30
0
        public static string BrowseForFolder(string startingPath)
        {
            var cfd = new CommonOpenFileDialog
                      {
                          DefaultFileName = startingPath,
                          IsFolderPicker = true,
                      };

            if (cfd.ShowDialog() != CommonFileDialogResult.Ok) return null;

            var ret = cfd.FileName;
            return ret;
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new CommonOpenFileDialog();
            dialog.Multiselect = false;
            CommonFileDialogResult result = dialog.ShowDialog();

            if (result == CommonFileDialogResult.Ok)
            {
                string json = File.ReadAllText(dialog.FileName);
                List<ShooterStageData> results = JsonConvert.DeserializeObject<List<ShooterStageData>>(json);

                ProcessTeams(results, GetTeams());
            }
        }
Exemple #32
0
        private void buttonDepot_Click(object sender, EventArgs e)
        {
            using (var ofd = new Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog())
            {
                ofd.IsFolderPicker = true;
                ofd.Multiselect    = false;

                var rslt = ofd.ShowDialog();
                if (rslt != CommonFileDialogResult.Ok)
                {
                    return;
                }

                textBoxDepotPath.Text = ofd.FileName;
            }
        }
        private string BrowseAndCheckForPath(ObservableCollection <Installation> installations)
        {
            using (var dialog = new Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog())
            {
                dialog.IsFolderPicker = true;
                Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogResult result = dialog.ShowDialog();

                if (result == CommonFileDialogResult.Ok)
                {
                    string path        = dialog.FileName;
                    var    same_pathed = installations.Where(x => x.Path.TrimEnd('\\') == path.TrimEnd('\\') && x.IsAutodiscoveredInstance == false);
                    if (same_pathed.Count() > 0)
                    {
                        var ans = MessageBox.Show(
                            $"You already have [{path}] in your user-added list. Do you really want to add it again [not recommended]?. Press No if you are not sure what to do.",
                            Branding.MessageBoxHeader, MessageBoxButton.YesNo, MessageBoxImage.Exclamation, MessageBoxResult.No);

                        if (ans == MessageBoxResult.No)
                        {
                            return(null);
                        }
                    }

                    if (!(new Installation(path)).Detected)
                    {
                        var ans = MessageBox.Show(
                            $"Cannot detect any {Branding.TargetProduct} installation in [{path}]. Do you really want to add this path? (No = Select another, Cancel = Add nothing)",
                            Branding.MessageBoxHeader, MessageBoxButton.YesNoCancel, MessageBoxImage.Exclamation, MessageBoxResult.No);

                        if (ans == MessageBoxResult.Cancel)
                        {
                            return(null);
                        }
                        else if (ans == MessageBoxResult.No)
                        {
                            return(BrowseAndCheckForPath(installations));
                        }
                    }

                    return(path);
                }
            }

            return(null);
        }
        public static bool OpenFolderDialog(Controls.TextBox tb, string initialDirectory)
        {
            bool success = false;
            var  win32   = PlatformID.Win32NT | PlatformID.Win32S | PlatformID.Win32Windows;

            if (((int)Environment.OSVersion.Platform & (int)win32) >= 1)
            {
                using (var dlg = new Dialogs.CommonOpenFileDialog
                {
                    InitialDirectory = initialDirectory,
                    EnsurePathExists = true,
                    IsFolderPicker = true,
                    Title = "Select directory",
                    AllowNonFileSystemItems = true
                })
                {
                    success = dlg.ShowDialog() == Dialogs.CommonFileDialogResult.Ok;
                    if (success)
                    {
                        success &= !string.IsNullOrWhiteSpace(dlg.FileName);
                        tb.Text  = success ? dlg.FileName : string.Empty;
                    }
                }
            }
            else
            {
                using (var dlg = new Forms.FolderBrowserDialog())
                {
                    if (dlg.ShowDialog() == Forms.DialogResult.OK && string.IsNullOrWhiteSpace(dlg.SelectedPath))
                    {
                        tb.Text = dlg.SelectedPath;
                    }
                }
            }

            if (!success)
            {
                MessageBox.Show("No folder selected");
            }

            return(success);
        }
        private void btnChoosePostInstallCommand_Click(object sender, RoutedEventArgs e)
        {
            bool oldTopMost = this.Topmost;

            this.Topmost = false;

            using (var dialog = new Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog())
            {
                dialog.Filters.Add(new CommonFileDialogFilter("Executable files", "*.exe; *.com; *.bat; *.cmd; *.ps1; *.vbs; *.sh; *.ps2; *.jar"));
                dialog.Filters.Add(new CommonFileDialogFilter("All files", "*.*"));


                Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogResult result = dialog.ShowDialog();

                if (result == CommonFileDialogResult.Ok)
                {
                    txtPostInstallCommand.Text = dialog.FileName;
                }
            }

            this.Topmost = oldTopMost;
        }
    private void ButtonKeyClick(object sender, EventArgs e)
    {
      if (CommonOpenFileDialog.IsPlatformSupported)
      {
        using (CommonOpenFileDialog dialog = new CommonOpenFileDialog())
        {
          dialog.Title = openFileDialogKey.Title;
          dialog.DefaultExtension = openFileDialogKey.DefaultExt;
          dialog.Filters.Add(new CommonFileDialogFilter("Key files", "*.snk;*.pfx"));
          dialog.EnsurePathExists = true;
          dialog.EnsureValidNames = true;
          dialog.IsFolderPicker = false;
          dialog.Multiselect = false;

          if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
          {
            string selectedFolder = dialog.FileName;
            while (!Directory.Exists(selectedFolder))
            {
              // Work around dialog bug in Vista.
              selectedFolder = Directory.GetParent(selectedFolder).FullName;
            }

            textBoxKey.Text = dialog.FileName;
          }
        }
      }
      else
      {
        if (openFileDialogKey.ShowDialog() == DialogResult.OK)
        {
          textBoxKey.Text = openFileDialogKey.FileName;
        }
      }
    }
 /// <summary>
 /// Opens a folder browser dialog and returns the selected folders.
 /// </summary>
 /// <param name="owner">The owner for the dialog.</param>
 /// <returns>A list with the selected folders.</returns>
 public static IList<string> GetFolders(Window owner)
 {
     if (CommonFileDialog.IsPlatformSupported)
     {
         using (var dialog = new CommonOpenFileDialog())
         {
             dialog.IsFolderPicker = true;
             dialog.Multiselect = true;
             var result = dialog.ShowDialog(owner);
             if (result == CommonFileDialogResult.Ok)
             {
                 return dialog.FileNames.ToList();
             }
         }
     }
     else
     {
         using (var dialog = new System.Windows.Forms.FolderBrowserDialog())
         {
             var result = owner is System.Windows.Forms.IWin32Window
                            ? dialog.ShowDialog((System.Windows.Forms.IWin32Window)owner)
                            : dialog.ShowDialog();
             if (result == System.Windows.Forms.DialogResult.OK)
             {
                 return new[] { dialog.SelectedPath };
             }
         }
     }
     return Enumerable.Empty<string>().ToList();
 }