Skip to content

Commit

Permalink
Finished implementing dsZipArchive.
Browse files Browse the repository at this point in the history
Use zlib-ng to decompress data from zip archives. Zip support may be
explicitly disabled or implicitly disabled if zlib-ng isn't found.

Removed dsFileArchive_closeFile() function as this can be accomplished with
closing the stream.
  • Loading branch information
akb825 committed Jan 27, 2025
1 parent 630de8f commit d57f204
Show file tree
Hide file tree
Showing 11 changed files with 772 additions and 58 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ set(DEEPSEA_BUILD_TESTS ON CACHE BOOL "Build unit tests.")
set(DEEPSEA_BUILD_DOCS ON CACHE BOOL "Build documentation.")

set(DEEPSEA_BUILD_EASY_PROFILER ON CACHE BOOL "Build the easy_profiler integration for profiling.")
set(DEEPSEA_BUILD_ZIP ON CACHE BOOL "Build with support for loading .zip files.")

set(DEEPSEA_BUILD_RENDER ON CACHE BOOL "Build rendering libraries.")
set(DEEPSEA_BUILD_RENDER_MOCK ON CACHE BOOL "Build mock rendering implementation, used by tests.")
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The following software is required to build DeepSea:
* [FreeType](https://www.freetype.org/) (required for text)
* [HarfBuzz](https://github.com/harfbuzz/harfbuzz) (required for text)
* [SheenBidi](https://github.com/mta452/SheenBidi) (required for text, provided as submodule)
* [zlib-ng](https://github.com/zlib-ng/zlib-ng) (optional)
* [doxygen](https://doxygen.nl/) (optional)
* [gtest](https://github.com/google/googletest) (optional)
* [Cuttlefish](https://github.com/akb825/Cuttlefish) (recommended to create textures, required for scene and vector image conversion scripts)
Expand Down Expand Up @@ -139,6 +140,7 @@ To build the examples, an Android Studio project is provided in the android subd
* `-DDEEPSEA_BUILD_TESTS=ON|OFF`: Set to `ON` to build the unit tests. `gtest` must also be found in order to build the unit tests. Defaults to `ON`.
* `-DDEEPSEA_BUILD_DOCS=ON|OFF`: Set to `ON` to build the documentation. `doxygen` must also be found in order to build the documentation. Defaults to `ON`.
* `-DDEEPSEA_BUILD_EASY_PROFILER=ON|OFF`: Set to `ON` to build the easy_profiler implementation for for profiling. Defaults to `ON`.
* `-DDEEPSEA_BUILD_ZIP=ON|OFF`: Set to `ON` to build with support for loading .zip files. Defaults to `ON`, but will be implicitly disabled if zlib-ng cannot be found.
* `-DDEEPSEA_BUILD_RENDER=ON|OFF`: Set to `ON` to build the libraries related to rendering. Defaults to `ON`.
* `-DDEEPSEA_BUILD_RENDER_MOCK=ON|OFF`: Set to `ON` to build the mock render implementation, used for the renderer unit tests. Defaults to `ON`.
* `-DDEEPSEA_BUILD_RENDER_OPENGL=ON|OFF`: Set to `ON` to build the OpenGL render implementation. Defaults to `ON`.
Expand Down
17 changes: 16 additions & 1 deletion cmake/config.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2017-2024 Aaron Barany
# Copyright 2017-2025 Aaron Barany
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -164,11 +164,17 @@ endmacro()

macro(ds_finish_modules)
if (DEEPSEA_SINGLE_SHARED)
get_property(findPackages GLOBAL PROPERTY DEEPSEA_FIND_PACKAGES)
get_property(sources GLOBAL PROPERTY DEEPSEA_SOURCES)
get_property(externalSources GLOBAL PROPERTY DEEPSEA_EXTERNAL_SOURCES)
get_property(modules GLOBAL PROPERTY DEEPSEA_MODULES)
get_property(externalLibraries GLOBAL PROPERTY DEEPSEA_EXTERNAL_LIBRARIES)

foreach (findPackage ${findPackages})
get_property(findPackageArgs GLOBAL PROPERTY ${findPackage})
find_package(${findPackageArgs})
endforeach()

if (externalSources)
if (MSVC)
set_source_files_properties(${externalSources} PROPERTIES COMPILE_FLAGS /w)
Expand All @@ -193,6 +199,15 @@ macro(ds_finish_modules)
endif()
endmacro()

macro(ds_find_package target)
find_package(${target} ${ARGN})

if (DEEPSEA_SINGLE_SHARED)
set_property(GLOBAL PROPERTY DEEPSEA_FIND_${target} ${target} ${ARGN})
set_property(GLOBAL PROPERTY DEEPSEA_FIND_PACKAGES DEEPSEA_FIND_${target})
endif()
endmacro()

macro(ds_add_library target)
set(options)
set(oneValueArgs MODULE)
Expand Down
13 changes: 13 additions & 0 deletions modules/Core/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ ds_target_compile_definitions(deepsea_core PUBLIC DS_PROFILING_ENABLED=${profili
DS_PATCH_VERSION=${DEEPSEA_PATCH_VERSION})
ds_target_link_libraries(deepsea_core PUBLIC ${CMAKE_THREAD_LIBS_INIT} PRIVATE ${CMAKE_DL_LIBS})

if (DEEPSEA_BUILD_ZIP)
ds_find_package(zlib-ng QUIET)
if (TARGET zlib-ng::zlib)
ds_target_link_libraries(deepsea_core PRIVATE zlib-ng::zlib)
ds_target_compile_definitions(deepsea_core PUBLIC DS_ZIP_ARCHIVE_ENABLED=1)
else()
message("zlib-ng not found, disabling .zip file support.")
ds_target_compile_definitions(deepsea_core PUBLIC DS_ZIP_ARCHIVE_ENABLED=0)
endif()
else()
ds_target_compile_definitions(deepsea_core PUBLIC DS_ZIP_ARCHIVE_ENABLED=0)
endif()

if (ANDROID)
ds_target_link_libraries(deepsea_core PRIVATE android log)
endif()
Expand Down
13 changes: 4 additions & 9 deletions modules/Core/Core/include/DeepSea/Core/Streams/FileArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,17 @@ DS_CORE_EXPORT bool dsFileArchive_closeDirectory(

/**
* @brief Opens a file within an archive.
*
* The stream will typically be dynamically allocated, and will be freed once dsStream_close() is
* called.
*
* @remark errno will be set on failure.
* @param archive The archive to open the file with.
* @param path The path to the file to open.
* @return The opened stream or NULL if the file couldn't be opened.
*/
DS_CORE_EXPORT dsStream* dsFileArchive_openFile(const dsFileArchive* archive, const char* path);

/**
* @brief Closes a file within an archive.
* @remark errno will be set on failure.
* @param archive The archive the file was opened with.
* @param stream The stream for the file that was oepend.
* @return False if the file couldn't be closed.
*/
DS_CORE_EXPORT bool dsFileArchive_closeFile(const dsFileArchive* archive, dsStream* stream);

#ifdef __cplusplus
}
#endif
17 changes: 4 additions & 13 deletions modules/Core/Core/include/DeepSea/Core/Streams/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,6 @@ typedef bool (*dsCloseFileArchiveDirectoryFunction)(
*/
typedef dsStream* (*dsOpenFileArchiveFileFunction)(const dsFileArchive* archive, const char* path);

/**
* @brief Function to close a file on an archive.
* @param archive The archive to close the file from.
* @param stream The stream previously opened.
* @return False if the file couldn't be closed.
*/
typedef bool (*dsCloseFileArchiveFileFunction)(const dsFileArchive* archive, dsStream* stream);

/**
* @brief Struct describing an archive of files.
*
Expand Down Expand Up @@ -454,13 +446,10 @@ struct dsFileArchive
* @brief Function to open a file within the archive.
*/
dsOpenFileArchiveFileFunction openFileFunc;

/**
* @brief Function to close a file within the archive.
*/
dsCloseFileArchiveFileFunction closeFileFunc;
};

#if DS_ZIP_ARCHIVE_ENABLED

/**
* @brief Struct describing a zip archive.
*
Expand All @@ -470,6 +459,8 @@ struct dsFileArchive
*/
typedef struct dsZipArchive dsZipArchive;

#endif

#ifdef __cplusplus
}
#endif
21 changes: 12 additions & 9 deletions modules/Core/Core/include/DeepSea/Core/Streams/ZipArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <DeepSea/Core/Export.h>
#include <DeepSea/Core/Streams/Types.h>

#if DS_ZIP_ARCHIVE_ENABLED

#ifdef __cplusplus
extern "C"
{
Expand All @@ -35,6 +37,11 @@ extern "C"
* @see dsZipArchive
*/

/**
* @brief Define for the minimum buffer size for .zip decompression.
*/
#define DS_MIN_ZIP_DECOMPRESS_BUFFER_SIZE 512

/**
* @brief Opens a zip archive from a file path.
* @remark errno will be set on failure.
Expand Down Expand Up @@ -107,22 +114,16 @@ DS_CORE_EXPORT bool dsZipArchive_closeDirectory(

/**
* @brief Opens a file within an archive.
*
* The stream will be dynamically allocated, and will be freed once dsStream_close() is called.
*
* @remark errno will be set on failure.
* @param archive The archive to open the file with.
* @param path The path to the file to open.
* @return The opened stream or NULL if the file couldn't be opened.
*/
DS_CORE_EXPORT dsStream* dsZipArchive_openFile(const dsZipArchive* archive, const char* path);

/**
* @brief Closes a file within an archive.
* @remark errno will be set on failure.
* @param archive The archive the file was opened with.
* @param stream The stream for the file that was oepend.
* @return False if the file couldn't be closed.
*/
DS_CORE_EXPORT bool dsZipArchive_closeFile(const dsZipArchive* archive, dsStream* stream);

/**
* @brief Closes a zip archive.
*
Expand All @@ -135,3 +136,5 @@ DS_CORE_EXPORT void dsZipArchive_close(dsZipArchive* archive);
#ifdef __cplusplus
}
#endif

#endif
13 changes: 1 addition & 12 deletions modules/Core/Core/src/Streams/FileArchive.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,11 @@ bool dsFileArchive_closeDirectory(const dsFileArchive* archive, dsDirectoryItera

dsStream* dsFileArchive_openFile(const dsFileArchive* archive, const char* path)
{
if (!archive || !archive->openFileFunc || !archive->closeFileFunc || !path || *path == 0)
if (!archive || !archive->openFileFunc || !path || *path == 0)
{
errno = EINVAL;
return NULL;
}

return archive->openFileFunc(archive, path);
}

bool dsFileArchive_closeFile(const dsFileArchive* archive, dsStream* stream)
{
if (!archive || !archive->closeFileFunc || !stream)
{
errno = EINVAL;
return false;
}

return archive->closeFileFunc(archive, stream);
}
Loading

0 comments on commit d57f204

Please sign in to comment.