|
@@ -1,182 +1,188 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
+using System.Text.RegularExpressions;
|
|
|
using Godot;
|
|
|
using TBL.GodotSharp.IO.File;
|
|
|
using Zio;
|
|
|
|
|
|
-namespace TBL.GodotSharp.Content.FileSystem;
|
|
|
-
|
|
|
-/// <summary>
|
|
|
-/// Godot 文件系统
|
|
|
-/// </summary>
|
|
|
-public class GodotFileSystem : Zio.FileSystems.FileSystem
|
|
|
+namespace TBL.GodotSharp.Content.FileSystem
|
|
|
{
|
|
|
/// <summary>
|
|
|
- /// 根目录
|
|
|
+ /// Godot 文件系统
|
|
|
/// </summary>
|
|
|
- private readonly string _rootPath;
|
|
|
+ public class GodotFileSystem : Zio.FileSystems.FileSystem
|
|
|
+ {
|
|
|
+ /// <summary>
|
|
|
+ /// 根目录
|
|
|
+ /// </summary>
|
|
|
+ private readonly string _rootPath;
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 目录工具
|
|
|
- /// </summary>
|
|
|
- private readonly Godot.Directory _directoryTool;
|
|
|
+ /// <summary>
|
|
|
+ /// 目录工具
|
|
|
+ /// </summary>
|
|
|
+ private readonly Godot.Directory _directoryTool;
|
|
|
|
|
|
- public GodotFileSystem(string rootPath)
|
|
|
- {
|
|
|
- _rootPath = rootPath;
|
|
|
- _directoryTool = new Godot.Directory();
|
|
|
- }
|
|
|
+ public GodotFileSystem(string rootPath)
|
|
|
+ {
|
|
|
+ _rootPath = rootPath;
|
|
|
+ _directoryTool = new Godot.Directory();
|
|
|
+ }
|
|
|
|
|
|
- private string GetFullPath(UPath uPath) => $"{_rootPath}{uPath}";
|
|
|
-
|
|
|
- protected override void CreateDirectoryImpl(UPath path)
|
|
|
- {
|
|
|
- _directoryTool.MakeDirRecursive(GetFullPath(path));
|
|
|
- }
|
|
|
+ private string GetFullPath(UPath uPath) => $"{_rootPath}{uPath}";
|
|
|
|
|
|
- protected override bool DirectoryExistsImpl(UPath path) => _directoryTool.DirExists(GetFullPath(path));
|
|
|
-
|
|
|
- protected override bool FileExistsImpl(UPath path) => _directoryTool.FileExists(GetFullPath(path));
|
|
|
-
|
|
|
- protected override Stream OpenFileImpl(UPath path, FileMode mode, FileAccess access, FileShare share)
|
|
|
- {
|
|
|
- if (mode == FileMode.Open && access == FileAccess.Read)
|
|
|
+ protected override void CreateDirectoryImpl(UPath path)
|
|
|
{
|
|
|
- return new GodotFileStream(GetFullPath(path), Godot.File.ModeFlags.Read);
|
|
|
+ _directoryTool.MakeDirRecursive(GetFullPath(path));
|
|
|
}
|
|
|
|
|
|
- throw new FileNotFoundException();
|
|
|
- }
|
|
|
-
|
|
|
- protected override IEnumerable<UPath> EnumeratePathsImpl(
|
|
|
- UPath path,
|
|
|
- string searchPattern,
|
|
|
- SearchOption searchOption,
|
|
|
- SearchTarget searchTarget
|
|
|
- )
|
|
|
- {
|
|
|
- var directoryTool = new Godot.Directory();
|
|
|
- var err = directoryTool.Open(GetFullPath(path));
|
|
|
- if (err != Error.Ok)
|
|
|
- throw new IOException($"{err}");
|
|
|
- directoryTool.ListDirBegin();
|
|
|
- for (var current = directoryTool.GetNext();; current = directoryTool.GetNext())
|
|
|
- {
|
|
|
- if (string.IsNullOrEmpty(current))
|
|
|
- break;
|
|
|
- if (current is ".." or ".")
|
|
|
- continue;
|
|
|
- if ((searchTarget == SearchTarget.Both || searchTarget == SearchTarget.File) &&
|
|
|
- !directoryTool.CurrentIsDir())
|
|
|
- yield return System.IO.Path.Combine(path.FullName, current);
|
|
|
- if ((searchTarget == SearchTarget.Both || searchTarget == SearchTarget.Directory) &&
|
|
|
- directoryTool.CurrentIsDir())
|
|
|
- yield return System.IO.Path.Combine(path.FullName, current);
|
|
|
- if (directoryTool.CurrentIsDir() && searchOption == SearchOption.AllDirectories)
|
|
|
+ protected override bool DirectoryExistsImpl(UPath path) => _directoryTool.DirExists(GetFullPath(path));
|
|
|
+
|
|
|
+ protected override bool FileExistsImpl(UPath path) => _directoryTool.FileExists(GetFullPath(path));
|
|
|
+
|
|
|
+ protected override Stream OpenFileImpl(UPath path, FileMode mode, FileAccess access, FileShare share)
|
|
|
+ {
|
|
|
+ if (mode == FileMode.Open && access == FileAccess.Read)
|
|
|
+ {
|
|
|
+ return new GodotFileStream(GetFullPath(path), Godot.File.ModeFlags.Read);
|
|
|
+ }
|
|
|
+
|
|
|
+ throw new FileNotFoundException();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override IEnumerable<UPath> EnumeratePathsImpl(
|
|
|
+ UPath path,
|
|
|
+ string searchPattern,
|
|
|
+ SearchOption searchOption,
|
|
|
+ SearchTarget searchTarget
|
|
|
+ )
|
|
|
+ {
|
|
|
+ var directoryTool = new Godot.Directory();
|
|
|
+ var err = directoryTool.Open(GetFullPath(path));
|
|
|
+ if (err != Error.Ok)
|
|
|
+ throw new IOException($"{err}");
|
|
|
+ directoryTool.ListDirBegin();
|
|
|
+
|
|
|
+ var searchPatternMatcher = SearchPattern.Parse(ref path, ref searchPattern);
|
|
|
+
|
|
|
+ for (var current = directoryTool.GetNext();; current = directoryTool.GetNext())
|
|
|
{
|
|
|
- foreach (var sub in EnumeratePathsImpl(System.IO.Path.Combine(path.FullName, current),
|
|
|
- searchPattern, searchOption, searchTarget))
|
|
|
+ if (string.IsNullOrEmpty(current))
|
|
|
+ break;
|
|
|
+ if (current == ".." || current == ".")
|
|
|
+ continue;
|
|
|
+ if ((searchTarget == SearchTarget.Both || searchTarget == SearchTarget.File) &&
|
|
|
+ !directoryTool.CurrentIsDir() && searchPatternMatcher.Match(current))
|
|
|
+ yield return System.IO.Path.Combine(path.FullName, current);
|
|
|
+ if ((searchTarget == SearchTarget.Both || searchTarget == SearchTarget.Directory) &&
|
|
|
+ directoryTool.CurrentIsDir() && searchPatternMatcher.Match(current))
|
|
|
+ yield return System.IO.Path.Combine(path.FullName, current);
|
|
|
+ if (directoryTool.CurrentIsDir() && searchOption == SearchOption.AllDirectories)
|
|
|
{
|
|
|
- yield return sub;
|
|
|
+ foreach (var sub in EnumeratePathsImpl(System.IO.Path.Combine(path.FullName, current),
|
|
|
+ searchPattern, searchOption, searchTarget))
|
|
|
+ {
|
|
|
+ yield return sub;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ directoryTool.ListDirEnd();
|
|
|
}
|
|
|
- directoryTool.ListDirEnd();
|
|
|
- }
|
|
|
|
|
|
- protected override void MoveDirectoryImpl(UPath srcPath, UPath destPath)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
+ protected override void MoveDirectoryImpl(UPath srcPath, UPath destPath)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
|
|
|
- protected override void DeleteDirectoryImpl(UPath path, bool isRecursive)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
+ protected override void DeleteDirectoryImpl(UPath path, bool isRecursive)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
|
|
|
- protected override void CopyFileImpl(UPath srcPath, UPath destPath, bool overwrite)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
+ protected override void CopyFileImpl(UPath srcPath, UPath destPath, bool overwrite)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
|
|
|
- protected override void ReplaceFileImpl(UPath srcPath, UPath destPath, UPath destBackupPath, bool ignoreMetadataErrors)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
+ protected override void ReplaceFileImpl(UPath srcPath, UPath destPath, UPath destBackupPath, bool ignoreMetadataErrors)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
|
|
|
- protected override long GetFileLengthImpl(UPath path)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
+ protected override long GetFileLengthImpl(UPath path)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
|
|
|
- protected override void MoveFileImpl(UPath srcPath, UPath destPath)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
+ protected override void MoveFileImpl(UPath srcPath, UPath destPath)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
|
|
|
- protected override void DeleteFileImpl(UPath path)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
+ protected override void DeleteFileImpl(UPath path)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
|
|
|
- protected override FileAttributes GetAttributesImpl(UPath path)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
+ protected override FileAttributes GetAttributesImpl(UPath path)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
|
|
|
- protected override void SetAttributesImpl(UPath path, FileAttributes attributes)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
+ protected override void SetAttributesImpl(UPath path, FileAttributes attributes)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
|
|
|
- protected override DateTime GetCreationTimeImpl(UPath path)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
+ protected override DateTime GetCreationTimeImpl(UPath path)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
|
|
|
- protected override void SetCreationTimeImpl(UPath path, DateTime time)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
+ protected override void SetCreationTimeImpl(UPath path, DateTime time)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
|
|
|
- protected override DateTime GetLastAccessTimeImpl(UPath path)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
+ protected override DateTime GetLastAccessTimeImpl(UPath path)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
|
|
|
- protected override void SetLastAccessTimeImpl(UPath path, DateTime time)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
+ protected override void SetLastAccessTimeImpl(UPath path, DateTime time)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
|
|
|
- protected override DateTime GetLastWriteTimeImpl(UPath path)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
+ protected override DateTime GetLastWriteTimeImpl(UPath path)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
|
|
|
- protected override void SetLastWriteTimeImpl(UPath path, DateTime time)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
+ protected override void SetLastWriteTimeImpl(UPath path, DateTime time)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
|
|
|
- protected override IEnumerable<FileSystemItem> EnumerateItemsImpl(UPath path, SearchOption searchOption, SearchPredicate searchPredicate)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
+ protected override IEnumerable<FileSystemItem> EnumerateItemsImpl(UPath path, SearchOption searchOption, SearchPredicate searchPredicate)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
|
|
|
- protected override IFileSystemWatcher WatchImpl(UPath path)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
+ protected override IFileSystemWatcher WatchImpl(UPath path)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
|
|
|
- protected override string ConvertPathToInternalImpl(UPath path)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
+ protected override string ConvertPathToInternalImpl(UPath path)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
|
|
|
- protected override UPath ConvertPathFromInternalImpl(string innerPath)
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
+ protected override UPath ConvertPathFromInternalImpl(string innerPath)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
}
|
|
|
-}
|
|
|
+}
|
|
|
+
|