/[pcsx2_0.9.7]/branch/debug/0.X/0.9.X/0.9.7/r3113/plugins/CDVDiso/src/Linux/Linux.cpp
ViewVC logotype

Contents of /branch/debug/0.X/0.9.X/0.9.7/r3113/plugins/CDVDiso/src/Linux/Linux.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 59 - (show annotations) (download)
Tue Sep 7 06:17:51 2010 UTC (10 years, 7 months ago) by william
File size: 13809 byte(s)
create working branch for pcsx2-0.9.7-r3113-debug
1 /* CDVDiso
2 * Copyright (C) 2002-2004 CDVDiso Team
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 #include "Config.h"
20
21 unsigned char Zbuf[CD_FRAMESIZE_RAW * 10 * 2];
22
23 GtkWidget *Method,*Progress;
24 GtkWidget *BtnCompress, *BtnDecompress;
25 GtkWidget *BtnCreate, *BtnCreateZ;
26
27 GList *methodlist;
28 extern char *methods[];
29 unsigned char param[4];
30 int cddev = -1;
31 bool stop;
32
33 #define CD_LEADOUT (0xaa)
34
35 union
36 {
37 struct cdrom_msf msf;
38 unsigned char buf[CD_FRAMESIZE_RAW];
39 } cr;
40
41 void OnStop(GtkButton *button, gpointer user_data)
42 {
43 stop = true;
44 }
45
46 void UpdZmode()
47 {
48 char *tmp;
49
50 tmp = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(Method)->entry));
51 if (!strcmp(tmp, methods[0])) Zmode = 1;
52 else Zmode = 2;
53 }
54
55 char buffer[2352 * 10];
56
57 void OnCompress(GtkButton *button, gpointer user_data)
58 {
59 struct stat buf;
60 u32 lsn;
61 u8 cdbuff[10*2352];
62 char Zfile[256];
63 char *tmp;
64 int ret;
65 isoFile *src;
66 isoFile *dst;
67
68 tmp = gtk_entry_get_text(GTK_ENTRY(Edit));
69 strcpy(IsoFile, tmp);
70 UpdZmode();
71
72 if (Zmode == 1) sprintf(Zfile, "%s.Z2", IsoFile);
73 if (Zmode == 2) sprintf(Zfile, "%s.BZ2", IsoFile);
74
75 if (stat(Zfile, &buf) != -1)
76 {
77 /*char str[256];*/
78 return;
79 /* sprintf(str, "'%s' already exists, overwrite?", Zfile);
80 if (MessageBox(hDlg, str, "Question", MB_YESNO) != IDYES) {
81 return;
82 }*/
83 }
84
85 src = isoOpen(IsoFile);
86 if (src == NULL) return;
87 dst = isoCreate(Zfile, Zmode == 1 ? ISOFLAGS_Z2 : ISOFLAGS_BZ2);
88 if (dst == NULL) return;
89
90 gtk_widget_set_sensitive(BtnCompress, FALSE);
91 gtk_widget_set_sensitive(BtnDecompress, FALSE);
92 gtk_widget_set_sensitive(BtnCreate, FALSE);
93 gtk_widget_set_sensitive(BtnCreateZ, FALSE);
94 stop = false;
95
96 for (lsn = 0; lsn < src->blocks; lsn++)
97 {
98 printf("block %d ", lsn);
99 putchar(13);
100 fflush(stdout);
101 ret = isoReadBlock(src, cdbuff, lsn);
102 if (ret == -1) break;
103 ret = isoWriteBlock(dst, cdbuff, lsn);
104 if (ret == -1) break;
105
106 gtk_progress_bar_update(GTK_PROGRESS_BAR(Progress), (lsn * 100) / src->blocks);
107 while (gtk_events_pending()) gtk_main_iteration();
108 if (stop) break;
109 }
110 isoClose(src);
111 isoClose(dst);
112
113 if (!stop) gtk_entry_set_text(GTK_ENTRY(Edit), IsoFile);
114
115 gtk_widget_set_sensitive(BtnCompress, TRUE);
116 gtk_widget_set_sensitive(BtnDecompress, TRUE);
117 gtk_widget_set_sensitive(BtnCreate, TRUE);
118 gtk_widget_set_sensitive(BtnCreateZ, TRUE);
119
120 if (!stop)
121 {
122 if (ret == -1)
123 {
124 SysMessageLoc("Error compressing iso image");
125 }
126 else
127 {
128 SysMessageLoc("Iso image compressed OK");
129 }
130 }
131 }
132
133 void OnDecompress(GtkButton *button, gpointer user_data)
134 {
135 #if 0
136 struct stat buf;
137 FILE *f;
138 unsigned long c = 0, p = 0, s;
139 char table[256];
140 char *tmp;
141 int blocks;
142
143 tmp = gtk_entry_get_text(GTK_ENTRY(Edit));
144 strcpy(IsoFile, tmp);
145
146 if (strstr(IsoFile, ".Z") != NULL) Zmode = 1;
147 else Zmode = 2;
148
149 strcpy(table, IsoFile);
150 if (Zmode == 1) strcat(table, ".table");
151 else strcat(table, ".index");
152
153 if (stat(table, &buf) == -1)
154 {
155 return;
156 }
157
158 if (Zmode == 1)
159 c = s = buf.st_size / 6;
160 else
161 c = s = (buf.st_size / 4) - 1;
162
163 f = fopen(table, "rb");
164 Ztable = (char*)malloc(buf.st_size);
165 fread(Ztable, 1, buf.st_size, f);
166 fclose(f);
167
168 cdHandle[0] = fopen(IsoFile, "rb");
169 if (cdHandle[0] == NULL)
170 {
171 return;
172 }
173
174 if (Zmode == 1)
175 IsoFile[strlen(IsoFile) - 2] = 0;
176 else
177 IsoFile[strlen(IsoFile) - 3] = 0;
178
179 f = fopen(IsoFile, "wb");
180 if (f == NULL)
181 {
182 return;
183 }
184
185 gtk_widget_set_sensitive(BtnCompress, FALSE);
186 gtk_widget_set_sensitive(BtnDecompress, FALSE);
187 gtk_widget_set_sensitive(BtnCreate, FALSE);
188 gtk_widget_set_sensitive(BtnCreateZ, FALSE);
189 stop = false;
190
191 if (Zmode == 1)
192 {
193 blocks = 1;
194 }
195 else
196 {
197 blocks = 10;
198 }
199
200 while (c--)
201 {
202 unsigned long size, pos, ssize;
203 float per;
204
205 if (Zmode == 1)
206 {
207 pos = *(unsigned long*) & Ztable[p * 6];
208 fseek(cdHandle[0], pos, SEEK_SET);
209
210 ssize = *(unsigned short*) & Ztable[p * 6 + 4];
211 fread(Zbuf, 1, ssize, cdHandle[0]);
212 }
213 else
214 {
215 pos = *(unsigned long*) & Ztable[p * 4];
216 fseek(cdHandle[0], pos, SEEK_SET);
217
218 ssize = *(unsigned long*) & Ztable[p * 4 + 4] - pos;
219 fread(Zbuf, 1, ssize, cdHandle[0]);
220 }
221
222 size = CD_FRAMESIZE_RAW * blocks;
223 if (Zmode == 1)
224 uncompress(cdbuffer, &size, Zbuf, ssize);
225 else
226 BZ2_bzBuffToBuffDecompress(cdbuffer, (unsigned int*)&size, Zbuf, ssize, 0, 0);
227
228 fwrite(cdbuffer, 1, size, f);
229
230 p++;
231
232 per = ((float)p / s);
233
234 gtk_progress_bar_update(GTK_PROGRESS_BAR(Progress), per);
235 while (gtk_events_pending()) gtk_main_iteration();
236
237 if (stop) break;
238 }
239 if (!stop) gtk_entry_set_text(GTK_ENTRY(Edit), IsoFile);
240
241 fclose(f);
242 fclose(cdHandle[0]);
243 cdHandle[0] = NULL;
244 free(Ztable);
245 Ztable = NULL;
246
247 gtk_widget_set_sensitive(BtnCompress, TRUE);
248 gtk_widget_set_sensitive(BtnDecompress, TRUE);
249 gtk_widget_set_sensitive(BtnCreate, TRUE);
250 gtk_widget_set_sensitive(BtnCreateZ, TRUE);
251
252 if (!stop) SysMessageLoc("Iso Image Decompressed OK");
253 #endif
254 }
255
256 void incSector()
257 {
258 param[2]++;
259 if (param[2] == 75)
260 {
261 param[2] = 0;
262 param[1]++;
263 }
264 if (param[1] == 60)
265 {
266 param[1] = 0;
267 param[0]++;
268 }
269 }
270
271 long CDR_open(void)
272 {
273 if (cddev != -1)
274 return 0;
275 cddev = open(CdDev, O_RDONLY);
276 if (cddev == -1)
277 {
278 printf("CDR: Could not open %s\n", CdDev);
279 return -1;
280 }
281
282 return 0;
283 }
284
285 long CDR_close(void)
286 {
287 if (cddev == -1) return 0;
288 close(cddev);
289 cddev = -1;
290
291 return 0;
292 }
293
294 // return Starting and Ending Track
295 // buffer:
296 // byte 0 - start track
297 // byte 1 - end track
298 long CDR_getTN(unsigned char *buffer)
299 {
300 struct cdrom_tochdr toc;
301
302 if (ioctl(cddev, CDROMREADTOCHDR, &toc) == -1) return -1;
303
304 buffer[0] = toc.cdth_trk0; // start track
305 buffer[1] = toc.cdth_trk1; // end track
306
307 return 0;
308 }
309
310 // return Track Time
311 // buffer:
312 // byte 0 - frame
313 // byte 1 - second
314 // byte 2 - minute
315 long CDR_getTD(unsigned char track, unsigned char *buffer)
316 {
317 struct cdrom_tocentry entry;
318
319 if (track == 0) track = 0xaa; // total time
320 entry.cdte_track = track;
321 entry.cdte_format = CDROM_MSF;
322
323 if (ioctl(cddev, CDROMREADTOCENTRY, &entry) == -1) return -1;
324
325 buffer[0] = entry.cdte_addr.msf.minute; /* minute */
326 buffer[1] = entry.cdte_addr.msf.second; /* second */
327 buffer[2] = entry.cdte_addr.msf.frame; /* frame */
328
329 return 0;
330 }
331
332 // read track
333 // time:
334 // byte 0 - minute
335 // byte 1 - second
336 // byte 2 - frame
337 char *CDR_readTrack(unsigned char *time)
338 {
339 cr.msf.cdmsf_min0 = time[0];
340 cr.msf.cdmsf_sec0 = time[1];
341 cr.msf.cdmsf_frame0 = time[2];
342
343 if (ioctl(cddev, CDROMREADRAW, &cr) == -1) return NULL;
344 return cr.buf;
345 }
346
347
348 void OnCreate(GtkButton *button, gpointer user_data)
349 {
350 FILE *f;
351 struct stat buf;
352 struct tm *Tm;
353 time_t Ttime;
354 unsigned long ftrack, ltrack;
355 unsigned long p = 0, s;
356 unsigned char *buffer;
357 unsigned char bufferz[2352];
358 unsigned char start[4], end[4];
359 char *tmp;
360 #ifdef VERBOSE
361 unsigned long count = 0;
362 int i = 0;
363 #endif
364
365 memset(bufferz, 0, sizeof(bufferz));
366 ftrack = 1;
367 ltrack = CD_LEADOUT;
368
369 tmp = gtk_entry_get_text(GTK_ENTRY(Edit));
370 strcpy(IsoFile, tmp);
371
372 if (stat(IsoFile, &buf) == 0)
373 {
374 printf("File %s Already exists\n", IsoFile);
375 return;
376 }
377
378 if (CDR_open() == -1)
379 {
380 return;
381 }
382
383 if (CDR_getTD(ftrack, start) == -1)
384 {
385 printf("Error getting TD\n");
386
387 CDR_close();
388 return;
389 }
390 if (CDR_getTD(ltrack, end) == -1)
391 {
392 printf("Error getting TD\n");
393
394 CDR_close();
395 return;
396 }
397
398 f = fopen(IsoFile, "wb");
399 if (f == NULL)
400 {
401 CDR_close();
402 printf("Error opening %s", IsoFile);
403 return;
404 }
405
406 printf("Making Iso: from %2.2d:%2.2d:%2.2d to %2.2d:%2.2d:%2.2d\n",
407 start[0], start[1], start[2], end[0], end[1], end[2]);
408
409 memcpy(param, start, 3);
410
411 time(&Ttime);
412
413 stop = false;
414 s = MSF2SECT(end[0], end[1], end[2]);
415 gtk_widget_set_sensitive(BtnCompress, FALSE);
416 gtk_widget_set_sensitive(BtnDecompress, FALSE);
417 gtk_widget_set_sensitive(BtnCreate, FALSE);
418 gtk_widget_set_sensitive(BtnCreateZ, FALSE);
419
420 for (;;) /* loop until end */
421 {
422 float per;
423
424 if ((param[0] == end[0]) & (param[1] == end[1]) & (param[2] == end[2]))
425 break;
426 buffer = CDR_readTrack(param);
427 if (buffer == NULL)
428 {
429 int i;
430
431 for (i = 0; i < 10; i++)
432 {
433 buffer = CDR_readTrack(param);
434 if (buffer != NULL) break;
435 }
436 if (buffer == NULL)
437 {
438 printf("Error Reading %2d:%2d:%2d\n", param[0], param[1], param[2]);
439 buffer = bufferz;
440 buffer[12] = param[0];
441 buffer[13] = param[1];
442 buffer[14] = param[2];
443 buffer[15] = 0x2;
444 }
445 }
446 fwrite(buffer, 1, 2352, f);
447 #ifdef VERBOSE
448 count += CD_FRAMESIZE_RAW;
449
450 printf("reading %2d:%2d:%2d ", param[0], param[1], param[2]);
451 if ((time(NULL) - Ttime) != 0)
452 {
453 i = (count / 1024) / (time(NULL) - Ttime);
454 printf("( %5dKbytes/s, %dX)", i, i / 150);
455 }
456 putchar(13);
457 fflush(stdout);
458 #endif
459
460 incSector();
461
462 p++;
463 per = ((float)p / s);
464 gtk_progress_bar_update(GTK_PROGRESS_BAR(Progress), per);
465 while (gtk_events_pending()) gtk_main_iteration();
466 if (stop) break;
467 }
468
469 Ttime = time(NULL) - Ttime;
470 Tm = gmtime(&Ttime);
471 printf("\nTotal Time used: %d:%d:%d\n", Tm->tm_hour, Tm->tm_min,
472 Tm->tm_sec);
473
474 CDR_close();
475 fclose(f);
476
477 gtk_widget_set_sensitive(BtnCompress, TRUE);
478 gtk_widget_set_sensitive(BtnDecompress, TRUE);
479 gtk_widget_set_sensitive(BtnCreate, TRUE);
480 gtk_widget_set_sensitive(BtnCreateZ, TRUE);
481
482 if (!stop) SysMessageLoc("Iso Image Created OK");
483 }
484
485 void OnCreateZ(GtkButton *button, gpointer user_data)
486 {
487 FILE *f;
488 FILE *t;
489 struct stat buf;
490 struct tm *Tm;
491 time_t Ttime;
492 unsigned long ftrack, ltrack;
493 unsigned long p = 0, s, c = 0;
494 unsigned char *buffer;
495 unsigned char bufferz[2352];
496 unsigned char start[4], end[4];
497 char table[256];
498 char *tmp;
499 int b, blocks;
500 #ifdef VERBOSE
501 unsigned long count = 0;
502 int i = 0;
503 #endif
504
505 memset(bufferz, 0, sizeof(bufferz));
506 ftrack = 1;
507 ltrack = CD_LEADOUT;
508
509 tmp = gtk_entry_get_text(GTK_ENTRY(Edit));
510 strcpy(IsoFile, tmp);
511
512 UpdZmode();
513
514 if (Zmode == 1)
515 {
516 blocks = 1;
517 if (strstr(IsoFile, ".Z") == NULL) strcat(IsoFile, ".Z");
518 }
519 else
520 {
521 blocks = 10;
522 if (strstr(IsoFile, ".bz") == NULL) strcat(IsoFile, ".bz");
523 }
524
525 if (stat(IsoFile, &buf) == 0)
526 {
527 printf("File %s Already exists\n", IsoFile);
528 return;
529 }
530
531 strcpy(table, IsoFile);
532 if (Zmode == 1)
533 strcat(table, ".table");
534 else
535 strcat(table, ".index");
536
537 t = fopen(table, "wb");
538
539 if (t == NULL) return;
540 if (CDR_open() == -1) return;
541
542 if (CDR_getTD(ftrack, start) == -1)
543 {
544 printf("Error getting TD\n");
545 CDR_close();
546 return;
547 }
548
549 if (CDR_getTD(ltrack, end) == -1)
550 {
551 printf("Error getting TD\n");
552 CDR_close();
553 return;
554 }
555
556 f = fopen(IsoFile, "wb");
557 if (f == NULL)
558 {
559 CDR_close();
560 printf("Error opening %s", IsoFile);
561 return;
562 }
563
564 printf("Making Iso: from %2.2d:%2.2d:%2.2d to %2.2d:%2.2d:%2.2d\n",
565 start[0], start[1], start[2], end[0], end[1], end[2]);
566
567 memcpy(param, start, 3);
568
569 time(&Ttime);
570
571 stop = false;
572 s = MSF2SECT(end[0], end[1], end[2]) / blocks;
573 gtk_widget_set_sensitive(BtnCompress, FALSE);
574 gtk_widget_set_sensitive(BtnDecompress, FALSE);
575 gtk_widget_set_sensitive(BtnCreate, FALSE);
576 gtk_widget_set_sensitive(BtnCreateZ, FALSE);
577
578 for (;;) /* loop until end */
579 {
580 unsigned long size;
581 unsigned char Zbuf[CD_FRAMESIZE_RAW * 10 * 2];
582 float per;
583
584 for (b = 0; b < blocks; b++)
585 {
586 if ((param[0] == end[0]) & (param[1] == end[1]) & (param[2] == end[2]))
587 break;
588
589 buffer = CDR_readTrack(param);
590 if (buffer == NULL)
591 {
592 int i;
593
594 for (i = 0; i < 10; i++)
595 {
596 buffer = CDR_readTrack(param);
597 if (buffer != NULL) break;
598 }
599
600 if (buffer == NULL)
601 {
602 printf("Error Reading %2d:%2d:%2d\n", param[0], param[1], param[2]);
603 buffer = bufferz;
604 buffer[12] = param[0];
605 buffer[13] = param[1];
606 buffer[14] = param[2];
607 buffer[15] = 0x2;
608 }
609 }
610 memcpy(cdbuffer + b * CD_FRAMESIZE_RAW, buffer, CD_FRAMESIZE_RAW);
611
612 incSector();
613 }
614 if ((param[0] == end[0]) & (param[1] == end[1]) & (param[2] == end[2]))
615 break;
616
617 size = CD_FRAMESIZE_RAW * blocks * 2;
618 if (Zmode == 1)
619 compress(Zbuf, &size, cdbuffer, CD_FRAMESIZE_RAW);
620 else
621 BZ2_bzBuffToBuffCompress(Zbuf, (unsigned int*)&size, cdbuffer, CD_FRAMESIZE_RAW * 10, 1, 0, 30);
622
623 fwrite(&c, 1, 4, t);
624 if (Zmode == 1) fwrite(&size, 1, 2, t);
625
626 fwrite(Zbuf, 1, size, f);
627
628 c += size;
629 #ifdef VERBOSE
630 count += CD_FRAMESIZE_RAW * blocks;
631
632 printf("reading %2d:%2d:%2d ", param[0], param[1], param[2]);
633 if ((time(NULL) - Ttime) != 0)
634 {
635 i = (count / 1024) / (time(NULL) - Ttime);
636 printf("( %5dKbytes/s, %dX)", i, i / 150);
637 }
638 putchar(13);
639 fflush(stdout);
640 #endif
641
642 p++;
643 per = ((float)p / s);
644
645 gtk_progress_bar_update(GTK_PROGRESS_BAR(Progress), per);
646 while (gtk_events_pending()) gtk_main_iteration();
647
648 if (stop) break;
649 }
650 if (Zmode == 2) fwrite(&c, 1, 4, f);
651
652 if (!stop) gtk_entry_set_text(GTK_ENTRY(Edit), IsoFile);
653
654 Ttime = time(NULL) - Ttime;
655 Tm = gmtime(&Ttime);
656 printf("\nTotal Time used: %d:%d:%d\n", Tm->tm_hour, Tm->tm_min,
657 Tm->tm_sec);
658
659 CDR_close();
660 fclose(f);
661 fclose(t);
662
663 gtk_widget_set_sensitive(BtnCompress, TRUE);
664 gtk_widget_set_sensitive(BtnDecompress, TRUE);
665 gtk_widget_set_sensitive(BtnCreate, TRUE);
666 gtk_widget_set_sensitive(BtnCreateZ, TRUE);
667
668 if (!stop) SysMessageLoc("Compressed Iso Image Created OK");
669 }

  ViewVC Help
Powered by ViewVC 1.1.22