Skip to content

Commit

Permalink
cage archive
Browse files Browse the repository at this point in the history
  • Loading branch information
malytomas committed Feb 8, 2025
1 parent 0abad94 commit ee69c76
Show file tree
Hide file tree
Showing 21 changed files with 1,475 additions and 144 deletions.
2 changes: 1 addition & 1 deletion cmake/cage_assets.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

set(cage_assets_current_list_dir "${CMAKE_CURRENT_LIST_DIR}")
set(cage_assets_destination_path "${CMAKE_BINARY_DIR}/result/assets.zip" CACHE FILEPATH "Where to save the final archive with all assets.")
set(cage_assets_destination_path "${CMAKE_BINARY_DIR}/result/assets.carch" CACHE FILEPATH "Where to save the final archive with all assets.")
set(cage_assets_intermediate_path "${CMAKE_BINARY_DIR}/result/data" CACHE PATH "Directory for assets processing and database.")

function(cage_assets_generate_config)
Expand Down
2 changes: 1 addition & 1 deletion sources/asset-database/databank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ void checkOutputDir()
{
const PathTypeFlags t = pathType(configPathOutput);
if (configOutputArchive && any(t & PathTypeFlags::NotFound))
return pathCreateArchive(configPathOutput);
return pathCreateArchiveCarch(configPathOutput);
if (any(t & PathTypeFlags::Archive))
return;
// the output is not an archive, output to it directly
Expand Down
2 changes: 1 addition & 1 deletion sources/include/cage-core/assetsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace cage

struct CAGE_CORE_API AssetManagerCreateConfig
{
String assetsFolderName = "assets.zip";
String assetsFolderName = "assets.carch";
uint32 diskLoadingThreads = 2;
uint32 customProcessingThreads = 5;
uint32 schemesMaxCount = 100; // 0..49 for engine and 50..99 for the game
Expand Down
11 changes: 6 additions & 5 deletions sources/include/cage-core/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ namespace cage
virtual ~File() = default;
};

CAGE_CORE_API Holder<File> newFile(const String &path, const FileMode &mode);
CAGE_CORE_API Holder<File> newFile(const String &path, FileMode mode);
CAGE_CORE_API Holder<File> readFile(const String &path);
CAGE_CORE_API Holder<File> writeFile(const String &path);
CAGE_CORE_API Holder<File> newFileBuffer(Holder<PointerRange<const char>> buffer);
CAGE_CORE_API Holder<File> newFileBuffer(Holder<PointerRange<char>> buffer, const FileMode &mode = FileMode(true, false));
CAGE_CORE_API Holder<File> newFileBuffer(Holder<PointerRange<char>> buffer, FileMode mode = FileMode(true, false));
CAGE_CORE_API Holder<File> newFileBuffer(Holder<const MemoryBuffer> buffer);
CAGE_CORE_API Holder<File> newFileBuffer(Holder<MemoryBuffer> buffer, const FileMode &mode = FileMode(true, true));
CAGE_CORE_API Holder<File> newFileBuffer(MemoryBuffer &&buffer, const FileMode &mode = FileMode(true, true));
CAGE_CORE_API Holder<File> newFileBuffer(Holder<MemoryBuffer> buffer, FileMode mode = FileMode(true, true));
CAGE_CORE_API Holder<File> newFileBuffer(MemoryBuffer &&buffer, FileMode mode = FileMode(true, true));
CAGE_CORE_API Holder<File> newFileBuffer();

// receive operating system issued notifications about filesystem changes
Expand Down Expand Up @@ -136,7 +136,8 @@ namespace cage
CAGE_CORE_API void pathCreateDirectories(const String &path);

// create an empty archive at the specified path, it can be populated afterwards
CAGE_CORE_API void pathCreateArchive(const String &path, const String &options = "");
CAGE_CORE_API void pathCreateArchiveZip(const String &path);
CAGE_CORE_API void pathCreateArchiveCarch(const String &path);

// moves (renames) or copies a file or directory
CAGE_CORE_API void pathMove(const String &from, const String &to);
Expand Down
10 changes: 6 additions & 4 deletions sources/libcore/filesystem/abstractFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@

#include "files.h"

#include <cage-core/concurrent.h>
#include <cage-core/debug.h>
#include <cage-core/memoryBuffer.h>
#include <cage-core/pointerRangeHolder.h>
#include <cage-core/stdHash.h>
#include <cage-core/string.h>

namespace cage
{
std::shared_ptr<ArchiveAbstract> archiveOpenZipTry(Holder<File> &&f);
std::shared_ptr<ArchiveAbstract> archiveOpenZipTry(Holder<File> f);
std::shared_ptr<ArchiveAbstract> archiveOpenCarchTry(Holder<File> f);
std::shared_ptr<ArchiveAbstract> archiveOpenReal(const String &path);

namespace
Expand Down Expand Up @@ -73,7 +72,10 @@ namespace cage
{
CAGE_ASSERT(parent);
const String inPath = pathToRel(fullPath, parent->myPath);
return archiveOpenZipTry(parent->openFile(inPath, FileMode(true, false)));
Holder<File> f = parent->openFile(inPath, FileMode(true, false));
if (auto cap = archiveOpenCarchTry(f.share()))
return cap;
return archiveOpenZipTry(f.share());
}

void walkRight(String &p, String &i)
Expand Down
22 changes: 16 additions & 6 deletions sources/libcore/filesystem/api.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#include "files.h"

#include <cage-core/concurrent.h>
#include <cage-core/debug.h>
#include <cage-core/lineReader.h>
#include <cage-core/math.h> // min
#include <cage-core/memoryBuffer.h>
#include <cage-core/pointerRangeHolder.h>
#include <cage-core/string.h>

namespace cage
{
void archiveCreateZip(const String &path, const String &options);
void archiveCreateZip(const String &path);
void archiveCreateCarch(const String &path);

bool FileMode::valid() const
{
Expand Down Expand Up @@ -134,7 +133,7 @@ namespace cage
CAGE_THROW_CRITICAL(Exception, "calling mode on an abstract file");
}

Holder<File> newFile(const String &path, const FileMode &mode)
Holder<File> newFile(const String &path, FileMode mode)
{
ScopeLock lock(fsMutex());
auto [a, p] = archiveFindTowardsRoot(path, ArchiveFindModeEnum::FileExclusive);
Expand Down Expand Up @@ -267,15 +266,26 @@ namespace cage
a->createDirectories(p);
}

void pathCreateArchive(const String &path, const String &options)
void pathCreateArchiveZip(const String &path)
{
ScopeLock lock(fsMutex());
if (any(pathType(path) & (PathTypeFlags::File | PathTypeFlags::Directory | PathTypeFlags::Archive)))
{
CAGE_LOG_THROW(Stringizer() + "path: " + path);
CAGE_THROW_ERROR(Exception, "cannot create archive, the path already exists");
}
archiveCreateZip(path, options);
archiveCreateZip(path);
}

void pathCreateArchiveCarch(const String &path)
{
ScopeLock lock(fsMutex());
if (any(pathType(path) & (PathTypeFlags::File | PathTypeFlags::Directory | PathTypeFlags::Archive)))
{
CAGE_LOG_THROW(Stringizer() + "path: " + path);
CAGE_THROW_ERROR(Exception, "cannot create archive, the path already exists");
}
archiveCreateCarch(path);
}

namespace
Expand Down
Loading

0 comments on commit ee69c76

Please sign in to comment.