/// <summary> /// Shows the file system file chooser to select one or more ROM files. /// </summary> /// <param name="multiselect">If <c>true</c>, instructs the file browser to allow the user to select multiple files.</param> /// <param name="prompt">The prompt to show in the file browser. If <c>null</c> or empty, a default will be used.</param> /// <returns>The files selected, or an empty enumerable.</returns> public static IEnumerable <string> BrowseForRoms(bool multiselect, string prompt) { var selectedFiles = System.Linq.Enumerable.Empty <string>(); var fileBrowser = FileDialogHelpers.Create(); fileBrowser.IsFolderBrowser = false; fileBrowser.AddFilter(Resources.Strings.FileDialog_SelectRomFilesFilter, ProgramFileKind.Rom.FileExtensions()); fileBrowser.AddFilter(FileDialogHelpers.AllFilesFilter, new string[] { ".*" }); if (!string.IsNullOrEmpty(prompt)) { fileBrowser.Title = prompt; } else { fileBrowser.Title = multiselect ? Resources.Strings.FileDialog_SelectFilesPrompt : Resources.Strings.FileDialog_SelectFilePrompt; } fileBrowser.EnsureFileExists = true; fileBrowser.EnsurePathExists = true; fileBrowser.Multiselect = multiselect; var result = fileBrowser.ShowDialog(); if (result == FileBrowserDialogResult.Ok) { selectedFiles = fileBrowser.FileNames; } return(selectedFiles); }
/// <summary> /// Prompt to add ROMs to the ROM list. /// </summary> /// <param name="parameter">If a non-<c>null</c> string that can be parsed as a Boolean value, /// the Boolean value indicates whether to prompt for files (false) or folders (true).</param> internal void AddRoms(object parameter) { var fileBrowser = FileDialogHelpers.Create(); bool isFolderBrowser = false; if (parameter is bool) { isFolderBrowser = (bool)parameter; } else if (!bool.TryParse(parameter as string, out isFolderBrowser)) { isFolderBrowser = false; } fileBrowser.IsFolderBrowser = isFolderBrowser; if (!fileBrowser.IsFolderBrowser) { fileBrowser.AddFilter(Resources.Strings.FileDialog_SelectRomFilesFilter, ProgramFileKind.Rom.FileExtensions()); #if !MAC fileBrowser.AddFilter(FileDialogHelpers.AllFilesFilter, new string[] { ".*" }); #endif // !MAC } fileBrowser.Title = fileBrowser.IsFolderBrowser ? Resources.Strings.FileDialog_SelectFoldersPrompt : Resources.Strings.FileDialog_SelectFilesPrompt; fileBrowser.EnsureFileExists = true; fileBrowser.EnsurePathExists = true; fileBrowser.Multiselect = true; var result = fileBrowser.ShowDialog(); if (result == FileBrowserDialogResult.Ok) { bool updatedSearchDirectories = false; if (isFolderBrowser) { foreach (var folder in fileBrowser.FileNames) { updatedSearchDirectories |= _searchDirectories.Add(folder); } } // TODO: Consider using current selection index as insert location. AddRoms(fileBrowser.FileNames, -1, false); if (updatedSearchDirectories) { CommandManager.InvalidateRequerySuggested(); } } }
/// <summary> /// Shows a dialog to select a support file for the program. /// </summary> /// <param name="program">The program for which a support file is being selected.</param> /// <param name="kind">The kind of support file to browse for.</param> /// <returns>The selected support file.</returns> internal static string BrowseForSupportFile(ProgramViewModel program, ProgramFileKind kind) { string filter = null; string prompt = null; switch (kind) { case ProgramFileKind.ManualText: filter = RomListViewModel.SelectManualFilter; prompt = string.Format(System.Globalization.CultureInfo.CurrentCulture, RomListViewModel.SelectManualPromptFormat, program.ProgramDescription.Name); break; case ProgramFileKind.SaveData: filter = RomListViewModel.SelectJlpSaveDataFilter; prompt = string.Format(System.Globalization.CultureInfo.CurrentCulture, RomListViewModel.SelectJlpSavePromptFormat, program.ProgramDescription.Name); break; default: ErrorReporting.ReportNotImplementedError("ProgramViewModel.BrowseForSupportFile"); break; } string supportFilePath = null; var fileBrowser = FileDialogHelpers.Create(); fileBrowser.IsFolderBrowser = false; fileBrowser.AddFilter(filter, kind.FileExtensions()); fileBrowser.AddFilter(FileDialogHelpers.AllFilesFilter, new string[] { ".*" }); fileBrowser.Title = prompt; fileBrowser.EnsureFileExists = true; fileBrowser.EnsurePathExists = true; fileBrowser.Multiselect = false; var result = fileBrowser.ShowDialog(); if (result == FileBrowserDialogResult.Ok) { supportFilePath = fileBrowser.FileNames.First(); } return(supportFilePath); }
private static void OnSelectEmulatorFile(object parameter, EmulatorFile whichFile) { var viewModel = parameter as JzIntvSettingsPageViewModel; var selectionPrompt = string.Empty; switch (whichFile) { case EmulatorFile.JzIntv: selectionPrompt = Resources.Strings.Locate_jzIntv_Prompt; break; case EmulatorFile.Exec: selectionPrompt = Resources.Strings.Locate_EXEC_Prompt; break; case EmulatorFile.Grom: selectionPrompt = Resources.Strings.Locate_GROM_Prompt; break; case EmulatorFile.Ecs: selectionPrompt = Resources.Strings.Locate_ECS_Prompt; break; case EmulatorFile.KeyboardConfig: selectionPrompt = Resources.Strings.Select_Hackfile_Prompt; break; case EmulatorFile.Cgc0Config: selectionPrompt = Resources.Strings.Select_CGC_Console_Prompt; break; case EmulatorFile.Cgc1Config: selectionPrompt = Resources.Strings.Select_CGC_ECS_Prompt; break; default: break; } if (!string.IsNullOrEmpty(selectionPrompt)) { var browser = FileDialogHelpers.Create(); browser.EnsureFileExists = true; browser.Title = selectionPrompt; if ((whichFile == EmulatorFile.JzIntv) && !string.IsNullOrEmpty(PathUtils.ProgramSuffix)) { browser.AddFilter("jzIntv", new[] { PathUtils.ProgramSuffix }); } var result = browser.ShowDialog(); if (result == FileBrowserDialogResult.Ok) { var path = PathUtils.ResolvePathForSettings(browser.FileNames.First()); switch (whichFile) { case EmulatorFile.JzIntv: viewModel.EmulatorPath = path; break; case EmulatorFile.Exec: viewModel.ExecRomPath = path; break; case EmulatorFile.Grom: viewModel.GromRomPath = path; break; case EmulatorFile.Ecs: viewModel.EcsRomPath = path; break; case EmulatorFile.KeyboardConfig: viewModel.DefaultKeyboardConfigPath = path; break; case EmulatorFile.Cgc0Config: viewModel.JzIntvCgc0ConfigPath = path; break; case EmulatorFile.Cgc1Config: viewModel.JzIntvCgc1ConfigPath = path; break; default: break; } } } else { OSMessageBox.Show(string.Format(Resources.Strings.ConfigurationFile_UnknownSelection_Error_Message_Format, whichFile), Resources.Strings.ConfigurationFile_UnknownSelection_Error_Title); } }