2024-07-12 06:15:38 +00:00
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
namespace Common;
|
|
|
|
|
|
|
|
public abstract class FileDirOp
|
|
|
|
{
|
2024-07-26 04:49:08 +00:00
|
|
|
public abstract void FileCreate(string absolutePath, DateTime mtime);
|
2024-07-12 06:15:38 +00:00
|
|
|
|
2024-07-26 04:49:08 +00:00
|
|
|
public abstract void DirCreate(Dir dir, bool IsRecursion = true);
|
2024-07-12 06:15:38 +00:00
|
|
|
|
2024-07-26 04:49:08 +00:00
|
|
|
public abstract void FileModify(string absolutePath, DateTime mtime);
|
|
|
|
public abstract void FileDel(string absolutePath);
|
|
|
|
public abstract void DirDel(Dir dir, bool IsRecursion = true);
|
2024-07-12 06:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public class SimpleFileDirOpForTest : FileDirOp
|
|
|
|
{
|
2024-07-26 04:49:08 +00:00
|
|
|
public override void FileCreate(string absolutePath, DateTime mtime)
|
2024-07-12 06:15:38 +00:00
|
|
|
{
|
|
|
|
using (FileStream fs = System.IO.File.OpenWrite(absolutePath))
|
|
|
|
{
|
|
|
|
byte[] info = Encoding.UTF8.GetBytes($"this is {absolutePath},Now{mtime}");
|
|
|
|
fs.Write(info, 0, info.Length);
|
|
|
|
}
|
|
|
|
System.IO.File.SetLastWriteTime(absolutePath, mtime);
|
|
|
|
}
|
|
|
|
|
2024-07-26 04:49:08 +00:00
|
|
|
public override void FileModify(string absolutePath, DateTime mtime)
|
2024-07-12 06:15:38 +00:00
|
|
|
{
|
|
|
|
using (FileStream fs = System.IO.File.OpenWrite(absolutePath))
|
|
|
|
{
|
|
|
|
byte[] info = Encoding.UTF8.GetBytes($"this is {absolutePath},Now{mtime}");
|
|
|
|
fs.Write(info, 0, info.Length);
|
|
|
|
}
|
|
|
|
System.IO.File.SetLastWriteTime(absolutePath, mtime);
|
|
|
|
}
|
|
|
|
|
2024-07-26 04:49:08 +00:00
|
|
|
public override void FileDel(string absolutePath)
|
2024-07-12 06:15:38 +00:00
|
|
|
{
|
|
|
|
//ToDo 权限检查
|
|
|
|
if (System.IO.File.Exists(absolutePath))
|
|
|
|
{
|
|
|
|
System.IO.File.Delete(absolutePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-26 04:49:08 +00:00
|
|
|
public override void DirCreate(Dir dir, bool IsRecursion = true)
|
2024-07-12 06:15:38 +00:00
|
|
|
{
|
|
|
|
//TODO需做权限检查
|
|
|
|
if (!Directory.Exists(dir.FormatedPath))
|
|
|
|
{
|
|
|
|
Directory.CreateDirectory(dir.FormatedPath);
|
|
|
|
if (IsRecursion)
|
|
|
|
{
|
|
|
|
foreach (var fd in dir.Children)
|
|
|
|
{
|
|
|
|
if (fd is File file)
|
|
|
|
{
|
|
|
|
this.FileCreate(file.FormatedPath, file.MTime);
|
|
|
|
}
|
|
|
|
else if (fd is Dir sdir)
|
|
|
|
{
|
|
|
|
DirCreate(sdir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-26 04:49:08 +00:00
|
|
|
public override void DirDel(Dir dir, bool IsRecursion = true)
|
2024-07-12 06:15:38 +00:00
|
|
|
{
|
|
|
|
//TODO 权限检查 正式徐执行递归
|
|
|
|
if (!IsRecursion)
|
|
|
|
{
|
|
|
|
if (Directory.Exists(dir.FormatedPath))
|
|
|
|
{
|
|
|
|
Directory.Delete(dir.FormatedPath, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|