yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie Hermaszewskaformatf65d756bf

master
2.0 KiB85 linesraw
1#include "slang-archive-file-system.h"
2
3#include "../core/slang-castable.h"
4#include "slang-blob.h"
5#include "slang-com-helper.h"
6#include "slang-com-ptr.h"
7#include "slang-io.h"
8#include "slang-riff-file-system.h"
9#include "slang-string-util.h"
10
11// Compression systems
12#include "slang-deflate-compression-system.h"
13#include "slang-lz4-compression-system.h"
14
15// Zip file system
16#include "slang-riff.h"
17#include "slang-zip-file-system.h"
18
19namespace Slang
20{
21
22SlangResult loadArchiveFileSystem(
23    const void* data,
24    size_t dataSizeInBytes,
25    ComPtr<ISlangFileSystemExt>& outFileSystem)
26{
27    ComPtr<ISlangMutableFileSystem> fileSystem;
28    if (ZipFileSystem::isArchive(data, dataSizeInBytes))
29    {
30        // It's a zip
31        SLANG_RETURN_ON_FAIL(ZipFileSystem::create(fileSystem));
32    }
33    else if (RiffFileSystem::isArchive(data, dataSizeInBytes))
34    {
35        // It's riff contained (Slang specific)
36        fileSystem = new RiffFileSystem(nullptr);
37    }
38    else
39    {
40        return SLANG_FAIL;
41    }
42
43    auto archiveFileSystem = as<IArchiveFileSystem>(fileSystem);
44    if (!archiveFileSystem)
45    {
46        return SLANG_FAIL;
47    }
48
49    SLANG_RETURN_ON_FAIL(archiveFileSystem->loadArchive(data, dataSizeInBytes));
50
51    outFileSystem = fileSystem;
52    return SLANG_OK;
53}
54
55SlangResult createArchiveFileSystem(
56    SlangArchiveType type,
57    ComPtr<ISlangMutableFileSystem>& outFileSystem)
58{
59    switch (type)
60    {
61    case SLANG_ARCHIVE_TYPE_ZIP:
62        {
63            return ZipFileSystem::create(outFileSystem);
64        }
65    case SLANG_ARCHIVE_TYPE_RIFF:
66        {
67            outFileSystem = new RiffFileSystem(nullptr);
68            return SLANG_OK;
69        }
70    case SLANG_ARCHIVE_TYPE_RIFF_DEFLATE:
71        {
72            outFileSystem = new RiffFileSystem(DeflateCompressionSystem::getSingleton());
73            return SLANG_OK;
74        }
75    case SLANG_ARCHIVE_TYPE_RIFF_LZ4:
76        {
77            outFileSystem = new RiffFileSystem(LZ4CompressionSystem::getSingleton());
78            return SLANG_OK;
79        }
80    }
81
82    return SLANG_FAIL;
83}
84
85} // namespace Slang