Ejemplo n.º 1
0
        /// <summary>
        /// Checks whether the file extension is valid for the given program file kind.
        /// </summary>
        /// <param name="fileKind">The kind of program file for which the extension is to be validated.</param>
        /// <param name="filePath">The file path to be checked.</param>
        /// <returns>If the file has an extension that is valid for the given file kind, returns <c>true</c>; <c>false</c> otherwise.</returns>
        public static bool HasCorrectExtension(this ProgramFileKind fileKind, string filePath)
        {
            var fileTypes            = fileKind.FileExtensions();
            var extension            = GetExtension(filePath);
            var hasStandardExtension = (extension != null) && fileTypes.Any(e => e.Equals(extension, System.StringComparison.OrdinalIgnoreCase));

            return(hasStandardExtension);
        }
Ejemplo n.º 2
0
        /// <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);
        }
 public void ProgramFileKind_FileExtensionsForUnsupportedFileKind_ThrowsKeyNotFoundException(ProgramFileKind fileKind)
 {
     Assert.Throws <KeyNotFoundException>(() => fileKind.FileExtensions());
 }
 public void ProgramFileKind_FileExtensions_ReturnsCorrectFileExtensions(ProgramFileKind fileKind, IEnumerable <string> expectedFileExtensions)
 {
     AssertCollectionsAreEquivalent(expectedFileExtensions, fileKind.FileExtensions());
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Gets the default file extension for a program file kind.
 /// </summary>
 /// <param name="fileKind">The kind of program file for which an extension is desired.</param>
 /// <returns>The file extension.</returns>
 /// <exception cref="KeyNotFoundException">Thrown if <paramref name="fileKind"/> is not supported.</exception>
 public static string FileExtension(this ProgramFileKind fileKind)
 {
     return(fileKind.FileExtensions().First());
 }