2024-12-19 23:07:52 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using ZXL.Helper;
|
|
|
|
|
|
|
|
|
|
namespace ZXLT.FileSystem
|
2024-12-18 23:46:42 +08:00
|
|
|
|
{
|
2024-12-19 23:07:52 +08:00
|
|
|
|
class FileBase
|
2024-12-18 23:46:42 +08:00
|
|
|
|
{
|
2024-12-19 23:07:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Directory : FileBase
|
|
|
|
|
{
|
|
|
|
|
DirectoryInfo directoryInfo;
|
|
|
|
|
|
|
|
|
|
List<Directory> directories = new List<Directory>();
|
|
|
|
|
List<File> files = new List<File>();
|
|
|
|
|
|
|
|
|
|
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<FileSystemInfo> 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<string, FileBase> fileBases = new SortedDictionary<string, FileBase>();
|
|
|
|
|
public event Action<FileSystemInfo> 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();
|
|
|
|
|
}
|
2024-12-18 23:46:42 +08:00
|
|
|
|
}
|
|
|
|
|
}
|