IFileOperator.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. namespace XGame.Framework.FileSystem
  2. {
  3. /// <summary>
  4. /// 文件操作接口
  5. /// </summary>
  6. public interface IFileOperator
  7. {
  8. /// <summary>
  9. /// 获取文件名
  10. /// </summary>
  11. /// <param name="fullName"></param>
  12. /// <param name="withoutExt"></param>
  13. /// <returns></returns>
  14. string GetFileName(string fullName, bool withoutExt = true);
  15. /// <summary>
  16. /// 拓展名
  17. /// </summary>
  18. /// <param name="fullName">文件全路径(含拓展名)</param>
  19. /// <returns>拓展名(不包含“.”)</returns>
  20. string Extension(string fullName);
  21. /// <summary>
  22. /// 文件是否存在
  23. /// </summary>
  24. /// <param name="fullName">文件全路径(含拓展名)</param>
  25. /// <returns>True: 存在; False: 不存在; </returns>
  26. bool Exist(string fullName);
  27. /// <summary>
  28. /// 删除文件
  29. /// </summary>
  30. /// <param name="fullName">文件全路径(含拓展名)</param>
  31. /// <returns>True: 删除成功; False: 删除失败;</returns>
  32. bool Delete(string fullName);
  33. /// <summary>
  34. /// 获取文件所在文件夹路径(全路径)
  35. /// </summary>
  36. /// <param name="fullName">文件全路径(含拓展名)</param>
  37. /// <returns>文件夹全路径</returns>
  38. string GetDirectory(string fullName);
  39. /// <summary>
  40. /// 复制文件
  41. /// TODO: 暂时只支持包外文件到包外
  42. /// </summary>
  43. /// <param name="source">源文件</param>
  44. /// <param name="destination">目标文件</param>
  45. /// <param name="overwrite">是否覆盖</param>
  46. /// <returns>True: 复制成功; False: 复制失败;</returns>
  47. bool Copy(string source, string destination, bool overwrite);
  48. /// <summary>
  49. /// 异步复制文件
  50. /// </summary>
  51. /// <param name="source">源文件</param>
  52. /// <param name="destination">包外文件全路径</param>
  53. /// <param name="overwrite">覆盖</param>
  54. /// <returns></returns>
  55. ICopyFileAsync CopyFileAsync(string source, string destination, bool overwrite);
  56. /// <summary>
  57. /// 移动文件
  58. /// </summary>
  59. /// <param name="source">源文件</param>
  60. /// <param name="destination">目标文件路径</param>
  61. void Move(string source, string destination);
  62. /// <summary>
  63. /// 保存字节数组到本地
  64. /// </summary>
  65. /// <param name="filePath">文件全路径(包外)</param>
  66. /// <param name="bytes"></param>
  67. void WriteAllBytes(string filePath, byte[] bytes);
  68. /// <summary>
  69. /// 保存字符串到本地
  70. /// </summary>
  71. /// <param name="filePath">文件全路径(包外)</param>
  72. /// <param name="contents">内容</param>
  73. void WriteAllText(string filePath, string contents);
  74. /// <summary>
  75. /// 读取文件
  76. /// </summary>
  77. /// <param name="filePath">文件全路径(包内包外都可以)</param>
  78. /// <returns>文件内容</returns>
  79. byte[] ReadAllBytes(string filePath);
  80. /// <summary>
  81. /// 读取文本(UTF-8)
  82. /// </summary>
  83. /// <param name="filePath">文件全路径(包内包外都可以)</param>
  84. /// <returns>文本内容</returns>
  85. string ReadAllText(string filePath);
  86. /// <summary>
  87. /// 异步读取文件
  88. /// </summary>
  89. /// <param name="filePath">文件全路径(包内包外都可以)</param>
  90. /// <returns>文件内容</returns>
  91. IReadFileAsync ReadFileAsync(string filePath);
  92. /// <summary>
  93. /// 重命名
  94. /// </summary>
  95. /// <param name="from"></param>
  96. /// <param name="to"></param>
  97. /// <returns></returns>
  98. bool Rename(string from, string to);
  99. }
  100. }