Skip to content

Commit f668179

Browse files
authored
Merge pull request #6 from Creative-Rift/develop
Release 1.1 Add compression process Add process to create shared/static lib for unpacker
2 parents e0958d2 + 522e4e2 commit f668179

10 files changed

Lines changed: 3205 additions & 24 deletions

File tree

.github/resources/images/logo.png

122 KB
Loading

.github/workflows/Test_windows.yml

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ on:
1212

1313
env:
1414
BUILD_TYPE: Release
15+
VERSION_NAME: 1.1
1516

1617
jobs:
17-
Test_windows:
18+
Build_exec:
1819
runs-on: windows-latest
1920
steps:
2021
- name: Checkout repository
21-
uses: actions/checkout@v2
22+
uses: actions/checkout@v4
2223

2324
- name: Config executables
2425
run: |
@@ -33,5 +34,52 @@ jobs:
3334
- name: Archive Executable
3435
uses: actions/upload-artifact@v3
3536
with:
36-
name: SWPacker
37-
path: ${{github.workspace}}\out\0.1\Release\
37+
name: SWPacker-Exec
38+
path: ${{github.workspace}}\out\${{env.VERSION_NAME}}\Release\
39+
if-no-files-found: error
40+
41+
Build_Unpack_Shared:
42+
runs-on: windows-latest
43+
steps:
44+
- name: Checkout repository
45+
uses: actions/checkout@v4
46+
47+
- name: Config executables
48+
run: |
49+
mkdir build && cd build
50+
cmake -B ${{github.workspace}}\build -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_UNPACK_LIB_SHARED=ON ..
51+
52+
- name: Build executables
53+
run: |
54+
cd ${{github.workspace}}\build
55+
cmake --build ${{github.workspace}}\build --target SWEngine-unpacker_${{env.VERSION_NAME}} --config ${{env.BUILD_TYPE}}
56+
57+
- name: Archive Library
58+
uses: actions/upload-artifact@v3
59+
with:
60+
name: SWPacker-shared-lib
61+
path: ${{github.workspace}}\out\${{env.VERSION_NAME}}\Release\
62+
if-no-files-found: error
63+
64+
Build_Unpack_Static:
65+
runs-on: windows-latest
66+
steps:
67+
- name: Checkout repository
68+
uses: actions/checkout@v4
69+
70+
- name: Config executables
71+
run: |
72+
mkdir build && cd build
73+
cmake -B ${{github.workspace}}\build -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_UNPACK_LIB_STATIC=ON ..
74+
75+
- name: Build executables
76+
run: |
77+
cd ${{github.workspace}}\build
78+
cmake --build ${{github.workspace}}\build --target SWEngine-unpacker_${{env.VERSION_NAME}} --config ${{env.BUILD_TYPE}}
79+
80+
- name: Archive library
81+
uses: actions/upload-artifact@v3
82+
with:
83+
name: SWPacker-static-lib
84+
path: ${{github.workspace}}\out\${{env.VERSION_NAME}}\Release\
85+
if-no-files-found: error

CMakeLists.txt

Lines changed: 28 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,31 @@ 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+
option(BUILD_UNPACK_LIB_SHARED "Define if Unpacker is build as a library as shared" )
36+
option(BUILD_UNPACK_LIB_STATIC "Define if Unpacker is build as a library as static" )
37+
38+
## IMPORTED STATIC LIBRARY NAME
39+
set( STATIC_LIB_NAME
40+
)
41+
42+
## IMPORTED STATIC LIBRARY .lib file
43+
set( STATIC_LIB
44+
)
45+
46+
list(LENGTH STATIC_LIB_NAME list_len)
47+
math(EXPR LIST_LEN "${list_len} - 1")
48+
49+
if (${LIST_LEN} GREATER_EQUAL 0)
50+
foreach(ctr RANGE ${LIST_LEN})
51+
list(GET STATIC_LIB_NAME ${ctr} lib)
52+
list(GET STATIC_LIB ${ctr} filelib)
53+
add_library(${lib} STATIC IMPORTED)
54+
set_target_properties(${lib} PROPERTIES
55+
IMPORTED_LOCATION ${filelib}
56+
)
57+
endforeach()
58+
endif ()
3459

3560
include(cmake/Packer.cmake)
36-
include(cmake/UnPacker.cmake)
61+
include(cmake/UnPacker.cmake)

