Skip to content

Commit 4c7e2ec

Browse files
authored
Feature/compression (#4)
* Add zstd as example to compress data Update cmake * Fix cmake build Update compression process make it optional Update ReadMe * Remove zstd ref in CMakeLists.txt * Update action change checkout v4 to v4 * Update action version name Update ReadMe version name
1 parent 8febf55 commit 4c7e2ec

9 files changed

Lines changed: 3142 additions & 20 deletions

File tree

.github/workflows/Test_windows.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
runs-on: windows-latest
1919
steps:
2020
- name: Checkout repository
21-
uses: actions/checkout@v2
21+
uses: actions/checkout@v4
2222

2323
- name: Config executables
2424
run: |
@@ -34,4 +34,4 @@ jobs:
3434
uses: actions/upload-artifact@v3
3535
with:
3636
name: SWPacker
37-
path: ${{github.workspace}}\out\0.1\Release\
37+
path: ${{github.workspace}}\out\1.1\Release\

CMakeLists.txt

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/out/ )
1010

1111
project( "SW Packer"
1212
VERSION
13-
1.0
13+
1.1
1414
DESCRIPTION
1515
"Pack all resources into one file"
1616
LANGUAGES
@@ -22,7 +22,7 @@ set( CMAKE_CXX_STANDARD_REQUIRED True )
2222
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/out/${CMAKE_PROJECT_VERSION} )
2323
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/out/${CMAKE_PROJECT_VERSION} )
2424
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/out/${CMAKE_PROJECT_VERSION} )
25-
set(PREFIX_MESSAGE "[${PROJECT_NAME}] ")
25+
set( PREFIX_MESSAGE "[${PROJECT_NAME}] ")
2626

2727
## <=====================================>
2828

