Skip to content

Commit d5a1e8d

Browse files
committed
Fix wrong packer args detection
* Also added packer flags description. * And packer --help message. * Fixed pack-info items print.
1 parent 16ff956 commit d5a1e8d

5 files changed

Lines changed: 65 additions & 20 deletions

File tree

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,14 @@ Creates compressed data pack from files.
106106

107107
* Usage: ```packer [-z, -v, -s] <pack-path> <file-path-1> <item-path-1>...```
108108
* Example: ```packer resources.pack C:/Users/user/Desktop/sky.png images/sky.png```
109-
* Arguments: [-z zipThreshold, -v dataVersion, -s preferSpeed]
109+
110+
#### Arguments:
111+
112+
* ```-z <zipThreshold>```: Specifies file compression threshold when we just pack file without compressing it.
113+
It's used for already compressed resources like images. Default value is 10. (0% - 100% range)
114+
* ```-v <dataVersion>```: Specifies ```resources.pack``` file version. It's used to check if we are
115+
loading correct resources pack for a current game or application version. Default value is 0.
116+
* ```-s```: Use faster decompression algorithm sacrificing resources pack file size.
110117

111118
### unpacker
112119

source/reader.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ PackResult createFilePackReader(const char* filePath, uint32_t dataVersion,
123123
PackReader packReaderInstance = calloc(1, sizeof(PackReader_T));
124124
if (!packReaderInstance)
125125
return FAILED_TO_ALLOCATE_PACK_RESULT;
126-
127126
packReaderInstance->threadCount = threadCount;
128127

129128
char* path;

utilities/pack_info.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@
1717
#include <stdio.h>
1818
#include <stdlib.h>
1919

20+
static void printPackInfoHelp()
21+
{
22+
printf("Usage: pack-info <pack-path>\n");
23+
}
24+
2025
int main(int argc, char *argv[])
2126
{
2227
if (argc != 2)
2328
{
24-
printf("Usage: pack-info <pack-path>\n");
29+
printPackInfoHelp();
2530
return EXIT_FAILURE;
2631
}
2732

@@ -34,8 +39,8 @@ int main(int argc, char *argv[])
3439
return EXIT_FAILURE;
3540
}
3641

37-
printf("Pack [v%d.%d.%d]\n\n"
38-
"Pack information:\n"
42+
printf("pack-info [v%d.%d.%d]\n\n"
43+
"Pack header:\n"
3944
" File version: %d.%d.%d\n"
4045
" Data version: %u\n"
4146
" Big endian: %s\n"
@@ -47,30 +52,35 @@ int main(int argc, char *argv[])
4752
(long long unsigned int)header.itemCount);
4853

4954
PackReader packReader;
50-
result = createFilePackReader(argv[1], 0, false, header.dataVersion, &packReader);
55+
result = createFilePackReader(argv[1], header.dataVersion, false, 1, &packReader);
5156
if (result != SUCCESS_PACK_RESULT)
5257
{
5358
printf("\nError: %s.\n", packResultToString(result));
5459
return EXIT_FAILURE;
5560
}
5661

5762
uint64_t itemCount = getPackItemCount(packReader);
63+
uint64_t totalDataSize = 0, totalZipSize = 0;
64+
5865
for (uint64_t i = 0; i < itemCount; ++i)
5966
{
67+
uint32_t dataSize = getPackItemDataSize(packReader, i);
68+
uint32_t zipSize = getPackItemZipSize(packReader, i);
69+
totalDataSize += dataSize; totalZipSize += zipSize;
70+
6071
printf("Item %llu:\n"
6172
" Path: %s\n"
62-
" Data size: %u\n"
63-
" Zip size: %u\n"
64-
" File offset: %llu\n"
65-
" Reference: %s\n",
66-
(long long unsigned int)i,
67-
getPackItemPath(packReader, i),
68-
getPackItemDataSize(packReader, i),
69-
getPackItemZipSize(packReader, i),
70-
(long long unsigned int)getPackItemFileOffset(packReader, i),
73+
" Data size: %u bytes\n"
74+
" Zip size: %u bytes\n"
75+
" File offset: %llu bytes\n"
76+
" Is reference: %s\n",
77+
(long long unsigned int)i, getPackItemPath(packReader, i), dataSize,
78+
zipSize, (long long unsigned int)getPackItemFileOffset(packReader, i),
7179
isPackItemReference(packReader, i) ? "true" : "false");
7280
fflush(stdout);
7381
}
7482

83+
printf("\nTotal zip/data size: %llu/%llu bytes.\n",
84+
(long long unsigned int)totalZipSize, (long long unsigned int)totalDataSize);
7585
return EXIT_SUCCESS;
7686
}

utilities/packer.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,29 @@
1818
#include <stdlib.h>
1919
#include <string.h>
2020

21+
static void printPackerHelp()
22+
{
23+
/////////////////////////////////////////////////////////////////////////////////////
24+
printf("Usage: packer [-z, -v, -s] <pack-path> <file-path-1> <item-path-1>...\n"
25+
"\n"
26+
"Note that file path and item path may differ!\n"
27+
"\n"
28+
"Options:\n"
29+
" -z <zipThreshold> Specifies file compression threshold when we just pack file \n"
30+
" without compressing it. It's used for already compressed \n"
31+
" resources like images. Default value is 10. (0% - 100% range)\n"
32+
" -v <dataVersion> Specifies pack file version. It's used to check if we are \n"
33+
" loading correct resources pack for a current game or \n"
34+
" application version. Default value is 0.\n"
35+
" -s Use faster decompression algorithm sacrificing resources pack file size.\n"
36+
);
37+
}
38+
2139
int main(int argc, char *argv[])
2240
{
2341
if (argc <= 2)
2442
{
25-
printf("Usage: packer [-z, -v, -s] <pack-path> <file-path-1> <item-path-1>...\n");
43+
printPackerHelp();
2644
return EXIT_FAILURE;
2745
}
2846

@@ -66,19 +84,25 @@ int main(int argc, char *argv[])
6684
argOffset += 1;
6785
continue;
6886
}
87+
else if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0)
88+
{
89+
printPackerHelp();
90+
return EXIT_SUCCESS;
91+
}
6992
break;
7093
}
7194

7295
char* packPath = argv[argOffset++];
96+
int itemCount = argc - argOffset;
7397

74-
if ((argc - argOffset) % 2 != 0)
98+
if (itemCount <= 0 || itemCount % 2 != 0)
7599
{
76100
printf("Bad pack file and item count, missing some of the items.\n");
77101
return EXIT_FAILURE;
78102
}
79103

80-
PackResult result = packFiles(packPath, (argc - argOffset) / 2, (const char**)argv + argOffset,
81-
dataVersion, zipThreshold, preferSpeed, true, NULL, NULL);
104+
PackResult result = packFiles(packPath, itemCount / 2, (const char**)argv +
105+
argOffset, dataVersion, zipThreshold, preferSpeed, true, NULL, NULL);
82106

83107
if (result != SUCCESS_PACK_RESULT)
84108
{

utilities/unpacker.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@
1717
#include <stdio.h>
1818
#include <stdlib.h>
1919

20+
static void printUnpackerHelp()
21+
{
22+
printf("Usage: unpacker <pack-path>\n");
23+
}
24+
2025
int main(int argc, char *argv[])
2126
{
2227
if (argc != 2)
2328
{
24-
printf("Usage: unpacker <pack-path>\n");
29+
printUnpackerHelp();
2530
return EXIT_FAILURE;
2631
}
2732

0 commit comments

Comments
 (0)