/// <summary> /// Returns the contents of the specified file, or null if there is an error. /// </summary> /// <param name="path">That path, not including the filename.</param> /// <param name="file">Filename.</param> /// <param name="error">Error details, or null if there is no error.</param> /// <returns>contents of the specified file, or null if there is an error.</returns> internal static string ReadAllText(string path, string file, out FsError error) { error = null; string fullPath = (file == null) ? path : Path.Combine(path, file); FsErrorType err = FsErrorType.Unspecified; try { return(File.ReadAllText(fullPath)); } catch (FileNotFoundException) { err = FsErrorType.FileNotFound; } catch (DirectoryNotFoundException) { err = FsErrorType.DirectoryNotFound; } catch (PathTooLongException) { err = FsErrorType.PathTooLong; } catch (NotSupportedException) { err = FsErrorType.InvalidPath; } catch (System.Security.SecurityException) { err = FsErrorType.SecurityException; } catch (IOException) { err = FsErrorType.IOError; } catch (ArgumentException) { err = FsErrorType.InvalidPath; } error = new FsError(fullPath, err); return(null); }
/// <summary> /// Performs the action and swallows file system exceptions AS WELL AS /// SOME EXCEPTIONS THAT MAY NOT BE CAUSE BY FILE SYSTEM. Use with caution. /// </summary> /// <param name="a"></param> /// <param name="error"></param> public static void PerformFileAction(FileAction a, out FsError error) { error = null; FsErrorType err = FsErrorType.Unspecified; try { a(); return; } catch (FileNotFoundException) { err = FsErrorType.FileNotFound; } catch (DirectoryNotFoundException) { err = FsErrorType.DirectoryNotFound; } catch (PathTooLongException) { err = FsErrorType.PathTooLong; } catch (NotSupportedException) { err = FsErrorType.InvalidPath; } catch (System.Security.SecurityException) { err = FsErrorType.SecurityException; } catch (IOException) { err = FsErrorType.IOError; } catch (ArgumentException) { err = FsErrorType.InvalidPath; } error = new FsError(string.Empty, err); }