mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Add DeleteDirectoryRecursively and CleanDirectoryRecursively
This commit is contained in:
parent
6590cad251
commit
3c45e7e71b
12 changed files with 144 additions and 5 deletions
|
@ -20,6 +20,28 @@ namespace LibHac.Nand
|
|||
Fs.DeleteDirectory(path);
|
||||
}
|
||||
|
||||
public void DeleteDirectoryRecursively(string path)
|
||||
{
|
||||
path = ToDiscUtilsPath(PathTools.Normalize(path));
|
||||
|
||||
Fs.DeleteDirectory(path, true);
|
||||
}
|
||||
|
||||
public void CleanDirectoryRecursively(string path)
|
||||
{
|
||||
path = ToDiscUtilsPath(PathTools.Normalize(path));
|
||||
|
||||
foreach (string file in Fs.GetFiles(path))
|
||||
{
|
||||
Fs.DeleteFile(file);
|
||||
}
|
||||
|
||||
foreach (string file in Fs.GetDirectories(path))
|
||||
{
|
||||
Fs.DeleteDirectory(file, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteFile(string path)
|
||||
{
|
||||
path = ToDiscUtilsPath(PathTools.Normalize(path));
|
||||
|
|
|
@ -64,6 +64,16 @@ namespace LibHac.IO
|
|||
BaseFileSystem.DeleteDirectory(path);
|
||||
}
|
||||
|
||||
public void DeleteDirectoryRecursively(string path)
|
||||
{
|
||||
BaseFileSystem.DeleteDirectoryRecursively(path);
|
||||
}
|
||||
|
||||
public void CleanDirectoryRecursively(string path)
|
||||
{
|
||||
BaseFileSystem.CleanDirectoryRecursively(path);
|
||||
}
|
||||
|
||||
public void DeleteFile(string path)
|
||||
{
|
||||
BaseFileSystem.DeleteFile(path);
|
||||
|
|
|
@ -91,6 +91,24 @@ namespace LibHac.IO
|
|||
BaseFileSystem.DeleteDirectory(path);
|
||||
}
|
||||
|
||||
public void DeleteDirectoryRecursively(string path)
|
||||
{
|
||||
path = PathTools.Normalize(path);
|
||||
|
||||
if (IsConcatenationFile(path)) throw new DirectoryNotFoundException();
|
||||
|
||||
BaseFileSystem.DeleteDirectoryRecursively(path);
|
||||
}
|
||||
|
||||
public void CleanDirectoryRecursively(string path)
|
||||
{
|
||||
path = PathTools.Normalize(path);
|
||||
|
||||
if (IsConcatenationFile(path)) throw new DirectoryNotFoundException();
|
||||
|
||||
BaseFileSystem.CleanDirectoryRecursively(path);
|
||||
}
|
||||
|
||||
public void DeleteFile(string path)
|
||||
{
|
||||
path = PathTools.Normalize(path);
|
||||
|
@ -220,7 +238,7 @@ namespace LibHac.IO
|
|||
|
||||
public void QueryEntry(Span<byte> outBuffer, ReadOnlySpan<byte> inBuffer, string path, QueryId queryId)
|
||||
{
|
||||
if(queryId != QueryId.MakeConcatFile) throw new NotSupportedException();
|
||||
if (queryId != QueryId.MakeConcatFile) throw new NotSupportedException();
|
||||
|
||||
SetConcatenationFileAttribute(path);
|
||||
}
|
||||
|
|
|
@ -182,6 +182,27 @@ namespace LibHac.IO
|
|||
{
|
||||
fs.QueryEntry(Span<byte>.Empty, Span<byte>.Empty, path, QueryId.MakeConcatFile);
|
||||
}
|
||||
|
||||
public static void CleanDirectoryRecursivelyGeneric(IDirectory directory)
|
||||
{
|
||||
IFileSystem fs = directory.ParentFileSystem;
|
||||
|
||||
foreach (DirectoryEntry entry in directory.Read())
|
||||
{
|
||||
if (entry.Type == DirectoryEntryType.Directory)
|
||||
{
|
||||
string subPath = directory.FullPath + '/' + entry.Name;
|
||||
IDirectory subDir = fs.OpenDirectory(subPath, OpenDirectoryMode.All);
|
||||
|
||||
CleanDirectoryRecursivelyGeneric(subDir);
|
||||
fs.DeleteDirectory(subPath);
|
||||
}
|
||||
else if (entry.Type == DirectoryEntryType.File)
|
||||
{
|
||||
fs.DeleteFile(directory.FullPath + '/' + entry.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
|
|
|
@ -33,9 +33,9 @@ namespace LibHac.IO
|
|||
/// <exception cref="IOException">An I/O error occurred while deleting the directory.</exception>
|
||||
void DeleteDirectory(string path);
|
||||
|
||||
//void DeleteDirectoryRecursively(string path);
|
||||
void DeleteDirectoryRecursively(string path);
|
||||
|
||||
//void CleanDirectoryRecursively(string path);
|
||||
void CleanDirectoryRecursively(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified file.
|
||||
|
|
|
@ -133,6 +133,8 @@ namespace LibHac.IO
|
|||
public void CreateDirectory(string path) => throw new NotSupportedException();
|
||||
public void CreateFile(string path, long size, CreateFileOptions options) => throw new NotSupportedException();
|
||||
public void DeleteDirectory(string path) => throw new NotSupportedException();
|
||||
public void DeleteDirectoryRecursively(string path) => throw new NotSupportedException();
|
||||
public void CleanDirectoryRecursively(string path) => throw new NotSupportedException();
|
||||
public void DeleteFile(string path) => throw new NotSupportedException();
|
||||
public void RenameDirectory(string srcPath, string dstPath) => throw new NotSupportedException();
|
||||
public void RenameFile(string srcPath, string dstPath) => throw new NotSupportedException();
|
||||
|
|
|
@ -75,8 +75,30 @@ namespace LibHac.IO
|
|||
{
|
||||
path = PathTools.Normalize(path);
|
||||
|
||||
string resolveLocalPath = ResolveLocalPath(path);
|
||||
Directory.Delete(resolveLocalPath);
|
||||
Directory.Delete(ResolveLocalPath(path));
|
||||
}
|
||||
|
||||
public void DeleteDirectoryRecursively(string path)
|
||||
{
|
||||
path = PathTools.Normalize(path);
|
||||
|
||||
Directory.Delete(ResolveLocalPath(path), true);
|
||||
}
|
||||
|
||||
public void CleanDirectoryRecursively(string path)
|
||||
{
|
||||
path = PathTools.Normalize(path);
|
||||
string localPath = ResolveLocalPath(path);
|
||||
|
||||
foreach (string file in Directory.EnumerateFiles(localPath))
|
||||
{
|
||||
File.Delete(file);
|
||||
}
|
||||
|
||||
foreach (string dir in Directory.EnumerateDirectories(localPath))
|
||||
{
|
||||
Directory.Delete(dir, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteFile(string path)
|
||||
|
|
|
@ -78,6 +78,8 @@ namespace LibHac.IO
|
|||
public void CreateDirectory(string path) => throw new NotSupportedException();
|
||||
public void CreateFile(string path, long size, CreateFileOptions options) => throw new NotSupportedException();
|
||||
public void DeleteDirectory(string path) => throw new NotSupportedException();
|
||||
public void DeleteDirectoryRecursively(string path) => throw new NotSupportedException();
|
||||
public void CleanDirectoryRecursively(string path) => throw new NotSupportedException();
|
||||
public void DeleteFile(string path) => throw new NotSupportedException();
|
||||
public void RenameDirectory(string srcPath, string dstPath) => throw new NotSupportedException();
|
||||
public void RenameFile(string srcPath, string dstPath) => throw new NotSupportedException();
|
||||
|
|
|
@ -86,6 +86,8 @@ namespace LibHac.IO.RomFs
|
|||
public void CreateDirectory(string path) => throw new NotSupportedException();
|
||||
public void CreateFile(string path, long size, CreateFileOptions options) => throw new NotSupportedException();
|
||||
public void DeleteDirectory(string path) => throw new NotSupportedException();
|
||||
public void DeleteDirectoryRecursively(string path) => throw new NotSupportedException();
|
||||
public void CleanDirectoryRecursively(string path) => throw new NotSupportedException();
|
||||
public void DeleteFile(string path) => throw new NotSupportedException();
|
||||
public void RenameDirectory(string srcPath, string dstPath) => throw new NotSupportedException();
|
||||
public void RenameFile(string srcPath, string dstPath) => throw new NotSupportedException();
|
||||
|
|
|
@ -157,6 +157,16 @@ namespace LibHac.IO.Save
|
|||
SaveDataFileSystemCore.DeleteDirectory(path);
|
||||
}
|
||||
|
||||
public void DeleteDirectoryRecursively(string path)
|
||||
{
|
||||
SaveDataFileSystemCore.DeleteDirectoryRecursively(path);
|
||||
}
|
||||
|
||||
public void CleanDirectoryRecursively(string path)
|
||||
{
|
||||
SaveDataFileSystemCore.CleanDirectoryRecursively(path);
|
||||
}
|
||||
|
||||
public void DeleteFile(string path)
|
||||
{
|
||||
SaveDataFileSystemCore.DeleteFile(path);
|
||||
|
|
|
@ -49,6 +49,22 @@ namespace LibHac.IO.Save
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void DeleteDirectoryRecursively(string path)
|
||||
{
|
||||
path = PathTools.Normalize(path);
|
||||
|
||||
CleanDirectoryRecursively(path);
|
||||
DeleteDirectory(path);
|
||||
}
|
||||
|
||||
public void CleanDirectoryRecursively(string path)
|
||||
{
|
||||
path = PathTools.Normalize(path);
|
||||
|
||||
IDirectory dir = OpenDirectory(path, OpenDirectoryMode.All);
|
||||
FileSystemExtensions.CleanDirectoryRecursivelyGeneric(dir);
|
||||
}
|
||||
|
||||
public void DeleteFile(string path)
|
||||
{
|
||||
path = PathTools.Normalize(path);
|
||||
|
|
|
@ -40,6 +40,20 @@ namespace LibHac.IO
|
|||
ParentFileSystem.DeleteDirectory(ResolveFullPath(path));
|
||||
}
|
||||
|
||||
public void DeleteDirectoryRecursively(string path)
|
||||
{
|
||||
path = PathTools.Normalize(path);
|
||||
|
||||
ParentFileSystem.DeleteDirectoryRecursively(ResolveFullPath(path));
|
||||
}
|
||||
|
||||
public void CleanDirectoryRecursively(string path)
|
||||
{
|
||||
path = PathTools.Normalize(path);
|
||||
|
||||
ParentFileSystem.CleanDirectoryRecursively(ResolveFullPath(path));
|
||||
}
|
||||
|
||||
public void DeleteFile(string path)
|
||||
{
|
||||
path = PathTools.Normalize(path);
|
||||
|
|
Loading…
Reference in a new issue