@@ -31,6 +31,30 @@ message(${PREFIX_MESSAGE} "Current cmake location: " ${CMAKE_CURRENT_SOURCE_DIR}
3131
message(${PREFIX_MESSAGE} "Project location: " ${CMAKE_SOURCE_DIR})
3232
message(${PREFIX_MESSAGE} "Project system: " ${CMAKE_SYSTEM_NAME})
3333

34+
option(SWFP_COMP "Define if the packer will enable compact process" )
35+
36+
## IMPORTED STATIC LIBRARY NAME
37+
set( STATIC_LIB_NAME
38+
)
39+
40+
## IMPORTED STATIC LIBRARY .lib file
41+
set( STATIC_LIB
42+
)
43+
44+
list(LENGTH STATIC_LIB_NAME list_len)
45+
math(EXPR LIST_LEN "${list_len} - 1")
46+
47+
if (${LIST_LEN} GREATER_EQUAL 0)
48+
49+
foreach(ctr RANGE ${LIST_LEN})
50+
list(GET STATIC_LIB_NAME ${ctr} lib)
51+
list(GET STATIC_LIB ${ctr} filelib)
52+
add_library(${lib} STATIC IMPORTED)
53+
set_target_properties(${lib} PROPERTIES
54+
IMPORTED_LOCATION ${filelib}
55+
)
56+
endforeach()
57+
endif ()
3458

3559
include(cmake/Packer.cmake)
36-
include(cmake/UnPacker.cmake)
60+
include(cmake/UnPacker.cmake)

README.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,41 @@ It builds a single file `.swfp` with all resources inside.
77
The compilation is simple, you can choose between two target: Packer and Unpacker.
88
```shell
99
mkdir "build" && cd build
10-
cmake -G "Visual Studio 17 2022" - DCMAKE_BUILD_TYPE=[Debug/Release] ..
11-
cmake --build . --target SWEngine-[packer/unpacker]_0.1 --config [Debug/Release]
10+
cmake -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=[Debug/Release] ..
11+
cmake --build . --target SWEngine-[packer/unpacker]_1.1 --config [Debug/Release]
1212
```
13+
#### Option
14+
You can define an option by using : `-D[option]=[value]`
15+
- CMAKE_BUILD_TYPE: Debug/Release
16+
- SWFP_COMP: ON/OFF
1317

1418
## Usage
1519
### Packer
1620
Simply run the executable and give the directory you want to pack.
1721
```shell
18-
./SWEngine-packer_0.1 [PATH_TO_DIRECTORY]
22+
./SWEngine-packer [PATH_TO_DIRECTORY]
1923
```
2024

2125
### UnPacker
2226
Simply run the executable and give the directory where the file `.swfp` file is.
2327
```shell
24-
./SWEngine-unpacker_0.1 [PATH_TO_SWFP_FILE]
28+
./SWEngine-unpacker [PATH_TO_SWFP_FILE]
2529
```
2630

31+
### Compression
32+
You're able to add a compression process in the packer (and decompress for unpacker).
33+
To do so, go to `Packer.cpp` and find the `SWFP_COMP` macro and edit the code above to add
34+
your own compression process. For `UnPacker.cpp` find `SWFP_COMP` and edit the code above.
35+
36+
To enable the compression process use `-DSWFP_COMP=ON` (default: OFF).
37+
38+
Note: There is a default compression algorithm: [zstd](https://github.com/facebook/zstd). \
39+
The header is already include in the project just build a __static__ libraries and add it to the cmake. \
40+
Add `zstd_static` to `STATIC_LIB_NAME` and `${CMAKE_SOURCE_DIR}/libraries/zstd_static.lib` to `STATIC_LIB` in the CMakeLists.txt.
41+
2742
## Authors
28-
The project is made by [Guillaume Soisson](https://github.com/Alvarwow69). \
29-
This project is based on raysan5 works for [rres](https://github.com/raysan5/rres)
43+
The project is made by [Guillaume Soisson](https://github.com/Alvarwow69).
44+
45+
## Credits
46+
This project is based on raysan5 works for [rres](https://github.com/raysan5/rres) \
47+
This project use [zstd](https://github.com/facebook/zstd) to provide default compression process.

cmake/Packer.cmake

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## PROJECT VAR
22
## <=====================================>
3+
unset(EXEC)
34
set( EXEC "SWEngine-packer_${CMAKE_PROJECT_VERSION}" )
45
set( EXT cpp )
56
## <=====================================>
@@ -15,6 +16,8 @@ set( SRC_FOLDERS
1516
)
1617
## INCLUDE FOLDERS
1718
set( INC_FOLDERS
19+
${CMAKE_CURRENT_SOURCE_DIR}/libraries/
20+
1821
${CMAKE_CURRENT_SOURCE_DIR}/includes/
1922
${CMAKE_CURRENT_SOURCE_DIR}/includes/file/
2023
${CMAKE_CURRENT_SOURCE_DIR}/includes/pack/
@@ -39,7 +42,10 @@ add_executable(${EXEC} ${SRC})
3942
## <=====================================>
4043

4144
target_compile_definitions(${EXEC} PUBLIC "SWFP_PACKER")
42-
45+
if (${SWFP_COMP})
46+
message(${PREFIX_MESSAGE} "Compression process enabled!")
47+
target_compile_definitions(${EXEC} PUBLIC "SWFP_COMP")
48+
endif ()
4349

4450
## ADD INCLUDES
4551
## <=====================================>
@@ -53,6 +59,26 @@ if(MSVC)
5359
endif()
5460
## <=====================================>
5561

62+
## IMPORTED STATIC LIBRARY NAME
63+
set( STATIC_LIB_NAME
64+
zstd_static
65+
)
66+
67+
## IMPORTED STATIC LIBRARY .lib file
68+
set( STATIC_LIB
69+
${CMAKE_SOURCE_DIR}/libraries/zstd_static.lib
70+
)
71+
72+
## STATIC LIBRARY LINKING
73+
## <=====================================>
74+
if (${STATIC_LIB_NAME})
75+
target_link_libraries(${EXEC}
76+
PUBLIC
77+
${STATIC_LIB_NAME}
78+
)
79+
endif ()
80+
## <=====================================>
81+
5682
if (${CMAKE_BUILD_TYPE} MATCHES Debug)
5783
set_target_properties(${EXEC} PROPERTIES
5884
DEBUG_POSTFIX "d")

cmake/UnPacker.cmake

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## PROJECT VAR
22
## <=====================================>
3+
unset(EXEC)
34
set( EXEC "SWEngine-unpacker_${CMAKE_PROJECT_VERSION}" )
45
set( EXT cpp )
56
## <=====================================>
@@ -15,6 +16,8 @@ set( SRC_FOLDERS
1516
)
1617
## INCLUDE FOLDERS
1718
set( INC_FOLDERS
19+
${CMAKE_CURRENT_SOURCE_DIR}/libraries/
20+
1821
${CMAKE_CURRENT_SOURCE_DIR}/includes/
1922
${CMAKE_CURRENT_SOURCE_DIR}/includes/file/
2023
${CMAKE_CURRENT_SOURCE_DIR}/includes/unpack/
@@ -31,15 +34,16 @@ endforeach()
3134
file(GLOB SRC ${TMP})
3235
## <=====================================>
3336

34-
3537
## OUTPUT
3638
## <=====================================>
3739
## EXECUTABLE
3840
add_executable(${EXEC} ${SRC})
3941
## <=====================================>
4042

4143
target_compile_definitions(${EXEC} PUBLIC "SWFP_UNPACKER")
42-
44+
if (${SWFP_COMP})
45+
target_compile_definitions(${EXEC} PUBLIC "SWFP_COMP")
46+
endif ()
4347
## ADD INCLUDES
4448
## <=====================================>
4549
target_include_directories(${EXEC} PUBLIC ${INC_FOLDERS})
@@ -52,6 +56,16 @@ if(MSVC)
5256
endif()
5357
## <=====================================>
5458

59+
## STATIC LIBRARY LINKING
60+
## <=====================================>
61+
if (${STATIC_LIB_NAME})
62+
target_link_libraries(${EXEC}
63+
PUBLIC
64+
${STATIC_LIB_NAME}
65+
)
66+
endif ()
67+
## <=====================================>
68+
5569
if (${CMAKE_BUILD_TYPE} MATCHES Debug)
5670
set_target_properties(${EXEC} PROPERTIES
5771
DEBUG_POSTFIX "d")

0 commit comments

Comments
 (0)