/// <summary> /// Checks whether the file is of the desired kind for a program. /// </summary> /// <param name="fileKind">The kind of file to look for.</param> /// <param name="filePath">The file to check.</param> /// <param name="rootFile">When not null or empty, require the file name of the given file path to begin with this value.</param> /// <returns><c>true</c> if the file is a ROM file or a support file for the given root file.</returns> public static bool IsProgramSupportFile(this ProgramFileKind fileKind, string filePath, string rootFile) { // First, check if file is in the blacklist. if (!string.IsNullOrEmpty(filePath) && _romFileBlacklist.Contains(Path.GetFileName(filePath), PathComparer.Instance)) { return(false); } // Now, check if it has appropriate extension. If rootFile is not null or empty, check that FilePath has the same 'base name'. var hasExpectedExtension = fileKind.HasCorrectExtension(filePath); var hasCustomRomExtension = !hasExpectedExtension && fileKind.HasCustomRomExtension(filePath); if (hasCustomRomExtension) { DebugOutput("We have a custom extension!"); } // Don't care about case sensitivity of file system. bool isProgramFile = (hasExpectedExtension || hasCustomRomExtension) && (string.IsNullOrEmpty(rootFile) || Path.GetFileName(filePath).StartsWith(Path.GetFileNameWithoutExtension(rootFile), StringComparison.InvariantCultureIgnoreCase)); if (isProgramFile) { // Check if file name has proper suffix. Don't care about case sensitivity of file system. var suffix = fileKind.GetSuffix(); isProgramFile = string.IsNullOrEmpty(suffix) || Path.GetFileNameWithoutExtension(filePath).EndsWith(suffix, StringComparison.InvariantCultureIgnoreCase); if (!isProgramFile) { // Check if it's in a proper directory. var subdirectoriesForFile = fileKind.GetSubdirectories(); isProgramFile = !subdirectoriesForFile.Any() || subdirectoriesForFile.Contains(Path.GetFileName(Path.GetDirectoryName(filePath)), PathComparer.Instance); } } return(isProgramFile); }
public void ProgramFileKind_HasCustomRomExtensionForEmptyPath_ReturnsFalseExceptForRomKind(ProgramFileKind fileKind) { var expectedResult = fileKind == ProgramFileKind.Rom; Assert.Equal(expectedResult, fileKind.HasCustomRomExtension(string.Empty)); }
public void ProgramFileKind_HasCustomRomExtensionForNullPath_ReturnsFalse(ProgramFileKind fileKind) { Assert.False(fileKind.HasCustomRomExtension(null)); }