diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-10-03 21:09:16 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-03 18:09:16 -0700 |
| commit | 0b51ea6bb54b1d8a12695ccc2c259fd591069791 (patch) | |
| tree | 1ff0587eb1454891bf8421a86b95ed5e95419e75 /source/core/slang-zip-file-system.cpp | |
| parent | cc3548c92b1cf028b94d7a264a55df83e6d4d212 (diff) | |
IMutableFileSystem::saveFileBlob (#2427)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Remove ref count for Entry in RiffFileSystem.
Free up backing Entry types (to work around Dictionary not doing this).
* Some small improvements to RiffFileSystem.
* Add testing for file systems.
* Split out MemoryFileSystem.
* Add some documentation around different FileSystems.
* Small tiry up - removing unused headers, fixing some comments.
Use StringBlob::moveCreate where appropriate.
* Small improvement to MemoryFileSystem.
Improve documentation comments a little.
* Added PathKind
* * Make MemoryFileSystem not have implicit directories
* Make RelativeFileSystem only allow access to files in file system (kind of like chroot)
* Added Path::simplifyAbsolute
* Special handling for root of MemoryFileSystem
* Improvements around paths for different impls
* More improvements around RelativeFileSystem.
Special case root handling.
* Test archive serialization.
Move testinf from compression.
Remove the implicit directory test -> doesn't work on all file systems.
* Small optimization that removes need for check for a parent unless an item is being *created*.
* Add implicit path testing.
* Add support for saveFileBlob
Add testing for saveFileBlob
* Removed TemporaryFileSet
Added PlatformUtil::outputDebugMessage
* Some small improvements around RelativeFileSystem.
* Split out ImplicitDirectoryCollector so can use without requiring compression systems.
* Split out StringSliceIndexMap into own files.
Diffstat (limited to 'source/core/slang-zip-file-system.cpp')
| -rw-r--r-- | source/core/slang-zip-file-system.cpp | 59 |
1 files changed, 40 insertions, 19 deletions
diff --git a/source/core/slang-zip-file-system.cpp b/source/core/slang-zip-file-system.cpp index d9c0a900e..28782dba7 100644 --- a/source/core/slang-zip-file-system.cpp +++ b/source/core/slang-zip-file-system.cpp @@ -10,6 +10,8 @@ #include "slang-uint-set.h" #include "slang-riff.h" +#include "slang-implicit-directory-collector.h" + #include "../../external/miniz/miniz.h" #include "../../external/miniz/miniz_common.h" #include "../../external/miniz/miniz_tdef.h" @@ -35,14 +37,14 @@ public: virtual SLANG_NO_THROW SlangResult SLANG_MCALL getFileUniqueIdentity(const char* path, ISlangBlob** uniqueIdentityOut) SLANG_OVERRIDE; virtual SLANG_NO_THROW SlangResult SLANG_MCALL calcCombinedPath(SlangPathType fromPathType, const char* fromPath, const char* path, ISlangBlob** pathOut) SLANG_OVERRIDE; virtual SLANG_NO_THROW SlangResult SLANG_MCALL getPathType(const char* path, SlangPathType* pathTypeOut) SLANG_OVERRIDE; - virtual SLANG_NO_THROW SlangResult SLANG_MCALL getSimplifiedPath(const char* path, ISlangBlob** outSimplifiedPath) SLANG_OVERRIDE; - virtual SLANG_NO_THROW SlangResult SLANG_MCALL getCanonicalPath(const char* path, ISlangBlob** outCanonicalPath) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getPath(PathKind pathKind, const char* path, ISlangBlob** outPath) SLANG_OVERRIDE; virtual SLANG_NO_THROW void SLANG_MCALL clearCache() SLANG_OVERRIDE {} virtual SLANG_NO_THROW SlangResult SLANG_MCALL enumeratePathContents(const char* path, FileSystemContentsCallBack callback, void* userData) SLANG_OVERRIDE; virtual SLANG_NO_THROW OSPathKind SLANG_MCALL getOSPathKind() SLANG_OVERRIDE { return OSPathKind::None; } // ISlangModifyableFileSystem virtual SLANG_NO_THROW SlangResult SLANG_MCALL saveFile(const char* path, const void* data, size_t size) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL saveFileBlob(const char* path, ISlangBlob* dataBlob) SLANG_OVERRIDE; virtual SLANG_NO_THROW SlangResult SLANG_MCALL remove(const char* path) SLANG_OVERRIDE; virtual SLANG_NO_THROW SlangResult SLANG_MCALL createDirectory(const char* path) SLANG_OVERRIDE; @@ -519,25 +521,40 @@ SlangResult ZipFileSystemImpl::getPathType(const char* path, SlangPathType* outP return SLANG_E_NOT_FOUND; } -SlangResult ZipFileSystemImpl::getCanonicalPath(const char* path, ISlangBlob** outCanonicalPath) +SlangResult ZipFileSystemImpl::getPath(PathKind pathKind, const char* path, ISlangBlob** outPath) { - mz_uint index; - SLANG_RETURN_ON_FAIL(_findEntryIndex(path, index)); - - mz_zip_archive_file_stat fileStat; - if (!mz_zip_reader_file_stat(&m_archive, index, &fileStat)) + switch (pathKind) { - return SLANG_FAIL; + case PathKind::Display: + case PathKind::Canonical: + { + mz_uint index; + SLANG_RETURN_ON_FAIL(_findEntryIndex(path, index)); + + mz_zip_archive_file_stat fileStat; + if (!mz_zip_reader_file_stat(&m_archive, index, &fileStat)) + { + return SLANG_FAIL; + } + + // Use the path in the archive itself + *outPath = StringUtil::createStringBlob(fileStat.m_filename).detach(); + return SLANG_OK; + } + case PathKind::Simplified: + { + *outPath = StringUtil::createStringBlob(Path::simplify(path)).detach(); + return SLANG_OK; + } + default: break; } - // Use the path in the archive itself - *outCanonicalPath = StringUtil::createStringBlob(fileStat.m_filename).detach(); - return SLANG_OK; + return SLANG_E_NOT_AVAILABLE; } SlangResult ZipFileSystemImpl::getFileUniqueIdentity(const char* path, ISlangBlob** outUniqueIdentity) { - return getCanonicalPath(path, outUniqueIdentity); + return getPath(PathKind::Canonical, path, outUniqueIdentity); } SlangResult ZipFileSystemImpl::calcCombinedPath(SlangPathType fromPathType, const char* fromPath, const char* path, ISlangBlob** pathOut) @@ -561,12 +578,6 @@ SlangResult ZipFileSystemImpl::calcCombinedPath(SlangPathType fromPathType, cons return SLANG_OK; } -SlangResult ZipFileSystemImpl::getSimplifiedPath(const char* path, ISlangBlob** outSimplifiedPath) -{ - *outSimplifiedPath = StringUtil::createStringBlob(Path::simplify(path)).detach(); - return SLANG_OK; -} - SlangResult ZipFileSystemImpl::_getPathContents(ImplicitDirectoryCollector::State terminationState, ImplicitDirectoryCollector* outCollector) { if (!_hasArchive()) @@ -619,6 +630,16 @@ SlangResult ZipFileSystemImpl::enumeratePathContents(const char* path, FileSyste return collector.enumerate(callback, userData); } +SlangResult ZipFileSystemImpl::saveFileBlob(const char* path, ISlangBlob* dataBlob) +{ + if (!dataBlob) + { + return SLANG_E_INVALID_ARG; + } + + return saveFile(path, dataBlob->getBufferPointer(), dataBlob->getBufferSize()); +} + SlangResult ZipFileSystemImpl::saveFile(const char* path, const void* data, size_t size) { String fixedPath; |
