Add delete mode options for VFS

This commit is contained in:
duckdoom4
2023-09-09 20:08:29 +02:00
parent 994a19466f
commit dc63ab38dc
10 changed files with 49 additions and 13 deletions

View File

@@ -212,9 +212,26 @@ public void CreateDirectory(FileSystemPath path)
fs.CreateDirectory(path);
}
public void Delete(FileSystemPath path)
public void Delete(FileSystemPath path, DeleteMode mode = DeleteMode.TopMostLayer)
{
foreach (var fs in FileSystems.Where(fs => fs.Exists(path)))
fs.Delete(path);
switch (mode)
{
case DeleteMode.TopMostLayer:
GetFirstWhereExists(path)?.Delete(path);
break;
case DeleteMode.TopMostWriteableLayer:
GetFirstWritableWhereExists(path)?.Delete(path);
break;
case DeleteMode.AllWritable:
foreach (var fs in FileSystems.Where(fs => !fs.IsReadOnly && fs.Exists(path)))
fs.Delete(path);
break;
case DeleteMode.All:
foreach (var fs in FileSystems.Where(fs => fs.Exists(path)))
fs.Delete(path);
break;
default:
throw new ArgumentOutOfRangeException(nameof(mode), mode, null);
}
}
}