IFileSystem.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. namespace MediaBrowser.Common.IO
  6. {
  7. /// <summary>
  8. /// Interface IFileSystem
  9. /// </summary>
  10. public interface IFileSystem
  11. {
  12. /// <summary>
  13. /// Determines whether the specified filename is shortcut.
  14. /// </summary>
  15. /// <param name="filename">The filename.</param>
  16. /// <returns><c>true</c> if the specified filename is shortcut; otherwise, <c>false</c>.</returns>
  17. bool IsShortcut(string filename);
  18. /// <summary>
  19. /// Resolves the shortcut.
  20. /// </summary>
  21. /// <param name="filename">The filename.</param>
  22. /// <returns>System.String.</returns>
  23. string ResolveShortcut(string filename);
  24. /// <summary>
  25. /// Creates the shortcut.
  26. /// </summary>
  27. /// <param name="shortcutPath">The shortcut path.</param>
  28. /// <param name="target">The target.</param>
  29. void CreateShortcut(string shortcutPath, string target);
  30. /// <summary>
  31. /// Gets the file system info.
  32. /// </summary>
  33. /// <param name="path">The path.</param>
  34. /// <returns>FileSystemInfo.</returns>
  35. FileSystemInfo GetFileSystemInfo(string path);
  36. /// <summary>
  37. /// Gets the valid filename.
  38. /// </summary>
  39. /// <param name="filename">The filename.</param>
  40. /// <returns>System.String.</returns>
  41. string GetValidFilename(string filename);
  42. /// <summary>
  43. /// Gets the creation time UTC.
  44. /// </summary>
  45. /// <param name="info">The info.</param>
  46. /// <returns>DateTime.</returns>
  47. DateTime GetCreationTimeUtc(FileSystemInfo info);
  48. /// <summary>
  49. /// Gets the last write time UTC.
  50. /// </summary>
  51. /// <param name="info">The information.</param>
  52. /// <returns>DateTime.</returns>
  53. DateTime GetLastWriteTimeUtc(FileSystemInfo info);
  54. /// <summary>
  55. /// Gets the last write time UTC.
  56. /// </summary>
  57. /// <param name="path">The path.</param>
  58. /// <returns>DateTime.</returns>
  59. DateTime GetLastWriteTimeUtc(string path);
  60. /// <summary>
  61. /// Gets the file stream.
  62. /// </summary>
  63. /// <param name="path">The path.</param>
  64. /// <param name="mode">The mode.</param>
  65. /// <param name="access">The access.</param>
  66. /// <param name="share">The share.</param>
  67. /// <param name="isAsync">if set to <c>true</c> [is asynchronous].</param>
  68. /// <returns>FileStream.</returns>
  69. Stream GetFileStream(string path, FileMode mode, FileAccess access, FileShare share, bool isAsync = false);
  70. Stream OpenRead(String path);
  71. /// <summary>
  72. /// Swaps the files.
  73. /// </summary>
  74. /// <param name="file1">The file1.</param>
  75. /// <param name="file2">The file2.</param>
  76. void SwapFiles(string file1, string file2);
  77. /// <summary>
  78. /// Determines whether [contains sub path] [the specified parent path].
  79. /// </summary>
  80. /// <param name="parentPath">The parent path.</param>
  81. /// <param name="path">The path.</param>
  82. /// <returns><c>true</c> if [contains sub path] [the specified parent path]; otherwise, <c>false</c>.</returns>
  83. bool ContainsSubPath(string parentPath, string path);
  84. /// <summary>
  85. /// Determines whether [is root path] [the specified path].
  86. /// </summary>
  87. /// <param name="path">The path.</param>
  88. /// <returns><c>true</c> if [is root path] [the specified path]; otherwise, <c>false</c>.</returns>
  89. bool IsRootPath(string path);
  90. /// <summary>
  91. /// Normalizes the path.
  92. /// </summary>
  93. /// <param name="path">The path.</param>
  94. /// <returns>System.String.</returns>
  95. string NormalizePath(string path);
  96. /// <summary>
  97. /// Substitutes the path.
  98. /// </summary>
  99. /// <param name="path">The path.</param>
  100. /// <param name="from">From.</param>
  101. /// <param name="to">To.</param>
  102. /// <returns>System.String.</returns>
  103. string SubstitutePath(string path, string from, string to);
  104. /// <summary>
  105. /// Gets the file name without extension.
  106. /// </summary>
  107. /// <param name="info">The information.</param>
  108. /// <returns>System.String.</returns>
  109. string GetFileNameWithoutExtension(FileSystemInfo info);
  110. /// <summary>
  111. /// Gets the file name without extension.
  112. /// </summary>
  113. /// <param name="path">The path.</param>
  114. /// <returns>System.String.</returns>
  115. string GetFileNameWithoutExtension(string path);
  116. /// <summary>
  117. /// Determines whether [is path file] [the specified path].
  118. /// </summary>
  119. /// <param name="path">The path.</param>
  120. /// <returns><c>true</c> if [is path file] [the specified path]; otherwise, <c>false</c>.</returns>
  121. bool IsPathFile(string path);
  122. /// <summary>
  123. /// Deletes the file.
  124. /// </summary>
  125. /// <param name="path">The path.</param>
  126. void DeleteFile(string path);
  127. /// <summary>
  128. /// Deletes the directory.
  129. /// </summary>
  130. /// <param name="path">The path.</param>
  131. /// <param name="recursive">if set to <c>true</c> [recursive].</param>
  132. void DeleteDirectory(string path, bool recursive);
  133. IEnumerable<DirectoryInfo> GetDirectories(string path, bool recursive = false);
  134. IEnumerable<FileInfo> GetFiles(string path, bool recursive = false);
  135. IEnumerable<FileSystemInfo> GetFileSystemEntries(string path, bool recursive = false);
  136. void CreateDirectory(string path);
  137. void CopyFile(string source, string target, bool overwrite);
  138. void MoveFile(string source, string target);
  139. void MoveDirectory(string source, string target);
  140. bool DirectoryExists(string path);
  141. bool FileExists(string path);
  142. string ReadAllText(string path);
  143. void WriteAllText(string path, string text);
  144. void WriteAllText(string path, string text, Encoding encoding);
  145. string ReadAllText(string path, Encoding encoding);
  146. IEnumerable<string> GetDirectoryPaths(string path, bool recursive = false);
  147. IEnumerable<string> GetFilePaths(string path, bool recursive = false);
  148. IEnumerable<string> GetFileSystemEntryPaths(string path, bool recursive = false);
  149. }
  150. }