From fb4d44c5eb4f8948d0b6f8d9939c8826db6862af Mon Sep 17 00:00:00 2001 From: zc <1062808664@qq.com> Date: Wed, 18 Dec 2024 21:58:26 +0800 Subject: [PATCH 1/3] Update .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index f771725..6b905c0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .idea/ .vscode/ _ReSharper.CSharp/ +.sln #svn */.svn/ @@ -41,3 +42,4 @@ obj/ Temp/ yoo /Assets/DemoGame/GameScript/Hotfix/Generate +/Packages From 1692f026437ee8263d006c196dc77aa507b2061a Mon Sep 17 00:00:00 2001 From: zc <1062808664@qq.com> Date: Wed, 18 Dec 2024 23:46:42 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E9=87=8D?= =?UTF-8?q?=E5=86=99=E6=96=87=E4=BB=B6=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/ZXL/Scripts/FileSystem.meta | 3 ++ .../ZXL/Scripts/FileSystem/DirectoryInfo.cs | 50 +++++++++++++++++++ .../Scripts/FileSystem/DirectoryInfo.cs.meta | 3 ++ Assets/ZXL/Scripts/FileSystem/FileInfo.cs | 35 +++++++++++++ .../ZXL/Scripts/FileSystem/FileInfo.cs.meta | 3 ++ Assets/ZXL/Scripts/FileSystem/FileSystem.cs | 7 +++ .../ZXL/Scripts/FileSystem/FileSystem.cs.meta | 3 ++ .../ZXL/Scripts/FileSystem/FileSystemInfo.cs | 14 ++++++ .../Scripts/FileSystem/FileSystemInfo.cs.meta | 3 ++ Assets/ZXL/Scripts/Manager/ZFileSystem.cs | 7 --- .../ZXL/Scripts/Manager/ZFileSystem.cs.meta | 3 -- EditorTool3D.sln.DotSettings.user | 3 ++ 12 files changed, 124 insertions(+), 10 deletions(-) create mode 100644 Assets/ZXL/Scripts/FileSystem.meta create mode 100644 Assets/ZXL/Scripts/FileSystem/DirectoryInfo.cs create mode 100644 Assets/ZXL/Scripts/FileSystem/DirectoryInfo.cs.meta create mode 100644 Assets/ZXL/Scripts/FileSystem/FileInfo.cs create mode 100644 Assets/ZXL/Scripts/FileSystem/FileInfo.cs.meta create mode 100644 Assets/ZXL/Scripts/FileSystem/FileSystem.cs create mode 100644 Assets/ZXL/Scripts/FileSystem/FileSystem.cs.meta create mode 100644 Assets/ZXL/Scripts/FileSystem/FileSystemInfo.cs create mode 100644 Assets/ZXL/Scripts/FileSystem/FileSystemInfo.cs.meta delete mode 100644 Assets/ZXL/Scripts/Manager/ZFileSystem.cs delete mode 100644 Assets/ZXL/Scripts/Manager/ZFileSystem.cs.meta diff --git a/Assets/ZXL/Scripts/FileSystem.meta b/Assets/ZXL/Scripts/FileSystem.meta new file mode 100644 index 0000000..3026ebe --- /dev/null +++ b/Assets/ZXL/Scripts/FileSystem.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 4df538268f04411baf7e6ed3f6f30196 +timeCreated: 1734530869 \ No newline at end of file diff --git a/Assets/ZXL/Scripts/FileSystem/DirectoryInfo.cs b/Assets/ZXL/Scripts/FileSystem/DirectoryInfo.cs new file mode 100644 index 0000000..71a7d42 --- /dev/null +++ b/Assets/ZXL/Scripts/FileSystem/DirectoryInfo.cs @@ -0,0 +1,50 @@ +using System.Collections.Generic; + +namespace ZXLT.FileSystem +{ + public sealed class DirectoryInfo : FileSystemInfo + { + List directories = new List(); + List files = new List(); + + public override bool Exists { get; } + public override string Name => _name; + + public DirectoryInfo Parent + { + get + { + var directoryInfo = new DirectoryInfo(System.IO.Path.GetDirectoryName(FullPath)); + return directoryInfo; + } + } + + public DirectoryInfo Root => new DirectoryInfo(System.IO.Path.GetPathRoot(this.FullPath)); + + public DirectoryInfo(string path) + { + this.Init(path, System.IO.Path.GetFullPath(path), isNormalized: true); + FullPath = path; + _name = path; + } + + private void Init(string originalPath, string fullPath = null, string fileName = null, bool isNormalized = false) + { + if (fullPath == null) + fullPath = originalPath; + fullPath = isNormalized ? fullPath : System.IO.Path.GetFullPath(fullPath); + this._name = fileName; + this.FullPath = fullPath; + } + + public DirectoryInfo[] GetDirectories() + { + return directories.ToArray(); + } + + public FileInfo[] GetFiles() + { + return files.ToArray(); + } + } +} \ No newline at end of file diff --git a/Assets/ZXL/Scripts/FileSystem/DirectoryInfo.cs.meta b/Assets/ZXL/Scripts/FileSystem/DirectoryInfo.cs.meta new file mode 100644 index 0000000..2467ec0 --- /dev/null +++ b/Assets/ZXL/Scripts/FileSystem/DirectoryInfo.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 65370db5c69842b881243c312e0c3ce2 +timeCreated: 1734532009 \ No newline at end of file diff --git a/Assets/ZXL/Scripts/FileSystem/FileInfo.cs b/Assets/ZXL/Scripts/FileSystem/FileInfo.cs new file mode 100644 index 0000000..0b8b612 --- /dev/null +++ b/Assets/ZXL/Scripts/FileSystem/FileInfo.cs @@ -0,0 +1,35 @@ +using System; +using System.IO; + +namespace ZXLT.FileSystem +{ + public sealed class FileInfo : FileSystemInfo + { + public string Extension { get; } + public override bool Exists { get; } + public override string Name => _name; + public string? DirectoryName => Path.GetDirectoryName(this.FullPath); + + public DirectoryInfo Directory + { + get + { + string directoryName = this.DirectoryName; + return new DirectoryInfo(directoryName); + } + } + + public FileInfo(string fileName) + : this(fileName ?? throw new ArgumentNullException(nameof(fileName)), (string)null, (string)null, false) + { + } + + internal FileInfo(string originalPath, string fullPath = null, string fileName = null, bool isNormalized = false) + { + if (fullPath == null) + fullPath = originalPath; + this.FullPath = isNormalized ? fullPath ?? originalPath : Path.GetFullPath(fullPath); + this._name = fileName; + } + } +} \ No newline at end of file diff --git a/Assets/ZXL/Scripts/FileSystem/FileInfo.cs.meta b/Assets/ZXL/Scripts/FileSystem/FileInfo.cs.meta new file mode 100644 index 0000000..5a8eb6b --- /dev/null +++ b/Assets/ZXL/Scripts/FileSystem/FileInfo.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: fdedcd6447e4414195754ba8f1f67072 +timeCreated: 1734532019 \ No newline at end of file diff --git a/Assets/ZXL/Scripts/FileSystem/FileSystem.cs b/Assets/ZXL/Scripts/FileSystem/FileSystem.cs new file mode 100644 index 0000000..8885867 --- /dev/null +++ b/Assets/ZXL/Scripts/FileSystem/FileSystem.cs @@ -0,0 +1,7 @@ +namespace ZXLT.FileSystem +{ + public class FileSystem + { + + } +} \ No newline at end of file diff --git a/Assets/ZXL/Scripts/FileSystem/FileSystem.cs.meta b/Assets/ZXL/Scripts/FileSystem/FileSystem.cs.meta new file mode 100644 index 0000000..21f4a27 --- /dev/null +++ b/Assets/ZXL/Scripts/FileSystem/FileSystem.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a1c6853ef5a44b3986a6a3854cc7ac1d +timeCreated: 1734530888 \ No newline at end of file diff --git a/Assets/ZXL/Scripts/FileSystem/FileSystemInfo.cs b/Assets/ZXL/Scripts/FileSystem/FileSystemInfo.cs new file mode 100644 index 0000000..6c1a5a9 --- /dev/null +++ b/Assets/ZXL/Scripts/FileSystem/FileSystemInfo.cs @@ -0,0 +1,14 @@ +using System; + +namespace ZXLT.FileSystem +{ + public abstract class FileSystemInfo + { + protected string _name; + protected string FullPath; + public DateTime CreationTime { get; set; } + public abstract bool Exists { get; } + public abstract string Name { get; } + public virtual string FullName => FullPath; + } +} \ No newline at end of file diff --git a/Assets/ZXL/Scripts/FileSystem/FileSystemInfo.cs.meta b/Assets/ZXL/Scripts/FileSystem/FileSystemInfo.cs.meta new file mode 100644 index 0000000..64d2f30 --- /dev/null +++ b/Assets/ZXL/Scripts/FileSystem/FileSystemInfo.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f977646b313a4fa3a7a98a2454009041 +timeCreated: 1734532034 \ No newline at end of file diff --git a/Assets/ZXL/Scripts/Manager/ZFileSystem.cs b/Assets/ZXL/Scripts/Manager/ZFileSystem.cs deleted file mode 100644 index c5151f9..0000000 --- a/Assets/ZXL/Scripts/Manager/ZFileSystem.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace ZXL.Manager -{ - public class ZFileSystem - { - - } -} \ No newline at end of file diff --git a/Assets/ZXL/Scripts/Manager/ZFileSystem.cs.meta b/Assets/ZXL/Scripts/Manager/ZFileSystem.cs.meta deleted file mode 100644 index 9ce9729..0000000 --- a/Assets/ZXL/Scripts/Manager/ZFileSystem.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 63f2843889a64090a60431d1d84b908c -timeCreated: 1734501412 \ No newline at end of file diff --git a/EditorTool3D.sln.DotSettings.user b/EditorTool3D.sln.DotSettings.user index 435a05b..013f128 100644 --- a/EditorTool3D.sln.DotSettings.user +++ b/EditorTool3D.sln.DotSettings.user @@ -1,4 +1,7 @@  ForceIncluded + ForceIncluded ForceIncluded + ForceIncluded + ForceIncluded ForceIncluded \ No newline at end of file From e28547e01fba3dd49f3ce281fa7d3579310124e2 Mon Sep 17 00:00:00 2001 From: zc <1062808664@qq.com> Date: Thu, 19 Dec 2024 23:07:52 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E9=87=8D=E6=9E=84=E8=99=9A=E6=8B=9F?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ZXL/Scripts/FileSystem/DirectoryInfo.cs | 40 +++--- Assets/ZXL/Scripts/FileSystem/FileInfo.cs | 16 +-- Assets/ZXL/Scripts/FileSystem/FileSystem.cs | 125 +++++++++++++++++- .../ZXL/Scripts/FileSystem/FileSystemInfo.cs | 9 +- 4 files changed, 152 insertions(+), 38 deletions(-) diff --git a/Assets/ZXL/Scripts/FileSystem/DirectoryInfo.cs b/Assets/ZXL/Scripts/FileSystem/DirectoryInfo.cs index 71a7d42..93c5fb8 100644 --- a/Assets/ZXL/Scripts/FileSystem/DirectoryInfo.cs +++ b/Assets/ZXL/Scripts/FileSystem/DirectoryInfo.cs @@ -4,17 +4,19 @@ namespace ZXLT.FileSystem { public sealed class DirectoryInfo : FileSystemInfo { - List directories = new List(); - List files = new List(); + // List directories = new List(); + // List files = new List(); public override bool Exists { get; } public override string Name => _name; + public override FileSystemInfoType FileSystemInfoType { get; } public DirectoryInfo Parent { get { - var directoryInfo = new DirectoryInfo(System.IO.Path.GetDirectoryName(FullPath)); + var parentPath = FullPath.Split("\\")[^1]; + var directoryInfo = new DirectoryInfo(System.IO.Path.GetFullPath(parentPath)); return directoryInfo; } } @@ -23,28 +25,18 @@ namespace ZXLT.FileSystem public DirectoryInfo(string path) { - this.Init(path, System.IO.Path.GetFullPath(path), isNormalized: true); - FullPath = path; - _name = path; + FullPath = System.IO.Path.GetFullPath(path); + _name = System.IO.Path.GetDirectoryName(path); } - private void Init(string originalPath, string fullPath = null, string fileName = null, bool isNormalized = false) - { - if (fullPath == null) - fullPath = originalPath; - fullPath = isNormalized ? fullPath : System.IO.Path.GetFullPath(fullPath); - this._name = fileName; - this.FullPath = fullPath; - } - - public DirectoryInfo[] GetDirectories() - { - return directories.ToArray(); - } - - public FileInfo[] GetFiles() - { - return files.ToArray(); - } + // public DirectoryInfo[] GetDirectories() + // { + // return directories.ToArray(); + // } + // + // public FileInfo[] GetFiles() + // { + // return files.ToArray(); + // } } } \ No newline at end of file diff --git a/Assets/ZXL/Scripts/FileSystem/FileInfo.cs b/Assets/ZXL/Scripts/FileSystem/FileInfo.cs index 0b8b612..2ff9529 100644 --- a/Assets/ZXL/Scripts/FileSystem/FileInfo.cs +++ b/Assets/ZXL/Scripts/FileSystem/FileInfo.cs @@ -5,9 +5,10 @@ namespace ZXLT.FileSystem { public sealed class FileInfo : FileSystemInfo { - public string Extension { get; } + public string Extension => Path.GetExtension(this.FullName); public override bool Exists { get; } public override string Name => _name; + public override FileSystemInfoType FileSystemInfoType { get; } public string? DirectoryName => Path.GetDirectoryName(this.FullPath); public DirectoryInfo Directory @@ -20,16 +21,11 @@ namespace ZXLT.FileSystem } public FileInfo(string fileName) - : this(fileName ?? throw new ArgumentNullException(nameof(fileName)), (string)null, (string)null, false) { - } - - internal FileInfo(string originalPath, string fullPath = null, string fileName = null, bool isNormalized = false) - { - if (fullPath == null) - fullPath = originalPath; - this.FullPath = isNormalized ? fullPath ?? originalPath : Path.GetFullPath(fullPath); - this._name = fileName; + fileName = fileName ?? throw new ArgumentNullException(nameof(fileName)); + _name = Path.GetFileName(fileName); + this.FullPath = Path.GetFullPath(fileName); + FileSystemInfoType = FileSystemInfoType.File; } } } \ No newline at end of file diff --git a/Assets/ZXL/Scripts/FileSystem/FileSystem.cs b/Assets/ZXL/Scripts/FileSystem/FileSystem.cs index 8885867..e171212 100644 --- a/Assets/ZXL/Scripts/FileSystem/FileSystem.cs +++ b/Assets/ZXL/Scripts/FileSystem/FileSystem.cs @@ -1,7 +1,126 @@ -namespace ZXLT.FileSystem +using System; +using System.Collections.Generic; +using ZXL.Helper; + +namespace ZXLT.FileSystem { - public class FileSystem + class FileBase { - + } + + class Directory : FileBase + { + DirectoryInfo directoryInfo; + + List directories = new List(); + List files = new List(); + + public Directory(DirectoryInfo directoryInfo) + { + this.directoryInfo = directoryInfo; + } + + public void AddDirectory(Directory dir) + { + directories.Add(dir); + } + + public void AddFile(File file) + { + files.Add(file); + } + + public void RemoveDirectory(Directory dir) + { + directories.Remove(dir); + } + + public void RemoveFile(File file) + { + files.Remove(file); + } + + public void Clear() + { + directories.Clear(); + } + } + + class File : FileBase + { + FileInfo fileInfo; + + public File(FileInfo fileInfo) + { + this.fileInfo = fileInfo; + } + } + + interface IFileSystem + { + event Action OnUpdateFileSystem; + void CreateDirectory(string path); + void DeleteDirectory(string path); + void DeleteFile(string path); + void MoveDirectory(string sourcePath, string destPath); + void MoveFile(string sourcePath, string destPath); + void RenameDirectory(string sourcePath, string destPath); + void RenameFile(string sourcePath, string destPath); + } + + public class FileSystem : IFileSystem + { + Directory rootDirectory; + SortedDictionary fileBases = new SortedDictionary(); + public event Action OnUpdateFileSystem; + + void UpdateFileSystem(FileSystemInfo systemInfo) + { + OnUpdateFileSystem?.Invoke(systemInfo); + } + + public void CreateDirectory(string path) + { + var directory = new Directory(new DirectoryInfo(path)); + fileBases.Add(path, directory); + FileHelper.CreateDirectory(path); + } + + public void CreateFile(string path) + { + var file = new File(new FileInfo(path)); + fileBases.Add(path, file); + FileHelper.CreateDirectory(path); + } + + public void DeleteDirectory(string path) + { + throw new NotImplementedException(); + } + + public void DeleteFile(string path) + { + throw new NotImplementedException(); + } + + public void MoveDirectory(string sourcePath, string destPath) + { + throw new NotImplementedException(); + } + + public void MoveFile(string sourcePath, string destPath) + { + throw new NotImplementedException(); + } + + public void RenameDirectory(string sourcePath, string destPath) + { + throw new NotImplementedException(); + } + + public void RenameFile(string sourcePath, string destPath) + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/Assets/ZXL/Scripts/FileSystem/FileSystemInfo.cs b/Assets/ZXL/Scripts/FileSystem/FileSystemInfo.cs index 6c1a5a9..77518b5 100644 --- a/Assets/ZXL/Scripts/FileSystem/FileSystemInfo.cs +++ b/Assets/ZXL/Scripts/FileSystem/FileSystemInfo.cs @@ -2,13 +2,20 @@ namespace ZXLT.FileSystem { + public enum FileSystemInfoType + { + File, + Directory, + } + public abstract class FileSystemInfo { protected string _name; protected string FullPath; - public DateTime CreationTime { get; set; } + public DateTime CreationTime { get; } public abstract bool Exists { get; } public abstract string Name { get; } public virtual string FullName => FullPath; + public abstract FileSystemInfoType FileSystemInfoType { get; } } } \ No newline at end of file