/// <summary> /// Opens a read-only stream to a file, first found by disk, then by embedded files. /// </summary> public static Stream OpenStream(string path) { // No file, empty string if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentException("Unable to open stream, null or blank path.", nameof(path)); } // Check disk path first else if (File.Exists(path)) { // Open file from disk for reading return(new FileStream(path, FileMode.Open, FileAccess.Read)); } // Check embedded path next else if (EmbeddedFiles.Exists(path)) { // Open embedded file for reading return(EmbeddedFiles.OpenStream(path)); } // No known file by this path else { throw new FileNotFoundException($"Unable to find file.", path); } }
/// <summary> /// Checks if a file exists, first by disk, then by embedded files. /// </summary> public static bool Exists(string path) { // No file, empty string if (string.IsNullOrWhiteSpace(path)) { return(false); } // Check disk path first else if (File.Exists(path)) { return(true); } // Check embedded path next else if (EmbeddedFiles.Exists(path)) { return(true); } // No known file by this path else { return(false); } }