diff options
Diffstat (limited to 'tools/creative.c')
-rw-r--r-- | tools/creative.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/tools/creative.c b/tools/creative.c index 43fdbbc917..1698f58930 100644 --- a/tools/creative.c +++ b/tools/creative.c | |||
@@ -155,7 +155,7 @@ static int make_jrm_file(const unsigned char *inbuf, unsigned char *outbuf) | |||
155 | return 0xC+length; | 155 | return 0xC+length; |
156 | } | 156 | } |
157 | 157 | ||
158 | int zvm_encode(const char *iname, const char *oname, int device) | 158 | int zvm_encode(const char *iname, const char *oname, int device, bool enable_ciff) |
159 | { | 159 | { |
160 | size_t len; | 160 | size_t len; |
161 | int length; | 161 | int length; |
@@ -164,7 +164,8 @@ int zvm_encode(const char *iname, const char *oname, int device) | |||
164 | unsigned char *buf; | 164 | unsigned char *buf; |
165 | 165 | ||
166 | file = fopen(iname, "rb"); | 166 | file = fopen(iname, "rb"); |
167 | if (!file) { | 167 | if (!file) |
168 | { | ||
168 | perror(iname); | 169 | perror(iname); |
169 | return -1; | 170 | return -1; |
170 | } | 171 | } |
@@ -174,20 +175,23 @@ int zvm_encode(const char *iname, const char *oname, int device) | |||
174 | fseek(file, 0, SEEK_SET); | 175 | fseek(file, 0, SEEK_SET); |
175 | 176 | ||
176 | buf = (unsigned char*)malloc(length); | 177 | buf = (unsigned char*)malloc(length); |
177 | if ( !buf ) { | 178 | if ( !buf ) |
179 | { | ||
178 | printf("Out of memory!\n"); | 180 | printf("Out of memory!\n"); |
179 | return -1; | 181 | return -1; |
180 | } | 182 | } |
181 | 183 | ||
182 | len = fread(buf, 1, length, file); | 184 | len = fread(buf, 1, length, file); |
183 | if(len < (size_t)length) { | 185 | if(len < (size_t)length) |
186 | { | ||
184 | perror(iname); | 187 | perror(iname); |
185 | return -2; | 188 | return -2; |
186 | } | 189 | } |
187 | fclose(file); | 190 | fclose(file); |
188 | 191 | ||
189 | outbuf = (unsigned char*)malloc(length+0x300); | 192 | outbuf = (unsigned char*)malloc(length+0x300); |
190 | if ( !outbuf ) { | 193 | if ( !outbuf ) |
194 | { | ||
191 | free(buf); | 195 | free(buf); |
192 | printf("Out of memory!\n"); | 196 | printf("Out of memory!\n"); |
193 | return -1; | 197 | return -1; |
@@ -200,20 +204,33 @@ int zvm_encode(const char *iname, const char *oname, int device) | |||
200 | printf("Error in making JRM file!\n"); | 204 | printf("Error in making JRM file!\n"); |
201 | return -1; | 205 | return -1; |
202 | } | 206 | } |
203 | buf = (unsigned char*)malloc(length+0x200); | 207 | if(enable_ciff) |
204 | memset(buf, 0, length+0x200); | 208 | { |
205 | length = make_ciff_file(outbuf, length, buf, device); | 209 | buf = (unsigned char*)malloc(length+0x200); |
206 | free(outbuf); | 210 | if ( !buf ) |
211 | { | ||
212 | free(outbuf); | ||
213 | printf("Out of memory!\n"); | ||
214 | return -1; | ||
215 | } | ||
216 | memset(buf, 0, length+0x200); | ||
217 | length = make_ciff_file(outbuf, length, buf, device); | ||
218 | free(outbuf); | ||
219 | } | ||
220 | else | ||
221 | buf = outbuf; | ||
207 | 222 | ||
208 | file = fopen(oname, "wb"); | 223 | file = fopen(oname, "wb"); |
209 | if (!file) { | 224 | if (!file) |
225 | { | ||
210 | free(buf); | 226 | free(buf); |
211 | perror(oname); | 227 | perror(oname); |
212 | return -3; | 228 | return -3; |
213 | } | 229 | } |
214 | 230 | ||
215 | len = fwrite(buf, 1, length, file); | 231 | len = fwrite(buf, 1, length, file); |
216 | if(len < (size_t)length) { | 232 | if(len < (size_t)length) |
233 | { | ||
217 | free(buf); | 234 | free(buf); |
218 | perror(oname); | 235 | perror(oname); |
219 | return -4; | 236 | return -4; |