README.md

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
<p align="center">
2+
<img src=".github/resources/images/logo.png"
3+
style="height: 200px">
4+
</p>
5+
16
# SWPacker
27
## Description
38
SWPacker is program that allow to pack all files from a directory.
@@ -7,23 +12,43 @@ It builds a single file `.swfp` with all resources inside.
712
The compilation is simple, you can choose between two target: Packer and Unpacker.
813
```shell
914
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]
15+
cmake -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=[Debug/Release] ..
16+
cmake --build . --target SWEngine-[packer/unpacker]_1.1 --config [Debug/Release]
1217
```
18+
#### Option
19+
You can define an option by using : `-D[option]=[value]`
20+
- CMAKE_BUILD_TYPE: Debug/Release
21+
- SWFP_COMP: ON/OFF
22+
- BUILD_UNPACK_LIB_SHARED: ON/OFF
23+
- BUILD_UNPACK_LIB_STATIC: ON/OFF
1324

1425
## Usage
1526
### Packer
1627
Simply run the executable and give the directory you want to pack.
1728
```shell
18-
./SWEngine-packer_0.1 [PATH_TO_DIRECTORY]
29+
./SWEngine-packer [PATH_TO_DIRECTORY]
1930
```
2031

2132
### UnPacker
2233
Simply run the executable and give the directory where the file `.swfp` file is.
2334
```shell
24-
./SWEngine-unpacker_0.1 [PATH_TO_SWFP_FILE]
35+
./SWEngine-unpacker [PATH_TO_SWFP_FILE]
2536
```
2637

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

cmake/Packer.cmake

Lines changed: 17 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,16 @@ if(MSVC)
5359
endif()
5460
## <=====================================>
5561

62+
## STATIC LIBRARY LINKING
63+
## <=====================================>
64+
if (${STATIC_LIB_NAME})
65+
target_link_libraries(${EXEC}
66+
PUBLIC
67+
${STATIC_LIB_NAME}
68+
)
69+
endif ()
70+
## <=====================================>
71+
5672
if (${CMAKE_BUILD_TYPE} MATCHES Debug)
5773
set_target_properties(${EXEC} PROPERTIES
5874
DEBUG_POSTFIX "d")

cmake/UnPacker.cmake

Lines changed: 31 additions & 4 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,29 @@ endforeach()
3134
file(GLOB SRC ${TMP})
3235
## <=====================================>
3336

34-
3537
## OUTPUT
3638
## <=====================================>
37-
## EXECUTABLE
38-
add_executable(${EXEC} ${SRC})
39+
40+
if (NOT ${BUILD_UNPACK_LIB_SHARED} AND NOT ${BUILD_UNPACK_LIB_STATIC})
41+
## EXECUTABLE
42+
add_executable(${EXEC} ${SRC})
43+
message(${PREFIX_MESSAGE} "Unpacker build as executable")
44+
elseif (${BUILD_UNPACK_LIB_SHARED})
45+
## SHARED LIB
46+
add_library(${EXEC} SHARED ${SRC})
47+
message(${PREFIX_MESSAGE} "Unpacker build as Shared library")
48+
elseif (${BUILD_UNPACK_LIB_STATIC})
49+
## STATIC LIB
50+
add_library(${EXEC} STATIC ${SRC})
51+
message(${PREFIX_MESSAGE} "Unpacker build as Static library")
52+
endif ()
53+
3954
## <=====================================>
4055

4156
target_compile_definitions(${EXEC} PUBLIC "SWFP_UNPACKER")
42-
57+
if (${SWFP_COMP})
58+
target_compile_definitions(${EXEC} PUBLIC "SWFP_COMP")
59+
endif ()
4360
## ADD INCLUDES
4461
## <=====================================>
4562
target_include_directories(${EXEC} PUBLIC ${INC_FOLDERS})
@@ -52,6 +69,16 @@ if(MSVC)
5269
endif()
5370
## <=====================================>
5471

72+
## STATIC LIBRARY LINKING
73+
## <=====================================>
74+
if (NOT ${STATIC_LIB_NAME} STREQUAL "")
75+
target_link_libraries(${EXEC}
76+
PUBLIC
77+
${STATIC_LIB_NAME}
78+
)
79+
endif ()
80+
## <=====================================>
81+
5582
if (${CMAKE_BUILD_TYPE} MATCHES Debug)
5683
set_target_properties(${EXEC} PROPERTIES
5784
DEBUG_POSTFIX "d")

0 commit comments

Comments
 (0)