Lines 1-4
Link Here
|
1 |
/* $Id: mdf2iso.c, 22/05/05 |
1 |
/* $Id: mdf2iso.c, 22/05/05 |
2 |
|
2 |
|
3 |
Copyright (C) 2004,2005 Salvatore Santagati <salvatore.santagati@gmail.com> |
3 |
Copyright (C) 2004,2005 Salvatore Santagati <salvatore.santagati@gmail.com> |
4 |
|
4 |
|
Lines 16-34
Link Here
|
16 |
along with this program; if not, write to the |
16 |
along with this program; if not, write to the |
17 |
Free Software Foundation, Inc., |
17 |
Free Software Foundation, Inc., |
18 |
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
*/ |
19 |
*/ |
20 |
|
20 |
|
21 |
#include <stdio.h> |
21 |
#include <stdio.h> |
22 |
#include <stdlib.h> |
22 |
#include <stdlib.h> |
23 |
#include <string.h> |
23 |
#include <string.h> |
24 |
#include <errno.h> |
24 |
#include <errno.h> |
25 |
|
25 |
|
26 |
#define VERSION "0.3.0" |
26 |
#define VERSION "0.3.1" |
27 |
|
|
|
28 |
/* Support Large File */ |
29 |
|
30 |
#define _FILE_OFFSET_BITS 64 |
31 |
|
32 |
|
27 |
|
33 |
|
28 |
|
34 |
const char SYNC_HEADER[12] = { (char) 0x00, |
29 |
const char SYNC_HEADER[12] = { (char) 0x00, |
Lines 83-96
Link Here
|
83 |
(char) 0x00 |
78 |
(char) 0x00 |
84 |
}; |
79 |
}; |
85 |
|
80 |
|
|
|
81 |
#define ISO9660 0 |
82 |
#define SYNC 1 |
83 |
#define SYNC_MDF 2 |
84 |
#define MDF_AUDIO 3 |
85 |
#define UNKNOWN -1 |
86 |
|
86 |
|
87 |
void |
87 |
int toc_file (char *destfilename, int sub) |
88 |
toc_file (char *destfilename, int sub) |
|
|
89 |
{ |
88 |
{ |
90 |
char destfiletoc[1024], destfiledat[1024]; |
89 |
int ret=0; |
|
|
90 |
char *destfiletoc; |
91 |
char *destfiledat; |
91 |
FILE *ftoc; |
92 |
FILE *ftoc; |
92 |
strcpy (destfiletoc, destfilename); |
93 |
|
93 |
strcpy (destfiledat, destfilename); |
94 |
destfiletoc=strdup(destfilename); |
|
|
95 |
destfiledat=strdup(destfilename); |
94 |
strcpy (destfiletoc + strlen (destfilename) - 4, ".toc"); |
96 |
strcpy (destfiletoc + strlen (destfilename) - 4, ".toc"); |
95 |
strcpy (destfiledat + strlen (destfilename) - 4, ".dat"); |
97 |
strcpy (destfiledat + strlen (destfilename) - 4, ".dat"); |
96 |
|
98 |
|
Lines 100-110
Link Here
|
100 |
fprintf (ftoc, "// Track 1\n"); |
102 |
fprintf (ftoc, "// Track 1\n"); |
101 |
fprintf (ftoc, "TRACK MODE1_RAW"); |
103 |
fprintf (ftoc, "TRACK MODE1_RAW"); |
102 |
|
104 |
|
103 |
if (sub == 1) |
105 |
if (sub == 1) fprintf (ftoc, " RW_RAW\n"); |
104 |
fprintf (ftoc, " RW_RAW\n"); |
106 |
else fprintf (ftoc, "\n"); |
105 |
|
|
|
106 |
else |
107 |
fprintf (ftoc, "\n"); |
108 |
|
107 |
|
109 |
fprintf (ftoc, "NO COPY\n"); |
108 |
fprintf (ftoc, "NO COPY\n"); |
110 |
fprintf (ftoc, "DATAFILE \"%s\"\n", destfiledat); |
109 |
fprintf (ftoc, "DATAFILE \"%s\"\n", destfiledat); |
Lines 114-139
Link Here
|
114 |
} |
113 |
} |
115 |
else |
114 |
else |
116 |
{ |
115 |
{ |
117 |
printf ("%s\n", strerror (errno)); |
116 |
printf ("Error opening %s for output: %s\n",destfiletoc,strerror(errno)); |
118 |
exit (EXIT_FAILURE); |
117 |
ret=-1; |
119 |
}; |
118 |
}; |
120 |
|
119 |
free(destfiletoc); |
|
|
120 |
free(destfiledat); |
121 |
return ret; |
121 |
} |
122 |
} |
122 |
|
123 |
|
123 |
int |
124 |
/* |
124 |
number_file (char *destfilename) |
125 |
int number_file (char *destfilename) |
125 |
{ |
126 |
{ |
126 |
int i = 1, test_mdf = 0; |
127 |
int i = 1, test_mdf = 0; |
127 |
int n_mdf; |
128 |
int n_mdf; |
128 |
char mdf[2], destfilemdf[2354]; |
129 |
char mdf[2], destfilemdf[2354]; |
129 |
FILE *fsource; |
130 |
FILE *fsource; |
|
|
131 |
|
130 |
strcpy (destfilemdf, destfilename); |
132 |
strcpy (destfilemdf, destfilename); |
131 |
strcpy (destfilemdf + strlen (destfilename) - 1, ".0"); |
133 |
strcpy (destfilemdf + strlen (destfilename) - 1, ".0"); |
132 |
for (i = 0; test_mdf == 0; i++) |
134 |
for (i = 0; test_mdf == 0; i++) |
133 |
|
|
|
134 |
{ |
135 |
{ |
135 |
if ((fsource = fopen (destfilemdf, "rb")) != NULL) |
136 |
if ((fsource = fopen (destfilemdf, "rb")) != NULL) |
136 |
|
|
|
137 |
{ |
137 |
{ |
138 |
printf ("\nCheck : "); |
138 |
printf ("\nCheck : "); |
139 |
sprintf (mdf, "md%d", i); |
139 |
sprintf (mdf, "md%d", i); |
Lines 141-343
Link Here
|
141 |
printf ("%s, ", destfilemdf); |
141 |
printf ("%s, ", destfilemdf); |
142 |
fclose (fsource); |
142 |
fclose (fsource); |
143 |
} |
143 |
} |
144 |
|
|
|
145 |
else |
144 |
else |
146 |
{ |
145 |
{ |
147 |
test_mdf = 1; |
146 |
test_mdf = 1; |
148 |
} |
147 |
} |
149 |
}; |
148 |
} |
150 |
printf ("\r \n"); |
149 |
printf ("\r \n"); |
151 |
n_mdf = i - 1; |
150 |
n_mdf = i - 1; |
152 |
return (n_mdf); |
151 |
return (n_mdf); |
153 |
} |
152 |
} |
|
|
153 |
*/ |
154 |
|
154 |
|
155 |
void |
155 |
int cuesheets (char *destfilename) |
156 |
cuesheets (char *destfilename) |
|
|
157 |
{ |
156 |
{ |
158 |
char destfilecue[1024], destfilebin[1024]; |
157 |
int ret=0; |
|
|
158 |
char *destfilecue; |
159 |
char *destfilebin; |
159 |
FILE *fcue; |
160 |
FILE *fcue; |
160 |
strcpy (destfilecue, destfilename); |
161 |
|
161 |
strcpy (destfilebin, destfilename); |
162 |
destfilecue=strdup(destfilename); |
|
|
163 |
destfilebin=strdup(destfilename); |
162 |
strcpy (destfilecue + strlen (destfilename) - 4, ".cue"); |
164 |
strcpy (destfilecue + strlen (destfilename) - 4, ".cue"); |
163 |
strcpy (destfilebin + strlen (destfilename) - 4, ".bin"); |
165 |
strcpy (destfilebin + strlen (destfilename) - 4, ".bin"); |
164 |
fcue = fopen (destfilecue, "w"); |
166 |
if ((fcue = fopen (destfilecue, "w"))!=NULL) |
|
|
167 |
{ |
165 |
fprintf (fcue, "FILE \"%s\" BINARY\n", destfilebin); |
168 |
fprintf (fcue, "FILE \"%s\" BINARY\n", destfilebin); |
166 |
fprintf (fcue, "TRACK 1 MODE1/2352\n"); |
169 |
fprintf (fcue, "TRACK 1 MODE1/2352\n"); |
167 |
fprintf (fcue, "INDEX 1 00:00:00\n"); |
170 |
fprintf (fcue, "INDEX 1 00:00:00\n"); |
168 |
rename (destfilename, destfilebin); |
171 |
rename (destfilename, destfilebin); |
169 |
printf ("Create Cuesheets : %s\n", destfilecue); |
172 |
printf ("Create Cuesheets : %s\n", destfilecue); |
170 |
fclose (fcue); |
173 |
fclose (fcue); |
|
|
174 |
} |
175 |
else |
176 |
{ |
177 |
printf ("Error opening %s for output: %s\n",destfilecue,strerror(errno)); |
178 |
ret=-1; |
179 |
} |
180 |
return ret; |
171 |
} |
181 |
} |
172 |
|
182 |
|
173 |
void |
183 |
int previous_percent=-1; |
174 |
main_percent (int percent_bar) |
184 |
void main_percent (int percent_bar) |
|
|
185 |
// Prints a progress bar, takes a percentage as argument. |
175 |
{ |
186 |
{ |
176 |
int progress_bar, progress_space; |
187 |
//int progress_bar, progress_space; |
|
|
188 |
|
189 |
if (percent_bar==previous_percent) return; // Nothing changed, don't waste CPU cycles. |
190 |
|
191 |
printf("%3d%% [:%.*s>%.*s:]\r",percent_bar,20-(percent_bar/5)," ", |
192 |
percent_bar/5,"===================="); |
193 |
/* |
177 |
printf ("%d%% [:", percent_bar); |
194 |
printf ("%d%% [:", percent_bar); |
178 |
for (progress_bar = 1; progress_bar <= (int) (percent_bar / 5); |
195 |
for (progress_bar = 1; progress_bar <= (int) (percent_bar / 5); progress_bar++) |
179 |
progress_bar++) |
|
|
180 |
printf ("="); |
196 |
printf ("="); |
181 |
printf (">"); |
197 |
printf (">"); |
182 |
|
198 |
|
183 |
for (progress_space = 0; progress_space < (20 - progress_bar); |
199 |
for (; progress_bar <= 20; ++progress_bar) printf (" "); |
184 |
progress_space++) |
|
|
185 |
printf (" "); |
186 |
printf (":]\r"); |
200 |
printf (":]\r"); |
|
|
201 |
*/ |
187 |
} |
202 |
} |
188 |
|
203 |
|
189 |
void |
204 |
void usage () |
190 |
usage () |
205 |
// Prints the command line syntax |
191 |
{ |
206 |
{ |
192 |
printf ("mdf2iso v%s by Salvatore Santagati\n", VERSION); |
207 |
printf (" Web : http//mdf2iso.berlios.de\n"); |
193 |
printf ("Web : http//mdf2iso.berlios.de\n"); |
208 |
printf (" Email : salvatore.santagati@gmail.com\n"); |
194 |
printf ("Email : salvatore.santagati@gmail.com\n"); |
209 |
printf (" Irc : irc.freenode.net #ignus\n"); |
195 |
printf ("Irc : irc.freenode.net #ignus\n"); |
210 |
printf (" Note : iodellavitanonhocapitouncazzo\n\n"); |
196 |
printf ("Note : iodellavitanonhocapitouncazzo\n"); |
|
|
197 |
printf ("License : released under the GNU GPL v2 or later\n\n"); |
198 |
printf ("Usage :\n"); |
211 |
printf ("Usage :\n"); |
199 |
printf ("mdf2iso [OPTION] [BASENAME.MDF] [DESTINATION]\n\n"); |
212 |
printf ("mdf2iso [--cue|--toc|--help] <sourcefile> [destfile]\n\n"); |
200 |
printf ("OPTION\n"); |
213 |
printf ("Options:\n"); |
201 |
printf ("\t--toc Generate toc file\n"); |
214 |
printf (" --toc Generate toc/dat files\n"); |
202 |
printf ("\t--cue Generate cue file\n"); |
215 |
printf (" --cue Generate cue/bin files\n"); |
203 |
printf ("\t--help display this notice\n\n"); |
216 |
printf (" --help Display this notice\n"); |
|
|
217 |
printf (" sourcefile\tFilename of the .mdf file to be converted\n"); |
218 |
printf (" destfile\tFilename of the target ISO9660 file.\n"\ |
219 |
"\t\tIf none given, one is derived from sourcefile.\n\n"); |
204 |
} |
220 |
} |
205 |
|
221 |
|
206 |
int |
222 |
char mdftype(FILE *f) |
207 |
main (int argc, char **argv) |
223 |
/* returns |
|
|
224 |
-1 for unknown |
225 |
0 for ISO9660 |
226 |
1 for SYNC |
227 |
2 for SYNC MDF |
228 |
3 for MDF Audio |
229 |
(see #defines above) |
230 |
*/ |
208 |
{ |
231 |
{ |
209 |
int seek_ecc, sector_size, seek_head, sector_data, n_mdf; |
232 |
char buf[12]; |
|
|
233 |
|
234 |
fseek(f, 32768, SEEK_SET); |
235 |
fread(buf, sizeof (char), 8, f); |
236 |
if (!memcmp (ISO_9660, buf, 8)) return ISO9660; // File is ISO9660 |
237 |
|
238 |
fseek(f, 0L, SEEK_SET); |
239 |
fread(buf, sizeof (char), 12, f); |
240 |
|
241 |
fseek (f, 2352, SEEK_SET); |
242 |
|
243 |
if (!memcmp (SYNC_HEADER, buf, 12)) // Has SYNC_HEADER |
244 |
{ |
245 |
fread (buf, sizeof (char), 12, f); |
246 |
if (!memcmp (SYNC_HEADER_MDF, buf, 12)) return SYNC_MDF; // File is SYNC MDF |
247 |
if (!memcmp (SYNC_HEADER, buf, 12)) return SYNC; // File is SYNC |
248 |
} |
249 |
else // Does not have SYNC_HEADER |
250 |
{ |
251 |
fread(buf, sizeof (char), 12, f); |
252 |
if (!memcmp (SYNC_HEADER_MDF_AUDIO, buf, 12)) return MDF_AUDIO; // File is MDF Audio |
253 |
} |
254 |
|
255 |
// Reached a point where nothing else matters. |
256 |
return UNKNOWN; // Unknown format |
257 |
} |
258 |
|
259 |
|
260 |
// === Main program code === |
261 |
|
262 |
int main (int argc, char **argv) |
263 |
{ |
264 |
int seek_ecc, sector_size, seek_head, sector_data;//, n_mdf; |
210 |
int cue = 0, cue_mode = 0, sub = 1, toc = 0, sub_toc = 0; |
265 |
int cue = 0, cue_mode = 0, sub = 1, toc = 0, sub_toc = 0; |
211 |
int opts = 0; |
266 |
int opts = 0; |
212 |
double size_iso, write_iso; |
267 |
long i, source_length; |
213 |
long percent = 0; |
268 |
char buf[2448]; |
214 |
long i, source_length, progressbar; |
269 |
char *destfilename=NULL; |
215 |
char buf[2448], destfilename[2354]; |
270 |
char *basefilename=NULL; |
216 |
FILE *fdest, *fsource; |
271 |
FILE *fdest, *fsource; |
217 |
|
272 |
|
|
|
273 |
// Print identification |
274 |
printf ("mdf2iso v%s by Salvatore Santagati\n", VERSION); |
275 |
printf ("Licensed under GPL v2 or later\n"); |
218 |
|
276 |
|
219 |
if (argc < 2) |
|
|
220 |
|
277 |
|
|
|
278 |
// *** Process command line options *** |
279 |
|
280 |
if (argc < 2) |
221 |
{ |
281 |
{ |
222 |
usage (); |
282 |
// Not enough parameters; print help |
223 |
exit (EXIT_FAILURE); |
283 |
usage(); |
|
|
284 |
exit(EXIT_FAILURE); |
224 |
} |
285 |
} |
225 |
|
286 |
|
226 |
else |
287 |
// Search for options --cue and --toc |
227 |
|
|
|
228 |
{ |
229 |
for (i = 0; i < argc; i++) |
288 |
for (i = 0; i < argc; i++) |
230 |
|
|
|
231 |
{ |
289 |
{ |
232 |
|
|
|
233 |
if (!strcmp (argv[i], "--help")) |
290 |
if (!strcmp (argv[i], "--help")) |
234 |
|
|
|
235 |
{ |
291 |
{ |
236 |
usage (); |
292 |
usage (); |
237 |
exit (EXIT_SUCCESS); |
293 |
exit (EXIT_SUCCESS); |
238 |
} |
294 |
} |
239 |
if (!strcmp (argv[i], "--cue")) |
295 |
if (!strcmp (argv[i], "--cue")) |
240 |
|
|
|
241 |
{ |
296 |
{ |
242 |
cue = 1; |
297 |
cue = 1; |
243 |
opts++; |
298 |
opts++; |
244 |
} |
299 |
} |
245 |
if (!strcmp (argv[i], "--toc")) |
300 |
if (!strcmp (argv[i], "--toc")) |
246 |
|
|
|
247 |
{ |
301 |
{ |
248 |
toc = 1; |
302 |
toc = 1; |
249 |
opts++; |
303 |
opts++; |
250 |
} |
304 |
} |
251 |
} |
305 |
} |
252 |
|
306 |
|
253 |
if ((cue == 1) && (toc == 1)) |
307 |
// Catch impossible parameter combinations |
254 |
|
308 |
if (((cue == 1) && (toc == 1)) || |
255 |
{ |
309 |
((opts == 1) && (argc <= 2))) |
256 |
usage (); |
|
|
257 |
exit (EXIT_FAILURE); |
258 |
} |
259 |
if ((opts == 1) && (argc <= 2)) |
260 |
|
261 |
{ |
310 |
{ |
262 |
usage (); |
311 |
usage(); |
263 |
exit (EXIT_FAILURE); |
312 |
exit(EXIT_FAILURE); |
264 |
} |
313 |
} |
265 |
|
314 |
|
|
|
315 |
// Get the base filename |
316 |
basefilename=argv[1+opts]; // simple pointer, but makes life easier. |
266 |
|
317 |
|
|
|
318 |
// Get the destination filename |
267 |
if (argc >= (3 + opts)) |
319 |
if (argc >= (3 + opts)) |
268 |
strcpy (destfilename, argv[2 + opts]); |
320 |
// The destination filename is explicitly entered at the prompt |
269 |
|
321 |
destfilename=strdup(argv[2 + opts]); |
270 |
else |
|
|
271 |
|
272 |
{ |
273 |
strcpy (destfilename, argv[1 + opts]); |
274 |
if (strlen (argv[1 + cue]) < 5 |
275 |
|| strcmp (destfilename + strlen (argv[1 + opts]) - 4, ".mdf")) |
276 |
strcpy (destfilename + strlen (argv[1 + opts]), ".iso"); |
277 |
|
278 |
else |
322 |
else |
279 |
strcpy (destfilename + strlen (argv[1 + opts]) - 4, ".iso"); |
|
|
280 |
} |
281 |
if ((fsource = fopen (argv[1 + opts], "rb")) != NULL) |
282 |
|
283 |
{ |
323 |
{ |
284 |
fseek (fsource, 32768, SEEK_CUR); |
324 |
// Derive destination filename from the basename: |
285 |
fread (buf, sizeof (char), 8, fsource); |
325 |
// If basename is "*.mdf" use "*.iso" als destname |
286 |
if (memcmp (ISO_9660, buf, 8)) |
326 |
// otherwise simply append ".iso" to the basename to create destname. |
287 |
|
327 |
destfilename=strdup(basefilename); |
|
|
328 |
i=strlen(destfilename); // Reusing 'i' here as temporary variable |
329 |
if (i < 5 || strcmp(destfilename + i - 4, ".mdf")) |
288 |
{ |
330 |
{ |
289 |
fseek (fsource, 0L, SEEK_SET); |
331 |
destfilename=realloc(destfilename,i+5); |
290 |
fread (buf, sizeof (char), 12, fsource); |
332 |
strcat(destfilename, ".iso"); |
291 |
if (!memcmp (SYNC_HEADER, buf, 12)) |
|
|
292 |
|
293 |
{ |
294 |
fseek (fsource, 0L, SEEK_SET); |
295 |
fseek (fsource, 2352, SEEK_CUR); |
296 |
fread (buf, sizeof (char), 12, fsource); |
297 |
if (!memcmp (SYNC_HEADER_MDF, buf, 12)) |
298 |
|
299 |
{ |
300 |
if (cue == 1) |
301 |
{ |
302 |
cue_mode = 1; |
303 |
|
304 |
/* BAD SECTOR TO NORMAL IMAGE */ |
305 |
seek_ecc = 96; |
306 |
sector_size = 2448; |
307 |
sector_data = 2352; |
308 |
seek_head = 0; |
309 |
} |
310 |
|
311 |
else if (toc == 0) |
312 |
|
313 |
{ |
314 |
|
315 |
/*BAD SECTOR */ |
316 |
seek_ecc = 384; |
317 |
sector_size = 2448; |
318 |
sector_data = 2048; |
319 |
seek_head = 16; |
320 |
} |
333 |
} |
321 |
|
|
|
322 |
else |
334 |
else |
323 |
|
335 |
strcpy(destfilename + i - 3, "iso"); |
324 |
{ |
|
|
325 |
|
326 |
/*BAD SECTOR */ |
327 |
seek_ecc = 0; |
328 |
sector_size = 2448; |
329 |
sector_data = 2448; |
330 |
seek_head = 0; |
331 |
sub_toc = 1; |
332 |
} |
333 |
} |
336 |
} |
334 |
|
337 |
|
335 |
else |
338 |
// *** Preprocess basefile *** |
336 |
|
339 |
|
|
|
340 |
// Try opening basefile |
341 |
if ((fsource = fopen(basefilename, "rb")) == NULL) |
337 |
{ |
342 |
{ |
338 |
if (!memcmp (SYNC_HEADER, buf, 12)) |
343 |
free(destfilename); |
|
|
344 |
printf ("Could not open %s: %s\n", basefilename, strerror(errno)); |
345 |
exit (EXIT_FAILURE); |
346 |
} |
339 |
|
347 |
|
|
|
348 |
// Determine filetype & set some stuff accordingly (or exit) |
349 |
switch (mdftype(fsource)) |
340 |
{ |
350 |
{ |
|
|
351 |
case ISO9660: |
352 |
printf("%s is already ISO9660.\n",basefilename); |
353 |
fclose(fsource); |
354 |
free(destfilename); |
355 |
exit(EXIT_SUCCESS); |
356 |
case SYNC: |
341 |
if (cue == 1) |
357 |
if (cue == 1) |
342 |
{ |
358 |
{ |
343 |
cue_mode = 1; |
359 |
cue_mode = 1; |
Lines 348-476
Link Here
|
348 |
seek_head = 0; |
364 |
seek_head = 0; |
349 |
} |
365 |
} |
350 |
if (toc == 0) |
366 |
if (toc == 0) |
351 |
|
|
|
352 |
{ |
367 |
{ |
353 |
|
|
|
354 |
/*NORMAL IMAGE */ |
368 |
/*NORMAL IMAGE */ |
355 |
seek_ecc = 288; |
369 |
seek_ecc = 288; |
356 |
sector_size = 2352; |
370 |
sector_size = 2352; |
357 |
sector_data = 2048; |
371 |
sector_data = 2048; |
358 |
seek_head = 16; |
372 |
seek_head = 16; |
359 |
} |
373 |
} |
360 |
|
|
|
361 |
else |
374 |
else |
362 |
|
|
|
363 |
{ |
375 |
{ |
364 |
seek_ecc = 0; |
376 |
seek_ecc = 0; |
365 |
sector_size = 2352; |
377 |
sector_size = 2352; |
366 |
sector_data = 2352; |
378 |
sector_data = 2352; |
367 |
seek_head = 0; |
379 |
seek_head = 0; |
368 |
} |
380 |
} |
369 |
} |
381 |
break; |
370 |
|
382 |
case SYNC_MDF: |
371 |
else |
383 |
if (cue == 1) |
372 |
|
|
|
373 |
{ |
374 |
printf ("Sorry I don't know this format :(\n"); |
375 |
exit (EXIT_FAILURE); |
376 |
} |
377 |
} |
378 |
} |
379 |
|
380 |
else |
381 |
|
382 |
{ |
384 |
{ |
383 |
fseek (fsource, 0L, SEEK_SET); |
385 |
cue_mode = 1; |
384 |
fseek (fsource, 2352, SEEK_CUR); |
|
|
385 |
fread (buf, sizeof (char), 12, fsource); |
386 |
if (memcmp (SYNC_HEADER_MDF_AUDIO, buf, 12)) |
387 |
|
386 |
|
|
|
387 |
/* BAD SECTOR TO NORMAL IMAGE */ |
388 |
seek_ecc = 96; |
389 |
sector_size = 2448; |
390 |
sector_data = 2352; |
391 |
seek_head = 0; |
392 |
} |
393 |
else if (toc == 0) |
388 |
{ |
394 |
{ |
389 |
printf ("Sorry I don't know this format :(\n"); |
395 |
/*BAD SECTOR */ |
390 |
exit (EXIT_FAILURE); |
396 |
seek_ecc = 384; |
|
|
397 |
sector_size = 2448; |
398 |
sector_data = 2048; |
399 |
seek_head = 16; |
391 |
} |
400 |
} |
392 |
|
|
|
393 |
else |
401 |
else |
394 |
|
|
|
395 |
{ |
402 |
{ |
396 |
|
403 |
/*BAD SECTOR */ |
|
|
404 |
seek_ecc = 0; |
405 |
sector_size = 2448; |
406 |
sector_data = 2448; |
407 |
seek_head = 0; |
408 |
sub_toc = 1; |
409 |
} |
410 |
break; |
411 |
case MDF_AUDIO: |
397 |
/*BAD SECTOR AUDIO */ |
412 |
/*BAD SECTOR AUDIO */ |
398 |
seek_head = 0; |
413 |
seek_head = 0; |
399 |
sector_size = 2448; |
414 |
sector_size = 2448; |
400 |
seek_ecc = 96; |
415 |
seek_ecc = 96; |
401 |
sector_data = 2352; |
416 |
sector_data = 2352; |
402 |
cue = 0; |
417 |
cue = 0; |
|
|
418 |
break; |
419 |
default:printf("Unknown format for %s.\n",basefilename); |
420 |
fclose(fsource); |
421 |
free(destfilename); |
422 |
exit (EXIT_FAILURE); |
403 |
} |
423 |
} |
404 |
} |
|
|
405 |
if ((fdest = fopen (destfilename, "wb")) != NULL); |
406 |
|
424 |
|
407 |
else |
425 |
// *** Create destination file *** |
|
|
426 |
|
427 |
// Try opening the destination file for output |
428 |
if ((fdest = fopen (destfilename, "wb")) == NULL) |
408 |
{ |
429 |
{ |
409 |
printf ("%s\n", strerror (errno)); |
430 |
printf ("Unable to open %s for output: %s\n",destfilename,strerror(errno)); |
|
|
431 |
free(destfilename); |
432 |
fclose(fsource); |
410 |
exit (EXIT_FAILURE); |
433 |
exit (EXIT_FAILURE); |
411 |
}; |
434 |
} |
|
|
435 |
|
436 |
|
412 |
fseek (fsource, 0L, SEEK_END); |
437 |
fseek (fsource, 0L, SEEK_END); |
413 |
source_length = ftell (fsource) / sector_size; |
438 |
source_length = ftell (fsource) / sector_size; |
414 |
size_iso = (int) (source_length * sector_data); |
|
|
415 |
progressbar = 100 / source_length; |
416 |
fseek (fsource, 0L, SEEK_SET); |
439 |
fseek (fsource, 0L, SEEK_SET); |
417 |
|
|
|
418 |
{ |
440 |
{ |
419 |
for (i = 0; i < source_length; i++) |
441 |
for (i = 0; i < source_length; i++) |
420 |
|
|
|
421 |
{ |
442 |
{ |
422 |
fseek (fsource, seek_head, SEEK_CUR); |
443 |
fseek (fsource, seek_head, SEEK_CUR); |
423 |
if (fread (buf, sizeof (char), sector_data, fsource)); |
444 |
if (fread(buf, sizeof (char), sector_data, fsource)!=sector_data) |
424 |
|
|
|
425 |
else |
426 |
{ |
445 |
{ |
427 |
printf ("%s\n", strerror (errno)); |
446 |
printf ("Error reading from %s: %s\n",basefilename, strerror (errno)); |
|
|
447 |
fclose(fsource); |
448 |
fclose(fdest); |
449 |
remove(destfilename); |
450 |
free(destfilename); |
428 |
exit (EXIT_FAILURE); |
451 |
exit (EXIT_FAILURE); |
429 |
}; |
452 |
} |
430 |
if (fwrite (buf, sizeof (char), sector_data, fdest)); |
453 |
if (fwrite (buf, sizeof (char), sector_data, fdest)!=sector_data) |
431 |
|
|
|
432 |
else |
433 |
{ |
454 |
{ |
434 |
printf ("%s\n", strerror (errno)); |
455 |
printf ("Error writing to %s: %s\n",destfilename, strerror (errno)); |
|
|
456 |
fclose(fsource); |
457 |
fclose(fdest); |
458 |
remove(destfilename); |
459 |
free(destfilename); |
435 |
exit (EXIT_FAILURE); |
460 |
exit (EXIT_FAILURE); |
436 |
}; |
461 |
} |
437 |
fseek (fsource, seek_ecc, SEEK_CUR); |
462 |
fseek (fsource, seek_ecc, SEEK_CUR); |
438 |
write_iso = (int) (sector_data * i); |
463 |
main_percent(i*100/source_length); |
439 |
if (i != 0) |
464 |
} |
440 |
percent = (int) (write_iso * 100 / size_iso); |
465 |
} printf ("100%% [:=====================:]\n"); |
441 |
main_percent (percent); |
|
|
442 |
}} printf ("100%%[:====================:]\n"); |
443 |
|
466 |
|
444 |
fclose (fsource); |
467 |
fclose (fsource); |
445 |
fclose (fdest); |
468 |
fclose (fdest); |
446 |
|
469 |
|
447 |
if (cue == 1) |
470 |
// *** create Toc or Cue file is requested *** |
448 |
cuesheets (destfilename); |
471 |
if (cue == 1) if (cuesheets(destfilename)) |
449 |
if (toc == 1) |
472 |
{ |
450 |
toc_file (destfilename, sub_toc); |
473 |
free(destfilename); |
|
|
474 |
exit(EXIT_FAILURE); |
475 |
} |
476 |
if (toc == 1) if (toc_file(destfilename, sub_toc)) |
477 |
{ |
478 |
free(destfilename); |
479 |
exit(EXIT_FAILURE); |
480 |
} |
451 |
if ((toc == 0) && (cue == 0)) |
481 |
if ((toc == 0) && (cue == 0)) |
452 |
printf ("Create iso9660: %s\n", destfilename); |
482 |
printf("Created iso9660: %s\n", destfilename); |
|
|
483 |
|
484 |
free(destfilename); |
453 |
|
485 |
|
454 |
exit (EXIT_SUCCESS); |
486 |
exit (EXIT_SUCCESS); |
455 |
} |
|
|
456 |
|
487 |
|
457 |
else |
488 |
/* |
458 |
printf ("This is file iso9660 ;)\n"); |
|
|
459 |
n_mdf = number_file (destfilename) - 1; |
489 |
n_mdf = number_file (destfilename) - 1; |
460 |
/* if (n_mdf > 1) |
490 |
/ * if (n_mdf > 1) |
461 |
|
|
|
462 |
{ |
491 |
{ |
463 |
printf ("\rDetect %d md* file and now emerge this\n", n_mdf); |
492 |
printf ("\rDetect %d md* file and now emerge this\n", n_mdf); |
464 |
} |
493 |
} |
465 |
*/ |
494 |
* / |
466 |
fclose (fsource); |
495 |
fclose (fsource); |
467 |
exit (EXIT_SUCCESS); |
496 |
exit (EXIT_SUCCESS);*/ |
468 |
} |
|
|
469 |
|
470 |
else |
471 |
{ |
472 |
printf ("%s\n", strerror (errno)); |
473 |
exit (EXIT_FAILURE); |
474 |
}; |
475 |
} |
476 |
} |
497 |
} |