annotate tools/packed.c @ 1267:ad13510c8e41

Fix handling of -x option in packed.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 27 May 2015 01:15:59 +0300
parents e8c99da451cd
children cb9865a49134
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * PACKed - PACKfile EDitor
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * (C) Copyright 2011 Tecnic Software productions (TNSP)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 #include "dmlib.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include "dmargs.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #include "dmpack.h"
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
9 #include "dmfile.h"
115
23e03defa759 Prettify pack content listing output.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
10 #include "dmres.h"
285
245b15cd1919 Don't link libSDL uselessly to utilities that do not actually use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 211
diff changeset
11 #include "dmmutex.h"
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
12 #include <zlib.h>
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
13
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 #define SET_MAX_FILES (4096)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 #define SET_DEFAULT_PACK "data.pak"
996
acda8cfc9119 Also here.
Matti Hamalainen <ccr@tnsp.org>
parents: 994
diff changeset
17 #define SET_TMPBUF_SIZE (128 * 1024)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
18
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 enum
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 CMD_NONE = 0,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 CMD_CREATE,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 CMD_ADD,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 CMD_LIST,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 CMD_EXTRACT
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 } DCOMMAND;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 enum
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 PACK_EXTRACTED = 0x0001,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 };
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
33 int nsrcFilenames = 0, nexcFilenames = 0;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 char * srcFilenames[SET_MAX_FILES];
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
35 char * excFilenames[SET_MAX_FILES];
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
36
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 char * optPackFilename = NULL;
1120
c1583a2278ec Fix '-n' option handling for packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
38 BOOL optDoCompress = TRUE;
1027
d29058e93799 Add option for setting the zlib compression level.
Matti Hamalainen <ccr@tnsp.org>
parents: 1026
diff changeset
39 int optCompressLevel = Z_BEST_COMPRESSION;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 int optCommand = CMD_NONE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 int optDefResFlags = 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
44 static const DMOptArg optList[] =
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 {
1020
021e76f94dcb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
46 { 0, '?', "help", "Show this help", OPT_NONE },
021e76f94dcb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
47 { 1, 'p', "pack", "Set pack filename (default: " SET_DEFAULT_PACK ")", OPT_ARGREQ },
021e76f94dcb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
48 { 2, 'c', "create", "Create and add files to PACK", OPT_NONE },
021e76f94dcb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
49 { 3, 'a', "add", "Add files to PACK", OPT_NONE },
021e76f94dcb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
50 { 4, 'l', "list", "List files in PACK", OPT_NONE },
021e76f94dcb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
51 { 5, 'e', "extract", "Extract files from PACK", OPT_NONE },
021e76f94dcb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
52 { 6, 'n', "nocompress", "No compression / decompression", OPT_NONE },
1027
d29058e93799 Add option for setting the zlib compression level.
Matti Hamalainen <ccr@tnsp.org>
parents: 1026
diff changeset
53 { 10, 'C', "level", "Set zlib compression level 1-9", OPT_ARGREQ },
1020
021e76f94dcb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
54 { 7, 'v', "verbose", "Increase verbosity", OPT_NONE },
021e76f94dcb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
55 { 8, 'f', "resflags", "Set default resource flags (-f 0xff)", OPT_ARGREQ },
021e76f94dcb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
56 { 9, 'x', "exclude", "Exclude name/glob pattern from add", OPT_ARGREQ },
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 };
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 static const int optListN = sizeof(optList) / sizeof(optList[0]);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 void argShowHelp()
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 {
117
b56ce9981d79 Correct help of 'packed' utility.
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
64 dmPrintBanner(stdout, dmProgName, "[options] [-p <packfilename>] [filename[s]]");
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
65 dmArgsPrintHelp(stdout, optList, optListN, 0);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 fprintf(stdout,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 "\n"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 "Examples:\n"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 "$ %s -p test.pak -l -- list files in test.pak\n"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 "$ %s -a foobar.jpg -- add foobar.jpg in " SET_DEFAULT_PACK "\n"
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
71 "$ %s -e foobar.jpg -- extract foobar.jpg from " SET_DEFAULT_PACK "\n",
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 dmProgName, dmProgName, dmProgName);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 {
1267
ad13510c8e41 Fix handling of -x option in packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
78 (void) currArg;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 switch (optN)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 {
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
81 case 0:
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
82 argShowHelp();
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
83 exit(0);
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
84 break;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
86 case 1:
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
87 optPackFilename = optArg;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
88 break;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
89 case 2:
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
90 optCommand = CMD_CREATE;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
91 break;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
92 case 3:
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
93 optCommand = CMD_ADD;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
94 break;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
95 case 4:
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
96 optCommand = CMD_LIST;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
97 break;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
98 case 5:
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
99 optCommand = CMD_EXTRACT;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
100 break;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
102 case 6:
1120
c1583a2278ec Fix '-n' option handling for packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
103 optDoCompress = FALSE;
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
104 break;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
106 case 7:
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
107 dmVerbosity++;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
108 break;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
110 case 8:
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 {
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
112 unsigned int i;
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
113 if (!dmGetIntVal(optArg, &i))
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
114 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
115 dmErrorMsg("Invalid flags value '%s'.\n", optArg);
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
116 return FALSE;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
117 }
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
118 optDefResFlags = i;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 }
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
120 break;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
121
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
122 case 9:
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
123 if (nexcFilenames < SET_MAX_FILES)
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
124 {
1267
ad13510c8e41 Fix handling of -x option in packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
125 excFilenames[nexcFilenames++] = optArg;
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
126 }
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
127 else
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
128 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
129 dmErrorMsg("Maximum number of exclusion patterns (%d) exceeded!\n",
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
130 SET_MAX_FILES);
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
131 return FALSE;
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
132 }
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
133 break;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
1027
d29058e93799 Add option for setting the zlib compression level.
Matti Hamalainen <ccr@tnsp.org>
parents: 1026
diff changeset
135 case 10:
d29058e93799 Add option for setting the zlib compression level.
Matti Hamalainen <ccr@tnsp.org>
parents: 1026
diff changeset
136 optCompressLevel = atoi(optArg);
d29058e93799 Add option for setting the zlib compression level.
Matti Hamalainen <ccr@tnsp.org>
parents: 1026
diff changeset
137 if (optCompressLevel < 1 || optCompressLevel > 9)
d29058e93799 Add option for setting the zlib compression level.
Matti Hamalainen <ccr@tnsp.org>
parents: 1026
diff changeset
138 {
d29058e93799 Add option for setting the zlib compression level.
Matti Hamalainen <ccr@tnsp.org>
parents: 1026
diff changeset
139 dmErrorMsg("Invalid compression level argument '%s', must be 1 .. 9.\n", optArg);
d29058e93799 Add option for setting the zlib compression level.
Matti Hamalainen <ccr@tnsp.org>
parents: 1026
diff changeset
140 return FALSE;
d29058e93799 Add option for setting the zlib compression level.
Matti Hamalainen <ccr@tnsp.org>
parents: 1026
diff changeset
141 }
d29058e93799 Add option for setting the zlib compression level.
Matti Hamalainen <ccr@tnsp.org>
parents: 1026
diff changeset
142 break;
d29058e93799 Add option for setting the zlib compression level.
Matti Hamalainen <ccr@tnsp.org>
parents: 1026
diff changeset
143
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
144 default:
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
145 return FALSE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 return TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 BOOL argHandleFile(char *currArg)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 if (nsrcFilenames < SET_MAX_FILES)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 {
1022
0020c192c8dd Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1021
diff changeset
156 srcFilenames[nsrcFilenames++] = currArg;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
160 dmErrorMsg("Maximum number of input files (%d) exceeded!\n",
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 SET_MAX_FILES);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 return FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 return TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
168 DMPackEntry *dmPackEntryCopy(const DMPackEntry *src)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
169 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
170 DMPackEntry *node = dmPackEntryNew();
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
171 if (node == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
172 return NULL;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
173
1033
c353e6bcb733 Change handling of filename field in PACKs.
Matti Hamalainen <ccr@tnsp.org>
parents: 1032
diff changeset
174 strncpy(node->filename, src->filename, DMRES_NAME_LEN);
c353e6bcb733 Change handling of filename field in PACKs.
Matti Hamalainen <ccr@tnsp.org>
parents: 1032
diff changeset
175 node->filename[DMRES_NAME_LEN] = 0;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
176
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
177 node->size = src->size;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
178 node->offset = src->offset;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
179 node->length = src->length;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
180 node->flags = src->flags;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
181
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
182 return node;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
183 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
184
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
185
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
186 int dmPackWrite(DMPackFile * pack)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
187 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
188 DMPackEntry *node;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
189 DMPackFileHeader hdr;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
190
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
191 if (pack == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
192 return DMERR_OK;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
193
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
194 if (pack->file == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
195 return DMERR_FOPEN;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
196
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
197 // Compute directory offset and number of entries
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
198 memcpy(&hdr.ident, DPACK_IDENT, sizeof(hdr.ident));
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
199 hdr.version = DPACK_VERSION;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
200 hdr.dirEntries = 0;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
201 hdr.dirOffset =
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
202 sizeof(hdr.ident) + sizeof(hdr.version) +
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
203 sizeof(hdr.dirEntries) + sizeof(hdr.dirOffset);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
204
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
205 node = pack->entries;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
206 while (node != NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
207 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
208 hdr.dirEntries++;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
209 hdr.dirOffset += node->length;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
210 node = node->next;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
211 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
212
1128
0194c8a26aa8 Add informative message to packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1120
diff changeset
213 dmMsg(1, "%d entries in PACK, dir at offset 0x%08x.\n",
0194c8a26aa8 Add informative message to packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1120
diff changeset
214 hdr.dirEntries, hdr.dirOffset);
0194c8a26aa8 Add informative message to packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1120
diff changeset
215
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
216 // Write PACK header
1108
5a8d29b88431 More fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1041
diff changeset
217 if (fseeko(pack->file, 0, SEEK_SET) != 0)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
218 return DMERR_FSEEK;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
219
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
220 if (!dm_fwrite_str(pack->file, (Uint8 *) & hdr.ident, sizeof(hdr.ident)) ||
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
221 !dm_fwrite_le16(pack->file, hdr.version) ||
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
222 !dm_fwrite_le32(pack->file, hdr.dirEntries) ||
1037
d674ddc0fc82 Change PACK file format to use 64 bit fileoffsets. Also switch some
Matti Hamalainen <ccr@tnsp.org>
parents: 1036
diff changeset
223 !dm_fwrite_le64(pack->file, hdr.dirOffset))
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
224 return DMERR_FWRITE;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
225
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
226 // Write the directory
1108
5a8d29b88431 More fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1041
diff changeset
227 if (fseeko(pack->file, hdr.dirOffset, SEEK_SET) != 0)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
228 return DMERR_FSEEK;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
229
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
230 node = pack->entries;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
231 while (node != NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
232 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
233 // Write one entry
1033
c353e6bcb733 Change handling of filename field in PACKs.
Matti Hamalainen <ccr@tnsp.org>
parents: 1032
diff changeset
234 if (!dm_fwrite_str(pack->file, node->filename, DMRES_NAME_LEN) ||
1037
d674ddc0fc82 Change PACK file format to use 64 bit fileoffsets. Also switch some
Matti Hamalainen <ccr@tnsp.org>
parents: 1036
diff changeset
235 !dm_fwrite_le64(pack->file, node->offset) ||
d674ddc0fc82 Change PACK file format to use 64 bit fileoffsets. Also switch some
Matti Hamalainen <ccr@tnsp.org>
parents: 1036
diff changeset
236 !dm_fwrite_le32(pack->file, node->length) ||
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
237 !dm_fwrite_le32(pack->file, node->size) ||
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
238 !dm_fwrite_le32(pack->file, node->flags))
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
239 return DMERR_FWRITE;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
240
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
241 node = node->next;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
242 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
243
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
244 return DMERR_OK;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
245 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
246
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
247
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
248 int dmPackCreate(const char *filename, DMPackFile ** pack)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
249 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
250 // Allocate packfile-structure
1024
66b01739e5d3 Use dmMalloc0() instead of dmCalloc(1, ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 1023
diff changeset
251 *pack = (DMPackFile *) dmMalloc0(sizeof(DMPackFile));
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
252 if (*pack == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
253 return DMERR_MALLOC;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
254
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
255 // Open the file
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
256 (*pack)->file = fopen(filename, "wb");
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
257 if ((*pack)->file == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
258 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
259 dmFree(*pack);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
260 return DMERR_FOPEN;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
261 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
262
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
263 (*pack)->filename = dm_strdup(filename);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
264
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
265 // Set the result
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
266 return DMERR_OK;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
267 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
268
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
269
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
270 int dmPackAddFile(DMPackFile * pack, const char *filename,
1041
d0f80f6a0c65 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1039
diff changeset
271 const Uint32 flags, const BOOL compress, int level,
d0f80f6a0c65 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1039
diff changeset
272 DMPackEntry ** ppEntry)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
273 {
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
274 Uint64 startOffs, outSize;
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
275 Uint8 *inBuffer = NULL, *outBuffer = NULL;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
276 DMPackEntry entry, *node;
1031
f7863608d84c Cleanup, remove debug code.
Matti Hamalainen <ccr@tnsp.org>
parents: 1029
diff changeset
277 FILE *inFile = NULL;
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
278 int ret = DMERR_OK;
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
279 BOOL zinit = FALSE;
1031
f7863608d84c Cleanup, remove debug code.
Matti Hamalainen <ccr@tnsp.org>
parents: 1029
diff changeset
280 z_stream zstr;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
281
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
282 *ppEntry = NULL;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
283
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
284 if (pack == NULL)
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
285 return DMERR_NULLPTR;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
286
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
287 if (pack->file == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
288 return DMERR_FOPEN;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
289
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
290 // Compute starting offset
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
291 outSize = 0;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
292 startOffs = sizeof(DMPackFileHeader);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
293 node = pack->entries;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
294 while (node != NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
295 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
296 startOffs += node->length;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
297 node = node->next;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
298 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
299
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
300 // Seek to the position
1108
5a8d29b88431 More fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1041
diff changeset
301 if (fseeko(pack->file, startOffs, SEEK_SET) != 0)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
302 return DMERR_INVALID;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
303
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
304 // Read file data
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
305 if ((inFile = fopen(filename, "rb")) == NULL)
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
306 return DMERR_FOPEN;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
307
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
308 // Allocate temporary buffer
996
acda8cfc9119 Also here.
Matti Hamalainen <ccr@tnsp.org>
parents: 994
diff changeset
309 if ((inBuffer = (Uint8 *) dmMalloc(SET_TMPBUF_SIZE)) == NULL ||
acda8cfc9119 Also here.
Matti Hamalainen <ccr@tnsp.org>
parents: 994
diff changeset
310 (outBuffer = (Uint8 *) dmMalloc(SET_TMPBUF_SIZE)) == NULL)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
311 {
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
312 ret = DMERR_MALLOC;
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
313 goto out;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
314 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
315
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
316 // Read (and possibly compress) the data
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
317 if (compress)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
318 {
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
319 int zret;
1167
848a88ce7a57 Use dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1128
diff changeset
320 dmMemset(&zstr, 0, sizeof(zstr));
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
321 if (deflateInit(&zstr, level) != Z_OK)
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
322 {
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
323 ret = DMERR_COMPRESSION;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
324 goto out;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
325 }
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
326 zinit = TRUE;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
327
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
328 // Initialize compression streams
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
329 zret = Z_OK;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
330 while (!feof(inFile) && zret == Z_OK)
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
331 {
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
332 zstr.avail_in = fread(inBuffer, sizeof(Uint8), SET_TMPBUF_SIZE, inFile);
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
333
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
334 zstr.next_in = inBuffer;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
335 zstr.next_out = outBuffer;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
336 zstr.avail_out = SET_TMPBUF_SIZE;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
337 zstr.total_out = 0;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
338 zret = deflate(&zstr, Z_FULL_FLUSH);
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
339
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
340 if (zret == Z_OK && zstr.total_out > 0)
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
341 {
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
342 outSize += zstr.total_out;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
343 if (fwrite(outBuffer, sizeof(Uint8), zstr.total_out, pack->file) != zstr.total_out)
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
344 {
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
345 ret = DMERR_FWRITE;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
346 goto out;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
347 }
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
348 }
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
349 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
350 }
1032
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
351 else
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
352 {
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
353 while (!feof(inFile))
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
354 {
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
355 size_t read = fread(inBuffer, sizeof(Uint8), SET_TMPBUF_SIZE, inFile);
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
356 if (read > 0)
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
357 {
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
358 outSize += read;
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
359 if (fwrite(inBuffer, sizeof(Uint8), read, pack->file) != read)
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
360 {
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
361 ret = DMERR_FWRITE;
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
362 goto out;
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
363 }
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
364 }
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
365 }
1039
54970cd5acf0 Remember to set the "compressed" size field for raw nodes too, as we check
Matti Hamalainen <ccr@tnsp.org>
parents: 1037
diff changeset
366 zstr.total_in = outSize;
1032
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
367 }
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
368
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
369 // Create directory entry
1035
d2fa4f6d6117 Oops, add a missing semicolon.
Matti Hamalainen <ccr@tnsp.org>
parents: 1033
diff changeset
370 strncpy(entry.filename, filename, DMRES_NAME_LEN);
1033
c353e6bcb733 Change handling of filename field in PACKs.
Matti Hamalainen <ccr@tnsp.org>
parents: 1032
diff changeset
371 entry.filename[DMRES_NAME_LEN] = 0;
1018
782a2a3a3707 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1011
diff changeset
372 entry.offset = startOffs;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
373 entry.size = zstr.total_in;
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
374 entry.length = outSize;
1029
c88b879c735c Add DMF_COMPRESSED flag to compressed entry node flags.
Matti Hamalainen <ccr@tnsp.org>
parents: 1028
diff changeset
375 entry.flags = flags | (compress ? DMF_COMPRESSED : 0);
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
376
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
377 // Add directory entry
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
378 if ((*ppEntry = dmPackEntryCopy(&entry)) == NULL)
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
379 {
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
380 ret = DMERR_MALLOC;
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
381 goto out;
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
382 }
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
383
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
384 dmPackEntryInsert(&pack->entries, *ppEntry);
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
385
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
386 out:
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
387 // Cleanup
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
388 if (zinit)
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
389 deflateEnd(&zstr);
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
390
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
391 dmFree(inBuffer);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
392 dmFree(outBuffer);
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
393 if (inFile != NULL)
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
394 fclose(inFile);
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
395
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
396 return ret;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
397 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
398
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
399
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
400 /*
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
401 * EXTRACT a file from the PACK
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
402 */
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
403 int dmPackExtractFile(DMPackFile *pack, DMPackEntry * entry, BOOL decompress)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
404 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
405 z_stream zstr;
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
406 FILE *outFile = NULL;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
407 Uint8 *inBuffer = NULL, *outBuffer = NULL;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
408 size_t remaining;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
409 int zret, ret = DMERR_OK;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
410 BOOL zinit = FALSE;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
411
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
412 if (pack == NULL)
1018
782a2a3a3707 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1011
diff changeset
413 return DMERR_NULLPTR;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
414
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
415 if (pack->file == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
416 return DMERR_FOPEN;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
417
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
418 // Seek to the position
1108
5a8d29b88431 More fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1041
diff changeset
419 if (fseeko(pack->file, entry->offset, SEEK_SET) != 0)
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
420 return DMERR_FSEEK;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
421
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
422 // Open destination file
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
423 if ((outFile = fopen(entry->filename, "wb")) == NULL)
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
424 return DMERR_FOPEN;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
425
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
426 // Allocate temporary buffer
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
427 if ((inBuffer = (Uint8 *) dmMalloc(SET_TMPBUF_SIZE)) == NULL ||
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
428 (outBuffer = (Uint8 *) dmMalloc(SET_TMPBUF_SIZE)) == NULL)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
429 {
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
430 ret = DMERR_MALLOC;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
431 goto out;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
432 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
433
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
434 // Read and uncompress the data, if needed
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
435 if (decompress || (entry->flags & DMF_COMPRESSED) == 0)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
436 {
1167
848a88ce7a57 Use dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1128
diff changeset
437 dmMemset(&zstr, 0, sizeof(zstr));
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
438 if (inflateInit(&zstr) != Z_OK)
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
439 {
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
440 ret = DMERR_COMPRESSION;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
441 goto out;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
442 }
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
443 zinit = TRUE;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
444 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
445
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
446 // Initialize compression streams
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
447 remaining = entry->length;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
448 zret = Z_OK;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
449 while (remaining > 0 && zret == Z_OK)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
450 {
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
451 size_t needed = remaining > SET_TMPBUF_SIZE ? SET_TMPBUF_SIZE : remaining;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
452 zstr.avail_in = fread(inBuffer, sizeof(Uint8), needed, pack->file);
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
453 if (zstr.avail_in < needed)
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
454 {
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
455 ret = DMERR_FREAD;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
456 goto out;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
457 }
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
458
1018
782a2a3a3707 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1011
diff changeset
459 remaining -= zstr.avail_in;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
460 zstr.next_in = inBuffer;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
461
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
462 if (!decompress)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
463 {
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
464 if (fwrite(inBuffer, sizeof(Uint8), zstr.avail_in, outFile) != zstr.avail_in)
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
465 {
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
466 ret = DMERR_FWRITE;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
467 goto out;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
468 }
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
469 }
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
470 else
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
471 while (zstr.avail_in > 0 && zret == Z_OK)
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
472 {
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
473 zstr.next_out = outBuffer;
996
acda8cfc9119 Also here.
Matti Hamalainen <ccr@tnsp.org>
parents: 994
diff changeset
474 zstr.avail_out = SET_TMPBUF_SIZE;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
475 zstr.total_out = 0;
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
476 zret = inflate(&zstr, Z_FULL_FLUSH);
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
477 if (zstr.total_out > 0 &&
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
478 fwrite(outBuffer, sizeof(Uint8), zstr.total_out, outFile) != zstr.total_out)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
479 {
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
480 ret = DMERR_FWRITE;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
481 goto out;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
482 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
483 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
484 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
485
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
486 out:
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
487 // Cleanup
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
488 if (zinit)
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
489 inflateEnd(&zstr);
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
490
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
491 dmFree(inBuffer);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
492 dmFree(outBuffer);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
493
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
494 if (outFile != NULL)
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
495 fclose(outFile);
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
496
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
497 return ret;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
498 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
499
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
500
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
501 /* Compare a string to a pattern. Case-SENSITIVE version.
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
502 * The matching pattern can consist of any normal characters plus
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503 * wildcards ? and *. "?" matches any character and "*" matches
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504 * any number of characters.
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
505 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506 BOOL dm_strmatch(const char *str, const char *pattern)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
507 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
508 BOOL matched = TRUE, any = FALSE, end = FALSE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
509 const char *tmp = NULL;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511 // Check given pattern and string
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
512 if (str == NULL || pattern == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
513 return FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
514
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515 // Start comparision
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516 do {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
517 matched = FALSE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
518 switch (*pattern)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
519 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
520 case '?':
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
521 // Any single character matches
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
522 if (*str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
523 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
524 matched = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
525 pattern++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
526 str++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
527 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
528 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
529
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530 case '*':
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
531 matched = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
532 pattern++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
533 if (!*pattern)
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
534 end = TRUE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
535 any = TRUE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
536 tmp = pattern;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
537 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
538
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
539 case 0:
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
540 if (any)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
541 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
542 if (*str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
543 str++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
544 else
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
545 end = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
546 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
547 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
548 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
549 if (*str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
550 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
551 if (tmp)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
552 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
553 any = TRUE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
554 pattern = tmp;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
555 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
556 else
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
557 matched = FALSE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
558 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
559 else
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
560 end = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
561 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
562 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
563 default:
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
564 if (any)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
565 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
566 if (*pattern == *str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
567 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
568 any = FALSE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
569 matched = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
570 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
571 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
572 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
573 if (*str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
574 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
575 matched = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
576 str++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
577 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
578 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
579 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
580 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
581 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
582 if (*pattern == *str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
583 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
584 matched = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
585 if (*pattern)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
586 pattern++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
587 if (*str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
588 str++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
589 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
590 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
591 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
592 if (tmp)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
593 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
594 matched = TRUE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
595 any = TRUE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
596 pattern = tmp;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
597 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
598 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
599 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
600
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
601 if (!*str && !*pattern)
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
602 end = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
603 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
604
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
605 } // switch
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
606
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
607 } while (matched && !end);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
608
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
609 return matched;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
610 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
611
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
612
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
613 BOOL dmCheckExcluded(const char *filename)
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
614 {
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
615 int i;
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
616 for (i = 0; i < nexcFilenames; i++)
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
617 {
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
618 if (dm_strmatch(filename, excFilenames[i]))
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
619 return TRUE;
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
620 }
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
621 return FALSE;
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
622 }
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
623
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
624
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
625 int main(int argc, char *argv[])
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
626 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
627 int i, res = 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
628 DMPackFile *pack = NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
629
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
630 // Parse arguments
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
631 dmInitProg("packed", "Pack File Editor", "0.5", NULL, NULL);
1011
aa745d31612e Set default verbosity of 'packed' to none.
Matti Hamalainen <ccr@tnsp.org>
parents: 1008
diff changeset
632 dmVerbosity = 0;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
633
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
634 if (!dmArgsProcess(argc, argv, optList, optListN,
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
635 argHandleOpt, argHandleFile, OPTH_BAILOUT))
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
636 exit(1);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
637
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
638 // Check PACK filename
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
639 if (optPackFilename == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
640 optPackFilename = SET_DEFAULT_PACK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
641
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
642 if (optCommand == CMD_NONE)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
643 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
644 argShowHelp();
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
645 dmErrorMsg("Nothing to do.\n");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
646 exit(0);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
647 return 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
648 }
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
649
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
650 dmMsg(1, "Processing %s ...\n", optPackFilename);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
651
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
652 // Execute command
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
653 switch (optCommand)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
654 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
655 case CMD_CREATE:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
656 case CMD_ADD:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
657 switch (optCommand)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
658 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
659 case CMD_CREATE:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
660 dmMsg(1, "Creating new PACK\n");
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
661 res = dmPackCreate(optPackFilename, &pack);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
662 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
663
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
664 case CMD_ADD:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
665 dmMsg(1, "Opening existing PACK\n");
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
666 res = dmPackOpen(optPackFilename, &pack, FALSE);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
667 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
668 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
669
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
670 // Add files into PACK
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
671 if (res == DMERR_OK)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
672 {
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
673 dmMsg(1, "Adding files...\n");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
674
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
675 for (i = 0; i < nsrcFilenames; i++)
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
676 if (!dmCheckExcluded(srcFilenames[i]))
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
677 {
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
678 DMPackEntry *node = NULL;
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
679 int res = dmPackAddFile(pack, srcFilenames[i],
1120
c1583a2278ec Fix '-n' option handling for packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
680 optDefResFlags, optDoCompress,
1027
d29058e93799 Add option for setting the zlib compression level.
Matti Hamalainen <ccr@tnsp.org>
parents: 1026
diff changeset
681 optCompressLevel, &node);
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
682
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
683 if (res != DMERR_OK)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
684 {
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
685 dmPrint(1, "%-32s [ERROR:%d]\n",
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
686 srcFilenames[i], res);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
687 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
688 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
689 {
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
690 dmPrint(1, "%-32s ['%s', s=%d, c=%d, o=%ld, f=0x%04x]\n",
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
691 srcFilenames[i], node->filename,
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
692 node->size, node->length, node->offset, node->flags);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
693 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
694 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
695
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
696 dmMsg(1, "w=%d\n", dmPackWrite(pack));
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
697 dmMsg(1, "c=%d\n", dmPackClose(pack));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
698 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
699 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
700 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
701 dmErrorMsg("Could not open packfile, error #%d: %s\n", res,
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
702 dmErrorStr(res));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
703 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
704 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
705
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
706 case CMD_LIST:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
707 // List files in PACK
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
708 res = dmPackOpen(optPackFilename, &pack, TRUE);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
709 if (res == DMERR_OK)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
710 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
711 DMPackEntry *node;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
712 for (i = 0, node = pack->entries; node; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
713 node = node->next;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
714 dmMsg(1, "%d files total\n", i);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
715
115
23e03defa759 Prettify pack content listing output.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
716 dmPrint(0, "%-32s | %8s | %8s | %8s | %s\n",
23e03defa759 Prettify pack content listing output.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
717 "Name", "Size", "CSize", "Offset", "ResFlags");
23e03defa759 Prettify pack content listing output.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
718
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
719 for (node = pack->entries; node != NULL; node = node->next)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
720 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
721 BOOL match;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
722
1025
b43885dd3d1a Comments, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1024
diff changeset
723 // Check for matches in specified filenames/patterns
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
724 if (nsrcFilenames > 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
725 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
726 match = FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
727 for (i = 0; i < nsrcFilenames && !match; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
728 match = dm_strmatch(node->filename, srcFilenames[i]);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
729 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
730 else
1025
b43885dd3d1a Comments, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1024
diff changeset
731 // No filenames specified, everything shown
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
732 match = TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
733
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
734 if (match)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
735 {
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
736 dmPrint(0, "%-32s | %8d | %8d | %08x | %04x\n",
115
23e03defa759 Prettify pack content listing output.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
737 node->filename, node->size, node->length,
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
738 node->offset, node->flags);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
739 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
740 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
741
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
742 dmMsg(1, "c=%d\n", dmPackClose(pack));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
743 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
744 else
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
745 dmErrorMsg("Could not open packfile, error #%d: %s\n", res,
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
746 dmErrorStr(res));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
747 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
748
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
749 case CMD_EXTRACT:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
750 // Extract files from PACK
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
751 res = dmPackOpen(optPackFilename, &pack, TRUE);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
752 if (res == DMERR_OK)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
753 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
754 DMPackEntry *node;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
755 FILE *resFile = fopen(DMRES_RES_FILE, "w");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
756 if (resFile == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
757 {
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
758 int err = dmGetErrno();
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
759 dmErrorMsg("Could not create resource output file '%s' #%d: %s\n",
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
760 DMRES_RES_FILE, err, dmErrorStr(err));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
761 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
762
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
763 for (node = pack->entries; node != NULL; node = node->next)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
764 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
765 BOOL match;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
766
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
767 // Check for matches
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
768 if (nsrcFilenames > 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
769 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
770 match = FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
771 for (i = 0; (i < nsrcFilenames) && !match; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
772 {
1267
ad13510c8e41 Fix handling of -x option in packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
773 if (dm_strmatch(node->filename, srcFilenames[i]) &&
ad13510c8e41 Fix handling of -x option in packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
774 !dmCheckExcluded(node->filename))
ad13510c8e41 Fix handling of -x option in packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
775 match = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
776 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
777 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
778 else
1267
ad13510c8e41 Fix handling of -x option in packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
779 {
ad13510c8e41 Fix handling of -x option in packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
780 match = !dmCheckExcluded(node->filename);
ad13510c8e41 Fix handling of -x option in packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
781 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
782
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
783 if (match && (node->privFlags & PACK_EXTRACTED) == 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
784 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
785 // Mark as done
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
786 node->privFlags |= PACK_EXTRACTED;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
787
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
788 // Print one entry
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
789 dmPrint(0, "Extracting: %-32s [siz=%d, cmp=%d, offs=0x%08x, flags=0x%04x]\n",
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
790 node->filename, node->size, node->length,
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
791 node->offset, node->flags);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
792
1120
c1583a2278ec Fix '-n' option handling for packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
793 dmPackExtractFile(pack, node, optDoCompress);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
794 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
795 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
796
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
797 dmMsg(1, "c=%d\n", dmPackClose(pack));
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
798
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
799 if (resFile != NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
800 fclose(resFile);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
801 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
802 else
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
803 dmErrorMsg("Could not open packfile, error #%d: %s\n", res,
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
804 dmErrorStr(res));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
805 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
806
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
807 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
808
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
809 return 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
810 }