Add GetFreeSpaceSize and GetTotalSpaceSize

This commit is contained in:
Alex Barney 2019-05-07 21:42:54 -05:00
parent bc22d6dd99
commit f1e839a64a
13 changed files with 96 additions and 3 deletions

View file

@ -106,6 +106,16 @@ namespace LibHac.Nand
return timeStamp;
}
public long GetFreeSpaceSize(string path)
{
return Fs.AvailableSpace;
}
public long GetTotalSpaceSize(string path)
{
return Fs.Size;
}
public void Commit() { }
public void CreateDirectory(string path) => throw new NotSupportedException();

View file

@ -184,6 +184,16 @@ namespace LibHac.IO
return BaseFileSystem.GetFileTimeStampRaw(path);
}
public long GetFreeSpaceSize(string path)
{
return BaseFileSystem.GetFreeSpaceSize(path);
}
public long GetTotalSpaceSize(string path)
{
return BaseFileSystem.GetTotalSpaceSize(path);
}
public void Commit()
{
BaseFileSystem.Commit();

View file

@ -198,6 +198,16 @@ namespace LibHac.IO
return BaseFileSystem.GetEntryType(path);
}
public long GetFreeSpaceSize(string path)
{
return BaseFileSystem.GetFreeSpaceSize(path);
}
public long GetTotalSpaceSize(string path)
{
return BaseFileSystem.GetTotalSpaceSize(path);
}
public FileTimeStampRaw GetFileTimeStampRaw(string path)
{
return BaseFileSystem.GetFileTimeStampRaw(path);

View file

@ -105,9 +105,9 @@ namespace LibHac.IO
/// <exception cref="FileNotFoundException">The specified path does not exist.</exception>
DirectoryEntryType GetEntryType(string path);
//long GetFreeSpaceSize(string path);
long GetFreeSpaceSize(string path);
//long GetTotalSpaceSize(string path);
long GetTotalSpaceSize(string path);
FileTimeStampRaw GetFileTimeStampRaw(string path);

View file

@ -136,5 +136,7 @@ namespace LibHac.IO
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();
public long GetFreeSpaceSize(string path) => throw new NotSupportedException();
public long GetTotalSpaceSize(string path) => throw new NotSupportedException();
}
}

View file

@ -174,6 +174,16 @@ namespace LibHac.IO
return timeStamp;
}
public long GetFreeSpaceSize(string path)
{
return new DriveInfo(BasePath).AvailableFreeSpace;
}
public long GetTotalSpaceSize(string path)
{
return new DriveInfo(BasePath).TotalSize;
}
public void Commit() { }
public void QueryEntry(Span<byte> outBuffer, Span<byte> inBuffer, string path, QueryId queryId) => throw new NotSupportedException();

View file

@ -81,6 +81,8 @@ namespace LibHac.IO
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();
public long GetFreeSpaceSize(string path) => throw new NotSupportedException();
public long GetTotalSpaceSize(string path) => throw new NotSupportedException();
public FileTimeStampRaw GetFileTimeStampRaw(string path) => throw new NotSupportedException();
public void Commit() { }
public void QueryEntry(Span<byte> outBuffer, Span<byte> inBuffer, string path, QueryId queryId) => throw new NotSupportedException();

View file

@ -89,6 +89,8 @@ namespace LibHac.IO.RomFs
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();
public long GetFreeSpaceSize(string path) => throw new NotSupportedException();
public long GetTotalSpaceSize(string path) => throw new NotSupportedException();
public FileTimeStampRaw GetFileTimeStampRaw(string path) => throw new NotSupportedException();
public void QueryEntry(Span<byte> outBuffer, Span<byte> inBuffer, string path, QueryId queryId) => throw new NotSupportedException();
}

View file

@ -272,6 +272,15 @@ namespace LibHac.IO.Save
WriteEntry(segAIndex, segA);
}
public int GetFreeListLength()
{
int freeListStart = GetFreeListBlockIndex();
if (freeListStart == -1) return 0;
return GetListLength(freeListStart);
}
public int GetListLength(int blockIndex)
{
int index = blockIndex;

View file

@ -190,6 +190,16 @@ namespace LibHac.IO.Save
return SaveDataFileSystemCore.GetEntryType(path);
}
public long GetFreeSpaceSize(string path)
{
return SaveDataFileSystemCore.GetFreeSpaceSize(path);
}
public long GetTotalSpaceSize(string path)
{
return SaveDataFileSystemCore.GetTotalSpaceSize(path);
}
public void Commit()
{
Commit(Keyset);

View file

@ -126,6 +126,17 @@ namespace LibHac.IO.Save
throw new FileNotFoundException(path);
}
public long GetFreeSpaceSize(string path)
{
int freeBlockCount = AllocationTable.GetFreeListLength();
return Header.BlockSize * freeBlockCount;
}
public long GetTotalSpaceSize(string path)
{
return Header.BlockSize * Header.BlockCount;
}
public void Commit()
{

View file

@ -105,6 +105,20 @@ namespace LibHac.IO
ParentFileSystem.Commit();
}
public long GetFreeSpaceSize(string path)
{
path = PathTools.Normalize(path);
return ParentFileSystem.GetFreeSpaceSize(ResolveFullPath(path));
}
public long GetTotalSpaceSize(string path)
{
path = PathTools.Normalize(path);
return ParentFileSystem.GetTotalSpaceSize(ResolveFullPath(path));
}
public FileTimeStampRaw GetFileTimeStampRaw(string path)
{
path = PathTools.Normalize(path);

View file

@ -269,6 +269,8 @@ namespace hactoolnet
var sb = new StringBuilder();
sb.AppendLine();
long freeSpace = save.GetFreeSpaceSize("");
sb.AppendLine("Savefile:");
PrintItem(sb, colLen, $"CMAC Signature{save.Header.SignatureValidity.GetValidityString()}:", save.Header.Cmac);
PrintItem(sb, colLen, "Title ID:", $"{save.Header.ExtraData.TitleId:x16}");
@ -279,6 +281,7 @@ namespace hactoolnet
PrintItem(sb, colLen, "Timestamp:", $"{DateTimeOffset.FromUnixTimeSeconds(save.Header.ExtraData.Timestamp):yyyy-MM-dd HH:mm:ss} UTC");
PrintItem(sb, colLen, "Save Data Size:", $"0x{save.Header.ExtraData.DataSize:x16} ({Util.GetBytesReadable(save.Header.ExtraData.DataSize)})");
PrintItem(sb, colLen, "Journal Size:", $"0x{save.Header.ExtraData.JournalSize:x16} ({Util.GetBytesReadable(save.Header.ExtraData.JournalSize)})");
PrintItem(sb, colLen, "Free Space:", $"0x{freeSpace:x16} ({Util.GetBytesReadable(freeSpace)})");
PrintItem(sb, colLen, $"Header Hash{save.Header.HeaderHashValidity.GetValidityString()}:", save.Header.Layout.Hash);
PrintItem(sb, colLen, "Number of Files:", save.EnumerateEntries().Count(x => x.Type == DirectoryEntryType.File));