From bc22d6dd993444ff18f25b9e76a3f74362b78fee Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Tue, 7 May 2019 18:30:04 -0500 Subject: [PATCH] Add GetFileTimeStampRaw --- src/LibHac.Nand/FatFileSystemProvider.cs | 14 ++++++++++++++ src/LibHac/IO/AesXtsFileSystem.cs | 5 +++++ src/LibHac/IO/ConcatenationFileSystem.cs | 5 +++++ src/LibHac/IO/FileTimeStamp.cs | 9 +++++++++ src/LibHac/IO/IFileSystem.cs | 10 ++++++++++ src/LibHac/IO/LayeredFileSystem.cs | 15 +++++++++++++++ src/LibHac/IO/LocalFileSystem.cs | 14 ++++++++++++++ src/LibHac/IO/PartitionFileSystem.cs | 1 + src/LibHac/IO/RomFs/RomFsFileSystem.cs | 1 + src/LibHac/IO/Save/SaveDataFileSystem.cs | 1 + src/LibHac/IO/Save/SaveDataFileSystemCore.cs | 1 + src/LibHac/IO/SubdirectoryFileSystem.cs | 9 +++++++++ 12 files changed, 85 insertions(+) create mode 100644 src/LibHac/IO/FileTimeStamp.cs diff --git a/src/LibHac.Nand/FatFileSystemProvider.cs b/src/LibHac.Nand/FatFileSystemProvider.cs index 1c814a69..b16baa15 100644 --- a/src/LibHac.Nand/FatFileSystemProvider.cs +++ b/src/LibHac.Nand/FatFileSystemProvider.cs @@ -92,6 +92,20 @@ namespace LibHac.Nand return Fs.GetFileInfo(path).Length; } + public FileTimeStampRaw GetFileTimeStampRaw(string path) + { + path = PathTools.Normalize(path); + string localPath = ToDiscUtilsPath(path); + + FileTimeStampRaw timeStamp = default; + + timeStamp.Created = new DateTimeOffset(Fs.GetCreationTime(localPath)).ToUnixTimeSeconds(); + timeStamp.Accessed = new DateTimeOffset(Fs.GetLastAccessTime(localPath)).ToUnixTimeSeconds(); + timeStamp.Modified = new DateTimeOffset(Fs.GetLastWriteTime(localPath)).ToUnixTimeSeconds(); + + return timeStamp; + } + public void Commit() { } public void CreateDirectory(string path) => throw new NotSupportedException(); diff --git a/src/LibHac/IO/AesXtsFileSystem.cs b/src/LibHac/IO/AesXtsFileSystem.cs index 5dbd1b30..c9c7bce3 100644 --- a/src/LibHac/IO/AesXtsFileSystem.cs +++ b/src/LibHac/IO/AesXtsFileSystem.cs @@ -179,6 +179,11 @@ namespace LibHac.IO return BaseFileSystem.GetEntryType(path); } + public FileTimeStampRaw GetFileTimeStampRaw(string path) + { + return BaseFileSystem.GetFileTimeStampRaw(path); + } + public void Commit() { BaseFileSystem.Commit(); diff --git a/src/LibHac/IO/ConcatenationFileSystem.cs b/src/LibHac/IO/ConcatenationFileSystem.cs index 350ec27c..f62bd54f 100644 --- a/src/LibHac/IO/ConcatenationFileSystem.cs +++ b/src/LibHac/IO/ConcatenationFileSystem.cs @@ -198,6 +198,11 @@ namespace LibHac.IO return BaseFileSystem.GetEntryType(path); } + public FileTimeStampRaw GetFileTimeStampRaw(string path) + { + return BaseFileSystem.GetFileTimeStampRaw(path); + } + public void Commit() { BaseFileSystem.Commit(); diff --git a/src/LibHac/IO/FileTimeStamp.cs b/src/LibHac/IO/FileTimeStamp.cs new file mode 100644 index 00000000..60b9fae3 --- /dev/null +++ b/src/LibHac/IO/FileTimeStamp.cs @@ -0,0 +1,9 @@ +namespace LibHac.IO +{ + public struct FileTimeStampRaw + { + public long Created; + public long Accessed; + public long Modified; + } +} diff --git a/src/LibHac/IO/IFileSystem.cs b/src/LibHac/IO/IFileSystem.cs index 902d9cbd..d597baf8 100644 --- a/src/LibHac/IO/IFileSystem.cs +++ b/src/LibHac/IO/IFileSystem.cs @@ -33,6 +33,10 @@ namespace LibHac.IO /// An I/O error occurred while deleting the directory. void DeleteDirectory(string path); + //void DeleteDirectoryRecursively(string path); + + //void CleanDirectoryRecursively(string path); + /// /// Deletes the specified file. /// @@ -101,6 +105,12 @@ namespace LibHac.IO /// The specified path does not exist. DirectoryEntryType GetEntryType(string path); + //long GetFreeSpaceSize(string path); + + //long GetTotalSpaceSize(string path); + + FileTimeStampRaw GetFileTimeStampRaw(string path); + /// /// Commits any changes to a transactional file system. /// Does nothing if called on a non-transactional file system. diff --git a/src/LibHac/IO/LayeredFileSystem.cs b/src/LibHac/IO/LayeredFileSystem.cs index 9a37781e..daece15f 100644 --- a/src/LibHac/IO/LayeredFileSystem.cs +++ b/src/LibHac/IO/LayeredFileSystem.cs @@ -97,6 +97,21 @@ namespace LibHac.IO throw new FileNotFoundException(path); } + public FileTimeStampRaw GetFileTimeStampRaw(string path) + { + path = PathTools.Normalize(path); + + foreach (IFileSystem fs in Sources) + { + if (fs.FileExists(path) || fs.DirectoryExists(path)) + { + return fs.GetFileTimeStampRaw(path); + } + } + + throw new FileNotFoundException(path); + } + public void QueryEntry(Span outBuffer, Span inBuffer, string path, QueryId queryId) { path = PathTools.Normalize(path); diff --git a/src/LibHac/IO/LocalFileSystem.cs b/src/LibHac/IO/LocalFileSystem.cs index 0b9d0b6b..3db52ec6 100644 --- a/src/LibHac/IO/LocalFileSystem.cs +++ b/src/LibHac/IO/LocalFileSystem.cs @@ -160,6 +160,20 @@ namespace LibHac.IO throw new FileNotFoundException(path); } + public FileTimeStampRaw GetFileTimeStampRaw(string path) + { + path = PathTools.Normalize(path); + string localPath = ResolveLocalPath(path); + + FileTimeStampRaw timeStamp = default; + + timeStamp.Created = new DateTimeOffset(File.GetCreationTime(localPath)).ToUnixTimeSeconds(); + timeStamp.Accessed = new DateTimeOffset(File.GetLastAccessTime(localPath)).ToUnixTimeSeconds(); + timeStamp.Modified = new DateTimeOffset(File.GetLastWriteTime(localPath)).ToUnixTimeSeconds(); + + return timeStamp; + } + public void Commit() { } public void QueryEntry(Span outBuffer, Span inBuffer, string path, QueryId queryId) => throw new NotSupportedException(); diff --git a/src/LibHac/IO/PartitionFileSystem.cs b/src/LibHac/IO/PartitionFileSystem.cs index 9cedb78c..bf1c29e2 100644 --- a/src/LibHac/IO/PartitionFileSystem.cs +++ b/src/LibHac/IO/PartitionFileSystem.cs @@ -81,6 +81,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 FileTimeStampRaw GetFileTimeStampRaw(string path) => throw new NotSupportedException(); public void Commit() { } public void QueryEntry(Span outBuffer, Span inBuffer, string path, QueryId queryId) => throw new NotSupportedException(); } diff --git a/src/LibHac/IO/RomFs/RomFsFileSystem.cs b/src/LibHac/IO/RomFs/RomFsFileSystem.cs index 8dc2fc82..ecc9981e 100644 --- a/src/LibHac/IO/RomFs/RomFsFileSystem.cs +++ b/src/LibHac/IO/RomFs/RomFsFileSystem.cs @@ -89,6 +89,7 @@ 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 FileTimeStampRaw GetFileTimeStampRaw(string path) => throw new NotSupportedException(); public void QueryEntry(Span outBuffer, Span inBuffer, string path, QueryId queryId) => throw new NotSupportedException(); } diff --git a/src/LibHac/IO/Save/SaveDataFileSystem.cs b/src/LibHac/IO/Save/SaveDataFileSystem.cs index 6c645918..d1207656 100644 --- a/src/LibHac/IO/Save/SaveDataFileSystem.cs +++ b/src/LibHac/IO/Save/SaveDataFileSystem.cs @@ -195,6 +195,7 @@ namespace LibHac.IO.Save Commit(Keyset); } + public FileTimeStampRaw GetFileTimeStampRaw(string path) => throw new NotSupportedException(); public void QueryEntry(Span outBuffer, Span inBuffer, string path, QueryId queryId) => throw new NotSupportedException(); public bool Commit(Keyset keyset) diff --git a/src/LibHac/IO/Save/SaveDataFileSystemCore.cs b/src/LibHac/IO/Save/SaveDataFileSystemCore.cs index 1e777e32..72488ef2 100644 --- a/src/LibHac/IO/Save/SaveDataFileSystemCore.cs +++ b/src/LibHac/IO/Save/SaveDataFileSystemCore.cs @@ -131,6 +131,7 @@ namespace LibHac.IO.Save } + public FileTimeStampRaw GetFileTimeStampRaw(string path) => throw new NotSupportedException(); public void QueryEntry(Span outBuffer, Span inBuffer, string path, QueryId queryId) => throw new NotSupportedException(); public IStorage GetBaseStorage() => BaseStorage.AsReadOnly(); diff --git a/src/LibHac/IO/SubdirectoryFileSystem.cs b/src/LibHac/IO/SubdirectoryFileSystem.cs index 2ec9c141..1b0a2434 100644 --- a/src/LibHac/IO/SubdirectoryFileSystem.cs +++ b/src/LibHac/IO/SubdirectoryFileSystem.cs @@ -105,8 +105,17 @@ namespace LibHac.IO ParentFileSystem.Commit(); } + public FileTimeStampRaw GetFileTimeStampRaw(string path) + { + path = PathTools.Normalize(path); + + return ParentFileSystem.GetFileTimeStampRaw(ResolveFullPath(path)); + } + public void QueryEntry(Span outBuffer, Span inBuffer, string path, QueryId queryId) { + path = PathTools.Normalize(path); + ParentFileSystem.QueryEntry(outBuffer, inBuffer, ResolveFullPath(path), queryId); } }