From 18917ebc21240d665a953d65f5e7fe6a568fb9ed Mon Sep 17 00:00:00 2001 From: arcum42 Date: Sat, 21 Feb 2009 10:36:02 +0000 Subject: [PATCH] CDVDisoEFP: I'm not sure what happened in the mists of time to this folder that caused all the source code in it to have the lines all become double-spaced and unreadable... Got rid of all the extra blank lines, and reformated. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@559 96395faa-99c1-11dd-bbfe-3dabce05a288 --- plugins/CDVDisoEFP/src/Linux/CD.c | 1135 ++++----- plugins/CDVDisoEFP/src/Linux/CD.h | 52 - plugins/CDVDisoEFP/src/Linux/CDVDiso.c | 627 +++-- plugins/CDVDisoEFP/src/Linux/CDVDiso.h | 32 - plugins/CDVDisoEFP/src/Linux/DVD.c | 1817 +++++--------- plugins/CDVDisoEFP/src/Linux/DVD.h | 51 - plugins/CDVDisoEFP/src/Linux/aboutbox.c | 321 +-- plugins/CDVDisoEFP/src/Linux/aboutbox.h | 50 +- plugins/CDVDisoEFP/src/Linux/actualfile.c | 682 ++---- plugins/CDVDisoEFP/src/Linux/actualfile.h | 55 - plugins/CDVDisoEFP/src/Linux/comparisonbox.c | 1283 ++++------ .../CDVDisoEFP/src/Linux/comparisondummy.c | 78 +- plugins/CDVDisoEFP/src/Linux/conf.c | 472 ++-- plugins/CDVDisoEFP/src/Linux/conf.h | 109 +- plugins/CDVDisoEFP/src/Linux/conversionbox.c | 1193 ++++----- plugins/CDVDisoEFP/src/Linux/conversionbox.h | 70 +- plugins/CDVDisoEFP/src/Linux/device.c | 571 +++-- plugins/CDVDisoEFP/src/Linux/device.h | 78 - plugins/CDVDisoEFP/src/Linux/devicebox.c | 1361 ++++------- plugins/CDVDisoEFP/src/Linux/devicebox.h | 77 +- plugins/CDVDisoEFP/src/Linux/interface.c | 205 +- plugins/CDVDisoEFP/src/Linux/interface.h | 32 - plugins/CDVDisoEFP/src/Linux/logfile.c | 169 +- plugins/CDVDisoEFP/src/Linux/logfile.h | 70 +- plugins/CDVDisoEFP/src/Linux/mainbox.c | 805 ++----- plugins/CDVDisoEFP/src/Linux/mainbox.h | 101 +- plugins/CDVDisoEFP/src/Linux/messagebox.c | 240 +- plugins/CDVDisoEFP/src/Linux/messagebox.h | 87 +- plugins/CDVDisoEFP/src/Linux/progressbox.c | 314 +-- plugins/CDVDisoEFP/src/Linux/progressbox.h | 111 +- plugins/CDVDisoEFP/src/Linux/selectionbox.c | 211 +- plugins/CDVDisoEFP/src/Linux/selectionbox.h | 93 +- plugins/CDVDisoEFP/src/Linux/tablerebuild.c | 484 ++-- plugins/CDVDisoEFP/src/Linux/tablerebuild.h | 64 +- plugins/CDVDisoEFP/src/PS2Edefs.h | 252 +- plugins/CDVDisoEFP/src/PS2Etypes.h | 17 +- plugins/CDVDisoEFP/src/Win32/CD.c | 947 +++----- plugins/CDVDisoEFP/src/Win32/CD.h | 132 +- plugins/CDVDisoEFP/src/Win32/CDVDiso.c | 839 ++++--- plugins/CDVDisoEFP/src/Win32/CDVDiso.h | 41 - plugins/CDVDisoEFP/src/Win32/DVD.c | 1028 +++----- plugins/CDVDisoEFP/src/Win32/DVD.h | 41 - plugins/CDVDisoEFP/src/Win32/actualfile.c | 547 ++--- plugins/CDVDisoEFP/src/Win32/actualfile.h | 59 - plugins/CDVDisoEFP/src/Win32/conf.c | 607 ++--- plugins/CDVDisoEFP/src/Win32/conf.h | 73 +- plugins/CDVDisoEFP/src/Win32/conversionbox.c | 982 +++----- plugins/CDVDisoEFP/src/Win32/conversionbox.h | 51 +- plugins/CDVDisoEFP/src/Win32/device.c | 1820 +++++--------- plugins/CDVDisoEFP/src/Win32/device.h | 73 - plugins/CDVDisoEFP/src/Win32/devicebox.c | 1061 +++----- plugins/CDVDisoEFP/src/Win32/devicebox.h | 52 +- plugins/CDVDisoEFP/src/Win32/logfile.c | 364 +-- plugins/CDVDisoEFP/src/Win32/logfile.h | 44 - plugins/CDVDisoEFP/src/Win32/mainbox.c | 479 ++-- plugins/CDVDisoEFP/src/Win32/mainbox.h | 55 +- plugins/CDVDisoEFP/src/Win32/progressbox.c | 381 +-- plugins/CDVDisoEFP/src/Win32/progressbox.h | 41 - plugins/CDVDisoEFP/src/Win32/screens.h | 37 - plugins/CDVDisoEFP/src/Win32/tablerebuild.c | 573 ++--- plugins/CDVDisoEFP/src/Win32/tablerebuild.h | 36 - plugins/CDVDisoEFP/src/blockv2.c | 698 ++---- plugins/CDVDisoEFP/src/blockv2.h | 58 - plugins/CDVDisoEFP/src/bzip2v2.c | 1270 +++------- plugins/CDVDisoEFP/src/bzip2v2.h | 58 - plugins/CDVDisoEFP/src/bzip2v3.c | 1155 +++------ plugins/CDVDisoEFP/src/bzip2v3.h | 58 - plugins/CDVDisoEFP/src/convert.c | 145 +- plugins/CDVDisoEFP/src/convert.h | 7 - plugins/CDVDisoEFP/src/ecma119.c | 178 +- plugins/CDVDisoEFP/src/ecma119.h | 459 +--- plugins/CDVDisoEFP/src/gzipv1.c | 988 +++----- plugins/CDVDisoEFP/src/gzipv1.h | 58 - plugins/CDVDisoEFP/src/gzipv2.c | 1169 +++------ plugins/CDVDisoEFP/src/gzipv2.h | 58 - plugins/CDVDisoEFP/src/imagetype.c | 364 +-- plugins/CDVDisoEFP/src/imagetype.h | 75 +- plugins/CDVDisoEFP/src/ini.c | 2135 ++++++----------- plugins/CDVDisoEFP/src/ini.h | 192 +- plugins/CDVDisoEFP/src/isocompress.c | 1242 ++++------ plugins/CDVDisoEFP/src/isocompress.h | 114 +- plugins/CDVDisoEFP/src/isofile.c | 1699 +++++-------- plugins/CDVDisoEFP/src/isofile.h | 224 +- plugins/CDVDisoEFP/src/multifile.c | 771 ++---- plugins/CDVDisoEFP/src/multifile.h | 61 - plugins/CDVDisoEFP/src/toc.c | 560 +++-- plugins/CDVDisoEFP/src/toc.h | 35 +- plugins/CDVDisoEFP/src/version.c | 108 +- plugins/CDVDisoEFP/src/version.h | 47 - 89 files changed, 12252 insertions(+), 25466 deletions(-) diff --git a/plugins/CDVDisoEFP/src/Linux/CD.c b/plugins/CDVDisoEFP/src/Linux/CD.c index c9918f29af..b4e2f383c5 100644 --- a/plugins/CDVDisoEFP/src/Linux/CD.c +++ b/plugins/CDVDisoEFP/src/Linux/CD.c @@ -1,734 +1,401 @@ -/* CD.c - - * Copyright (C) 2002-2005 PCSX2 Team - - * - - * This program is free software; you can redistribute it and/or modify - - * it under the terms of the GNU General Public License as published by - - * the Free Software Foundation; either version 2 of the License, or - - * (at your option) any later version. - - * - - * This program is distributed in the hope that it will be useful, - - * but WITHOUT ANY WARRANTY; without even the implied warranty of - - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - - * GNU General Public License for more details. - - * - - * You should have received a copy of the GNU General Public License - - * along with this program; if not, write to the Free Software - - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - * - - * PCSX2 members can be contacted through their website at www.pcsx2.net. - - */ - - - -#include // errno - -#include // NULL - -#include // strerror() - -#include // open() - -#include // ioctl() - -#include // open() - -#include // lseek(), open() - -#include // close(), lseek(), (sleep()) - - - -#include // CD/DVD based ioctl() and defines. - - - -#include "../convert.h" - -#include "logfile.h" - -#include "device.h" - -#include "CD.h" - - - - - -// Constants - -u8 *playstationcdname = "PLAYSTATION\0"; - -u8 *ps1name = "CD-XA001\0"; - - - -// CD-ROM temp storage structures (see linux/cdrom.h for details) - -struct cdrom_tochdr cdheader; - -struct cdrom_tocentry cdtrack; - -struct cdrom_subchnl subchannel; - -u8 cdtempbuffer[2352]; - - - -int cdmode; // mode of last CDVDreadTrack call (important for CDs) - - - - - -// Internal Functions - - - -void InitCDSectorInfo() { - - cdmode = -1; - -} // END InitSectorInfo(); - - - - - -// Function Calls from CDVD.c - - - -void InitCDInfo() { - - InitCDSectorInfo(); - -} // END InitDiscType() - - - -s32 CDreadTrack(u32 lsn, int mode, u8 *buffer) { - - s32 s32result; - - - -#ifdef VERBOSE_FUNCTION - - PrintLog("CDVD driver: CDreadTrack(%i)", lsn); - -#endif /* VERBOSE_FUNCTION */ - - - - s32result = 0; - - - - if(buffer == NULL) return(-1); - - - - // The CD way of figuring out where to read. - - LBAtoMSF(lsn, buffer); - - - - switch(mode) { - - case CDVD_MODE_2048: - - case CDVD_MODE_2328: - - case CDVD_MODE_2340: - - case CDVD_MODE_2352: - - errno = 4; // Interrupted system call... (simulated the first time) - - while(errno == 4) { - - errno = 0; - - s32result = ioctl(devicehandle, CDROMREADRAW, buffer); - - } // ENDWHILE- Continually being interrupted by the system... - - break; - - case CDVD_MODE_2368: // Unimplemented... as yet. - - default: - -#ifdef VERBOSE_WARNINGS - - PrintLog("CDVD driver: Unknown Mode %i", mode); - -#endif /* VERBOSE_WARNINGS */ - - return(-1); // Illegal Read Mode? Abort - - break; - - } // ENDSWITCH- Which read mode should we choose? - - if((s32result == -1) || (errno != 0)) { - -#ifdef VERBOSE_WARNINGS - - PrintLog("CDVD driver: Error reading CD: %i:%s", errno, strerror(errno)); - -#endif /* VERBOSE_WARNINGS */ - - InitCDSectorInfo(); - - return(-1); - - } // ENDIF- Trouble getting a track count? - - - - cdmode = mode; // Save mode for buffer positioning later. - - return(0); // Call accomplished - -} // END CDreadTrack() - - - -s32 CDgetBufferOffset() { - -#ifdef VERBOSE_FUNCTION - - PrintLog("CDVD driver: CDgetBufferOffset()"); - -#endif /* VERBOSE_FUNCTION */ - - - - switch(cdmode) { - - case CDVD_MODE_2048: - - return(0+24); - - case CDVD_MODE_2328: - - return(0+24); - - case CDVD_MODE_2340: - - return(0+12); - - case CDVD_MODE_2352: - - return(0+0); - - case CDVD_MODE_2368: // Unimplemented... as yet. - - default: - -#ifdef VERBOSE_WARNINGS - - PrintLog("CDVD driver: Unknown Mode %i", cdmode); - -#endif /* VERBOSE_WARNINGS */ - - return(0); // Not to worry. for now. - - } // ENDSWITCH- where should we put the buffer pointer? - -} // END CDgetBuffer() - - - -// I, personally, don't see the big deal with SubQ - -// However, sooner or later I'll incorporate it into the Cache Buffer system - -// (backward compatibility, and all that) - -s32 CDreadSubQ(u32 lsn, cdvdSubQ *subq) { - - int tempmode; - - s32 s32result; - - - - s32result = 0; - - - -#ifdef VERBOSE_FUNCTION - - PrintLog("CDVD driver: CDreadSubQ()"); - -#endif /* VERBOSE_FUNCTION */ - - - - tempmode = cdmode; - - if(tempmode == -1) tempmode = CDVD_MODE_2352; - - CDreadTrack(lsn, tempmode, cdtempbuffer); - - if((s32result == -1) || (errno != 0)) { - -#ifdef VERBOSE_WARNINGS - - PrintLog("CDVD driver: Error prepping CD SubQ: %i:%s", errno, strerror(errno)); - -#endif /* VERBOSE_WARNINGS */ - - return(s32result); - - } // ENDIF- Trouble? - - - - subchannel.cdsc_format = CDROM_MSF; - - s32result = ioctl(devicehandle, CDROMSUBCHNL, &subchannel); - - if((s32result == -1) || (errno != 0)) { - -#ifdef VERBOSE_WARNINGS - - PrintLog("CDVD driver: Error reading CD SubQ: %i:%s", errno, strerror(errno)); - -#endif /* VERBOSE_WARNINGS */ - - return(s32result); - - } // ENDIF- Trouble? - - - - if(subq != NULL) { - - subq->mode = subchannel.cdsc_adr; - - subq->ctrl = subchannel.cdsc_ctrl; - - subq->trackNum = subchannel.cdsc_trk; - - subq->trackIndex = subchannel.cdsc_ind; - - subq->trackM = subchannel.cdsc_reladdr.msf.minute; - - subq->trackS = subchannel.cdsc_reladdr.msf.second; - - subq->trackF = subchannel.cdsc_reladdr.msf.frame; - - subq->discM = subchannel.cdsc_absaddr.msf.minute; - - subq->discS = subchannel.cdsc_absaddr.msf.second; - - subq->discF = subchannel.cdsc_absaddr.msf.frame; - - } // ENDIF- Did the caller want all this data? - - - - return(0); - -} // END CDVDreadSubQ() - - - -s32 CDgetTN(cdvdTN *cdvdtn) { - -#ifdef VERBOSE_FUNCTION - - PrintLog("CDVD driver: CDgetTN()"); - -#endif /* VERBOSE_FUNCTION */ - - - - if(cdvdtn != NULL) { - - cdvdtn->strack = cdheader.cdth_trk0; - - cdvdtn->etrack = cdheader.cdth_trk1; - - } // ENDIF- programmer actually WANTS this info? - - - - return(0); // Call accomplished - -} // END CDVDgetTN() - - - -s32 CDgetTD(u8 newtrack, cdvdTD *cdvdtd) { - - u8 j; - - u16 k; - - char temptime[3]; - - - -#ifdef VERBOSE_FUNCTION - - PrintLog("CDVD driver: CDgetTD()"); - -#endif /* VERBOSE_FUNCTION */ - - - - j = newtrack; - - if(j == CDROM_LEADOUT) j = 0; - - - - if(j == 0) { - - k = 27; - - } else { - - k = j * 10 + 37; - - } // ENDIF- Where to start hunting for this number? - - - - if(cdvdtd != NULL) { - - cdvdtd->type = tocbuffer[j*10 + 30]; - - - - temptime[0] = BCDTOHEX(tocbuffer[k]); - - temptime[1] = BCDTOHEX(tocbuffer[k + 1]); - - temptime[2] = BCDTOHEX(tocbuffer[k + 2]); - - cdvdtd->lsn = MSFtoLBA(temptime); - - } // ENDIF- Does the caller REALLY want this data? - - - - return(0); // Call accomplished - -} // END CDVDgetTD() - - - -s32 CALLBACK CDgetDiskType(s32 ioctldisktype) { - - s32 offset; - - s32 s32result; - - int i; - - u8 j; - - int tempdisctype; - - - - offset = 0; - - errno = 0; - - i = 0; - - j = 0; - - tempdisctype = CDVD_TYPE_UNKNOWN; - - - -#ifdef VERBOSE_FUNCTION - - PrintLog("CDVD driver: CDgetDiskType()"); - -#endif /* VERBOSE_FUNCTION */ - - - - s32result = CDreadTrack(16, CDVD_MODE_2352, cdtempbuffer); - - if((s32result != 0) || (errno != 0)) { - - return(-1); - - } // ENDIF- Cannot read the CD's ISO9660 volume sector? Abort - - disctype = CDVD_TYPE_DETCTCD; - - - - switch(ioctldisktype) { - - case CDS_AUDIO: - -#ifdef VERBOSE_DISC_TYPE - - PrintLog("CDVD driver: Detected CDDA Audio disc."); - -#endif /* VERBOSE_DISC_TYPE */ - - tempdisctype = CDVD_TYPE_CDDA; - - tocbuffer[0] = 0x01; - - break; - - - - case CDS_DATA_1: - - case CDS_MIXED: - -#ifdef VERBOSE_DISC_TYPE - - PrintLog("CDVD driver: Detected CD disc."); - -#endif /* VERBOSE_DISC_TYPE */ - - tocbuffer[0] = 0x41; - - - - CDreadTrack(16, CDVD_MODE_2048, cdtempbuffer); - - offset = CDgetBufferOffset(); - - i = 0; - - while((*(playstationcdname + i) != 0) && - - (*(playstationcdname + i) == cdtempbuffer[offset + 8 + i])) i++; - - if(*(playstationcdname + i) == 0) { - - i = 0; - - while((*(ps1name + i) != 0) && - - (*(ps1name + i) == cdtempbuffer[offset + 1024 + i])) i++; - - if(*(ps1name + i) == 0) { - -#ifdef VERBOSE_DISC_TYPE - - PrintLog("CDVD driver: Detected Playstation CD disc."); - -#endif /* VERBOSE_DISC_TYPE */ - - tempdisctype = CDVD_TYPE_PSCD; - - } else { - -#ifdef VERBOSE_DISC_TYPE - - PrintLog("CDVD driver: Detected Playstation 2 CD disc."); - -#endif /* VERBOSE_DISC_TYPE */ - - tempdisctype = CDVD_TYPE_PS2CD; - - } // ENDIF- Did we find the CD ident? (For Playstation 1 CDs) - - } else { - - tempdisctype = CDVD_TYPE_UNKNOWN; - - } // ENDIF- Did we find the Playstation name? - - break; - - - - default: - - return(-1); - - } // ENDSWITCH- What has ioctl disc type come up with? - - - - // Collect TN data - - cdheader.cdth_trk0 = 0; - - cdheader.cdth_trk1 = 0; - - - - s32result = ioctl(devicehandle, CDROMREADTOCHDR, &cdheader); - - if((s32result == -1) || (errno != 0)) { - -#ifdef VERBOSE_WARNINGS - - PrintLog("CDVD driver: Error reading TN: (%i) %i:%s", - - s32result, errno, strerror(errno)); - -#endif /* VERBOSE_WARNINGS */ - - cdheader.cdth_trk0 = 1; - - cdheader.cdth_trk1 = 1; - - } // ENDIF- Failed to read in track count? Assume 1 track. - -#ifdef VERBOSE_DISC_INFO - - PrintLog("CDVD driver: Track Number Range: %i-%i", - - cdheader.cdth_trk0, cdheader.cdth_trk1); - -#endif /* VERBOSE_DISC_INFO */ - - tocbuffer[2] = 0xA0; - - tocbuffer[7] = HEXTOBCD(cdheader.cdth_trk0); - - tocbuffer[12] = 0xA1; - - tocbuffer[17] = HEXTOBCD(cdheader.cdth_trk1); - - - - // Collect disc TD data - - cdtrack.cdte_track = CDROM_LEADOUT; - - cdtrack.cdte_format = CDROM_LBA; - - s32result = ioctl(devicehandle, CDROMREADTOCENTRY, &cdtrack); - - if((s32result == -1) || (errno != 0)) { - -#ifdef VERBOSE_WARNINGS - - PrintLog("CDVD driver: Error reading TD for disc: (%i) %i:%s", - - s32result, errno, strerror(errno)); - -#endif /* VERBOSE_WARNINGS */ - - return(-1); - - } // ENDIF- Trouble getting a track count? - - - - LBAtoMSF(cdtrack.cdte_addr.lba, &tocbuffer[27]); - -#ifdef VERBOSE_DISC_INFO - - PrintLog("CDVD driver: Total Time: %i:%i", - - tocbuffer[27], tocbuffer[28]); - -#endif /* VERBOSE_DISC_INFO */ - - tocbuffer[27] = HEXTOBCD(tocbuffer[27]); - - tocbuffer[28] = HEXTOBCD(tocbuffer[28]); - - tocbuffer[29] = HEXTOBCD(tocbuffer[29]); - - - - // Collect track TD data - - for(j = cdheader.cdth_trk0; j <= cdheader.cdth_trk1; j++) { - - cdtrack.cdte_track = j; // j-1? - - cdtrack.cdte_format = CDROM_LBA; - - s32result = ioctl(devicehandle, CDROMREADTOCENTRY, &cdtrack); - - if((s32result == -1) || (errno != 0)) { - -#ifdef VERBOSE_WARNINGS - - PrintLog("CDVD driver: Error reading TD for track %i: (%i) %i:%s", - - j, s32result, errno, strerror(errno)); - -#endif /* VERBOSE_WARNINGS */ - - // No more here... - - - - } else { - - LBAtoMSF(cdtrack.cdte_addr.lba, &tocbuffer[j*10 + 37]); - -#ifdef VERBOSE_DISC_INFO - - PrintLog("CDVD driver: Track %i: Data Mode %i Disc Start Time:%i:%i.%i\n", - - j, - - cdtrack.cdte_datamode, - - tocbuffer[j*10+37], - - tocbuffer[j*10+38], - - tocbuffer[j*10+39]); - -#endif /* VERBOSE_DISC_INFO */ - - tocbuffer[j*10 + 30] = cdtrack.cdte_datamode; - - tocbuffer[j*10 + 32] = HEXTOBCD(j); - - tocbuffer[j*10 + 37] = HEXTOBCD(tocbuffer[j*10 + 37]); - - tocbuffer[j*10 + 38] = HEXTOBCD(tocbuffer[j*10 + 38]); - - tocbuffer[j*10 + 39] = HEXTOBCD(tocbuffer[j*10 + 39]); - - } // ENDIF- Trouble getting a track count? - - } // NEXT j- Reading each track's info in turn - - - - errno = 0; - - disctype = tempdisctype; // Trigger the fact we have the info (finally) - - return(disctype); - -} // END CDVDgetDiskType() - +/* CD.c + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + +#include // errno +#include // NULL +#include // strerror() +#include // open() +#include // ioctl() +#include // open() +#include // lseek(), open() +#include // close(), lseek(), (sleep()) + +#include // CD/DVD based ioctl() and defines. + +#include "../convert.h" +#include "logfile.h" +#include "device.h" +#include "CD.h" + + +// Constants +u8 *playstationcdname = "PLAYSTATION\0"; +u8 *ps1name = "CD-XA001\0"; + +// CD-ROM temp storage structures (see linux/cdrom.h for details) +struct cdrom_tochdr cdheader; +struct cdrom_tocentry cdtrack; +struct cdrom_subchnl subchannel; +u8 cdtempbuffer[2352]; + +int cdmode; // mode of last CDVDreadTrack call (important for CDs) + + +// Internal Functions + +void InitCDSectorInfo() +{ + cdmode = -1; +} // END InitSectorInfo(); + + +// Function Calls from CDVD.c + +void InitCDInfo() +{ + InitCDSectorInfo(); +} // END InitDiscType() + +s32 CDreadTrack(u32 lsn, int mode, u8 *buffer) +{ + s32 s32result; + +#ifdef VERBOSE_FUNCTION + PrintLog("CDVD driver: CDreadTrack(%i)", lsn); +#endif /* VERBOSE_FUNCTION */ + + s32result = 0; + + if (buffer == NULL) return(-1); + + // The CD way of figuring out where to read. + LBAtoMSF(lsn, buffer); + + switch (mode) + { + case CDVD_MODE_2048: + case CDVD_MODE_2328: + case CDVD_MODE_2340: + case CDVD_MODE_2352: + errno = 4; // Interrupted system call... (simulated the first time) + while (errno == 4) + { + errno = 0; + s32result = ioctl(devicehandle, CDROMREADRAW, buffer); + } // ENDWHILE- Continually being interrupted by the system... + break; + case CDVD_MODE_2368: // Unimplemented... as yet. + default: +#ifdef VERBOSE_WARNINGS + PrintLog("CDVD driver: Unknown Mode %i", mode); +#endif /* VERBOSE_WARNINGS */ + return(-1); // Illegal Read Mode? Abort + break; + } // ENDSWITCH- Which read mode should we choose? + if ((s32result == -1) || (errno != 0)) + { +#ifdef VERBOSE_WARNINGS + PrintLog("CDVD driver: Error reading CD: %i:%s", errno, strerror(errno)); +#endif /* VERBOSE_WARNINGS */ + InitCDSectorInfo(); + return(-1); + } // ENDIF- Trouble getting a track count? + + cdmode = mode; // Save mode for buffer positioning later. + return(0); // Call accomplished +} // END CDreadTrack() + +s32 CDgetBufferOffset() +{ +#ifdef VERBOSE_FUNCTION + PrintLog("CDVD driver: CDgetBufferOffset()"); +#endif /* VERBOSE_FUNCTION */ + + switch (cdmode) + { + case CDVD_MODE_2048: + return(0 + 24); + case CDVD_MODE_2328: + return(0 + 24); + case CDVD_MODE_2340: + return(0 + 12); + case CDVD_MODE_2352: + return(0 + 0); + case CDVD_MODE_2368: // Unimplemented... as yet. + default: +#ifdef VERBOSE_WARNINGS + PrintLog("CDVD driver: Unknown Mode %i", cdmode); +#endif /* VERBOSE_WARNINGS */ + return(0); // Not to worry. for now. + } // ENDSWITCH- where should we put the buffer pointer? +} // END CDgetBuffer() + +// I, personally, don't see the big deal with SubQ +// However, sooner or later I'll incorporate it into the Cache Buffer system +// (backward compatibility, and all that) +s32 CDreadSubQ(u32 lsn, cdvdSubQ *subq) +{ + int tempmode; + s32 s32result; + + s32result = 0; + +#ifdef VERBOSE_FUNCTION + PrintLog("CDVD driver: CDreadSubQ()"); +#endif /* VERBOSE_FUNCTION */ + + tempmode = cdmode; + if (tempmode == -1) tempmode = CDVD_MODE_2352; + CDreadTrack(lsn, tempmode, cdtempbuffer); + if ((s32result == -1) || (errno != 0)) + { +#ifdef VERBOSE_WARNINGS + PrintLog("CDVD driver: Error prepping CD SubQ: %i:%s", errno, strerror(errno)); +#endif /* VERBOSE_WARNINGS */ + return(s32result); + } // ENDIF- Trouble? + + subchannel.cdsc_format = CDROM_MSF; + s32result = ioctl(devicehandle, CDROMSUBCHNL, &subchannel); + if ((s32result == -1) || (errno != 0)) + { +#ifdef VERBOSE_WARNINGS + PrintLog("CDVD driver: Error reading CD SubQ: %i:%s", errno, strerror(errno)); +#endif /* VERBOSE_WARNINGS */ + return(s32result); + } // ENDIF- Trouble? + + if (subq != NULL) + { + subq->mode = subchannel.cdsc_adr; + subq->ctrl = subchannel.cdsc_ctrl; + subq->trackNum = subchannel.cdsc_trk; + subq->trackIndex = subchannel.cdsc_ind; + subq->trackM = subchannel.cdsc_reladdr.msf.minute; + subq->trackS = subchannel.cdsc_reladdr.msf.second; + subq->trackF = subchannel.cdsc_reladdr.msf.frame; + subq->discM = subchannel.cdsc_absaddr.msf.minute; + subq->discS = subchannel.cdsc_absaddr.msf.second; + subq->discF = subchannel.cdsc_absaddr.msf.frame; + } // ENDIF- Did the caller want all this data? + + return(0); +} // END CDVDreadSubQ() + +s32 CDgetTN(cdvdTN *cdvdtn) +{ +#ifdef VERBOSE_FUNCTION + PrintLog("CDVD driver: CDgetTN()"); +#endif /* VERBOSE_FUNCTION */ + + if (cdvdtn != NULL) + { + cdvdtn->strack = cdheader.cdth_trk0; + cdvdtn->etrack = cdheader.cdth_trk1; + } // ENDIF- programmer actually WANTS this info? + + return(0); // Call accomplished +} // END CDVDgetTN() + +s32 CDgetTD(u8 newtrack, cdvdTD *cdvdtd) +{ + u8 j; + u16 k; + char temptime[3]; + +#ifdef VERBOSE_FUNCTION + PrintLog("CDVD driver: CDgetTD()"); +#endif /* VERBOSE_FUNCTION */ + + j = newtrack; + if (j == CDROM_LEADOUT) j = 0; + + if (j == 0) + { + k = 27; + } + else + { + k = j * 10 + 37; + } // ENDIF- Where to start hunting for this number? + + if (cdvdtd != NULL) + { + cdvdtd->type = tocbuffer[j*10 + 30]; + + temptime[0] = BCDTOHEX(tocbuffer[k]); + temptime[1] = BCDTOHEX(tocbuffer[k + 1]); + temptime[2] = BCDTOHEX(tocbuffer[k + 2]); + cdvdtd->lsn = MSFtoLBA(temptime); + } // ENDIF- Does the caller REALLY want this data? + + return(0); // Call accomplished +} // END CDVDgetTD() + +s32 CALLBACK CDgetDiskType(s32 ioctldisktype) +{ + s32 offset; + s32 s32result; + int i; + u8 j; + int tempdisctype; + + offset = 0; + errno = 0; + i = 0; + j = 0; + tempdisctype = CDVD_TYPE_UNKNOWN; + +#ifdef VERBOSE_FUNCTION + PrintLog("CDVD driver: CDgetDiskType()"); +#endif /* VERBOSE_FUNCTION */ + + s32result = CDreadTrack(16, CDVD_MODE_2352, cdtempbuffer); + if ((s32result != 0) || (errno != 0)) + { + return(-1); + } // ENDIF- Cannot read the CD's ISO9660 volume sector? Abort + disctype = CDVD_TYPE_DETCTCD; + + switch (ioctldisktype) + { + case CDS_AUDIO: +#ifdef VERBOSE_DISC_TYPE + PrintLog("CDVD driver: Detected CDDA Audio disc."); +#endif /* VERBOSE_DISC_TYPE */ + tempdisctype = CDVD_TYPE_CDDA; + tocbuffer[0] = 0x01; + break; + + case CDS_DATA_1: + case CDS_MIXED: +#ifdef VERBOSE_DISC_TYPE + PrintLog("CDVD driver: Detected CD disc."); +#endif /* VERBOSE_DISC_TYPE */ + tocbuffer[0] = 0x41; + + CDreadTrack(16, CDVD_MODE_2048, cdtempbuffer); + offset = CDgetBufferOffset(); + i = 0; + while ((*(playstationcdname + i) != 0) && + (*(playstationcdname + i) == cdtempbuffer[offset + 8 + i])) i++; + if (*(playstationcdname + i) == 0) + { + i = 0; + while ((*(ps1name + i) != 0) && + (*(ps1name + i) == cdtempbuffer[offset + 1024 + i])) i++; + if (*(ps1name + i) == 0) + { +#ifdef VERBOSE_DISC_TYPE + PrintLog("CDVD driver: Detected Playstation CD disc."); +#endif /* VERBOSE_DISC_TYPE */ + tempdisctype = CDVD_TYPE_PSCD; + } + else + { +#ifdef VERBOSE_DISC_TYPE + PrintLog("CDVD driver: Detected Playstation 2 CD disc."); +#endif /* VERBOSE_DISC_TYPE */ + tempdisctype = CDVD_TYPE_PS2CD; + } // ENDIF- Did we find the CD ident? (For Playstation 1 CDs) + } + else + { + tempdisctype = CDVD_TYPE_UNKNOWN; + } // ENDIF- Did we find the Playstation name? + break; + + default: + return(-1); + } // ENDSWITCH- What has ioctl disc type come up with? + + // Collect TN data + cdheader.cdth_trk0 = 0; + cdheader.cdth_trk1 = 0; + + s32result = ioctl(devicehandle, CDROMREADTOCHDR, &cdheader); + if ((s32result == -1) || (errno != 0)) + { +#ifdef VERBOSE_WARNINGS + PrintLog("CDVD driver: Error reading TN: (%i) %i:%s", + s32result, errno, strerror(errno)); +#endif /* VERBOSE_WARNINGS */ + cdheader.cdth_trk0 = 1; + cdheader.cdth_trk1 = 1; + } // ENDIF- Failed to read in track count? Assume 1 track. +#ifdef VERBOSE_DISC_INFO + PrintLog("CDVD driver: Track Number Range: %i-%i", + cdheader.cdth_trk0, cdheader.cdth_trk1); +#endif /* VERBOSE_DISC_INFO */ + tocbuffer[2] = 0xA0; + tocbuffer[7] = HEXTOBCD(cdheader.cdth_trk0); + tocbuffer[12] = 0xA1; + tocbuffer[17] = HEXTOBCD(cdheader.cdth_trk1); + + // Collect disc TD data + cdtrack.cdte_track = CDROM_LEADOUT; + cdtrack.cdte_format = CDROM_LBA; + s32result = ioctl(devicehandle, CDROMREADTOCENTRY, &cdtrack); + if ((s32result == -1) || (errno != 0)) + { +#ifdef VERBOSE_WARNINGS + PrintLog("CDVD driver: Error reading TD for disc: (%i) %i:%s", + s32result, errno, strerror(errno)); +#endif /* VERBOSE_WARNINGS */ + return(-1); + } // ENDIF- Trouble getting a track count? + + LBAtoMSF(cdtrack.cdte_addr.lba, &tocbuffer[27]); +#ifdef VERBOSE_DISC_INFO + PrintLog("CDVD driver: Total Time: %i:%i", + tocbuffer[27], tocbuffer[28]); +#endif /* VERBOSE_DISC_INFO */ + tocbuffer[27] = HEXTOBCD(tocbuffer[27]); + tocbuffer[28] = HEXTOBCD(tocbuffer[28]); + tocbuffer[29] = HEXTOBCD(tocbuffer[29]); + + // Collect track TD data + for (j = cdheader.cdth_trk0; j <= cdheader.cdth_trk1; j++) + { + cdtrack.cdte_track = j; // j-1? + cdtrack.cdte_format = CDROM_LBA; + s32result = ioctl(devicehandle, CDROMREADTOCENTRY, &cdtrack); + if ((s32result == -1) || (errno != 0)) + { +#ifdef VERBOSE_WARNINGS + PrintLog("CDVD driver: Error reading TD for track %i: (%i) %i:%s", + j, s32result, errno, strerror(errno)); +#endif /* VERBOSE_WARNINGS */ + // No more here... + + } + else + { + LBAtoMSF(cdtrack.cdte_addr.lba, &tocbuffer[j*10 + 37]); +#ifdef VERBOSE_DISC_INFO + PrintLog("CDVD driver: Track %i: Data Mode %i Disc Start Time:%i:%i.%i\n", + j, + cdtrack.cdte_datamode, + tocbuffer[j*10+37], + tocbuffer[j*10+38], + tocbuffer[j*10+39]); +#endif /* VERBOSE_DISC_INFO */ + tocbuffer[j*10 + 30] = cdtrack.cdte_datamode; + tocbuffer[j*10 + 32] = HEXTOBCD(j); + tocbuffer[j*10 + 37] = HEXTOBCD(tocbuffer[j*10 + 37]); + tocbuffer[j*10 + 38] = HEXTOBCD(tocbuffer[j*10 + 38]); + tocbuffer[j*10 + 39] = HEXTOBCD(tocbuffer[j*10 + 39]); + } // ENDIF- Trouble getting a track count? + } // NEXT j- Reading each track's info in turn + + errno = 0; + disctype = tempdisctype; // Trigger the fact we have the info (finally) + return(disctype); +} // END CDVDgetDiskType() diff --git a/plugins/CDVDisoEFP/src/Linux/CD.h b/plugins/CDVDisoEFP/src/Linux/CD.h index 0f8f6f485e..4d909bee1a 100644 --- a/plugins/CDVDisoEFP/src/Linux/CD.h +++ b/plugins/CDVDisoEFP/src/Linux/CD.h @@ -1,92 +1,40 @@ /* CD.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - #ifndef __CD_H__ - #define __CD_H__ - - - - #ifndef __LINUX__ - #ifdef __linux__ - #define __LINUX__ - #endif /* __linux__ */ - #endif /* No __LINUX__ */ - - - #define CDVDdefs - #include "../PS2Edefs.h" - - - - // Exported Functions - - - extern void InitCDInfo(); - extern s32 CDreadTrack(u32 lsn, int mode, u8 *buffer); - extern s32 CDgetBufferOffset(); - extern s32 CDreadSubQ(u32 lsn, cdvdSubQ *subq); - extern s32 CDgetTN(cdvdTN *cdvdtn); - extern s32 CDgetTD(u8 newtrack, cdvdTD *cdvdtd); - extern s32 CDgetDiskType(s32 ioctldisktype); - - - - #endif /* __CD_H__ */ - diff --git a/plugins/CDVDisoEFP/src/Linux/CDVDiso.c b/plugins/CDVDisoEFP/src/Linux/CDVDiso.c index e5ad373caf..001b1efaf6 100644 --- a/plugins/CDVDisoEFP/src/Linux/CDVDiso.c +++ b/plugins/CDVDisoEFP/src/Linux/CDVDiso.c @@ -17,10 +17,7 @@ * * PCSX2 members can be contacted through their website at www.pcsx2.net. */ - - #include // NULL - #ifndef __LINUX__ #ifdef __linux__ #define __LINUX__ @@ -28,7 +25,6 @@ #endif /* No __LINUX__ */ #define CDVDdefs #include "PS2Edefs.h" - #include "conf.h" #include "actualfile.h" #include "isofile.h" @@ -36,415 +32,384 @@ #include "convert.h" #include "version.h" #include "CDVDiso.h" - - struct IsoFile *isofile; char isobuffer[2448]; char isocdcheck[2448]; int isomode; int deviceopencount; // 0 = Closed, 1+ = Open - - -char* CALLBACK PS2EgetLibName() { - return(libname); +char* CALLBACK PS2EgetLibName() +{ + return(libname); } // END PS2EgetLibName() - - -u32 CALLBACK PS2EgetLibType() { - return(PS2E_LT_CDVD); +u32 CALLBACK PS2EgetLibType() +{ + return(PS2E_LT_CDVD); } // END PS2getLibType() - - -u32 CALLBACK PS2EgetLibVersion2(u32 type) { - return((version << 16) | (revision << 8) | build); +u32 CALLBACK PS2EgetLibVersion2(u32 type) +{ + return((version << 16) | (revision << 8) | build); } +s32 CALLBACK CDVDinit() +{ + int i; + InitLog(); + if (OpenLog() != 0) return(-1); // Couldn't open Log File? Abort. -s32 CALLBACK CDVDinit() { - int i; - - InitLog(); - if(OpenLog() != 0) return(-1); // Couldn't open Log File? Abort. - #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDinit()"); + PrintLog("CDVDiso interface: CDVDinit()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ + InitConf(); + isofile = NULL; + isomode = -1; + for (i = 0; i < 2048; i++) isocdcheck[i] = 0; + deviceopencount = 0; - InitConf(); - - isofile = NULL; - isomode = -1; - for(i = 0; i < 2048; i++) isocdcheck[i] = 0; - deviceopencount = 0; - - return(0); + return(0); } // END CDVDinit() - - -void CALLBACK CDVDshutdown() { +void CALLBACK CDVDshutdown() +{ #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDshutdown()"); + PrintLog("CDVDiso interface: CDVDshutdown()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - - isofile = IsoFileClose(isofile); - CloseLog(); + isofile = IsoFileClose(isofile); + CloseLog(); } // END CDVDshutdown() - - -s32 CALLBACK CDVDopen(const char* pTitleFilename) { - int retval; - int i; - +s32 CALLBACK CDVDopen(const char* pTitleFilename) +{ + int retval; + int i; #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDopen()"); + PrintLog("CDVDiso interface: CDVDopen()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - - LoadConf(); - - if( pTitleFilename != NULL ) strcpy(conf.isoname, pTitleFilename); - - if((conf.isoname[0] == 0) || - ((conf.startconfigure != 0) && (deviceopencount == 0)) || - ((conf.restartconfigure != 0) && (deviceopencount > 0))) { - ExecCfg("configure"); - LoadConf(); - } // ENDIF- Haven't initialized the configure program yet? Do so now. - - isofile = IsoFileOpenForRead(conf.isoname); - if(isofile == NULL) { + LoadConf(); + if (pTitleFilename != NULL) strcpy(conf.isoname, pTitleFilename); + if ((conf.isoname[0] == 0) || + ((conf.startconfigure != 0) && (deviceopencount == 0)) || + ((conf.restartconfigure != 0) && (deviceopencount > 0))) + { + ExecCfg("configure"); + LoadConf(); + } // ENDIF- Haven't initialized the configure program yet? Do so now. + isofile = IsoFileOpenForRead(conf.isoname); + if (isofile == NULL) + { #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: Failed to open ISO file!"); + PrintLog("CDVDiso interface: Failed to open ISO file!"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - // return(-1); // Taken out for "NULL" device simulation - for(i = 0; i < 2048; i++) isocdcheck[i] = 0; - return(0); - } // ENDIF- Trouble opening file? Abort. - - retval = IsoFileSeek(isofile, 16); - if(retval != 0) return(-1); - retval = IsoFileRead(isofile, isobuffer); - if(retval != 0) return(-1); - - if(deviceopencount > 0) { - i = 0; - while((i < 2048) && (isocdcheck[i] == isobuffer[i])) i++; - if(i == 2048) deviceopencount = 0; // Same CD/DVD? No delay. - } // ENDIF- Is this a restart? Check for disc change. - - for(i = 0; i < 2048; i++) isocdcheck[i] = isobuffer[i]; - - return(0); + // return(-1); // Taken out for "NULL" device simulation + for (i = 0; i < 2048; i++) isocdcheck[i] = 0; + return(0); + } // ENDIF- Trouble opening file? Abort. + retval = IsoFileSeek(isofile, 16); + if (retval != 0) return(-1); + retval = IsoFileRead(isofile, isobuffer); + if (retval != 0) return(-1); + if (deviceopencount > 0) + { + i = 0; + while ((i < 2048) && (isocdcheck[i] == isobuffer[i])) i++; + if (i == 2048) deviceopencount = 0; // Same CD/DVD? No delay. + } // ENDIF- Is this a restart? Check for disc change. + for (i = 0; i < 2048; i++) isocdcheck[i] = isobuffer[i]; + return(0); } // END CDVDopen() - -void CALLBACK CDVDclose() { +void CALLBACK CDVDclose() +{ #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDclose()"); + PrintLog("CDVDiso interface: CDVDclose()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - isofile = IsoFileClose(isofile); - deviceopencount = 50; + isofile = IsoFileClose(isofile); + deviceopencount = 50; } // END CDVDclose() - -s32 CALLBACK CDVDreadSubQ(u32 lsn, cdvdSubQ* subq) { - char temptime[3]; - int i; - int pos; - u32 tracklsn; - +s32 CALLBACK CDVDreadSubQ(u32 lsn, cdvdSubQ* subq) +{ + char temptime[3]; + int i; + int pos; + u32 tracklsn; #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDreadSubQ()"); + PrintLog("CDVDiso interface: CDVDreadSubQ()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ + if (isofile == NULL) return(-1); + if (deviceopencount > 0) return(-1); + if ((isofile->cdvdtype == CDVD_TYPE_PS2DVD) || + (isofile->cdvdtype == CDVD_TYPE_DVDV)) + { + return(-1); // DVDs don't have SubQ data + } // ENDIF- Trying to get a SubQ from a DVD? + // fake it + i = BCDTOHEX(isofile->toc[7]); + pos = i * 10; + pos += 30; + temptime[0] = BCDTOHEX(isofile->toc[pos + 7]); + temptime[1] = BCDTOHEX(isofile->toc[pos + 8]); + temptime[2] = BCDTOHEX(isofile->toc[pos + 9]); + tracklsn = MSFtoLBA(temptime); + while ((i < BCDTOHEX(isofile->toc[17])) && (tracklsn < lsn)) + { + i++; + pos = i * 10; + pos += 30; + temptime[0] = BCDTOHEX(isofile->toc[pos + 7]); + temptime[1] = BCDTOHEX(isofile->toc[pos + 8]); + temptime[2] = BCDTOHEX(isofile->toc[pos + 9]); + tracklsn = MSFtoLBA(temptime); + } // ENDIF- Loop through tracks searching for lsn track + i--; - if(isofile == NULL) return(-1); - if(deviceopencount > 0) return(-1); + subq->ctrl = 4; + subq->mode = 1; + subq->trackNum = HEXTOBCD(i); + subq->trackIndex = HEXTOBCD(i); - if((isofile->cdvdtype == CDVD_TYPE_PS2DVD) || - (isofile->cdvdtype == CDVD_TYPE_DVDV)) { - return(-1); // DVDs don't have SubQ data - } // ENDIF- Trying to get a SubQ from a DVD? + LBAtoMSF(lsn - tracklsn, temptime); + subq->trackM = HEXTOBCD(temptime[0]); + subq->trackS = HEXTOBCD(temptime[1]); + subq->trackF = HEXTOBCD(temptime[2]); - // fake it - i = BCDTOHEX(isofile->toc[7]); - pos = i * 10; - pos += 30; - temptime[0] = BCDTOHEX(isofile->toc[pos + 7]); - temptime[1] = BCDTOHEX(isofile->toc[pos + 8]); - temptime[2] = BCDTOHEX(isofile->toc[pos + 9]); - tracklsn = MSFtoLBA(temptime); - while((i < BCDTOHEX(isofile->toc[17])) && (tracklsn < lsn)) { - i++; - pos = i * 10; - pos += 30; - temptime[0] = BCDTOHEX(isofile->toc[pos + 7]); - temptime[1] = BCDTOHEX(isofile->toc[pos + 8]); - temptime[2] = BCDTOHEX(isofile->toc[pos + 9]); - tracklsn = MSFtoLBA(temptime); - } // ENDIF- Loop through tracks searching for lsn track - i--; + subq->pad = 0; - subq->ctrl = 4; - subq->mode = 1; - subq->trackNum = HEXTOBCD(i); - subq->trackIndex = HEXTOBCD(i); - - LBAtoMSF(lsn - tracklsn, temptime); - subq->trackM = HEXTOBCD(temptime[0]); - subq->trackS = HEXTOBCD(temptime[1]); - subq->trackF = HEXTOBCD(temptime[2]); - - subq->pad = 0; - - // lba_to_msf(lsn + (2*75), &min, &sec, &frm); - LBAtoMSF(lsn, temptime); - subq->discM = HEXTOBCD(temptime[0]); - subq->discS = HEXTOBCD(temptime[1]); - subq->discF = HEXTOBCD(temptime[2]); + // lba_to_msf(lsn + (2*75), &min, &sec, &frm); + LBAtoMSF(lsn, temptime); + subq->discM = HEXTOBCD(temptime[0]); + subq->discS = HEXTOBCD(temptime[1]); + subq->discF = HEXTOBCD(temptime[2]); - return(0); + return(0); } // END CDVDreadSubQ() - - -s32 CALLBACK CDVDgetTN(cdvdTN *Buffer) { - if(isofile == NULL) return(-1); - if(deviceopencount > 0) return(-1); - +s32 CALLBACK CDVDgetTN(cdvdTN *Buffer) +{ + if (isofile == NULL) return(-1); + if (deviceopencount > 0) return(-1); #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDgetTN()"); + PrintLog("CDVDiso interface: CDVDgetTN()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - - if((isofile->cdvdtype == CDVD_TYPE_PS2DVD) || - (isofile->cdvdtype == CDVD_TYPE_DVDV)) { - Buffer->strack = 1; - Buffer->etrack = 1; - } else { - Buffer->strack = BCDTOHEX(isofile->toc[7]); - Buffer->etrack = BCDTOHEX(isofile->toc[17]); - } // ENDIF- Retrieve track info from a DVD? (or a CD?) - - return(0); + if ((isofile->cdvdtype == CDVD_TYPE_PS2DVD) || + (isofile->cdvdtype == CDVD_TYPE_DVDV)) + { + Buffer->strack = 1; + Buffer->etrack = 1; + } + else + { + Buffer->strack = BCDTOHEX(isofile->toc[7]); + Buffer->etrack = BCDTOHEX(isofile->toc[17]); + } // ENDIF- Retrieve track info from a DVD? (or a CD?) + return(0); } // END CDVDgetTN() - -s32 CALLBACK CDVDgetTD(u8 track, cdvdTD *Buffer) { - u8 actualtrack; - int pos; - char temptime[3]; - - if(isofile == NULL) return(-1); - if(deviceopencount > 0) return(-1); - +s32 CALLBACK CDVDgetTD(u8 track, cdvdTD *Buffer) +{ + u8 actualtrack; + int pos; + char temptime[3]; + if (isofile == NULL) return(-1); + if (deviceopencount > 0) return(-1); #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDgetTD()"); + PrintLog("CDVDiso interface: CDVDgetTD()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - - actualtrack = track; - if(actualtrack == 0xaa) actualtrack = 0; - - if((isofile->cdvdtype == CDVD_TYPE_PS2DVD) || - (isofile->cdvdtype == CDVD_TYPE_DVDV)) { - if (actualtrack <= 1) { - Buffer->type = 0; - Buffer->lsn = isofile->filesectorsize; - } else { - Buffer->type = CDVD_MODE1_TRACK; - Buffer->lsn = 0; - } // ENDIF- Whole disc? (or single track?) - } else { - if (actualtrack == 0) { - Buffer->type = 0; - temptime[0] = BCDTOHEX(isofile->toc[27]); - temptime[1] = BCDTOHEX(isofile->toc[28]); - temptime[2] = BCDTOHEX(isofile->toc[29]); - Buffer->lsn = MSFtoLBA(temptime); - } else { - pos = actualtrack * 10; - pos += 30; - Buffer->type = isofile->toc[pos]; - temptime[0] = BCDTOHEX(isofile->toc[pos + 7]); - temptime[1] = BCDTOHEX(isofile->toc[pos + 8]); - temptime[2] = BCDTOHEX(isofile->toc[pos + 9]); - Buffer->lsn = MSFtoLBA(temptime); - } // ENDIF- Whole disc? (or single track?) - } // ENDIF- Retrieve track info from a DVD? (or a CD?) - - return(0); + actualtrack = track; + if (actualtrack == 0xaa) actualtrack = 0; + if ((isofile->cdvdtype == CDVD_TYPE_PS2DVD) || + (isofile->cdvdtype == CDVD_TYPE_DVDV)) + { + if (actualtrack <= 1) + { + Buffer->type = 0; + Buffer->lsn = isofile->filesectorsize; + } + else + { + Buffer->type = CDVD_MODE1_TRACK; + Buffer->lsn = 0; + } // ENDIF- Whole disc? (or single track?) + } + else + { + if (actualtrack == 0) + { + Buffer->type = 0; + temptime[0] = BCDTOHEX(isofile->toc[27]); + temptime[1] = BCDTOHEX(isofile->toc[28]); + temptime[2] = BCDTOHEX(isofile->toc[29]); + Buffer->lsn = MSFtoLBA(temptime); + } + else + { + pos = actualtrack * 10; + pos += 30; + Buffer->type = isofile->toc[pos]; + temptime[0] = BCDTOHEX(isofile->toc[pos + 7]); + temptime[1] = BCDTOHEX(isofile->toc[pos + 8]); + temptime[2] = BCDTOHEX(isofile->toc[pos + 9]); + Buffer->lsn = MSFtoLBA(temptime); + } // ENDIF- Whole disc? (or single track?) + } // ENDIF- Retrieve track info from a DVD? (or a CD?) + return(0); } // END CDVDgetTD() - -s32 CALLBACK CDVDgetTOC(void* toc) { - int i; - - if(isofile == NULL) return(-1); - if(deviceopencount > 0) return(-1); - +s32 CALLBACK CDVDgetTOC(void* toc) +{ + int i; + if (isofile == NULL) return(-1); + if (deviceopencount > 0) return(-1); #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDgetTOC()"); + PrintLog("CDVDiso interface: CDVDgetTOC()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - - for(i = 0; i < 2048; i++) *(((char *) toc) + i) = isofile->toc[i]; - return(0); + for (i = 0; i < 2048; i++) *(((char *) toc) + i) = isofile->toc[i]; + return(0); } // END CDVDgetTOC() - -s32 CALLBACK CDVDreadTrack(u32 lsn, int mode) { - int retval; - - if(isofile == NULL) return(-1); - if(deviceopencount > 0) { - deviceopencount--; - return(-1); - } // ENDIF- Simulate a temporarily open device? - +s32 CALLBACK CDVDreadTrack(u32 lsn, int mode) +{ + int retval; + if (isofile == NULL) return(-1); + if (deviceopencount > 0) + { + deviceopencount--; + return(-1); + } // ENDIF- Simulate a temporarily open device? #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDreadTrack(%u)", lsn); + PrintLog("CDVDiso interface: CDVDreadTrack(%u)", lsn); #endif /* VERBOSE_FUNCTION_INTERFACE */ - - retval = IsoFileSeek(isofile, (off64_t) lsn); - if(retval != 0) { + retval = IsoFileSeek(isofile, (off64_t) lsn); + if (retval != 0) + { #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: Trouble finding the sector!"); + PrintLog("CDVDiso interface: Trouble finding the sector!"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - return(-1); - } // ENDIF- Trouble finding the sector? - - retval = IsoFileRead(isofile, isobuffer); - if(retval != 0) { + return(-1); + } // ENDIF- Trouble finding the sector? + retval = IsoFileRead(isofile, isobuffer); + if (retval != 0) + { #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: Trouble reading the sector!"); + PrintLog("CDVDiso interface: Trouble reading the sector!"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - return(-1); - } // ENDIF- Trouble finding the sector? - - isomode = mode; - return(0); + return(-1); + } // ENDIF- Trouble finding the sector? + isomode = mode; + return(0); } // END CDVDreadTrack() - -u8* CALLBACK CDVDgetBuffer() { - int offset; - - if(isofile == NULL) return(NULL); - if(deviceopencount > 0) return(NULL); - +u8* CALLBACK CDVDgetBuffer() +{ + int offset; + if (isofile == NULL) return(NULL); + if (deviceopencount > 0) return(NULL); #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDgetBuffer()"); + PrintLog("CDVDiso interface: CDVDgetBuffer()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - offset = 0; - switch(isomode) { - case CDVD_MODE_2352: - offset = 0; - break; - case CDVD_MODE_2340: - offset = 12; - break; - case CDVD_MODE_2328: - case CDVD_MODE_2048: - offset = 24; - break; - } // ENDSWITCH isomode- offset to where data it wants is. - - if(offset > isofile->blockoffset) offset = isofile->blockoffset; - - return(isobuffer + offset); + offset = 0; + switch (isomode) + { + case CDVD_MODE_2352: + offset = 0; + break; + case CDVD_MODE_2340: + offset = 12; + break; + case CDVD_MODE_2328: + case CDVD_MODE_2048: + offset = 24; + break; + } // ENDSWITCH isomode- offset to where data it wants is. + if (offset > isofile->blockoffset) offset = isofile->blockoffset; + return(isobuffer + offset); } // END CDVDgetBuffer() - - -s32 CALLBACK CDVDgetDiskType() { +s32 CALLBACK CDVDgetDiskType() +{ #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDgetDiskType()"); + PrintLog("CDVDiso interface: CDVDgetDiskType()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - if(isofile == NULL) return(CDVD_TYPE_NODISC); - if(deviceopencount > 0) { - deviceopencount--; - return(CDVD_TYPE_DETCT); - } // ENDIF- Simulate a temporarily open device? + if (isofile == NULL) return(CDVD_TYPE_NODISC); + if (deviceopencount > 0) + { + deviceopencount--; + return(CDVD_TYPE_DETCT); + } // ENDIF- Simulate a temporarily open device? - return(isofile->cdvdtype); + return(isofile->cdvdtype); } // END CDVDgetDiskType() - - -s32 CALLBACK CDVDgetTrayStatus() { +s32 CALLBACK CDVDgetTrayStatus() +{ #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDgetTrayStatus()"); + PrintLog("CDVDiso interface: CDVDgetTrayStatus()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - - if(isofile == NULL) return(CDVD_TRAY_OPEN); - if(deviceopencount > 30) { - deviceopencount--; - return(CDVD_TRAY_OPEN); - } // ENDIF- Simulate a temporarily open device? - - return(CDVD_TRAY_CLOSE); + if (isofile == NULL) return(CDVD_TRAY_OPEN); + if (deviceopencount > 30) + { + deviceopencount--; + return(CDVD_TRAY_OPEN); + } // ENDIF- Simulate a temporarily open device? + return(CDVD_TRAY_CLOSE); } // END CDVDgetTrayStatus() - - -s32 CALLBACK CDVDctrlTrayOpen() { - int i; +s32 CALLBACK CDVDctrlTrayOpen() +{ + int i; #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDctrlTrayOpen()"); + PrintLog("CDVDiso interface: CDVDctrlTrayOpen()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - // Close() - isofile = IsoFileClose(isofile); - deviceopencount = 50; + // Close() + isofile = IsoFileClose(isofile); + deviceopencount = 50; - // and re-Open() - if((conf.isoname[0] == 0) || - ((conf.restartconfigure != 0) && (deviceopencount > 0))) { - ExecCfg("configure"); - LoadConf(); - } // ENDIF- Haven't initialized the configure program yet? Do so now. - - isofile = IsoFileOpenForRead(conf.isoname); - if(isofile == NULL) { + // and re-Open() + if ((conf.isoname[0] == 0) || + ((conf.restartconfigure != 0) && (deviceopencount > 0))) + { + ExecCfg("configure"); + LoadConf(); + } // ENDIF- Haven't initialized the configure program yet? Do so now. + isofile = IsoFileOpenForRead(conf.isoname); + if (isofile == NULL) + { #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: Failed to open ISO file!"); + PrintLog("CDVDiso interface: Failed to open ISO file!"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - } // ENDIF- Trouble opening file? Abort. - - if(deviceopencount > 0) { - i = 0; - while((i < 2048) && (isocdcheck[i] == isobuffer[i])) i++; - if(i == 2048) deviceopencount = 0; // Same CD/DVD? No delay. - } // ENDIF- Is this a restart? Check for disc change. - - for(i = 0; i < 2048; i++) isocdcheck[i] = isobuffer[i]; - - return(0); + } // ENDIF- Trouble opening file? Abort. + if (deviceopencount > 0) + { + i = 0; + while ((i < 2048) && (isocdcheck[i] == isobuffer[i])) i++; + if (i == 2048) deviceopencount = 0; // Same CD/DVD? No delay. + } // ENDIF- Is this a restart? Check for disc change. + for (i = 0; i < 2048; i++) isocdcheck[i] = isobuffer[i]; + return(0); } // END CDVDctrlTrayOpen() - -s32 CALLBACK CDVDctrlTrayClose() { +s32 CALLBACK CDVDctrlTrayClose() +{ #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDctrlTrayClose()"); + PrintLog("CDVDiso interface: CDVDctrlTrayClose()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - return(0); + return(0); } // END CDVDctrlTrayClose() - - -void CALLBACK CDVDconfigure() { - ExecCfg("configure"); +void CALLBACK CDVDconfigure() +{ + ExecCfg("configure"); } // END CDVDconfigure() - - -s32 CALLBACK CDVDtest() { +s32 CALLBACK CDVDtest() +{ #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDtest()"); + PrintLog("CDVDiso interface: CDVDtest()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - InitConf(); // Odd... hasn't CDVDinit been called yet? - LoadConf(); + InitConf(); // Odd... hasn't CDVDinit been called yet? + LoadConf(); - if(conf.isoname[0] == 0) return(0); // No name chosen yet. Catch on Open() - if(IsIsoFile(conf.isoname) == 0) return(0); // Valid name. Go. - return(-1); // Invalid name - reconfigure first. - // Note really need this? Why not just return(0)... + if (conf.isoname[0] == 0) return(0); // No name chosen yet. Catch on Open() + if (IsIsoFile(conf.isoname) == 0) return(0); // Valid name. Go. + return(-1); // Invalid name - reconfigure first. + // Note really need this? Why not just return(0)... } // END CDVDtest() - -void CALLBACK CDVDabout() { - ExecCfg("about"); +void CALLBACK CDVDabout() +{ + ExecCfg("about"); } // END CDVDabout() - diff --git a/plugins/CDVDisoEFP/src/Linux/CDVDiso.h b/plugins/CDVDisoEFP/src/Linux/CDVDiso.h index 268bbb2e0d..20989b9aee 100644 --- a/plugins/CDVDisoEFP/src/Linux/CDVDiso.h +++ b/plugins/CDVDisoEFP/src/Linux/CDVDiso.h @@ -1,58 +1,26 @@ /* CDVDiso.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef CDVDISO_H - #define CDVDISO_H - - - - // #define VERBOSE_FUNCTION_INTERFACE - - - - #endif /* CDVDISO_H */ - diff --git a/plugins/CDVDisoEFP/src/Linux/DVD.c b/plugins/CDVDisoEFP/src/Linux/DVD.c index 46bfeb678b..1e4de3370e 100644 --- a/plugins/CDVDisoEFP/src/Linux/DVD.c +++ b/plugins/CDVDisoEFP/src/Linux/DVD.c @@ -1,1164 +1,653 @@ -/* DVD.c - - * Copyright (C) 2002-2005 PCSX2 Team - - * - - * This program is free software; you can redistribute it and/or modify - - * it under the terms of the GNU General Public License as published by - - * the Free Software Foundation; either version 2 of the License, or - - * (at your option) any later version. - - * - - * This program is distributed in the hope that it will be useful, - - * but WITHOUT ANY WARRANTY; without even the implied warranty of - - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - - * GNU General Public License for more details. - - * - - * You should have received a copy of the GNU General Public License - - * along with this program; if not, write to the Free Software - - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - * - - * PCSX2 members can be contacted through their website at www.pcsx2.net. - - */ - - - -#include // errno - -#include // NULL - -#include // sprintf() - -#include // strerror(), memset(), memcpy() - -#include // open() - -#include // ioctl() - -#include // open() - -#include // lseek(), open() - -#include // close(), lseek(), (sleep()) - - - -#include // CD/DVD based ioctl() and defines. - - - -#include "logfile.h" - -#include "device.h" - -#include "DVD.h" - - - - - -// Constants - -u8 *playstationname = "PLAYSTATION\0"; - - - -// DVD storage structures (see linux/cdrom.h for details) - -dvd_struct dvdphysical; - -dvd_struct dvdcopyright[DVD_LAYERS]; - -dvd_struct dvdbca; - -dvd_struct dvdmanufact[DVD_LAYERS]; - - - -u32 dvdlastlsn; - -u8 dvdtempbuffer[2064]; - - - - - -// Internal Functions - - - -void InitDVDSectorInfo() { - - dvdlastlsn = 0xffffffff; - -} // END InitSectorInfo(); - - - -void HexDump(u8 *strptr, u8 count) { - - int i; - - u8 ch[2]; - - char hexline[81]; - - int hexlinepos; - - - - ch[1] = 0; - - - - if(count == 0) count = 16; - - if((count < 1) || (count > 16)) return; - - - - hexlinepos = 0; - - hexlinepos += sprintf(&hexline[hexlinepos], "CDVD driver: "); - - - - for(i = 0; i < count; i++) { - - hexlinepos += sprintf(&hexline[hexlinepos], "%.2x ", (*(strptr + i)) * 1); - - } // NEXT i- printing each new Hex number - - - - for(i = 0; i < count; i++) { - - if((*(strptr + i) < 32) || (*(strptr + i) > 127)) { - - hexlinepos += sprintf(&hexline[hexlinepos], "."); - - } else { - - ch[0] = *(strptr + i); - - hexlinepos += sprintf(&hexline[hexlinepos], "%s", ch); - - } // ENDIF- Is this an unprintable character? - - } // NEXT i- printing each new character - - PrintLog(hexline); - -} // ENDIF HexDump() - - - - - -//// DVD Structure Functions - - - -s32 DVDreadPhysical() { - - s32 s32result; - - u8 i; - - - - errno = 0; - - - -#ifdef VERBOSE_FUNCTION - - PrintLog("CDVD driver: DVDreadPhysical()\n"); - -#endif /* VERBOSE_FUNCTION */ - - - - memset(&dvdphysical, 0, sizeof(dvd_struct)); - - dvdphysical.type = DVD_STRUCT_PHYSICAL; - - - - i = DVD_LAYERS; - - while(i > 0) { - - i--; - - dvdphysical.physical.layer_num = i; - - errno = 0; - - s32result = ioctl(devicehandle, DVD_READ_STRUCT, &dvdphysical); - - } // ENDWHILE- reading in all physical layers... - - - - if((s32result == -1) || (errno != 0)) { - - dvdphysical.type = 0xFF; - -#ifdef VERBOSE_WARNINGS - - PrintLog("CDVD driver: Error getting Physical structure: (%i) %i:%s", s32result, errno, strerror(errno)); - -#endif /* VERBOSE_WARNINGS */ - - return(-1); - - } // ENDIF- Problem with reading Layer 0 of the physical data? Abort - - - - i = 3; - - while((i > 0) && (dvdphysical.physical.layer[i].end_sector == 0)) i--; - - dvdphysical.physical.layer_num = i; - - - -#ifdef VERBOSE_DISC_INFO - - PrintLog("CDVD driver: Physical Characteristics"); - - PrintLog("CDVD driver: Number of Layers: %i", - - (s32) dvdphysical.physical.layer_num + 1); - - for(i = 0; i <= dvdphysical.physical.layer_num; i++) { - - PrintLog("CDVD driver: Layer Number %i", i); - - switch(dvdphysical.physical.layer[i].book_type) { - - case 0: - - PrintLog("CDVD driver: Book Type: DVD-ROM"); - - break; - - case 1: - - PrintLog("CDVD driver: Book Type: DVD-RAM"); - - break; - - case 2: - - PrintLog("CDVD driver: Book Type: DVD-R"); - - break; - - case 3: - - PrintLog("CDVD driver: Book Type: DVD-RW"); - - break; - - case 9: - - PrintLog("CDVD driver: Book Type: DVD+RW"); - - break; - - default: - - PrintLog("CDVD driver: Book Type: Unknown (%i)", - - dvdphysical.physical.layer[i].book_type); - - break; - - } // ENDSWITCH- Displaying the Book Type - - PrintLog("CDVD driver: Book Version %i", - - dvdphysical.physical.layer[i].book_version); - - switch(dvdphysical.physical.layer[i].min_rate) { - - case 0: - - PrintLog("CDVD driver: Use Minimum Rate for: DVD-ROM"); - - break; - - case 1: - - PrintLog("CDVD driver: Use Minimum Rate for: DVD-RAM"); - - break; - - case 2: - - PrintLog("CDVD driver: Use Minimum Rate for: DVD-R"); - - break; - - case 3: - - PrintLog("CDVD driver: Use Minimum Rate for: DVD-RW"); - - break; - - case 9: - - PrintLog("CDVD driver: Use Minimum Rate for: DVD+RW"); - - break; - - default: - - PrintLog("CDVD driver: Use Minimum Rate for: Unknown (%i)", - - dvdphysical.physical.layer[i].min_rate); - - break; - - } // ENDSWITCH- Displaying the Minimum (Spin?) Rate - - switch(dvdphysical.physical.layer[i].disc_size) { - - case 0: - - PrintLog("CDVD driver: Physical Disk Size: 120mm"); - - break; - - case 1: - - PrintLog("CDVD driver: Physical Disk Size: 80mm"); - - break; - - default: - - PrintLog("CDVD driver: Physical Disk Size: Unknown (%i)", - - dvdphysical.physical.layer[i].disc_size); - - break; - - } // ENDSWITCH- What's the Disk Size? - - switch(dvdphysical.physical.layer[i].layer_type) { - - case 1: - - PrintLog("CDVD driver: Layer Type: Read-Only"); - - break; - - case 2: - - PrintLog("CDVD driver: Layer Type: Recordable"); - - break; - - case 4: - - PrintLog("CDVD driver: Layer Type: Rewritable"); - - break; - - default: - - PrintLog("CDVD driver: Layer Type: Unknown (%i)", - - dvdphysical.physical.layer[i].layer_type); - - break; - - } // ENDSWITCH- Displaying the Layer Type - - switch(dvdphysical.physical.layer[i].track_path) { - - case 0: - - PrintLog("CDVD driver: Track Path: PTP"); - - break; - - case 1: - - PrintLog("CDVD driver: Track Path: OTP"); - - break; - - default: - - PrintLog("CDVD driver: Track Path: Unknown (%i)", - - dvdphysical.physical.layer[i].track_path); - - break; - - } // ENDSWITCH- What's Track Path Layout? - - // PrintLog("CDVD driver: Disc Size %i Layer Type %i Track Path %i Nlayers %i", - - // dvdphysical.physical.layer[i].nlayers); - - switch(dvdphysical.physical.layer[i].track_density) { - - case 0: - - PrintLog("CDVD driver: Track Density: .74 m/track"); - - break; - - case 1: - - PrintLog("CDVD driver: Track Density: .8 m/track"); - - break; - - case 2: - - PrintLog("CDVD driver: Track Density: .615 m/track"); - - break; - - default: - - PrintLog("CDVD driver: Track Density: Unknown (%i)", - - dvdphysical.physical.layer[i].track_density); - - break; - - } // ENDSWITCH- Displaying the Track Density - - switch(dvdphysical.physical.layer[i].linear_density) { - - case 0: - - PrintLog("CDVD driver: Linear Density: .267 m/bit"); - - break; - - case 1: - - PrintLog("CDVD driver: Linear Density: .293 m/bit"); - - break; - - case 2: - - PrintLog("CDVD driver: Linear Density: .409 to .435 m/bit"); - - break; - - case 4: - - PrintLog("CDVD driver: Linear Density: .280 to .291 m/bit"); - - break; - - case 8: - - PrintLog("CDVD driver: Linear Density: .353 m/bit"); - - break; - - default: - - PrintLog("CDVD driver: Linear Density: Unknown (%i)", - - dvdphysical.physical.layer[i].linear_density); - - break; - - } // ENDSWITCH- Displaying the Linear Density - - if(dvdphysical.physical.layer[i].start_sector == 0x30000) { - - PrintLog("CDVD driver: Starting Sector: %lu (DVD-ROM, DVD-R, DVD-RW)", - - dvdphysical.physical.layer[i].start_sector); - - } else if(dvdphysical.physical.layer[i].start_sector == 0x31000) { - - PrintLog("CDVD driver: Starting Sector: %lu (DVD-RAM, DVD+RW)", - - dvdphysical.physical.layer[i].start_sector); - - } else { - - PrintLog("CDVD driver: Starting Sector: %lu", - - dvdphysical.physical.layer[i].start_sector); - - } // ENDLONGIF- What does the starting sector tell us? - - PrintLog("CDVD driver: End of Layer 0: %lu", - - dvdphysical.physical.layer[i].end_sector_l0); - - PrintLog("CDVD driver: Ending Sector: %lu", - - dvdphysical.physical.layer[i].end_sector); - - if(dvdphysical.physical.layer[i].bca != 0) - - PrintLog("CDVD driver: BCA data present"); - - } // NEXT i- Work our way through each layer... - -#endif /* VERBOSE_DISC_INFO */ - - - - return(0); // Success. Physical data stored for perusal. - -} // END DVDreadPhysical() - - - -s32 DVDreadCopyright() { - - s32 s32result; - - u8 i; - - int successflag; - - - -#ifdef VERBOSE_FUNCTION - - PrintLog("CDVD driver: DVDreadCopyright()"); - -#endif /* VERBOSE_FUNCTION */ - - - - successflag = 0; - - - - for(i = 0; i <= dvdphysical.physical.layer_num; i++) { - - memset(&dvdcopyright[i], 0, sizeof(dvd_struct)); - - dvdcopyright[i].type = DVD_STRUCT_COPYRIGHT; - - dvdcopyright[i].copyright.layer_num = i; - - errno = 0; - - s32result = ioctl(devicehandle, DVD_READ_STRUCT, &dvdcopyright[i]); - - if(s32result == 0) { - - successflag = 1; - - } else { - - dvdcopyright[i].type = 0xFF; - - } // ENDIF- - - } // NEXT i- Getting copyright data for every known layer - - - - if(successflag == 0) { - -#ifdef VERBOSE_WARNINGS - - PrintLog("CDVD driver: Error getting Copyright info: (%i) %i:%s", s32result, errno, strerror(errno)); - -#endif /* VERBOSE_WARNINGS */ - - return(-1); - - } // ENDIF- Problem with read of physical data? - - - -#ifdef VERBOSE_DISC_INFO - - PrintLog("CDVD driver: Copyright Information\n"); - - for(i = 0; i <= dvdphysical.physical.layer_num; i++) { - - if(dvdcopyright[i].type != 0xFF) { - - PrintLog("CDVD driver: Layer Number %i CPST %i RMI %i", - - dvdcopyright[i].copyright.layer_num, - - dvdcopyright[i].copyright.cpst, - - dvdcopyright[i].copyright.rmi); - - } // ENDIF- Were we successful reading this one? - - } // NEXT i- Printing out all copyright info found... - -#endif /* VERBOSE_DISC_INFO */ - - - - errno = 0; - - return(0); // Success. Copyright data stored for perusal. - -} // END DVDreadCopyright() - - - -s32 DVDreadBCA() { - - s32 s32result; - - int i; - - - - i = 0; - - errno = 0; - - - -#ifdef VERBOSE_FUNCTION - - PrintLog("CDVD driver: DVDreadBCA()"); - -#endif /* VERBOSE_FUNCTION */ - - - - memset(&dvdbca, 0, sizeof(dvd_struct)); - - dvdbca.type = DVD_STRUCT_BCA; - - s32result = ioctl(devicehandle, DVD_READ_STRUCT, &dvdbca); - - if((s32result == -1) || (errno != 0)) { - - dvdbca.type = 0xFF; - -#ifdef VERBOSE_WARNINGS - - PrintLog("CDVD driver: Error getting BCA: (%i) %i:%s", s32result, errno, strerror(errno)); - -#endif /* VERBOSE_WARNINGS */ - - return(-1); - - } // ENDIF- Problem with read of physical data? - - - -#ifdef VERBOSE_DISC_INFO - - PrintLog("CDVD driver: BCA Length %i Value:", - - dvdbca.bca.len); - - for(i = 0; i < 188-15; i += 16) { - - HexDump(dvdbca.bca.value+i, 16); - - } // NEXT i- dumping whole key data - -#endif /* VERBOSE_DISC_INFO */ - - - - return(0); // Success. BCA data stored for perusal. - -} // END DVDreadBCA() - - - -s32 DVDreadManufact() { - - s32 s32result; - - u8 i; - - int successflag; - - int j; - - - -#ifdef VERBOSE_FUNCTION - - PrintLog("CDVD driver: DVDreadManufact()"); - -#endif /* VERBOSE_FUNCTION */ - - - - j = 0; - - successflag = 0; - - - - for(i = 0; i <= dvdphysical.physical.layer_num; i++) { - - memset(&dvdmanufact[i], 0, sizeof(dvd_struct)); - - dvdmanufact[i].type = DVD_STRUCT_MANUFACT; - - dvdmanufact[i].manufact.layer_num = i; - - errno = 0; - - s32result = ioctl(devicehandle, DVD_READ_STRUCT, &dvdmanufact[i]); - - if((s32result != 0) || (errno != 0)) { - - dvdmanufact[i].type = 0xFF; - - } else { - - successflag = 1; - - } // ENDIF- Did we fail to read in some manufacturer data? - - } // NEXT i- Collecting manufacturer data from all layers - - - - if(successflag == 0) { - -#ifdef VERBOSE_WARNINGS - - PrintLog("CDVD driver: Error getting Manufact: (%i) %i:%s", s32result, errno, strerror(errno)); - -#endif /* VERBOSE_WARNINGS */ - - return(-1); - - } // ENDIF- Problem with read of physical data? - - - -#ifdef VERBOSE_DISC_INFO - - PrintLog("CDVD driver: Manufact Data"); - - for(i = 0; i <= dvdphysical.physical.layer_num; i++) { - - if(dvdmanufact[i].type != 0xFF) { - - PrintLog("CDVD driver: Layer %i Length %i Value:", - - dvdmanufact[i].manufact.layer_num, - - dvdmanufact[i].manufact.len); - - for(j = 0; j < 128-15; j += 16) { - - HexDump(dvdmanufact[i].manufact.value+j, 16); - - } // NEXT j- dumping whole key data - - } // ENDIF- Do we have data at this layer? - - } // NEXT i- Running through all the layers - -#endif /* VERBOSE_DISC_INFO */ - - - - errno = 0; - - return(0); // Success. Manufacturer's data stored for perusal. - -} // END DVDreadManufact() - - - - - -// External Functions - - - -// Function Calls from CDVD.c - - - -void InitDVDInfo() { - - int j; - - - - dvdphysical.type = 0xFF; // Using for empty=0xff, full!=0xff test - - dvdbca.type = 0xFF; - - for(j = 0; j < DVD_LAYERS; j++) { - - dvdcopyright[j].type = 0xFF; - - dvdmanufact[j].type = 0xFF; - - } // NEXT j- Zeroing each layer of data - - InitDVDSectorInfo(); - -} // END InitDiscType() - - - -s32 DVDreadTrack(u32 lsn, int mode, u8 *buffer) { - - s32 s32result; - - off64_t offsettarget; - - off64_t offsetresult; - - - - errno = 0; - - s32result = 0; - - offsetresult = 0; - - - -#ifdef VERBOSE_FUNCTION - - PrintLog("CDVD driver: DVDreadTrack(%i)", lsn); - -#endif /* VERBOSE_FUNCTION */ - - - - if(lsn != dvdlastlsn + 1) { - - offsettarget = lsn; - - offsettarget *= 2048; - - errno = 4; - - while(errno == 4) { - - errno = 0; - - offsetresult = lseek64(devicehandle, offsettarget, SEEK_SET); - - } // ENDWHILE- waiting for the system interruptions to cease. - - if((offsetresult < 0) || (errno != 0)) { - -#ifdef VERBOSE_WARNINGS - - PrintLog("CDVD driver: Error on seek: %i:%s", errno, strerror(errno)); - -#endif /* VERBOSE_WARNINGS */ - - InitDVDSectorInfo(); - - return(-1); - - } // ENDIF- trouble with seek? Reset pointer and abort - - } // ENDIF- Do we have to seek a new position to read? - - - - errno = 4; - - while(errno == 4) { - - errno = 0; - - s32result = read(devicehandle, buffer, 2048); - - } // ENDWHILE- waiting for the system interruptions to cease. - - if((s32result != 2048) || (errno != 0)) { - -#ifdef VERBOSE_WARNINGS - - PrintLog("CDVD driver: DVD Short Block, Size: %i", s32result); - - PrintLog("CDVD driver: Error: %i:%s", errno, strerror(errno)); - -#endif /* VERBOSE_WARNINGS */ - - InitDVDSectorInfo(); - - return(-1); - - } // ENDIF- Trouble reading the data? Reset pointer and abort - - - - dvdlastlsn = lsn; - - return(0); // Call accomplished - -} // END DVDreadTrack() - - - -s32 DVDgetTN(cdvdTN *cdvdtn) { - -#ifdef VERBOSE_FUNCTION - - PrintLog("CDVD driver: CDVDgetTN()"); - -#endif /* VERBOSE_FUNCTION */ - - - - // Going to treat this as one large track for now. - - if(cdvdtn != NULL) { - - cdvdtn->strack = 1; - - cdvdtn->etrack = 1; - - } // ENDIF- programmer actually WANTS this info? - - - - return(0); // Call accomplished - -} // END DVDgetTN() - - - -s32 DVDgetTD(u8 newtrack, cdvdTD *cdvdtd) { - -#ifdef VERBOSE_FUNCTION - - PrintLog("CDVD driver: CDVDgetTD()"); - -#endif /* VERBOSE_FUNCTION */ - - - - if((newtrack >= 2) && (newtrack != CDROM_LEADOUT)) return(-1); - - - - if(cdvdtd != NULL) { - - cdvdtd->lsn = dvdphysical.physical.layer[0].end_sector - - - dvdphysical.physical.layer[0].start_sector - - + 1; - - cdvdtd->type = CDVD_MODE_2048; - - } // ENDIF- Does the caller REALLY want this data? - - - - return(0); // Call accomplished - -} // END DVDgetTD() - - - -s32 DVDgetDiskType(s32 ioctldisktype) { - - s32 s32result; - - int i; - - s32 tempdisctype; - - - - errno = 0; - - s32result = 0; - - i = 0; - - tempdisctype = CDVD_TYPE_UNKNOWN; - - - -#ifdef VERBOSE_FUNCTION - - PrintLog("CDVD driver: DVDgetDiskType()"); - -#endif /* VERBOSE_FUNCTION */ - - - - if((ioctldisktype != CDS_DATA_1) && (ioctldisktype != CDS_MIXED)) { - - return(-1); - - } // ENDIF- Not a data disc we know of? Abort then - - - - s32result = DVDreadPhysical(); - - if((s32result != 0) || (errno != 0)) { - - return(-1); - - } // ENDIF- Error reading the DVD physical structure? Not a DVD after all. - - - - if(dvdphysical.physical.layer[0].end_sector >= (2048*1024)) { - -#ifdef VERBOSE_DISC_TYPE - - PrintLog("CDVD driver: DVD Found (Dual-Sided)"); - -#endif /* VERBOSE_DISC_TYPE */ - - disctype = CDVD_TYPE_DETCTDVDD; - - } else { - -#ifdef VERBOSE_DISC_TYPE - - PrintLog("CDVD driver: DVD Found (Single-Sided)"); - -#endif /* VERBOSE_DISC_TYPE */ - - disctype = CDVD_TYPE_DETCTDVDS; - - } // ENDIF- Definitely a DVD. Size Test? - - - - // Read in the rest of the structures... - - DVDreadCopyright(); - - DVDreadBCA(); - - DVDreadManufact(); - - - - // Test for "Playstation" header - - s32result = DVDreadTrack(16, CDVD_MODE_2048, dvdtempbuffer); - - if(s32result != 0) { - - return(-1); - - } else { - - i = 0; - - while((*(playstationname + i) != 0) && - - (*(playstationname + i) == dvdtempbuffer[8 + i])) { - - i++; - - } // ENDWHILE- Checking each letter of PLAYSTATION name for a match - - if(*(playstationname + i) == 0) { - -#ifdef VERBOSE_DISC_TYPE - - PrintLog("CDVD driver: Detected Playstation 2 DVD"); - -#endif /* VERBOSE_DISC_TYPE */ - - tempdisctype = CDVD_TYPE_PS2DVD; - - } else { - -#ifdef VERBOSE_DISC_TYPE - - PrintLog("CDVD driver: Guessing it's a Video DVD"); - -#endif /* VERBOSE_DISC_TYPE */ - - tempdisctype = CDVD_TYPE_DVDV; - - } // ENDIF- Did we find the Playstation name? - - } // ENDIF- Error reading disc volume information? Invalidate Disc - - - - if(dvdphysical.physical.layer[0].end_sector >= (2048*1024)) { - - tocbuffer[0] = 0x24; // Dual-Sided DVD - - tocbuffer[4] = 0x41; - - tocbuffer[5] = 0x95; - - } else { - - tocbuffer[0] = 0x04; // Single-Sided DVD - - tocbuffer[4] = 0x86; - - tocbuffer[5] = 0x72; - - } // ENDIF- Are there too many sectors for a single-sided disc? - - - - tocbuffer[1] = 0x02; - - tocbuffer[2] = 0xF2; - - tocbuffer[3] = 0x00; - - - - tocbuffer[16] = 0x00; - - tocbuffer[17] = 0x03; - - tocbuffer[18] = 0x00; - - tocbuffer[19] = 0x00; - - - - disctype = tempdisctype; // Triggers the fact the other info is available - - return(disctype); - -} // END DVDgetDiskType() - +/* DVD.c + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + +#include // errno +#include // NULL +#include // sprintf() +#include // strerror(), memset(), memcpy() +#include // open() +#include // ioctl() +#include // open() +#include // lseek(), open() +#include // close(), lseek(), (sleep()) + +#include // CD/DVD based ioctl() and defines. + +#include "logfile.h" +#include "device.h" +#include "DVD.h" + + +// Constants +u8 *playstationname = "PLAYSTATION\0"; + +// DVD storage structures (see linux/cdrom.h for details) +dvd_struct dvdphysical; +dvd_struct dvdcopyright[DVD_LAYERS]; +dvd_struct dvdbca; +dvd_struct dvdmanufact[DVD_LAYERS]; + +u32 dvdlastlsn; +u8 dvdtempbuffer[2064]; + + +// Internal Functions + +void InitDVDSectorInfo() +{ + dvdlastlsn = 0xffffffff; +} // END InitSectorInfo(); + +void HexDump(u8 *strptr, u8 count) +{ + int i; + u8 ch[2]; + char hexline[81]; + int hexlinepos; + + ch[1] = 0; + + if (count == 0) count = 16; + if ((count < 1) || (count > 16)) return; + + hexlinepos = 0; + hexlinepos += sprintf(&hexline[hexlinepos], "CDVD driver: "); + + for (i = 0; i < count; i++) + { + hexlinepos += sprintf(&hexline[hexlinepos], "%.2x ", (*(strptr + i)) * 1); + } // NEXT i- printing each new Hex number + + for (i = 0; i < count; i++) + { + if ((*(strptr + i) < 32) || (*(strptr + i) > 127)) + { + hexlinepos += sprintf(&hexline[hexlinepos], "."); + } + else + { + ch[0] = *(strptr + i); + hexlinepos += sprintf(&hexline[hexlinepos], "%s", ch); + } // ENDIF- Is this an unprintable character? + } // NEXT i- printing each new character + PrintLog(hexline); +} // ENDIF HexDump() + + +//// DVD Structure Functions + +s32 DVDreadPhysical() +{ + s32 s32result; + u8 i; + + errno = 0; + +#ifdef VERBOSE_FUNCTION + PrintLog("CDVD driver: DVDreadPhysical()\n"); +#endif /* VERBOSE_FUNCTION */ + + memset(&dvdphysical, 0, sizeof(dvd_struct)); + dvdphysical.type = DVD_STRUCT_PHYSICAL; + + i = DVD_LAYERS; + while (i > 0) + { + i--; + dvdphysical.physical.layer_num = i; + errno = 0; + s32result = ioctl(devicehandle, DVD_READ_STRUCT, &dvdphysical); + } // ENDWHILE- reading in all physical layers... + + if ((s32result == -1) || (errno != 0)) + { + dvdphysical.type = 0xFF; +#ifdef VERBOSE_WARNINGS + PrintLog("CDVD driver: Error getting Physical structure: (%i) %i:%s", s32result, errno, strerror(errno)); +#endif /* VERBOSE_WARNINGS */ + return(-1); + } // ENDIF- Problem with reading Layer 0 of the physical data? Abort + + i = 3; + while ((i > 0) && (dvdphysical.physical.layer[i].end_sector == 0)) i--; + dvdphysical.physical.layer_num = i; + +#ifdef VERBOSE_DISC_INFO + PrintLog("CDVD driver: Physical Characteristics"); + PrintLog("CDVD driver: Number of Layers: %i", + (s32) dvdphysical.physical.layer_num + 1); + for (i = 0; i <= dvdphysical.physical.layer_num; i++) + { + PrintLog("CDVD driver: Layer Number %i", i); + switch (dvdphysical.physical.layer[i].book_type) + { + case 0: + PrintLog("CDVD driver: Book Type: DVD-ROM"); + break; + case 1: + PrintLog("CDVD driver: Book Type: DVD-RAM"); + break; + case 2: + PrintLog("CDVD driver: Book Type: DVD-R"); + break; + case 3: + PrintLog("CDVD driver: Book Type: DVD-RW"); + break; + case 9: + PrintLog("CDVD driver: Book Type: DVD+RW"); + break; + default: + PrintLog("CDVD driver: Book Type: Unknown (%i)", + dvdphysical.physical.layer[i].book_type); + break; + } // ENDSWITCH- Displaying the Book Type + PrintLog("CDVD driver: Book Version %i", + dvdphysical.physical.layer[i].book_version); + switch (dvdphysical.physical.layer[i].min_rate) + { + case 0: + PrintLog("CDVD driver: Use Minimum Rate for: DVD-ROM"); + break; + case 1: + PrintLog("CDVD driver: Use Minimum Rate for: DVD-RAM"); + break; + case 2: + PrintLog("CDVD driver: Use Minimum Rate for: DVD-R"); + break; + case 3: + PrintLog("CDVD driver: Use Minimum Rate for: DVD-RW"); + break; + case 9: + PrintLog("CDVD driver: Use Minimum Rate for: DVD+RW"); + break; + default: + PrintLog("CDVD driver: Use Minimum Rate for: Unknown (%i)", + dvdphysical.physical.layer[i].min_rate); + break; + } // ENDSWITCH- Displaying the Minimum (Spin?) Rate + switch (dvdphysical.physical.layer[i].disc_size) + { + case 0: + PrintLog("CDVD driver: Physical Disk Size: 120mm"); + break; + case 1: + PrintLog("CDVD driver: Physical Disk Size: 80mm"); + break; + default: + PrintLog("CDVD driver: Physical Disk Size: Unknown (%i)", + dvdphysical.physical.layer[i].disc_size); + break; + } // ENDSWITCH- What's the Disk Size? + switch (dvdphysical.physical.layer[i].layer_type) + { + case 1: + PrintLog("CDVD driver: Layer Type: Read-Only"); + break; + case 2: + PrintLog("CDVD driver: Layer Type: Recordable"); + break; + case 4: + PrintLog("CDVD driver: Layer Type: Rewritable"); + break; + default: + PrintLog("CDVD driver: Layer Type: Unknown (%i)", + dvdphysical.physical.layer[i].layer_type); + break; + } // ENDSWITCH- Displaying the Layer Type + switch (dvdphysical.physical.layer[i].track_path) + { + case 0: + PrintLog("CDVD driver: Track Path: PTP"); + break; + case 1: + PrintLog("CDVD driver: Track Path: OTP"); + break; + default: + PrintLog("CDVD driver: Track Path: Unknown (%i)", + dvdphysical.physical.layer[i].track_path); + break; + } // ENDSWITCH- What's Track Path Layout? + // PrintLog("CDVD driver: Disc Size %i Layer Type %i Track Path %i Nlayers %i", + // dvdphysical.physical.layer[i].nlayers); + switch (dvdphysical.physical.layer[i].track_density) + { + case 0: + PrintLog("CDVD driver: Track Density: .74 m/track"); + break; + case 1: + PrintLog("CDVD driver: Track Density: .8 m/track"); + break; + case 2: + PrintLog("CDVD driver: Track Density: .615 m/track"); + break; + default: + PrintLog("CDVD driver: Track Density: Unknown (%i)", + dvdphysical.physical.layer[i].track_density); + break; + } // ENDSWITCH- Displaying the Track Density + switch (dvdphysical.physical.layer[i].linear_density) + { + case 0: + PrintLog("CDVD driver: Linear Density: .267 m/bit"); + break; + case 1: + PrintLog("CDVD driver: Linear Density: .293 m/bit"); + break; + case 2: + PrintLog("CDVD driver: Linear Density: .409 to .435 m/bit"); + break; + case 4: + PrintLog("CDVD driver: Linear Density: .280 to .291 m/bit"); + break; + case 8: + PrintLog("CDVD driver: Linear Density: .353 m/bit"); + break; + default: + PrintLog("CDVD driver: Linear Density: Unknown (%i)", + dvdphysical.physical.layer[i].linear_density); + break; + } // ENDSWITCH- Displaying the Linear Density + if (dvdphysical.physical.layer[i].start_sector == 0x30000) + { + PrintLog("CDVD driver: Starting Sector: %lu (DVD-ROM, DVD-R, DVD-RW)", + dvdphysical.physical.layer[i].start_sector); + } + else if (dvdphysical.physical.layer[i].start_sector == 0x31000) + { + PrintLog("CDVD driver: Starting Sector: %lu (DVD-RAM, DVD+RW)", + dvdphysical.physical.layer[i].start_sector); + } + else + { + PrintLog("CDVD driver: Starting Sector: %lu", + dvdphysical.physical.layer[i].start_sector); + } // ENDLONGIF- What does the starting sector tell us? + PrintLog("CDVD driver: End of Layer 0: %lu", + dvdphysical.physical.layer[i].end_sector_l0); + PrintLog("CDVD driver: Ending Sector: %lu", + dvdphysical.physical.layer[i].end_sector); + if (dvdphysical.physical.layer[i].bca != 0) + PrintLog("CDVD driver: BCA data present"); + } // NEXT i- Work our way through each layer... +#endif /* VERBOSE_DISC_INFO */ + + return(0); // Success. Physical data stored for perusal. +} // END DVDreadPhysical() + +s32 DVDreadCopyright() +{ + s32 s32result; + u8 i; + int successflag; + +#ifdef VERBOSE_FUNCTION + PrintLog("CDVD driver: DVDreadCopyright()"); +#endif /* VERBOSE_FUNCTION */ + + successflag = 0; + + for (i = 0; i <= dvdphysical.physical.layer_num; i++) + { + memset(&dvdcopyright[i], 0, sizeof(dvd_struct)); + dvdcopyright[i].type = DVD_STRUCT_COPYRIGHT; + dvdcopyright[i].copyright.layer_num = i; + errno = 0; + s32result = ioctl(devicehandle, DVD_READ_STRUCT, &dvdcopyright[i]); + if (s32result == 0) + { + successflag = 1; + } + else + { + dvdcopyright[i].type = 0xFF; + } // ENDIF- + } // NEXT i- Getting copyright data for every known layer + + if (successflag == 0) + { +#ifdef VERBOSE_WARNINGS + PrintLog("CDVD driver: Error getting Copyright info: (%i) %i:%s", s32result, errno, strerror(errno)); +#endif /* VERBOSE_WARNINGS */ + return(-1); + } // ENDIF- Problem with read of physical data? + +#ifdef VERBOSE_DISC_INFO + PrintLog("CDVD driver: Copyright Information\n"); + for (i = 0; i <= dvdphysical.physical.layer_num; i++) + { + if (dvdcopyright[i].type != 0xFF) + { + PrintLog("CDVD driver: Layer Number %i CPST %i RMI %i", + dvdcopyright[i].copyright.layer_num, + dvdcopyright[i].copyright.cpst, + dvdcopyright[i].copyright.rmi); + } // ENDIF- Were we successful reading this one? + } // NEXT i- Printing out all copyright info found... +#endif /* VERBOSE_DISC_INFO */ + + errno = 0; + return(0); // Success. Copyright data stored for perusal. +} // END DVDreadCopyright() + +s32 DVDreadBCA() +{ + s32 s32result; + int i; + + i = 0; + errno = 0; + +#ifdef VERBOSE_FUNCTION + PrintLog("CDVD driver: DVDreadBCA()"); +#endif /* VERBOSE_FUNCTION */ + + memset(&dvdbca, 0, sizeof(dvd_struct)); + dvdbca.type = DVD_STRUCT_BCA; + s32result = ioctl(devicehandle, DVD_READ_STRUCT, &dvdbca); + if ((s32result == -1) || (errno != 0)) + { + dvdbca.type = 0xFF; +#ifdef VERBOSE_WARNINGS + PrintLog("CDVD driver: Error getting BCA: (%i) %i:%s", s32result, errno, strerror(errno)); +#endif /* VERBOSE_WARNINGS */ + return(-1); + } // ENDIF- Problem with read of physical data? + +#ifdef VERBOSE_DISC_INFO + PrintLog("CDVD driver: BCA Length %i Value:", + dvdbca.bca.len); + for (i = 0; i < 188 - 15; i += 16) + { + HexDump(dvdbca.bca.value + i, 16); + } // NEXT i- dumping whole key data +#endif /* VERBOSE_DISC_INFO */ + + return(0); // Success. BCA data stored for perusal. +} // END DVDreadBCA() + +s32 DVDreadManufact() +{ + s32 s32result; + u8 i; + int successflag; + int j; + +#ifdef VERBOSE_FUNCTION + PrintLog("CDVD driver: DVDreadManufact()"); +#endif /* VERBOSE_FUNCTION */ + + j = 0; + successflag = 0; + + for (i = 0; i <= dvdphysical.physical.layer_num; i++) + { + memset(&dvdmanufact[i], 0, sizeof(dvd_struct)); + dvdmanufact[i].type = DVD_STRUCT_MANUFACT; + dvdmanufact[i].manufact.layer_num = i; + errno = 0; + s32result = ioctl(devicehandle, DVD_READ_STRUCT, &dvdmanufact[i]); + if ((s32result != 0) || (errno != 0)) + { + dvdmanufact[i].type = 0xFF; + } + else + { + successflag = 1; + } // ENDIF- Did we fail to read in some manufacturer data? + } // NEXT i- Collecting manufacturer data from all layers + + if (successflag == 0) + { +#ifdef VERBOSE_WARNINGS + PrintLog("CDVD driver: Error getting Manufact: (%i) %i:%s", s32result, errno, strerror(errno)); +#endif /* VERBOSE_WARNINGS */ + return(-1); + } // ENDIF- Problem with read of physical data? + +#ifdef VERBOSE_DISC_INFO + PrintLog("CDVD driver: Manufact Data"); + for (i = 0; i <= dvdphysical.physical.layer_num; i++) + { + if (dvdmanufact[i].type != 0xFF) + { + PrintLog("CDVD driver: Layer %i Length %i Value:", + dvdmanufact[i].manufact.layer_num, + dvdmanufact[i].manufact.len); + for (j = 0; j < 128 - 15; j += 16) + { + HexDump(dvdmanufact[i].manufact.value + j, 16); + } // NEXT j- dumping whole key data + } // ENDIF- Do we have data at this layer? + } // NEXT i- Running through all the layers +#endif /* VERBOSE_DISC_INFO */ + + errno = 0; + return(0); // Success. Manufacturer's data stored for perusal. +} // END DVDreadManufact() + + +// External Functions + +// Function Calls from CDVD.c + +void InitDVDInfo() +{ + int j; + + dvdphysical.type = 0xFF; // Using for empty=0xff, full!=0xff test + dvdbca.type = 0xFF; + for (j = 0; j < DVD_LAYERS; j++) + { + dvdcopyright[j].type = 0xFF; + dvdmanufact[j].type = 0xFF; + } // NEXT j- Zeroing each layer of data + InitDVDSectorInfo(); +} // END InitDiscType() + +s32 DVDreadTrack(u32 lsn, int mode, u8 *buffer) +{ + s32 s32result; + off64_t offsettarget; + off64_t offsetresult; + + errno = 0; + s32result = 0; + offsetresult = 0; + +#ifdef VERBOSE_FUNCTION + PrintLog("CDVD driver: DVDreadTrack(%i)", lsn); +#endif /* VERBOSE_FUNCTION */ + + if (lsn != dvdlastlsn + 1) + { + offsettarget = lsn; + offsettarget *= 2048; + errno = 4; + while (errno == 4) + { + errno = 0; + offsetresult = lseek64(devicehandle, offsettarget, SEEK_SET); + } // ENDWHILE- waiting for the system interruptions to cease. + if ((offsetresult < 0) || (errno != 0)) + { +#ifdef VERBOSE_WARNINGS + PrintLog("CDVD driver: Error on seek: %i:%s", errno, strerror(errno)); +#endif /* VERBOSE_WARNINGS */ + InitDVDSectorInfo(); + return(-1); + } // ENDIF- trouble with seek? Reset pointer and abort + } // ENDIF- Do we have to seek a new position to read? + + errno = 4; + while (errno == 4) + { + errno = 0; + s32result = read(devicehandle, buffer, 2048); + } // ENDWHILE- waiting for the system interruptions to cease. + if ((s32result != 2048) || (errno != 0)) + { +#ifdef VERBOSE_WARNINGS + PrintLog("CDVD driver: DVD Short Block, Size: %i", s32result); + PrintLog("CDVD driver: Error: %i:%s", errno, strerror(errno)); +#endif /* VERBOSE_WARNINGS */ + InitDVDSectorInfo(); + return(-1); + } // ENDIF- Trouble reading the data? Reset pointer and abort + + dvdlastlsn = lsn; + return(0); // Call accomplished +} // END DVDreadTrack() + +s32 DVDgetTN(cdvdTN *cdvdtn) +{ +#ifdef VERBOSE_FUNCTION + PrintLog("CDVD driver: CDVDgetTN()"); +#endif /* VERBOSE_FUNCTION */ + + // Going to treat this as one large track for now. + if (cdvdtn != NULL) + { + cdvdtn->strack = 1; + cdvdtn->etrack = 1; + } // ENDIF- programmer actually WANTS this info? + + return(0); // Call accomplished +} // END DVDgetTN() + +s32 DVDgetTD(u8 newtrack, cdvdTD *cdvdtd) +{ +#ifdef VERBOSE_FUNCTION + PrintLog("CDVD driver: CDVDgetTD()"); +#endif /* VERBOSE_FUNCTION */ + + if ((newtrack >= 2) && (newtrack != CDROM_LEADOUT)) return(-1); + + if (cdvdtd != NULL) + { + cdvdtd->lsn = dvdphysical.physical.layer[0].end_sector + - dvdphysical.physical.layer[0].start_sector + + 1; + cdvdtd->type = CDVD_MODE_2048; + } // ENDIF- Does the caller REALLY want this data? + + return(0); // Call accomplished +} // END DVDgetTD() + +s32 DVDgetDiskType(s32 ioctldisktype) +{ + s32 s32result; + int i; + s32 tempdisctype; + + errno = 0; + s32result = 0; + i = 0; + tempdisctype = CDVD_TYPE_UNKNOWN; + +#ifdef VERBOSE_FUNCTION + PrintLog("CDVD driver: DVDgetDiskType()"); +#endif /* VERBOSE_FUNCTION */ + + if ((ioctldisktype != CDS_DATA_1) && (ioctldisktype != CDS_MIXED)) + { + return(-1); + } // ENDIF- Not a data disc we know of? Abort then + + s32result = DVDreadPhysical(); + if ((s32result != 0) || (errno != 0)) + { + return(-1); + } // ENDIF- Error reading the DVD physical structure? Not a DVD after all. + + if (dvdphysical.physical.layer[0].end_sector >= (2048*1024)) + { +#ifdef VERBOSE_DISC_TYPE + PrintLog("CDVD driver: DVD Found (Dual-Sided)"); +#endif /* VERBOSE_DISC_TYPE */ + disctype = CDVD_TYPE_DETCTDVDD; + } + else + { +#ifdef VERBOSE_DISC_TYPE + PrintLog("CDVD driver: DVD Found (Single-Sided)"); +#endif /* VERBOSE_DISC_TYPE */ + disctype = CDVD_TYPE_DETCTDVDS; + } // ENDIF- Definitely a DVD. Size Test? + + // Read in the rest of the structures... + DVDreadCopyright(); + DVDreadBCA(); + DVDreadManufact(); + + // Test for "Playstation" header + s32result = DVDreadTrack(16, CDVD_MODE_2048, dvdtempbuffer); + if (s32result != 0) + { + return(-1); + } + else + { + i = 0; + while ((*(playstationname + i) != 0) && + (*(playstationname + i) == dvdtempbuffer[8 + i])) + { + i++; + } // ENDWHILE- Checking each letter of PLAYSTATION name for a match + if (*(playstationname + i) == 0) + { +#ifdef VERBOSE_DISC_TYPE + PrintLog("CDVD driver: Detected Playstation 2 DVD"); +#endif /* VERBOSE_DISC_TYPE */ + tempdisctype = CDVD_TYPE_PS2DVD; + } + else + { +#ifdef VERBOSE_DISC_TYPE + PrintLog("CDVD driver: Guessing it's a Video DVD"); +#endif /* VERBOSE_DISC_TYPE */ + tempdisctype = CDVD_TYPE_DVDV; + } // ENDIF- Did we find the Playstation name? + } // ENDIF- Error reading disc volume information? Invalidate Disc + + if (dvdphysical.physical.layer[0].end_sector >= (2048*1024)) + { + tocbuffer[0] = 0x24; // Dual-Sided DVD + tocbuffer[4] = 0x41; + tocbuffer[5] = 0x95; + } + else + { + tocbuffer[0] = 0x04; // Single-Sided DVD + tocbuffer[4] = 0x86; + tocbuffer[5] = 0x72; + } // ENDIF- Are there too many sectors for a single-sided disc? + + tocbuffer[1] = 0x02; + tocbuffer[2] = 0xF2; + tocbuffer[3] = 0x00; + + tocbuffer[16] = 0x00; + tocbuffer[17] = 0x03; + tocbuffer[18] = 0x00; + tocbuffer[19] = 0x00; + + disctype = tempdisctype; // Triggers the fact the other info is available + return(disctype); +} // END DVDgetDiskType() diff --git a/plugins/CDVDisoEFP/src/Linux/DVD.h b/plugins/CDVDisoEFP/src/Linux/DVD.h index d3837b8520..c5637138fe 100644 --- a/plugins/CDVDisoEFP/src/Linux/DVD.h +++ b/plugins/CDVDisoEFP/src/Linux/DVD.h @@ -1,90 +1,39 @@ /* DVD.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - #ifndef __DVD_H__ - #define __DVD_H__ - - - - #ifndef __LINUX__ - #ifdef __linux__ - #define __LINUX__ - #endif /* __linux__ */ - #endif /* No __LINUX__ */ - - - #define CDVDdefs - #include "PS2Edefs.h" - - - - // Exported Functions - - - extern void HexDump(u8 *strptr, u8 count); - extern void InitDVDInfo(); - extern s32 DVDreadTrack(u32 lsn, int mode, u8 *buffer); - extern s32 DVDgetTN(cdvdTN *cdvdtn); - extern s32 DVDgetTD(u8 newtrack, cdvdTD *cdvdtd); - extern s32 DVDgetDiskType(s32 ioctldisktype); - - - - #endif /* __DVD_H__ */ - diff --git a/plugins/CDVDisoEFP/src/Linux/aboutbox.c b/plugins/CDVDisoEFP/src/Linux/aboutbox.c index b722ae5367..7b1bc7f9fb 100644 --- a/plugins/CDVDisoEFP/src/Linux/aboutbox.c +++ b/plugins/CDVDisoEFP/src/Linux/aboutbox.c @@ -1,212 +1,109 @@ -/* aboutbox.c - - * Copyright (C) 2002-2005 PCSX2 Team - - * - - * This program is free software; you can redistribute it and/or modify - - * it under the terms of the GNU General Public License as published by - - * the Free Software Foundation; either version 2 of the License, or - - * (at your option) any later version. - - * - - * This program is distributed in the hope that it will be useful, - - * but WITHOUT ANY WARRANTY; without even the implied warranty of - - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - - * GNU General Public License for more details. - - * - - * You should have received a copy of the GNU General Public License - - * along with this program; if not, write to the Free Software - - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - * - - * PCSX2 members can be contacted through their website at www.pcsx2.net. - - */ - - - - - -#include // NULL - -#include // sprintf() - - - -#include // gtk_button_new_with_label() - -#include // gtk_container_add() - -#include // gtk_hbutton_box_new() - -#include // gtk_label_new() - -#include // gtk_init(), gtk_main(), gtk_main_quit() - -#include // gtk_vbox_new() - -#include // gtk_window_new() - - - -#include "version.h" - -#include "aboutbox.h" - - - - - -struct AboutBoxData aboutbox; - - - - - -gint AboutBoxCancelEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - if(aboutbox.window != NULL) { - - gtk_widget_destroy(aboutbox.window); - - aboutbox.window = NULL; - - } // ENDIF- Do we have an About Box still? - - - - gtk_main_quit(); - - return(TRUE); - -} // END AboutBoxCancelEvent() - - - - - -void AboutBoxDisplay() { - - GtkWidget *item; - - GtkWidget *container; - - GtkWidget *vbox1; - - char templine[256]; - - - - aboutbox.window = NULL; - - aboutbox.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - gtk_container_set_border_width(GTK_CONTAINER(aboutbox.window), 5); - - gtk_window_set_title(GTK_WINDOW(aboutbox.window), "About CDVDisoEFP"); - - gtk_window_set_position(GTK_WINDOW(aboutbox.window), GTK_WIN_POS_CENTER); - - gtk_window_set_modal(GTK_WINDOW(aboutbox.window), TRUE); - - gtk_window_set_resizable(GTK_WINDOW(aboutbox.window), FALSE); - - - - g_signal_connect(G_OBJECT(aboutbox.window), "delete_event", - - G_CALLBACK(AboutBoxCancelEvent), NULL); - - - - vbox1 = gtk_vbox_new(FALSE, 5); - - gtk_container_add(GTK_CONTAINER(aboutbox.window), vbox1); - - gtk_container_set_border_width(GTK_CONTAINER(vbox1), 5); - - gtk_widget_show(vbox1); - - - - sprintf(templine, "%s v%i.%i", libname, revision, build); - - item = gtk_label_new(templine); - - gtk_box_pack_start(GTK_BOX(vbox1), item, FALSE, FALSE, 0); - - gtk_widget_show(item); - - item = NULL; - - - - item = gtk_label_new("Current Author: efp"); - - gtk_box_pack_start(GTK_BOX(vbox1), item, FALSE, FALSE, 0); - - gtk_widget_show(item); - - item = NULL; - - - - item = gtk_label_new("Original code by: linuzappz & shadow"); - - gtk_box_pack_start(GTK_BOX(vbox1), item, FALSE, FALSE, 0); - - gtk_widget_show(item); - - item = NULL; - - - - container = gtk_hbutton_box_new(); - - gtk_box_pack_start(GTK_BOX(vbox1), container, TRUE, TRUE, 0); - - gtk_widget_show(container); - - - - item = gtk_button_new_with_label("Ok"); - - gtk_container_add(GTK_CONTAINER(container), item); - - GTK_WIDGET_SET_FLAGS(item, GTK_CAN_DEFAULT); - - gtk_widget_show(item); - - - - g_signal_connect(G_OBJECT(item), "clicked", - - G_CALLBACK(AboutBoxCancelEvent), NULL); - - item = NULL; - - container = NULL; - - vbox1 = NULL; - - - - gtk_widget_show(aboutbox.window); - - gtk_main(); - -} // END AboutDisplay() - +/* aboutbox.c + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +#include // NULL +#include // sprintf() + +#include // gtk_button_new_with_label() +#include // gtk_container_add() +#include // gtk_hbutton_box_new() +#include // gtk_label_new() +#include // gtk_init(), gtk_main(), gtk_main_quit() +#include // gtk_vbox_new() +#include // gtk_window_new() + +#include "version.h" +#include "aboutbox.h" + + +struct AboutBoxData aboutbox; + + +gint AboutBoxCancelEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + if (aboutbox.window != NULL) + { + gtk_widget_destroy(aboutbox.window); + aboutbox.window = NULL; + } // ENDIF- Do we have an About Box still? + + gtk_main_quit(); + return(TRUE); +} // END AboutBoxCancelEvent() + + +void AboutBoxDisplay() +{ + GtkWidget *item; + GtkWidget *container; + GtkWidget *vbox1; + char templine[256]; + + aboutbox.window = NULL; + aboutbox.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_container_set_border_width(GTK_CONTAINER(aboutbox.window), 5); + gtk_window_set_title(GTK_WINDOW(aboutbox.window), "About CDVDisoEFP"); + gtk_window_set_position(GTK_WINDOW(aboutbox.window), GTK_WIN_POS_CENTER); + gtk_window_set_modal(GTK_WINDOW(aboutbox.window), TRUE); + gtk_window_set_resizable(GTK_WINDOW(aboutbox.window), FALSE); + + g_signal_connect(G_OBJECT(aboutbox.window), "delete_event", + G_CALLBACK(AboutBoxCancelEvent), NULL); + + vbox1 = gtk_vbox_new(FALSE, 5); + gtk_container_add(GTK_CONTAINER(aboutbox.window), vbox1); + gtk_container_set_border_width(GTK_CONTAINER(vbox1), 5); + gtk_widget_show(vbox1); + + sprintf(templine, "%s v%i.%i", libname, revision, build); + item = gtk_label_new(templine); + gtk_box_pack_start(GTK_BOX(vbox1), item, FALSE, FALSE, 0); + gtk_widget_show(item); + item = NULL; + + item = gtk_label_new("Current Author: efp"); + gtk_box_pack_start(GTK_BOX(vbox1), item, FALSE, FALSE, 0); + gtk_widget_show(item); + item = NULL; + + item = gtk_label_new("Original code by: linuzappz & shadow"); + gtk_box_pack_start(GTK_BOX(vbox1), item, FALSE, FALSE, 0); + gtk_widget_show(item); + item = NULL; + + container = gtk_hbutton_box_new(); + gtk_box_pack_start(GTK_BOX(vbox1), container, TRUE, TRUE, 0); + gtk_widget_show(container); + + item = gtk_button_new_with_label("Ok"); + gtk_container_add(GTK_CONTAINER(container), item); + GTK_WIDGET_SET_FLAGS(item, GTK_CAN_DEFAULT); + gtk_widget_show(item); + + g_signal_connect(G_OBJECT(item), "clicked", + G_CALLBACK(AboutBoxCancelEvent), NULL); + item = NULL; + container = NULL; + vbox1 = NULL; + + gtk_widget_show(aboutbox.window); + gtk_main(); +} // END AboutDisplay() diff --git a/plugins/CDVDisoEFP/src/Linux/aboutbox.h b/plugins/CDVDisoEFP/src/Linux/aboutbox.h index 875772f0c6..83e9b5101c 100644 --- a/plugins/CDVDisoEFP/src/Linux/aboutbox.h +++ b/plugins/CDVDisoEFP/src/Linux/aboutbox.h @@ -1,78 +1,34 @@ /* aboutbox.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef ABOUTBOX_H - #define ABOUTBOX_H - - - - #include - - - - -struct AboutBoxData { - - GtkWidget *window; // GtkWindow - About Box - +struct AboutBoxData +{ + GtkWidget *window; // GtkWindow - About Box }; - - - extern struct AboutBoxData aboutbox; - - - - extern void AboutBoxDisplay(); - - - - #endif /* ABOUTBOX_H */ - diff --git a/plugins/CDVDisoEFP/src/Linux/actualfile.c b/plugins/CDVDisoEFP/src/Linux/actualfile.c index 947cbe3a6c..86f0762e62 100644 --- a/plugins/CDVDisoEFP/src/Linux/actualfile.c +++ b/plugins/CDVDisoEFP/src/Linux/actualfile.c @@ -1,444 +1,238 @@ -/* actualfile.c - - * Copyright (C) 2002-2005 PCSX2 Team - - * - - * This program is free software; you can redistribute it and/or modify - - * it under the terms of the GNU General Public License as published by - - * the Free Software Foundation; either version 2 of the License, or - - * (at your option) any later version. - - * - - * This program is distributed in the hope that it will be useful, - - * but WITHOUT ANY WARRANTY; without even the implied warranty of - - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - - * GNU General Public License for more details. - - * - - * You should have received a copy of the GNU General Public License - - * along with this program; if not, write to the Free Software - - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - * - - * PCSX2 members can be contacted through their website at www.pcsx2.net. - - */ - - - - - -#include // errno - -#include // open() - -#include // rename() - -#include // strerror() - -#include // stat64(), open(), fstat() - -#include // stat64(), open(), fstat(), lseek64() - -#include // stat64(), fstat(), lseek64(), read(), close(), write() - -// unlink() - - - -#include "logfile.h" - -#include "actualfile.h" - - - - - -int IsActualFile(const char *filename) { - - int retval; - - struct stat64 filestat; - - - -#ifdef VERBOSE_FUNCTION_ACTUALFILE - - PrintLog("CDVDiso file: IsActualFile(%s)", filename); - -#endif /* VERBOSE_FUNCTION_ACTUALFILE */ - - - - errno = 0; - - retval = stat64(filename, &filestat); - - if((retval < 0) || (errno != 0)) { - -#ifdef VERBOSE_WARNING_ACTUALFILE - - PrintLog("CDVDiso file: Error retrieving stats on %s", filename); - - PrintLog("CDVDiso file: %i:%s\n", errno, strerror(errno)); - -#endif /* VERBOSE_WARNING_ACTUALFILE */ - - return(-1); // Name doesn't exist. - - } // ENDIF- Trouble getting stat on a file? - - - - if(S_ISREG(filestat.st_mode) == 0) return(-2); // Not a regular file. - - return(0); // Yep, that's a file. - -} // END IsActualFile() - - - - - -void ActualFileDelete(const char *filename) { - -#ifdef VERBOSE_FUNCTION_ACTUALFILE - - PrintLog("CDVDiso file: ActualFileDelete(%s)", filename); - -#endif /* VERBOSE_FUNCTION_ACTUALFILE */ - - - - unlink(filename); - -} // END ActualFileDelete() - - - - - -void ActualFileRename(const char *origname, const char *newname) { - -#ifdef VERBOSE_FUNCTION_ACTUALFILE - - PrintLog("CDVDiso file: ActualFileRename(%s->%s)", origname, newname); - -#endif /* VERBOSE_FUNCTION_ACTUALFILE */ - - - - rename(origname, newname); - - return; - -} // END ActualFileRename() - - - - - -ACTUALHANDLE ActualFileOpenForRead(const char *filename) { - - int newhandle; - - - - if(filename == NULL) return(-1); - - - -#ifdef VERBOSE_FUNCTION_ACTUALFILE - - PrintLog("CDVDiso file: ActualFileOpenForRead(%s)", filename); - -#endif /* VERBOSE_FUNCTION_ACTUALFILE */ - - - - errno = 0; - - newhandle = open(filename, O_RDONLY | O_LARGEFILE); - - if((newhandle < 0) || (errno != 0)) { - -#ifdef VERBOSE_WARNING_ACTUALFILE - - PrintLog("CDVDiso file: Error opening file %s\n", filename); - - PrintLog("CDVDiso file: (%i) %i:%s\n", newhandle, errno, strerror(errno)); - -#endif /* VERBOSE_WARNING_ACTUALFILE */ - - return(-1); - - } // ENDIF- Error? Abort - - - - return(newhandle); - -} // END ActualFileOpenForRead() - - - - - -off64_t ActualFileSize(ACTUALHANDLE handle) { - - int retval; - - struct stat64 filestat; - - - -#ifdef VERBOSE_FUNCTION_ACTUALFILE - - PrintLog("CDVDiso file: ActualFileSize()\n"); - -#endif /* VERBOSE_FUNCTION_ACTUALFILE */ - - - - errno = 0; - - retval = fstat64(handle, &filestat); - - if((retval < 0) || (errno != 0)) return(-1); // Name doesn't exist. - - return(filestat.st_size); - -} // END ActualFileSize() - - - - - -int ActualFileSeek(ACTUALHANDLE handle, off64_t position) { - - off64_t moved; - - - - if(handle < 0) return(-1); - - if(position < 0) return(-1); // Maybe... position = 0? - - - -#ifdef VERBOSE_FUNCTION_ACTUALFILE - - PrintLog("CDVDiso file: ActualFileSeek(%lli)", position); - -#endif /* VERBOSE_FUNCTION_ACTUALFILE */ - - - - errno = 0; - - moved = lseek64(handle, position, SEEK_SET); - - if(errno != 0) { - -#ifdef VERBOSE_WARNING_ACTUALFILE - - PrintLog("CDVDiso file: Error on seek (%lli)", position); - - PrintLog("CDVDiso file: %i:%s\n", errno, strerror(errno)); - -#endif /* VERBOSE_WARNING_ACTUALFILE */ - - return(-1); - - } // ENDIF- Error? Abort - - - - return(0); - -} // END ActualFileSeek() - - - - - -int ActualFileRead(ACTUALHANDLE handle, int bytes, char *buffer) { - - int retval; - - - - if(handle == ACTUALHANDLENULL) return(-1); - - if(bytes < 1) return(-1); - - if(buffer == NULL) return(-1); - - - -#ifdef VERBOSE_FUNCTION_ACTUALFILE - - PrintLog("CDVDiso file: ActualFileRead(%i)", bytes); - -#endif /* VERBOSE_FUNCTION_ACTUALFILE */ - - - - errno = 0; - - retval = read(handle, buffer, bytes); - - if((retval < 0) || (errno != 0)) { - -#ifdef VERBOSE_WARNING_ACTUALFILE - - PrintLog("CDVDiso file: Error reading from file!"); - - PrintLog("CDVDiso file: %i:%s", errno, strerror(errno)); - -#endif /* VERBOSE_WARNING_ACTUALFILE */ - - // return(-1); - - } // ENDIF- Error? Abort - - - - return(retval); // Send back how many bytes read - -} // END ActualFileRead() - - - - - -void ActualFileClose(ACTUALHANDLE handle) { - - if(handle < 0) return; - - - -#ifdef VERBOSE_FUNCTION_ACTUALFILE - - PrintLog("CDVDiso file: ActualFileClose()"); - -#endif /* VERBOSE_FUNCTION_ACTUALFILE */ - - - - errno = 0; - - close(handle); - - return; - -} // END ActualFileClose() - - - - - -ACTUALHANDLE ActualFileOpenForWrite(const char *filename) { - - int newhandle; - - - - if(filename == NULL) return(-1); - - - -#ifdef VERBOSE_FUNCTION_ACTUALFILE - - PrintLog("CDVDiso file: ActualFileOpenForWrite(%s)", filename); - -#endif /* VERBOSE_FUNCTION_ACTUALFILE */ - - - - errno = 0; - - newhandle = open(filename, O_WRONLY | O_CREAT | O_LARGEFILE, 0644); - - if((newhandle < 0) || (errno != 0)) { - -#ifdef VERBOSE_WARNING_ACTUALFILE - - PrintLog("CDVDiso file: Error opening file %s", filename); - - PrintLog("CDVDiso file: (%i) %i:%s", newhandle, errno, strerror(errno)); - -#endif /* VERBOSE_WARNING_ACTUALFILE */ - - return(-1); - - } // ENDIF- Error? Abort - - - - return(newhandle); - -} // END ActualFileOpenForWrite() - - - - - -int ActualFileWrite(ACTUALHANDLE handle, int bytes, char *buffer) { - - int retval; - - - - if(handle < 0) return(-1); - - if(bytes < 1) return(-1); - - if(buffer == NULL) return(-1); - - - -#ifdef VERBOSE_FUNCTION_ACTUALFILE - - PrintLog("CDVDiso file: ActualFileWrite(%i)", bytes); - -#endif /* VERBOSE_FUNCTION_ACTUALFILE */ - - - - errno = 0; - - retval = write(handle, buffer, bytes); - - if((retval < 0) || (errno != 0)) { - -#ifdef VERBOSE_WARNING_ACTUALFILE - - PrintLog("CDVDiso file: Error writing to file!"); - - PrintLog("CDVDiso file: %i:%s", errno, strerror(errno)); - -#endif /* VERBOSE_WARNING_ACTUALFILE */ - - // return(-1); - - } // ENDIF- Error? Abort - - - - return(retval); // Send back how many bytes written - -} // END ActualFileWrite() - +/* actualfile.c + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +#include // errno +#include // open() +#include // rename() +#include // strerror() +#include // stat64(), open(), fstat() +#include // stat64(), open(), fstat(), lseek64() +#include // stat64(), fstat(), lseek64(), read(), close(), write() +// unlink() + +#include "logfile.h" +#include "actualfile.h" + + +int IsActualFile(const char *filename) +{ + int retval; + struct stat64 filestat; + +#ifdef VERBOSE_FUNCTION_ACTUALFILE + PrintLog("CDVDiso file: IsActualFile(%s)", filename); +#endif /* VERBOSE_FUNCTION_ACTUALFILE */ + + errno = 0; + retval = stat64(filename, &filestat); + if ((retval < 0) || (errno != 0)) + { +#ifdef VERBOSE_WARNING_ACTUALFILE + PrintLog("CDVDiso file: Error retrieving stats on %s", filename); + PrintLog("CDVDiso file: %i:%s\n", errno, strerror(errno)); +#endif /* VERBOSE_WARNING_ACTUALFILE */ + return(-1); // Name doesn't exist. + } // ENDIF- Trouble getting stat on a file? + + if (S_ISREG(filestat.st_mode) == 0) return(-2); // Not a regular file. + return(0); // Yep, that's a file. +} // END IsActualFile() + + +void ActualFileDelete(const char *filename) +{ +#ifdef VERBOSE_FUNCTION_ACTUALFILE + PrintLog("CDVDiso file: ActualFileDelete(%s)", filename); +#endif /* VERBOSE_FUNCTION_ACTUALFILE */ + + unlink(filename); +} // END ActualFileDelete() + + +void ActualFileRename(const char *origname, const char *newname) +{ +#ifdef VERBOSE_FUNCTION_ACTUALFILE + PrintLog("CDVDiso file: ActualFileRename(%s->%s)", origname, newname); +#endif /* VERBOSE_FUNCTION_ACTUALFILE */ + + rename(origname, newname); + return; +} // END ActualFileRename() + + +ACTUALHANDLE ActualFileOpenForRead(const char *filename) +{ + int newhandle; + + if (filename == NULL) return(-1); + +#ifdef VERBOSE_FUNCTION_ACTUALFILE + PrintLog("CDVDiso file: ActualFileOpenForRead(%s)", filename); +#endif /* VERBOSE_FUNCTION_ACTUALFILE */ + + errno = 0; + newhandle = open(filename, O_RDONLY | O_LARGEFILE); + if ((newhandle < 0) || (errno != 0)) + { +#ifdef VERBOSE_WARNING_ACTUALFILE + PrintLog("CDVDiso file: Error opening file %s\n", filename); + PrintLog("CDVDiso file: (%i) %i:%s\n", newhandle, errno, strerror(errno)); +#endif /* VERBOSE_WARNING_ACTUALFILE */ + return(-1); + } // ENDIF- Error? Abort + + return(newhandle); +} // END ActualFileOpenForRead() + + +off64_t ActualFileSize(ACTUALHANDLE handle) +{ + int retval; + struct stat64 filestat; + +#ifdef VERBOSE_FUNCTION_ACTUALFILE + PrintLog("CDVDiso file: ActualFileSize()\n"); +#endif /* VERBOSE_FUNCTION_ACTUALFILE */ + + errno = 0; + retval = fstat64(handle, &filestat); + if ((retval < 0) || (errno != 0)) return(-1); // Name doesn't exist. + return(filestat.st_size); +} // END ActualFileSize() + + +int ActualFileSeek(ACTUALHANDLE handle, off64_t position) +{ + off64_t moved; + + if (handle < 0) return(-1); + if (position < 0) return(-1); // Maybe... position = 0? + +#ifdef VERBOSE_FUNCTION_ACTUALFILE + PrintLog("CDVDiso file: ActualFileSeek(%lli)", position); +#endif /* VERBOSE_FUNCTION_ACTUALFILE */ + + errno = 0; + moved = lseek64(handle, position, SEEK_SET); + if (errno != 0) + { +#ifdef VERBOSE_WARNING_ACTUALFILE + PrintLog("CDVDiso file: Error on seek (%lli)", position); + PrintLog("CDVDiso file: %i:%s\n", errno, strerror(errno)); +#endif /* VERBOSE_WARNING_ACTUALFILE */ + return(-1); + } // ENDIF- Error? Abort + + return(0); +} // END ActualFileSeek() + + +int ActualFileRead(ACTUALHANDLE handle, int bytes, char *buffer) +{ + int retval; + + if (handle == ACTUALHANDLENULL) return(-1); + if (bytes < 1) return(-1); + if (buffer == NULL) return(-1); + +#ifdef VERBOSE_FUNCTION_ACTUALFILE + PrintLog("CDVDiso file: ActualFileRead(%i)", bytes); +#endif /* VERBOSE_FUNCTION_ACTUALFILE */ + + errno = 0; + retval = read(handle, buffer, bytes); + if ((retval < 0) || (errno != 0)) + { +#ifdef VERBOSE_WARNING_ACTUALFILE + PrintLog("CDVDiso file: Error reading from file!"); + PrintLog("CDVDiso file: %i:%s", errno, strerror(errno)); +#endif /* VERBOSE_WARNING_ACTUALFILE */ + // return(-1); + } // ENDIF- Error? Abort + + return(retval); // Send back how many bytes read +} // END ActualFileRead() + + +void ActualFileClose(ACTUALHANDLE handle) +{ + if (handle < 0) return; + +#ifdef VERBOSE_FUNCTION_ACTUALFILE + PrintLog("CDVDiso file: ActualFileClose()"); +#endif /* VERBOSE_FUNCTION_ACTUALFILE */ + + errno = 0; + close(handle); + return; +} // END ActualFileClose() + + +ACTUALHANDLE ActualFileOpenForWrite(const char *filename) +{ + int newhandle; + + if (filename == NULL) return(-1); + +#ifdef VERBOSE_FUNCTION_ACTUALFILE + PrintLog("CDVDiso file: ActualFileOpenForWrite(%s)", filename); +#endif /* VERBOSE_FUNCTION_ACTUALFILE */ + + errno = 0; + newhandle = open(filename, O_WRONLY | O_CREAT | O_LARGEFILE, 0644); + if ((newhandle < 0) || (errno != 0)) + { +#ifdef VERBOSE_WARNING_ACTUALFILE + PrintLog("CDVDiso file: Error opening file %s", filename); + PrintLog("CDVDiso file: (%i) %i:%s", newhandle, errno, strerror(errno)); +#endif /* VERBOSE_WARNING_ACTUALFILE */ + return(-1); + } // ENDIF- Error? Abort + + return(newhandle); +} // END ActualFileOpenForWrite() + + +int ActualFileWrite(ACTUALHANDLE handle, int bytes, char *buffer) +{ + int retval; + + if (handle < 0) return(-1); + if (bytes < 1) return(-1); + if (buffer == NULL) return(-1); + +#ifdef VERBOSE_FUNCTION_ACTUALFILE + PrintLog("CDVDiso file: ActualFileWrite(%i)", bytes); +#endif /* VERBOSE_FUNCTION_ACTUALFILE */ + + errno = 0; + retval = write(handle, buffer, bytes); + if ((retval < 0) || (errno != 0)) + { +#ifdef VERBOSE_WARNING_ACTUALFILE + PrintLog("CDVDiso file: Error writing to file!"); + PrintLog("CDVDiso file: %i:%s", errno, strerror(errno)); +#endif /* VERBOSE_WARNING_ACTUALFILE */ + // return(-1); + } // ENDIF- Error? Abort + + return(retval); // Send back how many bytes written +} // END ActualFileWrite() diff --git a/plugins/CDVDisoEFP/src/Linux/actualfile.h b/plugins/CDVDisoEFP/src/Linux/actualfile.h index b7a72df55f..7bb6419b3d 100644 --- a/plugins/CDVDisoEFP/src/Linux/actualfile.h +++ b/plugins/CDVDisoEFP/src/Linux/actualfile.h @@ -1,100 +1,45 @@ /* actualfile.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef ACTUALFILE_H - #define ACTUALFILE_H - - - - #include // off64_t - - - - #define ACTUALHANDLE int - #define ACTUALHANDLENULL -1 - - // #define VERBOSE_FUNCTION_ACTUALFILE - // #define VERBOSE_WARNING_ACTUALFILE - - - - extern int IsActualFile(const char *filename); - extern void ActualFileDelete(const char *filename); - extern void ActualFileRename(const char *origname, const char *newname); - - extern ACTUALHANDLE ActualFileOpenForRead(const char *filename); - extern off64_t ActualFileSize(ACTUALHANDLE handle); - extern int ActualFileSeek(ACTUALHANDLE handle, off64_t position); - extern int ActualFileRead(ACTUALHANDLE handle, int bytes, char *buffer); - extern void ActualFileClose(ACTUALHANDLE handle); - - extern ACTUALHANDLE ActualFileOpenForWrite(const char *filename); - extern int ActualFileWrite(ACTUALHANDLE handle, int bytes, char *buffer); - - - - #endif /* ACTUALFILE_H */ - diff --git a/plugins/CDVDisoEFP/src/Linux/comparisonbox.c b/plugins/CDVDisoEFP/src/Linux/comparisonbox.c index 4b18abd64b..658cfd10d2 100644 --- a/plugins/CDVDisoEFP/src/Linux/comparisonbox.c +++ b/plugins/CDVDisoEFP/src/Linux/comparisonbox.c @@ -1,830 +1,453 @@ -/* comparisonbox.c - - * Copyright (C) 2002-2005 PCSX2 Team - - * - - * This program is free software; you can redistribute it and/or modify - - * it under the terms of the GNU General Public License as published by - - * the Free Software Foundation; either version 2 of the License, or - - * (at your option) any later version. - - * - - * This program is distributed in the hope that it will be useful, - - * but WITHOUT ANY WARRANTY; without even the implied warranty of - - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - - * GNU General Public License for more details. - - * - - * You should have received a copy of the GNU General Public License - - * along with this program; if not, write to the Free Software - - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - * - - * PCSX2 members can be contacted through their website at www.pcsx2.net. - - */ - - - - - -#include // NULL - -#include // sprintf() - -#include // strcpy() - - - -#include // gtk_button_new_with_label() - -#include // gtk_container_add() - -#include // gtk_entry_new() - -#include // gtk_file_selection_set_filename() - -#include // gtk_hbutton_box_new() - -#include // gtk_hbox_new() - -#include // gtk_hseparator_new() - -#include // gtk_label_new() - -#include // gtk_init(), gtk_main(), gtk_main_quit() - -#include // gtk_vbox_new() - -#include - -#include // gtk_window_new() - - - -#include "logfile.h" - -#include "conf.h" - -#include "isofile.h" - -#include "isocompress.h" // compressdesc[] - -#include "multifile.h" // multinames[] - -#include "tablerebuild.h" // IsoTableRebuild() - -#include "progressbox.h" - -#include "messagebox.h" - - - - - -struct MainBoxData { - - GtkWidget *window; // GtkWindow - - GtkWidget *file1; // GtkEntry - - GtkWidget *desc1; // GtkLabel - - GtkWidget *file2; // GtkEntry - - GtkWidget *desc2; // GtkLabel - - GtkWidget *okbutton; // GtkButton - - // Leaving the Cancel button unblocked... for emergency shutdown - - - - int stop; // Variable signal to stop long processes - -}; - - - - - -struct MainBoxData mainbox; - - - - - -void MainBoxDestroy() { - - if(mainbox.window != NULL) { - - gtk_widget_destroy(mainbox.window); - - mainbox.window = NULL; - - mainbox.file1 = NULL; - - mainbox.desc1 = NULL; - - mainbox.file2 = NULL; - - mainbox.desc2 = NULL; - - mainbox.okbutton = NULL; - - } // ENDIF- Do we have a Main Window still? - -} // END MainBoxDestroy() - - - - - -void MainBoxUnfocus() { - - gtk_widget_set_sensitive(mainbox.file1, FALSE); - - gtk_widget_set_sensitive(mainbox.file2, FALSE); - - gtk_widget_set_sensitive(mainbox.okbutton, FALSE); - - gtk_window_iconify(GTK_WINDOW(mainbox.window)); - -} // END MainBoxUnfocus() - - - - - -gint MainBoxFile1Event(GtkWidget *widget, GdkEvent event, gpointer data) { - - int returnval; - - char templine[256]; - - struct IsoFile *tempfile; - - - - returnval = IsIsoFile(gtk_entry_get_text(GTK_ENTRY(mainbox.file1))); - - if(returnval == -1) { - - gtk_label_set_text(GTK_LABEL(mainbox.desc1), "File Type: ---"); - - return(TRUE); - - } // ENDIF- Not a name of any sort? - - - - if(returnval == -2) { - - gtk_label_set_text(GTK_LABEL(mainbox.desc1), "File Type: Not a file"); - - return(TRUE); - - } // ENDIF- Not a regular file? - - - - if(returnval == -3) { - - gtk_label_set_text(GTK_LABEL(mainbox.desc1), "File Type: Not a valid image file"); - - return(TRUE); - - } // ENDIF- Not an Image file? - - - - if(returnval == -4) { - - gtk_label_set_text(GTK_LABEL(mainbox.desc1), "File Type: Missing Table File (will rebuild)"); - - return(TRUE); - - } // ENDIF- Missing Compression seek table? - - - - tempfile = IsoFileOpenForRead(gtk_entry_get_text(GTK_ENTRY(mainbox.file1))); - - sprintf(templine, "File Type: %s%s%s", - - multinames[tempfile->multi], - - tempfile->imagename, - - compressdesc[tempfile->compress]); - - gtk_label_set_text(GTK_LABEL(mainbox.desc1), templine); - - tempfile = IsoFileClose(tempfile); - - return(TRUE); - -} // END MainBoxFileEvent() - - - - - -gint MainBoxFile2Event(GtkWidget *widget, GdkEvent event, gpointer data) { - - int returnval; - - char templine[256]; - - struct IsoFile *tempfile; - - - - returnval = IsIsoFile(gtk_entry_get_text(GTK_ENTRY(mainbox.file2))); - - if(returnval == -1) { - - gtk_label_set_text(GTK_LABEL(mainbox.desc2), "File Type: ---"); - - return(TRUE); - - } // ENDIF- Not a name of any sort? - - - - if(returnval == -2) { - - gtk_label_set_text(GTK_LABEL(mainbox.desc2), "File Type: Not a file"); - - return(TRUE); - - } // ENDIF- Not a regular file? - - - - if(returnval == -3) { - - gtk_label_set_text(GTK_LABEL(mainbox.desc2), "File Type: Not a valid image file"); - - return(TRUE); - - } // ENDIF- Not an Image file? - - - - if(returnval == -4) { - - gtk_label_set_text(GTK_LABEL(mainbox.desc2), "File Type: Missing Table File (will rebuild)"); - - return(TRUE); - - } // ENDIF- Missing Compression seek table? - - - - tempfile = IsoFileOpenForRead(gtk_entry_get_text(GTK_ENTRY(mainbox.file2))); - - sprintf(templine, "File Type: %s%s%s", - - multinames[tempfile->multi], - - tempfile->imagename, - - compressdesc[tempfile->compress]); - - gtk_label_set_text(GTK_LABEL(mainbox.desc2), templine); - - tempfile = IsoFileClose(tempfile); - - return(TRUE); - -} // END MainBoxFileEvent() - - - - - -void MainBoxRefocus() { - - GdkEvent event; - - - - MainBoxFile1Event(NULL, event, NULL); - - MainBoxFile2Event(NULL, event, NULL); - - - - gtk_widget_set_sensitive(mainbox.file1, TRUE); - - gtk_widget_set_sensitive(mainbox.file2, TRUE); - - gtk_widget_set_sensitive(mainbox.okbutton, TRUE); - - gtk_window_set_focus(GTK_WINDOW(mainbox.window), mainbox.file1); - - gtk_window_deiconify(GTK_WINDOW(mainbox.window)); - -} // END MainBoxRefocus() - - - - - -gint MainBoxCancelEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - mainbox.stop = 1; // Halt all long processess... - - - - MessageBoxDestroy(); - - ProgressBoxDestroy(); - - MainBoxDestroy(); - - - - gtk_main_quit(); - - return(TRUE); - -} // END MainBoxCancelEvent() - - - - - -gint MainBoxOKEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - const char *tempisoname1; - - const char *tempisoname2; - - struct IsoFile *tempiso1; - - struct IsoFile *tempiso2; - - int stop; - - off64_t endsector; - - off64_t sector; - - int retval; - - char tempblock1[2448]; - - char tempblock2[2448]; - - int i; - - - - MainBoxUnfocus(); - - - - tempisoname1 = gtk_entry_get_text(GTK_ENTRY(mainbox.file1)); - - tempisoname2 = gtk_entry_get_text(GTK_ENTRY(mainbox.file2)); - - tempiso1 = NULL; - - tempiso2 = NULL; - - - - tempiso1 = IsoFileOpenForRead(tempisoname1); - - if(tempiso1 == NULL) { - - MainBoxRefocus(); - - MessageBoxShow("First file is not a Valid Image File.", 0); - - tempisoname1 = NULL; - - tempisoname2 = NULL; - - return(TRUE); - - } // ENDIF- Not an ISO file? Message and Stop here. - - - - tempiso2 = IsoFileOpenForRead(tempisoname2); - - if(tempiso2 == NULL) { - - MainBoxRefocus(); - - MessageBoxShow("Second file is not a Valid Image File.", 0); - - tempiso1 = IsoFileClose(tempiso1); - - tempisoname1 = NULL; - - tempisoname2 = NULL; - - return(TRUE); - - } // ENDIF- Not an ISO file? Message and Stop here. - - - - if(tempiso1->blocksize != tempiso2->blocksize) { - - MainBoxRefocus(); - - MessageBoxShow("Block sizes in Image files do not match.", 0); - - tempiso1 = IsoFileClose(tempiso1); - - tempiso2 = IsoFileClose(tempiso2); - - tempisoname1 = NULL; - - tempisoname2 = NULL; - - return(TRUE); - - } // ENDIF- Not an ISO file? Message and Stop here. - - - - if(tempiso1->multi == 1) { - - i = 0; - - while((i < 10) && - - (IsoFileSeek(tempiso1, tempiso1->multisectorend[i] + 1) == 0)) i++; - - endsector = tempiso1->multisectorend[tempiso1->multiend]; - - } else { - - endsector = tempiso1->filesectorsize; - - } // ENDIF- Get ending sector from multifile? (Or single file?) - - IsoFileSeek(tempiso1, 0); - - - - if(tempiso2->multi == 1) { - - i = 0; - - while((i < 10) && - - (IsoFileSeek(tempiso2, tempiso2->multisectorend[i] + 1) == 0)) i++; - - sector = tempiso2->multisectorend[tempiso2->multiend]; - - } else { - - sector = tempiso2->filesectorsize; - - } // ENDIF- Get ending sector from multifile? (Or single file?) - - IsoFileSeek(tempiso2, 0); - - if(sector != endsector) { - - MainBoxRefocus(); - - MessageBoxShow("Number of blocks in Image files do not match.", 0); - - tempiso1 = IsoFileClose(tempiso1); - - tempiso2 = IsoFileClose(tempiso2); - - tempisoname1 = NULL; - - tempisoname2 = NULL; - - return(TRUE); - - } // ENDIF- Number of blocks don't match? Say so. - - - - sprintf(tempblock1, "%s == %s ?", tempisoname1, tempisoname2); - - ProgressBoxStart(tempblock1, endsector); - - - - stop = 0; - - mainbox.stop = 0; - - progressbox.stop = 0; - - while((stop == 0) && (tempiso1->sectorpos < endsector)) { - - retval = IsoFileRead(tempiso1, tempblock1); - - if(retval < 0) { - - MainBoxRefocus(); - - MessageBoxShow("Trouble reading first file.", 0); - - stop = 1; - - } else { - - retval = IsoFileRead(tempiso2, tempblock2); - - if(retval < 0) { - - MainBoxRefocus(); - - MessageBoxShow("Trouble reading second file.", 0); - - stop = 1; - - } else { - - i = 0; - - while((i < tempiso1->blocksize) && (tempblock1[i] == tempblock2[i])) i++; - - if(i < tempiso1->blocksize) { - - MainBoxRefocus(); - - MessageBoxShow("Trouble reading second file.", 0); - - stop = 1; - - } // ENDIF- Sectors don't match? Say so. - - } // ENDIF- Trouble reading second file? - - } // ENDIF- Trouble reading first file? - - - - ProgressBoxTick(tempiso1->sectorpos); - - while(gtk_events_pending()) gtk_main_iteration(); - - - - if(mainbox.stop != 0) stop = 2; - - if(progressbox.stop != 0) stop = 2; - - } // ENDWHILE- Comparing two files... sector by sector - - - - if(stop == 0) { - - MainBoxRefocus(); - - MessageBoxShow("Images Match.", 0); - - } // ENDIF- Everything checked out? Say so. - - tempiso1 = IsoFileClose(tempiso1); - - tempiso2 = IsoFileClose(tempiso2); - - tempisoname1 = NULL; - - tempisoname2 = NULL; - - return(TRUE); - -} // END MainBoxOKEvent() - - - - - -void MainBoxDisplay() { - - GtkWidget *item; - - GtkWidget *hbox1; - - GtkWidget *vbox1; - - - - mainbox.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - gtk_container_set_border_width(GTK_CONTAINER(mainbox.window), 5); - - gtk_window_set_title(GTK_WINDOW(mainbox.window), "CDVDisoEFP Comparsion"); - - gtk_window_set_position(GTK_WINDOW(mainbox.window), GTK_WIN_POS_CENTER); - - // gtk_window_set_resizable(GTK_WINDOW(mainbox.window), FALSE); - - - - g_signal_connect(G_OBJECT(mainbox.window), "delete_event", - - G_CALLBACK(MainBoxCancelEvent), NULL); - - - - vbox1 = gtk_vbox_new(FALSE, 5); - - gtk_container_add(GTK_CONTAINER(mainbox.window), vbox1); - - gtk_container_set_border_width(GTK_CONTAINER(vbox1), 5); - - gtk_widget_show(vbox1); - - - - hbox1 = gtk_hbox_new(FALSE, 10); - - gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); - - gtk_widget_show(hbox1); - - - - item = gtk_label_new("First Iso File:"); - - gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0); - - gtk_widget_show(item); - - item = NULL; - - - - mainbox.file1 = gtk_entry_new(); - - gtk_box_pack_start(GTK_BOX(hbox1), mainbox.file1, TRUE, TRUE, 0); - - gtk_widget_show(mainbox.file1); - - g_signal_connect(G_OBJECT(mainbox.file1), "changed", - - G_CALLBACK(MainBoxFile1Event), NULL); - - hbox1 = NULL; - - - - mainbox.desc1 = gtk_label_new("File Type: ---"); - - gtk_box_pack_start(GTK_BOX(vbox1), mainbox.desc1, FALSE, FALSE, 0); - - gtk_widget_show(mainbox.desc1); - - - - item = gtk_hseparator_new(); - - gtk_box_pack_start(GTK_BOX(vbox1), item, TRUE, TRUE, 0); - - gtk_widget_show(item); - - item = NULL; - - - - hbox1 = gtk_hbox_new(FALSE, 10); - - gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); - - gtk_widget_show(hbox1); - - - - item = gtk_label_new("Second Iso File:"); - - gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0); - - gtk_widget_show(item); - - item = NULL; - - - - mainbox.file2 = gtk_entry_new(); - - gtk_box_pack_start(GTK_BOX(hbox1), mainbox.file2, TRUE, TRUE, 0); - - gtk_widget_show(mainbox.file2); - - g_signal_connect(G_OBJECT(mainbox.file2), "changed", - - G_CALLBACK(MainBoxFile2Event), NULL); - - hbox1 = NULL; - - - - mainbox.desc2 = gtk_label_new("File Type: ---"); - - gtk_box_pack_start(GTK_BOX(vbox1), mainbox.desc2, FALSE, FALSE, 0); - - gtk_widget_show(mainbox.desc2); - - - - hbox1 = gtk_hbutton_box_new(); - - gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); - - gtk_widget_show(hbox1); - - - - mainbox.okbutton = gtk_button_new_with_label("Compare"); - - gtk_box_pack_start(GTK_BOX(hbox1), mainbox.okbutton, TRUE, TRUE, 0); - - gtk_widget_show(mainbox.okbutton); - - g_signal_connect(G_OBJECT(mainbox.okbutton), "clicked", - - G_CALLBACK(MainBoxOKEvent), NULL); - - - - item = gtk_button_new_with_label("Exit"); - - gtk_box_pack_start(GTK_BOX(hbox1), item, TRUE, TRUE, 0); - - gtk_widget_show(item); - - g_signal_connect(G_OBJECT(item), "clicked", - - G_CALLBACK(MainBoxCancelEvent), NULL); - - item = NULL; - - hbox1 = NULL; - - vbox1 = NULL; - - - - // We held off setting the name until now... so description would show. - - gtk_entry_set_text(GTK_ENTRY(mainbox.file1), conf.isoname); - - gtk_entry_set_text(GTK_ENTRY(mainbox.file2), conf.isoname); - -} // END MainBoxDisplay() - - - - - -int main(int argc, char *argv[]) { - - gtk_init(NULL, NULL); - - - - OpenLog(); - - InitConf(); - - LoadConf(); - - MainBoxDisplay(); - - ProgressBoxDisplay(); - - MessageBoxDisplay(); - - - - gtk_widget_show_all(mainbox.window); - - gtk_main(); - - CloseLog(); - - return(0); - -} // END main() - +/* comparisonbox.c + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +#include // NULL +#include // sprintf() +#include // strcpy() + +#include // gtk_button_new_with_label() +#include // gtk_container_add() +#include // gtk_entry_new() +#include // gtk_file_selection_set_filename() +#include // gtk_hbutton_box_new() +#include // gtk_hbox_new() +#include // gtk_hseparator_new() +#include // gtk_label_new() +#include // gtk_init(), gtk_main(), gtk_main_quit() +#include // gtk_vbox_new() +#include +#include // gtk_window_new() + +#include "logfile.h" +#include "conf.h" +#include "isofile.h" +#include "isocompress.h" // compressdesc[] +#include "multifile.h" // multinames[] +#include "tablerebuild.h" // IsoTableRebuild() +#include "progressbox.h" +#include "messagebox.h" + + +struct MainBoxData +{ + GtkWidget *window; // GtkWindow + GtkWidget *file1; // GtkEntry + GtkWidget *desc1; // GtkLabel + GtkWidget *file2; // GtkEntry + GtkWidget *desc2; // GtkLabel + GtkWidget *okbutton; // GtkButton + // Leaving the Cancel button unblocked... for emergency shutdown + + int stop; // Variable signal to stop long processes +}; + + +struct MainBoxData mainbox; + + +void MainBoxDestroy() +{ + if (mainbox.window != NULL) + { + gtk_widget_destroy(mainbox.window); + mainbox.window = NULL; + mainbox.file1 = NULL; + mainbox.desc1 = NULL; + mainbox.file2 = NULL; + mainbox.desc2 = NULL; + mainbox.okbutton = NULL; + } // ENDIF- Do we have a Main Window still? +} // END MainBoxDestroy() + + +void MainBoxUnfocus() +{ + gtk_widget_set_sensitive(mainbox.file1, FALSE); + gtk_widget_set_sensitive(mainbox.file2, FALSE); + gtk_widget_set_sensitive(mainbox.okbutton, FALSE); + gtk_window_iconify(GTK_WINDOW(mainbox.window)); +} // END MainBoxUnfocus() + + +gint MainBoxFile1Event(GtkWidget *widget, GdkEvent event, gpointer data) +{ + int returnval; + char templine[256]; + struct IsoFile *tempfile; + + returnval = IsIsoFile(gtk_entry_get_text(GTK_ENTRY(mainbox.file1))); + if (returnval == -1) + { + gtk_label_set_text(GTK_LABEL(mainbox.desc1), "File Type: ---"); + return(TRUE); + } // ENDIF- Not a name of any sort? + + if (returnval == -2) + { + gtk_label_set_text(GTK_LABEL(mainbox.desc1), "File Type: Not a file"); + return(TRUE); + } // ENDIF- Not a regular file? + + if (returnval == -3) + { + gtk_label_set_text(GTK_LABEL(mainbox.desc1), "File Type: Not a valid image file"); + return(TRUE); + } // ENDIF- Not an Image file? + + if (returnval == -4) + { + gtk_label_set_text(GTK_LABEL(mainbox.desc1), "File Type: Missing Table File (will rebuild)"); + return(TRUE); + } // ENDIF- Missing Compression seek table? + + tempfile = IsoFileOpenForRead(gtk_entry_get_text(GTK_ENTRY(mainbox.file1))); + sprintf(templine, "File Type: %s%s%s", + multinames[tempfile->multi], + tempfile->imagename, + compressdesc[tempfile->compress]); + gtk_label_set_text(GTK_LABEL(mainbox.desc1), templine); + tempfile = IsoFileClose(tempfile); + return(TRUE); +} // END MainBoxFileEvent() + + +gint MainBoxFile2Event(GtkWidget *widget, GdkEvent event, gpointer data) +{ + int returnval; + char templine[256]; + struct IsoFile *tempfile; + + returnval = IsIsoFile(gtk_entry_get_text(GTK_ENTRY(mainbox.file2))); + if (returnval == -1) + { + gtk_label_set_text(GTK_LABEL(mainbox.desc2), "File Type: ---"); + return(TRUE); + } // ENDIF- Not a name of any sort? + + if (returnval == -2) + { + gtk_label_set_text(GTK_LABEL(mainbox.desc2), "File Type: Not a file"); + return(TRUE); + } // ENDIF- Not a regular file? + + if (returnval == -3) + { + gtk_label_set_text(GTK_LABEL(mainbox.desc2), "File Type: Not a valid image file"); + return(TRUE); + } // ENDIF- Not an Image file? + + if (returnval == -4) + { + gtk_label_set_text(GTK_LABEL(mainbox.desc2), "File Type: Missing Table File (will rebuild)"); + return(TRUE); + } // ENDIF- Missing Compression seek table? + + tempfile = IsoFileOpenForRead(gtk_entry_get_text(GTK_ENTRY(mainbox.file2))); + sprintf(templine, "File Type: %s%s%s", + multinames[tempfile->multi], + tempfile->imagename, + compressdesc[tempfile->compress]); + gtk_label_set_text(GTK_LABEL(mainbox.desc2), templine); + tempfile = IsoFileClose(tempfile); + return(TRUE); +} // END MainBoxFileEvent() + + +void MainBoxRefocus() +{ + GdkEvent event; + + MainBoxFile1Event(NULL, event, NULL); + MainBoxFile2Event(NULL, event, NULL); + + gtk_widget_set_sensitive(mainbox.file1, TRUE); + gtk_widget_set_sensitive(mainbox.file2, TRUE); + gtk_widget_set_sensitive(mainbox.okbutton, TRUE); + gtk_window_set_focus(GTK_WINDOW(mainbox.window), mainbox.file1); + gtk_window_deiconify(GTK_WINDOW(mainbox.window)); +} // END MainBoxRefocus() + + +gint MainBoxCancelEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + mainbox.stop = 1; // Halt all long processess... + + MessageBoxDestroy(); + ProgressBoxDestroy(); + MainBoxDestroy(); + + gtk_main_quit(); + return(TRUE); +} // END MainBoxCancelEvent() + + +gint MainBoxOKEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + const char *tempisoname1; + const char *tempisoname2; + struct IsoFile *tempiso1; + struct IsoFile *tempiso2; + int stop; + off64_t endsector; + off64_t sector; + int retval; + char tempblock1[2448]; + char tempblock2[2448]; + int i; + + MainBoxUnfocus(); + + tempisoname1 = gtk_entry_get_text(GTK_ENTRY(mainbox.file1)); + tempisoname2 = gtk_entry_get_text(GTK_ENTRY(mainbox.file2)); + tempiso1 = NULL; + tempiso2 = NULL; + + tempiso1 = IsoFileOpenForRead(tempisoname1); + if (tempiso1 == NULL) + { + MainBoxRefocus(); + MessageBoxShow("First file is not a Valid Image File.", 0); + tempisoname1 = NULL; + tempisoname2 = NULL; + return(TRUE); + } // ENDIF- Not an ISO file? Message and Stop here. + + tempiso2 = IsoFileOpenForRead(tempisoname2); + if (tempiso2 == NULL) + { + MainBoxRefocus(); + MessageBoxShow("Second file is not a Valid Image File.", 0); + tempiso1 = IsoFileClose(tempiso1); + tempisoname1 = NULL; + tempisoname2 = NULL; + return(TRUE); + } // ENDIF- Not an ISO file? Message and Stop here. + + if (tempiso1->blocksize != tempiso2->blocksize) + { + MainBoxRefocus(); + MessageBoxShow("Block sizes in Image files do not match.", 0); + tempiso1 = IsoFileClose(tempiso1); + tempiso2 = IsoFileClose(tempiso2); + tempisoname1 = NULL; + tempisoname2 = NULL; + return(TRUE); + } // ENDIF- Not an ISO file? Message and Stop here. + + if (tempiso1->multi == 1) + { + i = 0; + while ((i < 10) && + (IsoFileSeek(tempiso1, tempiso1->multisectorend[i] + 1) == 0)) i++; + endsector = tempiso1->multisectorend[tempiso1->multiend]; + } + else + { + endsector = tempiso1->filesectorsize; + } // ENDIF- Get ending sector from multifile? (Or single file?) + IsoFileSeek(tempiso1, 0); + + if (tempiso2->multi == 1) + { + i = 0; + while ((i < 10) && + (IsoFileSeek(tempiso2, tempiso2->multisectorend[i] + 1) == 0)) i++; + sector = tempiso2->multisectorend[tempiso2->multiend]; + } + else + { + sector = tempiso2->filesectorsize; + } // ENDIF- Get ending sector from multifile? (Or single file?) + IsoFileSeek(tempiso2, 0); + if (sector != endsector) + { + MainBoxRefocus(); + MessageBoxShow("Number of blocks in Image files do not match.", 0); + tempiso1 = IsoFileClose(tempiso1); + tempiso2 = IsoFileClose(tempiso2); + tempisoname1 = NULL; + tempisoname2 = NULL; + return(TRUE); + } // ENDIF- Number of blocks don't match? Say so. + + sprintf(tempblock1, "%s == %s ?", tempisoname1, tempisoname2); + ProgressBoxStart(tempblock1, endsector); + + stop = 0; + mainbox.stop = 0; + progressbox.stop = 0; + while ((stop == 0) && (tempiso1->sectorpos < endsector)) + { + retval = IsoFileRead(tempiso1, tempblock1); + if (retval < 0) + { + MainBoxRefocus(); + MessageBoxShow("Trouble reading first file.", 0); + stop = 1; + } + else + { + retval = IsoFileRead(tempiso2, tempblock2); + if (retval < 0) + { + MainBoxRefocus(); + MessageBoxShow("Trouble reading second file.", 0); + stop = 1; + } + else + { + i = 0; + while ((i < tempiso1->blocksize) && (tempblock1[i] == tempblock2[i])) i++; + if (i < tempiso1->blocksize) + { + MainBoxRefocus(); + MessageBoxShow("Trouble reading second file.", 0); + stop = 1; + } // ENDIF- Sectors don't match? Say so. + } // ENDIF- Trouble reading second file? + } // ENDIF- Trouble reading first file? + + ProgressBoxTick(tempiso1->sectorpos); + while (gtk_events_pending()) gtk_main_iteration(); + + if (mainbox.stop != 0) stop = 2; + if (progressbox.stop != 0) stop = 2; + } // ENDWHILE- Comparing two files... sector by sector + + if (stop == 0) + { + MainBoxRefocus(); + MessageBoxShow("Images Match.", 0); + } // ENDIF- Everything checked out? Say so. + tempiso1 = IsoFileClose(tempiso1); + tempiso2 = IsoFileClose(tempiso2); + tempisoname1 = NULL; + tempisoname2 = NULL; + return(TRUE); +} // END MainBoxOKEvent() + + +void MainBoxDisplay() +{ + GtkWidget *item; + GtkWidget *hbox1; + GtkWidget *vbox1; + + mainbox.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_container_set_border_width(GTK_CONTAINER(mainbox.window), 5); + gtk_window_set_title(GTK_WINDOW(mainbox.window), "CDVDisoEFP Comparsion"); + gtk_window_set_position(GTK_WINDOW(mainbox.window), GTK_WIN_POS_CENTER); + // gtk_window_set_resizable(GTK_WINDOW(mainbox.window), FALSE); + + g_signal_connect(G_OBJECT(mainbox.window), "delete_event", + G_CALLBACK(MainBoxCancelEvent), NULL); + + vbox1 = gtk_vbox_new(FALSE, 5); + gtk_container_add(GTK_CONTAINER(mainbox.window), vbox1); + gtk_container_set_border_width(GTK_CONTAINER(vbox1), 5); + gtk_widget_show(vbox1); + + hbox1 = gtk_hbox_new(FALSE, 10); + gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); + gtk_widget_show(hbox1); + + item = gtk_label_new("First Iso File:"); + gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0); + gtk_widget_show(item); + item = NULL; + + mainbox.file1 = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(hbox1), mainbox.file1, TRUE, TRUE, 0); + gtk_widget_show(mainbox.file1); + g_signal_connect(G_OBJECT(mainbox.file1), "changed", + G_CALLBACK(MainBoxFile1Event), NULL); + hbox1 = NULL; + + mainbox.desc1 = gtk_label_new("File Type: ---"); + gtk_box_pack_start(GTK_BOX(vbox1), mainbox.desc1, FALSE, FALSE, 0); + gtk_widget_show(mainbox.desc1); + + item = gtk_hseparator_new(); + gtk_box_pack_start(GTK_BOX(vbox1), item, TRUE, TRUE, 0); + gtk_widget_show(item); + item = NULL; + + hbox1 = gtk_hbox_new(FALSE, 10); + gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); + gtk_widget_show(hbox1); + + item = gtk_label_new("Second Iso File:"); + gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0); + gtk_widget_show(item); + item = NULL; + + mainbox.file2 = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(hbox1), mainbox.file2, TRUE, TRUE, 0); + gtk_widget_show(mainbox.file2); + g_signal_connect(G_OBJECT(mainbox.file2), "changed", + G_CALLBACK(MainBoxFile2Event), NULL); + hbox1 = NULL; + + mainbox.desc2 = gtk_label_new("File Type: ---"); + gtk_box_pack_start(GTK_BOX(vbox1), mainbox.desc2, FALSE, FALSE, 0); + gtk_widget_show(mainbox.desc2); + + hbox1 = gtk_hbutton_box_new(); + gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); + gtk_widget_show(hbox1); + + mainbox.okbutton = gtk_button_new_with_label("Compare"); + gtk_box_pack_start(GTK_BOX(hbox1), mainbox.okbutton, TRUE, TRUE, 0); + gtk_widget_show(mainbox.okbutton); + g_signal_connect(G_OBJECT(mainbox.okbutton), "clicked", + G_CALLBACK(MainBoxOKEvent), NULL); + + item = gtk_button_new_with_label("Exit"); + gtk_box_pack_start(GTK_BOX(hbox1), item, TRUE, TRUE, 0); + gtk_widget_show(item); + g_signal_connect(G_OBJECT(item), "clicked", + G_CALLBACK(MainBoxCancelEvent), NULL); + item = NULL; + hbox1 = NULL; + vbox1 = NULL; + + // We held off setting the name until now... so description would show. + gtk_entry_set_text(GTK_ENTRY(mainbox.file1), conf.isoname); + gtk_entry_set_text(GTK_ENTRY(mainbox.file2), conf.isoname); +} // END MainBoxDisplay() + + +int main(int argc, char *argv[]) +{ + gtk_init(NULL, NULL); + + OpenLog(); + InitConf(); + LoadConf(); + MainBoxDisplay(); + ProgressBoxDisplay(); + MessageBoxDisplay(); + + gtk_widget_show_all(mainbox.window); + gtk_main(); + CloseLog(); + return(0); +} // END main() diff --git a/plugins/CDVDisoEFP/src/Linux/comparisondummy.c b/plugins/CDVDisoEFP/src/Linux/comparisondummy.c index 43dd5519a0..c45b7d6781 100644 --- a/plugins/CDVDisoEFP/src/Linux/comparisondummy.c +++ b/plugins/CDVDisoEFP/src/Linux/comparisondummy.c @@ -1,48 +1,30 @@ -/* comparisondummy.c - - * Copyright (C) 2002-2005 PCSX2 Team - - * - - * This program is free software; you can redistribute it and/or modify - - * it under the terms of the GNU General Public License as published by - - * the Free Software Foundation; either version 2 of the License, or - - * (at your option) any later version. - - * - - * This program is distributed in the hope that it will be useful, - - * but WITHOUT ANY WARRANTY; without even the implied warranty of - - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - - * GNU General Public License for more details. - - * - - * You should have received a copy of the GNU General Public License - - * along with this program; if not, write to the Free Software - - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - * - - * PCSX2 members can be contacted through their website at www.pcsx2.net. - - */ - - - - - -void ConversionBoxRefocus() { return; } - - - -void DeviceBoxRefocus() { return; } - +/* comparisondummy.c + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +void ConversionBoxRefocus() +{ + return; +} + +void DeviceBoxRefocus() +{ + return; +} diff --git a/plugins/CDVDisoEFP/src/Linux/conf.c b/plugins/CDVDisoEFP/src/Linux/conf.c index 70d6853727..65c2473088 100644 --- a/plugins/CDVDisoEFP/src/Linux/conf.c +++ b/plugins/CDVDisoEFP/src/Linux/conf.c @@ -1,408 +1,204 @@ /* conf.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - #include // errno - #include // NULL - #include // sprintf() - #include // getenv() - #include // strerror() - #include // mkdir(), stat() - #include // mkdir(), stat() - #include // stat() - - // #define CDVDdefs - // #include "../PS2Edefs.h" - #include "logfile.h" - #include "../ini.h" - #include "conf.h" - - - - const char *cfgname[] = { \ - - "./cfg/cfgCDVDisoEFP", \ - - "../cfg/cfgCDVDisoEFP", \ - - "./cfgCDVDisoEFP", \ - - "../cfgCDVDisoEFP", \ - - "./plugins/cfgCDVDisoEFP", \ - - "../plugins/cfgCDVDisoEFP", \ - - NULL }; - - + "./cfg/cfgCDVDisoEFP", \ + "../cfg/cfgCDVDisoEFP", \ + "./cfgCDVDisoEFP", \ + "../cfgCDVDisoEFP", \ + "./plugins/cfgCDVDisoEFP", \ + "../plugins/cfgCDVDisoEFP", \ + NULL + }; const char *confnames[] = { "IsoFile", "CdDev", NULL }; - const u8 defaultdevice[] = DEFAULT_DEVICE; - const char defaulthome[] = "../inis"; - const char defaultdirectory[] = ".PS2E"; - const char defaultfile[] = "CDVDisoEFP.ini"; - - char confdirname[256]; - char conffilename[256]; - - - CDVDconf conf; - - - - -void ExecCfg(char *arg) { - - int nameptr; - - struct stat filestat; - - char templine[256]; - - - +void ExecCfg(char *arg) +{ + int nameptr; + struct stat filestat; + char templine[256]; #ifdef VERBOSE_FUNCTION_CONF - - PrintLog("CDVDiso interface: ExecCfg(%s)", arg); - + PrintLog("CDVDiso interface: ExecCfg(%s)", arg); #endif /* VERBOSE FUNCTION_CONF */ + errno = 0; + nameptr = 0; + while ((cfgname[nameptr] != NULL) && + (stat(cfgname[nameptr], &filestat) == -1)) nameptr++; + errno = 0; - errno = 0; - - nameptr = 0; - - while((cfgname[nameptr] != NULL) && - - (stat(cfgname[nameptr], &filestat) == -1)) nameptr++; - - errno = 0; - - - - if(cfgname[nameptr] == NULL) { - + if (cfgname[nameptr] == NULL) + { #ifdef VERBOSE_FUNCTION_CONF - - PrintLog("CDVDiso interface: Couldn't find configuration program!"); - + PrintLog("CDVDiso interface: Couldn't find configuration program!"); #endif /* VERBOSE_FUNCTION_CONF */ - - return; - - } // ENDIF- Did not find the executable? - - - - sprintf(templine, "%s %s", cfgname[nameptr], arg); - - system(templine); - + return; + } // ENDIF- Did not find the executable? + sprintf(templine, "%s %s", cfgname[nameptr], arg); + system(templine); } // END ExecCfg() - - - - -void InitConf() { - - int i; - - int pos; - - char *envptr; - - - +void InitConf() +{ + int i; + int pos; + char *envptr; #ifdef VERBOSE_FUNCTION_CONF - - PrintLog("CDVD config: InitConf()"); - + PrintLog("CDVD config: InitConf()"); #endif /* VERBOSE_FUNCTION_CONF */ - - - - conf.isoname[0] = 0; // Empty the iso name - - - - i = 0; - - while((i < 255) && defaultdevice[i] != 0) { - - conf.devicename[i] = defaultdevice[i]; - - i++; - - } // ENDWHILE- copying the default CD/DVD name in - - conf.devicename[i] = 0; // 0-terminate the device name - - - - // Locating directory and file positions - - pos = 0; - - envptr = getenv("HOME"); - - if(envptr == NULL) { - - // = - - i = 0; - - while((pos < 253) && (defaulthome[i] != 0)) { - - confdirname[pos] = defaulthome[i]; - - conffilename[pos] = defaulthome[i]; - - pos++; - - i++; - - } // NEXT- putting a default place to store configuration data - - - - } else { - - // = / - - i = 0; - - while((pos < 253) && (*(envptr + i) != 0)) { - - confdirname[pos] = *(envptr + i); - - conffilename[pos] = *(envptr + i); - - pos++; - - i++; - - } // ENDWHILE- copying home directory info in - - - - if(confdirname[pos-1] != '/') { - - confdirname[pos] = '/'; - - conffilename[pos] = '/'; - - pos++; - - } // ENDIF- No directory separator here? Add one. - - - - i = 0; - - while((pos < 253) && (defaultdirectory[i] != 0)) { - - confdirname[pos] = defaultdirectory[i]; - - conffilename[pos] = defaultdirectory[i]; - - pos++; - - i++; - - } // NEXT- putting a default place to store configuration data - - } // ENDIF- No Home directory? - - - - confdirname[pos] = 0; // Directory reference finished - - - - // += / - - if(conffilename[pos-1] != '/') { - - conffilename[pos] = '/'; - - pos++; - - } // ENDIF- No directory separator here? Add one. - - - - i = 0; - - while((pos < 253) && (defaultfile[i] != 0)) { - - conffilename[pos] = defaultfile[i]; - - pos++; - - i++; - - } // NEXT- putting a default place to store configuration data - - - - conffilename[pos] = 0; // File reference finished - - - + conf.isoname[0] = 0; // Empty the iso name + i = 0; + while ((i < 255) && defaultdevice[i] != 0) + { + conf.devicename[i] = defaultdevice[i]; + i++; + } // ENDWHILE- copying the default CD/DVD name in + conf.devicename[i] = 0; // 0-terminate the device name + + // Locating directory and file positions + pos = 0; + envptr = getenv("HOME"); + if (envptr == NULL) + { + // = + i = 0; + while ((pos < 253) && (defaulthome[i] != 0)) + { + confdirname[pos] = defaulthome[i]; + conffilename[pos] = defaulthome[i]; + pos++; + i++; + } // NEXT- putting a default place to store configuration data + } + else + { + // = / + i = 0; + while ((pos < 253) && (*(envptr + i) != 0)) + { + confdirname[pos] = *(envptr + i); + conffilename[pos] = *(envptr + i); + pos++; + i++; + } // ENDWHILE- copying home directory info in + if (confdirname[pos-1] != '/') + { + confdirname[pos] = '/'; + conffilename[pos] = '/'; + pos++; + } // ENDIF- No directory separator here? Add one. + i = 0; + while ((pos < 253) && (defaultdirectory[i] != 0)) + { + confdirname[pos] = defaultdirectory[i]; + conffilename[pos] = defaultdirectory[i]; + pos++; + i++; + } // NEXT- putting a default place to store configuration data + } // ENDIF- No Home directory? + + confdirname[pos] = 0; // Directory reference finished + + // += / + if (conffilename[pos-1] != '/') + { + conffilename[pos] = '/'; + pos++; + } // ENDIF- No directory separator here? Add one. + + i = 0; + while ((pos < 253) && (defaultfile[i] != 0)) + { + conffilename[pos] = defaultfile[i]; + pos++; + i++; + } // NEXT- putting a default place to store configuration data + conffilename[pos] = 0; // File reference finished #ifdef VERBOSE_FUNCTION_CONF - - PrintLog("CDVD config: Directory: %s\n", confdirname); - - PrintLog("CDVD config: File: %s\n", conffilename); - + PrintLog("CDVD config: Directory: %s\n", confdirname); + PrintLog("CDVD config: File: %s\n", conffilename); #endif /* VERBOSE_FUNCTION_CONF */ - } // END InitConf() - - - - -void LoadConf() { - - int retval; - - - +void LoadConf() +{ + int retval; #ifdef VERBOSE_FUNCTION_CONF - - PrintLog("CDVD config: LoadConf()\n"); - + PrintLog("CDVD config: LoadConf()\n"); #endif /* VERBOSE_FUNCTION_CONF */ + retval = INILoadString(conffilename, "Settings", "IsoFile", conf.isoname); + if (retval < 0) + { + sprintf(conf.isoname, "[Put an Image Name here]"); + } // ENDIF- Couldn't find keyword? Fill in a default + retval = INILoadString(conffilename, "Settings", "Device", conf.devicename); + if (retval < 0) + { + sprintf(conf.devicename, "/dev/dvd"); + } // ENDIF- Couldn't find keyword? Fill in a default + retval = INILoadUInt(conffilename, "Settings", "OpenOnStart", &conf.startconfigure); + if (retval < 0) + { + conf.startconfigure = 0; // False + } // ENDIF- Couldn't find keyword? Fill in a default - - retval = INILoadString(conffilename, "Settings", "IsoFile", conf.isoname); - - if(retval < 0) { - - sprintf(conf.isoname, "[Put an Image Name here]"); - - } // ENDIF- Couldn't find keyword? Fill in a default - - - - retval = INILoadString(conffilename, "Settings", "Device", conf.devicename); - - if(retval < 0) { - - sprintf(conf.devicename, "/dev/dvd"); - - } // ENDIF- Couldn't find keyword? Fill in a default - - - - retval = INILoadUInt(conffilename, "Settings", "OpenOnStart", &conf.startconfigure); - - if(retval < 0) { - - conf.startconfigure = 0; // False - - } // ENDIF- Couldn't find keyword? Fill in a default - - - - retval = INILoadUInt(conffilename, "Settings", "OpenOnRestart", &conf.restartconfigure); - - if(retval < 0) { - - conf.restartconfigure = 1; // True - - } // ENDIF- Couldn't find keyword? Fill in a default - + retval = INILoadUInt(conffilename, "Settings", "OpenOnRestart", &conf.restartconfigure); + if (retval < 0) + { + conf.restartconfigure = 1; // True + } // ENDIF- Couldn't find keyword? Fill in a default } // END LoadConf() - - - - -void SaveConf() { - +void SaveConf() +{ #ifdef VERBOSE_FUNCTION_CONF - - PrintLog("CDVD config: SaveConf()\n"); - + PrintLog("CDVD config: SaveConf()\n"); #endif /* VERBOSE_FUNCTION_CONF */ + mkdir(confdirname, 0755); - - mkdir(confdirname, 0755); - - - - INISaveString(conffilename, "Settings", "IsoFile", conf.isoname); - - INISaveString(conffilename, "Settings", "Device", conf.devicename); - - INISaveUInt(conffilename, "Settings", "OpenOnStart", conf.startconfigure); - - INISaveUInt(conffilename, "Settings", "OpenOnRestart", conf.restartconfigure); - + INISaveString(conffilename, "Settings", "IsoFile", conf.isoname); + INISaveString(conffilename, "Settings", "Device", conf.devicename); + INISaveUInt(conffilename, "Settings", "OpenOnStart", conf.startconfigure); + INISaveUInt(conffilename, "Settings", "OpenOnRestart", conf.restartconfigure); } // END SaveConf() - diff --git a/plugins/CDVDisoEFP/src/Linux/conf.h b/plugins/CDVDisoEFP/src/Linux/conf.h index 42bb401da6..d2930cb1f7 100644 --- a/plugins/CDVDisoEFP/src/Linux/conf.h +++ b/plugins/CDVDisoEFP/src/Linux/conf.h @@ -1,54 +1,55 @@ -/* conf.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - -#ifndef CONF_H -#define CONF_H - - -#define CDVDdefs -#include "../PS2Edefs.h" - - -#define VERBOSE_FUNCTION_CONF - - -// Configuration Data - -typedef struct { - u8 isoname[256]; - u8 devicename[256]; - unsigned int startconfigure; - unsigned int restartconfigure; -} CDVDconf; -extern CDVDconf conf; - -#define DEFAULT_DEVICE "K:\\" - - -// Configuration Functions - -extern void InitConf(); -extern void LoadConf(); -extern void SaveConf(); - -extern void ExecCfg(char *arg); - - -#endif /* CONF_H */ +/* conf.h + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + +#ifndef CONF_H +#define CONF_H + + +#define CDVDdefs +#include "../PS2Edefs.h" + + +#define VERBOSE_FUNCTION_CONF + + +// Configuration Data + +typedef struct +{ + u8 isoname[256]; + u8 devicename[256]; + unsigned int startconfigure; + unsigned int restartconfigure; +} CDVDconf; +extern CDVDconf conf; + +#define DEFAULT_DEVICE "K:\\" + + +// Configuration Functions + +extern void InitConf(); +extern void LoadConf(); +extern void SaveConf(); + +extern void ExecCfg(char *arg); + + +#endif /* CONF_H */ diff --git a/plugins/CDVDisoEFP/src/Linux/conversionbox.c b/plugins/CDVDisoEFP/src/Linux/conversionbox.c index f54ae8084c..e7fdde1bd0 100644 --- a/plugins/CDVDisoEFP/src/Linux/conversionbox.c +++ b/plugins/CDVDisoEFP/src/Linux/conversionbox.c @@ -1,776 +1,417 @@ -/* conversionbox.c - - * Copyright (C) 2002-2005 PCSX2 Team - - * - - * This program is free software; you can redistribute it and/or modify - - * it under the terms of the GNU General Public License as published by - - * the Free Software Foundation; either version 2 of the License, or - - * (at your option) any later version. - - * - - * This program is distributed in the hope that it will be useful, - - * but WITHOUT ANY WARRANTY; without even the implied warranty of - - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - - * GNU General Public License for more details. - - * - - * You should have received a copy of the GNU General Public License - - * along with this program; if not, write to the Free Software - - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - * - - * PCSX2 members can be contacted through their website at www.pcsx2.net. - - */ - - - - - -#include // NULL - -#include // sprintf() - -#include // strcpy() - -#include // off64_t - - - -#include // gtk_button_new_with_label() - -#include // gtk_combo_box_new() - -#include // gtk_check_button_new() - -#include // gtk_container_add() - -#include // gtk_entry_new() - -#include // gtk_file_selection_set_filename() - -#include // gtk_hbutton_box_new() - -#include // gtk_hbox_new() - -#include // gtk_hseparator_new() - -#include // gtk_label_new() - -#include // gtk_main_iteration() - -#include // gtk_toggle_button_get_active() - -#include // gtk_vbox_new() - -#include // gtk_window_new() - - - -#include "isofile.h" - -#include "isocompress.h" // compressdesc[] - -#include "imagetype.h" // imagedata[] - -#include "multifile.h" // multinames[] - -#include "toc.h" - -#include "progressbox.h" - -#include "messagebox.h" - -#include "selectionbox.h" - -#include "mainbox.h" - -#include "conversionbox.h" - - - - - -struct ConversionBoxData conversionbox; - - - - - -void ConversionBoxDestroy() { - - if(conversionbox.window != NULL) { - - gtk_widget_destroy(conversionbox.window); - - conversionbox.window = NULL; - - conversionbox.file = NULL; - - conversionbox.selectbutton = NULL; - - conversionbox.filedesc = NULL; - - conversionbox.compress = NULL; - - conversionbox.multi = NULL; - - conversionbox.okbutton = NULL; - - conversionbox.cancelbutton = NULL; - - } // ENDIF- Do we have a Main Window still? - -} // END ConversionBoxDestroy() - - - - - -void ConversionBoxUnfocus() { - - gtk_widget_set_sensitive(conversionbox.file, FALSE); - - gtk_widget_set_sensitive(conversionbox.selectbutton, FALSE); - - gtk_widget_set_sensitive(conversionbox.compress, FALSE); - - gtk_widget_set_sensitive(conversionbox.multi, FALSE); - - gtk_widget_set_sensitive(conversionbox.okbutton, FALSE); - - gtk_widget_set_sensitive(conversionbox.cancelbutton, FALSE); - - // gtk_window_iconify(GTK_WINDOW(conversionbox.window)); - - gtk_widget_hide(conversionbox.window); - -} // END ConversionBoxUnfocus() - - - - - -gint ConversionBoxFileEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - int returnval; - - char templine[256]; - - struct IsoFile *tempfile; - - - - returnval = IsIsoFile(gtk_entry_get_text(GTK_ENTRY(conversionbox.file))); - - if(returnval == -1) { - - gtk_label_set_text(GTK_LABEL(conversionbox.filedesc), "File Type: ---"); - - return(TRUE); - - } // ENDIF- Not a name of any sort? - - - - if(returnval == -2) { - - gtk_label_set_text(GTK_LABEL(conversionbox.filedesc), - - "File Type: Not a file"); - - return(TRUE); - - } // ENDIF- Not a regular file? - - - - if(returnval == -3) { - - gtk_label_set_text(GTK_LABEL(conversionbox.filedesc), - - "File Type: Not a valid image file"); - - return(TRUE); - - } // ENDIF- Not a regular file? - - - - if(returnval == -4) { - - gtk_label_set_text(GTK_LABEL(conversionbox.filedesc), - - "File Type: Missing Table File (will rebuild)"); - - return(TRUE); - - } // ENDIF- Not a regular file? - - - - tempfile = IsoFileOpenForRead(gtk_entry_get_text(GTK_ENTRY(conversionbox.file))); - - sprintf(templine, "File Type: %s%s%s", - - multinames[tempfile->multi], - - tempfile->imagename, - - compressdesc[tempfile->compress]); - - gtk_label_set_text(GTK_LABEL(conversionbox.filedesc), templine); - - tempfile = IsoFileClose(tempfile); - - return(TRUE); - -} // END ConversionBoxFileEvent() - - - - - -void ConversionBoxRefocus() { - - GdkEvent event; - - - - ConversionBoxFileEvent(NULL, event, NULL); - - - - gtk_widget_set_sensitive(conversionbox.file, TRUE); - - gtk_widget_set_sensitive(conversionbox.selectbutton, TRUE); - - gtk_widget_set_sensitive(conversionbox.compress, TRUE); - - gtk_widget_set_sensitive(conversionbox.multi, TRUE); - - gtk_widget_set_sensitive(conversionbox.okbutton, TRUE); - - gtk_widget_set_sensitive(conversionbox.cancelbutton, TRUE); - - gtk_window_set_focus(GTK_WINDOW(conversionbox.window), conversionbox.file); - - gtk_widget_show_all(conversionbox.window); - - gtk_window_deiconify(GTK_WINDOW(conversionbox.window)); - -} // END ConversionBoxRefocus() - - - - - -gint ConversionBoxCancelEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - gtk_widget_hide(conversionbox.window); - - MainBoxRefocus(); - - return(TRUE); - -} // END ConversionBoxCancelEvent() - - - - - -gint ConversionBoxOKEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - char templine[256]; - - char tempblock[2352]; - - const char *filename; - - int compressmethod; - - int multi; - - struct IsoFile *fromfile; - - struct IsoFile *tofile; - - int i; - - off64_t endsector; - - int stop; - - int retval; - - - - ConversionBoxUnfocus(); - - - - filename = gtk_entry_get_text(GTK_ENTRY(conversionbox.file)); - - if(IsIsoFile(filename) < 0) { - - filename = NULL; - - MessageBoxShow("Not a valid file", 3); - - return(TRUE); - - } // ENDIF- Not an Iso File? Stop early. - - - - compressmethod = gtk_combo_box_get_active(GTK_COMBO_BOX(conversionbox.compress)); - - if(compressmethod > 0) compressmethod += 2; - - multi = 0; - - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(conversionbox.multi)) == TRUE) - - multi = 1; - - - - fromfile = NULL; - - fromfile = IsoFileOpenForRead(filename); - - if(fromfile == NULL) { - - filename = NULL; - - MessageBoxShow("Cannot opening the source file", 3); - - return(TRUE); - - } // ENDIF- Not an Iso File? Stop early. - - - - if((compressmethod == fromfile->compress) && - - (multi == fromfile->multi)) { - - fromfile = IsoFileClose(fromfile); - - filename = NULL; - - MessageBoxShow("Compress/Multifile methods match - no need to convert", 3); - - return(TRUE); - - } // ENDIF- Not an Iso File? Stop early. - - - - tofile = IsoFileOpenForWrite(filename, - - GetImageTypeConvertTo(fromfile->imagetype), - - multi, - - compressmethod); - - if(tofile == NULL) { - - fromfile = IsoFileClose(fromfile); - - filename = NULL; - - MessageBoxShow("Cannot create the new file", 3); - - return(TRUE); - - } // ENDIF- Not an Iso File? Stop early. - - - - if(fromfile->multi == 1) { - - i = 0; - - while((i < 10) && - - (IsoFileSeek(fromfile, fromfile->multisectorend[i] + 1) == 0)) i++; - - endsector = fromfile->multisectorend[fromfile->multiend]; - - } else { - - endsector = fromfile->filesectorsize; - - } // ENDIF- Get ending sector from multifile? (Or single file?) - - IsoFileSeek(fromfile, 0); - - - - // Open Progress Bar - - sprintf(templine, "%s: %s%s -> %s%s", - - filename, - - multinames[fromfile->multi], - - compressdesc[fromfile->compress], - - multinames[tofile->multi], - - compressdesc[tofile->compress]); - - ProgressBoxStart(templine, endsector); - - - - tofile->cdvdtype = fromfile->cdvdtype; - - for(i = 0; i < 2048; i++) tofile->toc[i] = fromfile->toc[i]; - - - - stop = 0; - - mainbox.stop = 0; - - progressbox.stop = 0; - - while((stop == 0) && (tofile->sectorpos < endsector)) { - - retval = IsoFileRead(fromfile, tempblock); - - if(retval < 0) { - - MessageBoxShow("Trouble reading source file", 3); - - stop = 1; - - } else { - - retval = IsoFileWrite(tofile, tempblock); - - if(retval < 0) { - - MessageBoxShow("Trouble writing new file", 3); - - stop = 1; - - } // ENDIF- Trouble writing out the next block? - - } // ENDIF- Trouble reading in the next block? - - - - ProgressBoxTick(tofile->sectorpos); - - while(gtk_events_pending()) gtk_main_iteration(); - - - - if(mainbox.stop != 0) stop = 2; - - if(progressbox.stop != 0) stop = 2; - - } // ENDWHILE- Not stopped for some reason... - - - - ProgressBoxStop(); - - - - if(stop == 0) { - - if(tofile->multi == 1) tofile->name[tofile->multipos] = '0'; // First file - - strcpy(templine, tofile->name); - - - - // fromfile = IsoFileCloseAndDelete(fromfile); - - fromfile = IsoFileClose(fromfile); - - - - IsoSaveTOC(tofile); - - tofile = IsoFileClose(tofile); - - gtk_entry_set_text(GTK_ENTRY(mainbox.file), templine); - - - - } else { - - fromfile = IsoFileClose(fromfile); - - tofile = IsoFileCloseAndDelete(tofile); - - } // ENDIF- Did we succeed in the transfer? - - - - if(stop != 1) ConversionBoxRefocus(); - - if(stop == 0) ConversionBoxCancelEvent(widget, event, data); - - return(TRUE); - -} // END ConversionBoxOKEvent() - - - - - -gint ConversionBoxBrowseEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - ConversionBoxUnfocus(); - - - - // Transfer file name to file selection - - gtk_file_selection_set_filename(GTK_FILE_SELECTION(selectionbox.window), - - gtk_entry_get_text(GTK_ENTRY(conversionbox.file))); - - selectionbox.wherefrom = 3; // From the Conversion Window - - SelectionBoxRefocus(); - - return(TRUE); - -} // END ConversionBoxBrowseEvent() - - - - - -void ConversionBoxDisplay() { - - GtkWidget *item; - - GtkWidget *hbox1; - - GtkWidget *vbox1; - - int nameptr; - - - - conversionbox.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - gtk_container_set_border_width(GTK_CONTAINER(conversionbox.window), 5); - - gtk_window_set_title(GTK_WINDOW(conversionbox.window), "CDVDisoEFP File Conversion"); - - gtk_window_set_position(GTK_WINDOW(conversionbox.window), GTK_WIN_POS_CENTER); - - - - g_signal_connect(G_OBJECT(conversionbox.window), "delete_event", - - G_CALLBACK(ConversionBoxCancelEvent), NULL); - - - - vbox1 = gtk_vbox_new(FALSE, 5); - - gtk_container_add(GTK_CONTAINER(conversionbox.window), vbox1); - - gtk_container_set_border_width(GTK_CONTAINER(vbox1), 5); - - gtk_widget_show(vbox1); - - - - hbox1 = gtk_hbox_new(FALSE, 10); - - gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); - - gtk_widget_show(hbox1); - - - - item = gtk_label_new("Iso File:"); - - gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0); - - gtk_widget_show(item); - - item = NULL; - - - - conversionbox.file = gtk_entry_new(); - - gtk_box_pack_start(GTK_BOX(hbox1), conversionbox.file, TRUE, TRUE, 0); - - gtk_widget_show(conversionbox.file); - - g_signal_connect(G_OBJECT(conversionbox.file), "changed", - - G_CALLBACK(ConversionBoxFileEvent), NULL); - - - - conversionbox.selectbutton = gtk_button_new_with_label("Browse"); - - gtk_box_pack_start(GTK_BOX(hbox1), conversionbox.selectbutton, FALSE, FALSE, 0); - - gtk_widget_show(conversionbox.selectbutton); - - g_signal_connect(G_OBJECT(conversionbox.selectbutton), "clicked", - - G_CALLBACK(ConversionBoxBrowseEvent), NULL); - - hbox1 = NULL; - - - - conversionbox.filedesc = gtk_label_new("File Type: ---"); - - gtk_box_pack_start(GTK_BOX(vbox1), conversionbox.filedesc, FALSE, FALSE, 0); - - gtk_widget_show(conversionbox.filedesc); - - // ConversionBoxFileEvent(NULL, 0, NULL); // Work out compromise later... - - - - item = gtk_hseparator_new(); - - gtk_box_pack_start(GTK_BOX(vbox1), item, TRUE, TRUE, 0); - - gtk_widget_show(item); - - item = NULL; - - - - hbox1 = gtk_hbox_new(FALSE, 10); - - gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); - - gtk_widget_show(hbox1); - - - - item = gtk_label_new("Change Compression To:"); - - gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0); - - gtk_widget_show(item); - - item = NULL; - - - - conversionbox.compress = gtk_combo_box_new_text(); - - gtk_box_pack_start(GTK_BOX(hbox1), conversionbox.compress, FALSE, FALSE, 0); - - nameptr = 0; - - while(compressnames[nameptr] != NULL) { - - gtk_combo_box_append_text(GTK_COMBO_BOX(conversionbox.compress), - - compressnames[nameptr]); - - nameptr++; - - } // ENDWHILE- loading compression types into combo box - - gtk_combo_box_set_active(GTK_COMBO_BOX(conversionbox.compress), 0); // Temp Line - - gtk_widget_show(conversionbox.compress); - - hbox1 = NULL; - - - - hbox1 = gtk_hbox_new(FALSE, 10); - - gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); - - gtk_widget_show(hbox1); - - - - item = gtk_label_new("Multiple Files (all under 2 GB):"); - - gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0); - - gtk_widget_show(item); - - item = NULL; - - - - conversionbox.multi = gtk_check_button_new(); - - gtk_box_pack_start(GTK_BOX(hbox1), conversionbox.multi, FALSE, FALSE, 0); - - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(conversionbox.multi), FALSE); - - gtk_widget_show(conversionbox.multi); - - hbox1 = NULL; - - - - hbox1 = gtk_hbutton_box_new(); - - gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); - - gtk_widget_show(hbox1); - - - - conversionbox.okbutton = gtk_button_new_with_label("Change File"); - - gtk_box_pack_start(GTK_BOX(hbox1), conversionbox.okbutton, TRUE, TRUE, 0); - - gtk_widget_show(conversionbox.okbutton); - - g_signal_connect(G_OBJECT(conversionbox.okbutton), "clicked", - - G_CALLBACK(ConversionBoxOKEvent), NULL); - - - - conversionbox.cancelbutton = gtk_button_new_with_label("Cancel"); - - gtk_box_pack_start(GTK_BOX(hbox1), conversionbox.cancelbutton, TRUE, TRUE, 0); - - gtk_widget_show(conversionbox.cancelbutton); - - g_signal_connect(G_OBJECT(conversionbox.cancelbutton), "clicked", - - G_CALLBACK(ConversionBoxCancelEvent), NULL); - - hbox1 = NULL; - - vbox1 = NULL; - -} // END ConversionBoxDisplay() - +/* conversionbox.c + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +#include // NULL +#include // sprintf() +#include // strcpy() +#include // off64_t + +#include // gtk_button_new_with_label() +#include // gtk_combo_box_new() +#include // gtk_check_button_new() +#include // gtk_container_add() +#include // gtk_entry_new() +#include // gtk_file_selection_set_filename() +#include // gtk_hbutton_box_new() +#include // gtk_hbox_new() +#include // gtk_hseparator_new() +#include // gtk_label_new() +#include // gtk_main_iteration() +#include // gtk_toggle_button_get_active() +#include // gtk_vbox_new() +#include // gtk_window_new() + +#include "isofile.h" +#include "isocompress.h" // compressdesc[] +#include "imagetype.h" // imagedata[] +#include "multifile.h" // multinames[] +#include "toc.h" +#include "progressbox.h" +#include "messagebox.h" +#include "selectionbox.h" +#include "mainbox.h" +#include "conversionbox.h" + + +struct ConversionBoxData conversionbox; + + +void ConversionBoxDestroy() +{ + if (conversionbox.window != NULL) + { + gtk_widget_destroy(conversionbox.window); + conversionbox.window = NULL; + conversionbox.file = NULL; + conversionbox.selectbutton = NULL; + conversionbox.filedesc = NULL; + conversionbox.compress = NULL; + conversionbox.multi = NULL; + conversionbox.okbutton = NULL; + conversionbox.cancelbutton = NULL; + } // ENDIF- Do we have a Main Window still? +} // END ConversionBoxDestroy() + + +void ConversionBoxUnfocus() +{ + gtk_widget_set_sensitive(conversionbox.file, FALSE); + gtk_widget_set_sensitive(conversionbox.selectbutton, FALSE); + gtk_widget_set_sensitive(conversionbox.compress, FALSE); + gtk_widget_set_sensitive(conversionbox.multi, FALSE); + gtk_widget_set_sensitive(conversionbox.okbutton, FALSE); + gtk_widget_set_sensitive(conversionbox.cancelbutton, FALSE); + // gtk_window_iconify(GTK_WINDOW(conversionbox.window)); + gtk_widget_hide(conversionbox.window); +} // END ConversionBoxUnfocus() + + +gint ConversionBoxFileEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + int returnval; + char templine[256]; + struct IsoFile *tempfile; + + returnval = IsIsoFile(gtk_entry_get_text(GTK_ENTRY(conversionbox.file))); + if (returnval == -1) + { + gtk_label_set_text(GTK_LABEL(conversionbox.filedesc), "File Type: ---"); + return(TRUE); + } // ENDIF- Not a name of any sort? + + if (returnval == -2) + { + gtk_label_set_text(GTK_LABEL(conversionbox.filedesc), + "File Type: Not a file"); + return(TRUE); + } // ENDIF- Not a regular file? + + if (returnval == -3) + { + gtk_label_set_text(GTK_LABEL(conversionbox.filedesc), + "File Type: Not a valid image file"); + return(TRUE); + } // ENDIF- Not a regular file? + + if (returnval == -4) + { + gtk_label_set_text(GTK_LABEL(conversionbox.filedesc), + "File Type: Missing Table File (will rebuild)"); + return(TRUE); + } // ENDIF- Not a regular file? + + tempfile = IsoFileOpenForRead(gtk_entry_get_text(GTK_ENTRY(conversionbox.file))); + sprintf(templine, "File Type: %s%s%s", + multinames[tempfile->multi], + tempfile->imagename, + compressdesc[tempfile->compress]); + gtk_label_set_text(GTK_LABEL(conversionbox.filedesc), templine); + tempfile = IsoFileClose(tempfile); + return(TRUE); +} // END ConversionBoxFileEvent() + + +void ConversionBoxRefocus() +{ + GdkEvent event; + + ConversionBoxFileEvent(NULL, event, NULL); + + gtk_widget_set_sensitive(conversionbox.file, TRUE); + gtk_widget_set_sensitive(conversionbox.selectbutton, TRUE); + gtk_widget_set_sensitive(conversionbox.compress, TRUE); + gtk_widget_set_sensitive(conversionbox.multi, TRUE); + gtk_widget_set_sensitive(conversionbox.okbutton, TRUE); + gtk_widget_set_sensitive(conversionbox.cancelbutton, TRUE); + gtk_window_set_focus(GTK_WINDOW(conversionbox.window), conversionbox.file); + gtk_widget_show_all(conversionbox.window); + gtk_window_deiconify(GTK_WINDOW(conversionbox.window)); +} // END ConversionBoxRefocus() + + +gint ConversionBoxCancelEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + gtk_widget_hide(conversionbox.window); + MainBoxRefocus(); + return(TRUE); +} // END ConversionBoxCancelEvent() + + +gint ConversionBoxOKEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + char templine[256]; + char tempblock[2352]; + const char *filename; + int compressmethod; + int multi; + struct IsoFile *fromfile; + struct IsoFile *tofile; + int i; + off64_t endsector; + int stop; + int retval; + + ConversionBoxUnfocus(); + + filename = gtk_entry_get_text(GTK_ENTRY(conversionbox.file)); + if (IsIsoFile(filename) < 0) + { + filename = NULL; + MessageBoxShow("Not a valid file", 3); + return(TRUE); + } // ENDIF- Not an Iso File? Stop early. + + compressmethod = gtk_combo_box_get_active(GTK_COMBO_BOX(conversionbox.compress)); + if (compressmethod > 0) compressmethod += 2; + multi = 0; + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(conversionbox.multi)) == TRUE) + multi = 1; + + fromfile = NULL; + fromfile = IsoFileOpenForRead(filename); + if (fromfile == NULL) + { + filename = NULL; + MessageBoxShow("Cannot opening the source file", 3); + return(TRUE); + } // ENDIF- Not an Iso File? Stop early. + + if ((compressmethod == fromfile->compress) && + (multi == fromfile->multi)) + { + fromfile = IsoFileClose(fromfile); + filename = NULL; + MessageBoxShow("Compress/Multifile methods match - no need to convert", 3); + return(TRUE); + } // ENDIF- Not an Iso File? Stop early. + + tofile = IsoFileOpenForWrite(filename, + GetImageTypeConvertTo(fromfile->imagetype), + multi, + compressmethod); + if (tofile == NULL) + { + fromfile = IsoFileClose(fromfile); + filename = NULL; + MessageBoxShow("Cannot create the new file", 3); + return(TRUE); + } // ENDIF- Not an Iso File? Stop early. + + if (fromfile->multi == 1) + { + i = 0; + while ((i < 10) && + (IsoFileSeek(fromfile, fromfile->multisectorend[i] + 1) == 0)) i++; + endsector = fromfile->multisectorend[fromfile->multiend]; + } + else + { + endsector = fromfile->filesectorsize; + } // ENDIF- Get ending sector from multifile? (Or single file?) + IsoFileSeek(fromfile, 0); + + // Open Progress Bar + sprintf(templine, "%s: %s%s -> %s%s", + filename, + multinames[fromfile->multi], + compressdesc[fromfile->compress], + multinames[tofile->multi], + compressdesc[tofile->compress]); + ProgressBoxStart(templine, endsector); + + tofile->cdvdtype = fromfile->cdvdtype; + for (i = 0; i < 2048; i++) tofile->toc[i] = fromfile->toc[i]; + + stop = 0; + mainbox.stop = 0; + progressbox.stop = 0; + while ((stop == 0) && (tofile->sectorpos < endsector)) + { + retval = IsoFileRead(fromfile, tempblock); + if (retval < 0) + { + MessageBoxShow("Trouble reading source file", 3); + stop = 1; + } + else + { + retval = IsoFileWrite(tofile, tempblock); + if (retval < 0) + { + MessageBoxShow("Trouble writing new file", 3); + stop = 1; + } // ENDIF- Trouble writing out the next block? + } // ENDIF- Trouble reading in the next block? + + ProgressBoxTick(tofile->sectorpos); + while (gtk_events_pending()) gtk_main_iteration(); + + if (mainbox.stop != 0) stop = 2; + if (progressbox.stop != 0) stop = 2; + } // ENDWHILE- Not stopped for some reason... + + ProgressBoxStop(); + + if (stop == 0) + { + if (tofile->multi == 1) tofile->name[tofile->multipos] = '0'; // First file + strcpy(templine, tofile->name); + + // fromfile = IsoFileCloseAndDelete(fromfile); + fromfile = IsoFileClose(fromfile); + + IsoSaveTOC(tofile); + tofile = IsoFileClose(tofile); + gtk_entry_set_text(GTK_ENTRY(mainbox.file), templine); + + } + else + { + fromfile = IsoFileClose(fromfile); + tofile = IsoFileCloseAndDelete(tofile); + } // ENDIF- Did we succeed in the transfer? + + if (stop != 1) ConversionBoxRefocus(); + if (stop == 0) ConversionBoxCancelEvent(widget, event, data); + return(TRUE); +} // END ConversionBoxOKEvent() + + +gint ConversionBoxBrowseEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + ConversionBoxUnfocus(); + + // Transfer file name to file selection + gtk_file_selection_set_filename(GTK_FILE_SELECTION(selectionbox.window), + gtk_entry_get_text(GTK_ENTRY(conversionbox.file))); + selectionbox.wherefrom = 3; // From the Conversion Window + SelectionBoxRefocus(); + return(TRUE); +} // END ConversionBoxBrowseEvent() + + +void ConversionBoxDisplay() +{ + GtkWidget *item; + GtkWidget *hbox1; + GtkWidget *vbox1; + int nameptr; + + conversionbox.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_container_set_border_width(GTK_CONTAINER(conversionbox.window), 5); + gtk_window_set_title(GTK_WINDOW(conversionbox.window), "CDVDisoEFP File Conversion"); + gtk_window_set_position(GTK_WINDOW(conversionbox.window), GTK_WIN_POS_CENTER); + + g_signal_connect(G_OBJECT(conversionbox.window), "delete_event", + G_CALLBACK(ConversionBoxCancelEvent), NULL); + + vbox1 = gtk_vbox_new(FALSE, 5); + gtk_container_add(GTK_CONTAINER(conversionbox.window), vbox1); + gtk_container_set_border_width(GTK_CONTAINER(vbox1), 5); + gtk_widget_show(vbox1); + + hbox1 = gtk_hbox_new(FALSE, 10); + gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); + gtk_widget_show(hbox1); + + item = gtk_label_new("Iso File:"); + gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0); + gtk_widget_show(item); + item = NULL; + + conversionbox.file = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(hbox1), conversionbox.file, TRUE, TRUE, 0); + gtk_widget_show(conversionbox.file); + g_signal_connect(G_OBJECT(conversionbox.file), "changed", + G_CALLBACK(ConversionBoxFileEvent), NULL); + + conversionbox.selectbutton = gtk_button_new_with_label("Browse"); + gtk_box_pack_start(GTK_BOX(hbox1), conversionbox.selectbutton, FALSE, FALSE, 0); + gtk_widget_show(conversionbox.selectbutton); + g_signal_connect(G_OBJECT(conversionbox.selectbutton), "clicked", + G_CALLBACK(ConversionBoxBrowseEvent), NULL); + hbox1 = NULL; + + conversionbox.filedesc = gtk_label_new("File Type: ---"); + gtk_box_pack_start(GTK_BOX(vbox1), conversionbox.filedesc, FALSE, FALSE, 0); + gtk_widget_show(conversionbox.filedesc); + // ConversionBoxFileEvent(NULL, 0, NULL); // Work out compromise later... + + item = gtk_hseparator_new(); + gtk_box_pack_start(GTK_BOX(vbox1), item, TRUE, TRUE, 0); + gtk_widget_show(item); + item = NULL; + + hbox1 = gtk_hbox_new(FALSE, 10); + gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); + gtk_widget_show(hbox1); + + item = gtk_label_new("Change Compression To:"); + gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0); + gtk_widget_show(item); + item = NULL; + + conversionbox.compress = gtk_combo_box_new_text(); + gtk_box_pack_start(GTK_BOX(hbox1), conversionbox.compress, FALSE, FALSE, 0); + nameptr = 0; + while (compressnames[nameptr] != NULL) + { + gtk_combo_box_append_text(GTK_COMBO_BOX(conversionbox.compress), + compressnames[nameptr]); + nameptr++; + } // ENDWHILE- loading compression types into combo box + gtk_combo_box_set_active(GTK_COMBO_BOX(conversionbox.compress), 0); // Temp Line + gtk_widget_show(conversionbox.compress); + hbox1 = NULL; + + hbox1 = gtk_hbox_new(FALSE, 10); + gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); + gtk_widget_show(hbox1); + + item = gtk_label_new("Multiple Files (all under 2 GB):"); + gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0); + gtk_widget_show(item); + item = NULL; + + conversionbox.multi = gtk_check_button_new(); + gtk_box_pack_start(GTK_BOX(hbox1), conversionbox.multi, FALSE, FALSE, 0); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(conversionbox.multi), FALSE); + gtk_widget_show(conversionbox.multi); + hbox1 = NULL; + + hbox1 = gtk_hbutton_box_new(); + gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); + gtk_widget_show(hbox1); + + conversionbox.okbutton = gtk_button_new_with_label("Change File"); + gtk_box_pack_start(GTK_BOX(hbox1), conversionbox.okbutton, TRUE, TRUE, 0); + gtk_widget_show(conversionbox.okbutton); + g_signal_connect(G_OBJECT(conversionbox.okbutton), "clicked", + G_CALLBACK(ConversionBoxOKEvent), NULL); + + conversionbox.cancelbutton = gtk_button_new_with_label("Cancel"); + gtk_box_pack_start(GTK_BOX(hbox1), conversionbox.cancelbutton, TRUE, TRUE, 0); + gtk_widget_show(conversionbox.cancelbutton); + g_signal_connect(G_OBJECT(conversionbox.cancelbutton), "clicked", + G_CALLBACK(ConversionBoxCancelEvent), NULL); + hbox1 = NULL; + vbox1 = NULL; +} // END ConversionBoxDisplay() diff --git a/plugins/CDVDisoEFP/src/Linux/conversionbox.h b/plugins/CDVDisoEFP/src/Linux/conversionbox.h index f0ff425924..8f2002c7e0 100644 --- a/plugins/CDVDisoEFP/src/Linux/conversionbox.h +++ b/plugins/CDVDisoEFP/src/Linux/conversionbox.h @@ -1,94 +1,44 @@ /* conversionbox.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef CONVERSIONBOX_H - #define CONVERSIONBOX_H - - - - #include - - - - -struct ConversionBoxData { - - GtkWidget *window; // GtkWindow - - GtkWidget *file; // GtkEntry - - GtkWidget *selectbutton; // GtkButton - - GtkWidget *filedesc; // GtkLabel - - GtkWidget *compress; // GtkComboBox - - GtkWidget *multi; // GtkCheckButton - - GtkWidget *okbutton; // GtkButton - - GtkWidget *cancelbutton; // GtkButton - +struct ConversionBoxData +{ + GtkWidget *window; // GtkWindow + GtkWidget *file; // GtkEntry + GtkWidget *selectbutton; // GtkButton + GtkWidget *filedesc; // GtkLabel + GtkWidget *compress; // GtkComboBox + GtkWidget *multi; // GtkCheckButton + GtkWidget *okbutton; // GtkButton + GtkWidget *cancelbutton; // GtkButton }; - - extern struct ConversionBoxData conversionbox; - - extern void ConversionBoxDestroy(); - extern void ConversionBoxRefocus(); - extern void ConversionBoxDisplay(); - - - - #endif /* CONVERSIONBOX_H */ - diff --git a/plugins/CDVDisoEFP/src/Linux/device.c b/plugins/CDVDisoEFP/src/Linux/device.c index 51efeea883..8c736f9332 100644 --- a/plugins/CDVDisoEFP/src/Linux/device.c +++ b/plugins/CDVDisoEFP/src/Linux/device.c @@ -17,7 +17,6 @@ * * PCSX2 members can be contacted through their website at www.pcsx2.net. */ - #include // errno #include // open() #include // NULL @@ -28,391 +27,389 @@ #include // open() #include // time_t, time(), struct timeval #include // close(), select() - #include // CD/DVD based ioctl() and defines. - #include "logfile.h" #include "conf.h" #include "CD.h" #include "DVD.h" #include "device.h" - - // Globals - int devicehandle; // File Handle for the device/drive s32 devicecapability; // Capability Flags time_t lasttime; // Time marker (in case something gets called too often) s32 traystatus; // Is the CD/DVD tray open? - s32 disctype; // Type of disc in drive (Video DVD, PSX CD, etc.) u8 tocbuffer[2048]; - -void DeviceInit() { - devicehandle = -1; - devicecapability = 0; - lasttime = time(NULL); - - InitDisc(); +void DeviceInit() +{ + devicehandle = -1; + devicecapability = 0; + lasttime = time(NULL); + InitDisc(); } // END DeviceInit() - - // Called by DeviceOpen(), DeviceGetDiskType() -void InitDisc() { - int i; - +void InitDisc() +{ + int i; #ifdef VERBOSE_FUNCTION_DEVICE - PrintLog("CDVD device: InitDisc()"); + PrintLog("CDVD device: InitDisc()"); #endif /* VERBOSE_FUNCTION_DEVICE */ + if ((disctype == CDVD_TYPE_PS2DVD) || + (disctype == CDVD_TYPE_DVDV)) + { + InitDVDInfo(); + } // ENDIF- Clean out DVD Disc Info? - if((disctype == CDVD_TYPE_PS2DVD) || - (disctype == CDVD_TYPE_DVDV)) { - InitDVDInfo(); - } // ENDIF- Clean out DVD Disc Info? + if ((disctype == CDVD_TYPE_PS2CD) || + (disctype == CDVD_TYPE_PS2CDDA) || + (disctype == CDVD_TYPE_PSCD) || + (disctype == CDVD_TYPE_PSCDDA) || + (disctype == CDVD_TYPE_CDDA)) + { + InitCDInfo(); + } // ENDIF- Clean out DVD Disc Info? - if((disctype == CDVD_TYPE_PS2CD) || - (disctype == CDVD_TYPE_PS2CDDA) || - (disctype == CDVD_TYPE_PSCD) || - (disctype == CDVD_TYPE_PSCDDA) || - (disctype == CDVD_TYPE_CDDA)) { - InitCDInfo(); - } // ENDIF- Clean out DVD Disc Info? - - disctype = CDVD_TYPE_NODISC; - for(i = 0; i > sizeof(tocbuffer); i++) tocbuffer[i] = 0x00; + disctype = CDVD_TYPE_NODISC; + for (i = 0; i > sizeof(tocbuffer); i++) tocbuffer[i] = 0x00; } // END InitDisc() - -s32 DiscInserted() { - if(devicehandle == -1) return(-1); - if(traystatus == CDVD_TRAY_OPEN) return(-1); - if(disctype == CDVD_TYPE_ILLEGAL) return(-1); - // if(disctype == CDVD_TYPE_UNKNOWN) return(-1); // Hmm. Let this one through? - if(disctype == CDVD_TYPE_DETCTDVDD) return(-1); - if(disctype == CDVD_TYPE_DETCTDVDS) return(-1); - if(disctype == CDVD_TYPE_DETCTCD) return(-1); - if(disctype == CDVD_TYPE_DETCT) return(-1); - if(disctype == CDVD_TYPE_NODISC) return(-1); - +s32 DiscInserted() +{ + if (devicehandle == -1) return(-1); + if (traystatus == CDVD_TRAY_OPEN) return(-1); + if (disctype == CDVD_TYPE_ILLEGAL) return(-1); + // if(disctype == CDVD_TYPE_UNKNOWN) return(-1); // Hmm. Let this one through? + if (disctype == CDVD_TYPE_DETCTDVDD) return(-1); + if (disctype == CDVD_TYPE_DETCTDVDS) return(-1); + if (disctype == CDVD_TYPE_DETCTCD) return(-1); + if (disctype == CDVD_TYPE_DETCT) return(-1); + if (disctype == CDVD_TYPE_NODISC) return(-1); #ifdef VERBOSE_FUNCTION_DEVICE - PrintLog("CDVD device: DiscInserted()"); + PrintLog("CDVD device: DiscInserted()"); #endif /* VERBOSE_FUNCTION_DEVICE */ - - return(0); + return(0); } // END DiscInserted() - // Called by DeviceTrayStatus() and CDVDopen() -s32 DeviceOpen() { - // s32 s32result; +s32 DeviceOpen() +{ + // s32 s32result; - errno = 0; + errno = 0; - if(devicehandle != -1) { + if (devicehandle != -1) + { #ifdef VERBOSE_WARNING_DEVICE - PrintLog("CDVD device: Device already open!"); + PrintLog("CDVD device: Device already open!"); #endif /* VERBOSE_WARNING_DEVICE */ - return(0); - } // ENDIF- Is the CD/DVD already in use? That's fine. - + return(0); + } // ENDIF- Is the CD/DVD already in use? That's fine. #ifdef VERBOSE_FUNCTION_DEVICE - PrintLog("CDVD device: DeviceOpen()"); + PrintLog("CDVD device: DeviceOpen()"); #endif /* VERBOSE_FUNCTION_DEVICE */ + // InitConf(); + // LoadConf(); // Should be done once before making this call - // InitConf(); - // LoadConf(); // Should be done once before making this call - - devicehandle = open(conf.devicename, O_RDONLY | O_NONBLOCK); - if(devicehandle == -1) { + devicehandle = open(conf.devicename, O_RDONLY | O_NONBLOCK); + if (devicehandle == -1) + { #ifdef VERBOSE_WARNINGS - PrintLog("CDVD device: Error opening device: %i:%s", errno, strerror(errno)); + PrintLog("CDVD device: Error opening device: %i:%s", errno, strerror(errno)); #endif /* VERBOSE_WARNINGS */ - return(-1); - } // ENDIF- Failed to open device? Abort + return(-1); + } // ENDIF- Failed to open device? Abort - // Note: Hmm. Need a minimum capability in case this fails? - devicecapability = ioctl(devicehandle, CDROM_GET_CAPABILITY); - if(errno != 0) { + // Note: Hmm. Need a minimum capability in case this fails? + devicecapability = ioctl(devicehandle, CDROM_GET_CAPABILITY); + if (errno != 0) + { #ifdef VERBOSE_WARNINGS - PrintLog("CDVD device: Error getting device capabilities: %i:%s", errno, strerror(errno)); + PrintLog("CDVD device: Error getting device capabilities: %i:%s", errno, strerror(errno)); #endif /* VERBOSE_WARNINGS */ - close(devicehandle); - devicehandle = -1; - devicecapability = 0; - return(-1); - } // ENDIF- Can't read drive capabilities? Close and Abort. + close(devicehandle); + devicehandle = -1; + devicecapability = 0; + return(-1); + } // ENDIF- Can't read drive capabilities? Close and Abort. #ifdef VERBOSE_DISC_TYPE - PrintLog("CDVD device: Device Type(s)"); - if(devicecapability < CDC_CD_R) PrintLog("CDVD device: CD"); - if(devicecapability & CDC_CD_R) PrintLog("CDVD device: CD-R"); - if(devicecapability & CDC_CD_RW) PrintLog("CDVD device: CD-RW"); - if(devicecapability & CDC_DVD) PrintLog("CDVD device: DVD"); - if(devicecapability & CDC_DVD_R) PrintLog("CDVD device: DVD-R"); - if(devicecapability & CDC_DVD_RAM) PrintLog("CDVD device: DVD-RAM"); + PrintLog("CDVD device: Device Type(s)"); + if (devicecapability < CDC_CD_R) PrintLog("CDVD device: CD"); + if (devicecapability & CDC_CD_R) PrintLog("CDVD device: CD-R"); + if (devicecapability & CDC_CD_RW) PrintLog("CDVD device: CD-RW"); + if (devicecapability & CDC_DVD) PrintLog("CDVD device: DVD"); + if (devicecapability & CDC_DVD_R) PrintLog("CDVD device: DVD-R"); + if (devicecapability & CDC_DVD_RAM) PrintLog("CDVD device: DVD-RAM"); #endif /* VERBOSE_DISC_TYPE */ #ifdef VERBOSE_DISC_INFO - PrintLog("CDVD device: Device Capabilities:"); - if(devicecapability & CDC_CLOSE_TRAY) PrintLog("CDVD device: Can close a tray"); - if(devicecapability & CDC_OPEN_TRAY) PrintLog("CDVD device: Can open a tray"); - // if(devicecapability & CDC_LOCK) PrintLog("CDVD device: Can lock the drive door"); - if(devicecapability & CDC_SELECT_SPEED) PrintLog("CDVD device: Can change spin speed"); - // if(devicecapability & CDC_SELECT_DISC) PrintLog("CDVD device: Can change disks (multi-disk tray)"); - // if(devicecapability & CDC_MULTI_SESSION) PrintLog("CDVD device: Can read multi-session disks"); - // if(devicecapability & CDC_MCN) PrintLog("CDVD device: Can read Medium Catalog Numbers (maybe)"); - if(devicecapability & CDC_MEDIA_CHANGED) PrintLog("CDVD device: Can tell if the disc was changed"); - if(devicecapability & CDC_PLAY_AUDIO) PrintLog("CDVD device: Can play audio disks"); - // if(devicecapability & CDC_RESET) PrintLog("CDVD device: Can reset the device"); - //if(devicecapability & CDC_IOCTLS) PrintLog("CDVD device: Odd IOCTLs. Not sure of compatability"); - if(devicecapability & CDC_DRIVE_STATUS) PrintLog("CDVD device: Can monitor the drive tray"); + PrintLog("CDVD device: Device Capabilities:"); + if (devicecapability & CDC_CLOSE_TRAY) PrintLog("CDVD device: Can close a tray"); + if (devicecapability & CDC_OPEN_TRAY) PrintLog("CDVD device: Can open a tray"); + // if(devicecapability & CDC_LOCK) PrintLog("CDVD device: Can lock the drive door"); + if (devicecapability & CDC_SELECT_SPEED) PrintLog("CDVD device: Can change spin speed"); + // if(devicecapability & CDC_SELECT_DISC) PrintLog("CDVD device: Can change disks (multi-disk tray)"); + // if(devicecapability & CDC_MULTI_SESSION) PrintLog("CDVD device: Can read multi-session disks"); + // if(devicecapability & CDC_MCN) PrintLog("CDVD device: Can read Medium Catalog Numbers (maybe)"); + if (devicecapability & CDC_MEDIA_CHANGED) PrintLog("CDVD device: Can tell if the disc was changed"); + if (devicecapability & CDC_PLAY_AUDIO) PrintLog("CDVD device: Can play audio disks"); + // if(devicecapability & CDC_RESET) PrintLog("CDVD device: Can reset the device"); + //if(devicecapability & CDC_IOCTLS) PrintLog("CDVD device: Odd IOCTLs. Not sure of compatability"); + if (devicecapability & CDC_DRIVE_STATUS) PrintLog("CDVD device: Can monitor the drive tray"); #endif /* VERBOSE_DISC_INFO */ - ////// Should be called after an open (instead of inside of one) - // InitDisc(); - // traystatus = CDVD_TRAY_OPEN; // Start with Tray Open - // DeviceTrayStatus(); // Now find out for sure. - - return(0); // Device opened and ready for use. + ////// Should be called after an open (instead of inside of one) + // InitDisc(); + // traystatus = CDVD_TRAY_OPEN; // Start with Tray Open + // DeviceTrayStatus(); // Now find out for sure. + return(0); // Device opened and ready for use. } // END DeviceOpen() - - // Called by DeviceTrayStatus(), CDVDclose(), and CDVDshutdown() -void DeviceClose() { - // s32 s32result; - int zerospeed; - - zerospeed = 0; +void DeviceClose() +{ + // s32 s32result; + int zerospeed; - if(devicehandle == -1) { + zerospeed = 0; + + if (devicehandle == -1) + { #ifdef VERBOSE_FUNCTION_DEVICE - PrintLog("CDVD device: Device already closed"); + PrintLog("CDVD device: Device already closed"); #endif /* VERBOSE_FUNCTION_DEVICE */ - return; - } // ENDIF- Device already closed? Ok. - + return; + } // ENDIF- Device already closed? Ok. #ifdef VERBOSE_FUNCTION_DEVICE - PrintLog("CDVD device: DeviceClose()"); + PrintLog("CDVD device: DeviceClose()"); #endif /* VERBOSE_FUNCTION_DEVICE */ - - InitDisc(); - close(devicehandle); - devicehandle = -1; - devicecapability = 0; - return; + InitDisc(); + close(devicehandle); + devicehandle = -1; + devicecapability = 0; + return; } // END CDVDclose() - -s32 DeviceReadTrack(u32 lsn, int mode, u8 *buffer) { - s32 s32result; - +s32 DeviceReadTrack(u32 lsn, int mode, u8 *buffer) +{ + s32 s32result; #ifdef VERBOSE_FUNCTION_DEVICE - PrintLog("CDVD device: DeviceReadTrack(%i)", lsn); + PrintLog("CDVD device: DeviceReadTrack(%i)", lsn); #endif /* VERBOSE_FUNCTION_DEVICE */ - - if(DiscInserted() == -1) return(-1); - - // Get that data - if((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) { - s32result = DVDreadTrack(lsn, mode, buffer); - } else { - s32result = CDreadTrack(lsn, mode, buffer); - } //ENDIF- Read a DVD sector or a CD sector? - - return(s32result); + if (DiscInserted() == -1) return(-1); + // Get that data + if ((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) + { + s32result = DVDreadTrack(lsn, mode, buffer); + } + else + { + s32result = CDreadTrack(lsn, mode, buffer); + } //ENDIF- Read a DVD sector or a CD sector? + return(s32result); } // END DeviceReadTrack() - -s32 DeviceBufferOffset() { +s32 DeviceBufferOffset() +{ #ifdef VERBOSE_FUNCTION_DEVICE - PrintLog("CDVD device: DeviceBufferOffset()"); + PrintLog("CDVD device: DeviceBufferOffset()"); #endif /* VERBOSE_FUNCTION_DEVICE */ - - if(DiscInserted() == -1) return(-1); - - if((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) { - return(0); - } else { - return(CDgetBufferOffset()); - } // ENDIF- Is this a DVD? + if (DiscInserted() == -1) return(-1); + if ((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) + { + return(0); + } + else + { + return(CDgetBufferOffset()); + } // ENDIF- Is this a DVD? } // END DeviceBufferOffset() - -s32 DeviceGetTD(u8 track, cdvdTD *cdvdtd) { - if(DiscInserted() == -1) return(-1); - - if((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) { - return(DVDgetTD(track, cdvdtd)); - } else { - return(CDgetTD(track, cdvdtd)); - } // ENDIF- Is this a DVD? +s32 DeviceGetTD(u8 track, cdvdTD *cdvdtd) +{ + if (DiscInserted() == -1) return(-1); + if ((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) + { + return(DVDgetTD(track, cdvdtd)); + } + else + { + return(CDgetTD(track, cdvdtd)); + } // ENDIF- Is this a DVD? } // END DeviceGetTD() - - // Called by DeviceTrayStatus() -s32 DeviceGetDiskType() { - s32 s32result; - s32 ioctldisktype; - - errno = 0; +s32 DeviceGetDiskType() +{ + s32 s32result; + s32 ioctldisktype; - if(devicehandle == -1) { - return(-1); - } // ENDIF- Someone forget to open the device? + errno = 0; - if(traystatus == CDVD_TRAY_OPEN) { - return(disctype); - } // ENDIF- Is the device tray open? No disc to check yet. + if (devicehandle == -1) + { + return(-1); + } // ENDIF- Someone forget to open the device? - if(disctype != CDVD_TYPE_NODISC) { - return(disctype); - } // ENDIF- Already checked? Drive still closed? Disc hasn't changed. + if (traystatus == CDVD_TRAY_OPEN) + { + return(disctype); + } // ENDIF- Is the device tray open? No disc to check yet. + + if (disctype != CDVD_TYPE_NODISC) + { + return(disctype); + } // ENDIF- Already checked? Drive still closed? Disc hasn't changed. #ifdef VERBOSE_FUNCTION_DEVICE - PrintLog("CDVD device: DeviceGetDiskType()"); + PrintLog("CDVD device: DeviceGetDiskType()"); #endif /* VERBOSE_FUNCTION_DEVICE */ - disctype = CDVD_TYPE_DETCT; - - ioctldisktype = ioctl(devicehandle, CDROM_DISC_STATUS); - if(errno != 0) { + disctype = CDVD_TYPE_DETCT; + ioctldisktype = ioctl(devicehandle, CDROM_DISC_STATUS); + if (errno != 0) + { #ifdef VERBOSE_WARNINGS - PrintLog("CDVD device: Trouble reading Disc Type!"); - PrintLog("CDVD device: Error: %i:%s", errno, strerror(errno)); + PrintLog("CDVD device: Trouble reading Disc Type!"); + PrintLog("CDVD device: Error: %i:%s", errno, strerror(errno)); #endif /* VERBOSE_WARNINGS */ - disctype = CDVD_TYPE_UNKNOWN; - return(disctype); - } // ENDIF- Trouble probing for a disc? + disctype = CDVD_TYPE_UNKNOWN; + return(disctype); + } // ENDIF- Trouble probing for a disc? + s32result = DVDgetDiskType(ioctldisktype); + if (s32result != -1) + { + return(disctype); + } // ENDIF- Did we find a disc type? - s32result = DVDgetDiskType(ioctldisktype); - if(s32result != -1) { - return(disctype); - } // ENDIF- Did we find a disc type? - - s32result = CDgetDiskType(ioctldisktype); - if(s32result != -1) { - return(disctype); - } // ENDIF- Did we find a disc type? - - disctype = CDVD_TYPE_UNKNOWN; // Not a CD? Not a DVD? Is is peanut butter? - return(disctype); + s32result = CDgetDiskType(ioctldisktype); + if (s32result != -1) + { + return(disctype); + } // ENDIF- Did we find a disc type? + disctype = CDVD_TYPE_UNKNOWN; // Not a CD? Not a DVD? Is is peanut butter? + return(disctype); } // END CDVDgetDiskType() - // Called by PollLoop() and CDVDgetTrayStatus() -s32 DeviceTrayStatus() { - s32 s32result; +s32 DeviceTrayStatus() +{ + s32 s32result; - errno = 0; + errno = 0; #ifdef VERBOSE_FUNCTION_DEVICE - PrintLog("CDVD device: DeviceTrayStatus()"); + PrintLog("CDVD device: DeviceTrayStatus()"); #endif /* VERBOSE_FUNCTION_DEVICE */ - if(devicehandle == -1) { - return(-1); - } // ENDIF- Someone forget to open the device? + if (devicehandle == -1) + { + return(-1); + } // ENDIF- Someone forget to open the device? - if((devicecapability & CDC_DRIVE_STATUS) != 0) { - s32result = ioctl(devicehandle, CDROM_DRIVE_STATUS); - if(s32result < 0) { + if ((devicecapability & CDC_DRIVE_STATUS) != 0) + { + s32result = ioctl(devicehandle, CDROM_DRIVE_STATUS); + if (s32result < 0) + { #ifdef VERBOSE_WARNINGS - PrintLog("CDVD device: Trouble reading Drive Status!"); - PrintLog("CDVD device: Error: (%i) %i:%s", s32result, errno, strerror(errno)); + PrintLog("CDVD device: Trouble reading Drive Status!"); + PrintLog("CDVD device: Error: (%i) %i:%s", s32result, errno, strerror(errno)); #endif /* VERBOSE_WARNINGS */ - s32result = CDS_TRAY_OPEN; - } // ENDIF- Failure to get status? Assume it's open. - errno = 0; - - } else { - s32result = ioctl(devicehandle, CDROM_DISC_STATUS); - if(errno != 0) { + s32result = CDS_TRAY_OPEN; + } // ENDIF- Failure to get status? Assume it's open. + errno = 0; + } + else + { + s32result = ioctl(devicehandle, CDROM_DISC_STATUS); + if (errno != 0) + { #ifdef VERBOSE_WARNINGS - PrintLog("CDVD device: Trouble detecting Disc Status presense!"); - PrintLog("CDVD device: Error: (%i) %i:%s", s32result, errno, strerror(errno)); + PrintLog("CDVD device: Trouble detecting Disc Status presense!"); + PrintLog("CDVD device: Error: (%i) %i:%s", s32result, errno, strerror(errno)); #endif /* VERBOSE_WARNINGS */ - s32result = CDS_TRAY_OPEN; - errno = 0; - } // ENDIF- Trouble? - if(s32result == CDS_NO_DISC) { - s32result = CDS_TRAY_OPEN; - } // ENDIF- Is there no disc in the device? Guess the tray is open - } // ENDIF- Can we poll the tray directly? (Or look at disc status instead?) - - if(s32result == CDS_TRAY_OPEN) { - traystatus = CDVD_TRAY_OPEN; - if(disctype != CDVD_TYPE_NODISC) { - DeviceClose(); // Kind of severe way of flushing all buffers. - DeviceOpen(); - InitDisc(); - } // ENDIF- Tray just opened... clear disc info - } else { - traystatus = CDVD_TRAY_CLOSE; - if(disctype == CDVD_TYPE_NODISC) { - DeviceGetDiskType(); - } // ENDIF- Tray just closed? Get disc information - } // ENDIF- Do we detect an open tray? - return(traystatus); + s32result = CDS_TRAY_OPEN; + errno = 0; + } // ENDIF- Trouble? + if (s32result == CDS_NO_DISC) + { + s32result = CDS_TRAY_OPEN; + } // ENDIF- Is there no disc in the device? Guess the tray is open + } // ENDIF- Can we poll the tray directly? (Or look at disc status instead?) + if (s32result == CDS_TRAY_OPEN) + { + traystatus = CDVD_TRAY_OPEN; + if (disctype != CDVD_TYPE_NODISC) + { + DeviceClose(); // Kind of severe way of flushing all buffers. + DeviceOpen(); + InitDisc(); + } // ENDIF- Tray just opened... clear disc info + } + else + { + traystatus = CDVD_TRAY_CLOSE; + if (disctype == CDVD_TYPE_NODISC) + { + DeviceGetDiskType(); + } // ENDIF- Tray just closed? Get disc information + } // ENDIF- Do we detect an open tray? + return(traystatus); } // END CDVD_getTrayStatus() +s32 DeviceTrayOpen() +{ + s32 s32result; + errno = 0; -s32 DeviceTrayOpen() { - s32 s32result; + if (devicehandle == -1) + { + return(-1); + } // ENDIF- Someone forget to open the device? - errno = 0; - - if(devicehandle == -1) { - return(-1); - } // ENDIF- Someone forget to open the device? - - if((devicecapability & CDC_OPEN_TRAY) == 0) { - return(-1); - } // ENDIF- Don't have open capability? Error out. - - // Tray already open? Exit. - if(traystatus == CDVD_TRAY_OPEN) return(0); + if ((devicecapability & CDC_OPEN_TRAY) == 0) + { + return(-1); + } // ENDIF- Don't have open capability? Error out. + // Tray already open? Exit. + if (traystatus == CDVD_TRAY_OPEN) return(0); #ifdef VERBOSE_FUNCTION_DEVICE - PrintLog("CDVD device: DeviceTrayOpen()"); + PrintLog("CDVD device: DeviceTrayOpen()"); #endif /* VERBOSE_FUNCTION_DEVICE */ - - s32result = ioctl(devicehandle, CDROMEJECT); + s32result = ioctl(devicehandle, CDROMEJECT); #ifdef VERBOSE_WARNINGS - if((s32result != 0) || (errno != 0)) { - PrintLog("CDVD device: Could not open the tray!"); - PrintLog("CDVD device: Error: (%i) %i:%s", s32result, errno, strerror(errno)); - } // ENDIF- Trouble? + if ((s32result != 0) || (errno != 0)) + { + PrintLog("CDVD device: Could not open the tray!"); + PrintLog("CDVD device: Error: (%i) %i:%s", s32result, errno, strerror(errno)); + } // ENDIF- Trouble? #endif /* VERBOSE_WARNINGS */ - return(s32result); + return(s32result); } // END DeviceTrayOpen() - - -s32 DeviceTrayClose() { - s32 s32result; - - errno = 0; - - if(devicehandle == -1) { - return(-1); - } // ENDIF- Someone forget to open the device? - - if((devicecapability & CDC_CLOSE_TRAY) == 0) { - return(-1); - } // ENDIF- Don't have close capability? Error out. - - // Tray already closed? Exit. - if(traystatus == CDVD_TRAY_CLOSE) return(0); - +s32 DeviceTrayClose() +{ + s32 s32result; + errno = 0; + if (devicehandle == -1) + { + return(-1); + } // ENDIF- Someone forget to open the device? + if ((devicecapability & CDC_CLOSE_TRAY) == 0) + { + return(-1); + } // ENDIF- Don't have close capability? Error out. + // Tray already closed? Exit. + if (traystatus == CDVD_TRAY_CLOSE) return(0); #ifdef VERBOSE_FUNCTION_DEVICE - PrintLog("CDVD device: DeviceTrayClose()"); + PrintLog("CDVD device: DeviceTrayClose()"); #endif /* VERBOSE_FUNCTION_DEVICE */ - - s32result = ioctl(devicehandle, CDROMCLOSETRAY); + s32result = ioctl(devicehandle, CDROMCLOSETRAY); #ifdef VERBOSE_WARNINGS - if((s32result != 0) || (errno != 0)) { - PrintLog("CDVD device: Could not close the tray!"); - PrintLog("CDVD device: Error: (%i) %i:%s", s32result, errno, strerror(errno)); - } // ENDIF- Trouble? + if ((s32result != 0) || (errno != 0)) + { + PrintLog("CDVD device: Could not close the tray!"); + PrintLog("CDVD device: Error: (%i) %i:%s", s32result, errno, strerror(errno)); + } // ENDIF- Trouble? #endif /* VERBOSE_WARNINGS */ - return(s32result); + return(s32result); } // END DeviceTrayClose() diff --git a/plugins/CDVDisoEFP/src/Linux/device.h b/plugins/CDVDisoEFP/src/Linux/device.h index ec38e857a5..462231e4ea 100644 --- a/plugins/CDVDisoEFP/src/Linux/device.h +++ b/plugins/CDVDisoEFP/src/Linux/device.h @@ -1,138 +1,60 @@ /* device.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - #ifndef __DEVICE_H__ - #define __DEVICE_H__ - - - - #include // time_t - - - #ifndef __LINUX__ - #ifdef __linux__ - #define __LINUX__ - #endif /* __linux__ */ - #endif /* No __LINUX__ */ - #define CDVDdefs - #include "../PS2Edefs.h" - - - - // #define VERBOSE_FUNCTION_DEVICE - // #define VERBOSE_WARNINGS - #define VERBOSE_DISC_TYPE - #define VERBOSE_DISC_INFO - - - - // Device Data - - extern int devicehandle; - extern s32 devicecapability; // Need to export? - - - extern time_t lasttime; - extern s32 traystatus; - extern s32 disctype; - extern u8 tocbuffer[]; - - - - // Device Functions - - - extern void DeviceInit(); - extern void InitDisc(); - extern s32 DiscInserted(); - extern s32 DeviceOpen(); - extern void DeviceClose(); - extern s32 DeviceReadTrack(u32 lsn, int mode, u8 *buffer); - extern s32 DeviceBufferOffset(); - extern s32 DeviceGetTD(u8 track, cdvdTD *cdvdtd); - extern s32 DeviceGetDiskType(); - extern s32 DeviceTrayStatus(); - extern s32 DeviceTrayOpen(); - extern s32 DeviceTrayClose(); - - - - #endif /* __DEVICE_H__ */ - diff --git a/plugins/CDVDisoEFP/src/Linux/devicebox.c b/plugins/CDVDisoEFP/src/Linux/devicebox.c index 128d7ed0e7..db1c85c113 100644 --- a/plugins/CDVDisoEFP/src/Linux/devicebox.c +++ b/plugins/CDVDisoEFP/src/Linux/devicebox.c @@ -1,886 +1,475 @@ -/* devicebox.c - - * Copyright (C) 2002-2005 PCSX2 Team - - * - - * This program is free software; you can redistribute it and/or modify - - * it under the terms of the GNU General Public License as published by - - * the Free Software Foundation; either version 2 of the License, or - - * (at your option) any later version. - - * - - * This program is distributed in the hope that it will be useful, - - * but WITHOUT ANY WARRANTY; without even the implied warranty of - - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - - * GNU General Public License for more details. - - * - - * You should have received a copy of the GNU General Public License - - * along with this program; if not, write to the Free Software - - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - * - - * PCSX2 members can be contacted through their website at www.pcsx2.net. - - */ - - - - - -#include // NULL - -#include // sprintf() - -#include // strcpy() - -#include // stat() - -#include // stat() - -#include // stat() - - - -#include // gtk_button_new_with_label() - -#include // gtk_combo_box_new() - -#include // gtk_check_button_new() - -#include // gtk_container_add() - -#include // gtk_entry_new() - -#include // gtk_file_selection_set_filename() - -#include // gtk_hbutton_box_new() - -#include // gtk_hbox_new() - -#include // gtk_hseparator_new() - -#include // gtk_label_new() - -#include // gtk_main_iteration() - -#include // gtk_toggle_button_get_active() - -#include // gtk_vbox_new() - -#include // gtk_window_new() - - - -#ifndef __LINUX__ - -#ifdef __linux__ - -#define __LINUX__ - -#endif /* __linux__ */ - -#endif /* No __LINUX__ */ - -#define CDVDdefs - -#include "PS2Edefs.h" - - - -#include "conf.h" - -#include "device.h" - -#include "isofile.h" - -#include "isocompress.h" // compressdesc[] - -// #include "imagetype.h" // imagedata[].name - -#include "multifile.h" // multinames[] - -#include "toc.h" - -#include "progressbox.h" - -#include "messagebox.h" - -#include "selectionbox.h" - -#include "mainbox.h" - -#include "devicebox.h" - - - - - -struct DeviceBoxData devicebox; - - - - - -void DeviceBoxDestroy() { - - if(devicebox.window != NULL) { - - gtk_widget_destroy(devicebox.window); - - devicebox.window = NULL; - - devicebox.device = NULL; - - devicebox.devicedesc = NULL; - - devicebox.file = NULL; - - devicebox.selectbutton = NULL; - - devicebox.filedesc = NULL; - - devicebox.compress = NULL; - - devicebox.multi = NULL; - - devicebox.okbutton = NULL; - - devicebox.cancelbutton = NULL; - - } // ENDIF- Do we have a Main Window still? - -} // END DeviceBoxDestroy() - - - - - -void DeviceBoxUnfocus() { - - gtk_widget_set_sensitive(devicebox.device, FALSE); - - gtk_widget_set_sensitive(devicebox.file, FALSE); - - gtk_widget_set_sensitive(devicebox.selectbutton, FALSE); - - gtk_widget_set_sensitive(devicebox.compress, FALSE); - - gtk_widget_set_sensitive(devicebox.multi, FALSE); - - gtk_widget_set_sensitive(devicebox.okbutton, FALSE); - - gtk_widget_set_sensitive(devicebox.cancelbutton, FALSE); - - gtk_widget_hide(devicebox.window); - - // gtk_window_iconify(GTK_WINDOW(devicebox.window)); - -} // END DeviceBoxUnfocus() - - - - - -gint DeviceBoxDeviceEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - struct stat filestat; - - int returnval; - - - - returnval = stat(gtk_entry_get_text(GTK_ENTRY(devicebox.device)), &filestat); - - if(returnval == -1) { - - gtk_label_set_text(GTK_LABEL(devicebox.devicedesc), "Device Type: ---"); - - return(TRUE); - - } // ENDIF- Not a name of any sort? - - - - if(S_ISDIR(filestat.st_mode) != 0) { - - gtk_label_set_text(GTK_LABEL(devicebox.devicedesc), "Device Type: Not a device"); - - return(TRUE); - - } // ENDIF- Not a regular file? - - - - gtk_label_set_text(GTK_LABEL(devicebox.devicedesc), "Device Type: Device Likely"); - - return(TRUE); - -} // END DeviceBoxDeviceEvent() - - - - - -gint DeviceBoxFileEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - int returnval; - - char templine[256]; - - struct IsoFile *tempfile; - - - - returnval = IsIsoFile(gtk_entry_get_text(GTK_ENTRY(devicebox.file))); - - if(returnval == -1) { - - gtk_label_set_text(GTK_LABEL(devicebox.filedesc), "File Type: ---"); - - return(TRUE); - - } // ENDIF- Not a name of any sort? - - - - if(returnval == -2) { - - gtk_label_set_text(GTK_LABEL(devicebox.filedesc), "File Type: Not a file"); - - return(TRUE); - - } // ENDIF- Not a regular file? - - - - if(returnval == -3) { - - gtk_label_set_text(GTK_LABEL(devicebox.filedesc), "File Type: Not a valid image file"); - - return(TRUE); - - } // ENDIF- Not an image file? - - - - if(returnval == -4) { - - gtk_label_set_text(GTK_LABEL(devicebox.filedesc), "File Type: Missing Table File (will rebuild)"); - - return(TRUE); - - } // ENDIF- Not a regular file? - - - - tempfile = IsoFileOpenForRead(gtk_entry_get_text(GTK_ENTRY(devicebox.file))); - - sprintf(templine, "File Type: %s%s%s", - - multinames[tempfile->multi], - - tempfile->imagename, - - compressdesc[tempfile->compress]); - - gtk_label_set_text(GTK_LABEL(devicebox.filedesc), templine); - - tempfile = IsoFileClose(tempfile); - - return(TRUE); - -} // END DeviceBoxFileEvent() - - - - - -void DeviceBoxRefocus() { - - GdkEvent event; - - - - DeviceBoxDeviceEvent(NULL, event, NULL); - - DeviceBoxFileEvent(NULL, event, NULL); - - - - gtk_widget_set_sensitive(devicebox.device, TRUE); - - gtk_widget_set_sensitive(devicebox.file, TRUE); - - gtk_widget_set_sensitive(devicebox.selectbutton, TRUE); - - gtk_widget_set_sensitive(devicebox.compress, TRUE); - - gtk_widget_set_sensitive(devicebox.multi, TRUE); - - gtk_widget_set_sensitive(devicebox.okbutton, TRUE); - - gtk_widget_set_sensitive(devicebox.cancelbutton, TRUE); - - gtk_window_set_focus(GTK_WINDOW(devicebox.window), devicebox.file); - - gtk_widget_show_all(devicebox.window); - - gtk_window_deiconify(GTK_WINDOW(devicebox.window)); - -} // END DeviceBoxRefocus() - - - - - -gint DeviceBoxCancelEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - gtk_widget_hide(devicebox.window); - - MainBoxRefocus(); - - return(TRUE); - -} // END DeviceBoxCancelEvent() - - - - - -gint DeviceBoxOKEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - char templine[256]; - - u8 tempbuffer[2352]; - - struct IsoFile *tofile; - - const char *tempdevice; - - s32 retval; - - cdvdTD cdvdtd; - - int stop; - - int compressmethod; - - int multi; - - int imagetype; - - int i; - - - - DeviceBoxUnfocus(); - - - - tempdevice = gtk_entry_get_text(GTK_ENTRY(devicebox.device)); - - strcpy(conf.devicename, tempdevice); // Temporarily put in new device name - - tempdevice = NULL; - - retval = DeviceOpen(); - - if(retval != 0) { - - DeviceClose(); - - MessageBoxShow("Could not open the device", 2); - - return(TRUE); - - } // ENDIF- Trouble opening device? Abort here. - - - - DeviceTrayStatus(); - - retval = DiscInserted(); - - if(retval != 0) { - - DeviceClose(); - - MessageBoxShow("No disc in the device\r\nPlease put a disc in and try again.", 2); - - return(TRUE); - - } // ENDIF- Trouble opening device? Abort here. - - - - retval = DeviceGetTD(0, &cdvdtd); // Fish for Ending Sector - - if(retval < 0) { - - DeviceClose(); - - MessageBoxShow("Could not retrieve disc sector size", 2); - - return(TRUE); - - } // ENDIF- Trouble getting disc sector count? - - - - compressmethod = gtk_combo_box_get_active(GTK_COMBO_BOX(devicebox.compress)); - - if(compressmethod > 0) compressmethod += 2; - - multi = 0; - - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(devicebox.multi)) == TRUE) - - multi = 1; - - - - imagetype = 0; - - if((disctype != CDVD_TYPE_PS2DVD) && - - (disctype != CDVD_TYPE_DVDV)) imagetype = 8; - - - - tofile = IsoFileOpenForWrite(gtk_entry_get_text(GTK_ENTRY(devicebox.file)), - - imagetype, - - multi, - - compressmethod); - - if(tofile == NULL) { - - DeviceClose(); - - MessageBoxShow("Could not create the new ISO file", 2); - - return(TRUE); - - } // ENDIF- Trouble opening the ISO file? - - - - // Open Progress Bar - - sprintf(templine, "%s -> %s", - - gtk_entry_get_text(GTK_ENTRY(devicebox.device)), tofile->name); - - ProgressBoxStart(templine, (off64_t) cdvdtd.lsn); - - - - tofile->cdvdtype = disctype; - - for(i = 0; i < 2048; i++) tofile->toc[i] = tocbuffer[i]; - - - - stop = 0; - - mainbox.stop = 0; - - progressbox.stop = 0; - - while((stop == 0) && (tofile->sectorpos < cdvdtd.lsn)) { - - if(imagetype == 0) { - - retval = DeviceReadTrack((u32) tofile->sectorpos, - - CDVD_MODE_2048, - - tempbuffer); - - } else { - - retval = DeviceReadTrack((u32) tofile->sectorpos, - - CDVD_MODE_2352, - - tempbuffer); - - } // ENDIF- Are we reading a DVD sector? (Or a CD sector?) - - if(retval < 0) { - - for(i = 0; i < 2352; i++) { - - tempbuffer[i] = 0; - - } // NEXT i- Zeroing the buffer - - } // ENDIF- Trouble reading next block? - - retval = IsoFileWrite(tofile, tempbuffer); - - if(retval < 0) { - - MessageBoxShow("Trouble writing new file", 3); - - stop = 1; - - } // ENDIF- Trouble writing out the next block? - - - - ProgressBoxTick(tofile->sectorpos); - - while(gtk_events_pending()) gtk_main_iteration(); - - - - if(mainbox.stop != 0) stop = 2; - - if(progressbox.stop != 0) stop = 2; - - } // ENDWHILE- No reason found to stop... - - - - ProgressBoxStop(); - - - - if(stop == 0) { - - if(tofile->multi == 1) tofile->name[tofile->multipos] = '0'; // First file - - strcpy(templine, tofile->name); - - } // ENDIF- Did we succeed with the transfer? - - - - DeviceClose(); - - if(stop == 0) { - - IsoSaveTOC(tofile); - - tofile = IsoFileClose(tofile); - - gtk_entry_set_text(GTK_ENTRY(mainbox.file), templine); - - } else { - - tofile = IsoFileCloseAndDelete(tofile); - - } // ENDIF- (Failed to complete writing file? Get rid of the garbage files.) - - - - if(stop != 1) DeviceBoxRefocus(); - - if(stop == 0) DeviceBoxCancelEvent(widget, event, data); - - return(TRUE); - -} // END DeviceBoxOKEvent() - - - - - -gint DeviceBoxBrowseEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - DeviceBoxUnfocus(); - - - - // Transfer file name to file selection - - gtk_file_selection_set_filename(GTK_FILE_SELECTION(selectionbox.window), - - gtk_entry_get_text(GTK_ENTRY(devicebox.file))); - - selectionbox.wherefrom = 2; // From the Device Window - - SelectionBoxRefocus(); - - return(TRUE); - -} // END DeviceBoxBrowseEvent() - - - - - -void DeviceBoxDisplay() { - - GtkWidget *item; - - GtkWidget *hbox1; - - GtkWidget *vbox1; - - int nameptr; - - - - devicebox.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - gtk_container_set_border_width(GTK_CONTAINER(devicebox.window), 5); - - gtk_window_set_title(GTK_WINDOW(devicebox.window), "CDVDisoEFP ISO Creation"); - - gtk_window_set_position(GTK_WINDOW(devicebox.window), GTK_WIN_POS_CENTER); - - - - g_signal_connect(G_OBJECT(devicebox.window), "delete_event", - - G_CALLBACK(DeviceBoxCancelEvent), NULL); - - - - vbox1 = gtk_vbox_new(FALSE, 5); - - gtk_container_add(GTK_CONTAINER(devicebox.window), vbox1); - - gtk_container_set_border_width(GTK_CONTAINER(vbox1), 5); - - gtk_widget_show(vbox1); - - - - hbox1 = gtk_hbox_new(FALSE, 10); - - gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); - - gtk_widget_show(hbox1); - - - - item = gtk_label_new("Source CD/DVD Device:"); - - gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0); - - gtk_widget_show(item); - - item = NULL; - - - - devicebox.device = gtk_entry_new(); - - gtk_box_pack_start(GTK_BOX(hbox1), devicebox.device, TRUE, TRUE, 0); - - gtk_widget_show(devicebox.device); - - g_signal_connect(G_OBJECT(devicebox.device), "changed", - - G_CALLBACK(DeviceBoxDeviceEvent), NULL); - - hbox1 = NULL; - - - - devicebox.devicedesc = gtk_label_new("Device Type: ---"); - - gtk_box_pack_start(GTK_BOX(vbox1), devicebox.devicedesc, FALSE, FALSE, 0); - - gtk_widget_show(devicebox.devicedesc); - - - - item = gtk_hseparator_new(); - - gtk_box_pack_start(GTK_BOX(vbox1), item, TRUE, TRUE, 0); - - gtk_widget_show(item); - - item = NULL; - - - - hbox1 = gtk_hbox_new(FALSE, 10); - - gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); - - gtk_widget_show(hbox1); - - - - item = gtk_label_new("Iso File:"); - - gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0); - - gtk_widget_show(item); - - item = NULL; - - - - devicebox.file = gtk_entry_new(); - - gtk_box_pack_start(GTK_BOX(hbox1), devicebox.file, TRUE, TRUE, 0); - - gtk_widget_show(devicebox.file); - - g_signal_connect(G_OBJECT(devicebox.file), "changed", - - G_CALLBACK(DeviceBoxFileEvent), NULL); - - - - devicebox.selectbutton = gtk_button_new_with_label("Browse"); - - gtk_box_pack_start(GTK_BOX(hbox1), devicebox.selectbutton, FALSE, FALSE, 0); - - gtk_widget_show(devicebox.selectbutton); - - g_signal_connect(G_OBJECT(devicebox.selectbutton), "clicked", - - G_CALLBACK(DeviceBoxBrowseEvent), NULL); - - hbox1 = NULL; - - - - devicebox.filedesc = gtk_label_new("File Type: ---"); - - gtk_box_pack_start(GTK_BOX(vbox1), devicebox.filedesc, FALSE, FALSE, 0); - - gtk_widget_show(devicebox.filedesc); - - - - hbox1 = gtk_hbox_new(FALSE, 10); - - gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); - - gtk_widget_show(hbox1); - - - - item = gtk_label_new("New File Compression:"); - - gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0); - - gtk_widget_show(item); - - item = NULL; - - - - devicebox.compress = gtk_combo_box_new_text(); - - gtk_box_pack_start(GTK_BOX(hbox1), devicebox.compress, FALSE, FALSE, 0); - - nameptr = 0; - - while(compressnames[nameptr] != NULL) { - - gtk_combo_box_append_text(GTK_COMBO_BOX(devicebox.compress), - - compressnames[nameptr]); - - nameptr++; - - } // ENDWHILE- loading compression types into combo box - - gtk_combo_box_set_active(GTK_COMBO_BOX(devicebox.compress), 0); // Temp Line - - gtk_widget_show(devicebox.compress); - - hbox1 = NULL; - - - - hbox1 = gtk_hbox_new(FALSE, 10); - - gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); - - gtk_widget_show(hbox1); - - - - item = gtk_label_new("Multiple Files (all under 2 GB):"); - - gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0); - - gtk_widget_show(item); - - item = NULL; - - - - devicebox.multi = gtk_check_button_new(); - - gtk_box_pack_start(GTK_BOX(hbox1), devicebox.multi, FALSE, FALSE, 0); - - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(devicebox.multi), FALSE); - - gtk_widget_show(devicebox.multi); - - hbox1 = NULL; - - - - hbox1 = gtk_hbutton_box_new(); - - gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); - - gtk_widget_show(hbox1); - - - - devicebox.okbutton = gtk_button_new_with_label("Make File"); - - gtk_box_pack_start(GTK_BOX(hbox1), devicebox.okbutton, TRUE, TRUE, 0); - - gtk_widget_show(devicebox.okbutton); - - g_signal_connect(G_OBJECT(devicebox.okbutton), "clicked", - - G_CALLBACK(DeviceBoxOKEvent), NULL); - - - - devicebox.cancelbutton = gtk_button_new_with_label("Cancel"); - - gtk_box_pack_start(GTK_BOX(hbox1), devicebox.cancelbutton, TRUE, TRUE, 0); - - gtk_widget_show(devicebox.cancelbutton); - - g_signal_connect(G_OBJECT(devicebox.cancelbutton), "clicked", - - G_CALLBACK(DeviceBoxCancelEvent), NULL); - - hbox1 = NULL; - - vbox1 = NULL; - - - - // Device text not set until now to get the correct description. - - gtk_entry_set_text(GTK_ENTRY(devicebox.device), conf.devicename); - - - - DeviceInit(); // Initialize device access - -} // END DeviceBoxDisplay() - +/* devicebox.c + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +#include // NULL +#include // sprintf() +#include // strcpy() +#include // stat() +#include // stat() +#include // stat() + +#include // gtk_button_new_with_label() +#include // gtk_combo_box_new() +#include // gtk_check_button_new() +#include // gtk_container_add() +#include // gtk_entry_new() +#include // gtk_file_selection_set_filename() +#include // gtk_hbutton_box_new() +#include // gtk_hbox_new() +#include // gtk_hseparator_new() +#include // gtk_label_new() +#include // gtk_main_iteration() +#include // gtk_toggle_button_get_active() +#include // gtk_vbox_new() +#include // gtk_window_new() + +#ifndef __LINUX__ +#ifdef __linux__ +#define __LINUX__ +#endif /* __linux__ */ +#endif /* No __LINUX__ */ +#define CDVDdefs +#include "PS2Edefs.h" + +#include "conf.h" +#include "device.h" +#include "isofile.h" +#include "isocompress.h" // compressdesc[] +// #include "imagetype.h" // imagedata[].name +#include "multifile.h" // multinames[] +#include "toc.h" +#include "progressbox.h" +#include "messagebox.h" +#include "selectionbox.h" +#include "mainbox.h" +#include "devicebox.h" + + +struct DeviceBoxData devicebox; + + +void DeviceBoxDestroy() +{ + if (devicebox.window != NULL) + { + gtk_widget_destroy(devicebox.window); + devicebox.window = NULL; + devicebox.device = NULL; + devicebox.devicedesc = NULL; + devicebox.file = NULL; + devicebox.selectbutton = NULL; + devicebox.filedesc = NULL; + devicebox.compress = NULL; + devicebox.multi = NULL; + devicebox.okbutton = NULL; + devicebox.cancelbutton = NULL; + } // ENDIF- Do we have a Main Window still? +} // END DeviceBoxDestroy() + + +void DeviceBoxUnfocus() +{ + gtk_widget_set_sensitive(devicebox.device, FALSE); + gtk_widget_set_sensitive(devicebox.file, FALSE); + gtk_widget_set_sensitive(devicebox.selectbutton, FALSE); + gtk_widget_set_sensitive(devicebox.compress, FALSE); + gtk_widget_set_sensitive(devicebox.multi, FALSE); + gtk_widget_set_sensitive(devicebox.okbutton, FALSE); + gtk_widget_set_sensitive(devicebox.cancelbutton, FALSE); + gtk_widget_hide(devicebox.window); + // gtk_window_iconify(GTK_WINDOW(devicebox.window)); +} // END DeviceBoxUnfocus() + + +gint DeviceBoxDeviceEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + struct stat filestat; + int returnval; + + returnval = stat(gtk_entry_get_text(GTK_ENTRY(devicebox.device)), &filestat); + if (returnval == -1) + { + gtk_label_set_text(GTK_LABEL(devicebox.devicedesc), "Device Type: ---"); + return(TRUE); + } // ENDIF- Not a name of any sort? + + if (S_ISDIR(filestat.st_mode) != 0) + { + gtk_label_set_text(GTK_LABEL(devicebox.devicedesc), "Device Type: Not a device"); + return(TRUE); + } // ENDIF- Not a regular file? + + gtk_label_set_text(GTK_LABEL(devicebox.devicedesc), "Device Type: Device Likely"); + return(TRUE); +} // END DeviceBoxDeviceEvent() + + +gint DeviceBoxFileEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + int returnval; + char templine[256]; + struct IsoFile *tempfile; + + returnval = IsIsoFile(gtk_entry_get_text(GTK_ENTRY(devicebox.file))); + if (returnval == -1) + { + gtk_label_set_text(GTK_LABEL(devicebox.filedesc), "File Type: ---"); + return(TRUE); + } // ENDIF- Not a name of any sort? + + if (returnval == -2) + { + gtk_label_set_text(GTK_LABEL(devicebox.filedesc), "File Type: Not a file"); + return(TRUE); + } // ENDIF- Not a regular file? + + if (returnval == -3) + { + gtk_label_set_text(GTK_LABEL(devicebox.filedesc), "File Type: Not a valid image file"); + return(TRUE); + } // ENDIF- Not an image file? + + if (returnval == -4) + { + gtk_label_set_text(GTK_LABEL(devicebox.filedesc), "File Type: Missing Table File (will rebuild)"); + return(TRUE); + } // ENDIF- Not a regular file? + + tempfile = IsoFileOpenForRead(gtk_entry_get_text(GTK_ENTRY(devicebox.file))); + sprintf(templine, "File Type: %s%s%s", + multinames[tempfile->multi], + tempfile->imagename, + compressdesc[tempfile->compress]); + gtk_label_set_text(GTK_LABEL(devicebox.filedesc), templine); + tempfile = IsoFileClose(tempfile); + return(TRUE); +} // END DeviceBoxFileEvent() + + +void DeviceBoxRefocus() +{ + GdkEvent event; + + DeviceBoxDeviceEvent(NULL, event, NULL); + DeviceBoxFileEvent(NULL, event, NULL); + + gtk_widget_set_sensitive(devicebox.device, TRUE); + gtk_widget_set_sensitive(devicebox.file, TRUE); + gtk_widget_set_sensitive(devicebox.selectbutton, TRUE); + gtk_widget_set_sensitive(devicebox.compress, TRUE); + gtk_widget_set_sensitive(devicebox.multi, TRUE); + gtk_widget_set_sensitive(devicebox.okbutton, TRUE); + gtk_widget_set_sensitive(devicebox.cancelbutton, TRUE); + gtk_window_set_focus(GTK_WINDOW(devicebox.window), devicebox.file); + gtk_widget_show_all(devicebox.window); + gtk_window_deiconify(GTK_WINDOW(devicebox.window)); +} // END DeviceBoxRefocus() + + +gint DeviceBoxCancelEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + gtk_widget_hide(devicebox.window); + MainBoxRefocus(); + return(TRUE); +} // END DeviceBoxCancelEvent() + + +gint DeviceBoxOKEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + char templine[256]; + u8 tempbuffer[2352]; + struct IsoFile *tofile; + const char *tempdevice; + s32 retval; + cdvdTD cdvdtd; + int stop; + int compressmethod; + int multi; + int imagetype; + int i; + + DeviceBoxUnfocus(); + + tempdevice = gtk_entry_get_text(GTK_ENTRY(devicebox.device)); + strcpy(conf.devicename, tempdevice); // Temporarily put in new device name + tempdevice = NULL; + retval = DeviceOpen(); + if (retval != 0) + { + DeviceClose(); + MessageBoxShow("Could not open the device", 2); + return(TRUE); + } // ENDIF- Trouble opening device? Abort here. + + DeviceTrayStatus(); + retval = DiscInserted(); + if (retval != 0) + { + DeviceClose(); + MessageBoxShow("No disc in the device\r\nPlease put a disc in and try again.", 2); + return(TRUE); + } // ENDIF- Trouble opening device? Abort here. + + retval = DeviceGetTD(0, &cdvdtd); // Fish for Ending Sector + if (retval < 0) + { + DeviceClose(); + MessageBoxShow("Could not retrieve disc sector size", 2); + return(TRUE); + } // ENDIF- Trouble getting disc sector count? + + compressmethod = gtk_combo_box_get_active(GTK_COMBO_BOX(devicebox.compress)); + if (compressmethod > 0) compressmethod += 2; + multi = 0; + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(devicebox.multi)) == TRUE) + multi = 1; + + imagetype = 0; + if ((disctype != CDVD_TYPE_PS2DVD) && + (disctype != CDVD_TYPE_DVDV)) imagetype = 8; + + tofile = IsoFileOpenForWrite(gtk_entry_get_text(GTK_ENTRY(devicebox.file)), + imagetype, + multi, + compressmethod); + if (tofile == NULL) + { + DeviceClose(); + MessageBoxShow("Could not create the new ISO file", 2); + return(TRUE); + } // ENDIF- Trouble opening the ISO file? + + // Open Progress Bar + sprintf(templine, "%s -> %s", + gtk_entry_get_text(GTK_ENTRY(devicebox.device)), tofile->name); + ProgressBoxStart(templine, (off64_t) cdvdtd.lsn); + + tofile->cdvdtype = disctype; + for (i = 0; i < 2048; i++) tofile->toc[i] = tocbuffer[i]; + + stop = 0; + mainbox.stop = 0; + progressbox.stop = 0; + while ((stop == 0) && (tofile->sectorpos < cdvdtd.lsn)) + { + if (imagetype == 0) + { + retval = DeviceReadTrack((u32) tofile->sectorpos, + CDVD_MODE_2048, + tempbuffer); + } + else + { + retval = DeviceReadTrack((u32) tofile->sectorpos, + CDVD_MODE_2352, + tempbuffer); + } // ENDIF- Are we reading a DVD sector? (Or a CD sector?) + if (retval < 0) + { + for (i = 0; i < 2352; i++) + { + tempbuffer[i] = 0; + } // NEXT i- Zeroing the buffer + } // ENDIF- Trouble reading next block? + retval = IsoFileWrite(tofile, tempbuffer); + if (retval < 0) + { + MessageBoxShow("Trouble writing new file", 3); + stop = 1; + } // ENDIF- Trouble writing out the next block? + + ProgressBoxTick(tofile->sectorpos); + while (gtk_events_pending()) gtk_main_iteration(); + + if (mainbox.stop != 0) stop = 2; + if (progressbox.stop != 0) stop = 2; + } // ENDWHILE- No reason found to stop... + + ProgressBoxStop(); + + if (stop == 0) + { + if (tofile->multi == 1) tofile->name[tofile->multipos] = '0'; // First file + strcpy(templine, tofile->name); + } // ENDIF- Did we succeed with the transfer? + + DeviceClose(); + if (stop == 0) + { + IsoSaveTOC(tofile); + tofile = IsoFileClose(tofile); + gtk_entry_set_text(GTK_ENTRY(mainbox.file), templine); + } + else + { + tofile = IsoFileCloseAndDelete(tofile); + } // ENDIF- (Failed to complete writing file? Get rid of the garbage files.) + + if (stop != 1) DeviceBoxRefocus(); + if (stop == 0) DeviceBoxCancelEvent(widget, event, data); + return(TRUE); +} // END DeviceBoxOKEvent() + + +gint DeviceBoxBrowseEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + DeviceBoxUnfocus(); + + // Transfer file name to file selection + gtk_file_selection_set_filename(GTK_FILE_SELECTION(selectionbox.window), + gtk_entry_get_text(GTK_ENTRY(devicebox.file))); + selectionbox.wherefrom = 2; // From the Device Window + SelectionBoxRefocus(); + return(TRUE); +} // END DeviceBoxBrowseEvent() + + +void DeviceBoxDisplay() +{ + GtkWidget *item; + GtkWidget *hbox1; + GtkWidget *vbox1; + int nameptr; + + devicebox.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_container_set_border_width(GTK_CONTAINER(devicebox.window), 5); + gtk_window_set_title(GTK_WINDOW(devicebox.window), "CDVDisoEFP ISO Creation"); + gtk_window_set_position(GTK_WINDOW(devicebox.window), GTK_WIN_POS_CENTER); + + g_signal_connect(G_OBJECT(devicebox.window), "delete_event", + G_CALLBACK(DeviceBoxCancelEvent), NULL); + + vbox1 = gtk_vbox_new(FALSE, 5); + gtk_container_add(GTK_CONTAINER(devicebox.window), vbox1); + gtk_container_set_border_width(GTK_CONTAINER(vbox1), 5); + gtk_widget_show(vbox1); + + hbox1 = gtk_hbox_new(FALSE, 10); + gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); + gtk_widget_show(hbox1); + + item = gtk_label_new("Source CD/DVD Device:"); + gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0); + gtk_widget_show(item); + item = NULL; + + devicebox.device = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(hbox1), devicebox.device, TRUE, TRUE, 0); + gtk_widget_show(devicebox.device); + g_signal_connect(G_OBJECT(devicebox.device), "changed", + G_CALLBACK(DeviceBoxDeviceEvent), NULL); + hbox1 = NULL; + + devicebox.devicedesc = gtk_label_new("Device Type: ---"); + gtk_box_pack_start(GTK_BOX(vbox1), devicebox.devicedesc, FALSE, FALSE, 0); + gtk_widget_show(devicebox.devicedesc); + + item = gtk_hseparator_new(); + gtk_box_pack_start(GTK_BOX(vbox1), item, TRUE, TRUE, 0); + gtk_widget_show(item); + item = NULL; + + hbox1 = gtk_hbox_new(FALSE, 10); + gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); + gtk_widget_show(hbox1); + + item = gtk_label_new("Iso File:"); + gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0); + gtk_widget_show(item); + item = NULL; + + devicebox.file = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(hbox1), devicebox.file, TRUE, TRUE, 0); + gtk_widget_show(devicebox.file); + g_signal_connect(G_OBJECT(devicebox.file), "changed", + G_CALLBACK(DeviceBoxFileEvent), NULL); + + devicebox.selectbutton = gtk_button_new_with_label("Browse"); + gtk_box_pack_start(GTK_BOX(hbox1), devicebox.selectbutton, FALSE, FALSE, 0); + gtk_widget_show(devicebox.selectbutton); + g_signal_connect(G_OBJECT(devicebox.selectbutton), "clicked", + G_CALLBACK(DeviceBoxBrowseEvent), NULL); + hbox1 = NULL; + + devicebox.filedesc = gtk_label_new("File Type: ---"); + gtk_box_pack_start(GTK_BOX(vbox1), devicebox.filedesc, FALSE, FALSE, 0); + gtk_widget_show(devicebox.filedesc); + + hbox1 = gtk_hbox_new(FALSE, 10); + gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); + gtk_widget_show(hbox1); + + item = gtk_label_new("New File Compression:"); + gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0); + gtk_widget_show(item); + item = NULL; + + devicebox.compress = gtk_combo_box_new_text(); + gtk_box_pack_start(GTK_BOX(hbox1), devicebox.compress, FALSE, FALSE, 0); + nameptr = 0; + while (compressnames[nameptr] != NULL) + { + gtk_combo_box_append_text(GTK_COMBO_BOX(devicebox.compress), + compressnames[nameptr]); + nameptr++; + } // ENDWHILE- loading compression types into combo box + gtk_combo_box_set_active(GTK_COMBO_BOX(devicebox.compress), 0); // Temp Line + gtk_widget_show(devicebox.compress); + hbox1 = NULL; + + hbox1 = gtk_hbox_new(FALSE, 10); + gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); + gtk_widget_show(hbox1); + + item = gtk_label_new("Multiple Files (all under 2 GB):"); + gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0); + gtk_widget_show(item); + item = NULL; + + devicebox.multi = gtk_check_button_new(); + gtk_box_pack_start(GTK_BOX(hbox1), devicebox.multi, FALSE, FALSE, 0); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(devicebox.multi), FALSE); + gtk_widget_show(devicebox.multi); + hbox1 = NULL; + + hbox1 = gtk_hbutton_box_new(); + gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); + gtk_widget_show(hbox1); + + devicebox.okbutton = gtk_button_new_with_label("Make File"); + gtk_box_pack_start(GTK_BOX(hbox1), devicebox.okbutton, TRUE, TRUE, 0); + gtk_widget_show(devicebox.okbutton); + g_signal_connect(G_OBJECT(devicebox.okbutton), "clicked", + G_CALLBACK(DeviceBoxOKEvent), NULL); + + devicebox.cancelbutton = gtk_button_new_with_label("Cancel"); + gtk_box_pack_start(GTK_BOX(hbox1), devicebox.cancelbutton, TRUE, TRUE, 0); + gtk_widget_show(devicebox.cancelbutton); + g_signal_connect(G_OBJECT(devicebox.cancelbutton), "clicked", + G_CALLBACK(DeviceBoxCancelEvent), NULL); + hbox1 = NULL; + vbox1 = NULL; + + // Device text not set until now to get the correct description. + gtk_entry_set_text(GTK_ENTRY(devicebox.device), conf.devicename); + + DeviceInit(); // Initialize device access +} // END DeviceBoxDisplay() diff --git a/plugins/CDVDisoEFP/src/Linux/devicebox.h b/plugins/CDVDisoEFP/src/Linux/devicebox.h index 05d662e73f..75a733f935 100644 --- a/plugins/CDVDisoEFP/src/Linux/devicebox.h +++ b/plugins/CDVDisoEFP/src/Linux/devicebox.h @@ -1,100 +1,47 @@ /* devicebox.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef DEVICEBOX_H - #define DEVICEBOX_H - - - - #include - - - - -struct DeviceBoxData { - - GtkWidget *window; // GtkWindow - - GtkWidget *device; // GtkEntry - - GtkWidget *devicedesc; // GtkLabel - - GtkWidget *file; // GtkEntry - - GtkWidget *selectbutton; // GtkButton - - GtkWidget *filedesc; // GtkLabel - - GtkWidget *compress; // GtkComboBox - - GtkWidget *multi; // GtkCheckButton - - GtkWidget *okbutton; // GtkButton - - GtkWidget *cancelbutton; // GtkButton - +struct DeviceBoxData +{ + GtkWidget *window; // GtkWindow + GtkWidget *device; // GtkEntry + GtkWidget *devicedesc; // GtkLabel + GtkWidget *file; // GtkEntry + GtkWidget *selectbutton; // GtkButton + GtkWidget *filedesc; // GtkLabel + GtkWidget *compress; // GtkComboBox + GtkWidget *multi; // GtkCheckButton + GtkWidget *okbutton; // GtkButton + GtkWidget *cancelbutton; // GtkButton }; - - extern struct DeviceBoxData devicebox; - - extern void DeviceBoxDestroy(); - // extern void DeviceBoxUnfocus(); - extern void DeviceBoxRefocus(); - extern void DeviceBoxDisplay(); - - - - #endif /* DEVICEBOX_H */ - diff --git a/plugins/CDVDisoEFP/src/Linux/interface.c b/plugins/CDVDisoEFP/src/Linux/interface.c index 7243c15b6f..3dd9d40a4b 100644 --- a/plugins/CDVDisoEFP/src/Linux/interface.c +++ b/plugins/CDVDisoEFP/src/Linux/interface.c @@ -1,134 +1,71 @@ -/* interface.c - - * Copyright (C) 2002-2005 PCSX2 Team - - * - - * This program is free software; you can redistribute it and/or modify - - * it under the terms of the GNU General Public License as published by - - * the Free Software Foundation; either version 2 of the License, or - - * (at your option) any later version. - - * - - * This program is distributed in the hope that it will be useful, - - * but WITHOUT ANY WARRANTY; without even the implied warranty of - - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - - * GNU General Public License for more details. - - * - - * You should have received a copy of the GNU General Public License - - * along with this program; if not, write to the Free Software - - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - * - - * PCSX2 members can be contacted through their website at www.pcsx2.net. - - */ - - - - - -#include // NULL - -#include // sprintf() - -#include // strcmp() - - - -#include // gtk_init(), gtk_main(), gtk_main_quit() - -#include // gtk_widget_show_all() - - - -#include "logfile.h" - -#include "conf.h" - -#include "aboutbox.h" - -#include "mainbox.h" - -#include "devicebox.h" - -#include "selectionbox.h" - -#include "progressbox.h" - -#include "messagebox.h" - -#include "conversionbox.h" - -#include "interface.h" - - - - - -int main(int argc, char *argv[]) { - - if(argc != 2) return(1); - - - - gtk_init(NULL, NULL); - - - - if(!strcmp(argv[1], "about")) { - - AboutBoxDisplay(); - - return(0); - - } else if (!strcmp(argv[1], "configure")) { - - OpenLog(); - - InitConf(); - - LoadConf(); - - MainBoxDisplay(); - - DeviceBoxDisplay(); - - ConversionBoxDisplay(); - - ProgressBoxDisplay(); - - MessageBoxDisplay(); - - SelectionBoxDisplay(); - - - - gtk_widget_show_all(mainbox.window); - - gtk_main(); - - CloseLog(); - - return(0); - - } // ENDLONGIF- Which display would you like to see? - - - - return(1); // No Displays chosen? Abort! - -} // END main() - +/* interface.c + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +#include // NULL +#include // sprintf() +#include // strcmp() + +#include // gtk_init(), gtk_main(), gtk_main_quit() +#include // gtk_widget_show_all() + +#include "logfile.h" +#include "conf.h" +#include "aboutbox.h" +#include "mainbox.h" +#include "devicebox.h" +#include "selectionbox.h" +#include "progressbox.h" +#include "messagebox.h" +#include "conversionbox.h" +#include "interface.h" + + +int main(int argc, char *argv[]) +{ + if (argc != 2) return(1); + + gtk_init(NULL, NULL); + + if (!strcmp(argv[1], "about")) + { + AboutBoxDisplay(); + return(0); + } + else if (!strcmp(argv[1], "configure")) + { + OpenLog(); + InitConf(); + LoadConf(); + MainBoxDisplay(); + DeviceBoxDisplay(); + ConversionBoxDisplay(); + ProgressBoxDisplay(); + MessageBoxDisplay(); + SelectionBoxDisplay(); + + gtk_widget_show_all(mainbox.window); + gtk_main(); + CloseLog(); + return(0); + } // ENDLONGIF- Which display would you like to see? + + return(1); // No Displays chosen? Abort! +} // END main() diff --git a/plugins/CDVDisoEFP/src/Linux/interface.h b/plugins/CDVDisoEFP/src/Linux/interface.h index badfac8930..ed6be1a7f2 100644 --- a/plugins/CDVDisoEFP/src/Linux/interface.h +++ b/plugins/CDVDisoEFP/src/Linux/interface.h @@ -1,58 +1,26 @@ /* interface.h - * Copyright (C) 2002-2004 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef INTERFACE_H - #define INTERFACE_H - - - - // Place holder... for now - - - - #endif /* INTERFACE_H */ - diff --git a/plugins/CDVDisoEFP/src/Linux/logfile.c b/plugins/CDVDisoEFP/src/Linux/logfile.c index 9c1a2348f5..beb4231540 100644 --- a/plugins/CDVDisoEFP/src/Linux/logfile.c +++ b/plugins/CDVDisoEFP/src/Linux/logfile.c @@ -1,180 +1,83 @@ /* logfile.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include // open - #include // vsprintf() - #include // va_start(), va_end(), vsprintf() - #include // mkdir(), open() - #include // mkdir(), open() - #include // close(), write(), unlink() - - - #include "logfile.h" - - - - int logfile; - char logfiletemp[2048]; - - - - -void InitLog() { - - // Token comment line - +void InitLog() +{ + // Token comment line #ifdef VERBOSE_LOGFILE - - mkdir("./logs", 0755); - - - - unlink("./logs/CDVDlog.txt"); - + mkdir("./logs", 0755); + unlink("./logs/CDVDlog.txt"); #endif /* VERBOSE LOGFILE */ - } // END InitLog(); - - - - -int OpenLog() { - - // Token comment line - +int OpenLog() +{ + // Token comment line #ifdef VERBOSE_LOGFILE - - logfile = -1; - - logfile = open("./logs/CDVDlog.txt", O_WRONLY | O_CREAT | O_APPEND, 0755); - - if(logfile == -1) return(-1); - + logfile = -1; + logfile = open("./logs/CDVDlog.txt", O_WRONLY | O_CREAT | O_APPEND, 0755); + if (logfile == -1) return(-1); #endif /* VERBOSE LOGFILE */ - - - return(0); - + return(0); } // END OpenLog(); - - - - -void CloseLog() { - - // Token comment line - +void CloseLog() +{ + // Token comment line #ifdef VERBOSE_LOGFILE - - if(logfile != -1) { - - close(logfile); - - logfile = -1; - - } // ENDIF- Is the log file actually open? Close it. - + if (logfile != -1) + { + close(logfile); + logfile = -1; + } // ENDIF- Is the log file actually open? Close it. #endif /* VERBOSE LOGFILE */ - } // END CloseLog() - - - - -void PrintLog(const char *fmt, ...) { - - // Token comment line - +void PrintLog(const char *fmt, ...) +{ + // Token comment line #ifdef VERBOSE_LOGFILE - - va_list list; - - int len; - - - - if(logfile == -1) return; // Log file not open. - - - - va_start(list, fmt); - - vsprintf(logfiletemp, fmt, list); - - va_end(list); - - - - len = 0; - - while((len < 2048) && (logfiletemp[len] != 0)) len++; - - if((len > 0) && (logfiletemp[len-1] == '\n')) len--; - - if((len > 0) && (logfiletemp[len-1] == '\r')) len--; - - logfiletemp[len] = 0; // Slice off the last "\r\n"... - - - - write(logfile, logfiletemp, len); - - write(logfile, "\r\n", 2); // ... and write out your own. - + va_list list; + int len; + if (logfile == -1) return; // Log file not open. + va_start(list, fmt); + vsprintf(logfiletemp, fmt, list); + va_end(list); + len = 0; + while ((len < 2048) && (logfiletemp[len] != 0)) len++; + if ((len > 0) && (logfiletemp[len-1] == '\n')) len--; + if ((len > 0) && (logfiletemp[len-1] == '\r')) len--; + logfiletemp[len] = 0; // Slice off the last "\r\n"... + write(logfile, logfiletemp, len); + write(logfile, "\r\n", 2); // ... and write out your own. #endif /* VERBOSE LOGFILE */ - } // END PrintLog() - diff --git a/plugins/CDVDisoEFP/src/Linux/logfile.h b/plugins/CDVDisoEFP/src/Linux/logfile.h index 8cee990080..eb9d623e96 100644 --- a/plugins/CDVDisoEFP/src/Linux/logfile.h +++ b/plugins/CDVDisoEFP/src/Linux/logfile.h @@ -1,35 +1,35 @@ -/* logfile.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - -#ifndef LOGFILE_H -#define LOGFILE_H - - -#define VERBOSE_LOGFILE - - -extern void InitLog(); -extern int OpenLog(); -extern void CloseLog(); -extern void PrintLog(const char *format, ...); - - -#endif /* LOGFILE_H */ +/* logfile.h + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +#ifndef LOGFILE_H +#define LOGFILE_H + + +#define VERBOSE_LOGFILE + + +extern void InitLog(); +extern int OpenLog(); +extern void CloseLog(); +extern void PrintLog(const char *format, ...); + + +#endif /* LOGFILE_H */ diff --git a/plugins/CDVDisoEFP/src/Linux/mainbox.c b/plugins/CDVDisoEFP/src/Linux/mainbox.c index 9e8fc1c980..871195e730 100644 --- a/plugins/CDVDisoEFP/src/Linux/mainbox.c +++ b/plugins/CDVDisoEFP/src/Linux/mainbox.c @@ -1,648 +1,317 @@ /* mainbox.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include // NULL - #include // sprintf() - #include // strcpy() - - #include // gtk_button_new_with_label() - #include // gtk_check_button_new_with_label() - #include // gtk_container_add() - #include // gtk_entry_new() - #include // gtk_file_selection_set_filename() - #include // gtk_hbutton_box_new() - #include // gtk_hbox_new() - #include // gtk_label_new() - #include // gtk_init(), gtk_main(), gtk_main_quit() - #include // gtk_toggle_button_set_active(), (_get_) - #include // gtk_vbox_new() - #include // gtk_window_new() - - - #include "conf.h" - #include "isofile.h" - #include "isocompress.h" // compressdesc[] - // #include "imagetype.h" // imagedata[].name - #include "multifile.h" // multinames[] - #include "tablerebuild.h" // IsoTableRebuild() - #include "devicebox.h" - #include "conversionbox.h" - #include "progressbox.h" - #include "messagebox.h" - #include "selectionbox.h" - #include "mainbox.h" - - - - struct MainBoxData mainbox; - - - - -void MainBoxDestroy() { - - if(mainbox.window != NULL) { - - gtk_widget_destroy(mainbox.window); - - mainbox.window = NULL; - - mainbox.file = NULL; - - mainbox.selectbutton = NULL; - - mainbox.desc = NULL; - - mainbox.startcheck = NULL; - - mainbox.restartcheck = NULL; - - mainbox.okbutton = NULL; - - mainbox.devbutton = NULL; - - mainbox.convbutton = NULL; - - } // ENDIF- Do we have a Main Window still? - +void MainBoxDestroy() +{ + if (mainbox.window != NULL) + { + gtk_widget_destroy(mainbox.window); + mainbox.window = NULL; + mainbox.file = NULL; + mainbox.selectbutton = NULL; + mainbox.desc = NULL; + mainbox.startcheck = NULL; + mainbox.restartcheck = NULL; + mainbox.okbutton = NULL; + mainbox.devbutton = NULL; + mainbox.convbutton = NULL; + } // ENDIF- Do we have a Main Window still? } // END MainBoxDestroy() - - - - -void MainBoxUnfocus() { - - gtk_widget_set_sensitive(mainbox.file, FALSE); - - gtk_widget_set_sensitive(mainbox.selectbutton, FALSE); - - gtk_widget_set_sensitive(mainbox.startcheck, FALSE); - - gtk_widget_set_sensitive(mainbox.restartcheck, FALSE); - - gtk_widget_set_sensitive(mainbox.okbutton, FALSE); - - gtk_widget_set_sensitive(mainbox.devbutton, FALSE); - - gtk_widget_set_sensitive(mainbox.convbutton, FALSE); - - gtk_window_iconify(GTK_WINDOW(mainbox.window)); - +void MainBoxUnfocus() +{ + gtk_widget_set_sensitive(mainbox.file, FALSE); + gtk_widget_set_sensitive(mainbox.selectbutton, FALSE); + gtk_widget_set_sensitive(mainbox.startcheck, FALSE); + gtk_widget_set_sensitive(mainbox.restartcheck, FALSE); + gtk_widget_set_sensitive(mainbox.okbutton, FALSE); + gtk_widget_set_sensitive(mainbox.devbutton, FALSE); + gtk_widget_set_sensitive(mainbox.convbutton, FALSE); + gtk_window_iconify(GTK_WINDOW(mainbox.window)); } // END MainBoxUnfocus() +gint MainBoxFileEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + int returnval; + char templine[256]; + struct IsoFile *tempfile; + returnval = IsIsoFile(gtk_entry_get_text(GTK_ENTRY(mainbox.file))); + if (returnval == -1) + { + gtk_label_set_text(GTK_LABEL(mainbox.desc), "File Type: ---"); + return(TRUE); + } // ENDIF- Not a name of any sort? + if (returnval == -2) + { + gtk_label_set_text(GTK_LABEL(mainbox.desc), "File Type: Not a file"); + return(TRUE); + } // ENDIF- Not a regular file? + if (returnval == -3) + { + gtk_label_set_text(GTK_LABEL(mainbox.desc), "File Type: Not a valid image file"); + return(TRUE); + } // ENDIF- Not an Image file? + if (returnval == -4) + { + gtk_label_set_text(GTK_LABEL(mainbox.desc), "File Type: Missing Table File (will rebuild)"); + return(TRUE); + } // ENDIF- Missing Compression seek table? - - -gint MainBoxFileEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - int returnval; - - char templine[256]; - - struct IsoFile *tempfile; - - - - returnval = IsIsoFile(gtk_entry_get_text(GTK_ENTRY(mainbox.file))); - - if(returnval == -1) { - - gtk_label_set_text(GTK_LABEL(mainbox.desc), "File Type: ---"); - - return(TRUE); - - } // ENDIF- Not a name of any sort? - - - - if(returnval == -2) { - - gtk_label_set_text(GTK_LABEL(mainbox.desc), "File Type: Not a file"); - - return(TRUE); - - } // ENDIF- Not a regular file? - - - - if(returnval == -3) { - - gtk_label_set_text(GTK_LABEL(mainbox.desc), "File Type: Not a valid image file"); - - return(TRUE); - - } // ENDIF- Not an Image file? - - - - if(returnval == -4) { - - gtk_label_set_text(GTK_LABEL(mainbox.desc), "File Type: Missing Table File (will rebuild)"); - - return(TRUE); - - } // ENDIF- Missing Compression seek table? - - - - tempfile = IsoFileOpenForRead(gtk_entry_get_text(GTK_ENTRY(mainbox.file))); - - sprintf(templine, "File Type: %s%s%s", - - multinames[tempfile->multi], - - tempfile->imagename, - - compressdesc[tempfile->compress]); - - gtk_label_set_text(GTK_LABEL(mainbox.desc), templine); - - tempfile = IsoFileClose(tempfile); - - return(TRUE); - + tempfile = IsoFileOpenForRead(gtk_entry_get_text(GTK_ENTRY(mainbox.file))); + sprintf(templine, "File Type: %s%s%s", + multinames[tempfile->multi], + tempfile->imagename, + compressdesc[tempfile->compress]); + gtk_label_set_text(GTK_LABEL(mainbox.desc), templine); + tempfile = IsoFileClose(tempfile); + return(TRUE); } // END MainBoxFileEvent() +void MainBoxRefocus() +{ + GdkEvent event; + MainBoxFileEvent(NULL, event, NULL); - - -void MainBoxRefocus() { - - GdkEvent event; - - - - MainBoxFileEvent(NULL, event, NULL); - - - - gtk_widget_set_sensitive(mainbox.file, TRUE); - - gtk_widget_set_sensitive(mainbox.selectbutton, TRUE); - - gtk_widget_set_sensitive(mainbox.startcheck, TRUE); - - gtk_widget_set_sensitive(mainbox.restartcheck, TRUE); - - gtk_widget_set_sensitive(mainbox.okbutton, TRUE); - - gtk_widget_set_sensitive(mainbox.devbutton, TRUE); - - gtk_widget_set_sensitive(mainbox.convbutton, TRUE); - - gtk_window_set_focus(GTK_WINDOW(mainbox.window), mainbox.file); - - gtk_window_deiconify(GTK_WINDOW(mainbox.window)); - + gtk_widget_set_sensitive(mainbox.file, TRUE); + gtk_widget_set_sensitive(mainbox.selectbutton, TRUE); + gtk_widget_set_sensitive(mainbox.startcheck, TRUE); + gtk_widget_set_sensitive(mainbox.restartcheck, TRUE); + gtk_widget_set_sensitive(mainbox.okbutton, TRUE); + gtk_widget_set_sensitive(mainbox.devbutton, TRUE); + gtk_widget_set_sensitive(mainbox.convbutton, TRUE); + gtk_window_set_focus(GTK_WINDOW(mainbox.window), mainbox.file); + gtk_window_deiconify(GTK_WINDOW(mainbox.window)); } // END MainBoxRefocus() +gint MainBoxCancelEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + mainbox.stop = 1; // Halt all long processess... + MessageBoxDestroy(); + SelectionBoxDestroy(); + ProgressBoxDestroy(); + ConversionBoxDestroy(); + DeviceBoxDestroy(); + MainBoxDestroy(); - - - -gint MainBoxCancelEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - mainbox.stop = 1; // Halt all long processess... - - - - MessageBoxDestroy(); - - SelectionBoxDestroy(); - - ProgressBoxDestroy(); - - ConversionBoxDestroy(); - - DeviceBoxDestroy(); - - MainBoxDestroy(); - - - - gtk_main_quit(); - - return(TRUE); - + gtk_main_quit(); + return(TRUE); } // END MainBoxCancelEvent() +gint MainBoxOKEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + const char *tempisoname; + MainBoxUnfocus(); + tempisoname = gtk_entry_get_text(GTK_ENTRY(mainbox.file)); + if (*(tempisoname) != 0) + { + if (IsIsoFile(tempisoname) == -4) + { + IsoTableRebuild(tempisoname); + MainBoxRefocus(); + return(TRUE); + } // ENDIF- Do we need to rebuild an image file's index before using it? + if (IsIsoFile(tempisoname) < 0) + { + tempisoname = NULL; + MainBoxRefocus(); + MessageBoxShow("Not a Valid Image File.", 1); + return(TRUE); + } // ENDIF- Not an ISO file? Message and Stop here. + } // ENDIF- Is there an ISO file to check out? -gint MainBoxOKEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - const char *tempisoname; - - - - MainBoxUnfocus(); - - - - tempisoname = gtk_entry_get_text(GTK_ENTRY(mainbox.file)); - - if(*(tempisoname) != 0) { - - if(IsIsoFile(tempisoname) == -4) { - - IsoTableRebuild(tempisoname); - - MainBoxRefocus(); - - return(TRUE); - - } // ENDIF- Do we need to rebuild an image file's index before using it? - - - - if(IsIsoFile(tempisoname) < 0) { - - tempisoname = NULL; - - MainBoxRefocus(); - - MessageBoxShow("Not a Valid Image File.", 1); - - return(TRUE); - - } // ENDIF- Not an ISO file? Message and Stop here. - - } // ENDIF- Is there an ISO file to check out? - - - - strcpy(conf.isoname, tempisoname); - - tempisoname = NULL; - - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mainbox.startcheck)) == FALSE) { - - conf.startconfigure = 0; // FALSE - - } else { - - conf.startconfigure = 1; // TRUE - - } // ENDIF- Was this check button turned off? - - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mainbox.restartcheck)) == FALSE) { - - conf.restartconfigure = 0; // FALSE - - } else { - - conf.restartconfigure = 1; // TRUE - - } // ENDIF- Was this check button turned off? - - - - SaveConf(); - - - - MainBoxCancelEvent(widget, event, data); - - return(TRUE); - + strcpy(conf.isoname, tempisoname); + tempisoname = NULL; + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mainbox.startcheck)) == FALSE) + { + conf.startconfigure = 0; // FALSE + } + else + { + conf.startconfigure = 1; // TRUE + } // ENDIF- Was this check button turned off? + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mainbox.restartcheck)) == FALSE) + { + conf.restartconfigure = 0; // FALSE + } + else + { + conf.restartconfigure = 1; // TRUE + } // ENDIF- Was this check button turned off? + SaveConf(); + MainBoxCancelEvent(widget, event, data); + return(TRUE); } // END MainBoxOKEvent() - - - - -gint MainBoxBrowseEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - MainBoxUnfocus(); - - - - gtk_file_selection_set_filename(GTK_FILE_SELECTION(selectionbox.window), - - gtk_entry_get_text(GTK_ENTRY(mainbox.file))); - - selectionbox.wherefrom = 1; // From the Main Window - - SelectionBoxRefocus(); - - return(TRUE); - +gint MainBoxBrowseEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + MainBoxUnfocus(); + gtk_file_selection_set_filename(GTK_FILE_SELECTION(selectionbox.window), + gtk_entry_get_text(GTK_ENTRY(mainbox.file))); + selectionbox.wherefrom = 1; // From the Main Window + SelectionBoxRefocus(); + return(TRUE); } // END MainBoxBrowseEvent() +gint MainBoxDeviceEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + MainBoxUnfocus(); - - - -gint MainBoxDeviceEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - MainBoxUnfocus(); - - - - gtk_entry_set_text(GTK_ENTRY(devicebox.file), - - gtk_entry_get_text(GTK_ENTRY(mainbox.file))); - - gtk_window_set_focus(GTK_WINDOW(devicebox.window), devicebox.file); - - gtk_widget_show_all(devicebox.window); - - return(TRUE); - + gtk_entry_set_text(GTK_ENTRY(devicebox.file), + gtk_entry_get_text(GTK_ENTRY(mainbox.file))); + gtk_window_set_focus(GTK_WINDOW(devicebox.window), devicebox.file); + gtk_widget_show_all(devicebox.window); + return(TRUE); } // END MainBoxBrowseEvent() - - - - -gint MainBoxConversionEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - MainBoxUnfocus(); - - - - gtk_entry_set_text(GTK_ENTRY(conversionbox.file), - - gtk_entry_get_text(GTK_ENTRY(mainbox.file))); - - gtk_window_set_focus(GTK_WINDOW(conversionbox.window), conversionbox.file); - - gtk_widget_show_all(conversionbox.window); - - return(TRUE); - +gint MainBoxConversionEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + MainBoxUnfocus(); + gtk_entry_set_text(GTK_ENTRY(conversionbox.file), + gtk_entry_get_text(GTK_ENTRY(mainbox.file))); + gtk_window_set_focus(GTK_WINDOW(conversionbox.window), conversionbox.file); + gtk_widget_show_all(conversionbox.window); + return(TRUE); } // END MainBoxBrowseEvent() - - - - -void MainBoxDisplay() { - - GtkWidget *item; - - GtkWidget *hbox1; - - GtkWidget *vbox1; - - - - mainbox.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - gtk_container_set_border_width(GTK_CONTAINER(mainbox.window), 5); - - gtk_window_set_title(GTK_WINDOW(mainbox.window), "CDVDisoEFP Configuration"); - - gtk_window_set_position(GTK_WINDOW(mainbox.window), GTK_WIN_POS_CENTER); - - - - g_signal_connect(G_OBJECT(mainbox.window), "delete_event", - - G_CALLBACK(MainBoxCancelEvent), NULL); - - - - vbox1 = gtk_vbox_new(FALSE, 5); - - gtk_container_add(GTK_CONTAINER(mainbox.window), vbox1); - - gtk_container_set_border_width(GTK_CONTAINER(vbox1), 5); - - gtk_widget_show(vbox1); - - - - hbox1 = gtk_hbox_new(FALSE, 10); - - gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); - - gtk_widget_show(hbox1); - - - - item = gtk_label_new("Iso File:"); - - gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0); - - gtk_widget_show(item); - - item = NULL; - - - - mainbox.file = gtk_entry_new(); - - gtk_box_pack_start(GTK_BOX(hbox1), mainbox.file, TRUE, TRUE, 0); - - gtk_widget_show(mainbox.file); - - g_signal_connect(G_OBJECT(mainbox.file), "changed", - - G_CALLBACK(MainBoxFileEvent), NULL); - - - - mainbox.selectbutton = gtk_button_new_with_label("Browse"); - - gtk_box_pack_start(GTK_BOX(hbox1), mainbox.selectbutton, FALSE, FALSE, 0); - - gtk_widget_show(mainbox.selectbutton); - - g_signal_connect(G_OBJECT(mainbox.selectbutton), "clicked", - - G_CALLBACK(MainBoxBrowseEvent), NULL); - - hbox1 = NULL; - - - - mainbox.desc = gtk_label_new("File Type: ---"); - - gtk_box_pack_start(GTK_BOX(vbox1), mainbox.desc, FALSE, FALSE, 0); - - gtk_widget_show(mainbox.desc); - - - - // hbox1 = gtk_hbox_new(FALSE, 10); - - // gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); - - // gtk_widget_show(hbox1); - - - - mainbox.startcheck = gtk_check_button_new_with_label("Show Configure screen when starting emulation"); - - gtk_box_pack_start(GTK_BOX(vbox1), mainbox.startcheck, FALSE, FALSE, 0); - - gtk_widget_show(mainbox.startcheck); - - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mainbox.startcheck), FALSE); - - if(conf.startconfigure != 0) { - - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mainbox.startcheck), TRUE); - - } // ENDIF- Is this box supposed to be checked? - - - - mainbox.restartcheck = gtk_check_button_new_with_label("Show Configure screen when restarting emulation"); - - gtk_box_pack_start(GTK_BOX(vbox1), mainbox.restartcheck, FALSE, FALSE, 0); - - gtk_widget_show(mainbox.restartcheck); - - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mainbox.restartcheck), FALSE); - - if(conf.restartconfigure != 0) { - - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mainbox.restartcheck), TRUE); - - } // ENDIF- Is this box supposed to be checked? - - - - hbox1 = gtk_hbutton_box_new(); - - gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); - - gtk_widget_show(hbox1); - - - - mainbox.okbutton = gtk_button_new_with_label("Ok"); - - gtk_box_pack_start(GTK_BOX(hbox1), mainbox.okbutton, TRUE, TRUE, 0); - - gtk_widget_show(mainbox.okbutton); - - g_signal_connect(G_OBJECT(mainbox.okbutton), "clicked", - - G_CALLBACK(MainBoxOKEvent), NULL); - - - - mainbox.devbutton = gtk_button_new_with_label("Get from Disc"); - - gtk_box_pack_start(GTK_BOX(hbox1), mainbox.devbutton, TRUE, TRUE, 0); - - gtk_widget_show(mainbox.devbutton); - - g_signal_connect(G_OBJECT(mainbox.devbutton), "clicked", - - G_CALLBACK(MainBoxDeviceEvent), NULL); - - - - mainbox.convbutton = gtk_button_new_with_label("Convert"); - - gtk_box_pack_start(GTK_BOX(hbox1), mainbox.convbutton, TRUE, TRUE, 0); - - gtk_widget_show(mainbox.convbutton); - - g_signal_connect(G_OBJECT(mainbox.convbutton), "clicked", - - G_CALLBACK(MainBoxConversionEvent), NULL); - - - - item = gtk_button_new_with_label("Cancel"); - - gtk_box_pack_start(GTK_BOX(hbox1), item, TRUE, TRUE, 0); - - gtk_widget_show(item); - - g_signal_connect(G_OBJECT(item), "clicked", - - G_CALLBACK(MainBoxCancelEvent), NULL); - - item = NULL; - - hbox1 = NULL; - - vbox1 = NULL; - - - - // We held off setting the name until now... so description would show. - - gtk_entry_set_text(GTK_ENTRY(mainbox.file), conf.isoname); - +void MainBoxDisplay() +{ + GtkWidget *item; + GtkWidget *hbox1; + GtkWidget *vbox1; + + mainbox.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_container_set_border_width(GTK_CONTAINER(mainbox.window), 5); + gtk_window_set_title(GTK_WINDOW(mainbox.window), "CDVDisoEFP Configuration"); + gtk_window_set_position(GTK_WINDOW(mainbox.window), GTK_WIN_POS_CENTER); + g_signal_connect(G_OBJECT(mainbox.window), "delete_event", + G_CALLBACK(MainBoxCancelEvent), NULL); + + vbox1 = gtk_vbox_new(FALSE, 5); + gtk_container_add(GTK_CONTAINER(mainbox.window), vbox1); + gtk_container_set_border_width(GTK_CONTAINER(vbox1), 5); + gtk_widget_show(vbox1); + hbox1 = gtk_hbox_new(FALSE, 10); + gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); + gtk_widget_show(hbox1); + item = gtk_label_new("Iso File:"); + gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0); + gtk_widget_show(item); + item = NULL; + + mainbox.file = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(hbox1), mainbox.file, TRUE, TRUE, 0); + gtk_widget_show(mainbox.file); + g_signal_connect(G_OBJECT(mainbox.file), "changed", + G_CALLBACK(MainBoxFileEvent), NULL); + + mainbox.selectbutton = gtk_button_new_with_label("Browse"); + gtk_box_pack_start(GTK_BOX(hbox1), mainbox.selectbutton, FALSE, FALSE, 0); + gtk_widget_show(mainbox.selectbutton); + g_signal_connect(G_OBJECT(mainbox.selectbutton), "clicked", + G_CALLBACK(MainBoxBrowseEvent), NULL); + hbox1 = NULL; + mainbox.desc = gtk_label_new("File Type: ---"); + gtk_box_pack_start(GTK_BOX(vbox1), mainbox.desc, FALSE, FALSE, 0); + gtk_widget_show(mainbox.desc); + // hbox1 = gtk_hbox_new(FALSE, 10); + // gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); + // gtk_widget_show(hbox1); + mainbox.startcheck = gtk_check_button_new_with_label("Show Configure screen when starting emulation"); + gtk_box_pack_start(GTK_BOX(vbox1), mainbox.startcheck, FALSE, FALSE, 0); + gtk_widget_show(mainbox.startcheck); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mainbox.startcheck), FALSE); + if (conf.startconfigure != 0) + { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mainbox.startcheck), TRUE); + } // ENDIF- Is this box supposed to be checked? + mainbox.restartcheck = gtk_check_button_new_with_label("Show Configure screen when restarting emulation"); + gtk_box_pack_start(GTK_BOX(vbox1), mainbox.restartcheck, FALSE, FALSE, 0); + gtk_widget_show(mainbox.restartcheck); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mainbox.restartcheck), FALSE); + if (conf.restartconfigure != 0) + { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mainbox.restartcheck), TRUE); + } // ENDIF- Is this box supposed to be checked? + hbox1 = gtk_hbutton_box_new(); + gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); + gtk_widget_show(hbox1); + mainbox.okbutton = gtk_button_new_with_label("Ok"); + gtk_box_pack_start(GTK_BOX(hbox1), mainbox.okbutton, TRUE, TRUE, 0); + gtk_widget_show(mainbox.okbutton); + g_signal_connect(G_OBJECT(mainbox.okbutton), "clicked", + G_CALLBACK(MainBoxOKEvent), NULL); + mainbox.devbutton = gtk_button_new_with_label("Get from Disc"); + gtk_box_pack_start(GTK_BOX(hbox1), mainbox.devbutton, TRUE, TRUE, 0); + gtk_widget_show(mainbox.devbutton); + g_signal_connect(G_OBJECT(mainbox.devbutton), "clicked", + G_CALLBACK(MainBoxDeviceEvent), NULL); + mainbox.convbutton = gtk_button_new_with_label("Convert"); + gtk_box_pack_start(GTK_BOX(hbox1), mainbox.convbutton, TRUE, TRUE, 0); + gtk_widget_show(mainbox.convbutton); + g_signal_connect(G_OBJECT(mainbox.convbutton), "clicked", + G_CALLBACK(MainBoxConversionEvent), NULL); + item = gtk_button_new_with_label("Cancel"); + gtk_box_pack_start(GTK_BOX(hbox1), item, TRUE, TRUE, 0); + gtk_widget_show(item); + g_signal_connect(G_OBJECT(item), "clicked", + G_CALLBACK(MainBoxCancelEvent), NULL); + item = NULL; + hbox1 = NULL; + vbox1 = NULL; + + // We held off setting the name until now... so description would show. + gtk_entry_set_text(GTK_ENTRY(mainbox.file), conf.isoname); } // END MainBoxDisplay() - diff --git a/plugins/CDVDisoEFP/src/Linux/mainbox.h b/plugins/CDVDisoEFP/src/Linux/mainbox.h index 52f8403891..68ae257386 100644 --- a/plugins/CDVDisoEFP/src/Linux/mainbox.h +++ b/plugins/CDVDisoEFP/src/Linux/mainbox.h @@ -1,50 +1,51 @@ -/* mainbox.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - -#ifndef MAINBOX_H -#define MAINBOX_H - - -#include - - -struct MainBoxData { - GtkWidget *window; // GtkWindow - GtkWidget *file; // GtkEntry - GtkWidget *selectbutton; // GtkButton - GtkWidget *desc; // GtkLabel - GtkWidget *startcheck; // GtkCheckBox - GtkWidget *restartcheck; // GtkCheckBox - GtkWidget *devbutton; // GtkButton - GtkWidget *convbutton; // GtkButton - GtkWidget *okbutton; // GtkButton - // Leaving the Cancel button unblocked... for emergency shutdown - - int stop; // Variable signal to stop long processes -}; - -extern struct MainBoxData mainbox; - -extern void MainBoxRefocus(); -extern void MainBoxDisplay(); - - -#endif /* MAINBOX_H */ +/* mainbox.h + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +#ifndef MAINBOX_H +#define MAINBOX_H + + +#include + + +struct MainBoxData +{ + GtkWidget *window; // GtkWindow + GtkWidget *file; // GtkEntry + GtkWidget *selectbutton; // GtkButton + GtkWidget *desc; // GtkLabel + GtkWidget *startcheck; // GtkCheckBox + GtkWidget *restartcheck; // GtkCheckBox + GtkWidget *devbutton; // GtkButton + GtkWidget *convbutton; // GtkButton + GtkWidget *okbutton; // GtkButton + // Leaving the Cancel button unblocked... for emergency shutdown + + int stop; // Variable signal to stop long processes +}; + +extern struct MainBoxData mainbox; + +extern void MainBoxRefocus(); +extern void MainBoxDisplay(); + + +#endif /* MAINBOX_H */ diff --git a/plugins/CDVDisoEFP/src/Linux/messagebox.c b/plugins/CDVDisoEFP/src/Linux/messagebox.c index a8145ecb25..50bddd83f9 100644 --- a/plugins/CDVDisoEFP/src/Linux/messagebox.c +++ b/plugins/CDVDisoEFP/src/Linux/messagebox.c @@ -1,226 +1,108 @@ /* messagebox.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include // NULL - - #include // gtk_button_new_with_label() - #include // gtk_hbutton_box_new() - #include // gtk_label_new() - #include // gtk_init(), gtk_main(), gtk_main_quit() - #include // gtk_vbox_new() - #include // gtk_window_new() - - - #include "mainbox.h" - #include "devicebox.h" - #include "conversionbox.h" - #include "messagebox.h" - - - - struct MessageBoxData messagebox; - - - - -void MessageBoxDestroy() { - - if(messagebox.window != NULL) { - - gtk_widget_destroy(messagebox.window); - - messagebox.window = NULL; - - messagebox.desc = NULL; - - } // ENDIF- Do we have a Main Window still? - +void MessageBoxDestroy() +{ + if (messagebox.window != NULL) + { + gtk_widget_destroy(messagebox.window); + messagebox.window = NULL; + messagebox.desc = NULL; + } // ENDIF- Do we have a Main Window still? } // END MessageBoxDestroy() - - - - -void MessageBoxShow(char *message, int wherefrom) { - - gtk_label_set_text(GTK_LABEL(messagebox.desc), message); - - messagebox.wherefrom = wherefrom; - - - - gtk_widget_show_all(messagebox.window); - - gtk_window_deiconify(GTK_WINDOW(messagebox.window)); - +void MessageBoxShow(char *message, int wherefrom) +{ + gtk_label_set_text(GTK_LABEL(messagebox.desc), message); + messagebox.wherefrom = wherefrom; + gtk_widget_show_all(messagebox.window); + gtk_window_deiconify(GTK_WINDOW(messagebox.window)); } // END MessageBox() - - - - -gint MessageBoxCancelEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - gtk_widget_hide(messagebox.window); - - - - switch(messagebox.wherefrom) { - - case 1: - - MainBoxRefocus(); - - break; - - case 2: - - DeviceBoxRefocus(); - - break; - - case 3: - - ConversionBoxRefocus(); - - break; - - } // ENDSWITCH- Whose window do I get to re-focus when this is done? - - - - return(TRUE); - +gint MessageBoxCancelEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + gtk_widget_hide(messagebox.window); + switch (messagebox.wherefrom) + { + case 1: + MainBoxRefocus(); + break; + case 2: + DeviceBoxRefocus(); + break; + case 3: + ConversionBoxRefocus(); + break; + } // ENDSWITCH- Whose window do I get to re-focus when this is done? + return(TRUE); } // END MessageBoxCancelEvent() +void MessageBoxDisplay() +{ + GtkWidget *item; + GtkWidget *hbox1; + GtkWidget *vbox1; + messagebox.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_container_set_border_width(GTK_CONTAINER(messagebox.window), 5); + gtk_window_set_title(GTK_WINDOW(messagebox.window), "CDVDisoEFP"); + gtk_window_set_position(GTK_WINDOW(messagebox.window), GTK_WIN_POS_CENTER); + gtk_window_set_resizable(GTK_WINDOW(messagebox.window), FALSE); + g_signal_connect(G_OBJECT(messagebox.window), "delete_event", + G_CALLBACK(MessageBoxCancelEvent), NULL); + vbox1 = gtk_vbox_new(FALSE, 5); + gtk_container_add(GTK_CONTAINER(messagebox.window), vbox1); + gtk_container_set_border_width(GTK_CONTAINER(vbox1), 5); + gtk_widget_show(vbox1); + messagebox.desc = gtk_label_new("Hi There!\r\nHow are you doing?"); + gtk_box_pack_start(GTK_BOX(vbox1), messagebox.desc, FALSE, FALSE, 0); + gtk_widget_show(messagebox.desc); -void MessageBoxDisplay() { - - GtkWidget *item; - - GtkWidget *hbox1; - - GtkWidget *vbox1; - - - - messagebox.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - gtk_container_set_border_width(GTK_CONTAINER(messagebox.window), 5); - - gtk_window_set_title(GTK_WINDOW(messagebox.window), "CDVDisoEFP"); - - gtk_window_set_position(GTK_WINDOW(messagebox.window), GTK_WIN_POS_CENTER); - - gtk_window_set_resizable(GTK_WINDOW(messagebox.window), FALSE); - - - - g_signal_connect(G_OBJECT(messagebox.window), "delete_event", - - G_CALLBACK(MessageBoxCancelEvent), NULL); - - - - vbox1 = gtk_vbox_new(FALSE, 5); - - gtk_container_add(GTK_CONTAINER(messagebox.window), vbox1); - - gtk_container_set_border_width(GTK_CONTAINER(vbox1), 5); - - gtk_widget_show(vbox1); - - - - messagebox.desc = gtk_label_new("Hi There!\r\nHow are you doing?"); - - gtk_box_pack_start(GTK_BOX(vbox1), messagebox.desc, FALSE, FALSE, 0); - - gtk_widget_show(messagebox.desc); - - - - hbox1 = gtk_hbutton_box_new(); - - gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); - - gtk_widget_show(hbox1); - - - - item = gtk_button_new_with_label("Cancel"); - - gtk_box_pack_start(GTK_BOX(hbox1), item, TRUE, TRUE, 0); - - GTK_WIDGET_SET_FLAGS(item, GTK_CAN_DEFAULT); - - gtk_widget_show(item); - - g_signal_connect(G_OBJECT(item), "clicked", - - G_CALLBACK(MessageBoxCancelEvent), NULL); - - item = NULL; - - hbox1 = NULL; - - vbox1 = NULL; + hbox1 = gtk_hbutton_box_new(); + gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); + gtk_widget_show(hbox1); + item = gtk_button_new_with_label("Cancel"); + gtk_box_pack_start(GTK_BOX(hbox1), item, TRUE, TRUE, 0); + GTK_WIDGET_SET_FLAGS(item, GTK_CAN_DEFAULT); + gtk_widget_show(item); + g_signal_connect(G_OBJECT(item), "clicked", + G_CALLBACK(MessageBoxCancelEvent), NULL); + item = NULL; + hbox1 = NULL; + vbox1 = NULL; } // END MessageBoxDisplay() - diff --git a/plugins/CDVDisoEFP/src/Linux/messagebox.h b/plugins/CDVDisoEFP/src/Linux/messagebox.h index 94ccb3ccc1..6a10591ab0 100644 --- a/plugins/CDVDisoEFP/src/Linux/messagebox.h +++ b/plugins/CDVDisoEFP/src/Linux/messagebox.h @@ -1,43 +1,44 @@ -/* messagebox.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - -#ifndef MESSAGEBOX_H -#define MESSAGEBOX_H - - -#include - - -struct MessageBoxData { - GtkWidget *window; // GtkWindow - GtkWidget *desc; // GtkLabel - - int wherefrom; // Whom do I refocus when the message is read? -}; - -extern struct MessageBoxData messagebox; - -extern void MessageBoxDestroy(); -extern void MessageBoxShow(char *message, int wherefrom); -extern void MessageBoxDisplay(); - - -#endif /* MESSAGEBOX_H */ +/* messagebox.h + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +#ifndef MESSAGEBOX_H +#define MESSAGEBOX_H + + +#include + + +struct MessageBoxData +{ + GtkWidget *window; // GtkWindow + GtkWidget *desc; // GtkLabel + + int wherefrom; // Whom do I refocus when the message is read? +}; + +extern struct MessageBoxData messagebox; + +extern void MessageBoxDestroy(); +extern void MessageBoxShow(char *message, int wherefrom); +extern void MessageBoxDisplay(); + + +#endif /* MESSAGEBOX_H */ diff --git a/plugins/CDVDisoEFP/src/Linux/progressbox.c b/plugins/CDVDisoEFP/src/Linux/progressbox.c index 2c497053c1..f94b5fffff 100644 --- a/plugins/CDVDisoEFP/src/Linux/progressbox.c +++ b/plugins/CDVDisoEFP/src/Linux/progressbox.c @@ -1,288 +1,134 @@ /* progressbox.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include // NULL - #include // sprintf() - #include // off64_t - - #include // gtk_button_new_with_label() - #include // gtk_container_add() - #include // gtk_file_selection_set_filename() - #include // gtk_hbutton_box_new() - #include // gtk_hbox_new() - #include // gtk_label_new() - #include // gtk_main_iteration(), gtk_events_pending() - #include // gtk_progress_bar_new() - #include // gtk_vbox_new() - #include // gtk_window_new() - - - #include "progressbox.h" - - - - struct ProgressBoxData progressbox; - char progressboxline[256]; - - - - -void ProgressBoxDestroy() { - - if(progressbox.window != NULL) { - - gtk_widget_destroy(progressbox.window); - - progressbox.window = NULL; - - progressbox.desc = NULL; - - } // ENDIF- Do we have a Main Window still? - +void ProgressBoxDestroy() +{ + if (progressbox.window != NULL) + { + gtk_widget_destroy(progressbox.window); + progressbox.window = NULL; + progressbox.desc = NULL; + } // ENDIF- Do we have a Main Window still? } // END ProgressBoxDestroy() +void ProgressBoxStart(char *description, off64_t maximum) +{ + gtk_label_set_text(GTK_LABEL(progressbox.desc), description); - - - -void ProgressBoxStart(char *description, off64_t maximum) { - - gtk_label_set_text(GTK_LABEL(progressbox.desc), description); - - - - progressbox.max = maximum; - - progressbox.gmax = maximum; - - progressbox.lastpct = 100; - - progressbox.stop = 0; - - - - ProgressBoxTick(0); - - gtk_widget_show_all(progressbox.window); - - gtk_window_deiconify(GTK_WINDOW(progressbox.window)); - + progressbox.max = maximum; + progressbox.gmax = maximum; + progressbox.lastpct = 100; + progressbox.stop = 0; + ProgressBoxTick(0); + gtk_widget_show_all(progressbox.window); + gtk_window_deiconify(GTK_WINDOW(progressbox.window)); } // END ProgressBoxStart() +void ProgressBoxTick(off64_t current) +{ + gdouble gcur; + off64_t thispct; + gcur = current; + gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressbox.bar), + gcur / progressbox.gmax); + sprintf(progressboxline, "%llu of %llu", current, progressbox.max); + gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progressbox.bar), progressboxline); - - - -void ProgressBoxTick(off64_t current) { - - gdouble gcur; - - off64_t thispct; - - - - gcur = current; - - gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressbox.bar), - - gcur / progressbox.gmax); - - - - sprintf(progressboxline, "%llu of %llu", current, progressbox.max); - - gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progressbox.bar), progressboxline); - - - - if(progressbox.max >= 100) { - - thispct = current / ( progressbox.max / 100 ); - - if(thispct != progressbox.lastpct) { - - sprintf(progressboxline, "%llu%% CDVDisoEFP Progress", thispct); - - gtk_window_set_title(GTK_WINDOW(progressbox.window), progressboxline); - - progressbox.lastpct = thispct; - - } // ENDIF- Change in percentage? (Avoiding title flicker) - - } // ENDIF- Our maximum # over 100? (Avoiding divide-by-zero error) - - - - while(gtk_events_pending()) gtk_main_iteration(); // Give time for window to redraw. - + if (progressbox.max >= 100) + { + thispct = current / (progressbox.max / 100); + if (thispct != progressbox.lastpct) + { + sprintf(progressboxline, "%llu%% CDVDisoEFP Progress", thispct); + gtk_window_set_title(GTK_WINDOW(progressbox.window), progressboxline); + progressbox.lastpct = thispct; + } // ENDIF- Change in percentage? (Avoiding title flicker) + } // ENDIF- Our maximum # over 100? (Avoiding divide-by-zero error) + while (gtk_events_pending()) gtk_main_iteration(); // Give time for window to redraw. } // END ProgressBoxTick() - - - - -void ProgressBoxStop() { - - gtk_widget_hide(progressbox.window); - - gtk_window_set_title(GTK_WINDOW(progressbox.window), "CDVDisoEFP Progress"); - +void ProgressBoxStop() +{ + gtk_widget_hide(progressbox.window); + gtk_window_set_title(GTK_WINDOW(progressbox.window), "CDVDisoEFP Progress"); } // END ProgressBoxStop() +gint ProgressBoxCancelEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + progressbox.stop = 1; - - - -gint ProgressBoxCancelEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - progressbox.stop = 1; - - - - return(TRUE); - + return(TRUE); } // END ProgressBoxCancelEvent() +void ProgressBoxDisplay() +{ + GtkWidget *item; + GtkWidget *hbox1; + GtkWidget *vbox1; + progressbox.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_container_set_border_width(GTK_CONTAINER(progressbox.window), 5); + gtk_window_set_title(GTK_WINDOW(progressbox.window), "CDVDisoEFP Progress"); + gtk_window_set_position(GTK_WINDOW(progressbox.window), GTK_WIN_POS_CENTER); + gtk_window_set_resizable(GTK_WINDOW(progressbox.window), FALSE); + g_signal_connect(G_OBJECT(progressbox.window), "delete_event", + G_CALLBACK(ProgressBoxCancelEvent), NULL); - - - -void ProgressBoxDisplay() { - - GtkWidget *item; - - GtkWidget *hbox1; - - GtkWidget *vbox1; - - - - progressbox.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - gtk_container_set_border_width(GTK_CONTAINER(progressbox.window), 5); - - gtk_window_set_title(GTK_WINDOW(progressbox.window), "CDVDisoEFP Progress"); - - gtk_window_set_position(GTK_WINDOW(progressbox.window), GTK_WIN_POS_CENTER); - - gtk_window_set_resizable(GTK_WINDOW(progressbox.window), FALSE); - - - - g_signal_connect(G_OBJECT(progressbox.window), "delete_event", - - G_CALLBACK(ProgressBoxCancelEvent), NULL); - - - - vbox1 = gtk_vbox_new(FALSE, 5); - - gtk_container_add(GTK_CONTAINER(progressbox.window), vbox1); - - gtk_container_set_border_width(GTK_CONTAINER(vbox1), 5); - - gtk_widget_show(vbox1); - - - - progressbox.desc = gtk_label_new("Twiddling Thumbs"); - - gtk_box_pack_start(GTK_BOX(vbox1), progressbox.desc, FALSE, FALSE, 0); - - gtk_widget_show(progressbox.desc); - - - - progressbox.bar = gtk_progress_bar_new(); - - gtk_box_pack_start(GTK_BOX(vbox1), progressbox.bar, FALSE, FALSE, 0); - - gtk_widget_show(progressbox.bar); - - - - hbox1 = gtk_hbutton_box_new(); - - gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); - - gtk_widget_show(hbox1); - - - - item = gtk_button_new_with_label("Cancel"); - - gtk_box_pack_start(GTK_BOX(hbox1), item, TRUE, TRUE, 0); - - GTK_WIDGET_SET_FLAGS(item, GTK_CAN_DEFAULT); - - gtk_widget_show(item); - - g_signal_connect(G_OBJECT(item), "clicked", - - G_CALLBACK(ProgressBoxCancelEvent), NULL); - - item = NULL; - - hbox1 = NULL; - - vbox1 = NULL; - + vbox1 = gtk_vbox_new(FALSE, 5); + gtk_container_add(GTK_CONTAINER(progressbox.window), vbox1); + gtk_container_set_border_width(GTK_CONTAINER(vbox1), 5); + gtk_widget_show(vbox1); + progressbox.desc = gtk_label_new("Twiddling Thumbs"); + gtk_box_pack_start(GTK_BOX(vbox1), progressbox.desc, FALSE, FALSE, 0); + gtk_widget_show(progressbox.desc); + progressbox.bar = gtk_progress_bar_new(); + gtk_box_pack_start(GTK_BOX(vbox1), progressbox.bar, FALSE, FALSE, 0); + gtk_widget_show(progressbox.bar); + hbox1 = gtk_hbutton_box_new(); + gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); + gtk_widget_show(hbox1); + item = gtk_button_new_with_label("Cancel"); + gtk_box_pack_start(GTK_BOX(hbox1), item, TRUE, TRUE, 0); + GTK_WIDGET_SET_FLAGS(item, GTK_CAN_DEFAULT); + gtk_widget_show(item); + g_signal_connect(G_OBJECT(item), "clicked", + G_CALLBACK(ProgressBoxCancelEvent), NULL); + item = NULL; + hbox1 = NULL; + vbox1 = NULL; } // END ProgressBoxDisplay() - diff --git a/plugins/CDVDisoEFP/src/Linux/progressbox.h b/plugins/CDVDisoEFP/src/Linux/progressbox.h index 3b2eff5c51..05d288e1ef 100644 --- a/plugins/CDVDisoEFP/src/Linux/progressbox.h +++ b/plugins/CDVDisoEFP/src/Linux/progressbox.h @@ -1,55 +1,56 @@ -/* progressbox.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - -#ifndef PROGRESSBOX_H -#define PROGRESSBOX_H - - -#include // off64_t - -#include // GtkWidget - - -extern const char *compressnames[]; - -struct ProgressBoxData { - GtkWidget *window; // GtkWindow - GtkWidget *desc; // GtkLabel - What are we showing progress on? - GtkWidget *bar; // GtkProgressBar - - off64_t max; - gdouble gmax; - off64_t lastpct; - - int stop; // Someone pressed the Stop button -}; - -extern struct ProgressBoxData progressbox; - - -extern void ProgressBoxStart(char *description, off64_t maximum); -extern void ProgressBoxTick(off64_t current); -extern void ProgressBoxStop(); -extern void ProgressBoxDestroy(); -extern void ProgressBoxDisplay(); - - -#endif /* MAINBOX_H */ +/* progressbox.h + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +#ifndef PROGRESSBOX_H +#define PROGRESSBOX_H + + +#include // off64_t + +#include // GtkWidget + + +extern const char *compressnames[]; + +struct ProgressBoxData +{ + GtkWidget *window; // GtkWindow + GtkWidget *desc; // GtkLabel - What are we showing progress on? + GtkWidget *bar; // GtkProgressBar + + off64_t max; + gdouble gmax; + off64_t lastpct; + + int stop; // Someone pressed the Stop button +}; + +extern struct ProgressBoxData progressbox; + + +extern void ProgressBoxStart(char *description, off64_t maximum); +extern void ProgressBoxTick(off64_t current); +extern void ProgressBoxStop(); +extern void ProgressBoxDestroy(); +extern void ProgressBoxDisplay(); + + +#endif /* MAINBOX_H */ diff --git a/plugins/CDVDisoEFP/src/Linux/selectionbox.c b/plugins/CDVDisoEFP/src/Linux/selectionbox.c index 01a04f48e0..30c567fe9a 100644 --- a/plugins/CDVDisoEFP/src/Linux/selectionbox.c +++ b/plugins/CDVDisoEFP/src/Linux/selectionbox.c @@ -1,204 +1,99 @@ /* selectionbox.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include // NULL - - #include // g_signal_connect() - #include // gtk_entry_set_text() - #include // gtk_file_selection_new() - - #include "devicebox.h" - #include "conversionbox.h" - #include "selectionbox.h" - #include "mainbox.h" - - - - struct SelectionBoxData selectionbox; - - - - -void SelectionBoxDestroy() { - - if(selectionbox.window != NULL) { - - gtk_widget_destroy(selectionbox.window); - - selectionbox.window = NULL; - - } // ENDIF- Do we have a Main Window still? - +void SelectionBoxDestroy() +{ + if (selectionbox.window != NULL) + { + gtk_widget_destroy(selectionbox.window); + selectionbox.window = NULL; + } // ENDIF- Do we have a Main Window still? } // END SelectionBoxDestroy() - - - - -void SelectionBoxRefresh() { - +void SelectionBoxRefresh() +{ } // END SelectionBoxRefresh() - - - - -void SelectionBoxUnfocus() { - - gtk_widget_hide(selectionbox.window); - +void SelectionBoxUnfocus() +{ + gtk_widget_hide(selectionbox.window); } // END SelectionBoxUnfocus() - - - - -void SelectionBoxRefocus() { - - gtk_widget_show(selectionbox.window); - +void SelectionBoxRefocus() +{ + gtk_widget_show(selectionbox.window); } // END SelectionBoxRefocus() - - - - -gint SelectionBoxCancelEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - SelectionBoxUnfocus(); - - switch(selectionbox.wherefrom) { - - case 1: - - gtk_entry_set_text(GTK_ENTRY(mainbox.file), - - gtk_file_selection_get_filename(GTK_FILE_SELECTION(selectionbox.window))); - - MainBoxRefocus(); - - break; - - case 2: - - gtk_entry_set_text(GTK_ENTRY(devicebox.file), - - gtk_file_selection_get_filename(GTK_FILE_SELECTION(selectionbox.window))); - - DeviceBoxRefocus(); - - break; - - case 3: - - gtk_entry_set_text(GTK_ENTRY(conversionbox.file), - - gtk_file_selection_get_filename(GTK_FILE_SELECTION(selectionbox.window))); - - ConversionBoxRefocus(); - - break; - - } // ENDSWITCH wherefrom- What Box called us? - - return(TRUE); - +gint SelectionBoxCancelEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + SelectionBoxUnfocus(); + switch (selectionbox.wherefrom) + { + case 1: + gtk_entry_set_text(GTK_ENTRY(mainbox.file), + gtk_file_selection_get_filename(GTK_FILE_SELECTION(selectionbox.window))); + MainBoxRefocus(); + break; + case 2: + gtk_entry_set_text(GTK_ENTRY(devicebox.file), + gtk_file_selection_get_filename(GTK_FILE_SELECTION(selectionbox.window))); + DeviceBoxRefocus(); + break; + case 3: + gtk_entry_set_text(GTK_ENTRY(conversionbox.file), + gtk_file_selection_get_filename(GTK_FILE_SELECTION(selectionbox.window))); + ConversionBoxRefocus(); + break; + } // ENDSWITCH wherefrom- What Box called us? + return(TRUE); } // END SelectionBoxCancelEvent() - - - - -gint SelectionBoxOKEvent(GtkWidget *widget, GdkEvent event, gpointer data) { - - // Validate listed file(?) - - - - // Transfer file name to calling window? - - - - SelectionBoxCancelEvent(widget, event, data); - - return(TRUE); - +gint SelectionBoxOKEvent(GtkWidget *widget, GdkEvent event, gpointer data) +{ + // Validate listed file(?) + // Transfer file name to calling window? + SelectionBoxCancelEvent(widget, event, data); + return(TRUE); } // END SelectionBoxOKEvent() - - - - -void SelectionBoxDisplay() { - - selectionbox.window = gtk_file_selection_new("Select an ISO file"); - - g_signal_connect(G_OBJECT(selectionbox.window), "delete_event", - - G_CALLBACK(SelectionBoxCancelEvent), NULL); - - g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(selectionbox.window)->ok_button), - - "clicked", G_CALLBACK(SelectionBoxOKEvent), NULL); - - g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(selectionbox.window)->cancel_button), - - "clicked", G_CALLBACK(SelectionBoxCancelEvent), NULL); - - - - selectionbox.wherefrom = 0; // Called by no one... yet. - +void SelectionBoxDisplay() +{ + selectionbox.window = gtk_file_selection_new("Select an ISO file"); + g_signal_connect(G_OBJECT(selectionbox.window), "delete_event", + G_CALLBACK(SelectionBoxCancelEvent), NULL); + g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(selectionbox.window)->ok_button), + "clicked", G_CALLBACK(SelectionBoxOKEvent), NULL); + g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(selectionbox.window)->cancel_button), + "clicked", G_CALLBACK(SelectionBoxCancelEvent), NULL); + selectionbox.wherefrom = 0; // Called by no one... yet. } // END SelectionBoxDisplay() - diff --git a/plugins/CDVDisoEFP/src/Linux/selectionbox.h b/plugins/CDVDisoEFP/src/Linux/selectionbox.h index d79febb38f..34ea5dbcd2 100644 --- a/plugins/CDVDisoEFP/src/Linux/selectionbox.h +++ b/plugins/CDVDisoEFP/src/Linux/selectionbox.h @@ -1,46 +1,47 @@ -/* selectionbox.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - -#ifndef SELECTIONBOX_H -#define SELECTIONBOX_H - - -#include - - -struct SelectionBoxData { - GtkWidget *window; // GtkWindow - - int wherefrom; // Which box called you? - // 1 = MainBox - // 2 = DeviceBox - // 3 = ConversionBox -}; - -extern struct SelectionBoxData selectionbox; - - -extern void SelectionBoxDestroy(); -extern void SelectionBoxRefocus(); -extern void SelectionBoxDisplay(); - - -#endif /* SELECTIONBOX_H */ +/* selectionbox.h + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +#ifndef SELECTIONBOX_H +#define SELECTIONBOX_H + + +#include + + +struct SelectionBoxData +{ + GtkWidget *window; // GtkWindow + + int wherefrom; // Which box called you? + // 1 = MainBox + // 2 = DeviceBox + // 3 = ConversionBox +}; + +extern struct SelectionBoxData selectionbox; + + +extern void SelectionBoxDestroy(); +extern void SelectionBoxRefocus(); +extern void SelectionBoxDisplay(); + + +#endif /* SELECTIONBOX_H */ diff --git a/plugins/CDVDisoEFP/src/Linux/tablerebuild.c b/plugins/CDVDisoEFP/src/Linux/tablerebuild.c index 99a67aa148..ac3c9ec36a 100644 --- a/plugins/CDVDisoEFP/src/Linux/tablerebuild.c +++ b/plugins/CDVDisoEFP/src/Linux/tablerebuild.c @@ -1,380 +1,190 @@ /* tablerebuild.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include // NULL - #include // sprintf() - #include // malloc() - - // #include // gtk_main_iteration() - - #include "mainbox.h" - #include "progressbox.h" - #include "isofile.h" - #include "multifile.h" - #include "isocompress.h" // CompressClose() - #include "gzipv1.h" - #include "gzipv2.h" - #include "bzip2v2.h" - #include "bzip2v3.h" - #include "actualfile.h" // ACTUALHANDLENULL - - - - -void IsoTableRebuild(const char *filename) { - - struct IsoFile *datafile; - - struct IsoFile *tablefile; - - int retval; - - char tempblock[65536]; - - int stop; - - - - struct TableData table; - - - - datafile = IsoFileOpenForRead(filename); - - - - // Note: This is the start of the "Multifile" process. It's commented - - // out so at least we can rebuild 1 part of a multifile at a time. - - // IsoNameStripExt(datafile); - - // IsoNameStripMulti(datafile); - - - - // Prep tablefile to hold ONLY a table (no data) - - tablefile = (struct IsoFile *) malloc(sizeof(struct IsoFile)); - - if(tablefile == NULL) { - - datafile = IsoFileClose(datafile); - - return; - - } // ENDIF- Failed to allocate? Abort. - - - - tablefile->sectorpos = 0; - - tablefile->openforread = 0; - - tablefile->filebytepos = 0; - - tablefile->filebytesize = 0; - - tablefile->filesectorpos = 0; - - tablefile->filesectorsize = 0; - - tablefile->handle = ACTUALHANDLENULL; - - - - tablefile->namepos = 0; - - while((tablefile->namepos < 255) && - - (*(filename + tablefile->namepos) != 0)) { - - tablefile->name[tablefile->namepos] = *(filename + tablefile->namepos); - - tablefile->namepos++; - - } // ENDWHILE- Copying file name into tablefile - - tablefile->name[tablefile->namepos] = 0; // And 0-terminate. - - - - tablefile->imageheader = datafile->imageheader; - - tablefile->blocksize = datafile->blocksize; - - tablefile->blockoffset = datafile->blockoffset; - - tablefile->cdvdtype = 0; // Not important right now. - - - - tablefile->compress = datafile->compress; - - tablefile->compresspos = datafile->compresspos; - - tablefile->numsectors = datafile->numsectors; - - tablefile->tabledata = NULL; - - - - switch(tablefile->compress) { - - case 1: - - retval = GZipV1OpenTableForWrite(tablefile); - - break; - - case 2: - - retval = -1; - - break; - - case 3: - - retval = GZipV2OpenTableForWrite(tablefile); - - break; - - case 4: - - retval = BZip2V2OpenTableForWrite(tablefile); - - break; - - case 5: - - retval = BZip2V3OpenTableForWrite(tablefile); - - break; - - default: - - retval = -1; - - break; - - } // ENDSWITCH compress- Which table are we writing out? - - if(retval < 0) { - - datafile = IsoFileClose(datafile); - - return; - - } // ENDIF- Failed to open table file? Abort - - - - sprintf(tempblock, "Rebuilding table for %s", datafile->name); - - ProgressBoxStart(tempblock, datafile->filebytesize); - - - - stop = 0; - - mainbox.stop = 0; - - progressbox.stop = 0; - - while((stop == 0) && (datafile->filebytepos < datafile->filebytesize)) { - - switch(datafile->compress) { - - case 1: - - retval = GZipV1Read(datafile, 0, tempblock); - - break; - - case 2: - - retval = -1; - - break; - - case 3: - - retval = GZipV2Read(datafile, 0, tempblock); - - break; - - case 4: - - retval = BZip2V2Read(datafile, 0, tempblock); - - break; - - case 5: - - retval = BZip2V3Read(datafile, 0, tempblock); - - break; - - default: - - retval = -1; - - break; - - } // ENDSWITCH compress- Scanning for the next complete compressed block - - - - if(retval <= 0) { - +void IsoTableRebuild(const char *filename) +{ + struct IsoFile *datafile; + struct IsoFile *tablefile; + int retval; + char tempblock[65536]; + int stop; + struct TableData table; + datafile = IsoFileOpenForRead(filename); + // Note: This is the start of the "Multifile" process. It's commented + // out so at least we can rebuild 1 part of a multifile at a time. + // IsoNameStripExt(datafile); + // IsoNameStripMulti(datafile); + + // Prep tablefile to hold ONLY a table (no data) + tablefile = (struct IsoFile *) malloc(sizeof(struct IsoFile)); + if (tablefile == NULL) + { + datafile = IsoFileClose(datafile); + return; + } // ENDIF- Failed to allocate? Abort. + tablefile->sectorpos = 0; + tablefile->openforread = 0; + tablefile->filebytepos = 0; + tablefile->filebytesize = 0; + tablefile->filesectorpos = 0; + tablefile->filesectorsize = 0; + tablefile->handle = ACTUALHANDLENULL; + tablefile->namepos = 0; + while ((tablefile->namepos < 255) && + (*(filename + tablefile->namepos) != 0)) + { + tablefile->name[tablefile->namepos] = *(filename + tablefile->namepos); + tablefile->namepos++; + } // ENDWHILE- Copying file name into tablefile + tablefile->name[tablefile->namepos] = 0; // And 0-terminate. + tablefile->imageheader = datafile->imageheader; + tablefile->blocksize = datafile->blocksize; + tablefile->blockoffset = datafile->blockoffset; + tablefile->cdvdtype = 0; // Not important right now. + + tablefile->compress = datafile->compress; + tablefile->compresspos = datafile->compresspos; + tablefile->numsectors = datafile->numsectors; + tablefile->tabledata = NULL; + switch (tablefile->compress) + { + case 1: + retval = GZipV1OpenTableForWrite(tablefile); + break; + case 2: + retval = -1; + break; + case 3: + retval = GZipV2OpenTableForWrite(tablefile); + break; + case 4: + retval = BZip2V2OpenTableForWrite(tablefile); + break; + case 5: + retval = BZip2V3OpenTableForWrite(tablefile); + break; + default: + retval = -1; + break; + } // ENDSWITCH compress- Which table are we writing out? + if (retval < 0) + { + datafile = IsoFileClose(datafile); + return; + } // ENDIF- Failed to open table file? Abort + + sprintf(tempblock, "Rebuilding table for %s", datafile->name); + ProgressBoxStart(tempblock, datafile->filebytesize); + stop = 0; + mainbox.stop = 0; + progressbox.stop = 0; + while ((stop == 0) && (datafile->filebytepos < datafile->filebytesize)) + { + switch (datafile->compress) + { + case 1: + retval = GZipV1Read(datafile, 0, tempblock); + break; + case 2: + retval = -1; + break; + case 3: + retval = GZipV2Read(datafile, 0, tempblock); + break; + case 4: + retval = BZip2V2Read(datafile, 0, tempblock); + break; + case 5: + retval = BZip2V3Read(datafile, 0, tempblock); + break; + default: + retval = -1; + break; + } // ENDSWITCH compress- Scanning for the next complete compressed block + + if (retval <= 0) + { #ifdef FUNCTION_WARNING_TABLEREBUILD - - PrintLog("CDVDiso rebuild: failed to decompress - data corrupt"); - + PrintLog("CDVDiso rebuild: failed to decompress - data corrupt"); #endif /* FUNCTION_WARNING_TABLEREBUILD */ + stop = 1; + } + else + { + table.offset = datafile->filebytepos - retval; + table.size = retval; + switch (tablefile->compress) + { + case 1: + retval = GZipV1WriteTable(tablefile, table); + break; + case 2: + retval = -1; + break; + case 3: + retval = GZipV2WriteTable(tablefile, table); + break; + case 4: + retval = BZip2V2WriteTable(tablefile, table); + break; + case 5: + retval = BZip2V3WriteTable(tablefile, table); + break; + default: + retval = -1; + break; + } // ENDSWITCH compress- Writing out the relavent table facts + if (retval < 0) stop = 1; + } // ENDIF- Do we have a valid record to write an entry for? + ProgressBoxTick(datafile->filebytepos); + // while(gtk_events_pending()) gtk_main_iteration(); - stop = 1; + if (mainbox.stop != 0) stop = 2; + if (progressbox.stop != 0) stop = 2; + } // ENDWHILE- Read in the data file and writing a table, 1 block at a time - } else { - - table.offset = datafile->filebytepos - retval; - - table.size = retval; - - switch(tablefile->compress) { - - case 1: - - retval = GZipV1WriteTable(tablefile, table); - - break; - - case 2: - - retval = -1; - - break; - - case 3: - - retval = GZipV2WriteTable(tablefile, table); - - break; - - case 4: - - retval = BZip2V2WriteTable(tablefile, table); - - break; - - case 5: - - retval = BZip2V3WriteTable(tablefile, table); - - break; - - default: - - retval = -1; - - break; - - } // ENDSWITCH compress- Writing out the relavent table facts - - if(retval < 0) stop = 1; - - } // ENDIF- Do we have a valid record to write an entry for? - - - - ProgressBoxTick(datafile->filebytepos); - - // while(gtk_events_pending()) gtk_main_iteration(); - - - - if(mainbox.stop != 0) stop = 2; - - if(progressbox.stop != 0) stop = 2; - - } // ENDWHILE- Read in the data file and writing a table, 1 block at a time - - - - ProgressBoxStop(); - - - - CompressClose(tablefile); // Guarentee the table is flushed and closed. - - if(stop != 0) { - - ActualFileDelete(tablefile->tablename); - - } // ENDIF- Aborted or trouble? Delete the table file - - tablefile = IsoFileClose(tablefile); - - datafile = IsoFileClose(datafile); - - - - return; + ProgressBoxStop(); + CompressClose(tablefile); // Guarentee the table is flushed and closed. + if (stop != 0) + { + ActualFileDelete(tablefile->tablename); + } // ENDIF- Aborted or trouble? Delete the table file + tablefile = IsoFileClose(tablefile); + datafile = IsoFileClose(datafile); + return; } // END IsoTableRebuild() - diff --git a/plugins/CDVDisoEFP/src/Linux/tablerebuild.h b/plugins/CDVDisoEFP/src/Linux/tablerebuild.h index 731911d29a..2eda8557fd 100644 --- a/plugins/CDVDisoEFP/src/Linux/tablerebuild.h +++ b/plugins/CDVDisoEFP/src/Linux/tablerebuild.h @@ -1,32 +1,32 @@ -/* tablerebuild.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - -#ifndef TABLEREBUILD_H -#define TABLEREBUILD_H - - -// #define FUNCTION_WARNING_TABLEREBUILD - - -extern void IsoTableRebuild(const char *filename); - - -#endif /* TABLEREBUILD_H */ +/* tablerebuild.h + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +#ifndef TABLEREBUILD_H +#define TABLEREBUILD_H + + +// #define FUNCTION_WARNING_TABLEREBUILD + + +extern void IsoTableRebuild(const char *filename); + + +#endif /* TABLEREBUILD_H */ diff --git a/plugins/CDVDisoEFP/src/PS2Edefs.h b/plugins/CDVDisoEFP/src/PS2Edefs.h index 8bf1cc0c93..ae1ff20c55 100644 --- a/plugins/CDVDisoEFP/src/PS2Edefs.h +++ b/plugins/CDVDisoEFP/src/PS2Edefs.h @@ -10,7 +10,7 @@ */ /* - Notes: + Notes: * Since this is still beta things may change. * OSflags: @@ -23,23 +23,17 @@ * reserved keys: F1 to F10 are reserved for the emulator - - * plugins should NOT change the current + * plugins should NOT change the current working directory. (on win32, add flag OFN_NOCHANGEDIR for GetOpenFileName) - */ - #include "PS2Etypes.h" - #ifdef __LINUX__ #define CALLBACK #else #include #endif - - /* common defines */ #ifndef C_ASSERT #define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1] @@ -71,42 +65,37 @@ #define PS2E_FW_VERSION 0x0002 #define PS2E_SIO_VERSION 0x0001 #ifdef COMMONdefs - u32 CALLBACK PS2EgetLibType(void); u32 CALLBACK PS2EgetLibVersion2(u32 type); char* CALLBACK PS2EgetLibName(void); - #endif - // key values: /* key values must be OS dependant: win32: the VK_XXX will be used (WinUser) linux: the XK_XXX will be used (XFree86) */ - // event values: #define KEYPRESS 1 #define KEYRELEASE 2 - -typedef struct { +typedef struct +{ u32 key; u32 event; } keyEvent; - // for 64bit compilers typedef char __keyEvent_Size__[(sizeof(keyEvent) == 8)?1:-1]; - // plugin types #define SIO_TYPE_PAD 0x00000001 #define SIO_TYPE_MTAP 0x00000004 #define SIO_TYPE_RM 0x00000040 #define SIO_TYPE_MC 0x00000100 - typedef int (CALLBACK * SIOchangeSlotCB)(int slot); - -typedef struct { - u8 ctrl:4; // control and mode bits - u8 mode:4; // control and mode bits +typedef struct +{ +u8 ctrl: + 4; // control and mode bits +u8 mode: + 4; // control and mode bits u8 trackNum; // current track number (1 to 99) u8 trackIndex; // current index within track (0 to 99) u8 trackM; // current minute location on the disc (BCD encoded) @@ -117,17 +106,16 @@ typedef struct { u8 discS; // current sector offset from first track (BCD encoded) u8 discF; // current frame offset from first track (BCD encoded) } cdvdSubQ; - -typedef struct { // NOT bcd coded +typedef struct // NOT bcd coded +{ u32 lsn; u8 type; } cdvdTD; - -typedef struct { +typedef struct +{ u8 strack; //number of the first track (usually 1) u8 etrack; //number of the last track } cdvdTN; - // CDVDreadTrack mode values: #define CDVD_MODE_2352 0 // full 2352 bytes #define CDVD_MODE_2340 1 // skip sync (12) bytes @@ -159,43 +147,36 @@ typedef struct { #define CDVD_AUDIO_TRACK 0x01 #define CDVD_MODE1_TRACK 0x41 #define CDVD_MODE2_TRACK 0x61 - #define CDVD_AUDIO_MASK 0x00 #define CDVD_DATA_MASK 0x40 // CDROM_DATA_TRACK 0x04 //do not enable this! (from linux kernel) - typedef void (*DEV9callback)(int cycles); -typedef int (*DEV9handler)(void); +typedef int (*DEV9handler)(void); typedef void (*USBcallback)(int cycles); -typedef int (*USBhandler)(void); - +typedef int (*USBhandler)(void); // freeze modes: #define FREEZE_LOAD 0 #define FREEZE_SAVE 1 #define FREEZE_SIZE 2 - -typedef struct { +typedef struct +{ char name[8]; void *common; } GSdriverInfo; - #ifdef _WIN32 -typedef struct { // unsupported values must be set to zero +typedef struct // unsupported values must be set to zero +{ HWND hWnd; HMENU hMenu; HWND hStatusWnd; } winInfo; #endif - /* GS plugin API */ - // if this file is included with this define // the next api will not be skipped by the compiler #ifdef GSdefs - // basic funcs - s32 CALLBACK GSinit(); s32 CALLBACK GSopen(void *pDsp, char *Title, int multithread); void CALLBACK GSclose(); @@ -207,9 +188,7 @@ void CALLBACK GSgifTransfer3(u32 *pMem, u32 size); void CALLBACK GSgifSoftReset(u32 mask); void CALLBACK GSreadFIFO(off64_t *mem); void CALLBACK GSreadFIFO2(off64_t *mem, int qwc); - // extended funcs - // GSkeyEvent gets called when there is a keyEvent from the PAD plugin void CALLBACK GSkeyEvent(keyEvent *ev); void CALLBACK GSchangeSaveState(int, const char* filename); @@ -219,10 +198,8 @@ void CALLBACK GSirqCallback(void (*callback)()); void CALLBACK GSprintf(int timeout, char *fmt, ...); void CALLBACK GSsetBaseMem(void*); void CALLBACK GSsetGameCRC(int); - // controls frame skipping in the GS, if this routine isn't present, frame skipping won't be done void CALLBACK GSsetFrameSkip(int frameskip); - void CALLBACK GSreset(); void CALLBACK GSwriteCSR(u32 value); void CALLBACK GSgetDriverInfo(GSdriverInfo *info); @@ -233,17 +210,12 @@ s32 CALLBACK GSfreeze(int mode, freezeData *data); void CALLBACK GSconfigure(); void CALLBACK GSabout(); s32 CALLBACK GStest(); - #endif - /* PAD plugin API -=[ OBSOLETE ]=- */ - // if this file is included with this define // the next api will not be skipped by the compiler #ifdef PADdefs - // basic funcs - s32 CALLBACK PADinit(u32 flags); s32 CALLBACK PADopen(void *pDsp); void CALLBACK PADclose(); @@ -263,17 +235,12 @@ void CALLBACK PADgsDriverInfo(GSdriverInfo *info); void CALLBACK PADconfigure(); void CALLBACK PADabout(); s32 CALLBACK PADtest(); - #endif - /* SIO plugin API */ - // if this file is included with this define // the next api will not be skipped by the compiler #ifdef SIOdefs - // basic funcs - s32 CALLBACK SIOinit(u32 port, u32 slot, SIOchangeSlotCB f); s32 CALLBACK SIOopen(void *pDsp); void CALLBACK SIOclose(); @@ -282,23 +249,16 @@ u8 CALLBACK SIOstartPoll(u8 value); u8 CALLBACK SIOpoll(u8 value); // returns: SIO_TYPE_{PAD,MTAP,RM,MC} u32 CALLBACK SIOquery(); - // extended funcs - void CALLBACK SIOconfigure(); void CALLBACK SIOabout(); s32 CALLBACK SIOtest(); - #endif - /* SPU2 plugin API */ - // if this file is included with this define // the next api will not be skipped by the compiler #ifdef SPU2defs - // basic funcs - s32 CALLBACK SPU2init(); s32 CALLBACK SPU2open(void *pDsp); void CALLBACK SPU2close(); @@ -312,32 +272,25 @@ void CALLBACK SPU2readDMA7Mem(u16* pMem, int size); void CALLBACK SPU2writeDMA7Mem(u16 *pMem, int size); void CALLBACK SPU2interruptDMA7(); u32 CALLBACK SPU2ReadMemAddr(int core); -void CALLBACK SPU2WriteMemAddr(int core,u32 value); -void CALLBACK SPU2irqCallback(void (*SPU2callback)(),void (*DMA4callback)(),void (*DMA7callback)()); +void CALLBACK SPU2WriteMemAddr(int core, u32 value); +void CALLBACK SPU2irqCallback(void (*SPU2callback)(), void (*DMA4callback)(), void (*DMA7callback)()); // extended funcs - void CALLBACK SPU2async(u32 cycles); s32 CALLBACK SPU2freeze(int mode, freezeData *data); void CALLBACK SPU2configure(); void CALLBACK SPU2about(); s32 CALLBACK SPU2test(); - #endif - /* CDVD plugin API */ - // if this file is included with this define // the next api will not be skipped by the compiler #ifdef CDVDdefs - // basic funcs - s32 CALLBACK CDVDinit(); s32 CALLBACK CDVDopen(const char* pTitleFilename); void CALLBACK CDVDclose(); void CALLBACK CDVDshutdown(); s32 CALLBACK CDVDreadTrack(u32 lsn, int mode); - // return can be NULL (for async modes) u8* CALLBACK CDVDgetBuffer(); @@ -349,9 +302,7 @@ s32 CALLBACK CDVDgetDiskType(); //CDVD_TYPE_xxxx s32 CALLBACK CDVDgetTrayStatus(); //CDVD_TRAY_xxxx s32 CALLBACK CDVDctrlTrayOpen(); //open disc tray s32 CALLBACK CDVDctrlTrayClose(); //close disc tray - // extended funcs - void CALLBACK CDVDconfigure(); void CALLBACK CDVDabout(); s32 CALLBACK CDVDtest(); @@ -385,9 +336,7 @@ void CALLBACK DEV9writeDMA8Mem(u32 *pMem, int size); // if callback returns 1 the irq is triggered, else not void CALLBACK DEV9irqCallback(DEV9callback callback); DEV9handler CALLBACK DEV9irqHandler(void); - // extended funcs - s32 CALLBACK DEV9freeze(int mode, freezeData *data); void CALLBACK DEV9configure(); void CALLBACK DEV9about(); @@ -425,16 +374,12 @@ s32 CALLBACK USBfreeze(int mode, freezeData *data); void CALLBACK USBconfigure(); void CALLBACK USBabout(); s32 CALLBACK USBtest(); - #endif - /* FW plugin API */ - // if this file is included with this define // the next api will not be skipped by the compiler #ifdef FWdefs // basic funcs - // NOTE: The read/write functions CANNOT use XMM/MMX regs // If you want to use them, need to save and restore current ones s32 CALLBACK FWinit(); @@ -444,27 +389,22 @@ void CALLBACK FWshutdown(); u32 CALLBACK FWread32(u32 addr); void CALLBACK FWwrite32(u32 addr, u32 value); void CALLBACK FWirqCallback(void (*callback)()); - // extended funcs - s32 CALLBACK FWfreeze(int mode, freezeData *data); void CALLBACK FWconfigure(); void CALLBACK FWabout(); s32 CALLBACK FWtest(); #endif - // might be useful for emulators #ifdef PLUGINtypedefs - -typedef u32 (CALLBACK* _PS2EgetLibType)(void); -typedef u32 (CALLBACK* _PS2EgetLibVersion2)(u32 type); +typedef u32(CALLBACK* _PS2EgetLibType)(void); +typedef u32(CALLBACK* _PS2EgetLibVersion2)(u32 type); typedef char*(CALLBACK* _PS2EgetLibName)(void); - // GS // NOTE: GSreadFIFOX/GSwriteCSR functions CANNOT use XMM/MMX regs // If you want to use them, need to save and restore current ones -typedef s32 (CALLBACK* _GSinit)(); -typedef s32 (CALLBACK* _GSopen)(void *pDsp, char *Title, int multithread); +typedef s32(CALLBACK* _GSinit)(); +typedef s32(CALLBACK* _GSopen)(void *pDsp, char *Title, int multithread); typedef void (CALLBACK* _GSclose)(); typedef void (CALLBACK* _GSshutdown)(); typedef void (CALLBACK* _GSvsync)(int field); @@ -474,7 +414,6 @@ typedef void (CALLBACK* _GSgifTransfer3)(u32 *pMem, u32 size); typedef void (CALLBACK* _GSgifSoftReset)(u32 mask); typedef void (CALLBACK* _GSreadFIFO)(off64_t *pMem); typedef void (CALLBACK* _GSreadFIFO2)(off64_t *pMem, int qwc); - typedef void (CALLBACK* _GSkeyEvent)(keyEvent* ev); typedef void (CALLBACK* _GSchangeSaveState)(int, const char* filename); typedef void (CALLBACK* _GSirqCallback)(void (*callback)()); @@ -486,147 +425,139 @@ typedef void (CALLBACK* _GSreset)(); typedef void (CALLBACK* _GSwriteCSR)(u32 value); typedef void (CALLBACK* _GSgetDriverInfo)(GSdriverInfo *info); #ifdef _WIN32 -typedef s32 (CALLBACK* _GSsetWindowInfo)(winInfo *info); +typedef s32(CALLBACK* _GSsetWindowInfo)(winInfo *info); #endif typedef void (CALLBACK* _GSmakeSnapshot)(char *path); typedef void (CALLBACK* _GSmakeSnapshot2)(char *path, int*, int); -typedef s32 (CALLBACK* _GSfreeze)(int mode, freezeData *data); +typedef s32(CALLBACK* _GSfreeze)(int mode, freezeData *data); typedef void (CALLBACK* _GSconfigure)(); -typedef s32 (CALLBACK* _GStest)(); +typedef s32(CALLBACK* _GStest)(); typedef void (CALLBACK* _GSabout)(); - // PAD -typedef s32 (CALLBACK* _PADinit)(u32 flags); -typedef s32 (CALLBACK* _PADopen)(void *pDsp); +typedef s32(CALLBACK* _PADinit)(u32 flags); +typedef s32(CALLBACK* _PADopen)(void *pDsp); typedef void (CALLBACK* _PADclose)(); typedef void (CALLBACK* _PADshutdown)(); -typedef keyEvent* (CALLBACK* _PADkeyEvent)(); -typedef u8 (CALLBACK* _PADstartPoll)(int pad); -typedef u8 (CALLBACK* _PADpoll)(u8 value); -typedef u32 (CALLBACK* _PADquery)(); - +typedef keyEvent*(CALLBACK* _PADkeyEvent)(); +typedef u8(CALLBACK* _PADstartPoll)(int pad); +typedef u8(CALLBACK* _PADpoll)(u8 value); +typedef u32(CALLBACK* _PADquery)(); typedef void (CALLBACK* _PADgsDriverInfo)(GSdriverInfo *info); typedef void (CALLBACK* _PADconfigure)(); -typedef s32 (CALLBACK* _PADtest)(); +typedef s32(CALLBACK* _PADtest)(); typedef void (CALLBACK* _PADabout)(); - // SIO -typedef s32 (CALLBACK* _SIOinit)(u32 port, u32 slot, SIOchangeSlotCB f); -typedef s32 (CALLBACK* _SIOopen)(void *pDsp); +typedef s32(CALLBACK* _SIOinit)(u32 port, u32 slot, SIOchangeSlotCB f); +typedef s32(CALLBACK* _SIOopen)(void *pDsp); typedef void (CALLBACK* _SIOclose)(); typedef void (CALLBACK* _SIOshutdown)(); -typedef u8 (CALLBACK* _SIOstartPoll)(u8 value); -typedef u8 (CALLBACK* _SIOpoll)(u8 value); -typedef u32 (CALLBACK* _SIOquery)(); +typedef u8(CALLBACK* _SIOstartPoll)(u8 value); +typedef u8(CALLBACK* _SIOpoll)(u8 value); +typedef u32(CALLBACK* _SIOquery)(); typedef void (CALLBACK* _SIOconfigure)(); -typedef s32 (CALLBACK* _SIOtest)(); +typedef s32(CALLBACK* _SIOtest)(); typedef void (CALLBACK* _SIOabout)(); // SPU2 // NOTE: The read/write functions CANNOT use XMM/MMX regs // If you want to use them, need to save and restore current ones -typedef s32 (CALLBACK* _SPU2init)(); -typedef s32 (CALLBACK* _SPU2open)(void *pDsp); +typedef s32(CALLBACK* _SPU2init)(); +typedef s32(CALLBACK* _SPU2open)(void *pDsp); typedef void (CALLBACK* _SPU2close)(); typedef void (CALLBACK* _SPU2shutdown)(); typedef void (CALLBACK* _SPU2write)(u32 mem, u16 value); -typedef u16 (CALLBACK* _SPU2read)(u32 mem); +typedef u16(CALLBACK* _SPU2read)(u32 mem); typedef void (CALLBACK* _SPU2readDMA4Mem)(u16 *pMem, int size); typedef void (CALLBACK* _SPU2writeDMA4Mem)(u16 *pMem, int size); typedef void (CALLBACK* _SPU2interruptDMA4)(); typedef void (CALLBACK* _SPU2readDMA7Mem)(u16 *pMem, int size); typedef void (CALLBACK* _SPU2writeDMA7Mem)(u16 *pMem, int size); typedef void (CALLBACK* _SPU2interruptDMA7)(); -typedef void (CALLBACK* _SPU2irqCallback)(void (*SPU2callback)(),void (*DMA4callback)(),void (*DMA7callback)()); -typedef u32 (CALLBACK* _SPU2ReadMemAddr)(int core); -typedef void (CALLBACK* _SPU2WriteMemAddr)(int core,u32 value); +typedef void (CALLBACK* _SPU2irqCallback)(void (*SPU2callback)(), void (*DMA4callback)(), void (*DMA7callback)()); +typedef u32(CALLBACK* _SPU2ReadMemAddr)(int core); +typedef void (CALLBACK* _SPU2WriteMemAddr)(int core, u32 value); typedef void (CALLBACK* _SPU2async)(u32 cycles); -typedef s32 (CALLBACK* _SPU2freeze)(int mode, freezeData *data); +typedef s32(CALLBACK* _SPU2freeze)(int mode, freezeData *data); typedef void (CALLBACK* _SPU2configure)(); -typedef s32 (CALLBACK* _SPU2test)(); +typedef s32(CALLBACK* _SPU2test)(); typedef void (CALLBACK* _SPU2about)(); // CDVD // NOTE: The read/write functions CANNOT use XMM/MMX regs // If you want to use them, need to save and restore current ones -typedef s32 (CALLBACK* _CDVDinit)(); -typedef s32 (CALLBACK* _CDVDopen)(const char* pTitleFilename); +typedef s32(CALLBACK* _CDVDinit)(); +typedef s32(CALLBACK* _CDVDopen)(const char* pTitleFilename); typedef void (CALLBACK* _CDVDclose)(); typedef void (CALLBACK* _CDVDshutdown)(); -typedef s32 (CALLBACK* _CDVDreadTrack)(u32 lsn, int mode); -typedef u8* (CALLBACK* _CDVDgetBuffer)(); -typedef s32 (CALLBACK* _CDVDreadSubQ)(u32 lsn, cdvdSubQ* subq); -typedef s32 (CALLBACK* _CDVDgetTN)(cdvdTN *Buffer); -typedef s32 (CALLBACK* _CDVDgetTD)(u8 Track, cdvdTD *Buffer); -typedef s32 (CALLBACK* _CDVDgetTOC)(void* toc); -typedef s32 (CALLBACK* _CDVDgetDiskType)(); -typedef s32 (CALLBACK* _CDVDgetTrayStatus)(); -typedef s32 (CALLBACK* _CDVDctrlTrayOpen)(); -typedef s32 (CALLBACK* _CDVDctrlTrayClose)(); +typedef s32(CALLBACK* _CDVDreadTrack)(u32 lsn, int mode); +typedef u8*(CALLBACK* _CDVDgetBuffer)(); +typedef s32(CALLBACK* _CDVDreadSubQ)(u32 lsn, cdvdSubQ* subq); +typedef s32(CALLBACK* _CDVDgetTN)(cdvdTN *Buffer); +typedef s32(CALLBACK* _CDVDgetTD)(u8 Track, cdvdTD *Buffer); +typedef s32(CALLBACK* _CDVDgetTOC)(void* toc); +typedef s32(CALLBACK* _CDVDgetDiskType)(); +typedef s32(CALLBACK* _CDVDgetTrayStatus)(); +typedef s32(CALLBACK* _CDVDctrlTrayOpen)(); +typedef s32(CALLBACK* _CDVDctrlTrayClose)(); typedef void (CALLBACK* _CDVDconfigure)(); -typedef s32 (CALLBACK* _CDVDtest)(); +typedef s32(CALLBACK* _CDVDtest)(); typedef void (CALLBACK* _CDVDabout)(); typedef void (CALLBACK* _CDVDnewDiskCB)(void (*callback)()); - // DEV9 // NOTE: The read/write functions CANNOT use XMM/MMX regs // If you want to use them, need to save and restore current ones -typedef s32 (CALLBACK* _DEV9init)(); -typedef s32 (CALLBACK* _DEV9open)(void *pDsp); +typedef s32(CALLBACK* _DEV9init)(); +typedef s32(CALLBACK* _DEV9open)(void *pDsp); typedef void (CALLBACK* _DEV9close)(); typedef void (CALLBACK* _DEV9shutdown)(); -typedef u8 (CALLBACK* _DEV9read8)(u32 mem); -typedef u16 (CALLBACK* _DEV9read16)(u32 mem); -typedef u32 (CALLBACK* _DEV9read32)(u32 mem); +typedef u8(CALLBACK* _DEV9read8)(u32 mem); +typedef u16(CALLBACK* _DEV9read16)(u32 mem); +typedef u32(CALLBACK* _DEV9read32)(u32 mem); typedef void (CALLBACK* _DEV9write8)(u32 mem, u8 value); typedef void (CALLBACK* _DEV9write16)(u32 mem, u16 value); typedef void (CALLBACK* _DEV9write32)(u32 mem, u32 value); typedef void (CALLBACK* _DEV9readDMA8Mem)(u32 *pMem, int size); typedef void (CALLBACK* _DEV9writeDMA8Mem)(u32 *pMem, int size); typedef void (CALLBACK* _DEV9irqCallback)(DEV9callback callback); -typedef DEV9handler (CALLBACK* _DEV9irqHandler)(void); - -typedef s32 (CALLBACK* _DEV9freeze)(int mode, freezeData *data); +typedef DEV9handler(CALLBACK* _DEV9irqHandler)(void); +typedef s32(CALLBACK* _DEV9freeze)(int mode, freezeData *data); typedef void (CALLBACK* _DEV9configure)(); -typedef s32 (CALLBACK* _DEV9test)(); +typedef s32(CALLBACK* _DEV9test)(); typedef void (CALLBACK* _DEV9about)(); // USB // NOTE: The read/write functions CANNOT use XMM/MMX regs // If you want to use them, need to save and restore current ones -typedef s32 (CALLBACK* _USBinit)(); -typedef s32 (CALLBACK* _USBopen)(void *pDsp); +typedef s32(CALLBACK* _USBinit)(); +typedef s32(CALLBACK* _USBopen)(void *pDsp); typedef void (CALLBACK* _USBclose)(); typedef void (CALLBACK* _USBshutdown)(); -typedef u8 (CALLBACK* _USBread8)(u32 mem); -typedef u16 (CALLBACK* _USBread16)(u32 mem); -typedef u32 (CALLBACK* _USBread32)(u32 mem); +typedef u8(CALLBACK* _USBread8)(u32 mem); +typedef u16(CALLBACK* _USBread16)(u32 mem); +typedef u32(CALLBACK* _USBread32)(u32 mem); typedef void (CALLBACK* _USBwrite8)(u32 mem, u8 value); typedef void (CALLBACK* _USBwrite16)(u32 mem, u16 value); typedef void (CALLBACK* _USBwrite32)(u32 mem, u32 value); typedef void (CALLBACK* _USBirqCallback)(USBcallback callback); -typedef USBhandler (CALLBACK* _USBirqHandler)(void); +typedef USBhandler(CALLBACK* _USBirqHandler)(void); typedef void (CALLBACK* _USBsetRAM)(void *mem); - -typedef s32 (CALLBACK* _USBfreeze)(int mode, freezeData *data); +typedef s32(CALLBACK* _USBfreeze)(int mode, freezeData *data); typedef void (CALLBACK* _USBconfigure)(); -typedef s32 (CALLBACK* _USBtest)(); +typedef s32(CALLBACK* _USBtest)(); typedef void (CALLBACK* _USBabout)(); - //FW -typedef s32 (CALLBACK* _FWinit)(); -typedef s32 (CALLBACK* _FWopen)(void *pDsp); +typedef s32(CALLBACK* _FWinit)(); +typedef s32(CALLBACK* _FWopen)(void *pDsp); typedef void (CALLBACK* _FWclose)(); typedef void (CALLBACK* _FWshutdown)(); -typedef u32 (CALLBACK* _FWread32)(u32 mem); +typedef u32(CALLBACK* _FWread32)(u32 mem); typedef void (CALLBACK* _FWwrite32)(u32 mem, u32 value); typedef void (CALLBACK* _FWirqCallback)(void (*callback)()); - -typedef s32 (CALLBACK* _FWfreeze)(int mode, freezeData *data); +typedef s32(CALLBACK* _FWfreeze)(int mode, freezeData *data); typedef void (CALLBACK* _FWconfigure)(); -typedef s32 (CALLBACK* _FWtest)(); +typedef s32(CALLBACK* _FWtest)(); typedef void (CALLBACK* _FWabout)(); #endif @@ -645,7 +576,6 @@ _GSgifTransfer3 GSgifTransfer3; _GSgifSoftReset GSgifSoftReset; _GSreadFIFO GSreadFIFO; _GSreadFIFO2 GSreadFIFO2; - _GSkeyEvent GSkeyEvent; _GSchangeSaveState GSchangeSaveState; _GSmakeSnapshot GSmakeSnapshot; @@ -665,7 +595,6 @@ _GSfreeze GSfreeze; _GSconfigure GSconfigure; _GStest GStest; _GSabout GSabout; - // PAD1 _PADinit PAD1init; _PADopen PAD1open; @@ -675,12 +604,10 @@ _PADkeyEvent PAD1keyEvent; _PADstartPoll PAD1startPoll; _PADpoll PAD1poll; _PADquery PAD1query; - _PADgsDriverInfo PAD1gsDriverInfo; _PADconfigure PAD1configure; _PADtest PAD1test; _PADabout PAD1about; - // PAD2 _PADinit PAD2init; _PADopen PAD2open; @@ -690,12 +617,10 @@ _PADkeyEvent PAD2keyEvent; _PADstartPoll PAD2startPoll; _PADpoll PAD2poll; _PADquery PAD2query; - _PADgsDriverInfo PAD2gsDriverInfo; _PADconfigure PAD2configure; _PADtest PAD2test; _PADabout PAD2about; - // SIO[2] _SIOinit SIOinit[2][9]; _SIOopen SIOopen[2][9]; @@ -725,13 +650,11 @@ _SPU2interruptDMA7 SPU2interruptDMA7; _SPU2ReadMemAddr SPU2ReadMemAddr; _SPU2WriteMemAddr SPU2WriteMemAddr; _SPU2irqCallback SPU2irqCallback; - _SPU2async SPU2async; _SPU2freeze SPU2freeze; _SPU2configure SPU2configure; _SPU2test SPU2test; _SPU2about SPU2about; - // CDVD _CDVDinit CDVDinit; _CDVDopen CDVDopen; @@ -747,12 +670,10 @@ _CDVDgetDiskType CDVDgetDiskType; _CDVDgetTrayStatus CDVDgetTrayStatus; _CDVDctrlTrayOpen CDVDctrlTrayOpen; _CDVDctrlTrayClose CDVDctrlTrayClose; - _CDVDconfigure CDVDconfigure; _CDVDtest CDVDtest; _CDVDabout CDVDabout; _CDVDnewDiskCB CDVDnewDiskCB; - // DEV9 _DEV9init DEV9init; _DEV9open DEV9open; @@ -768,12 +689,10 @@ _DEV9readDMA8Mem DEV9readDMA8Mem; _DEV9writeDMA8Mem DEV9writeDMA8Mem; _DEV9irqCallback DEV9irqCallback; _DEV9irqHandler DEV9irqHandler; - _DEV9configure DEV9configure; _DEV9freeze DEV9freeze; _DEV9test DEV9test; _DEV9about DEV9about; - // USB _USBinit USBinit; _USBopen USBopen; @@ -793,7 +712,6 @@ _USBconfigure USBconfigure; _USBfreeze USBfreeze; _USBtest USBtest; _USBabout USBabout; - // FW _FWinit FWinit; _FWopen FWopen; @@ -802,11 +720,9 @@ _FWshutdown FWshutdown; _FWread32 FWread32; _FWwrite32 FWwrite32; _FWirqCallback FWirqCallback; - _FWconfigure FWconfigure; _FWfreeze FWfreeze; _FWtest FWtest; _FWabout FWabout; #endif - #endif /* __PS2EDEFS_H__ */ diff --git a/plugins/CDVDisoEFP/src/PS2Etypes.h b/plugins/CDVDisoEFP/src/PS2Etypes.h index 04ad5599a0..f38b475205 100644 --- a/plugins/CDVDisoEFP/src/PS2Etypes.h +++ b/plugins/CDVDisoEFP/src/PS2Etypes.h @@ -11,65 +11,52 @@ // Basic types #if defined(_MSC_VER) - typedef __int8 s8; typedef __int16 s16; typedef __int32 s32; typedef __int64 s64; - typedef unsigned __int8 u8; typedef unsigned __int16 u16; typedef unsigned __int32 u32; typedef unsigned __int64 u64; - #if defined(__x86_64__) typedef u64 uptr; #else typedef u32 uptr; #endif - #define PCSX2_ALIGNED16(x) __declspec(align(16)) x - #else - typedef char s8; typedef short s16; typedef int s32; typedef long long s64; - typedef unsigned char u8; typedef unsigned short u16; typedef unsigned int u32; typedef unsigned long long u64; - #if defined(__x86_64__) typedef u64 uptr; #else typedef u32 uptr; #endif - #ifdef __LINUX__ typedef union _LARGE_INTEGER { long long QuadPart; } LARGE_INTEGER; #endif - #if defined(__MINGW32__) #define PCSX2_ALIGNED16(x) __declspec(align(16)) x #else #define PCSX2_ALIGNED16(x) x __attribute((aligned(16))) #endif - #ifndef __forceinline #define __forceinline inline #endif - #endif - -typedef struct { +typedef struct +{ int size; s8 *data; } freezeData; - #endif /* __PS2ETYPES_H__ */ diff --git a/plugins/CDVDisoEFP/src/Win32/CD.c b/plugins/CDVDisoEFP/src/Win32/CD.c index 593e348468..9245d58f79 100644 --- a/plugins/CDVDisoEFP/src/Win32/CD.c +++ b/plugins/CDVDisoEFP/src/Win32/CD.c @@ -1,774 +1,393 @@ /* CD.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include - #include // IOCTL_CDROM... - - - #include // off64_t - - - #define CDVDdefs - #include "PS2Edefs.h" - - #include "logfile.h" - #include "../convert.h" // MSFtoLBA(), HEXTOBCD() - #include "actualfile.h" - #include "device.h" // tocbuffer[], FinishCommand() - #include "CD.h" - - - - int actualcdmode; // -1=ReadFile, 0=YellowMode2, 1=XAForm2, 2=CDDA - DWORD cdblocksize; // 2048 to 2352 - int cdoffset; // 0, 8, 16, or 24 - int cdmode; - - - - -void InitCDInfo() { - - actualcdmode = -1; - - cdblocksize = 2048; - - cdmode = -1; - +void InitCDInfo() +{ + actualcdmode = -1; + cdblocksize = 2048; + cdmode = -1; } // END InitCDInfo() +s32 CDreadTrackPass(u32 lsn, int mode, u8 *buffer) +{ + RAW_READ_INFO rawinfo; + BOOL boolresult; + DWORD byteswritten; + DWORD errcode; + LARGE_INTEGER targetpos; + int i; - - - -s32 CDreadTrackPass(u32 lsn, int mode, u8 *buffer) { - - RAW_READ_INFO rawinfo; - - BOOL boolresult; - - DWORD byteswritten; - - DWORD errcode; - - LARGE_INTEGER targetpos; - - int i; - - - - if((actualcdmode < -1) || (actualcdmode > 2)) return(-1); - - + if ((actualcdmode < -1) || (actualcdmode > 2)) return(-1); #ifdef VERBOSE_FUNCTION_DEVICE - - PrintLog("CDVD CD: CDreadTrack(%llu, %i)", lsn, actualcdmode); - + PrintLog("CDVD CD: CDreadTrack(%llu, %i)", lsn, actualcdmode); #endif /* VERBOSE_FUNCTION_DEVICE */ + if (actualcdmode >= 0) + { + rawinfo.DiskOffset.QuadPart = lsn * 2048; // Yes, 2048. + rawinfo.SectorCount = 1; + rawinfo.TrackMode = actualcdmode; + boolresult = DeviceIoControl(devicehandle, + IOCTL_CDROM_RAW_READ, + &rawinfo, + sizeof(RAW_READ_INFO), + buffer, + 2352, + &byteswritten, + &waitevent); + errcode = FinishCommand(boolresult); - - if(actualcdmode >= 0) { - - rawinfo.DiskOffset.QuadPart = lsn * 2048; // Yes, 2048. - - rawinfo.SectorCount = 1; - - rawinfo.TrackMode = actualcdmode; - - boolresult = DeviceIoControl(devicehandle, - - IOCTL_CDROM_RAW_READ, - - &rawinfo, - - sizeof(RAW_READ_INFO), - - buffer, - - 2352, - - &byteswritten, - - &waitevent); - - errcode = FinishCommand(boolresult); - - - - if(errcode != 0) { - + if (errcode != 0) + { #ifdef VERBOSE_WARNING_DEVICE - - PrintLog("CDVDiso CD: Couldn't read a sector raw!"); - - PrintError("CDVDiso CD", errcode); - + PrintLog("CDVDiso CD: Couldn't read a sector raw!"); + PrintError("CDVDiso CD", errcode); #endif /* VERBOSE_WARNING_DEVICE */ + return(-1); + } // ENDIF- Couldn't read a raw sector? Maybe not a CD. - return(-1); - - } // ENDIF- Couldn't read a raw sector? Maybe not a CD. - - - - } else { - - targetpos.QuadPart = lsn * 2048; - - waitevent.Offset = targetpos.LowPart; - - waitevent.OffsetHigh = targetpos.HighPart; - - - - boolresult = ReadFile(devicehandle, - - buffer + 24, - - 2048, - - &byteswritten, - - &waitevent); - - errcode = FinishCommand(boolresult); - - - - if(errcode != 0) { + } + else + { + targetpos.QuadPart = lsn * 2048; + waitevent.Offset = targetpos.LowPart; + waitevent.OffsetHigh = targetpos.HighPart; + boolresult = ReadFile(devicehandle, + buffer + 24, + 2048, + &byteswritten, + &waitevent); + errcode = FinishCommand(boolresult); + if (errcode != 0) + { #ifdef VERBOSE_WARNING_DEVICE - - PrintLog("CDVDiso CD: Couldn't read a cooked sector!"); - - PrintError("CDVDiso CD", errcode); - + PrintLog("CDVDiso CD: Couldn't read a cooked sector!"); + PrintError("CDVDiso CD", errcode); #endif /* VERBOSE_WARNING_DEVICE */ + return(-1); + } // ENDIF- Trouble with seek? Report it. - return(-1); + for (i = 0; i < 24; i++) *(buffer + i) = 0; + for (i = 24 + 2048; i < 2352; i++) *(buffer + i) = 0; + } // ENDIF- Could we read a raw sector? Read another one! - } // ENDIF- Trouble with seek? Report it. - - - - for(i = 0; i < 24; i++) *(buffer + i) = 0; - - for(i = 24 + 2048; i < 2352; i++) *(buffer + i) = 0; - - } // ENDIF- Could we read a raw sector? Read another one! - - - - if(boolresult == FALSE) { - - boolresult = GetOverlappedResult(devicehandle, - - &waitevent, - - &byteswritten, - - FALSE); - - } // ENDIF- Did the initial call not complete? Get byteswritten for - - // the completed call. - - - - if(byteswritten < 2048) { + if (boolresult == FALSE) + { + boolresult = GetOverlappedResult(devicehandle, + &waitevent, + &byteswritten, + FALSE); + } // ENDIF- Did the initial call not complete? Get byteswritten for + // the completed call. + if (byteswritten < 2048) + { #ifdef VERBOSE_WARNING_DEVICE - - errcode = GetLastError(); - - PrintLog("CDVDiso CD: Short block! only got %u out of %u bytes", - - byteswritten, cdblocksize); - - PrintError("CDVDiso CD", errcode); - + errcode = GetLastError(); + PrintLog("CDVDiso CD: Short block! only got %u out of %u bytes", + byteswritten, cdblocksize); + PrintError("CDVDiso CD", errcode); #endif /* VERBOSE_WARNING_DEVICE */ + return(-1); + } // ENDIF- Couldn't read a raw sector? Maybe not a CD. - return(-1); - - } // ENDIF- Couldn't read a raw sector? Maybe not a CD. - - - - cdmode = mode; - - cdblocksize = byteswritten; - - return(0); - + cdmode = mode; + cdblocksize = byteswritten; + return(0); } // END CDreadTrackPass() - - - - -s32 CDreadTrack(u32 lsn, int mode, u8 *buffer) { - - int retval; - - int lastmode; - - int i; - - - - retval = CDreadTrackPass(lsn, mode, buffer); - - if(retval >= 0) return(retval); - - +s32 CDreadTrack(u32 lsn, int mode, u8 *buffer) +{ + int retval; + int lastmode; + int i; + retval = CDreadTrackPass(lsn, mode, buffer); + if (retval >= 0) return(retval); #ifdef VERBOSE_WARNING_DEVICE - - PrintLog("CDVDiso CD: Same mode doesn't work. Scanning..."); - + PrintLog("CDVDiso CD: Same mode doesn't work. Scanning..."); #endif /* VERBOSE_WARNING_DEVICE */ - - - lastmode = actualcdmode; - - actualcdmode = 2; - - while(actualcdmode >= -1) { - - retval = CDreadTrackPass(lsn, mode, buffer); - - if(retval >= 0) return(retval); - - actualcdmode--; - - } // ENDWHILE- Searching each mode for a way to read the sector - - actualcdmode = lastmode; // None worked? Go back to first mode. - - - + lastmode = actualcdmode; + actualcdmode = 2; + while (actualcdmode >= -1) + { + retval = CDreadTrackPass(lsn, mode, buffer); + if (retval >= 0) return(retval); + actualcdmode--; + } // ENDWHILE- Searching each mode for a way to read the sector + actualcdmode = lastmode; // None worked? Go back to first mode. #ifdef VERBOSE_WARNING_DEVICE - - PrintLog("CDVDiso CD: No modes work. Failing sector!"); - + PrintLog("CDVDiso CD: No modes work. Failing sector!"); #endif /* VERBOSE_WARNING_DEVICE */ - - - - for(i = 0; i < 2352; i++) *(buffer + i) = 0; - - return(-1); - + for (i = 0; i < 2352; i++) *(buffer + i) = 0; + return(-1); } // END CDreadTrack() - - - - -s32 CDgetBufferOffset() { - +s32 CDgetBufferOffset() +{ #ifdef VERBOSE_FUNCTION_DEVICE - - PrintLog("CDVD CD: CDgetBufferOffset()"); - + PrintLog("CDVD CD: CDgetBufferOffset()"); #endif /* VERBOSE_FUNCTION_DEVICE */ + // Send a whole CDDA record in? + if ((actualcdmode == CDDA) && (cdmode == CDVD_MODE_2352)) return(0); - - - // Send a whole CDDA record in? - - if((actualcdmode == CDDA) && (cdmode == CDVD_MODE_2352)) return(0); - - - - // Otherwise, send the start of the data block in... - - return(cdoffset); - + // Otherwise, send the start of the data block in... + return(cdoffset); } // END CDgetBufferOffset() - - - - -s32 CDreadSubQ() { - - return(-1); - +s32 CDreadSubQ() +{ + return(-1); } // END CDreadSubQ() - - - - -s32 CDgetTN(cdvdTN *cdvdtn) { - - cdvdtn->strack = BCDTOHEX(tocbuffer[7]); - - cdvdtn->etrack = BCDTOHEX(tocbuffer[17]); - - return(0); - +s32 CDgetTN(cdvdTN *cdvdtn) +{ + cdvdtn->strack = BCDTOHEX(tocbuffer[7]); + cdvdtn->etrack = BCDTOHEX(tocbuffer[17]); + return(0); } // END CDgetTN() - - - - -s32 CDgetTD(u8 newtrack, cdvdTD *cdvdtd) { - - u8 actualtrack; - - int pos; - - char temptime[3]; - - +s32 CDgetTD(u8 newtrack, cdvdTD *cdvdtd) +{ + u8 actualtrack; + int pos; + char temptime[3]; #ifdef VERBOSE_FUNCTION_DEVICE - - PrintLog("CDVDiso CD: CDgetTD()"); - + PrintLog("CDVDiso CD: CDgetTD()"); #endif /* VERBOSE_FUNCTION_DEVICE */ - - - actualtrack = newtrack; - - if(actualtrack == 0xaa) actualtrack = 0; - - - - if(actualtrack == 0) { - - cdvdtd->type = 0; - - temptime[0] = BCDTOHEX(tocbuffer[27]); - - temptime[1] = BCDTOHEX(tocbuffer[28]); - - temptime[2] = BCDTOHEX(tocbuffer[29]); - - cdvdtd->lsn = MSFtoLBA(temptime); - - } else { - - pos = actualtrack * 10; - - pos += 30; - - cdvdtd->type = tocbuffer[pos]; - - temptime[0] = BCDTOHEX(tocbuffer[pos + 7]); - - temptime[1] = BCDTOHEX(tocbuffer[pos + 8]); - - temptime[2] = BCDTOHEX(tocbuffer[pos + 9]); - - cdvdtd->lsn = MSFtoLBA(temptime); - - } // ENDIF- Whole disc? (or single track?) - - - - return(0); - + actualtrack = newtrack; + if (actualtrack == 0xaa) actualtrack = 0; + if (actualtrack == 0) + { + cdvdtd->type = 0; + temptime[0] = BCDTOHEX(tocbuffer[27]); + temptime[1] = BCDTOHEX(tocbuffer[28]); + temptime[2] = BCDTOHEX(tocbuffer[29]); + cdvdtd->lsn = MSFtoLBA(temptime); + } + else + { + pos = actualtrack * 10; + pos += 30; + cdvdtd->type = tocbuffer[pos]; + temptime[0] = BCDTOHEX(tocbuffer[pos + 7]); + temptime[1] = BCDTOHEX(tocbuffer[pos + 8]); + temptime[2] = BCDTOHEX(tocbuffer[pos + 9]); + cdvdtd->lsn = MSFtoLBA(temptime); + } // ENDIF- Whole disc? (or single track?) + return(0); } // END CDgetTD() - - - - -s32 CDgetDiskType() { - - CDROM_TOC cdinfo; - - BOOL boolresult; - - int retval; - - DWORD byteswritten; - - DWORD errcode; - - u8 iso9660name[] = "CD001\0"; - - u8 playstationname[] = "PLAYSTATION\0"; - - u8 ps1name[] = "CD-XA001\0"; - - u8 tempbuffer[2448]; - - int tempdisctype; - - int i; - - int pos; - - unsigned long volumesize; - - +s32 CDgetDiskType() +{ + CDROM_TOC cdinfo; + BOOL boolresult; + int retval; + DWORD byteswritten; + DWORD errcode; + u8 iso9660name[] = "CD001\0"; + u8 playstationname[] = "PLAYSTATION\0"; + u8 ps1name[] = "CD-XA001\0"; + u8 tempbuffer[2448]; + int tempdisctype; + int i; + int pos; + unsigned long volumesize; #ifdef VERBOSE_FUNCTION_DEVICE - - PrintLog("CDVDiso CD: CDgetDiskType()"); - + PrintLog("CDVDiso CD: CDgetDiskType()"); #endif /* VERBOSE_FUNCTION_DEVICE */ + tempdisctype = CDVD_TYPE_UNKNOWN; + actualcdmode = 2; + retval = CDreadTrack(16, CDVD_MODE_2048, tempbuffer); + if (retval < 0) + { + disctype = tempdisctype; + return(-1); + } // ENDIF- Couldn't read the directory sector? Abort. + disctype = CDVD_TYPE_DETCTCD; + tempdisctype = CDVD_TYPE_CDDA; - tempdisctype = CDVD_TYPE_UNKNOWN; - - - - actualcdmode = 2; - - retval = CDreadTrack(16, CDVD_MODE_2048, tempbuffer); - - if(retval < 0) { - - disctype = tempdisctype; - - return(-1); - - } // ENDIF- Couldn't read the directory sector? Abort. - - - - disctype = CDVD_TYPE_DETCTCD; - - tempdisctype = CDVD_TYPE_CDDA; - - - - cdoffset = 0; - - i = 0; - - while((cdoffset <= 24) && (iso9660name[i] != 0)) { - - i = 0; - - while((iso9660name[i] != 0) && - - (iso9660name[i] == tempbuffer[cdoffset + 1 + i])) i++; - - if(iso9660name[i] != 0) cdoffset += 8; - - } // ENDWHILE- Trying to find a working offset for a ISO9660 record. - - - - if(iso9660name[i] != 0) { - + cdoffset = 0; + i = 0; + while ((cdoffset <= 24) && (iso9660name[i] != 0)) + { + i = 0; + while ((iso9660name[i] != 0) && + (iso9660name[i] == tempbuffer[cdoffset + 1 + i])) i++; + if (iso9660name[i] != 0) cdoffset += 8; + } // ENDWHILE- Trying to find a working offset for a ISO9660 record. + if (iso9660name[i] != 0) + { #ifdef VERBOSE_DISC_TYPE - - PrintLog("Detected a CDDA (Music CD)."); - + PrintLog("Detected a CDDA (Music CD)."); #endif /* VERBOSE_DISC_TYPE */ + tempdisctype = CDVD_TYPE_CDDA; + tocbuffer[0] = 0x01; - tempdisctype = CDVD_TYPE_CDDA; - - tocbuffer[0] = 0x01; - - - - } else { - - tocbuffer[0] = 0x41; - - i = 0; - - while((playstationname[i] != 0) && - - (playstationname[i] == tempbuffer[cdoffset + 8 + i])) i++; - - if(playstationname[i] != 0) { - + } + else + { + tocbuffer[0] = 0x41; + i = 0; + while ((playstationname[i] != 0) && + (playstationname[i] == tempbuffer[cdoffset + 8 + i])) i++; + if (playstationname[i] != 0) + { #ifdef VERBOSE_DISC_TYPE - - PrintLog("Detected a non-Playstation CD."); - + PrintLog("Detected a non-Playstation CD."); #endif /* VERBOSE_DISC_TYPE */ - - tempdisctype = CDVD_TYPE_UNKNOWN; - - - - } else { - - i = 0; - - while((ps1name[i] != 0) && - - (ps1name[i] == tempbuffer[cdoffset + 1024 + i])) i++; - - if(ps1name[i] != 0) { - + tempdisctype = CDVD_TYPE_UNKNOWN; + } + else + { + i = 0; + while ((ps1name[i] != 0) && + (ps1name[i] == tempbuffer[cdoffset + 1024 + i])) i++; + if (ps1name[i] != 0) + { #ifdef VERBOSE_DISC_TYPE - - PrintLog("Detected a Playstation 2 CD."); - + PrintLog("Detected a Playstation 2 CD."); #endif /* VERBOSE_DISC_TYPE */ - - tempdisctype = CDVD_TYPE_PS2CD; - - } else { - + tempdisctype = CDVD_TYPE_PS2CD; + } + else + { #ifdef VERBOSE_DISC_TYPE - - PrintLog("Detected a Playstation CD."); - + PrintLog("Detected a Playstation CD."); #endif /* VERBOSE_DISC_TYPE */ - - tempdisctype = CDVD_TYPE_PSCD; - - } // ENDIF- Is this not a PlayStation Disc? - - } // ENDIF- Is this not a PlayStation Disc? - - } // ENDIF- Is this not an ISO9660 CD? (a CDDA, in other words?) - - - - // Build the Fake TOC - - tocbuffer[2] = 0xA0; - - tocbuffer[7] = HEXTOBCD(1); // Starting Track - - tocbuffer[12] = 0xA1; - - tocbuffer[17] = HEXTOBCD(1); // Ending Track - - - - volumesize = tempbuffer[84]; // Volume size (big endian) - - volumesize *= 256; - - volumesize += tempbuffer[85]; - - volumesize *= 256; - - volumesize += tempbuffer[86]; - - volumesize *= 256; - - volumesize += tempbuffer[87]; - + tempdisctype = CDVD_TYPE_PSCD; + } // ENDIF- Is this not a PlayStation Disc? + } // ENDIF- Is this not a PlayStation Disc? + } // ENDIF- Is this not an ISO9660 CD? (a CDDA, in other words?) + // Build the Fake TOC + tocbuffer[2] = 0xA0; + tocbuffer[7] = HEXTOBCD(1); // Starting Track + tocbuffer[12] = 0xA1; + tocbuffer[17] = HEXTOBCD(1); // Ending Track + volumesize = tempbuffer[84]; // Volume size (big endian) + volumesize *= 256; + volumesize += tempbuffer[85]; + volumesize *= 256; + volumesize += tempbuffer[86]; + volumesize *= 256; + volumesize += tempbuffer[87]; #ifdef VERBOSE_DISC_INFO - - if(tempdisctype != CDVD_TYPE_CDDA) { - - PrintLog("CDVDiso CD: ISO9660 size %llu", volumesize); - - } // ENDIF- Data CD? Print size in blocks. - + if (tempdisctype != CDVD_TYPE_CDDA) + { + PrintLog("CDVDiso CD: ISO9660 size %llu", volumesize); + } // ENDIF- Data CD? Print size in blocks. #endif /* VERBOSE_DISC_INFO */ + LBAtoMSF(volumesize, &tocbuffer[27]); + tocbuffer[27] = HEXTOBCD(tocbuffer[27]); + tocbuffer[28] = HEXTOBCD(tocbuffer[28]); + tocbuffer[29] = HEXTOBCD(tocbuffer[29]); + tocbuffer[40] = 0x02; // Data Mode + tocbuffer[42] = 0x01; // Track # + LBAtoMSF(0, &tocbuffer[47]); + tocbuffer[47] = HEXTOBCD(tocbuffer[47]); + tocbuffer[48] = HEXTOBCD(tocbuffer[48]); + tocbuffer[49] = HEXTOBCD(tocbuffer[49]); + // Can we get the REAL TOC? + boolresult = DeviceIoControl(devicehandle, + IOCTL_CDROM_READ_TOC, + NULL, + 0, + &cdinfo, + sizeof(CDROM_TOC), + &byteswritten, + NULL); - LBAtoMSF(volumesize, &tocbuffer[27]); - - tocbuffer[27] = HEXTOBCD(tocbuffer[27]); - - tocbuffer[28] = HEXTOBCD(tocbuffer[28]); - - tocbuffer[29] = HEXTOBCD(tocbuffer[29]); - - - - tocbuffer[40] = 0x02; // Data Mode - - tocbuffer[42] = 0x01; // Track # - - LBAtoMSF(0, &tocbuffer[47]); - - tocbuffer[47] = HEXTOBCD(tocbuffer[47]); - - tocbuffer[48] = HEXTOBCD(tocbuffer[48]); - - tocbuffer[49] = HEXTOBCD(tocbuffer[49]); - - - - // Can we get the REAL TOC? - - boolresult = DeviceIoControl(devicehandle, - - IOCTL_CDROM_READ_TOC, - - NULL, - - 0, - - &cdinfo, - - sizeof(CDROM_TOC), - - &byteswritten, - - NULL); - - - - if(boolresult == FALSE) { - + if (boolresult == FALSE) + { #ifdef VERBOSE_WARNING_DEVICE - - errcode = GetLastError(); - - PrintLog("CDVDiso CD: Can't get TOC!"); - - PrintError("CDVDiso CD", errcode); - + errcode = GetLastError(); + PrintLog("CDVDiso CD: Can't get TOC!"); + PrintError("CDVDiso CD", errcode); #endif /* VERBOSE_WARNING_DEVICE */ + disctype = tempdisctype; + return(disctype); + } // ENDIF- Can't read the TOC? Accept the fake TOC then. - disctype = tempdisctype; + // Fill in the pieces of the REAL TOC. +#ifdef VERBOSE_DISC_INFO + PrintLog("CDVDiso CD: TOC First Track: %u Last Track: %u", + cdinfo.FirstTrack, cdinfo.LastTrack); +#endif /* VERBOSE_DISC_INFO */ + tocbuffer[7] = HEXTOBCD(cdinfo.FirstTrack); + tocbuffer[17] = HEXTOBCD(cdinfo.LastTrack); - return(disctype); - - } // ENDIF- Can't read the TOC? Accept the fake TOC then. - - - - // Fill in the pieces of the REAL TOC. + // for(i = cdinfo.FirstTrack; i <= cdinfo.LastTrack; i++) { + for (i = 0; i <= cdinfo.LastTrack - cdinfo.FirstTrack; i++) + { +#ifdef VERBOSE_DISC_INFO + PrintLog("CDVDiso CD: TOC Track %u Disc Size: %u:%u.%u Data Mode %u", + cdinfo.TrackData[i].TrackNumber, + cdinfo.TrackData[i].Address[1] * 1, + cdinfo.TrackData[i].Address[2] * 1, + cdinfo.TrackData[i].Address[3] * 1, + cdinfo.TrackData[i].Control * 1); +#endif /* VERBOSE_DISC_INFO */ + pos = i * 10 + 40; + tocbuffer[pos] = cdinfo.TrackData[i].Control; + tocbuffer[pos + 2] = HEXTOBCD(i + 1); + tocbuffer[pos + 7] = HEXTOBCD(cdinfo.TrackData[i].Address[1]); + tocbuffer[pos + 8] = HEXTOBCD(cdinfo.TrackData[i].Address[2]); + tocbuffer[pos + 9] = HEXTOBCD(cdinfo.TrackData[i].Address[3]); + } // NEXT i- Transferring Track data to the PS2 TOC #ifdef VERBOSE_DISC_INFO - - PrintLog("CDVDiso CD: TOC First Track: %u Last Track: %u", - - cdinfo.FirstTrack, cdinfo.LastTrack); - + PrintLog("CDVDiso CD: TOC Disc Size: %u:%u.%u", + cdinfo.TrackData[i].Address[1] * 1, + cdinfo.TrackData[i].Address[2] * 1, + cdinfo.TrackData[i].Address[3] * 1); #endif /* VERBOSE_DISC_INFO */ - - tocbuffer[7] = HEXTOBCD(cdinfo.FirstTrack); - - tocbuffer[17] = HEXTOBCD(cdinfo.LastTrack); - - - - // for(i = cdinfo.FirstTrack; i <= cdinfo.LastTrack; i++) { - - for(i = 0; i <= cdinfo.LastTrack - cdinfo.FirstTrack; i++) { - -#ifdef VERBOSE_DISC_INFO - - PrintLog("CDVDiso CD: TOC Track %u Disc Size: %u:%u.%u Data Mode %u", - - cdinfo.TrackData[i].TrackNumber, - - cdinfo.TrackData[i].Address[1] * 1, - - cdinfo.TrackData[i].Address[2] * 1, - - cdinfo.TrackData[i].Address[3] * 1, - - cdinfo.TrackData[i].Control * 1); - -#endif /* VERBOSE_DISC_INFO */ - - pos = i * 10 + 40; - - tocbuffer[pos] = cdinfo.TrackData[i].Control; - - tocbuffer[pos + 2] = HEXTOBCD(i + 1); - - tocbuffer[pos + 7] = HEXTOBCD(cdinfo.TrackData[i].Address[1]); - - tocbuffer[pos + 8] = HEXTOBCD(cdinfo.TrackData[i].Address[2]); - - tocbuffer[pos + 9] = HEXTOBCD(cdinfo.TrackData[i].Address[3]); - - } // NEXT i- Transferring Track data to the PS2 TOC - - - - - -#ifdef VERBOSE_DISC_INFO - - PrintLog("CDVDiso CD: TOC Disc Size: %u:%u.%u", - - cdinfo.TrackData[i].Address[1] * 1, - - cdinfo.TrackData[i].Address[2] * 1, - - cdinfo.TrackData[i].Address[3] * 1); - -#endif /* VERBOSE_DISC_INFO */ - - tocbuffer[27] = HEXTOBCD(cdinfo.TrackData[i].Address[1]); - - tocbuffer[28] = HEXTOBCD(cdinfo.TrackData[i].Address[2]); - - tocbuffer[29] = HEXTOBCD(cdinfo.TrackData[i].Address[3]); - - - - disctype = tempdisctype; - - return(disctype); - + tocbuffer[27] = HEXTOBCD(cdinfo.TrackData[i].Address[1]); + tocbuffer[28] = HEXTOBCD(cdinfo.TrackData[i].Address[2]); + tocbuffer[29] = HEXTOBCD(cdinfo.TrackData[i].Address[3]); + disctype = tempdisctype; + return(disctype); } // END CDgetDiskType() - diff --git a/plugins/CDVDisoEFP/src/Win32/CD.h b/plugins/CDVDisoEFP/src/Win32/CD.h index 2049fe764d..d6e9a65cfe 100644 --- a/plugins/CDVDisoEFP/src/Win32/CD.h +++ b/plugins/CDVDisoEFP/src/Win32/CD.h @@ -1,88 +1,44 @@ -/* CD.h - - * Copyright (C) 2002-2005 PCSX2 Team - - * - - * This program is free software; you can redistribute it and/or modify - - * it under the terms of the GNU General Public License as published by - - * the Free Software Foundation; either version 2 of the License, or - - * (at your option) any later version. - - * - - * This program is distributed in the hope that it will be useful, - - * but WITHOUT ANY WARRANTY; without even the implied warranty of - - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - - * GNU General Public License for more details. - - * - - * You should have received a copy of the GNU General Public License - - * along with this program; if not, write to the Free Software - - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - * - - * PCSX2 members can be contacted through their website at www.pcsx2.net. - - */ - - - - - -#ifndef CD_H - -#define CD_H - - - - - -#include // DWORD - - - -#define CDVDdefs - -#include "PS2Edefs.h" - - - - - -extern DWORD cdblocksize; - - - - - -extern void InitCDInfo(); - -extern s32 CDreadTrack(u32 lsn, int mode, u8 *buffer); - -extern s32 CDgetBufferOffset(); - -extern s32 CDreadSubQ(); - -extern s32 CDgetTN(cdvdTN *cdvdtn); - -extern s32 CDgetTD(u8 newtrack, cdvdTD *cdvdtd); - -extern s32 CDgetDiskType(); - - - - - -#endif /* CD_H */ - +/* CD.h + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +#ifndef CD_H +#define CD_H + + +#include // DWORD + +#define CDVDdefs +#include "PS2Edefs.h" + + +extern DWORD cdblocksize; + + +extern void InitCDInfo(); +extern s32 CDreadTrack(u32 lsn, int mode, u8 *buffer); +extern s32 CDgetBufferOffset(); +extern s32 CDreadSubQ(); +extern s32 CDgetTN(cdvdTN *cdvdtn); +extern s32 CDgetTD(u8 newtrack, cdvdTD *cdvdtd); +extern s32 CDgetDiskType(); + + +#endif /* CD_H */ diff --git a/plugins/CDVDisoEFP/src/Win32/CDVDiso.c b/plugins/CDVDisoEFP/src/Win32/CDVDiso.c index 27cf979d55..81d35117e2 100644 --- a/plugins/CDVDisoEFP/src/Win32/CDVDiso.c +++ b/plugins/CDVDisoEFP/src/Win32/CDVDiso.c @@ -17,11 +17,8 @@ * * PCSX2 members can be contacted through their website at www.pcsx2.net. */ - - #include // BOOL, CALLBACK, APIENTRY #include // NULL - #define CDVDdefs #include "../PS2Edefs.h" @@ -37,534 +34,508 @@ #include "conversionbox.h" // Initialize conversionboxwindow #include "devicebox.h" // Initialize deviceboxwindow #include "CDVDiso.h" - - struct IsoFile *isofile; char isobuffer[2448]; char isocdcheck[2048]; int isomode; int deviceopencount; - HINSTANCE progmodule; - - BOOL APIENTRY DllMain(HANDLE hModule, DWORD param, - LPVOID reserved) { - - - switch(param) { - case DLL_PROCESS_ATTACH: - progmodule = hModule; - // mainboxwindow = NULL; - // progressboxwindow = NULL; - // conversionboxwindow = NULL; - // deviceboxwindow = NULL; - return(TRUE); - break; - case DLL_PROCESS_DETACH: - // CDVDshutdown(); - return(TRUE); - break; - case DLL_THREAD_ATTACH: - return(TRUE); - break; - case DLL_THREAD_DETACH: - return(TRUE); - break; - } // ENDSWITCH param- What does the OS want with us? - - return(FALSE); // Wasn't on list? Wasn't handled. + LPVOID reserved) +{ + switch (param) + { + case DLL_PROCESS_ATTACH: + progmodule = hModule; + // mainboxwindow = NULL; + // progressboxwindow = NULL; + // conversionboxwindow = NULL; + // deviceboxwindow = NULL; + return(TRUE); + break; + case DLL_PROCESS_DETACH: + // CDVDshutdown(); + return(TRUE); + break; + case DLL_THREAD_ATTACH: + return(TRUE); + break; + case DLL_THREAD_DETACH: + return(TRUE); + break; + } // ENDSWITCH param- What does the OS want with us? + return(FALSE); // Wasn't on list? Wasn't handled. } // END DllMain() - -char* CALLBACK PS2EgetLibName() { - return(libname); +char* CALLBACK PS2EgetLibName() +{ + return(libname); } // END PS2EgetLibName() - -u32 CALLBACK PS2EgetLibType() { - return(PS2E_LT_CDVD); +u32 CALLBACK PS2EgetLibType() +{ + return(PS2E_LT_CDVD); } // END PS2getLibType() - -u32 CALLBACK PS2EgetLibVersion2(u32 type) { - return((version << 16) | (revision << 8) | build); +u32 CALLBACK PS2EgetLibVersion2(u32 type) +{ + return((version << 16) | (revision << 8) | build); } // END PS2EgetLibVersion2() +s32 CALLBACK CDVDinit() +{ + int i; + InitLog(); + if (OpenLog() != 0) return(-1); // Couldn't open Log File? Abort. -s32 CALLBACK CDVDinit() { - int i; - - InitLog(); - if(OpenLog() != 0) return(-1); // Couldn't open Log File? Abort. - #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDinit()"); + PrintLog("CDVDiso interface: CDVDinit()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ + InitConf(); + isofile = NULL; + isomode = -1; + deviceopencount = 0; + for (i = 0; i < 2048; i++) isocdcheck[i] = 0; + mainboxwindow = NULL; + progressboxwindow = NULL; + conversionboxwindow = NULL; + deviceboxwindow = NULL; - InitConf(); - - isofile = NULL; - isomode = -1; - deviceopencount = 0; - for(i = 0; i < 2048; i++) isocdcheck[i] = 0; - - mainboxwindow = NULL; - progressboxwindow = NULL; - conversionboxwindow = NULL; - deviceboxwindow = NULL; - - return(0); + return(0); } // END CDVDinit() - - -void CALLBACK CDVDshutdown() { +void CALLBACK CDVDshutdown() +{ #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDshutdown()"); + PrintLog("CDVDiso interface: CDVDshutdown()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - - isofile = IsoFileClose(isofile); - - // Close Windows as well? (Just in case) - - CloseLog(); + isofile = IsoFileClose(isofile); + // Close Windows as well? (Just in case) + CloseLog(); } // END CDVDshutdown() - -s32 CALLBACK CDVDopen(const char* pTitleFilename) { - HWND lastwindow; - int i; - int retval; - +s32 CALLBACK CDVDopen(const char* pTitleFilename) +{ + HWND lastwindow; + int i; + int retval; #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDopen()"); + PrintLog("CDVDiso interface: CDVDopen()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - - lastwindow = GetActiveWindow(); - LoadConf(); - - if( pTitleFilename != NULL ) strcpy(conf.isoname, pTitleFilename); - - if((conf.isoname[0] == 0) || (conf.isoname[0] == '[') || - ((conf.startconfigure == 1) && (deviceopencount == 0)) || - ((conf.restartconfigure == 1) && (deviceopencount > 0))) { - DialogBox(progmodule, - MAKEINTRESOURCE(DLG_0200), - lastwindow, - (DLGPROC)MainBoxCallback); - SetActiveWindow(lastwindow); - LoadConf(); - // Blank out the name in config file afterwards? Seems excessive. - } // ENDIF- Haven't initialized the configure program yet? Do so now. - lastwindow = NULL; - - isofile = IsoFileOpenForRead(conf.isoname); - if(isofile == NULL) { + lastwindow = GetActiveWindow(); + LoadConf(); + if (pTitleFilename != NULL) strcpy(conf.isoname, pTitleFilename); + if ((conf.isoname[0] == 0) || (conf.isoname[0] == '[') || + ((conf.startconfigure == 1) && (deviceopencount == 0)) || + ((conf.restartconfigure == 1) && (deviceopencount > 0))) + { + DialogBox(progmodule, + MAKEINTRESOURCE(DLG_0200), + lastwindow, + (DLGPROC)MainBoxCallback); + SetActiveWindow(lastwindow); + LoadConf(); + // Blank out the name in config file afterwards? Seems excessive. + } // ENDIF- Haven't initialized the configure program yet? Do so now. + lastwindow = NULL; + isofile = IsoFileOpenForRead(conf.isoname); + if (isofile == NULL) + { #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: Failed to open ISO file!"); + PrintLog("CDVDiso interface: Failed to open ISO file!"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - // return(-1); // Removed to simulate disc not in drive. - for(i = 0; i < 2048; i++) isocdcheck[i] = 0; - return(0); - } // ENDIF- Trouble opening file? Abort. - - retval = IsoFileSeek(isofile, 16); - if(retval != 0) return(-1); - retval = IsoFileRead(isofile, isobuffer); - if(retval != 0) return(-1); - - if(deviceopencount > 0) { - i = 0; - while((i < 2048) && (isocdcheck[i] == isobuffer[i])) i++; - if(i == 2048) deviceopencount = 0; // Same CD/DVD? No delay. - } // ENDIF- Is this a restart? Check for disc change. - - for(i = 0; i < 2048; i++) isocdcheck[i] = isobuffer[i]; - - return(0); + // return(-1); // Removed to simulate disc not in drive. + for (i = 0; i < 2048; i++) isocdcheck[i] = 0; + return(0); + } // ENDIF- Trouble opening file? Abort. + retval = IsoFileSeek(isofile, 16); + if (retval != 0) return(-1); + retval = IsoFileRead(isofile, isobuffer); + if (retval != 0) return(-1); + if (deviceopencount > 0) + { + i = 0; + while ((i < 2048) && (isocdcheck[i] == isobuffer[i])) i++; + if (i == 2048) deviceopencount = 0; // Same CD/DVD? No delay. + } // ENDIF- Is this a restart? Check for disc change. + for (i = 0; i < 2048; i++) isocdcheck[i] = isobuffer[i]; + return(0); } // END CDVDopen() - -void CALLBACK CDVDclose() { +void CALLBACK CDVDclose() +{ #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDclose()"); + PrintLog("CDVDiso interface: CDVDclose()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - isofile = IsoFileClose(isofile); - deviceopencount = 50; + isofile = IsoFileClose(isofile); + deviceopencount = 50; } // END CDVDclose() - -s32 CALLBACK CDVDreadSubQ(u32 lsn, cdvdSubQ* subq) { - char temptime[3]; - int i; - int pos; - u32 tracklsn; +s32 CALLBACK CDVDreadSubQ(u32 lsn, cdvdSubQ* subq) +{ + char temptime[3]; + int i; + int pos; + u32 tracklsn; #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDreadSubQ()"); + PrintLog("CDVDiso interface: CDVDreadSubQ()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - if(isofile == NULL) return(-1); - if(deviceopencount > 0) { - deviceopencount--; - if(deviceopencount > 0) return(-1); - } // ENDIF- Still simulating device tray open? + if (isofile == NULL) return(-1); + if (deviceopencount > 0) + { + deviceopencount--; + if (deviceopencount > 0) return(-1); + } // ENDIF- Still simulating device tray open? - if((isofile->cdvdtype == CDVD_TYPE_PS2DVD) || - (isofile->cdvdtype == CDVD_TYPE_DVDV)) { - return(-1); // DVDs don't have SubQ data - } // ENDIF- Trying to get a SubQ from a DVD? + if ((isofile->cdvdtype == CDVD_TYPE_PS2DVD) || + (isofile->cdvdtype == CDVD_TYPE_DVDV)) + { + return(-1); // DVDs don't have SubQ data + } // ENDIF- Trying to get a SubQ from a DVD? + // fake it + i = BCDTOHEX(isofile->toc[7]); + pos = i * 10; + pos += 30; + temptime[0] = BCDTOHEX(isofile->toc[pos + 7]); + temptime[1] = BCDTOHEX(isofile->toc[pos + 8]); + temptime[2] = BCDTOHEX(isofile->toc[pos + 9]); + tracklsn = MSFtoLBA(temptime); + while ((i < BCDTOHEX(isofile->toc[17])) && (tracklsn < lsn)) + { + i++; + pos = i * 10; + pos += 30; + temptime[0] = BCDTOHEX(isofile->toc[pos + 7]); + temptime[1] = BCDTOHEX(isofile->toc[pos + 8]); + temptime[2] = BCDTOHEX(isofile->toc[pos + 9]); + tracklsn = MSFtoLBA(temptime); + } // ENDIF- Loop through tracks searching for lsn track + i--; + subq->ctrl = 4; + subq->mode = 1; + subq->trackNum = HEXTOBCD(i); + subq->trackIndex = HEXTOBCD(i); - // fake it - i = BCDTOHEX(isofile->toc[7]); - pos = i * 10; - pos += 30; - temptime[0] = BCDTOHEX(isofile->toc[pos + 7]); - temptime[1] = BCDTOHEX(isofile->toc[pos + 8]); - temptime[2] = BCDTOHEX(isofile->toc[pos + 9]); - tracklsn = MSFtoLBA(temptime); - while((i < BCDTOHEX(isofile->toc[17])) && (tracklsn < lsn)) { - i++; - pos = i * 10; - pos += 30; - temptime[0] = BCDTOHEX(isofile->toc[pos + 7]); - temptime[1] = BCDTOHEX(isofile->toc[pos + 8]); - temptime[2] = BCDTOHEX(isofile->toc[pos + 9]); - tracklsn = MSFtoLBA(temptime); - } // ENDIF- Loop through tracks searching for lsn track - i--; + LBAtoMSF(lsn - tracklsn, temptime); + subq->trackM = HEXTOBCD(temptime[0]); + subq->trackS = HEXTOBCD(temptime[1]); + subq->trackF = HEXTOBCD(temptime[2]); - subq->ctrl = 4; - subq->mode = 1; - subq->trackNum = HEXTOBCD(i); - subq->trackIndex = HEXTOBCD(i); - - LBAtoMSF(lsn - tracklsn, temptime); - subq->trackM = HEXTOBCD(temptime[0]); - subq->trackS = HEXTOBCD(temptime[1]); - subq->trackF = HEXTOBCD(temptime[2]); - - subq->pad = 0; - - // lba_to_msf(lsn + (2*75), &min, &sec, &frm); - LBAtoMSF(lsn, temptime); - subq->discM = HEXTOBCD(temptime[0]); - subq->discS = HEXTOBCD(temptime[1]); - subq->discF = HEXTOBCD(temptime[2]); + subq->pad = 0; - return(0); + // lba_to_msf(lsn + (2*75), &min, &sec, &frm); + LBAtoMSF(lsn, temptime); + subq->discM = HEXTOBCD(temptime[0]); + subq->discS = HEXTOBCD(temptime[1]); + subq->discF = HEXTOBCD(temptime[2]); + return(0); } // END CDVDreadSubQ() - -s32 CALLBACK CDVDgetTN(cdvdTN *Buffer) { +s32 CALLBACK CDVDgetTN(cdvdTN *Buffer) +{ #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDgetTN()"); + PrintLog("CDVDiso interface: CDVDgetTN()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - if(isofile == NULL) return(-1); - if(deviceopencount > 0) { - deviceopencount--; - if(deviceopencount > 0) return(-1); - } // ENDIF- Still simulating device tray open? + if (isofile == NULL) return(-1); + if (deviceopencount > 0) + { + deviceopencount--; + if (deviceopencount > 0) return(-1); + } // ENDIF- Still simulating device tray open? - if((isofile->cdvdtype == CDVD_TYPE_PS2DVD) || - (isofile->cdvdtype == CDVD_TYPE_DVDV)) { - Buffer->strack = 1; - Buffer->etrack = 1; - } else { - Buffer->strack = BCDTOHEX(isofile->toc[7]); - Buffer->etrack = BCDTOHEX(isofile->toc[17]); - } // ENDIF- Retrieve track info from a DVD? (or a CD?) - - return(0); + if ((isofile->cdvdtype == CDVD_TYPE_PS2DVD) || + (isofile->cdvdtype == CDVD_TYPE_DVDV)) + { + Buffer->strack = 1; + Buffer->etrack = 1; + } + else + { + Buffer->strack = BCDTOHEX(isofile->toc[7]); + Buffer->etrack = BCDTOHEX(isofile->toc[17]); + } // ENDIF- Retrieve track info from a DVD? (or a CD?) + return(0); } // END CDVDgetTN() - - -s32 CALLBACK CDVDgetTD(u8 track, cdvdTD *Buffer) { - u8 actualtrack; - int pos; - char temptime[3]; +s32 CALLBACK CDVDgetTD(u8 track, cdvdTD *Buffer) +{ + u8 actualtrack; + int pos; + char temptime[3]; #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDgetTD()"); + PrintLog("CDVDiso interface: CDVDgetTD()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - if(isofile == NULL) return(-1); - if(deviceopencount > 0) { - deviceopencount--; - if(deviceopencount > 0) return(-1); - } // ENDIF- Still simulating device tray open? + if (isofile == NULL) return(-1); + if (deviceopencount > 0) + { + deviceopencount--; + if (deviceopencount > 0) return(-1); + } // ENDIF- Still simulating device tray open? - actualtrack = track; - if(actualtrack == 0xaa) actualtrack = 0; - - if((isofile->cdvdtype == CDVD_TYPE_PS2DVD) || - (isofile->cdvdtype == CDVD_TYPE_DVDV)) { - if (actualtrack <= 1) { - Buffer->type = 0; - Buffer->lsn = isofile->filesectorsize; - } else { - Buffer->type = CDVD_MODE1_TRACK; - Buffer->lsn = 0; - } // ENDIF- Whole disc? (or single track?) - } else { - if (actualtrack == 0) { - Buffer->type = 0; - temptime[0] = BCDTOHEX(isofile->toc[27]); - temptime[1] = BCDTOHEX(isofile->toc[28]); - temptime[2] = BCDTOHEX(isofile->toc[29]); - Buffer->lsn = MSFtoLBA(temptime); - } else { - pos = actualtrack * 10; - pos += 30; - Buffer->type = isofile->toc[pos]; - temptime[0] = BCDTOHEX(isofile->toc[pos + 7]); - temptime[1] = BCDTOHEX(isofile->toc[pos + 8]); - temptime[2] = BCDTOHEX(isofile->toc[pos + 9]); - Buffer->lsn = MSFtoLBA(temptime); - } // ENDIF- Whole disc? (or single track?) - } // ENDIF- Retrieve track info from a DVD? (or a CD?) - - return(0); + actualtrack = track; + if (actualtrack == 0xaa) actualtrack = 0; + if ((isofile->cdvdtype == CDVD_TYPE_PS2DVD) || + (isofile->cdvdtype == CDVD_TYPE_DVDV)) + { + if (actualtrack <= 1) + { + Buffer->type = 0; + Buffer->lsn = isofile->filesectorsize; + } + else + { + Buffer->type = CDVD_MODE1_TRACK; + Buffer->lsn = 0; + } // ENDIF- Whole disc? (or single track?) + } + else + { + if (actualtrack == 0) + { + Buffer->type = 0; + temptime[0] = BCDTOHEX(isofile->toc[27]); + temptime[1] = BCDTOHEX(isofile->toc[28]); + temptime[2] = BCDTOHEX(isofile->toc[29]); + Buffer->lsn = MSFtoLBA(temptime); + } + else + { + pos = actualtrack * 10; + pos += 30; + Buffer->type = isofile->toc[pos]; + temptime[0] = BCDTOHEX(isofile->toc[pos + 7]); + temptime[1] = BCDTOHEX(isofile->toc[pos + 8]); + temptime[2] = BCDTOHEX(isofile->toc[pos + 9]); + Buffer->lsn = MSFtoLBA(temptime); + } // ENDIF- Whole disc? (or single track?) + } // ENDIF- Retrieve track info from a DVD? (or a CD?) + return(0); } // END CDVDgetTD() - -s32 CALLBACK CDVDgetTOC(void* toc) { - int i; - +s32 CALLBACK CDVDgetTOC(void* toc) +{ + int i; #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDgetTOC()"); + PrintLog("CDVDiso interface: CDVDgetTOC()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - - if(isofile == NULL) return(-1); - if(deviceopencount > 0) { - deviceopencount--; - if(deviceopencount > 0) return(-1); - } // ENDIF- Still simulating device tray open? - - for(i = 0; i < 2048; i++) *(((char *) toc) + i) = isofile->toc[i]; - return(0); + if (isofile == NULL) return(-1); + if (deviceopencount > 0) + { + deviceopencount--; + if (deviceopencount > 0) return(-1); + } // ENDIF- Still simulating device tray open? + for (i = 0; i < 2048; i++) *(((char *) toc) + i) = isofile->toc[i]; + return(0); } // END CDVDgetTOC() - -s32 CALLBACK CDVDreadTrack(u32 lsn, int mode) { - int retval; - +s32 CALLBACK CDVDreadTrack(u32 lsn, int mode) +{ + int retval; #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDreadTrack(%u)", lsn); + PrintLog("CDVDiso interface: CDVDreadTrack(%u)", lsn); #endif /* VERBOSE_FUNCTION_INTERFACE */ - - if(isofile == NULL) return(-1); - if(deviceopencount > 0) { - deviceopencount--; - if(deviceopencount > 0) return(-1); - } // ENDIF- Still simulating device tray open? - - retval = IsoFileSeek(isofile, (off64_t) lsn); - if(retval != 0) { + if (isofile == NULL) return(-1); + if (deviceopencount > 0) + { + deviceopencount--; + if (deviceopencount > 0) return(-1); + } // ENDIF- Still simulating device tray open? + retval = IsoFileSeek(isofile, (off64_t) lsn); + if (retval != 0) + { #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: Trouble finding the sector!"); + PrintLog("CDVDiso interface: Trouble finding the sector!"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - return(-1); - } // ENDIF- Trouble finding the sector? - - retval = IsoFileRead(isofile, isobuffer); - if(retval != 0) { + return(-1); + } // ENDIF- Trouble finding the sector? + retval = IsoFileRead(isofile, isobuffer); + if (retval != 0) + { #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: Trouble reading the sector!"); + PrintLog("CDVDiso interface: Trouble reading the sector!"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - return(-1); - } // ENDIF- Trouble finding the sector? - - isomode = mode; - return(0); + return(-1); + } // ENDIF- Trouble finding the sector? + isomode = mode; + return(0); } // END CDVDreadTrack() - -u8* CALLBACK CDVDgetBuffer() { - int offset; - +u8* CALLBACK CDVDgetBuffer() +{ + int offset; #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDgetBuffer()"); + PrintLog("CDVDiso interface: CDVDgetBuffer()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - - if(isofile == NULL) return(NULL); - if(deviceopencount > 0) { - deviceopencount--; - if(deviceopencount > 0) return(NULL); - } // ENDIF- Still simulating device tray open? - - offset = 0; - switch(isomode) { - case CDVD_MODE_2352: - offset = 0; - break; - case CDVD_MODE_2340: - offset = 12; - break; - case CDVD_MODE_2328: - case CDVD_MODE_2048: - offset = 24; - break; - } // ENDSWITCH isomode- offset to where data it wants is. - - if(offset > isofile->blockoffset) offset = isofile->blockoffset; - - return(isobuffer + offset); + if (isofile == NULL) return(NULL); + if (deviceopencount > 0) + { + deviceopencount--; + if (deviceopencount > 0) return(NULL); + } // ENDIF- Still simulating device tray open? + offset = 0; + switch (isomode) + { + case CDVD_MODE_2352: + offset = 0; + break; + case CDVD_MODE_2340: + offset = 12; + break; + case CDVD_MODE_2328: + case CDVD_MODE_2048: + offset = 24; + break; + } // ENDSWITCH isomode- offset to where data it wants is. + if (offset > isofile->blockoffset) offset = isofile->blockoffset; + return(isobuffer + offset); } // END CDVDgetBuffer() - - -s32 CALLBACK CDVDgetDiskType() { +s32 CALLBACK CDVDgetDiskType() +{ #ifdef VERBOSE_FUNCTION_INTERFACE - // PrintLog("CDVDiso interface: CDVDgetDiskType()"); + // PrintLog("CDVDiso interface: CDVDgetDiskType()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - if(isofile == NULL) return(CDVD_TYPE_NODISC); - if(deviceopencount > 0) { - deviceopencount--; - if(deviceopencount > 0) return(CDVD_TYPE_DETCT); - } // ENDIF- Still simulating device tray open? + if (isofile == NULL) return(CDVD_TYPE_NODISC); + if (deviceopencount > 0) + { + deviceopencount--; + if (deviceopencount > 0) return(CDVD_TYPE_DETCT); + } // ENDIF- Still simulating device tray open? - return(isofile->cdvdtype); + return(isofile->cdvdtype); } // END CDVDgetDiskType() - - -s32 CALLBACK CDVDgetTrayStatus() { +s32 CALLBACK CDVDgetTrayStatus() +{ #ifdef VERBOSE_FUNCTION_INTERFACE - // PrintLog("CDVDiso interface: CDVDgetTrayStatus()"); + // PrintLog("CDVDiso interface: CDVDgetTrayStatus()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - - if(isofile == NULL) return(CDVD_TRAY_OPEN); - if(deviceopencount > 30) { - deviceopencount--; - return(CDVD_TRAY_OPEN); - } // ENDIF- Still simulating device tray open? - - return(CDVD_TRAY_CLOSE); + if (isofile == NULL) return(CDVD_TRAY_OPEN); + if (deviceopencount > 30) + { + deviceopencount--; + return(CDVD_TRAY_OPEN); + } // ENDIF- Still simulating device tray open? + return(CDVD_TRAY_CLOSE); } // END CDVDgetTrayStatus() - - -s32 CALLBACK CDVDctrlTrayOpen() { - HWND lastwindow; - int i; - int retval; +s32 CALLBACK CDVDctrlTrayOpen() +{ + HWND lastwindow; + int i; + int retval; #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDctrlTrayOpen()"); + PrintLog("CDVDiso interface: CDVDctrlTrayOpen()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - // CDVDclose(); - isofile = IsoFileClose(isofile); - deviceopencount = 50; - - // CDVDopen(); - lastwindow = GetActiveWindow(); - LoadConf(); - if((conf.isoname[0] == 0) || (conf.isoname[0] == '[') || - ((conf.restartconfigure == 1) && (deviceopencount > 0))) { - DialogBox(progmodule, - MAKEINTRESOURCE(DLG_0200), - lastwindow, - (DLGPROC)MainBoxCallback); - SetActiveWindow(lastwindow); - LoadConf(); - // Blank out the name in config file afterwards? Seems excessive. - } // ENDIF- Haven't initialized the configure program yet? Do so now. - lastwindow = NULL; - deviceopencount = 0; // Temp line! - // NOTE: What happened to repetitive polling when disc not in drive? - - isofile = IsoFileOpenForRead(conf.isoname); - if(isofile == NULL) { + // CDVDclose(); + isofile = IsoFileClose(isofile); + deviceopencount = 50; + // CDVDopen(); + lastwindow = GetActiveWindow(); + LoadConf(); + if ((conf.isoname[0] == 0) || (conf.isoname[0] == '[') || + ((conf.restartconfigure == 1) && (deviceopencount > 0))) + { + DialogBox(progmodule, + MAKEINTRESOURCE(DLG_0200), + lastwindow, + (DLGPROC)MainBoxCallback); + SetActiveWindow(lastwindow); + LoadConf(); + // Blank out the name in config file afterwards? Seems excessive. + } // ENDIF- Haven't initialized the configure program yet? Do so now. + lastwindow = NULL; + deviceopencount = 0; // Temp line! + // NOTE: What happened to repetitive polling when disc not in drive? + isofile = IsoFileOpenForRead(conf.isoname); + if (isofile == NULL) + { #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: Failed to open ISO file!"); + PrintLog("CDVDiso interface: Failed to open ISO file!"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - // return(-1); // Removed to simulate disc not in drive. - for(i = 0; i < 2048; i++) isocdcheck[i] = 0; - return(0); - } // ENDIF- Trouble opening file? Abort. - - retval = IsoFileSeek(isofile, 16); - if(retval != 0) return(-1); - retval = IsoFileRead(isofile, isobuffer); - if(retval != 0) return(-1); - - if(deviceopencount > 0) { - i = 0; - while((i < 2048) && (isocdcheck[i] == isobuffer[i])) i++; - if(i == 2048) deviceopencount = 0; // Same CD/DVD? No delay. - } // ENDIF- Is this a restart? Check for disc change. - - for(i = 0; i < 2048; i++) isocdcheck[i] = isobuffer[i]; - - return(0); + // return(-1); // Removed to simulate disc not in drive. + for (i = 0; i < 2048; i++) isocdcheck[i] = 0; + return(0); + } // ENDIF- Trouble opening file? Abort. + retval = IsoFileSeek(isofile, 16); + if (retval != 0) return(-1); + retval = IsoFileRead(isofile, isobuffer); + if (retval != 0) return(-1); + if (deviceopencount > 0) + { + i = 0; + while ((i < 2048) && (isocdcheck[i] == isobuffer[i])) i++; + if (i == 2048) deviceopencount = 0; // Same CD/DVD? No delay. + } // ENDIF- Is this a restart? Check for disc change. + for (i = 0; i < 2048; i++) isocdcheck[i] = isobuffer[i]; + return(0); } // END CDVDctrlTrayOpen() - -s32 CALLBACK CDVDctrlTrayClose() { +s32 CALLBACK CDVDctrlTrayClose() +{ #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDctrlTrayClose()"); + PrintLog("CDVDiso interface: CDVDctrlTrayClose()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - return(0); + return(0); } // END CDVDctrlTrayClose() - - -s32 CALLBACK CDVDtest() { +s32 CALLBACK CDVDtest() +{ #ifdef VERBOSE_FUNCTION_INTERFACE - PrintLog("CDVDiso interface: CDVDtest()"); + PrintLog("CDVDiso interface: CDVDtest()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ - // InitConf(); // Shouldn't need this. Doesn't CDVDInit() get called first? - LoadConf(); + // InitConf(); // Shouldn't need this. Doesn't CDVDInit() get called first? + LoadConf(); - if(conf.isoname[0] == 0) return(0); // No name chosen yet. Catch on Open() - if(IsIsoFile(conf.isoname) == 0) return(0); // Valid name. Go. - return(-1); // Invalid name - reconfigure first. - // Note really need this? Why not just return(0)... + if (conf.isoname[0] == 0) return(0); // No name chosen yet. Catch on Open() + if (IsIsoFile(conf.isoname) == 0) return(0); // Valid name. Go. + return(-1); // Invalid name - reconfigure first. + // Note really need this? Why not just return(0)... } // END CDVDtest() - -void CALLBACK CDVDconfigure() { - HWND lastwindow; - - lastwindow = GetActiveWindow(); - DialogBox(progmodule, - MAKEINTRESOURCE(DLG_0200), - lastwindow, - (DLGPROC)MainBoxCallback); - SetActiveWindow(lastwindow); - lastwindow = NULL; - return; +void CALLBACK CDVDconfigure() +{ + HWND lastwindow; + lastwindow = GetActiveWindow(); + DialogBox(progmodule, + MAKEINTRESOURCE(DLG_0200), + lastwindow, + (DLGPROC)MainBoxCallback); + SetActiveWindow(lastwindow); + lastwindow = NULL; + return; } // END CDVDconfigure() - - -BOOL CALLBACK AboutCallback(HWND window, UINT msg, WPARAM param, LPARAM param2) { - switch(msg) { - case WM_COMMAND: - switch(LOWORD(param)) { - case IDC_0104: // "Ok" Button - EndDialog(window, FALSE); - return(TRUE); - break; - } // ENDSWITCH param- Which Windows Message Command? - - case WM_CLOSE: - EndDialog(window, FALSE); - return(TRUE); - break; - } // ENDSWITCH msg- what message has been sent to this window? - - return(FALSE); // Not a recognisable message. Pass it back to the OS. +BOOL CALLBACK AboutCallback(HWND window, UINT msg, WPARAM param, LPARAM param2) +{ + switch (msg) + { + case WM_COMMAND: + switch (LOWORD(param)) + { + case IDC_0104: // "Ok" Button + EndDialog(window, FALSE); + return(TRUE); + break; + } // ENDSWITCH param- Which Windows Message Command? + case WM_CLOSE: + EndDialog(window, FALSE); + return(TRUE); + break; + } // ENDSWITCH msg- what message has been sent to this window? + return(FALSE); // Not a recognisable message. Pass it back to the OS. } // END AboutCallback() -void CALLBACK CDVDabout() { - HWND lastwindow; - - lastwindow = GetActiveWindow(); - DialogBox(progmodule, - MAKEINTRESOURCE(DLG_0100), - lastwindow, - (DLGPROC)AboutCallback); - SetActiveWindow(lastwindow); - return; +void CALLBACK CDVDabout() +{ + HWND lastwindow; + lastwindow = GetActiveWindow(); + DialogBox(progmodule, + MAKEINTRESOURCE(DLG_0100), + lastwindow, + (DLGPROC)AboutCallback); + SetActiveWindow(lastwindow); + return; } // END CDVDabout() diff --git a/plugins/CDVDisoEFP/src/Win32/CDVDiso.h b/plugins/CDVDisoEFP/src/Win32/CDVDiso.h index f502d4150e..fe69d007c9 100644 --- a/plugins/CDVDisoEFP/src/Win32/CDVDiso.h +++ b/plugins/CDVDisoEFP/src/Win32/CDVDiso.h @@ -1,72 +1,31 @@ /* CDVDiso.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef CDVDISO_H - #define CDVDISO_H - - - - #include // HINSTANCE - - - - // #define VERBOSE_FUNCTION_INTERFACE - - - - extern HINSTANCE progmodule; - extern char isobuffer[]; - - - - #endif /* CDVDISO_H */ - diff --git a/plugins/CDVDisoEFP/src/Win32/DVD.c b/plugins/CDVDisoEFP/src/Win32/DVD.c index 077c50f6a0..91958933c3 100644 --- a/plugins/CDVDisoEFP/src/Win32/DVD.c +++ b/plugins/CDVDisoEFP/src/Win32/DVD.c @@ -1,796 +1,412 @@ /* DVD.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include - #include // IOCTL_DVD... - - - #include // off64_t - - - #define CDVDdefs - #include "PS2Edefs.h" - - #include "logfile.h" - #include "device.h" // FinishCommand() - - - - -struct { - - DVD_DESCRIPTOR_HEADER h; - - DVD_LAYER_DESCRIPTOR d; - +struct +{ + DVD_DESCRIPTOR_HEADER h; + DVD_LAYER_DESCRIPTOR d; } layer; - // DVD_LAYER_DESCRIPTOR layer; - // DVD_COPYRIGHT_DESCRIPTOR copyright; - // DVD_DISK_KEY_DESCRIPTOR disckey; - // DVD_BCA_DESCRIPTOR bca; - // DVD_MANUFACTURER_DESCRIPTOR manufact; - - - - -void InitDVDInfo() { - - layer.d.EndDataSector = 0; - +void InitDVDInfo() +{ + layer.d.EndDataSector = 0; } // END InitDVDInfo() - - - - -s32 DVDGetStructures() { - - DVD_SESSION_ID sessionid; - - DVD_READ_STRUCTURE request; - - DWORD byteswritten; - - BOOL boolresult; - - DWORD errcode; - - s32 retval; - - +s32 DVDGetStructures() +{ + DVD_SESSION_ID sessionid; + DVD_READ_STRUCTURE request; + DWORD byteswritten; + BOOL boolresult; + DWORD errcode; + s32 retval; #ifdef VERBOSE_FUNCTION_DEVICE - - PrintLog("CDVDiso DVD: DVDgetStructures()"); - + PrintLog("CDVDiso DVD: DVDgetStructures()"); #endif /* VERBOSE_FUNCTION_DEVICE */ - - - boolresult = DeviceIoControl(devicehandle, - - IOCTL_DVD_START_SESSION, - - NULL, - - 0, - - &sessionid, - - sizeof(DVD_SESSION_ID), - - &byteswritten, - - &waitevent); - - errcode = FinishCommand(boolresult); - - if(errcode != 0) { - + boolresult = DeviceIoControl(devicehandle, + IOCTL_DVD_START_SESSION, + NULL, + 0, + &sessionid, + sizeof(DVD_SESSION_ID), + &byteswritten, + &waitevent); + errcode = FinishCommand(boolresult); + if (errcode != 0) + { #ifdef VERBOSE_WARNING_DEVICE - - PrintLog("CDVDiso DVD: Couldn't start session!"); - - PrintError("CDVDiso DVD", errcode); - + PrintLog("CDVDiso DVD: Couldn't start session!"); + PrintError("CDVDiso DVD", errcode); #endif /* VERBOSE_WARNING_DEVICE */ - - return(-1); - - } // ENDIF- Couldn't start a user session on the DVD drive? Fail. - - - - request.BlockByteOffset.QuadPart = 0; - - request.Format = DvdPhysicalDescriptor; - - request.SessionId = sessionid; - - request.LayerNumber = 0; - - retval = 0; - - boolresult = DeviceIoControl(devicehandle, - - IOCTL_DVD_READ_STRUCTURE, - - &request, - - sizeof(DVD_READ_STRUCTURE), - - &layer, - - sizeof(layer), - - &byteswritten, - - &waitevent); - - errcode = FinishCommand(boolresult); - - if(errcode != 0) { - + return(-1); + } // ENDIF- Couldn't start a user session on the DVD drive? Fail. + request.BlockByteOffset.QuadPart = 0; + request.Format = DvdPhysicalDescriptor; + request.SessionId = sessionid; + request.LayerNumber = 0; + retval = 0; + boolresult = DeviceIoControl(devicehandle, + IOCTL_DVD_READ_STRUCTURE, + &request, + sizeof(DVD_READ_STRUCTURE), + &layer, + sizeof(layer), + &byteswritten, + &waitevent); + errcode = FinishCommand(boolresult); + if (errcode != 0) + { #ifdef VERBOSE_WARNING_DEVICE - - PrintLog("CDVDiso DVD: Couldn't get layer data!"); - - PrintError("CDVDiso DVD", errcode); - + PrintLog("CDVDiso DVD: Couldn't get layer data!"); + PrintError("CDVDiso DVD", errcode); #endif /* VERBOSE_WARNING_DEVICE */ - - retval = -1; - - } // ENDIF- Couldn't get layer data? (Including DVD size) Abort. - - - + retval = -1; + } // ENDIF- Couldn't get layer data? (Including DVD size) Abort. #ifdef VERBOSE_DISC_INFO - - switch(layer.d.BookType) { - - case 0: - - PrintLog("CDVDiso DVD: Book Type: DVD-ROM"); - - break; - - case 1: - - PrintLog("CDVDiso DVD: Book Type: DVD-RAM"); - - break; - - case 2: - - PrintLog("CDVDiso DVD: Book Type: DVD-R"); - - break; - - case 3: - - PrintLog("CDVDiso DVD: Book Type: DVD-RW"); - - break; - - case 9: - - PrintLog("CDVDiso DVD: Book Type: DVD+RW"); - - break; - - default: - - PrintLog("CDVDiso DVD: Book Type: Unknown (%i)", layer.d.BookType); - - break; - - } // ENDSWITCH- Displaying the Book Type - - PrintLog("CDVDiso DVD: Book Version %i", layer.d.BookVersion); - - switch(layer.d.MinimumRate) { - - case 0: - - PrintLog("CDVDiso DVD: Use Minimum Rate for: DVD-ROM"); - - break; - - case 1: - - PrintLog("CDVDiso DVD: Use Minimum Rate for: DVD-RAM"); - - break; - - case 2: - - PrintLog("CDVDiso DVD: Use Minimum Rate for: DVD-R"); - - break; - - case 3: - - PrintLog("CDVDiso DVD: Use Minimum Rate for: DVD-RW"); - - break; - - case 9: - - PrintLog("CDVDiso DVD: Use Minimum Rate for: DVD+RW"); - - break; - - default: - - PrintLog("CDVDiso DVD: Use Minimum Rate for: Unknown (%i)", layer.d.MinimumRate); - - break; - - } // ENDSWITCH- Displaying the Minimum (Spin?) Rate - - switch(layer.d.DiskSize) { - - case 0: - - PrintLog("CDVDiso DVD: Physical Disk Size: 120mm"); - - break; - - case 1: - - PrintLog("CDVDiso DVD: Physical Disk Size: 80mm"); - - break; - - default: - - PrintLog("CDVDiso DVD: Physical Disk Size: Unknown (%i)", layer.d.DiskSize); - - break; - - } // ENDSWITCH- What's the Disk Size? - - switch(layer.d.LayerType) { - - case 1: - - PrintLog("CDVDiso DVD: Layer Type: Read-Only"); - - break; - - case 2: - - PrintLog("CDVDiso DVD: Layer Type: Recordable"); - - break; - - case 4: - - PrintLog("CDVDiso DVD: Layer Type: Rewritable"); - - break; - - default: - - PrintLog("CDVDiso DVD: Layer Type: Unknown (%i)", layer.d.LayerType); - - break; - - } // ENDSWITCH- Displaying the Layer Type - - switch(layer.d.TrackPath) { - - case 0: - - PrintLog("CDVDiso DVD: Track Path: PTP"); - - break; - - case 1: - - PrintLog("CDVDiso DVD: Track Path: OTP"); - - break; - - default: - - PrintLog("CDVDiso DVD: Track Path: Unknown (%i)", layer.d.TrackPath); - - break; - - } // ENDSWITCH- What's Track Path Layout? - - PrintLog("CDVDiso DVD: Number of Layers: %i", layer.d.NumberOfLayers + 1); - - switch(layer.d.TrackDensity) { - - case 0: - - PrintLog("CDVDiso DVD: Track Density: .74 m/track"); - - break; - - case 1: - - PrintLog("CDVDiso DVD: Track Density: .8 m/track"); - - break; - - case 2: - - PrintLog("CDVDiso DVD: Track Density: .615 m/track"); - - break; - - default: - - PrintLog("CDVDiso DVD: Track Density: Unknown (%i)", layer.d.TrackDensity); - - break; - - } // ENDSWITCH- Displaying the Layer Type - - switch(layer.d.LinearDensity) { - - case 0: - - PrintLog("CDVDiso DVD: Linear Density: .267 m/bit"); - - break; - - case 1: - - PrintLog("CDVDiso DVD: Linear Density: .293 m/bit"); - - break; - - case 2: - - PrintLog("CDVDiso DVD: Linear Density: .409 to .435 m/bit"); - - break; - - case 4: - - PrintLog("CDVDiso DVD: Linear Density: .280 to .291 m/bit"); - - break; - - case 8: - - PrintLog("CDVDiso DVD: Linear Density: .353 m/bit"); - - break; - - default: - - PrintLog("CDVDiso DVD: Linear Density: Unknown (%i)", layer.d.LinearDensity); - - break; - - } // ENDSWITCH- Displaying the Book Type - - if(layer.d.StartingDataSector == 0x30000) { - - PrintLog("CDVDiso DVD: Starting Sector: %lu (DVD-ROM, DVD-R, DVD-RW)", - - layer.d.StartingDataSector); - - } else if(layer.d.StartingDataSector == 0x31000) { - - PrintLog("CDVDiso DVD: Starting Sector: %lu (DVD-RAM, DVD+RW)", - - layer.d.StartingDataSector); - - } else { - - PrintLog("CDVDiso DVD: Starting Sector: %lu", layer.d.StartingDataSector); - - } // ENDLONGIF- What does the starting sector tell us? - - PrintLog("CDVDiso DVD: End of Layer 0: %lu", layer.d.EndLayerZeroSector); - - PrintLog("CDVDiso DVD: Ending Sector: %lu", layer.d.EndDataSector); - - if(layer.d.BCAFlag != 0) PrintLog("CDVDiso DVD: BCA data present"); - + switch (layer.d.BookType) + { + case 0: + PrintLog("CDVDiso DVD: Book Type: DVD-ROM"); + break; + case 1: + PrintLog("CDVDiso DVD: Book Type: DVD-RAM"); + break; + case 2: + PrintLog("CDVDiso DVD: Book Type: DVD-R"); + break; + case 3: + PrintLog("CDVDiso DVD: Book Type: DVD-RW"); + break; + case 9: + PrintLog("CDVDiso DVD: Book Type: DVD+RW"); + break; + default: + PrintLog("CDVDiso DVD: Book Type: Unknown (%i)", layer.d.BookType); + break; + } // ENDSWITCH- Displaying the Book Type + PrintLog("CDVDiso DVD: Book Version %i", layer.d.BookVersion); + switch (layer.d.MinimumRate) + { + case 0: + PrintLog("CDVDiso DVD: Use Minimum Rate for: DVD-ROM"); + break; + case 1: + PrintLog("CDVDiso DVD: Use Minimum Rate for: DVD-RAM"); + break; + case 2: + PrintLog("CDVDiso DVD: Use Minimum Rate for: DVD-R"); + break; + case 3: + PrintLog("CDVDiso DVD: Use Minimum Rate for: DVD-RW"); + break; + case 9: + PrintLog("CDVDiso DVD: Use Minimum Rate for: DVD+RW"); + break; + default: + PrintLog("CDVDiso DVD: Use Minimum Rate for: Unknown (%i)", layer.d.MinimumRate); + break; + } // ENDSWITCH- Displaying the Minimum (Spin?) Rate + switch (layer.d.DiskSize) + { + case 0: + PrintLog("CDVDiso DVD: Physical Disk Size: 120mm"); + break; + case 1: + PrintLog("CDVDiso DVD: Physical Disk Size: 80mm"); + break; + default: + PrintLog("CDVDiso DVD: Physical Disk Size: Unknown (%i)", layer.d.DiskSize); + break; + } // ENDSWITCH- What's the Disk Size? + switch (layer.d.LayerType) + { + case 1: + PrintLog("CDVDiso DVD: Layer Type: Read-Only"); + break; + case 2: + PrintLog("CDVDiso DVD: Layer Type: Recordable"); + break; + case 4: + PrintLog("CDVDiso DVD: Layer Type: Rewritable"); + break; + default: + PrintLog("CDVDiso DVD: Layer Type: Unknown (%i)", layer.d.LayerType); + break; + } // ENDSWITCH- Displaying the Layer Type + switch (layer.d.TrackPath) + { + case 0: + PrintLog("CDVDiso DVD: Track Path: PTP"); + break; + case 1: + PrintLog("CDVDiso DVD: Track Path: OTP"); + break; + default: + PrintLog("CDVDiso DVD: Track Path: Unknown (%i)", layer.d.TrackPath); + break; + } // ENDSWITCH- What's Track Path Layout? + PrintLog("CDVDiso DVD: Number of Layers: %i", layer.d.NumberOfLayers + 1); + switch (layer.d.TrackDensity) + { + case 0: + PrintLog("CDVDiso DVD: Track Density: .74 m/track"); + break; + case 1: + PrintLog("CDVDiso DVD: Track Density: .8 m/track"); + break; + case 2: + PrintLog("CDVDiso DVD: Track Density: .615 m/track"); + break; + default: + PrintLog("CDVDiso DVD: Track Density: Unknown (%i)", layer.d.TrackDensity); + break; + } // ENDSWITCH- Displaying the Layer Type + switch (layer.d.LinearDensity) + { + case 0: + PrintLog("CDVDiso DVD: Linear Density: .267 m/bit"); + break; + case 1: + PrintLog("CDVDiso DVD: Linear Density: .293 m/bit"); + break; + case 2: + PrintLog("CDVDiso DVD: Linear Density: .409 to .435 m/bit"); + break; + case 4: + PrintLog("CDVDiso DVD: Linear Density: .280 to .291 m/bit"); + break; + case 8: + PrintLog("CDVDiso DVD: Linear Density: .353 m/bit"); + break; + default: + PrintLog("CDVDiso DVD: Linear Density: Unknown (%i)", layer.d.LinearDensity); + break; + } // ENDSWITCH- Displaying the Book Type + if (layer.d.StartingDataSector == 0x30000) + { + PrintLog("CDVDiso DVD: Starting Sector: %lu (DVD-ROM, DVD-R, DVD-RW)", + layer.d.StartingDataSector); + } + else if (layer.d.StartingDataSector == 0x31000) + { + PrintLog("CDVDiso DVD: Starting Sector: %lu (DVD-RAM, DVD+RW)", + layer.d.StartingDataSector); + } + else + { + PrintLog("CDVDiso DVD: Starting Sector: %lu", layer.d.StartingDataSector); + } // ENDLONGIF- What does the starting sector tell us? + PrintLog("CDVDiso DVD: End of Layer 0: %lu", layer.d.EndLayerZeroSector); + PrintLog("CDVDiso DVD: Ending Sector: %lu", layer.d.EndDataSector); + if (layer.d.BCAFlag != 0) PrintLog("CDVDiso DVD: BCA data present"); #endif /* VERBOSE_DISC_INFO */ - - - boolresult = DeviceIoControl(devicehandle, - - IOCTL_DVD_END_SESSION, - - &sessionid, - - sizeof(DVD_SESSION_ID), - - NULL, - - 0, - - &byteswritten, - - &waitevent); - - errcode = FinishCommand(boolresult); - - if(errcode != 0) { - + boolresult = DeviceIoControl(devicehandle, + IOCTL_DVD_END_SESSION, + &sessionid, + sizeof(DVD_SESSION_ID), + NULL, + 0, + &byteswritten, + &waitevent); + errcode = FinishCommand(boolresult); + if (errcode != 0) + { #ifdef VERBOSE_WARNING_DEVICE - - PrintLog("CDVDiso DVD: Couldn't end the session!"); - - PrintError("CDVDiso DVD", errcode); - + PrintLog("CDVDiso DVD: Couldn't end the session!"); + PrintError("CDVDiso DVD", errcode); #endif /* VERBOSE_WARNING_DEVICE */ + } // ENDIF- Couldn't end the user session? Report it. - } // ENDIF- Couldn't end the user session? Report it. - - - - return(retval); - + return(retval); } // END DVDGetStructures() - - - - -s32 DVDreadTrack(u32 lsn, int mode, u8 *buffer) { - - LARGE_INTEGER targetpos; - - DWORD byteswritten; - - BOOL boolresult; - - DWORD errcode; - - +s32 DVDreadTrack(u32 lsn, int mode, u8 *buffer) +{ + LARGE_INTEGER targetpos; + DWORD byteswritten; + BOOL boolresult; + DWORD errcode; #ifdef VERBOSE_FUNCTION_DEVICE - - PrintLog("CDVDiso DVD: DVDreadTrack(%lu)", lsn); - + PrintLog("CDVDiso DVD: DVDreadTrack(%lu)", lsn); #endif /* VERBOSE_FUNCTION_DEVICE */ + targetpos.QuadPart = lsn * 2048; + waitevent.Offset = targetpos.LowPart; + waitevent.OffsetHigh = targetpos.HighPart; - - targetpos.QuadPart = lsn * 2048; - - waitevent.Offset = targetpos.LowPart; - - waitevent.OffsetHigh = targetpos.HighPart; - - - - boolresult = ReadFile(devicehandle, - - buffer, - - 2048, - - &byteswritten, - - &waitevent); - - errcode = FinishCommand(boolresult); - - - - if(errcode != 0) { - + boolresult = ReadFile(devicehandle, + buffer, + 2048, + &byteswritten, + &waitevent); + errcode = FinishCommand(boolresult); + if (errcode != 0) + { #ifdef VERBOSE_WARNING_DEVICE - - PrintLog("CDVDiso DVD: Couldn't read sector!"); - - PrintError("CDVDiso DVD", errcode); - + PrintLog("CDVDiso DVD: Couldn't read sector!"); + PrintError("CDVDiso DVD", errcode); #endif /* VERBOSE_WARNING_DEVICE */ - - return(-1); - - } // ENDIF- Trouble with the command? Report it. - - - - if(boolresult == FALSE) { - - boolresult = GetOverlappedResult(devicehandle, - - &waitevent, - - &byteswritten, - - FALSE); - - } // ENDIF- Did the initial call not complete? Get byteswritten for - - // the completed call. - - - - if(byteswritten < 2048) { - + return(-1); + } // ENDIF- Trouble with the command? Report it. + if (boolresult == FALSE) + { + boolresult = GetOverlappedResult(devicehandle, + &waitevent, + &byteswritten, + FALSE); + } // ENDIF- Did the initial call not complete? Get byteswritten for + // the completed call. + if (byteswritten < 2048) + { #ifdef VERBOSE_WARNING_DEVICE - - errcode = GetLastError(); - - PrintLog("CDVDiso CD: Short block! only got %u out of %u bytes", - - byteswritten, 2048); - - PrintError("CDVDiso CD", errcode); - + errcode = GetLastError(); + PrintLog("CDVDiso CD: Short block! only got %u out of %u bytes", + byteswritten, 2048); + PrintError("CDVDiso CD", errcode); #endif /* VERBOSE_WARNING_DEVICE */ - - return(-1); - - } // ENDIF- Didn't get enough bytes? Report and Abort! - - - - return(0); - + return(-1); + } // ENDIF- Didn't get enough bytes? Report and Abort! + return(0); } // END DVDreadTrack() - - - - -s32 DVDgetTN(cdvdTN *cdvdtn) { - +s32 DVDgetTN(cdvdTN *cdvdtn) +{ #ifdef VERBOSE_FUNCTION_DEVICE - - PrintLog("CDVDiso DVD: DVDgetTN()"); - + PrintLog("CDVDiso DVD: DVDgetTN()"); #endif /* VERBOSE_FUNCTION_DEVICE */ - - - if(cdvdtn != NULL) { - - cdvdtn->strack = 1; - - cdvdtn->etrack = 1; - - } // ENDIF- Does the user really want this data? - - return(0); - + if (cdvdtn != NULL) + { + cdvdtn->strack = 1; + cdvdtn->etrack = 1; + } // ENDIF- Does the user really want this data? + return(0); } // END DVDgetTN() - - - - -s32 DVDgetTD(u8 newtrack, cdvdTD *cdvdtd) { - +s32 DVDgetTD(u8 newtrack, cdvdTD *cdvdtd) +{ #ifdef VERBOSE_FUNCTION_DEVICE - - PrintLog("CDVDiso DVD: DVDgetTD()"); - + PrintLog("CDVDiso DVD: DVDgetTD()"); #endif /* VERBOSE_FUNCTION_DEVICE */ - - - - if((newtrack >= 2) && (newtrack != 0xAA)) return(-1); // Wrong track - - - - if(cdvdtd != NULL) { - - cdvdtd->type = 0; - - cdvdtd->lsn = layer.d.EndDataSector - layer.d.StartingDataSector + 1; - - } // ENDIF- Does the user really want this data? - - return(0); - + if ((newtrack >= 2) && (newtrack != 0xAA)) return(-1); // Wrong track + if (cdvdtd != NULL) + { + cdvdtd->type = 0; + cdvdtd->lsn = layer.d.EndDataSector - layer.d.StartingDataSector + 1; + } // ENDIF- Does the user really want this data? + return(0); } // END DVDgetTD() - - - - -s32 DVDgetDiskType() { - - char playstationname[] = "PLAYSTATION\0"; - - int retval; - - s32 tempdisctype; - - char tempbuffer[2048]; - - int i; - - +s32 DVDgetDiskType() +{ + char playstationname[] = "PLAYSTATION\0"; + int retval; + s32 tempdisctype; + char tempbuffer[2048]; + int i; #ifdef VERBOSE_FUNCTION_DEVICE - - PrintLog("CDVDiso DVD: DVDgetDiskType()"); - + PrintLog("CDVDiso DVD: DVDgetDiskType()"); #endif /* VERBOSE_FUNCTION_DEVICE */ + retval = DVDGetStructures(); + if (retval < 0) return(-1); // Can't get DVD structures? Not a DVD then. + if (layer.d.EndDataSector == 0) return(-1); // Missing info? Abort. - - retval = DVDGetStructures(); - - if(retval < 0) return(-1); // Can't get DVD structures? Not a DVD then. - - if(layer.d.EndDataSector == 0) return(-1); // Missing info? Abort. - - - - retval = DVDreadTrack(16, CDVD_MODE_2048, tempbuffer); - - if(retval < 0) { - - return(-1); - - } // ENDIF- Couldn't read the ISO9660 volume track? Fail. - - - - tempdisctype = CDVD_TYPE_UNKNOWN; - - if(layer.d.NumberOfLayers == 0) { - + retval = DVDreadTrack(16, CDVD_MODE_2048, tempbuffer); + if (retval < 0) + { + return(-1); + } // ENDIF- Couldn't read the ISO9660 volume track? Fail. + tempdisctype = CDVD_TYPE_UNKNOWN; + if (layer.d.NumberOfLayers == 0) + { #ifdef VERBOSE_DISC_INFO - - PrintLog("CDVDiso DVD: Found Single-Sided DVD."); - + PrintLog("CDVDiso DVD: Found Single-Sided DVD."); #endif /* VERBOSE_DISC_INFO */ - - disctype = CDVD_TYPE_DETCTDVDS; - - } else { - + disctype = CDVD_TYPE_DETCTDVDS; + } + else + { #ifdef VERBOSE_DISC_INFO - - PrintLog("CDVDiso DVD: Found Dual-Sided DVD."); - + PrintLog("CDVDiso DVD: Found Dual-Sided DVD."); #endif /* VERBOSE_DISC_INFO */ + disctype = CDVD_TYPE_DETCTDVDD; + } // ENDIF- Are we looking at a single layer DVD? (NumberOfLayers + 1) - disctype = CDVD_TYPE_DETCTDVDD; - - } // ENDIF- Are we looking at a single layer DVD? (NumberOfLayers + 1) - - - - i = 0; - - while((playstationname[i] != 0) && - - (playstationname[i] == tempbuffer[8 + i])) i++; - - if(playstationname[i] == 0) { - + i = 0; + while ((playstationname[i] != 0) && + (playstationname[i] == tempbuffer[8 + i])) i++; + if (playstationname[i] == 0) + { #ifdef VERBOSE_DISC_TYPE - - PrintLog("CDVDiso DVD: Found Playstation 2 DVD."); - + PrintLog("CDVDiso DVD: Found Playstation 2 DVD."); #endif /* VERBOSE_DISC_TYPE */ - - tempdisctype = CDVD_TYPE_PS2DVD; - - } else { - + tempdisctype = CDVD_TYPE_PS2DVD; + } + else + { #ifdef VERBOSE_DISC_TYPE - - PrintLog("CDVDiso DVD: Guessing it's a Video DVD."); - + PrintLog("CDVDiso DVD: Guessing it's a Video DVD."); #endif /* VERBOSE_DISC_TYPE */ + tempdisctype = CDVD_TYPE_DVDV; + } // ENDIF- Is this a playstation disc? + for (i = 0; i < 2048; i++) tocbuffer[i] = 0; + if (layer.d.NumberOfLayers == 0) + { + tocbuffer[0] = 0x04; + tocbuffer[4] = 0x86; + tocbuffer[5] = 0x72; + } + else + { + tocbuffer[0] = 0x24; + tocbuffer[4] = 0x41; + tocbuffer[5] = 0x95; + } // ENDIF- Are we looking at a single layer DVD? (NumberOfLayers + 1) + tocbuffer[1] = 0x02; + tocbuffer[2] = 0xF2; + tocbuffer[3] = 0x00; + tocbuffer[16] = 0x00; + tocbuffer[17] = 0x03; + tocbuffer[18] = 0x00; + tocbuffer[19] = 0x00; - tempdisctype = CDVD_TYPE_DVDV; - - } // ENDIF- Is this a playstation disc? - - - - for(i = 0; i < 2048; i++) tocbuffer[i] = 0; - - - - if(layer.d.NumberOfLayers == 0) { - - tocbuffer[0] = 0x04; - - tocbuffer[4] = 0x86; - - tocbuffer[5] = 0x72; - - } else { - - tocbuffer[0] = 0x24; - - tocbuffer[4] = 0x41; - - tocbuffer[5] = 0x95; - - } // ENDIF- Are we looking at a single layer DVD? (NumberOfLayers + 1) - - - - tocbuffer[1] = 0x02; - - tocbuffer[2] = 0xF2; - - tocbuffer[3] = 0x00; - - - - tocbuffer[16] = 0x00; - - tocbuffer[17] = 0x03; - - tocbuffer[18] = 0x00; - - tocbuffer[19] = 0x00; - - - - disctype = tempdisctype; - - return(disctype); - + disctype = tempdisctype; + return(disctype); } // END DVDgetDiskType() - diff --git a/plugins/CDVDisoEFP/src/Win32/DVD.h b/plugins/CDVDisoEFP/src/Win32/DVD.h index b6d05d0e29..2751715dbe 100644 --- a/plugins/CDVDisoEFP/src/Win32/DVD.h +++ b/plugins/CDVDisoEFP/src/Win32/DVD.h @@ -1,74 +1,33 @@ /* DVD.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef DVD_H - #define DVD_H - - - - #define CDVDdefs - #include "PS2Edefs.h" - - - - extern void InitDVDInfo(); - extern s32 DVDreadTrack(u32 lsn, int mode, u8 *buffer); - extern s32 DVDgetTN(cdvdTN *cdvdtn); - extern s32 DVDgetTD(u8 newtrack, cdvdTD *cdvdtd); - extern s32 DVDgetDiskType(); - - - - #endif /* DVD_H */ - diff --git a/plugins/CDVDisoEFP/src/Win32/actualfile.c b/plugins/CDVDisoEFP/src/Win32/actualfile.c index 864bf91717..486d43cf05 100644 --- a/plugins/CDVDisoEFP/src/Win32/actualfile.c +++ b/plugins/CDVDisoEFP/src/Win32/actualfile.c @@ -1,506 +1,233 @@ /* actualfile.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include - - #include // NULL - - #include "logfile.h" - #include "actualfile.h" - - - - -int IsActualFile(const char *filename) { - - DWORD retval; - - - - if(filename == NULL) return(-1); - - - +int IsActualFile(const char *filename) +{ + DWORD retval; + if (filename == NULL) return(-1); #ifdef VERBOSE_FUNCTION_ACTUALFILE - - PrintLog("CDVDiso file: IsActualFile(%s)", filename); - + PrintLog("CDVDiso file: IsActualFile(%s)", filename); #endif /* VERBOSE_FUNCTION_ACTUALFILE */ - - - - retval = GetFileAttributes(filename); - - if(retval == INVALID_FILE_ATTRIBUTES) return(-1); // Name doesn't exist. - - if((retval & FILE_ATTRIBUTE_DIRECTORY) != 0) return(-2); - - - - return(0); // Yep, that's a file. - + retval = GetFileAttributes(filename); + if (retval == INVALID_FILE_ATTRIBUTES) return(-1); // Name doesn't exist. + if ((retval & FILE_ATTRIBUTE_DIRECTORY) != 0) return(-2); + return(0); // Yep, that's a file. } // END IsActualFile() - - - - -void ActualFileDelete(const char *filename) { - +void ActualFileDelete(const char *filename) +{ #ifdef VERBOSE_FUNCTION_ACTUALFILE - - PrintLog("CDVDiso file: ActualFileDelete(%s)", filename); - + PrintLog("CDVDiso file: ActualFileDelete(%s)", filename); #endif /* VERBOSE_FUNCTION_ACTUALFILE */ - - - DeleteFile(filename); - + DeleteFile(filename); } // END ActualFileDelete() - - - - -void ActualFileRename(const char *origname, const char *newname) { - +void ActualFileRename(const char *origname, const char *newname) +{ #ifdef VERBOSE_FUNCTION_ACTUALFILE - - PrintLog("CDVDiso file: ActualFileDelete(%s->%s)", origname, newname); - + PrintLog("CDVDiso file: ActualFileDelete(%s->%s)", origname, newname); #endif /* VERBOSE_FUNCTION_ACTUALFILE */ - - - - MoveFile(origname, newname); - - return; - + MoveFile(origname, newname); + return; } // END ActualFileRename() - - - - -ACTUALHANDLE ActualFileOpenForRead(const char *filename) { - - HANDLE newhandle; - - - - if(filename == NULL) return(NULL); - - - +ACTUALHANDLE ActualFileOpenForRead(const char *filename) +{ + HANDLE newhandle; + if (filename == NULL) return(NULL); #ifdef VERBOSE_FUNCTION_ACTUALFILE - - PrintLog("CDVDiso file: ActualFileOpenForRead(%s)", filename); - + PrintLog("CDVDiso file: ActualFileOpenForRead(%s)", filename); #endif /* VERBOSE_FUNCTION_ACTUALFILE */ - - - - newhandle = CreateFile(filename, - - GENERIC_READ, - - FILE_SHARE_READ, - - NULL, - - OPEN_EXISTING, - - FILE_FLAG_RANDOM_ACCESS, - - NULL); - - if(newhandle == INVALID_HANDLE_VALUE) { - + newhandle = CreateFile(filename, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_FLAG_RANDOM_ACCESS, + NULL); + if (newhandle == INVALID_HANDLE_VALUE) + { #ifdef VERBOSE_WARNING_ACTUALFILE - - PrintLog("CDVDiso file: Error opening file %s", filename); - + PrintLog("CDVDiso file: Error opening file %s", filename); #endif /* VERBOSE_WARNING_ACTUALFILE */ - - return(NULL); - - } // ENDIF- Error? Abort - - - - return(newhandle); - + return(NULL); + } // ENDIF- Error? Abort + return(newhandle); } // END ActualFileOpenForRead() +off64_t ActualFileSize(ACTUALHANDLE handle) +{ + int retval; + BY_HANDLE_FILE_INFORMATION info; + off64_t retsize; - - - -off64_t ActualFileSize(ACTUALHANDLE handle) { - - int retval; - - BY_HANDLE_FILE_INFORMATION info; - - off64_t retsize; - - - - if(handle == NULL) return(-1); - - if(handle == INVALID_HANDLE_VALUE) return(-1); - - - + if (handle == NULL) return(-1); + if (handle == INVALID_HANDLE_VALUE) return(-1); #ifdef VERBOSE_FUNCTION_ACTUALFILE - - PrintLog("CDVDiso file: ActualFileSize()"); - + PrintLog("CDVDiso file: ActualFileSize()"); #endif /* VERBOSE_FUNCTION_ACTUALFILE */ + retval = GetFileInformationByHandle(handle, &info); + if (retval == 0) return(-1); // Handle doesn't exist... - - - retval = GetFileInformationByHandle(handle, &info); - - if(retval == 0) return(-1); // Handle doesn't exist... - - - - retsize = info.nFileSizeHigh; - - retsize *= 0x10000; - - retsize *= 0x10000; - - retsize += info.nFileSizeLow; - - return(retsize); - + retsize = info.nFileSizeHigh; + retsize *= 0x10000; + retsize *= 0x10000; + retsize += info.nFileSizeLow; + return(retsize); } // END ActualFileSize() - - - - -int ActualFileSeek(ACTUALHANDLE handle, off64_t position) { - - // int retval; - - LARGE_INTEGER realpos; - - DWORD errcode; - - - - if(handle == NULL) return(-1); - - if(handle == INVALID_HANDLE_VALUE) return(-1); - - if(position < 0) return(-1); - - - +int ActualFileSeek(ACTUALHANDLE handle, off64_t position) +{ + // int retval; + LARGE_INTEGER realpos; + DWORD errcode; + if (handle == NULL) return(-1); + if (handle == INVALID_HANDLE_VALUE) return(-1); + if (position < 0) return(-1); #ifdef VERBOSE_FUNCTION_ACTUALFILE - - PrintLog("CDVDiso file: ActualFileSeek(%llu)", position); - + PrintLog("CDVDiso file: ActualFileSeek(%llu)", position); #endif /* VERBOSE_FUNCTION_ACTUALFILE */ - - - - realpos.QuadPart = position; - + realpos.QuadPart = position; ////// WinXP code for seek - // retval = SetFilePointerEx(handle, - // realpos, - // NULL, - // FILE_BEGIN); - // if(retval == 0) { - - - ////// Win98 code for seek - - realpos.LowPart = SetFilePointer(handle, - - realpos.LowPart, - - &realpos.HighPart, - - FILE_BEGIN); - - errcode = GetLastError(); - - if((realpos.LowPart == 0xFFFFFFFF) && (errcode != NO_ERROR)) { - - - + realpos.LowPart = SetFilePointer(handle, + realpos.LowPart, + &realpos.HighPart, + FILE_BEGIN); + errcode = GetLastError(); + if ((realpos.LowPart == 0xFFFFFFFF) && (errcode != NO_ERROR)) + { #ifdef VERBOSE_WARNING_ACTUALFILE - - PrintLog("CDVDiso file: Error on seek (%llu)", position); - - PrintError("CDVDiso file", errcode); - + PrintLog("CDVDiso file: Error on seek (%llu)", position); + PrintError("CDVDiso file", errcode); #endif /* VERBOSE_WARNING_ACTUALFILE */ + return(-1); + } // ENDIF- Error? Abort - return(-1); - - } // ENDIF- Error? Abort - - - - return(0); - + return(0); } // END ActualFileSeek() - - - - -int ActualFileRead(ACTUALHANDLE handle, int bytes, char *buffer) { - - int retval; - - DWORD bytesread; - +int ActualFileRead(ACTUALHANDLE handle, int bytes, char *buffer) +{ + int retval; + DWORD bytesread; #ifdef VERBOSE_WARNING_ACTUALFILE - - DWORD errcode; - + DWORD errcode; #endif /* VERBOSE_WARNING_ACTUALFILE */ - - - - if(handle == NULL) return(-1); - - if(handle == INVALID_HANDLE_VALUE) return(-1); - - if(bytes < 1) return(-1); - - if(buffer == NULL) return(-1); - - + if (handle == NULL) return(-1); + if (handle == INVALID_HANDLE_VALUE) return(-1); + if (bytes < 1) return(-1); + if (buffer == NULL) return(-1); #ifdef VERBOSE_FUNCTION_ACTUALFILE - - PrintLog("CDVDiso file: ActualFileRead(%i)", bytes); - + PrintLog("CDVDiso file: ActualFileRead(%i)", bytes); #endif /* VERBOSE_FUNCTION_ACTUALFILE */ - - - retval = ReadFile(handle, buffer, bytes, &bytesread, NULL); - - if(retval == 0) { - + retval = ReadFile(handle, buffer, bytes, &bytesread, NULL); + if (retval == 0) + { #ifdef VERBOSE_WARNING_ACTUALFILE - - errcode = GetLastError(); - - PrintLog("CDVDiso file: Error reading from file"); - - PrintError("CDVDiso file", errcode); - + errcode = GetLastError(); + PrintLog("CDVDiso file: Error reading from file"); + PrintError("CDVDiso file", errcode); #endif /* VERBOSE_WARNING_ACTUALFILE */ - - return(-1); - - } // ENDIF- Error? Abort - - if(bytesread < bytes) { - + return(-1); + } // ENDIF- Error? Abort + if (bytesread < bytes) + { #ifdef VERBOSE_WARNING_ACTUALFILE - - PrintLog("CDVDiso file: Short Block! Only read %i out of %i bytes", bytesread, bytes); - + PrintLog("CDVDiso file: Short Block! Only read %i out of %i bytes", bytesread, bytes); #endif /* VERBOSE_WARNING_ACTUALFILE */ - - } // ENDIF- Error? Abort - - - - return(bytesread); // Send back how many bytes read - + } // ENDIF- Error? Abort + return(bytesread); // Send back how many bytes read } // END ActualFileRead() - - - - -void ActualFileClose(ACTUALHANDLE handle) { - - if(handle == NULL) return; - - if(handle == INVALID_HANDLE_VALUE) return; - - - +void ActualFileClose(ACTUALHANDLE handle) +{ + if (handle == NULL) return; + if (handle == INVALID_HANDLE_VALUE) return; #ifdef VERBOSE_FUNCTION_ACTUALFILE - - PrintLog("CDVDiso file: ActualFileClose()"); - + PrintLog("CDVDiso file: ActualFileClose()"); #endif /* VERBOSE_FUNCTION_ACTUALFILE */ - - - - CloseHandle(handle); - - return; - + CloseHandle(handle); + return; } // END ActualFileClose() - - - - -ACTUALHANDLE ActualFileOpenForWrite(const char *filename) { - - HANDLE newhandle; - - - - if(filename == NULL) return(NULL); - - - +ACTUALHANDLE ActualFileOpenForWrite(const char *filename) +{ + HANDLE newhandle; + if (filename == NULL) return(NULL); #ifdef VERBOSE_FUNCTION_ACTUALFILE - - PrintLog("CDVDiso file: ActualFileOpenForWrite(%s)", filename); - + PrintLog("CDVDiso file: ActualFileOpenForWrite(%s)", filename); #endif /* VERBOSE_FUNCTION_ACTUALFILE */ - - - - newhandle = CreateFile(filename, - - GENERIC_WRITE, - - 0, - - NULL, - - CREATE_ALWAYS, - - FILE_FLAG_SEQUENTIAL_SCAN, - - NULL); - - if(newhandle == INVALID_HANDLE_VALUE) { - + newhandle = CreateFile(filename, + GENERIC_WRITE, + 0, + NULL, + CREATE_ALWAYS, + FILE_FLAG_SEQUENTIAL_SCAN, + NULL); + if (newhandle == INVALID_HANDLE_VALUE) + { #ifdef VERBOSE_WARNING_ACTUALFILE - - PrintLog("CDVDiso file: Error opening file %s", filename); - + PrintLog("CDVDiso file: Error opening file %s", filename); #endif /* VERBOSE_WARNING_ACTUALFILE */ - - return(NULL); - - } // ENDIF- Error? Abort - - - - return(newhandle); - + return(NULL); + } // ENDIF- Error? Abort + return(newhandle); } // END ActualFileOpenForWrite() - - - - -int ActualFileWrite(ACTUALHANDLE handle, int bytes, char *buffer) { - - int retval; - - DWORD byteswritten; - - - - if(handle == NULL) return(-1); - - if(handle == INVALID_HANDLE_VALUE) return(-1); - - if(bytes < 1) return(-1); - - if(buffer == NULL) return(-1); - - +int ActualFileWrite(ACTUALHANDLE handle, int bytes, char *buffer) +{ + int retval; + DWORD byteswritten; + if (handle == NULL) return(-1); + if (handle == INVALID_HANDLE_VALUE) return(-1); + if (bytes < 1) return(-1); + if (buffer == NULL) return(-1); #ifdef VERBOSE_FUNCTION_ACTUALFILE - - PrintLog("CDVDiso file: ActualFileWrite(%i)", bytes); - + PrintLog("CDVDiso file: ActualFileWrite(%i)", bytes); #endif /* VERBOSE_FUNCTION_ACTUALFILE */ - - - retval = WriteFile(handle, buffer, bytes, &byteswritten, NULL); - - if(retval == 0) { - + retval = WriteFile(handle, buffer, bytes, &byteswritten, NULL); + if (retval == 0) + { #ifdef VERBOSE_WARNING_ACTUALFILE - - PrintLog("CDVDiso file: Error writing to file!"); - + PrintLog("CDVDiso file: Error writing to file!"); #endif /* VERBOSE_WARNING_ACTUALFILE */ + // return(-1); + } // ENDIF- Error? Abort - // return(-1); - - } // ENDIF- Error? Abort - - - - return(byteswritten); // Send back how many bytes written - + return(byteswritten); // Send back how many bytes written } // END ActualFileWrite() - diff --git a/plugins/CDVDisoEFP/src/Win32/actualfile.h b/plugins/CDVDisoEFP/src/Win32/actualfile.h index f1cc9c421b..dbafb6913c 100644 --- a/plugins/CDVDisoEFP/src/Win32/actualfile.h +++ b/plugins/CDVDisoEFP/src/Win32/actualfile.h @@ -1,104 +1,45 @@ /* actualfile.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef ACTUALFILE_H - #define ACTUALFILE_H - - - - #include - - #include // off64_t #include "PS2Etypes.h" - - - #define ACTUALHANDLE HANDLE - #define ACTUALHANDLENULL NULL - - - // #define VERBOSE_FUNCTION_ACTUALFILE - // #define VERBOSE_WARNING_ACTUALFILE - - - - extern int IsActualFile(const char *filename); - extern void ActualFileDelete(const char *filename); - extern void ActualFileRename(const char *origname, const char *newname); - - - extern ACTUALHANDLE ActualFileOpenForRead(const char *filename); - extern off64_t ActualFileSize(ACTUALHANDLE handle); - extern int ActualFileSeek(ACTUALHANDLE handle, off64_t position); - extern int ActualFileRead(ACTUALHANDLE handle, int bytes, char *buffer); - extern void ActualFileClose(ACTUALHANDLE handle); - - - extern ACTUALHANDLE ActualFileOpenForWrite(const char *filename); - extern int ActualFileWrite(ACTUALHANDLE handle, int bytes, char *buffer); - - - - #endif /* ACTUALFILE_H */ - diff --git a/plugins/CDVDisoEFP/src/Win32/conf.c b/plugins/CDVDisoEFP/src/Win32/conf.c index abc603e9cd..0bc3227a98 100644 --- a/plugins/CDVDisoEFP/src/Win32/conf.c +++ b/plugins/CDVDisoEFP/src/Win32/conf.c @@ -1,390 +1,217 @@ -/* conf.c - - * Copyright (C) 2002-2005 PCSX2 Team - - * - - * This program is free software; you can redistribute it and/or modify - - * it under the terms of the GNU General Public License as published by - - * the Free Software Foundation; either version 2 of the License, or - - * (at your option) any later version. - - * - - * This program is distributed in the hope that it will be useful, - - * but WITHOUT ANY WARRANTY; without even the implied warranty of - - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - - * GNU General Public License for more details. - - * - - * You should have received a copy of the GNU General Public License - - * along with this program; if not, write to the Free Software - - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - * - - * PCSX2 members can be contacted through their website at www.pcsx2.net. - - */ - - - -#include // errno - -#include // NULL - -#include // sprintf() - -#include // getenv() - -#include // strerror() - -#include // mkdir(), stat() - -#include // mkdir(), stat(), fork() - -#include // stat(), fork(), execlp() - - - -#include // CreateProcess() - - - -// #define CDVDdefs - -// #include "../PS2Edefs.h" - -#include "../PS2Etypes.h" // u8 - -#include "logfile.h" - -#include "../ini.h" - -#include "conf.h" - - - - - -const char *confnames[] = { "IsoFile", "Device", "OpenOnStart", "OpenOnRestart", NULL }; - -const u8 defaultdevice[] = DEFAULT_DEVICE; - -const char defaulthome[] = "inis"; - -const char defaultdirectory[] = "HideMe.PS2E"; - -const char defaultfile[] = "CDVDisoEFP.ini"; - - - -char confdirname[256]; - -char conffilename[256]; - - - -CDVDconf conf; - - - - - -void InitConf() { - - DWORD retval; - - int i; - - int pos; - - char *envptr; - - - -#ifdef VERBOSE_FUNCTION_CONF - - PrintLog("CDVD config: InitConf()"); - -#endif /* VERBOSE_FUNCTION_CONF */ - - - - conf.isoname[0] = 0; // Empty the iso name - - - - i = 0; - - while((i < 255) && defaultdevice[i] != 0) { - - conf.devicename[i] = defaultdevice[i]; - - i++; - - } // ENDWHILE- copying the default CD/DVD name in - - conf.devicename[i] = 0; // 0-terminate the device name - - - - // Locating directory and file positions - - pos = 0; - - envptr = NULL; - - // envptr = getenv("HOME"); - - if(envptr == NULL) { - - // = - - retval = GetCurrentDirectory(253, confdirname); - - if(retval > 0) { - - pos = retval; - - } else { - - pos = 2; - - confdirname[0] = '.'; - - confdirname[1] = '\\'; - - } // ENDIF- Did we retrieve a directory reference? - - - - i = 0; - - while(i < pos) { - - conffilename[i] = confdirname[i]; - - i++; - - } // ENDWHILE- Copying dir info (so far) into file info - - - - if(confdirname[pos-1] != '\\') { - - confdirname[pos] = '\\'; - - conffilename[pos] = '\\'; - - pos++; - - } // ENDIF- No directory separator here? Add one. - - - - i = 0; - - while((pos < 253) && (defaulthome[i] != 0)) { - - confdirname[pos] = defaulthome[i]; - - conffilename[pos] = defaulthome[i]; - - pos++; - - i++; - - } // ENDWHILE- putting an offset where to store ini data - - - - } else { - - // = / - - i = 0; - - while((pos < 253) && (*(envptr + i) != 0)) { - - confdirname[pos] = *(envptr + i); - - conffilename[pos] = *(envptr + i); - - pos++; - - i++; - - } // ENDWHILE- copying home directory info in - - - - if(confdirname[pos-1] != '\\') { - - confdirname[pos] = '\\'; - - conffilename[pos] = '\\'; - - pos++; - - } // ENDIF- No directory separator here? Add one. - - - - i = 0; - - while((pos < 253) && (defaultdirectory[i] != 0)) { - - confdirname[pos] = defaultdirectory[i]; - - conffilename[pos] = defaultdirectory[i]; - - pos++; - - i++; - - } // NEXT- putting a default place to store configuration data - - } // ENDIF- No Home directory? - - - - confdirname[pos] = 0; // Directory reference finished - - - - // += / - - if(conffilename[pos-1] != '\\') { - - conffilename[pos] = '\\'; - - pos++; - - } // ENDIF- No directory separator here? Add one. - - - - i = 0; - - while((pos < 253) && (defaultfile[i] != 0)) { - - conffilename[pos] = defaultfile[i]; - - pos++; - - i++; - - } // NEXT- putting a default place to store configuration data - - - - conffilename[pos] = 0; // File reference finished - - - -#ifdef VERBOSE_FUNCTION_CONF - - PrintLog("CDVD config: Directory: %s", confdirname); - - PrintLog("CDVD config: File: %s", conffilename); - -#endif /* VERBOSE_FUNCTION_CONF */ - -} // END InitConf() - - - - - -void LoadConf() { - - int retval; - - - -#ifdef VERBOSE_FUNCTION_CONF - - PrintLog("CDVD config: LoadConf()"); - -#endif /* VERBOSE_FUNCTION_CONF */ - - - - retval = INILoadString(conffilename, "Settings", "IsoFile", conf.isoname); - - if(retval < 0) { - - sprintf(conf.isoname, "[Put an Image File here]"); - - } // ENDIF- Couldn't find keyword? Fill in a default - - - - retval = INILoadString(conffilename, "Settings", "Device", conf.devicename); - - if(retval < 0) { - - sprintf(conf.devicename, "D:"); - - } // ENDIF- Couldn't find keyword? Fill in a default - - - - retval = INILoadUInt(conffilename, "Settings", "OpenOnStart", &conf.startconfigure); - - if(retval < 0) { - - conf.startconfigure = 0; // FALSE - - } // ENDIF- Couldn't find keyword? Fill in a default - - - - retval = INILoadUInt(conffilename, "Settings", "OpenOnRestart", &conf.restartconfigure); - - if(retval < 0) { - - conf.restartconfigure = 1; // TRUE - - } // ENDIF- Couldn't find keyword? Fill in a default - -} // END LoadConf() - - - - - -void SaveConf() { - -#ifdef VERBOSE_FUNCTION_CONF - - PrintLog("CDVD config: SaveConf()"); - -#endif /* VERBOSE_FUNCTION_CONF */ - - - - mkdir(confdirname); - - - - INISaveString(conffilename, "Settings", "IsoFile", conf.isoname); - - INISaveString(conffilename, "Settings", "Device", conf.devicename); - - INISaveUInt(conffilename, "Settings", "OpenOnStart", conf.startconfigure); - - INISaveUInt(conffilename, "Settings", "OpenOnRestart", conf.restartconfigure); - -} // END SaveConf() - +/* conf.c + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + +#include // errno +#include // NULL +#include // sprintf() +#include // getenv() +#include // strerror() +#include // mkdir(), stat() +#include // mkdir(), stat(), fork() +#include // stat(), fork(), execlp() + +#include // CreateProcess() + +// #define CDVDdefs +// #include "../PS2Edefs.h" +#include "../PS2Etypes.h" // u8 +#include "logfile.h" +#include "../ini.h" +#include "conf.h" + + +const char *confnames[] = { "IsoFile", "Device", "OpenOnStart", "OpenOnRestart", NULL }; +const u8 defaultdevice[] = DEFAULT_DEVICE; +const char defaulthome[] = "inis"; +const char defaultdirectory[] = "HideMe.PS2E"; +const char defaultfile[] = "CDVDisoEFP.ini"; + +char confdirname[256]; +char conffilename[256]; + +CDVDconf conf; + + +void InitConf() +{ + DWORD retval; + int i; + int pos; + char *envptr; + +#ifdef VERBOSE_FUNCTION_CONF + PrintLog("CDVD config: InitConf()"); +#endif /* VERBOSE_FUNCTION_CONF */ + + conf.isoname[0] = 0; // Empty the iso name + + i = 0; + while ((i < 255) && defaultdevice[i] != 0) + { + conf.devicename[i] = defaultdevice[i]; + i++; + } // ENDWHILE- copying the default CD/DVD name in + conf.devicename[i] = 0; // 0-terminate the device name + + // Locating directory and file positions + pos = 0; + envptr = NULL; + // envptr = getenv("HOME"); + if (envptr == NULL) + { + // = + retval = GetCurrentDirectory(253, confdirname); + if (retval > 0) + { + pos = retval; + } + else + { + pos = 2; + confdirname[0] = '.'; + confdirname[1] = '\\'; + } // ENDIF- Did we retrieve a directory reference? + + i = 0; + while (i < pos) + { + conffilename[i] = confdirname[i]; + i++; + } // ENDWHILE- Copying dir info (so far) into file info + + if (confdirname[pos-1] != '\\') + { + confdirname[pos] = '\\'; + conffilename[pos] = '\\'; + pos++; + } // ENDIF- No directory separator here? Add one. + + i = 0; + while ((pos < 253) && (defaulthome[i] != 0)) + { + confdirname[pos] = defaulthome[i]; + conffilename[pos] = defaulthome[i]; + pos++; + i++; + } // ENDWHILE- putting an offset where to store ini data + + } + else + { + // = / + i = 0; + while ((pos < 253) && (*(envptr + i) != 0)) + { + confdirname[pos] = *(envptr + i); + conffilename[pos] = *(envptr + i); + pos++; + i++; + } // ENDWHILE- copying home directory info in + + if (confdirname[pos-1] != '\\') + { + confdirname[pos] = '\\'; + conffilename[pos] = '\\'; + pos++; + } // ENDIF- No directory separator here? Add one. + + i = 0; + while ((pos < 253) && (defaultdirectory[i] != 0)) + { + confdirname[pos] = defaultdirectory[i]; + conffilename[pos] = defaultdirectory[i]; + pos++; + i++; + } // NEXT- putting a default place to store configuration data + } // ENDIF- No Home directory? + + confdirname[pos] = 0; // Directory reference finished + + // += / + if (conffilename[pos-1] != '\\') + { + conffilename[pos] = '\\'; + pos++; + } // ENDIF- No directory separator here? Add one. + + i = 0; + while ((pos < 253) && (defaultfile[i] != 0)) + { + conffilename[pos] = defaultfile[i]; + pos++; + i++; + } // NEXT- putting a default place to store configuration data + + conffilename[pos] = 0; // File reference finished + +#ifdef VERBOSE_FUNCTION_CONF + PrintLog("CDVD config: Directory: %s", confdirname); + PrintLog("CDVD config: File: %s", conffilename); +#endif /* VERBOSE_FUNCTION_CONF */ +} // END InitConf() + + +void LoadConf() +{ + int retval; + +#ifdef VERBOSE_FUNCTION_CONF + PrintLog("CDVD config: LoadConf()"); +#endif /* VERBOSE_FUNCTION_CONF */ + + retval = INILoadString(conffilename, "Settings", "IsoFile", conf.isoname); + if (retval < 0) + { + sprintf(conf.isoname, "[Put an Image File here]"); + } // ENDIF- Couldn't find keyword? Fill in a default + + retval = INILoadString(conffilename, "Settings", "Device", conf.devicename); + if (retval < 0) + { + sprintf(conf.devicename, "D:"); + } // ENDIF- Couldn't find keyword? Fill in a default + + retval = INILoadUInt(conffilename, "Settings", "OpenOnStart", &conf.startconfigure); + if (retval < 0) + { + conf.startconfigure = 0; // FALSE + } // ENDIF- Couldn't find keyword? Fill in a default + + retval = INILoadUInt(conffilename, "Settings", "OpenOnRestart", &conf.restartconfigure); + if (retval < 0) + { + conf.restartconfigure = 1; // TRUE + } // ENDIF- Couldn't find keyword? Fill in a default +} // END LoadConf() + + +void SaveConf() +{ +#ifdef VERBOSE_FUNCTION_CONF + PrintLog("CDVD config: SaveConf()"); +#endif /* VERBOSE_FUNCTION_CONF */ + + mkdir(confdirname); + + INISaveString(conffilename, "Settings", "IsoFile", conf.isoname); + INISaveString(conffilename, "Settings", "Device", conf.devicename); + INISaveUInt(conffilename, "Settings", "OpenOnStart", conf.startconfigure); + INISaveUInt(conffilename, "Settings", "OpenOnRestart", conf.restartconfigure); +} // END SaveConf() diff --git a/plugins/CDVDisoEFP/src/Win32/conf.h b/plugins/CDVDisoEFP/src/Win32/conf.h index e490985a89..8380d8fe3e 100644 --- a/plugins/CDVDisoEFP/src/Win32/conf.h +++ b/plugins/CDVDisoEFP/src/Win32/conf.h @@ -1,108 +1,47 @@ /* conf.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - #ifndef CONF_H - #define CONF_H - - - - #define CDVDdefs - #include "../PS2Edefs.h" - - - - #define VERBOSE_FUNCTION_CONF - - - - // Configuration Data - - -typedef struct { - - u8 isoname[256]; - - u8 devicename[256]; - - unsigned int startconfigure; - - unsigned int restartconfigure; - +typedef struct +{ + u8 isoname[256]; + u8 devicename[256]; + unsigned int startconfigure; + unsigned int restartconfigure; } CDVDconf; - extern CDVDconf conf; - - #define DEFAULT_DEVICE "K:\\" - - - - // Configuration Functions - - - extern void InitConf(); - extern void LoadConf(); - extern void SaveConf(); - - - extern void ExecCfg(char *arg); - - - - #endif /* CONF_H */ - diff --git a/plugins/CDVDisoEFP/src/Win32/conversionbox.c b/plugins/CDVDisoEFP/src/Win32/conversionbox.c index ea78fc622a..f13c92d04e 100644 --- a/plugins/CDVDisoEFP/src/Win32/conversionbox.c +++ b/plugins/CDVDisoEFP/src/Win32/conversionbox.c @@ -1,750 +1,370 @@ /* conversionbox.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include - #include // ComboBox_AddString(), CheckDlgButton() - #include // NULL - // #include - - - #include // sprintf() - #include // strcpy() - #include // off64_t - - - #include "isofile.h" - #include "isocompress.h" // compressdesc[] - #include "imagetype.h" // imagedata[] - #include "multifile.h" // multinames[] - #include "toc.h" - #include "progressbox.h" - #include "mainbox.h" - #include "screens.h" // DLG_..., IDC_... - #include "conversionbox.h" - - - - HWND conversionboxwindow; - - - - -void ConversionBoxDestroy() { - - if(conversionboxwindow != NULL) { - - EndDialog(conversionboxwindow, FALSE); - - conversionboxwindow = NULL; - - } // ENDIF- Do we have a Main Window still? - +void ConversionBoxDestroy() +{ + if (conversionboxwindow != NULL) + { + EndDialog(conversionboxwindow, FALSE); + conversionboxwindow = NULL; + } // ENDIF- Do we have a Main Window still? } // END ConversionBoxDestroy() - - - - -void ConversionBoxUnfocus() { - - // gtk_widget_set_sensitive(conversionbox.file, FALSE); - - // gtk_widget_set_sensitive(conversionbox.selectbutton, FALSE); - - // gtk_widget_set_sensitive(conversionbox.compress, FALSE); - - // gtk_widget_set_sensitive(conversionbox.multi, FALSE); - - // gtk_widget_set_sensitive(conversionbox.okbutton, FALSE); - - // gtk_widget_set_sensitive(conversionbox.cancelbutton, FALSE); - - ShowWindow(conversionboxwindow, SW_HIDE); - +void ConversionBoxUnfocus() +{ + // gtk_widget_set_sensitive(conversionbox.file, FALSE); + // gtk_widget_set_sensitive(conversionbox.selectbutton, FALSE); + // gtk_widget_set_sensitive(conversionbox.compress, FALSE); + // gtk_widget_set_sensitive(conversionbox.multi, FALSE); + // gtk_widget_set_sensitive(conversionbox.okbutton, FALSE); + // gtk_widget_set_sensitive(conversionbox.cancelbutton, FALSE); + ShowWindow(conversionboxwindow, SW_HIDE); } // END ConversionBoxUnfocus() +void ConversionBoxFileEvent() +{ + int returnval; + char templine[256]; + struct IsoFile *tempfile; + GetDlgItemText(conversionboxwindow, IDC_0402, templine, 256); + returnval = IsIsoFile(templine); + if (returnval == -1) + { + SetDlgItemText(conversionboxwindow, IDC_0404, "File Type: ---"); + return; + } // ENDIF- Not a name of any sort? + if (returnval == -2) + { + SetDlgItemText(conversionboxwindow, IDC_0404, "File Type: Not a file"); + return; + } // ENDIF- Not a regular file? + if (returnval == -3) + { + SetDlgItemText(conversionboxwindow, IDC_0404, "File Type: Not a valid image file"); + return; + } // ENDIF- Not a regular file? - - -void ConversionBoxFileEvent() { - - int returnval; - - char templine[256]; - - struct IsoFile *tempfile; - - - - GetDlgItemText(conversionboxwindow, IDC_0402, templine, 256); - - returnval = IsIsoFile(templine); - - if(returnval == -1) { - - SetDlgItemText(conversionboxwindow, IDC_0404, "File Type: ---"); - - return; - - } // ENDIF- Not a name of any sort? - - - - if(returnval == -2) { - - SetDlgItemText(conversionboxwindow, IDC_0404, "File Type: Not a file"); - - return; - - } // ENDIF- Not a regular file? - - - - if(returnval == -3) { - - SetDlgItemText(conversionboxwindow, IDC_0404, "File Type: Not a valid image file"); - - return; - - } // ENDIF- Not a regular file? - - - - if(returnval == -4) { - - SetDlgItemText(conversionboxwindow, IDC_0404, "File Type: Missing Table File (will rebuild)"); - - return; - - } // ENDIF- Not a regular file? - - - - tempfile = IsoFileOpenForRead(templine); - - sprintf(templine, "File Type: %s%s%s", - - multinames[tempfile->multi], - - tempfile->imagename, - - compressdesc[tempfile->compress]); - - SetDlgItemText(conversionboxwindow, IDC_0404, templine); - - tempfile = IsoFileClose(tempfile); - - return; - + if (returnval == -4) + { + SetDlgItemText(conversionboxwindow, IDC_0404, "File Type: Missing Table File (will rebuild)"); + return; + } // ENDIF- Not a regular file? + tempfile = IsoFileOpenForRead(templine); + sprintf(templine, "File Type: %s%s%s", + multinames[tempfile->multi], + tempfile->imagename, + compressdesc[tempfile->compress]); + SetDlgItemText(conversionboxwindow, IDC_0404, templine); + tempfile = IsoFileClose(tempfile); + return; } // END ConversionBoxFileEvent() - - - - -void ConversionBoxRefocus() { - - ConversionBoxFileEvent(); - - - - // gtk_widget_set_sensitive(conversionbox.file, TRUE); - - // gtk_widget_set_sensitive(conversionbox.selectbutton, TRUE); - - // gtk_widget_set_sensitive(conversionbox.compress, TRUE); - - // gtk_widget_set_sensitive(conversionbox.multi, TRUE); - - // gtk_widget_set_sensitive(conversionbox.okbutton, TRUE); - - // gtk_widget_set_sensitive(conversionbox.cancelbutton, TRUE); - - // gtk_window_set_focus(GTK_WINDOW(conversionbox.window), conversionbox.file); - - ShowWindow(conversionboxwindow, SW_SHOW); - - SetActiveWindow(conversionboxwindow); - +void ConversionBoxRefocus() +{ + ConversionBoxFileEvent(); + // gtk_widget_set_sensitive(conversionbox.file, TRUE); + // gtk_widget_set_sensitive(conversionbox.selectbutton, TRUE); + // gtk_widget_set_sensitive(conversionbox.compress, TRUE); + // gtk_widget_set_sensitive(conversionbox.multi, TRUE); + // gtk_widget_set_sensitive(conversionbox.okbutton, TRUE); + // gtk_widget_set_sensitive(conversionbox.cancelbutton, TRUE); + // gtk_window_set_focus(GTK_WINDOW(conversionbox.window), conversionbox.file); + ShowWindow(conversionboxwindow, SW_SHOW); + SetActiveWindow(conversionboxwindow); } // END ConversionBoxRefocus() - - - - -void ConversionBoxCancelEvent() { - - // ShowWindow(conversionboxwindow, SW_HIDE); - - ConversionBoxDestroy(); - - MainBoxRefocus(); - - return; - +void ConversionBoxCancelEvent() +{ + // ShowWindow(conversionboxwindow, SW_HIDE); + ConversionBoxDestroy(); + MainBoxRefocus(); + return; } // END ConversionBoxCancelEvent() - - - - -void ConversionBoxOKEvent() { - - char templine[256]; - - char tempblock[2352]; - - char filename[256]; - - HWND tempitem; - - int compressmethod; - - int multi; - - struct IsoFile *fromfile; - - struct IsoFile *tofile; - - int i; - - off64_t endsector; - - int stop; - - int retval; - - - - ConversionBoxUnfocus(); - - - - GetDlgItemText(conversionboxwindow, IDC_0402, filename, 256); - - if(IsIsoFile(filename) < 0) { - - ConversionBoxRefocus(); - - MessageBox(conversionboxwindow, - - "Not a Valid Image File.", - - "CDVDisoEFP Message", - - MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); - - return; - - } // ENDIF- Not an Iso File? Stop early. - - - - tempitem = GetDlgItem(conversionboxwindow, IDC_0406); - - compressmethod = ComboBox_GetCurSel(tempitem); - - tempitem = NULL; - - if(compressmethod > 0) compressmethod += 2; - - - - multi = 0; - - if(IsDlgButtonChecked(conversionboxwindow, IDC_0408)) multi = 1; - - - - fromfile = NULL; - - fromfile = IsoFileOpenForRead(filename); - - if(fromfile == NULL) { - - ConversionBoxRefocus(); - - MessageBox(conversionboxwindow, - - "Cannot opening the source file", - - "CDVDisoEFP Message", - - MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); - - return; - - } // ENDIF- Not an Iso File? Stop early. - - - - if((compressmethod == fromfile->compress) && - - (multi == fromfile->multi)) { - - fromfile = IsoFileClose(fromfile); - - ConversionBoxRefocus(); - - MessageBox(conversionboxwindow, - - "Compress/Multifile methods match - no need to convert", - - "CDVDisoEFP Message", - - MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); - - return; - - } // ENDIF- Not an Iso File? Stop early. - - - - tofile = IsoFileOpenForWrite(filename, - - GetImageTypeConvertTo(fromfile->imagetype), - - multi, - - compressmethod); - - if(tofile == NULL) { - - fromfile = IsoFileClose(fromfile); - - ConversionBoxRefocus(); - - MessageBox(conversionboxwindow, - - "Cannot create the new file", - - "CDVDisoEFP Message", - - MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); - - return; - - } // ENDIF- Not an Iso File? Stop early. - - - - if(fromfile->multi == 1) { - - i = 0; - - while((i < 10) && - - (IsoFileSeek(fromfile, fromfile->multisectorend[i] + 1) == 0)) i++; - - endsector = fromfile->multisectorend[fromfile->multiend]; - - } else { - - endsector = fromfile->filesectorsize; - - } // ENDIF- Get ending sector from multifile? (Or single file?) - - IsoFileSeek(fromfile, 0); - - - - // Open Progress Bar - - sprintf(templine, "%s: %s%s -> %s%s", - - filename, - - multinames[fromfile->multi], - - compressdesc[fromfile->compress], - - multinames[tofile->multi], - - compressdesc[tofile->compress]); - - ProgressBoxStart(templine, endsector); - - - - tofile->cdvdtype = fromfile->cdvdtype; - - for(i = 0; i < 2048; i++) tofile->toc[i] = fromfile->toc[i]; - - - - stop = 0; - - mainboxstop = 0; - - progressboxstop = 0; - - while((stop == 0) && (tofile->sectorpos < endsector)) { - - retval = IsoFileRead(fromfile, tempblock); - - if(retval < 0) { - - MessageBox(conversionboxwindow, - - "Trouble reading source file", - - "CDVDisoEFP Message", - - MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); - - stop = 1; - - } else { - - retval = IsoFileWrite(tofile, tempblock); - - if(retval < 0) { - - MessageBox(conversionboxwindow, - - "Trouble writing new file", - - "CDVDisoEFP Message", - - MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); - - stop = 1; - - } // ENDIF- Trouble writing out the next block? - - } // ENDIF- Trouble reading in the next block? - - - - ProgressBoxTick(tofile->sectorpos); - - - - if(mainboxstop != 0) stop = 2; - - if(progressboxstop != 0) stop = 2; - - } // ENDWHILE- Not stopped for some reason... - - - - ProgressBoxStop(); - - - - if(stop == 0) { - - if(tofile->multi == 1) tofile->name[tofile->multipos] = '0'; // First file - - strcpy(templine, tofile->name); - - - - // fromfile = IsoFileCloseAndDelete(fromfile); - - fromfile = IsoFileClose(fromfile); - - - - IsoSaveTOC(tofile); - - tofile = IsoFileClose(tofile); - - SetDlgItemText(mainboxwindow, IDC_0202, templine); - - - - } else { - - fromfile = IsoFileClose(fromfile); - - tofile = IsoFileCloseAndDelete(tofile); - - } // ENDIF- Did we succeed in the transfer? - - - - ConversionBoxRefocus(); - - if(stop == 0) ConversionBoxCancelEvent(); - - return; - +void ConversionBoxOKEvent() +{ + char templine[256]; + char tempblock[2352]; + char filename[256]; + HWND tempitem; + int compressmethod; + int multi; + struct IsoFile *fromfile; + struct IsoFile *tofile; + int i; + off64_t endsector; + int stop; + int retval; + ConversionBoxUnfocus(); + GetDlgItemText(conversionboxwindow, IDC_0402, filename, 256); + if (IsIsoFile(filename) < 0) + { + ConversionBoxRefocus(); + MessageBox(conversionboxwindow, + "Not a Valid Image File.", + "CDVDisoEFP Message", + MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); + return; + } // ENDIF- Not an Iso File? Stop early. + tempitem = GetDlgItem(conversionboxwindow, IDC_0406); + compressmethod = ComboBox_GetCurSel(tempitem); + tempitem = NULL; + if (compressmethod > 0) compressmethod += 2; + + multi = 0; + if (IsDlgButtonChecked(conversionboxwindow, IDC_0408)) multi = 1; + fromfile = NULL; + fromfile = IsoFileOpenForRead(filename); + if (fromfile == NULL) + { + ConversionBoxRefocus(); + MessageBox(conversionboxwindow, + "Cannot opening the source file", + "CDVDisoEFP Message", + MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); + return; + } // ENDIF- Not an Iso File? Stop early. + + if ((compressmethod == fromfile->compress) && + (multi == fromfile->multi)) + { + fromfile = IsoFileClose(fromfile); + ConversionBoxRefocus(); + MessageBox(conversionboxwindow, + "Compress/Multifile methods match - no need to convert", + "CDVDisoEFP Message", + MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); + return; + } // ENDIF- Not an Iso File? Stop early. + tofile = IsoFileOpenForWrite(filename, + GetImageTypeConvertTo(fromfile->imagetype), + multi, + compressmethod); + if (tofile == NULL) + { + fromfile = IsoFileClose(fromfile); + ConversionBoxRefocus(); + MessageBox(conversionboxwindow, + "Cannot create the new file", + "CDVDisoEFP Message", + MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); + return; + } // ENDIF- Not an Iso File? Stop early. + if (fromfile->multi == 1) + { + i = 0; + while ((i < 10) && + (IsoFileSeek(fromfile, fromfile->multisectorend[i] + 1) == 0)) i++; + endsector = fromfile->multisectorend[fromfile->multiend]; + } + else + { + endsector = fromfile->filesectorsize; + } // ENDIF- Get ending sector from multifile? (Or single file?) + IsoFileSeek(fromfile, 0); + // Open Progress Bar + sprintf(templine, "%s: %s%s -> %s%s", + filename, + multinames[fromfile->multi], + compressdesc[fromfile->compress], + multinames[tofile->multi], + compressdesc[tofile->compress]); + ProgressBoxStart(templine, endsector); + + tofile->cdvdtype = fromfile->cdvdtype; + for (i = 0; i < 2048; i++) tofile->toc[i] = fromfile->toc[i]; + stop = 0; + mainboxstop = 0; + progressboxstop = 0; + while ((stop == 0) && (tofile->sectorpos < endsector)) + { + retval = IsoFileRead(fromfile, tempblock); + if (retval < 0) + { + MessageBox(conversionboxwindow, + "Trouble reading source file", + "CDVDisoEFP Message", + MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); + stop = 1; + } + else + { + retval = IsoFileWrite(tofile, tempblock); + if (retval < 0) + { + MessageBox(conversionboxwindow, + "Trouble writing new file", + "CDVDisoEFP Message", + MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); + stop = 1; + } // ENDIF- Trouble writing out the next block? + } // ENDIF- Trouble reading in the next block? + ProgressBoxTick(tofile->sectorpos); + if (mainboxstop != 0) stop = 2; + if (progressboxstop != 0) stop = 2; + } // ENDWHILE- Not stopped for some reason... + ProgressBoxStop(); + if (stop == 0) + { + if (tofile->multi == 1) tofile->name[tofile->multipos] = '0'; // First file + strcpy(templine, tofile->name); + // fromfile = IsoFileCloseAndDelete(fromfile); + fromfile = IsoFileClose(fromfile); + + IsoSaveTOC(tofile); + tofile = IsoFileClose(tofile); + SetDlgItemText(mainboxwindow, IDC_0202, templine); + + } + else + { + fromfile = IsoFileClose(fromfile); + tofile = IsoFileCloseAndDelete(tofile); + } // ENDIF- Did we succeed in the transfer? + ConversionBoxRefocus(); + if (stop == 0) ConversionBoxCancelEvent(); + return; } // END ConversionBoxOKEvent() +void ConversionBoxBrowseEvent() +{ + OPENFILENAME filebox; + char newfilename[256]; + BOOL returnbool; + filebox.lStructSize = sizeof(filebox); + filebox.hwndOwner = conversionboxwindow; + filebox.hInstance = NULL; + filebox.lpstrFilter = fileselection; + filebox.lpstrCustomFilter = NULL; + filebox.nFilterIndex = 0; + filebox.lpstrFile = newfilename; + filebox.nMaxFile = 256; + filebox.lpstrFileTitle = NULL; + filebox.nMaxFileTitle = 0; + filebox.lpstrInitialDir = NULL; + filebox.lpstrTitle = NULL; + filebox.Flags = OFN_FILEMUSTEXIST + | OFN_NOCHANGEDIR + | OFN_HIDEREADONLY; + filebox.nFileOffset = 0; + filebox.nFileExtension = 0; + filebox.lpstrDefExt = NULL; + filebox.lCustData = 0; + filebox.lpfnHook = NULL; + filebox.lpTemplateName = NULL; + GetDlgItemText(conversionboxwindow, IDC_0402, newfilename, 256); + returnbool = GetOpenFileName(&filebox); + if (returnbool != FALSE) + { + SetDlgItemText(conversionboxwindow, IDC_0402, newfilename); + } // ENDIF- User actually selected a name? Save it. - -void ConversionBoxBrowseEvent() { - - OPENFILENAME filebox; - - char newfilename[256]; - - BOOL returnbool; - - - - filebox.lStructSize = sizeof(filebox); - - filebox.hwndOwner = conversionboxwindow; - - filebox.hInstance = NULL; - - filebox.lpstrFilter = fileselection; - - filebox.lpstrCustomFilter = NULL; - - filebox.nFilterIndex = 0; - - filebox.lpstrFile = newfilename; - - filebox.nMaxFile = 256; - - filebox.lpstrFileTitle = NULL; - - filebox.nMaxFileTitle = 0; - - filebox.lpstrInitialDir = NULL; - - filebox.lpstrTitle = NULL; - - filebox.Flags = OFN_FILEMUSTEXIST - - | OFN_NOCHANGEDIR - - | OFN_HIDEREADONLY; - - filebox.nFileOffset = 0; - - filebox.nFileExtension = 0; - - filebox.lpstrDefExt = NULL; - - filebox.lCustData = 0; - - filebox.lpfnHook = NULL; - - filebox.lpTemplateName = NULL; - - - - GetDlgItemText(conversionboxwindow, IDC_0402, newfilename, 256); - - returnbool = GetOpenFileName(&filebox); - - if(returnbool != FALSE) { - - SetDlgItemText(conversionboxwindow, IDC_0402, newfilename); - - } // ENDIF- User actually selected a name? Save it. - - - - return; - + return; } // END ConversionBoxBrowseEvent() +void ConversionBoxDisplay() +{ + char templine[256]; + HWND itemptr; + int itemcount; + // Adjust window position? + // Pull the name from the Main Window... for a starting place. + GetDlgItemText(mainboxwindow, IDC_0202, templine, 256); + SetDlgItemText(conversionboxwindow, IDC_0402, templine); + // ConversionBoxFileEvent(); // Needed? + itemptr = GetDlgItem(conversionboxwindow, IDC_0406); // Compression Combo + itemcount = 0; + while (compressnames[itemcount] != NULL) + { + ComboBox_AddString(itemptr, compressnames[itemcount]); + itemcount++; + } // ENDWHILE- loading compression types into combo box + ComboBox_SetCurSel(itemptr, 0); // First Selection? + itemptr = NULL; + CheckDlgButton(conversionboxwindow, IDC_0408, FALSE); // Start unchecked - - -void ConversionBoxDisplay() { - - char templine[256]; - - HWND itemptr; - - int itemcount; - - - - // Adjust window position? - - - - // Pull the name from the Main Window... for a starting place. - - GetDlgItemText(mainboxwindow, IDC_0202, templine, 256); - - SetDlgItemText(conversionboxwindow, IDC_0402, templine); - - - - // ConversionBoxFileEvent(); // Needed? - - - - itemptr = GetDlgItem(conversionboxwindow, IDC_0406); // Compression Combo - - itemcount = 0; - - while(compressnames[itemcount] != NULL) { - - ComboBox_AddString(itemptr, compressnames[itemcount]); - - itemcount++; - - } // ENDWHILE- loading compression types into combo box - - ComboBox_SetCurSel(itemptr, 0); // First Selection? - - itemptr = NULL; - - - - CheckDlgButton(conversionboxwindow, IDC_0408, FALSE); // Start unchecked - - - - return; - + return; } // END ConversionBoxDisplay() - - - - BOOL CALLBACK ConversionBoxCallback(HWND window, - UINT msg, - WPARAM param, + LPARAM param2) +{ + switch (msg) + { + case WM_INITDIALOG: + conversionboxwindow = window; + ConversionBoxDisplay(); // Final touches to this window + return(FALSE); // Let Windows display this window + break; + case WM_CLOSE: // The "X" in the upper right corner was hit. + ConversionBoxCancelEvent(); + return(TRUE); + break; - LPARAM param2) { + case WM_COMMAND: + switch (LOWORD(param)) + { + case IDC_0402: // Filename Edit Box + ConversionBoxFileEvent(); // Describe the File's current type... + return(FALSE); // Let Windows edit the text. + break; + case IDC_0403: // "Browse" Button + ConversionBoxBrowseEvent(); + return(TRUE); + break; - switch(msg) { - - case WM_INITDIALOG: - - conversionboxwindow = window; - - ConversionBoxDisplay(); // Final touches to this window - - return(FALSE); // Let Windows display this window - - break; - - - - case WM_CLOSE: // The "X" in the upper right corner was hit. - - ConversionBoxCancelEvent(); - - return(TRUE); - - break; - - - - case WM_COMMAND: - - switch(LOWORD(param)) { - - case IDC_0402: // Filename Edit Box - - ConversionBoxFileEvent(); // Describe the File's current type... - - return(FALSE); // Let Windows edit the text. - - break; - - - - case IDC_0403: // "Browse" Button - - ConversionBoxBrowseEvent(); - - return(TRUE); - - break; - - - - case IDC_0409: // "Change File" Button - - ConversionBoxOKEvent(); - - return(TRUE); - - break; - - - - case IDC_0410: // "Cancel" Button - - ConversionBoxCancelEvent(); - - return(TRUE); - - break; - - } // ENDSWITCH param- Which object got the message? - - } // ENDSWITCH msg- what message has been sent to this window? - - - - return(FALSE); + case IDC_0409: // "Change File" Button + ConversionBoxOKEvent(); + return(TRUE); + break; + case IDC_0410: // "Cancel" Button + ConversionBoxCancelEvent(); + return(TRUE); + break; + } // ENDSWITCH param- Which object got the message? + } // ENDSWITCH msg- what message has been sent to this window? + return(FALSE); } // END ConversionBoxEventLoop() - diff --git a/plugins/CDVDisoEFP/src/Win32/conversionbox.h b/plugins/CDVDisoEFP/src/Win32/conversionbox.h index 7bf8c0dfdb..d62be37ca2 100644 --- a/plugins/CDVDisoEFP/src/Win32/conversionbox.h +++ b/plugins/CDVDisoEFP/src/Win32/conversionbox.h @@ -1,80 +1,35 @@ /* conversionbox.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef CONVERSIONBOX_H - #define CONVERSIONBOX_H - - - - #include // HWND - - - - extern HWND conversionboxwindow; - - - extern void ConversionBoxDestroy(); - extern void ConversionBoxRefocus(); - extern void ConversionBoxDisplay(); - extern BOOL CALLBACK ConversionBoxCallback(HWND window, - - UINT msg, - - WPARAM param, - - LPARAM param2); - - - - + UINT msg, + WPARAM param, + LPARAM param2); #endif /* CONVERSIONBOX_H */ - diff --git a/plugins/CDVDisoEFP/src/Win32/device.c b/plugins/CDVDisoEFP/src/Win32/device.c index f46ad13cd9..3f306d21a6 100644 --- a/plugins/CDVDisoEFP/src/Win32/device.c +++ b/plugins/CDVDisoEFP/src/Win32/device.c @@ -1,1172 +1,648 @@ -/* device.c - - * Copyright (C) 2002-2005 PCSX2 Team - - * - - * This program is free software; you can redistribute it and/or modify - - * it under the terms of the GNU General Public License as published by - - * the Free Software Foundation; either version 2 of the License, or - - * (at your option) any later version. - - * - - * This program is distributed in the hope that it will be useful, - - * but WITHOUT ANY WARRANTY; without even the implied warranty of - - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - - * GNU General Public License for more details. - - * - - * You should have received a copy of the GNU General Public License - - * along with this program; if not, write to the Free Software - - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - * - - * PCSX2 members can be contacted through their website at www.pcsx2.net. - - */ - - - - - -#include - -#include // IOCTL_CDROM..., IOCTL_STORAGE... - -#include // IOCTL_DISK... - -#include // sprintf() - -#include // time_t - - - -#define CDVDdefs - -#include "PS2Edefs.h" - - - -#include "logfile.h" - -#include "conf.h" - -#include "CD.h" - -#include "DVD.h" - -#include "device.h" - - - - - -HANDLE devicehandle; - -OVERLAPPED waitevent; - - - -time_t lasttime; - -s32 traystatus; - -int traystatusmethod; - -s32 disctype; - -char tocbuffer[2048]; - - - - - -void DeviceInit() { - - devicehandle = NULL; - - waitevent.hEvent = NULL; - - waitevent.Internal = 0; - - waitevent.InternalHigh = 0; - - waitevent.Offset = 0; - - waitevent.OffsetHigh = 0; - - lasttime = 0; - - - - InitDisc(); - -} // END DeviceInit() - - - - - -void InitDisc() { - - int i; - - - - InitCDInfo(); - - InitDVDInfo(); - - traystatus = CDVD_TRAY_OPEN; - - traystatusmethod = 0; // Poll all until one works - - disctype = CDVD_TYPE_NODISC; - - for(i = 0; i < 2048; i++) tocbuffer[i] = 0; - -} // END InitDisc() - - - - - -s32 DiscInserted() { - - if(traystatus != CDVD_TRAY_CLOSE) return(-1); - - - - if(disctype == CDVD_TYPE_ILLEGAL) return(-1); - - // if(disctype == CDVD_TYPE_UNKNOWN) return(-1); // Hmm. Let this one through? - - if(disctype == CDVD_TYPE_DETCTDVDD) return(-1); - - if(disctype == CDVD_TYPE_DETCTDVDS) return(-1); - - if(disctype == CDVD_TYPE_DETCTCD) return(-1); - - if(disctype == CDVD_TYPE_DETCT) return(-1); - - if(disctype == CDVD_TYPE_NODISC) return(-1); - - - -#ifdef VERBOSE_FUNCTION_DEVICE - - PrintLog("CDVDiso device: DiscInserted()"); - -#endif /* VERBOSE_FUNCTION_DEVICE */ - - - - return(0); - -} // END DiscInserted() - - - - - -// Returns errcode (or 0 if successful) - -DWORD FinishCommand(BOOL boolresult) { - - DWORD errcode; - - DWORD waitcode; - - - -#ifdef VERBOSE_FUNCTION_DEVICE - - PrintLog("CDVDiso device: FinishCommand()"); - -#endif /* VERBOSE_FUNCTION_DEVICE */ - - - - if(boolresult == TRUE) { - - ResetEvent(waitevent.hEvent); - - return(0); - - } // ENDIF- Device is ready? Say so. - - - - errcode = GetLastError(); - - if(errcode == ERROR_IO_PENDING) { - -#ifdef VERBOSE_FUNCTION_DEVICE - - PrintLog("CDVDiso device: Waiting for completion."); - -#endif /* VERBOSE_FUNCTION_DEVICE */ - - waitcode = WaitForSingleObject(waitevent.hEvent, 10 * 1000); // 10 sec wait - - if((waitcode == WAIT_FAILED) || (waitcode == WAIT_ABANDONED)) { - - errcode = GetLastError(); - - } else if(waitcode == WAIT_TIMEOUT) { - - errcode = 21; - - CancelIo(devicehandle); // Speculative Line - - } else { - - ResetEvent(waitevent.hEvent); - - return(0); // Success! - - } // ENDIF- Trouble waiting? (Or doesn't finish in 5 seconds?) - - } // ENDIF- Should we wait for the call to finish? - - - - ResetEvent(waitevent.hEvent); - - return(errcode); - -} // END DeviceCommand() - - - - - -s32 DeviceOpen() { - - char tempname[256]; - - UINT drivetype; - - DWORD errcode; - - - - if(conf.devicename[0] == 0) return(-1); - - - - if(devicehandle != NULL) return(0); - - - -#ifdef VERBOSE_FUNCTION_DEVICE - - PrintLog("CDVDiso device: DeviceOpen()"); - -#endif /* VERBOSE_FUNCTION_DEVICE */ - - - - // InitConf(); - - // LoadConf(); // Should be done at least once before this call - - - - // Root Directory reference - - if(conf.devicename[1] == 0) { - - sprintf(tempname, "%s:\\", conf.devicename); - - } else if((conf.devicename[1] == ':') && (conf.devicename[2] == 0)) { - - sprintf(tempname, "%s\\", conf.devicename); - - } else { - - sprintf(tempname, "%s", conf.devicename); - - } // ENDIF- Not a single drive letter? (or a letter/colon?) Copy the name in. - - - - drivetype = GetDriveType(tempname); - - if(drivetype != DRIVE_CDROM) { - -#ifdef VERBOSE_WARNING_DEVICE - - PrintLog("CDVDiso device: Not a CD-ROM!"); - - PrintLog("CDVDiso device: (Came back: %u)", drivetype); - - errcode = GetLastError(); - - if(errcode > 0) PrintError("CDVDiso device", errcode); - -#endif /* VERBOSE_WARNING_DEVICE */ - - return(-1); - - } // ENDIF- Not a CD-ROM? Say so! - - // Hmm. Do we want to include DRIVE_REMOVABLE... just in case? - - - - // Device Reference - - if(conf.devicename[1] == 0) { - - sprintf(tempname, "\\\\.\\%s:", conf.devicename); - - } else if((conf.devicename[1] == ':') && (conf.devicename[2] == 0)) { - - sprintf(tempname, "\\\\.\\%s", conf.devicename); - - } else { - - sprintf(tempname, "%s", conf.devicename); - - } // ENDIF- Not a single drive letter? (or a letter/colon?) Copy the name in. - - - - devicehandle = CreateFile(tempname, - - GENERIC_READ, - - FILE_SHARE_READ, - - NULL, - - OPEN_EXISTING, - - FILE_FLAG_OVERLAPPED | FILE_FLAG_SEQUENTIAL_SCAN, - - NULL); - - - - if(devicehandle == INVALID_HANDLE_VALUE) { - -#ifdef VERBOSE_WARNING_DEVICE - - PrintLog("CDVDiso device: Couldn't open device read-only! Read-Write perhaps?"); - - errcode = GetLastError(); - - PrintError("CDVDiso device", errcode); - -#endif /* VERBOSE_WARNING_DEVICE */ - - devicehandle = CreateFile(tempname, - - GENERIC_READ | GENERIC_WRITE, - - FILE_SHARE_READ | FILE_SHARE_WRITE, - - NULL, - - OPEN_EXISTING, - - FILE_FLAG_OVERLAPPED | FILE_FLAG_SEQUENTIAL_SCAN, - - NULL); - - } // ENDIF- Couldn't open for read? Try read/write (for those drives that insist) - - - - if(devicehandle == INVALID_HANDLE_VALUE) { - -#ifdef VERBOSE_WARNING_DEVICE - - PrintLog("CDVDiso device: Couldn't open device!"); - - errcode = GetLastError(); - - PrintError("CDVDiso device", errcode); - -#endif /* VERBOSE_WARNING_DEVICE */ - - devicehandle = NULL; - - return(-1); - - } // ENDIF- Couldn't open that way either? Abort. - - - - waitevent.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - - if(waitevent.hEvent == INVALID_HANDLE_VALUE) { - -#ifdef VERBOSE_WARNING_DEVICE - - PrintLog("CDVDiso device: Couldn't open event handler!"); - - errcode = GetLastError(); - - PrintError("CDVDiso device", errcode); - -#endif /* VERBOSE_WARNING_DEVICE */ - - waitevent.hEvent = NULL; - - CloseHandle(devicehandle); - - devicehandle = NULL; - - } // ENDIF- Couldn't create an "Wait for I/O" handle? Abort. - - - - // More here... DeviceIoControl? for Drive Capabilities - - // DEVICE_CAPABILITIES? - - - - ////// Should be done just after the first DeviceOpen(); - - // InitDisc(); // ? - - // DeviceTrayStatus(); - - - - return(0); - -} // END DeviceOpen() - - - - - -void DeviceClose() { - - if(devicehandle == NULL) return; - - - - if(devicehandle == INVALID_HANDLE_VALUE) { - - devicehandle = NULL; - - return; - - } // ENDIF- Bad value? Just clear the value. - - - -#ifdef VERBOSE_FUNCTION_DEVICE - - PrintLog("CDVDiso device: DeviceClose()"); - -#endif /* VERBOSE_FUNCTION_DEVICE */ - - - - if(waitevent.hEvent != NULL) { - - if(waitevent.hEvent != INVALID_HANDLE_VALUE) { - - CancelIo(devicehandle); - - CloseHandle(waitevent.hEvent); - - } // ENDIF- Is this handle actually open? - - waitevent.hEvent = NULL; - - waitevent.Offset = 0; - - waitevent.OffsetHigh = 0; - - } // ENDIF- Reset the event handle? - - - - CloseHandle(devicehandle); - - devicehandle = NULL; - - return; - -} // END DeviceClose() - - - - - -s32 DeviceReadTrack(u32 lsn, int mode, u8 *buffer) { - - if(DiscInserted() == -1) return(-1); - - - - if((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) { - - return(DVDreadTrack(lsn, mode, buffer)); - - } else { - - return(CDreadTrack(lsn, mode, buffer)); - - } // ENDIF- Is this a DVD? - -} // END DeviceReadTrack() - - - - - -s32 DeviceBufferOffset() { - - if(DiscInserted() == -1) return(-1); - - - - if((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) { - - return(0); - - } else { - - return(CDgetBufferOffset()); - - } // ENDIF- Is this a DVD? - - - - return(-1); - -} // END DeviceBufferOffset() - - - - - -s32 DeviceGetTD(u8 track, cdvdTD *cdvdtd) { - - if(DiscInserted() == -1) return(-1); - - - - if((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) { - - return(DVDgetTD(track, cdvdtd)); - - } else { - - return(CDgetTD(track, cdvdtd)); - - } // ENDIF- Is this a DVD? - - - - return(-1); - -} // END DeviceGetTD() - - - - - -s32 DeviceGetDiskType() { - - s32 s32result; - - - - if(devicehandle == NULL) return(-1); - - if(devicehandle == INVALID_HANDLE_VALUE) return(-1); - - - - if(traystatus == CDVD_TRAY_OPEN) return(disctype); - - - - if(disctype != CDVD_TYPE_NODISC) return(disctype); - - - -#ifdef VERBOSE_FUNCTION_DEVICE - - PrintLog("CDVDiso device: DeviceGetDiskType()"); - -#endif /* VERBOSE_FUNCTION_DEVICE */ - - - - disctype = CDVD_TYPE_DETCT; - - - - s32result = DVDgetDiskType(); - - if(s32result != -1) return(disctype); - - - - s32result = CDgetDiskType(); - - if(s32result != -1) return(disctype); - - - - disctype = CDVD_TYPE_UNKNOWN; - - return(disctype); - -} // END DeviceGetDiskType() - - - - - -BOOL DeviceTrayStatusStorage() { - - BOOL boolresult; - - DWORD byteswritten; - - DWORD errcode; - - - - // Note: Unlike other calls, CHECK_VERIFY is not waited on. At this point, - - // this is the only way to detect if a disc is ready for action. - - - - boolresult = DeviceIoControl(devicehandle, - - IOCTL_STORAGE_CHECK_VERIFY, - - NULL, - - 0, - - NULL, - - 0, - - &byteswritten, - - NULL); - - errcode = GetLastError(); - - - - if(errcode == 0) return(TRUE); - - if(errcode == 21) return(FALSE); // Device not ready? (Valid error) - - - -#ifdef VERBOSE_WARNING_DEVICE - - PrintLog("CDVDiso device: Trouble detecting drive status (STORAGE)!"); - - PrintError("CDVDiso device", errcode); - -#endif /* VERBOSE_WARNING_DEVICE */ - - return(FALSE); - -} // END DeviceTrayStatusStorage() - - - - - -BOOL DeviceTrayStatusCDRom() { - - BOOL boolresult; - - DWORD byteswritten; - - DWORD errcode; - - - - // Note: Unlike other calls, CHECK_VERIFY is not waited on. At this point, - - // this is the only way to detect if a disc is ready for action. - - - - boolresult = DeviceIoControl(devicehandle, - - IOCTL_CDROM_CHECK_VERIFY, - - NULL, - - 0, - - NULL, - - 0, - - &byteswritten, - - NULL); - - errcode = GetLastError(); - - - - if(errcode == 0) return(TRUE); - - if(errcode == 21) return(FALSE); // Device not ready? (Valid error) - - - -#ifdef VERBOSE_WARNING_DEVICE - - PrintLog("CDVDiso device: Trouble detecting drive status (CDROM)!"); - - PrintError("CDVDiso device", errcode); - -#endif /* VERBOSE_WARNING_DEVICE */ - - return(FALSE); - -} // END DeviceTrayStatusCDRom() - - - - - -BOOL DeviceTrayStatusDisk() { - - BOOL boolresult; - - DWORD byteswritten; - - DWORD errcode; - - - - // Note: Unlike other calls, CHECK_VERIFY is not waited on. At this point, - - // this is the only way to detect if a disc is ready for action. - - - - boolresult = DeviceIoControl(devicehandle, - - IOCTL_DISK_CHECK_VERIFY, - - NULL, - - 0, - - NULL, - - 0, - - &byteswritten, - - NULL); - - errcode = GetLastError(); - - - - if(errcode == 0) return(TRUE); - - if(errcode == 21) return(FALSE); // Device not ready? (Valid error) - - - -#ifdef VERBOSE_WARNING_DEVICE - - PrintLog("CDVDiso device: Trouble detecting drive status (DISK)!"); - - PrintError("CDVDiso device", errcode); - -#endif /* VERBOSE_WARNING_DEVICE */ - - return(FALSE); - -} // END DeviceTrayStatusDisk() - - - - - -s32 DeviceTrayStatus() { - - BOOL boolresult; - - - - if(devicehandle == NULL) return(-1); - - if(devicehandle == INVALID_HANDLE_VALUE) return(-1); - - - -#ifdef VERBOSE_FUNCTION_DEVICE - - PrintLog("CDVDiso device: DeviceTrayStatus()"); - -#endif /* VERBOSE_FUNCTION_DEVICE */ - - - - switch(traystatusmethod) { - - case 1: - - boolresult = DeviceTrayStatusStorage(); - - break; - - case 2: - - boolresult = DeviceTrayStatusCDRom(); - - break; - - case 3: - - boolresult = DeviceTrayStatusDisk(); - - break; - - default: - - boolresult = FALSE; - - break; - - } // ENDSWITCH traystatusmethod- One method already working? Try it again. - - - - if(boolresult == FALSE) { - - traystatusmethod = 0; - - boolresult = DeviceTrayStatusStorage(); - - if(boolresult == TRUE) { - - traystatusmethod = 1; - - } else { - - boolresult = DeviceTrayStatusCDRom(); - - if(boolresult == TRUE) { - - traystatusmethod = 2; - - } else { - - boolresult = DeviceTrayStatusDisk(); - - if(boolresult == TRUE) traystatusmethod = 3; - - } // ENDIF- Did we succeed with CDRom? - - } // ENDIF- Did we succeed with Storage? - - } // Single call to already working test just failed? Test them all. - - - - if(boolresult == FALSE) { - - if(traystatus == CDVD_TRAY_CLOSE) { - - traystatus = CDVD_TRAY_OPEN; - - DeviceClose(); - - DeviceOpen(); - - InitDisc(); - - } // ENDIF- Just opened? clear disc info - - return(traystatus); - - } // ENDIF- Still failed? Assume no disc in drive then. - - - - if(traystatus == CDVD_TRAY_OPEN) { - - traystatus = CDVD_TRAY_CLOSE; - - DeviceGetDiskType(); - - return(traystatus); - - } // ENDIF- Just closed? Get disc information - - - - return(traystatus); - -} // END DeviceTrayStatus() - - - - - -s32 DeviceTrayOpen() { - - BOOL boolresult; - - DWORD byteswritten; - - DWORD errcode; - - - - if(devicehandle == NULL) return(-1); - - if(devicehandle == INVALID_HANDLE_VALUE) return(-1); - - - - if(traystatus == CDVD_TRAY_OPEN) return(0); - - - -#ifdef VERBOSE_FUNCTION_DEVICE - - PrintLog("CDVDiso device: DeviceOpenTray()"); - -#endif /* VERBOSE_FUNCTION_DEVICE */ - - - - boolresult = DeviceIoControl(devicehandle, - - IOCTL_STORAGE_EJECT_MEDIA, - - NULL, - - 0, - - NULL, - - 0, - - &byteswritten, - - &waitevent); - - errcode = FinishCommand(boolresult); - - - - if(errcode != 0) { - -#ifdef VERBOSE_WARNING_DEVICE - - PrintLog("CDVDiso device: Couldn't signal media to eject! (STORAGE)"); - - PrintError("CDVDiso device", errcode); - -#endif /* VERBOSE_WARNING_DEVICE */ - - - -// boolresult = DeviceIoControl(devicehandle, - -// IOCTL_DISK_EJECT_MEDIA, - -// NULL, - -// 0, - -// NULL, - -// 0, - -// &byteswritten, - -// NULL); - -// } // ENDIF- Storage Call failed? Try Disk call. - - - -// if(boolresult == FALSE) { - -// #ifdef VERBOSE_WARNING_DEVICE - -// PrintLog("CDVDiso device: Couldn't signal media to eject! (DISK)"); - -// PrintError("CDVDiso device", errcode); - -// #endif /* VERBOSE_WARNING_DEVICE */ - - return(-1); - - } // ENDIF- Disk Call failed as well? Give it up. - - - - return(0); - -} // END DeviceTrayOpen() - - - - - -s32 DeviceTrayClose() { - - BOOL boolresult; - - DWORD byteswritten; - - DWORD errcode; - - - - if(devicehandle == NULL) return(-1); - - if(devicehandle == INVALID_HANDLE_VALUE) return(-1); - - - - if(traystatus == CDVD_TRAY_CLOSE) return(0); - - - -#ifdef VERBOSE_FUNCTION_DEVICE - - PrintLog("CDVDiso device: DeviceCloseTray()"); - -#endif /* VERBOSE_FUNCTION_DEVICE */ - - - - boolresult = DeviceIoControl(devicehandle, - - IOCTL_STORAGE_LOAD_MEDIA, - - NULL, - - 0, - - NULL, - - 0, - - &byteswritten, - - NULL); - - errcode = FinishCommand(boolresult); - - - - if(errcode != 0) { - -#ifdef VERBOSE_WARNING_DEVICE - - PrintLog("CDVDiso device: Couldn't signal media to load! (STORAGE)"); - - PrintError("CDVDiso device", errcode); - -#endif /* VERBOSE_WARNING_DEVICE */ - -// boolresult = DeviceIoControl(devicehandle, - -// IOCTL_CDROM_LOAD_MEDIA, - -// NULL, - -// 0, - -// NULL, - -// 0, - -// &byteswritten, - -// NULL); - -// } // ENDIF- Storage call failed. CDRom call? - - - -// if(boolresult == FALSE) { - -// errcode = GetLastError(); - -// #ifdef VERBOSE_WARNING_DEVICE - -// PrintLog("CDVDiso device: Couldn't signal media to load! (CDROM)"); - -// PrintError("CDVDiso device", errcode); - -// #endif /* VERBOSE_WARNING_DEVICE */ - -// boolresult = DeviceIoControl(devicehandle, - -// IOCTL_DISK_LOAD_MEDIA, - -// NULL, - -// 0, - -// NULL, - -// 0, - -// &byteswritten, - -// NULL); - -// } // ENDIF- CDRom call failed. Disk call? - - - -// if(boolresult == FALSE) { - -// #ifdef VERBOSE_WARNING_DEVICE - -// PrintLog("CDVDiso device: Couldn't signal media to load! (DISK)"); - -// PrintError("CDVDiso device", errcode); - -// #endif /* VERBOSE_WARNING_DEVICE */ - - return(-1); - - } // ENDIF- Media not available? - - - - return(0); - -} // END DeviceTrayClose() - +/* device.c + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +#include +#include // IOCTL_CDROM..., IOCTL_STORAGE... +#include // IOCTL_DISK... +#include // sprintf() +#include // time_t + +#define CDVDdefs +#include "PS2Edefs.h" + +#include "logfile.h" +#include "conf.h" +#include "CD.h" +#include "DVD.h" +#include "device.h" + + +HANDLE devicehandle; +OVERLAPPED waitevent; + +time_t lasttime; +s32 traystatus; +int traystatusmethod; +s32 disctype; +char tocbuffer[2048]; + + +void DeviceInit() +{ + devicehandle = NULL; + waitevent.hEvent = NULL; + waitevent.Internal = 0; + waitevent.InternalHigh = 0; + waitevent.Offset = 0; + waitevent.OffsetHigh = 0; + lasttime = 0; + + InitDisc(); +} // END DeviceInit() + + +void InitDisc() +{ + int i; + + InitCDInfo(); + InitDVDInfo(); + traystatus = CDVD_TRAY_OPEN; + traystatusmethod = 0; // Poll all until one works + disctype = CDVD_TYPE_NODISC; + for (i = 0; i < 2048; i++) tocbuffer[i] = 0; +} // END InitDisc() + + +s32 DiscInserted() +{ + if (traystatus != CDVD_TRAY_CLOSE) return(-1); + + if (disctype == CDVD_TYPE_ILLEGAL) return(-1); + // if(disctype == CDVD_TYPE_UNKNOWN) return(-1); // Hmm. Let this one through? + if (disctype == CDVD_TYPE_DETCTDVDD) return(-1); + if (disctype == CDVD_TYPE_DETCTDVDS) return(-1); + if (disctype == CDVD_TYPE_DETCTCD) return(-1); + if (disctype == CDVD_TYPE_DETCT) return(-1); + if (disctype == CDVD_TYPE_NODISC) return(-1); + +#ifdef VERBOSE_FUNCTION_DEVICE + PrintLog("CDVDiso device: DiscInserted()"); +#endif /* VERBOSE_FUNCTION_DEVICE */ + + return(0); +} // END DiscInserted() + + +// Returns errcode (or 0 if successful) +DWORD FinishCommand(BOOL boolresult) +{ + DWORD errcode; + DWORD waitcode; + +#ifdef VERBOSE_FUNCTION_DEVICE + PrintLog("CDVDiso device: FinishCommand()"); +#endif /* VERBOSE_FUNCTION_DEVICE */ + + if (boolresult == TRUE) + { + ResetEvent(waitevent.hEvent); + return(0); + } // ENDIF- Device is ready? Say so. + + errcode = GetLastError(); + if (errcode == ERROR_IO_PENDING) + { +#ifdef VERBOSE_FUNCTION_DEVICE + PrintLog("CDVDiso device: Waiting for completion."); +#endif /* VERBOSE_FUNCTION_DEVICE */ + waitcode = WaitForSingleObject(waitevent.hEvent, 10 * 1000); // 10 sec wait + if ((waitcode == WAIT_FAILED) || (waitcode == WAIT_ABANDONED)) + { + errcode = GetLastError(); + } + else if (waitcode == WAIT_TIMEOUT) + { + errcode = 21; + CancelIo(devicehandle); // Speculative Line + } + else + { + ResetEvent(waitevent.hEvent); + return(0); // Success! + } // ENDIF- Trouble waiting? (Or doesn't finish in 5 seconds?) + } // ENDIF- Should we wait for the call to finish? + + ResetEvent(waitevent.hEvent); + return(errcode); +} // END DeviceCommand() + + +s32 DeviceOpen() +{ + char tempname[256]; + UINT drivetype; + DWORD errcode; + + if (conf.devicename[0] == 0) return(-1); + + if (devicehandle != NULL) return(0); + +#ifdef VERBOSE_FUNCTION_DEVICE + PrintLog("CDVDiso device: DeviceOpen()"); +#endif /* VERBOSE_FUNCTION_DEVICE */ + + // InitConf(); + // LoadConf(); // Should be done at least once before this call + + // Root Directory reference + if (conf.devicename[1] == 0) + { + sprintf(tempname, "%s:\\", conf.devicename); + } + else if ((conf.devicename[1] == ':') && (conf.devicename[2] == 0)) + { + sprintf(tempname, "%s\\", conf.devicename); + } + else + { + sprintf(tempname, "%s", conf.devicename); + } // ENDIF- Not a single drive letter? (or a letter/colon?) Copy the name in. + + drivetype = GetDriveType(tempname); + if (drivetype != DRIVE_CDROM) + { +#ifdef VERBOSE_WARNING_DEVICE + PrintLog("CDVDiso device: Not a CD-ROM!"); + PrintLog("CDVDiso device: (Came back: %u)", drivetype); + errcode = GetLastError(); + if (errcode > 0) PrintError("CDVDiso device", errcode); +#endif /* VERBOSE_WARNING_DEVICE */ + return(-1); + } // ENDIF- Not a CD-ROM? Say so! + // Hmm. Do we want to include DRIVE_REMOVABLE... just in case? + + // Device Reference + if (conf.devicename[1] == 0) + { + sprintf(tempname, "\\\\.\\%s:", conf.devicename); + } + else if ((conf.devicename[1] == ':') && (conf.devicename[2] == 0)) + { + sprintf(tempname, "\\\\.\\%s", conf.devicename); + } + else + { + sprintf(tempname, "%s", conf.devicename); + } // ENDIF- Not a single drive letter? (or a letter/colon?) Copy the name in. + + devicehandle = CreateFile(tempname, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_FLAG_OVERLAPPED | FILE_FLAG_SEQUENTIAL_SCAN, + NULL); + + if (devicehandle == INVALID_HANDLE_VALUE) + { +#ifdef VERBOSE_WARNING_DEVICE + PrintLog("CDVDiso device: Couldn't open device read-only! Read-Write perhaps?"); + errcode = GetLastError(); + PrintError("CDVDiso device", errcode); +#endif /* VERBOSE_WARNING_DEVICE */ + devicehandle = CreateFile(tempname, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_FLAG_OVERLAPPED | FILE_FLAG_SEQUENTIAL_SCAN, + NULL); + } // ENDIF- Couldn't open for read? Try read/write (for those drives that insist) + + if (devicehandle == INVALID_HANDLE_VALUE) + { +#ifdef VERBOSE_WARNING_DEVICE + PrintLog("CDVDiso device: Couldn't open device!"); + errcode = GetLastError(); + PrintError("CDVDiso device", errcode); +#endif /* VERBOSE_WARNING_DEVICE */ + devicehandle = NULL; + return(-1); + } // ENDIF- Couldn't open that way either? Abort. + + waitevent.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (waitevent.hEvent == INVALID_HANDLE_VALUE) + { +#ifdef VERBOSE_WARNING_DEVICE + PrintLog("CDVDiso device: Couldn't open event handler!"); + errcode = GetLastError(); + PrintError("CDVDiso device", errcode); +#endif /* VERBOSE_WARNING_DEVICE */ + waitevent.hEvent = NULL; + CloseHandle(devicehandle); + devicehandle = NULL; + } // ENDIF- Couldn't create an "Wait for I/O" handle? Abort. + + // More here... DeviceIoControl? for Drive Capabilities + // DEVICE_CAPABILITIES? + + ////// Should be done just after the first DeviceOpen(); + // InitDisc(); // ? + // DeviceTrayStatus(); + + return(0); +} // END DeviceOpen() + + +void DeviceClose() +{ + if (devicehandle == NULL) return; + + if (devicehandle == INVALID_HANDLE_VALUE) + { + devicehandle = NULL; + return; + } // ENDIF- Bad value? Just clear the value. + +#ifdef VERBOSE_FUNCTION_DEVICE + PrintLog("CDVDiso device: DeviceClose()"); +#endif /* VERBOSE_FUNCTION_DEVICE */ + + if (waitevent.hEvent != NULL) + { + if (waitevent.hEvent != INVALID_HANDLE_VALUE) + { + CancelIo(devicehandle); + CloseHandle(waitevent.hEvent); + } // ENDIF- Is this handle actually open? + waitevent.hEvent = NULL; + waitevent.Offset = 0; + waitevent.OffsetHigh = 0; + } // ENDIF- Reset the event handle? + + CloseHandle(devicehandle); + devicehandle = NULL; + return; +} // END DeviceClose() + + +s32 DeviceReadTrack(u32 lsn, int mode, u8 *buffer) +{ + if (DiscInserted() == -1) return(-1); + + if ((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) + { + return(DVDreadTrack(lsn, mode, buffer)); + } + else + { + return(CDreadTrack(lsn, mode, buffer)); + } // ENDIF- Is this a DVD? +} // END DeviceReadTrack() + + +s32 DeviceBufferOffset() +{ + if (DiscInserted() == -1) return(-1); + + if ((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) + { + return(0); + } + else + { + return(CDgetBufferOffset()); + } // ENDIF- Is this a DVD? + + return(-1); +} // END DeviceBufferOffset() + + +s32 DeviceGetTD(u8 track, cdvdTD *cdvdtd) +{ + if (DiscInserted() == -1) return(-1); + + if ((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) + { + return(DVDgetTD(track, cdvdtd)); + } + else + { + return(CDgetTD(track, cdvdtd)); + } // ENDIF- Is this a DVD? + + return(-1); +} // END DeviceGetTD() + + +s32 DeviceGetDiskType() +{ + s32 s32result; + + if (devicehandle == NULL) return(-1); + if (devicehandle == INVALID_HANDLE_VALUE) return(-1); + + if (traystatus == CDVD_TRAY_OPEN) return(disctype); + + if (disctype != CDVD_TYPE_NODISC) return(disctype); + +#ifdef VERBOSE_FUNCTION_DEVICE + PrintLog("CDVDiso device: DeviceGetDiskType()"); +#endif /* VERBOSE_FUNCTION_DEVICE */ + + disctype = CDVD_TYPE_DETCT; + + s32result = DVDgetDiskType(); + if (s32result != -1) return(disctype); + + s32result = CDgetDiskType(); + if (s32result != -1) return(disctype); + + disctype = CDVD_TYPE_UNKNOWN; + return(disctype); +} // END DeviceGetDiskType() + + +BOOL DeviceTrayStatusStorage() +{ + BOOL boolresult; + DWORD byteswritten; + DWORD errcode; + + // Note: Unlike other calls, CHECK_VERIFY is not waited on. At this point, + // this is the only way to detect if a disc is ready for action. + + boolresult = DeviceIoControl(devicehandle, + IOCTL_STORAGE_CHECK_VERIFY, + NULL, + 0, + NULL, + 0, + &byteswritten, + NULL); + errcode = GetLastError(); + + if (errcode == 0) return(TRUE); + if (errcode == 21) return(FALSE); // Device not ready? (Valid error) + +#ifdef VERBOSE_WARNING_DEVICE + PrintLog("CDVDiso device: Trouble detecting drive status (STORAGE)!"); + PrintError("CDVDiso device", errcode); +#endif /* VERBOSE_WARNING_DEVICE */ + return(FALSE); +} // END DeviceTrayStatusStorage() + + +BOOL DeviceTrayStatusCDRom() +{ + BOOL boolresult; + DWORD byteswritten; + DWORD errcode; + + // Note: Unlike other calls, CHECK_VERIFY is not waited on. At this point, + // this is the only way to detect if a disc is ready for action. + + boolresult = DeviceIoControl(devicehandle, + IOCTL_CDROM_CHECK_VERIFY, + NULL, + 0, + NULL, + 0, + &byteswritten, + NULL); + errcode = GetLastError(); + + if (errcode == 0) return(TRUE); + if (errcode == 21) return(FALSE); // Device not ready? (Valid error) + +#ifdef VERBOSE_WARNING_DEVICE + PrintLog("CDVDiso device: Trouble detecting drive status (CDROM)!"); + PrintError("CDVDiso device", errcode); +#endif /* VERBOSE_WARNING_DEVICE */ + return(FALSE); +} // END DeviceTrayStatusCDRom() + + +BOOL DeviceTrayStatusDisk() +{ + BOOL boolresult; + DWORD byteswritten; + DWORD errcode; + + // Note: Unlike other calls, CHECK_VERIFY is not waited on. At this point, + // this is the only way to detect if a disc is ready for action. + + boolresult = DeviceIoControl(devicehandle, + IOCTL_DISK_CHECK_VERIFY, + NULL, + 0, + NULL, + 0, + &byteswritten, + NULL); + errcode = GetLastError(); + + if (errcode == 0) return(TRUE); + if (errcode == 21) return(FALSE); // Device not ready? (Valid error) + +#ifdef VERBOSE_WARNING_DEVICE + PrintLog("CDVDiso device: Trouble detecting drive status (DISK)!"); + PrintError("CDVDiso device", errcode); +#endif /* VERBOSE_WARNING_DEVICE */ + return(FALSE); +} // END DeviceTrayStatusDisk() + + +s32 DeviceTrayStatus() +{ + BOOL boolresult; + + if (devicehandle == NULL) return(-1); + if (devicehandle == INVALID_HANDLE_VALUE) return(-1); + +#ifdef VERBOSE_FUNCTION_DEVICE + PrintLog("CDVDiso device: DeviceTrayStatus()"); +#endif /* VERBOSE_FUNCTION_DEVICE */ + + switch (traystatusmethod) + { + case 1: + boolresult = DeviceTrayStatusStorage(); + break; + case 2: + boolresult = DeviceTrayStatusCDRom(); + break; + case 3: + boolresult = DeviceTrayStatusDisk(); + break; + default: + boolresult = FALSE; + break; + } // ENDSWITCH traystatusmethod- One method already working? Try it again. + + if (boolresult == FALSE) + { + traystatusmethod = 0; + boolresult = DeviceTrayStatusStorage(); + if (boolresult == TRUE) + { + traystatusmethod = 1; + } + else + { + boolresult = DeviceTrayStatusCDRom(); + if (boolresult == TRUE) + { + traystatusmethod = 2; + } + else + { + boolresult = DeviceTrayStatusDisk(); + if (boolresult == TRUE) traystatusmethod = 3; + } // ENDIF- Did we succeed with CDRom? + } // ENDIF- Did we succeed with Storage? + } // Single call to already working test just failed? Test them all. + + if (boolresult == FALSE) + { + if (traystatus == CDVD_TRAY_CLOSE) + { + traystatus = CDVD_TRAY_OPEN; + DeviceClose(); + DeviceOpen(); + InitDisc(); + } // ENDIF- Just opened? clear disc info + return(traystatus); + } // ENDIF- Still failed? Assume no disc in drive then. + + if (traystatus == CDVD_TRAY_OPEN) + { + traystatus = CDVD_TRAY_CLOSE; + DeviceGetDiskType(); + return(traystatus); + } // ENDIF- Just closed? Get disc information + + return(traystatus); +} // END DeviceTrayStatus() + + +s32 DeviceTrayOpen() +{ + BOOL boolresult; + DWORD byteswritten; + DWORD errcode; + + if (devicehandle == NULL) return(-1); + if (devicehandle == INVALID_HANDLE_VALUE) return(-1); + + if (traystatus == CDVD_TRAY_OPEN) return(0); + +#ifdef VERBOSE_FUNCTION_DEVICE + PrintLog("CDVDiso device: DeviceOpenTray()"); +#endif /* VERBOSE_FUNCTION_DEVICE */ + + boolresult = DeviceIoControl(devicehandle, + IOCTL_STORAGE_EJECT_MEDIA, + NULL, + 0, + NULL, + 0, + &byteswritten, + &waitevent); + errcode = FinishCommand(boolresult); + + if (errcode != 0) + { +#ifdef VERBOSE_WARNING_DEVICE + PrintLog("CDVDiso device: Couldn't signal media to eject! (STORAGE)"); + PrintError("CDVDiso device", errcode); +#endif /* VERBOSE_WARNING_DEVICE */ + +// boolresult = DeviceIoControl(devicehandle, +// IOCTL_DISK_EJECT_MEDIA, +// NULL, +// 0, +// NULL, +// 0, +// &byteswritten, +// NULL); +// } // ENDIF- Storage Call failed? Try Disk call. + +// if(boolresult == FALSE) { +// #ifdef VERBOSE_WARNING_DEVICE +// PrintLog("CDVDiso device: Couldn't signal media to eject! (DISK)"); +// PrintError("CDVDiso device", errcode); +// #endif /* VERBOSE_WARNING_DEVICE */ + return(-1); + } // ENDIF- Disk Call failed as well? Give it up. + + return(0); +} // END DeviceTrayOpen() + + +s32 DeviceTrayClose() +{ + BOOL boolresult; + DWORD byteswritten; + DWORD errcode; + + if (devicehandle == NULL) return(-1); + if (devicehandle == INVALID_HANDLE_VALUE) return(-1); + + if (traystatus == CDVD_TRAY_CLOSE) return(0); + +#ifdef VERBOSE_FUNCTION_DEVICE + PrintLog("CDVDiso device: DeviceCloseTray()"); +#endif /* VERBOSE_FUNCTION_DEVICE */ + + boolresult = DeviceIoControl(devicehandle, + IOCTL_STORAGE_LOAD_MEDIA, + NULL, + 0, + NULL, + 0, + &byteswritten, + NULL); + errcode = FinishCommand(boolresult); + + if (errcode != 0) + { +#ifdef VERBOSE_WARNING_DEVICE + PrintLog("CDVDiso device: Couldn't signal media to load! (STORAGE)"); + PrintError("CDVDiso device", errcode); +#endif /* VERBOSE_WARNING_DEVICE */ +// boolresult = DeviceIoControl(devicehandle, +// IOCTL_CDROM_LOAD_MEDIA, +// NULL, +// 0, +// NULL, +// 0, +// &byteswritten, +// NULL); +// } // ENDIF- Storage call failed. CDRom call? + +// if(boolresult == FALSE) { +// errcode = GetLastError(); +// #ifdef VERBOSE_WARNING_DEVICE +// PrintLog("CDVDiso device: Couldn't signal media to load! (CDROM)"); +// PrintError("CDVDiso device", errcode); +// #endif /* VERBOSE_WARNING_DEVICE */ +// boolresult = DeviceIoControl(devicehandle, +// IOCTL_DISK_LOAD_MEDIA, +// NULL, +// 0, +// NULL, +// 0, +// &byteswritten, +// NULL); +// } // ENDIF- CDRom call failed. Disk call? + +// if(boolresult == FALSE) { +// #ifdef VERBOSE_WARNING_DEVICE +// PrintLog("CDVDiso device: Couldn't signal media to load! (DISK)"); +// PrintError("CDVDiso device", errcode); +// #endif /* VERBOSE_WARNING_DEVICE */ + return(-1); + } // ENDIF- Media not available? + + return(0); +} // END DeviceTrayClose() diff --git a/plugins/CDVDisoEFP/src/Win32/device.h b/plugins/CDVDisoEFP/src/Win32/device.h index 6a4034fb76..0de49e1a9c 100644 --- a/plugins/CDVDisoEFP/src/Win32/device.h +++ b/plugins/CDVDisoEFP/src/Win32/device.h @@ -1,128 +1,55 @@ /* device.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - #ifndef __DEVICE_H__ - #define __DEVICE_H__ - - - - #include // BOOL, DWORD - - - #include // time_t - - - #define CDVDdefs - #include "../PS2Edefs.h" - - - - // #define VERBOSE_FUNCTION_DEVICE - // #define VERBOSE_WARNING_DEVICE - #define VERBOSE_DISC_TYPE - #define VERBOSE_DISC_INFO - - - - extern HANDLE devicehandle; - extern OVERLAPPED waitevent; - - extern time_t lasttime; - extern s32 traystatus; - extern s32 disctype; - extern char tocbuffer[]; - - - - extern void DeviceInit(); - extern void InitDisc(); - extern s32 DiscInserted(); - extern DWORD FinishCommand(BOOL boolresult); - - - extern s32 DeviceOpen(); - extern void DeviceClose(); - extern s32 DeviceReadTrack(u32 lsn, int mode, u8 *buffer); - extern s32 DeviceBufferOffset(); - extern s32 DeviceGetTD(u8 track, cdvdTD *cdvdtd); - extern s32 DeviceGetDiskType(); - extern s32 DeviceTrayStatus(); - extern s32 DeviceTrayOpen(); - extern s32 DeviceTrayClose(); - - - - #endif /* __DEVICE_H__ */ - diff --git a/plugins/CDVDisoEFP/src/Win32/devicebox.c b/plugins/CDVDisoEFP/src/Win32/devicebox.c index 1749908a8b..7c45656b99 100644 --- a/plugins/CDVDisoEFP/src/Win32/devicebox.c +++ b/plugins/CDVDisoEFP/src/Win32/devicebox.c @@ -1,818 +1,407 @@ /* devicebox.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include - #include // ComboBox_AddString() - #include // NULL - - #include // sprintf() - #include // strcpy() - #include // stat() - #include // stat() - #include // stat() - - #define CDVDdefs - #include "PS2Edefs.h" - - - #include "conf.h" - #include "device.h" - #include "isofile.h" - #include "isocompress.h" // compressdesc[] - // #include "imagetype.h" // imagedata[].name - #include "multifile.h" // multinames[] - #include "toc.h" - #include "progressbox.h" - #include "mainbox.h" - #include "screens.h" - #include "devicebox.h" - - - - HWND deviceboxwindow; - - - - -void DeviceBoxDestroy() { - - if(deviceboxwindow != NULL) { - - EndDialog(deviceboxwindow, FALSE); - - deviceboxwindow = NULL; - - } // ENDIF- Do we have a Main Window still? - +void DeviceBoxDestroy() +{ + if (deviceboxwindow != NULL) + { + EndDialog(deviceboxwindow, FALSE); + deviceboxwindow = NULL; + } // ENDIF- Do we have a Main Window still? } // END DeviceBoxDestroy() - - - - -void DeviceBoxUnfocus() { - - // gtk_widget_set_sensitive(devicebox.device, FALSE); - - // gtk_widget_set_sensitive(devicebox.file, FALSE); - - // gtk_widget_set_sensitive(devicebox.selectbutton, FALSE); - - // gtk_widget_set_sensitive(devicebox.compress, FALSE); - - // gtk_widget_set_sensitive(devicebox.multi, FALSE); - - // gtk_widget_set_sensitive(devicebox.okbutton, FALSE); - - // gtk_widget_set_sensitive(devicebox.cancelbutton, FALSE); - - ShowWindow(deviceboxwindow, SW_HIDE); - +void DeviceBoxUnfocus() +{ + // gtk_widget_set_sensitive(devicebox.device, FALSE); + // gtk_widget_set_sensitive(devicebox.file, FALSE); + // gtk_widget_set_sensitive(devicebox.selectbutton, FALSE); + // gtk_widget_set_sensitive(devicebox.compress, FALSE); + // gtk_widget_set_sensitive(devicebox.multi, FALSE); + // gtk_widget_set_sensitive(devicebox.okbutton, FALSE); + // gtk_widget_set_sensitive(devicebox.cancelbutton, FALSE); + ShowWindow(deviceboxwindow, SW_HIDE); } // END DeviceBoxUnfocus() +void DeviceBoxDeviceEvent() +{ + char tempdevice[256]; + struct stat filestat; + int returnval; + GetDlgItemText(deviceboxwindow, IDC_0302, tempdevice, 256); + returnval = stat(tempdevice, &filestat); + if (returnval == -1) + { + SetDlgItemText(deviceboxwindow, IDC_0303, "Device Type: ---"); + return; + } // ENDIF- Not a name of any sort? + if (S_ISDIR(filestat.st_mode) != 0) + { + SetDlgItemText(deviceboxwindow, IDC_0303, "Device Type: Not a device"); + return; + } // ENDIF- Not a regular file? - - -void DeviceBoxDeviceEvent() { - - char tempdevice[256]; - - struct stat filestat; - - int returnval; - - - - GetDlgItemText(deviceboxwindow, IDC_0302, tempdevice, 256); - - returnval = stat(tempdevice, &filestat); - - if(returnval == -1) { - - SetDlgItemText(deviceboxwindow, IDC_0303, "Device Type: ---"); - - return; - - } // ENDIF- Not a name of any sort? - - - - if(S_ISDIR(filestat.st_mode) != 0) { - - SetDlgItemText(deviceboxwindow, IDC_0303, "Device Type: Not a device"); - - return; - - } // ENDIF- Not a regular file? - - - - SetDlgItemText(deviceboxwindow, IDC_0303, "Device Type: Device Likely"); - - return; - + SetDlgItemText(deviceboxwindow, IDC_0303, "Device Type: Device Likely"); + return; } // END DeviceBoxDeviceEvent() +void DeviceBoxFileEvent() +{ + int returnval; + char templine[256]; + struct IsoFile *tempfile; + GetDlgItemText(deviceboxwindow, IDC_0305, templine, 256); + returnval = IsIsoFile(templine); + if (returnval == -1) + { + SetDlgItemText(deviceboxwindow, IDC_0307, "File Type: ---"); + return; + } // ENDIF- Not a name of any sort? + if (returnval == -2) + { + SetDlgItemText(deviceboxwindow, IDC_0307, "File Type: Not a file"); + return; + } // ENDIF- Not a regular file? + if (returnval == -3) + { + SetDlgItemText(deviceboxwindow, IDC_0307, "File Type: Not a valid image file"); + return; + } // ENDIF- Not an image file? + if (returnval == -4) + { + SetDlgItemText(deviceboxwindow, IDC_0307, "File Type: Missing Table File (will rebuild)"); + return; + } // ENDIF- Not a regular file? - -void DeviceBoxFileEvent() { - - int returnval; - - char templine[256]; - - struct IsoFile *tempfile; - - - - GetDlgItemText(deviceboxwindow, IDC_0305, templine, 256); - - returnval = IsIsoFile(templine); - - if(returnval == -1) { - - SetDlgItemText(deviceboxwindow, IDC_0307, "File Type: ---"); - - return; - - } // ENDIF- Not a name of any sort? - - - - if(returnval == -2) { - - SetDlgItemText(deviceboxwindow, IDC_0307, "File Type: Not a file"); - - return; - - } // ENDIF- Not a regular file? - - - - if(returnval == -3) { - - SetDlgItemText(deviceboxwindow, IDC_0307, "File Type: Not a valid image file"); - - return; - - } // ENDIF- Not an image file? - - - - if(returnval == -4) { - - SetDlgItemText(deviceboxwindow, IDC_0307, "File Type: Missing Table File (will rebuild)"); - - return; - - } // ENDIF- Not a regular file? - - - - tempfile = IsoFileOpenForRead(templine); - - sprintf(templine, "File Type: %s%s%s", - - multinames[tempfile->multi], - - tempfile->imagename, - - compressdesc[tempfile->compress]); - - SetDlgItemText(deviceboxwindow, IDC_0307, templine); - - tempfile = IsoFileClose(tempfile); - - return; - + tempfile = IsoFileOpenForRead(templine); + sprintf(templine, "File Type: %s%s%s", + multinames[tempfile->multi], + tempfile->imagename, + compressdesc[tempfile->compress]); + SetDlgItemText(deviceboxwindow, IDC_0307, templine); + tempfile = IsoFileClose(tempfile); + return; } // END DeviceBoxFileEvent() - - - - -void DeviceBoxRefocus() { - - DeviceBoxDeviceEvent(); - - DeviceBoxFileEvent(); - - - - // gtk_widget_set_sensitive(devicebox.device, TRUE); - - // gtk_widget_set_sensitive(devicebox.file, TRUE); - - // gtk_widget_set_sensitive(devicebox.selectbutton, TRUE); - - // gtk_widget_set_sensitive(devicebox.compress, TRUE); - - // gtk_widget_set_sensitive(devicebox.multi, TRUE); - - // gtk_widget_set_sensitive(devicebox.okbutton, TRUE); - - // gtk_widget_set_sensitive(devicebox.cancelbutton, TRUE); - - // gtk_window_set_focus(GTK_WINDOW(devicebox.window), devicebox.file); - - ShowWindow(deviceboxwindow, SW_SHOW); - - SetActiveWindow(deviceboxwindow); - +void DeviceBoxRefocus() +{ + DeviceBoxDeviceEvent(); + DeviceBoxFileEvent(); + // gtk_widget_set_sensitive(devicebox.device, TRUE); + // gtk_widget_set_sensitive(devicebox.file, TRUE); + // gtk_widget_set_sensitive(devicebox.selectbutton, TRUE); + // gtk_widget_set_sensitive(devicebox.compress, TRUE); + // gtk_widget_set_sensitive(devicebox.multi, TRUE); + // gtk_widget_set_sensitive(devicebox.okbutton, TRUE); + // gtk_widget_set_sensitive(devicebox.cancelbutton, TRUE); + // gtk_window_set_focus(GTK_WINDOW(devicebox.window), devicebox.file); + ShowWindow(deviceboxwindow, SW_SHOW); + SetActiveWindow(deviceboxwindow); } // END DeviceBoxRefocus() - - - - -void DeviceBoxCancelEvent() { - - // ShowWindow(deviceboxwindow, SW_HIDE); - - DeviceBoxDestroy(); - - MainBoxRefocus(); - - return; - +void DeviceBoxCancelEvent() +{ + // ShowWindow(deviceboxwindow, SW_HIDE); + DeviceBoxDestroy(); + MainBoxRefocus(); + return; } // END DeviceBoxCancelEvent() - - - - -void DeviceBoxOKEvent() { - - char templine[256]; - - u8 tempbuffer[2352]; - - struct IsoFile *tofile; - - s32 retval; - - cdvdTD cdvdtd; - - int stop; - - HWND tempitem; - - int compressmethod; - - int multi; - - int imagetype; - - int i; - - - - DeviceBoxUnfocus(); - - - - GetDlgItemText(deviceboxwindow, IDC_0302, conf.devicename, 256); - - retval = DeviceOpen(); - - if(retval != 0) { - - DeviceClose(); - - DeviceBoxRefocus(); - - MessageBox(deviceboxwindow, - - "Could not open the device", - - "CDVDisoEFP Message", - - MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); - - return; - - } // ENDIF- Trouble opening device? Abort here. - - - - DeviceTrayStatus(); - - retval = DiscInserted(); - - if(retval != 0) { - - DeviceClose(); - - DeviceBoxRefocus(); - - MessageBox(deviceboxwindow, - - "No disc in the device\r\nPlease put a disc in and try again.", - - "CDVDisoEFP Message", - - MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); - - return; - - } // ENDIF- Trouble opening device? Abort here. - - - - retval = DeviceGetTD(0, &cdvdtd); // Fish for Ending Sector - - if(retval < 0) { - - DeviceClose(); - - DeviceBoxRefocus(); - - MessageBox(deviceboxwindow, - - "Could not retrieve disc sector size", - - "CDVDisoEFP Message", - - MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); - - return; - - } // ENDIF- Trouble getting disc sector count? - - - - tempitem = GetDlgItem(deviceboxwindow, IDC_0309); - - compressmethod = ComboBox_GetCurSel(tempitem); - - tempitem = NULL; - - if(compressmethod > 0) compressmethod += 2; - - - - multi = 0; - - if(IsDlgButtonChecked(deviceboxwindow, IDC_0311)) multi = 1; - - - - imagetype = 0; - - if((disctype != CDVD_TYPE_PS2DVD) && - - (disctype != CDVD_TYPE_DVDV)) imagetype = 8; - - - - GetDlgItemText(deviceboxwindow, IDC_0305, templine, 256); - - tofile = IsoFileOpenForWrite(templine, - - imagetype, - - multi, - - compressmethod); - - if(tofile == NULL) { - - DeviceClose(); - - DeviceBoxRefocus(); - - MessageBox(deviceboxwindow, - - "Could not create the new ISO file", - - "CDVDisoEFP Message", - - MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); - - return; - - } // ENDIF- Trouble opening the ISO file? - - - - // Open Progress Bar - - sprintf(templine, "%s -> %s", conf.devicename, tofile->name); - - ProgressBoxStart(templine, (off64_t) cdvdtd.lsn); - - - - tofile->cdvdtype = disctype; - - for(i = 0; i < 2048; i++) tofile->toc[i] = tocbuffer[i]; - - - - stop = 0; - - mainboxstop = 0; - - progressboxstop = 0; - - while((stop == 0) && (tofile->sectorpos < cdvdtd.lsn)) { - - if(imagetype == 0) { - - retval = DeviceReadTrack((u32) tofile->sectorpos, - - CDVD_MODE_2048, - - tempbuffer); - - } else { - - retval = DeviceReadTrack((u32) tofile->sectorpos, - - CDVD_MODE_2352, - - tempbuffer); - - } // ENDIF- Are we reading a DVD sector? (Or a CD sector?) - - if(retval < 0) { - - for(i = 0; i < 2352; i++) { - - tempbuffer[i] = 0; - - } // NEXT i- Zeroing the buffer - - } // ENDIF- Trouble reading next block? - - retval = IsoFileWrite(tofile, tempbuffer); - - if(retval < 0) { - - MessageBox(deviceboxwindow, - - "Trouble writing new file", - - "CDVDisoEFP Message", - - MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); - - stop = 1; - - } // ENDIF- Trouble writing out the next block? - - - - ProgressBoxTick(tofile->sectorpos); - - - - if(mainboxstop != 0) stop = 2; - - if(progressboxstop != 0) stop = 2; - - } // ENDWHILE- No reason found to stop... - - - - ProgressBoxStop(); - - - - if(stop == 0) { - - if(tofile->multi == 1) tofile->name[tofile->multipos] = '0'; // First file - - strcpy(templine, tofile->name); - - } // ENDIF- Did we succeed with the transfer? - - - - DeviceClose(); - - if(stop == 0) { - - IsoSaveTOC(tofile); - - tofile = IsoFileClose(tofile); - - SetDlgItemText(mainboxwindow, IDC_0202, templine); - - } else { - - tofile = IsoFileCloseAndDelete(tofile); - - } // ENDIF- (Failed to complete writing file? Get rid of the garbage files.) - - - - DeviceBoxRefocus(); - - if(stop == 0) DeviceBoxCancelEvent(); - - return; - +void DeviceBoxOKEvent() +{ + char templine[256]; + u8 tempbuffer[2352]; + struct IsoFile *tofile; + s32 retval; + cdvdTD cdvdtd; + int stop; + HWND tempitem; + int compressmethod; + int multi; + int imagetype; + int i; + DeviceBoxUnfocus(); + GetDlgItemText(deviceboxwindow, IDC_0302, conf.devicename, 256); + retval = DeviceOpen(); + if (retval != 0) + { + DeviceClose(); + DeviceBoxRefocus(); + MessageBox(deviceboxwindow, + "Could not open the device", + "CDVDisoEFP Message", + MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); + return; + } // ENDIF- Trouble opening device? Abort here. + DeviceTrayStatus(); + retval = DiscInserted(); + if (retval != 0) + { + DeviceClose(); + DeviceBoxRefocus(); + MessageBox(deviceboxwindow, + "No disc in the device\r\nPlease put a disc in and try again.", + "CDVDisoEFP Message", + MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); + return; + } // ENDIF- Trouble opening device? Abort here. + retval = DeviceGetTD(0, &cdvdtd); // Fish for Ending Sector + if (retval < 0) + { + DeviceClose(); + DeviceBoxRefocus(); + MessageBox(deviceboxwindow, + "Could not retrieve disc sector size", + "CDVDisoEFP Message", + MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); + return; + } // ENDIF- Trouble getting disc sector count? + + tempitem = GetDlgItem(deviceboxwindow, IDC_0309); + compressmethod = ComboBox_GetCurSel(tempitem); + tempitem = NULL; + if (compressmethod > 0) compressmethod += 2; + multi = 0; + if (IsDlgButtonChecked(deviceboxwindow, IDC_0311)) multi = 1; + + imagetype = 0; + if ((disctype != CDVD_TYPE_PS2DVD) && + (disctype != CDVD_TYPE_DVDV)) imagetype = 8; + + GetDlgItemText(deviceboxwindow, IDC_0305, templine, 256); + tofile = IsoFileOpenForWrite(templine, + imagetype, + multi, + compressmethod); + if (tofile == NULL) + { + DeviceClose(); + DeviceBoxRefocus(); + MessageBox(deviceboxwindow, + "Could not create the new ISO file", + "CDVDisoEFP Message", + MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); + return; + } // ENDIF- Trouble opening the ISO file? + // Open Progress Bar + sprintf(templine, "%s -> %s", conf.devicename, tofile->name); + ProgressBoxStart(templine, (off64_t) cdvdtd.lsn); + tofile->cdvdtype = disctype; + for (i = 0; i < 2048; i++) tofile->toc[i] = tocbuffer[i]; + + stop = 0; + mainboxstop = 0; + progressboxstop = 0; + while ((stop == 0) && (tofile->sectorpos < cdvdtd.lsn)) + { + if (imagetype == 0) + { + retval = DeviceReadTrack((u32) tofile->sectorpos, + CDVD_MODE_2048, + tempbuffer); + } + else + { + retval = DeviceReadTrack((u32) tofile->sectorpos, + CDVD_MODE_2352, + tempbuffer); + } // ENDIF- Are we reading a DVD sector? (Or a CD sector?) + if (retval < 0) + { + for (i = 0; i < 2352; i++) + { + tempbuffer[i] = 0; + } // NEXT i- Zeroing the buffer + } // ENDIF- Trouble reading next block? + retval = IsoFileWrite(tofile, tempbuffer); + if (retval < 0) + { + MessageBox(deviceboxwindow, + "Trouble writing new file", + "CDVDisoEFP Message", + MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); + stop = 1; + } // ENDIF- Trouble writing out the next block? + ProgressBoxTick(tofile->sectorpos); + if (mainboxstop != 0) stop = 2; + if (progressboxstop != 0) stop = 2; + } // ENDWHILE- No reason found to stop... + ProgressBoxStop(); + if (stop == 0) + { + if (tofile->multi == 1) tofile->name[tofile->multipos] = '0'; // First file + strcpy(templine, tofile->name); + } // ENDIF- Did we succeed with the transfer? + + DeviceClose(); + if (stop == 0) + { + IsoSaveTOC(tofile); + tofile = IsoFileClose(tofile); + SetDlgItemText(mainboxwindow, IDC_0202, templine); + } + else + { + tofile = IsoFileCloseAndDelete(tofile); + } // ENDIF- (Failed to complete writing file? Get rid of the garbage files.) + DeviceBoxRefocus(); + if (stop == 0) DeviceBoxCancelEvent(); + return; } // END DeviceBoxOKEvent() +void DeviceBoxBrowseEvent() +{ + OPENFILENAME filebox; + char newfilename[256]; + BOOL returnbool; + filebox.lStructSize = sizeof(filebox); + filebox.hwndOwner = deviceboxwindow; + filebox.hInstance = NULL; + filebox.lpstrFilter = fileselection; + filebox.lpstrCustomFilter = NULL; + filebox.nFilterIndex = 0; + filebox.lpstrFile = newfilename; + filebox.nMaxFile = 256; + filebox.lpstrFileTitle = NULL; + filebox.nMaxFileTitle = 0; + filebox.lpstrInitialDir = NULL; + filebox.lpstrTitle = NULL; + filebox.Flags = OFN_PATHMUSTEXIST + | OFN_NOCHANGEDIR + | OFN_HIDEREADONLY; + filebox.nFileOffset = 0; + filebox.nFileExtension = 0; + filebox.lpstrDefExt = NULL; + filebox.lCustData = 0; + filebox.lpfnHook = NULL; + filebox.lpTemplateName = NULL; + GetDlgItemText(deviceboxwindow, IDC_0305, newfilename, 256); + returnbool = GetOpenFileName(&filebox); + if (returnbool != FALSE) + { + SetDlgItemText(deviceboxwindow, IDC_0305, newfilename); + } // ENDIF- User actually selected a name? Save it. - -void DeviceBoxBrowseEvent() { - - OPENFILENAME filebox; - - char newfilename[256]; - - BOOL returnbool; - - - - filebox.lStructSize = sizeof(filebox); - - filebox.hwndOwner = deviceboxwindow; - - filebox.hInstance = NULL; - - filebox.lpstrFilter = fileselection; - - filebox.lpstrCustomFilter = NULL; - - filebox.nFilterIndex = 0; - - filebox.lpstrFile = newfilename; - - filebox.nMaxFile = 256; - - filebox.lpstrFileTitle = NULL; - - filebox.nMaxFileTitle = 0; - - filebox.lpstrInitialDir = NULL; - - filebox.lpstrTitle = NULL; - - filebox.Flags = OFN_PATHMUSTEXIST - - | OFN_NOCHANGEDIR - - | OFN_HIDEREADONLY; - - filebox.nFileOffset = 0; - - filebox.nFileExtension = 0; - - filebox.lpstrDefExt = NULL; - - filebox.lCustData = 0; - - filebox.lpfnHook = NULL; - - filebox.lpTemplateName = NULL; - - - - GetDlgItemText(deviceboxwindow, IDC_0305, newfilename, 256); - - returnbool = GetOpenFileName(&filebox); - - if(returnbool != FALSE) { - - SetDlgItemText(deviceboxwindow, IDC_0305, newfilename); - - } // ENDIF- User actually selected a name? Save it. - - - - return; - + return; } // END DeviceBoxBrowseEvent() +void DeviceBoxDisplay() +{ + char templine[256]; + HWND itemptr; + int itemcount; + // Adjust Window Position? + SetDlgItemText(deviceboxwindow, IDC_0302, conf.devicename); + // DeviceBoxDeviceEvent(); // Needed? + GetDlgItemText(mainboxwindow, IDC_0202, templine, 256); + SetDlgItemText(deviceboxwindow, IDC_0305, templine); + // DeviceBoxFileEvent(); // Needed? - - -void DeviceBoxDisplay() { - - char templine[256]; - - HWND itemptr; - - int itemcount; - - - - // Adjust Window Position? - - - - SetDlgItemText(deviceboxwindow, IDC_0302, conf.devicename); - - - - // DeviceBoxDeviceEvent(); // Needed? - - - - GetDlgItemText(mainboxwindow, IDC_0202, templine, 256); - - SetDlgItemText(deviceboxwindow, IDC_0305, templine); - - - - // DeviceBoxFileEvent(); // Needed? - - - - itemptr = GetDlgItem(deviceboxwindow, IDC_0309); // Compression Combo - - itemcount = 0; - - while(compressnames[itemcount] != NULL) { - - ComboBox_AddString(itemptr, compressnames[itemcount]); - - itemcount++; - - } // ENDWHILE- loading compression types into combo box - - ComboBox_SetCurSel(itemptr, 0); // First Selection? - - itemptr = NULL; - - - - CheckDlgButton(deviceboxwindow, IDC_0311, FALSE); // Start unchecked - - - - DeviceInit(); // Initialize device access - + itemptr = GetDlgItem(deviceboxwindow, IDC_0309); // Compression Combo + itemcount = 0; + while (compressnames[itemcount] != NULL) + { + ComboBox_AddString(itemptr, compressnames[itemcount]); + itemcount++; + } // ENDWHILE- loading compression types into combo box + ComboBox_SetCurSel(itemptr, 0); // First Selection? + itemptr = NULL; + CheckDlgButton(deviceboxwindow, IDC_0311, FALSE); // Start unchecked + DeviceInit(); // Initialize device access } // END DeviceBoxDisplay() - - - - BOOL CALLBACK DeviceBoxCallback(HWND window, - UINT msg, - WPARAM param, + LPARAM param2) +{ + switch (msg) + { + case WM_INITDIALOG: + deviceboxwindow = window; + DeviceBoxDisplay(); // Final touches to this window + return(FALSE); // Let Windows display this window + break; - LPARAM param2) { + case WM_CLOSE: // The "X" in the upper right corner was hit. + DeviceBoxCancelEvent(); + return(TRUE); + break; + case WM_COMMAND: + switch (LOWORD(param)) + { + case IDC_0302: // Device Edit Box + DeviceBoxDeviceEvent(); + return(FALSE); + break; - switch(msg) { + case IDC_0305: // Filename Edit Box + DeviceBoxFileEvent(); + return(FALSE); + break; + case IDC_0306: // "Browse" Button + DeviceBoxBrowseEvent(); + return(TRUE); + break; - case WM_INITDIALOG: - - deviceboxwindow = window; - - DeviceBoxDisplay(); // Final touches to this window - - return(FALSE); // Let Windows display this window - - break; - - - - case WM_CLOSE: // The "X" in the upper right corner was hit. - - DeviceBoxCancelEvent(); - - return(TRUE); - - break; - - - - case WM_COMMAND: - - switch(LOWORD(param)) { - - case IDC_0302: // Device Edit Box - - DeviceBoxDeviceEvent(); - - return(FALSE); - - break; - - - - case IDC_0305: // Filename Edit Box - - DeviceBoxFileEvent(); - - return(FALSE); - - break; - - - - case IDC_0306: // "Browse" Button - - DeviceBoxBrowseEvent(); - - return(TRUE); - - break; - - - - case IDC_0312: // "Make File" Button - - DeviceBoxOKEvent(); - - return(TRUE); - - break; - - - - case IDC_0313: // "Cancel" Button - - DeviceBoxCancelEvent(); - - return(TRUE); - - break; - - } // ENDSWITCH param- Which object got the message? - - } // ENDSWITCH msg- What message has been sent to this window? - - - - return(FALSE); + case IDC_0312: // "Make File" Button + DeviceBoxOKEvent(); + return(TRUE); + break; + case IDC_0313: // "Cancel" Button + DeviceBoxCancelEvent(); + return(TRUE); + break; + } // ENDSWITCH param- Which object got the message? + } // ENDSWITCH msg- What message has been sent to this window? + return(FALSE); } // END DeviceBoxCallback() - diff --git a/plugins/CDVDisoEFP/src/Win32/devicebox.h b/plugins/CDVDisoEFP/src/Win32/devicebox.h index aa693e3e98..88bbb8de18 100644 --- a/plugins/CDVDisoEFP/src/Win32/devicebox.h +++ b/plugins/CDVDisoEFP/src/Win32/devicebox.h @@ -1,82 +1,36 @@ /* devicebox.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef DEVICEBOX_H - #define DEVICEBOX_H - - - - #include // HWND - - - - extern HWND deviceboxwindow; - - - extern void DeviceBoxDestroy(); - // extern void DeviceBoxUnfocus(); - extern void DeviceBoxRefocus(); - extern void DeviceBoxDisplay(); - extern BOOL CALLBACK DeviceBoxCallback(HWND window, - - UINT msg, - - WPARAM param, - - LPARAM param2); - - - - + UINT msg, + WPARAM param, + LPARAM param2); #endif /* DEVICEBOX_H */ - diff --git a/plugins/CDVDisoEFP/src/Win32/logfile.c b/plugins/CDVDisoEFP/src/Win32/logfile.c index 8d1226e298..c771189725 100644 --- a/plugins/CDVDisoEFP/src/Win32/logfile.c +++ b/plugins/CDVDisoEFP/src/Win32/logfile.c @@ -1,238 +1,126 @@ -/* logfile.c - - * Copyright (C) 2002-2005 PCSX2 Team - - * - - * This program is free software; you can redistribute it and/or modify - - * it under the terms of the GNU General Public License as published by - - * the Free Software Foundation; either version 2 of the License, or - - * (at your option) any later version. - - * - - * This program is distributed in the hope that it will be useful, - - * but WITHOUT ANY WARRANTY; without even the implied warranty of - - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - - * GNU General Public License for more details. - - * - - * You should have received a copy of the GNU General Public License - - * along with this program; if not, write to the Free Software - - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - * - - * PCSX2 members can be contacted through their website at www.pcsx2.net. - - */ - - - - - -#include - - - -// #include // open() - -// #include // mkdir() - -#include // NULL - -#include // vsprintf() - -#include // va_start(), va_end(), vsprintf() - -// #include // open() - -// #include // open() - - - -#include "logfile.h" - - - - - -HANDLE logfile; - -char logfiletemp[2048]; - - - - - -void InitLog() { - - // Token comment line - -#ifdef VERBOSE_LOGFILE - - CreateDirectory("logs", NULL); - - - - DeleteFile("logs\\CDVDlog.txt"); - - logfile = NULL; - -#endif /* VERBOSE LOGFILE */ - -} // END InitLog(); - - - - - -int OpenLog() { - - // Token comment line - -#ifdef VERBOSE_LOGFILE - - logfile = CreateFile("logs\\CDVDlog.txt", - - GENERIC_WRITE, - - 0, - - NULL, - - CREATE_ALWAYS, - - FILE_FLAG_SEQUENTIAL_SCAN, - - NULL); - - if(logfile == INVALID_HANDLE_VALUE) { - - logfile = NULL; - - return(-1); - - } // ENDIF- Failed to open? Say so. - -#endif /* VERBOSE LOGFILE */ - - - - return(0); - -} // END OpenLog(); - - - - - -void CloseLog() { - - // Token comment line - -#ifdef VERBOSE_LOGFILE - - if(logfile != NULL) { - - CloseHandle(logfile); - - logfile = NULL; - - } // ENDIF- Is the log file actually open? Close it. - -#endif /* VERBOSE LOGFILE */ - -} // END CloseLog() - - - - - -void PrintLog(const char *fmt, ...) { - - DWORD byteswritten; - - - - // Token comment line - -#ifdef VERBOSE_LOGFILE - - va_list list; - - int len; - - - - if(logfile == NULL) return; // Log file not open... yet. - - - - va_start(list, fmt); - - vsprintf(logfiletemp, fmt, list); - - va_end(list); - - - - len = 0; - - while((len < 2048) && (logfiletemp[len] != 0)) len++; - - if((len > 0) && (logfiletemp[len-1] == '\n')) len--; - - if((len > 0) && (logfiletemp[len-1] == '\r')) len--; - - logfiletemp[len] = 0; // Slice off the last "\r\n"... - - - - WriteFile(logfile, logfiletemp, len, &byteswritten, NULL); - - WriteFile(logfile, "\r\n", 2, &byteswritten, NULL); - -#endif /* VERBOSE LOGFILE */ - -} // END PrintLog() - - - -void PrintError(const char *header, DWORD errcode) { - -#ifdef VERBOSE_LOGFILE - - TCHAR errmsg[256]; - - - - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | 80, - - NULL, - - errcode, - - 0, - - errmsg, - - 256, - - NULL); - - PrintLog("%s: (%u) %s", header, errcode, errmsg); - -#endif /* VERBOSE_WARNING_DEVICE */ - -} // END PrintError() - +/* logfile.c + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +#include + +// #include // open() +// #include // mkdir() +#include // NULL +#include // vsprintf() +#include // va_start(), va_end(), vsprintf() +// #include // open() +// #include // open() + +#include "logfile.h" + + +HANDLE logfile; +char logfiletemp[2048]; + + +void InitLog() +{ + // Token comment line +#ifdef VERBOSE_LOGFILE + CreateDirectory("logs", NULL); + + DeleteFile("logs\\CDVDlog.txt"); + logfile = NULL; +#endif /* VERBOSE LOGFILE */ +} // END InitLog(); + + +int OpenLog() +{ + // Token comment line +#ifdef VERBOSE_LOGFILE + logfile = CreateFile("logs\\CDVDlog.txt", + GENERIC_WRITE, + 0, + NULL, + CREATE_ALWAYS, + FILE_FLAG_SEQUENTIAL_SCAN, + NULL); + if (logfile == INVALID_HANDLE_VALUE) + { + logfile = NULL; + return(-1); + } // ENDIF- Failed to open? Say so. +#endif /* VERBOSE LOGFILE */ + + return(0); +} // END OpenLog(); + + +void CloseLog() +{ + // Token comment line +#ifdef VERBOSE_LOGFILE + if (logfile != NULL) + { + CloseHandle(logfile); + logfile = NULL; + } // ENDIF- Is the log file actually open? Close it. +#endif /* VERBOSE LOGFILE */ +} // END CloseLog() + + +void PrintLog(const char *fmt, ...) +{ + DWORD byteswritten; + + // Token comment line +#ifdef VERBOSE_LOGFILE + va_list list; + int len; + + if (logfile == NULL) return; // Log file not open... yet. + + va_start(list, fmt); + vsprintf(logfiletemp, fmt, list); + va_end(list); + + len = 0; + while ((len < 2048) && (logfiletemp[len] != 0)) len++; + if ((len > 0) && (logfiletemp[len-1] == '\n')) len--; + if ((len > 0) && (logfiletemp[len-1] == '\r')) len--; + logfiletemp[len] = 0; // Slice off the last "\r\n"... + + WriteFile(logfile, logfiletemp, len, &byteswritten, NULL); + WriteFile(logfile, "\r\n", 2, &byteswritten, NULL); +#endif /* VERBOSE LOGFILE */ +} // END PrintLog() + +void PrintError(const char *header, DWORD errcode) +{ +#ifdef VERBOSE_LOGFILE + TCHAR errmsg[256]; + + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | 80, + NULL, + errcode, + 0, + errmsg, + 256, + NULL); + PrintLog("%s: (%u) %s", header, errcode, errmsg); +#endif /* VERBOSE_WARNING_DEVICE */ +} // END PrintError() diff --git a/plugins/CDVDisoEFP/src/Win32/logfile.h b/plugins/CDVDisoEFP/src/Win32/logfile.h index 3efaad8f4d..a0ffd9be8b 100644 --- a/plugins/CDVDisoEFP/src/Win32/logfile.h +++ b/plugins/CDVDisoEFP/src/Win32/logfile.h @@ -1,78 +1,34 @@ /* logfile.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef LOGFILE_H - #define LOGFILE_H - - - - #include // Just for DWORD - - - - #define VERBOSE_LOGFILE - - - - extern void InitLog(); - extern int OpenLog(); - extern void CloseLog(); - extern void PrintLog(const char *format, ...); - extern void PrintError(const char *header, DWORD errcode); - - - - #endif /* LOGFILE_H */ - diff --git a/plugins/CDVDisoEFP/src/Win32/mainbox.c b/plugins/CDVDisoEFP/src/Win32/mainbox.c index 2b831829b4..bd18ba7293 100644 --- a/plugins/CDVDisoEFP/src/Win32/mainbox.c +++ b/plugins/CDVDisoEFP/src/Win32/mainbox.c @@ -15,15 +15,11 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - - #include #include // Button_ #include // NULL - #include // sprintf() #include // strcpy() - #include "conf.h" #include "isofile.h" #include "isocompress.h" // compressdesc[] @@ -37,273 +33,264 @@ #include "CDVDiso.h" // progmodule #include "mainbox.h" - const char fileselection[] = "\Disc Image Files (*.bin,*.img,*.iso,*.nrg)\0*.bin;*.img;*.iso;*.nrg\0\All Files (*.*)\0*.*\0\\0\0"; - HWND mainboxwindow; int mainboxstop; - - -void MainBoxDestroy() { - if(progressboxwindow != NULL) { - ProgressBoxDestroy(); - } // ENDIF- Do we have a Progress Window still? - - if(mainboxwindow != NULL) { - EndDialog(mainboxwindow, FALSE); - mainboxwindow = NULL; - } // ENDIF- Do we have a Main Window still? +void MainBoxDestroy() +{ + if (progressboxwindow != NULL) + { + ProgressBoxDestroy(); + } // ENDIF- Do we have a Progress Window still? + if (mainboxwindow != NULL) + { + EndDialog(mainboxwindow, FALSE); + mainboxwindow = NULL; + } // ENDIF- Do we have a Main Window still? } // END MainBoxDestroy() - - -void MainBoxUnfocus() { - // EnableWindow(?) - // gtk_widget_set_sensitive(mainbox.file, FALSE); - // gtk_widget_set_sensitive(mainbox.selectbutton, FALSE); - // gtk_widget_set_sensitive(mainbox.okbutton, FALSE); - // gtk_widget_set_sensitive(mainbox.devbutton, FALSE); - // gtk_widget_set_sensitive(mainbox.convbutton, FALSE); - ShowWindow(mainboxwindow, SW_HIDE); +void MainBoxUnfocus() +{ + // EnableWindow(?) + // gtk_widget_set_sensitive(mainbox.file, FALSE); + // gtk_widget_set_sensitive(mainbox.selectbutton, FALSE); + // gtk_widget_set_sensitive(mainbox.okbutton, FALSE); + // gtk_widget_set_sensitive(mainbox.devbutton, FALSE); + // gtk_widget_set_sensitive(mainbox.convbutton, FALSE); + ShowWindow(mainboxwindow, SW_HIDE); } // END MainBoxUnfocus() +void MainBoxFileEvent() +{ + int returnval; + char templine[256]; + struct IsoFile *tempfile; + GetDlgItemText(mainboxwindow, IDC_0202, templine, 256); + returnval = IsIsoFile(templine); + if (returnval == -1) + { + SetDlgItemText(mainboxwindow, IDC_0204, "File Type: ---"); + return; + } // ENDIF- Not a name of any sort? + if (returnval == -2) + { + SetDlgItemText(mainboxwindow, IDC_0204, "File Type: Not a file"); + return; + } // ENDIF- Not a regular file? + if (returnval == -3) + { + SetDlgItemText(mainboxwindow, IDC_0204, "File Type: Not a valid image file"); + return; + } // ENDIF- Not an Image file? + if (returnval == -4) + { + SetDlgItemText(mainboxwindow, IDC_0204, "File Type: Missing Table File (will rebuild)"); + return; + } // ENDIF- Missing Compression seek table? -void MainBoxFileEvent() { - int returnval; - char templine[256]; - struct IsoFile *tempfile; - - GetDlgItemText(mainboxwindow, IDC_0202, templine, 256); - returnval = IsIsoFile(templine); - if(returnval == -1) { - SetDlgItemText(mainboxwindow, IDC_0204, "File Type: ---"); - return; - } // ENDIF- Not a name of any sort? - - if(returnval == -2) { - SetDlgItemText(mainboxwindow, IDC_0204, "File Type: Not a file"); - return; - } // ENDIF- Not a regular file? - - if(returnval == -3) { - SetDlgItemText(mainboxwindow, IDC_0204, "File Type: Not a valid image file"); - return; - } // ENDIF- Not an Image file? - - if(returnval == -4) { - SetDlgItemText(mainboxwindow, IDC_0204, "File Type: Missing Table File (will rebuild)"); - return; - } // ENDIF- Missing Compression seek table? - - tempfile = IsoFileOpenForRead(templine); - sprintf(templine, "File Type: %s%s%s", - multinames[tempfile->multi], - tempfile->imagename, - compressdesc[tempfile->compress]); - SetDlgItemText(mainboxwindow, IDC_0204, templine); - tempfile = IsoFileClose(tempfile); - return; + tempfile = IsoFileOpenForRead(templine); + sprintf(templine, "File Type: %s%s%s", + multinames[tempfile->multi], + tempfile->imagename, + compressdesc[tempfile->compress]); + SetDlgItemText(mainboxwindow, IDC_0204, templine); + tempfile = IsoFileClose(tempfile); + return; } // END MainBoxFileEvent() - -void MainBoxRefocus() { - MainBoxFileEvent(); - - // gtk_widget_set_sensitive(mainbox.file, TRUE); - // gtk_widget_set_sensitive(mainbox.selectbutton, TRUE); - // gtk_widget_set_sensitive(mainbox.okbutton, TRUE); - // gtk_widget_set_sensitive(mainbox.devbutton, TRUE); - // gtk_widget_set_sensitive(mainbox.convbutton, TRUE); - // gtk_window_set_focus(GTK_WINDOW(mainbox.window), mainbox.file); - // ShowWindow(mainboxwindow, SW_RESTORE); // and/or, SW_SHOW? SW_SHOWNORMAL? - ShowWindow(mainboxwindow, SW_SHOW); - SetActiveWindow(mainboxwindow); +void MainBoxRefocus() +{ + MainBoxFileEvent(); + // gtk_widget_set_sensitive(mainbox.file, TRUE); + // gtk_widget_set_sensitive(mainbox.selectbutton, TRUE); + // gtk_widget_set_sensitive(mainbox.okbutton, TRUE); + // gtk_widget_set_sensitive(mainbox.devbutton, TRUE); + // gtk_widget_set_sensitive(mainbox.convbutton, TRUE); + // gtk_window_set_focus(GTK_WINDOW(mainbox.window), mainbox.file); + // ShowWindow(mainboxwindow, SW_RESTORE); // and/or, SW_SHOW? SW_SHOWNORMAL? + ShowWindow(mainboxwindow, SW_SHOW); + SetActiveWindow(mainboxwindow); } // END MainBoxRefocus() - -void MainBoxCancelEvent() { - mainboxstop = 1; // Halt all long processess... - - MainBoxDestroy(); - return; +void MainBoxCancelEvent() +{ + mainboxstop = 1; // Halt all long processess... + MainBoxDestroy(); + return; } // END MainBoxCancelEvent() +void MainBoxOKEvent() +{ + char tempisoname[256]; + MainBoxUnfocus(); + GetDlgItemText(mainboxwindow, IDC_0202, tempisoname, 256); + if (*(tempisoname) != 0) + { + if (IsIsoFile(tempisoname) == -4) + { + IsoTableRebuild(tempisoname); + MainBoxRefocus(); + return; + } // ENDIF- Do we need to rebuild an image file's index before using it? + if (IsIsoFile(tempisoname) < 0) + { + MainBoxRefocus(); + MessageBox(mainboxwindow, + "Not a Valid Image File.", + "CDVDisoEFP Message", + MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); + return; + } // ENDIF- Not an ISO file? Message and Stop here. + } // ENDIF- Do we have a name to check out? + strcpy(conf.isoname, tempisoname); + if (Button_GetCheck(GetDlgItem(mainboxwindow, IDC_0209)) == BST_UNCHECKED) + { + conf.startconfigure = 0; // FALSE + } + else + { + conf.startconfigure = 1; // TRUE + } // ENDIF- Was this checkbox unchecked? + if (Button_GetCheck(GetDlgItem(mainboxwindow, IDC_0210)) == BST_UNCHECKED) + { + conf.restartconfigure = 0; // FALSE + } + else + { + conf.restartconfigure = 1; // TRUE + } // ENDIF- Was this checkbox unchecked? + SaveConf(); -void MainBoxOKEvent() { - char tempisoname[256]; - - MainBoxUnfocus(); - - GetDlgItemText(mainboxwindow, IDC_0202, tempisoname, 256); - if(*(tempisoname) != 0) { - if(IsIsoFile(tempisoname) == -4) { - IsoTableRebuild(tempisoname); - MainBoxRefocus(); - return; - } // ENDIF- Do we need to rebuild an image file's index before using it? - - if(IsIsoFile(tempisoname) < 0) { - MainBoxRefocus(); - MessageBox(mainboxwindow, - "Not a Valid Image File.", - "CDVDisoEFP Message", - MB_OK | MB_ICONWARNING | MB_SETFOREGROUND); - return; - } // ENDIF- Not an ISO file? Message and Stop here. - } // ENDIF- Do we have a name to check out? - - strcpy(conf.isoname, tempisoname); - if(Button_GetCheck(GetDlgItem(mainboxwindow, IDC_0209)) == BST_UNCHECKED) { - conf.startconfigure = 0; // FALSE - } else { - conf.startconfigure = 1; // TRUE - } // ENDIF- Was this checkbox unchecked? - if(Button_GetCheck(GetDlgItem(mainboxwindow, IDC_0210)) == BST_UNCHECKED) { - conf.restartconfigure = 0; // FALSE - } else { - conf.restartconfigure = 1; // TRUE - } // ENDIF- Was this checkbox unchecked? - SaveConf(); - - MainBoxCancelEvent(); - return; + MainBoxCancelEvent(); + return; } // END MainBoxOKEvent() - -void MainBoxBrowseEvent() { - OPENFILENAME filebox; - char newfilename[256]; - BOOL returnbool; - - filebox.lStructSize = sizeof(filebox); - filebox.hwndOwner = mainboxwindow; - filebox.hInstance = NULL; - filebox.lpstrFilter = fileselection; - filebox.lpstrCustomFilter = NULL; - filebox.nFilterIndex = 0; - filebox.lpstrFile = newfilename; - filebox.nMaxFile = 256; - filebox.lpstrFileTitle = NULL; - filebox.nMaxFileTitle = 0; - filebox.lpstrInitialDir = NULL; - filebox.lpstrTitle = NULL; - filebox.Flags = OFN_FILEMUSTEXIST - | OFN_NOCHANGEDIR - | OFN_HIDEREADONLY; - filebox.nFileOffset = 0; - filebox.nFileExtension = 0; - filebox.lpstrDefExt = NULL; - filebox.lCustData = 0; - filebox.lpfnHook = NULL; - filebox.lpTemplateName = NULL; - - GetDlgItemText(mainboxwindow, IDC_0202, newfilename, 256); - returnbool = GetOpenFileName(&filebox); - if(returnbool != FALSE) { - SetDlgItemText(mainboxwindow, IDC_0202, newfilename); - } // ENDIF- User actually selected a name? Save it. - - return; +void MainBoxBrowseEvent() +{ + OPENFILENAME filebox; + char newfilename[256]; + BOOL returnbool; + filebox.lStructSize = sizeof(filebox); + filebox.hwndOwner = mainboxwindow; + filebox.hInstance = NULL; + filebox.lpstrFilter = fileselection; + filebox.lpstrCustomFilter = NULL; + filebox.nFilterIndex = 0; + filebox.lpstrFile = newfilename; + filebox.nMaxFile = 256; + filebox.lpstrFileTitle = NULL; + filebox.nMaxFileTitle = 0; + filebox.lpstrInitialDir = NULL; + filebox.lpstrTitle = NULL; + filebox.Flags = OFN_FILEMUSTEXIST + | OFN_NOCHANGEDIR + | OFN_HIDEREADONLY; + filebox.nFileOffset = 0; + filebox.nFileExtension = 0; + filebox.lpstrDefExt = NULL; + filebox.lCustData = 0; + filebox.lpfnHook = NULL; + filebox.lpTemplateName = NULL; + GetDlgItemText(mainboxwindow, IDC_0202, newfilename, 256); + returnbool = GetOpenFileName(&filebox); + if (returnbool != FALSE) + { + SetDlgItemText(mainboxwindow, IDC_0202, newfilename); + } // ENDIF- User actually selected a name? Save it. + return; } // END MainBoxBrowseEvent() - -void MainBoxDeviceEvent() { - MainBoxUnfocus(); - - DialogBox(progmodule, - MAKEINTRESOURCE(DLG_0300), - mainboxwindow, - (DLGPROC)DeviceBoxCallback); - return; +void MainBoxDeviceEvent() +{ + MainBoxUnfocus(); + DialogBox(progmodule, + MAKEINTRESOURCE(DLG_0300), + mainboxwindow, + (DLGPROC)DeviceBoxCallback); + return; } // END MainBoxBrowseEvent() +void MainBoxConversionEvent() +{ + MainBoxUnfocus(); - -void MainBoxConversionEvent() { - MainBoxUnfocus(); - - DialogBox(progmodule, - MAKEINTRESOURCE(DLG_0400), - mainboxwindow, - (DLGPROC)ConversionBoxCallback); - return; + DialogBox(progmodule, + MAKEINTRESOURCE(DLG_0400), + mainboxwindow, + (DLGPROC)ConversionBoxCallback); + return; } // END MainBoxBrowseEvent() - - -void MainBoxDisplay() { - LoadConf(); - - // Adjust window position? - - // We held off setting the name until now... so description would show. - SetDlgItemText(mainboxwindow, IDC_0202, conf.isoname); - if(conf.startconfigure == 0) { - Button_SetCheck(GetDlgItem(mainboxwindow, IDC_0209), BST_UNCHECKED); - } else { - Button_SetCheck(GetDlgItem(mainboxwindow, IDC_0209), BST_CHECKED); - } // ENDIF- Do we need to uncheck this box? - if(conf.restartconfigure == 0) { - Button_SetCheck(GetDlgItem(mainboxwindow, IDC_0210), BST_UNCHECKED); - } else { - Button_SetCheck(GetDlgItem(mainboxwindow, IDC_0210), BST_CHECKED); - } // ENDIF- Do we need to uncheck this box? - - // First Time - Show the window - ShowWindow(mainboxwindow, SW_SHOWNORMAL); +void MainBoxDisplay() +{ + LoadConf(); + // Adjust window position? + // We held off setting the name until now... so description would show. + SetDlgItemText(mainboxwindow, IDC_0202, conf.isoname); + if (conf.startconfigure == 0) + { + Button_SetCheck(GetDlgItem(mainboxwindow, IDC_0209), BST_UNCHECKED); + } + else + { + Button_SetCheck(GetDlgItem(mainboxwindow, IDC_0209), BST_CHECKED); + } // ENDIF- Do we need to uncheck this box? + if (conf.restartconfigure == 0) + { + Button_SetCheck(GetDlgItem(mainboxwindow, IDC_0210), BST_UNCHECKED); + } + else + { + Button_SetCheck(GetDlgItem(mainboxwindow, IDC_0210), BST_CHECKED); + } // ENDIF- Do we need to uncheck this box? + // First Time - Show the window + ShowWindow(mainboxwindow, SW_SHOWNORMAL); } // END MainBoxDisplay() - - BOOL CALLBACK MainBoxCallback(HWND window, UINT msg, WPARAM param, - LPARAM param2) { - switch(msg) { - case WM_INITDIALOG: - mainboxwindow = window; - MainBoxDisplay(); // In this case, final touches to this window. - ProgressBoxDisplay(); // Create the Progress Box at this time. - return(FALSE); // And let Windows display this window. - break; + LPARAM param2) +{ + switch (msg) + { + case WM_INITDIALOG: + mainboxwindow = window; + MainBoxDisplay(); // In this case, final touches to this window. + ProgressBoxDisplay(); // Create the Progress Box at this time. + return(FALSE); // And let Windows display this window. + break; + case WM_CLOSE: // The "X" in the upper right corner was hit. + MainBoxCancelEvent(); + return(TRUE); + break; + case WM_COMMAND: + // Do we wish to capture 'ENTER/RETURN' and/or 'ESC' here? + switch (LOWORD(param)) + { + case IDC_0202: // Filename Edit Box + MainBoxFileEvent(); // Describe the File's type... + return(FALSE); // Let Windows handle the actual 'edit' processing... + break; + case IDC_0203: // "Browse" Button + MainBoxBrowseEvent(); + return(TRUE); + break; + case IDC_0205: // "Ok" Button + MainBoxOKEvent(); + return(TRUE); + break; + case IDC_0206: // "Get from Disc" Button + MainBoxDeviceEvent(); + return(TRUE); + break; - case WM_CLOSE: // The "X" in the upper right corner was hit. - MainBoxCancelEvent(); - return(TRUE); - break; - - case WM_COMMAND: - // Do we wish to capture 'ENTER/RETURN' and/or 'ESC' here? - - switch(LOWORD(param)) { - case IDC_0202: // Filename Edit Box - MainBoxFileEvent(); // Describe the File's type... - return(FALSE); // Let Windows handle the actual 'edit' processing... - break; - - case IDC_0203: // "Browse" Button - MainBoxBrowseEvent(); - return(TRUE); - break; - - case IDC_0205: // "Ok" Button - MainBoxOKEvent(); - return(TRUE); - break; - - case IDC_0206: // "Get from Disc" Button - MainBoxDeviceEvent(); - return(TRUE); - break; - - case IDC_0207: // "Convert" Button - MainBoxConversionEvent(); - return(TRUE); - break; - - case IDC_0208: // "Cancel" Button - MainBoxCancelEvent(); - return(TRUE); - break; - } // ENDSWITCH param- Which object got the message? - } // ENDSWITCH msg- what message has been sent to this window? - - return(FALSE); // Not a recognized message? Tell Windows to handle it. + case IDC_0207: // "Convert" Button + MainBoxConversionEvent(); + return(TRUE); + break; + case IDC_0208: // "Cancel" Button + MainBoxCancelEvent(); + return(TRUE); + break; + } // ENDSWITCH param- Which object got the message? + } // ENDSWITCH msg- what message has been sent to this window? + return(FALSE); // Not a recognized message? Tell Windows to handle it. } // END MainBoxEventLoop() diff --git a/plugins/CDVDisoEFP/src/Win32/mainbox.h b/plugins/CDVDisoEFP/src/Win32/mainbox.h index f1431054b8..c87a2e6c85 100644 --- a/plugins/CDVDisoEFP/src/Win32/mainbox.h +++ b/plugins/CDVDisoEFP/src/Win32/mainbox.h @@ -1,86 +1,37 @@ /* mainbox.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef MAINBOX_H - #define MAINBOX_H - - - - #include // HWND - - - - extern const char fileselection[]; - - - extern HWND mainboxwindow; - extern int mainboxstop; - - - - extern void MainBoxRefocus(); - extern void MainBoxDisplay(); - extern BOOL CALLBACK MainBoxCallback(HWND window, - - UINT msg, - - WPARAM param, - - LPARAM param2); - - - - + UINT msg, + WPARAM param, + LPARAM param2); #endif /* MAINBOX_H */ - diff --git a/plugins/CDVDisoEFP/src/Win32/progressbox.c b/plugins/CDVDisoEFP/src/Win32/progressbox.c index 0666c6e7b1..2db83952dc 100644 --- a/plugins/CDVDisoEFP/src/Win32/progressbox.c +++ b/plugins/CDVDisoEFP/src/Win32/progressbox.c @@ -1,340 +1,165 @@ /* progressbox.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include - #include // Enable_Button() - #include // NULL - #include // PBM_... - - - #include // sprintf() - #include // strcat() - #include // off64_t - - - #include "CDVDiso.h" // progmodule - #include "screens.h" - #include "mainbox.h" - #include "progressbox.h" - - - - HWND progressboxwindow; - HWND progressboxbar; - int progressboxstop; - - - off64_t progressboxmax; - off64_t progressboxlastpct; - char progressboxline[256]; - char progressboxmaxchar[16]; - - - - -void ProgressBoxDestroy() { - - if(progressboxwindow != NULL) { - - DestroyWindow(progressboxwindow); - - progressboxwindow = NULL; - - progressboxbar = NULL; - - } // ENDIF- Do we have a Progress Window still? - - return; - +void ProgressBoxDestroy() +{ + if (progressboxwindow != NULL) + { + DestroyWindow(progressboxwindow); + progressboxwindow = NULL; + progressboxbar = NULL; + } // ENDIF- Do we have a Progress Window still? + return; } // END ProgressBoxDestroy() +void ProgressBoxStart(char *description, off64_t maximum) +{ + SetDlgItemText(progressboxwindow, IDC_0501, description); - - - -void ProgressBoxStart(char *description, off64_t maximum) { - - SetDlgItemText(progressboxwindow, IDC_0501, description); - - - - progressboxmax = maximum; - - sprintf(progressboxmaxchar, "%llu", maximum); - - progressboxlastpct = 100; - - progressboxstop = 0; - - - - ProgressBoxTick(0); - - ShowWindow(progressboxwindow, SW_SHOW); - - SetForegroundWindow(progressboxwindow); - - return; - + progressboxmax = maximum; + sprintf(progressboxmaxchar, "%llu", maximum); + progressboxlastpct = 100; + progressboxstop = 0; + ProgressBoxTick(0); + ShowWindow(progressboxwindow, SW_SHOW); + SetForegroundWindow(progressboxwindow); + return; } // END ProgressBoxStart() +void ProgressBoxTick(off64_t current) +{ + off64_t thispct; + MSG msg; + BOOL returnbool; + sprintf(progressboxline, "%llu of ", current); + strcat(progressboxline, progressboxmaxchar); + SetDlgItemText(progressboxwindow, IDC_0503, progressboxline); + if (progressboxmax >= 30000) + { + SendMessage(progressboxbar, PBM_SETPOS, current / (progressboxmax / 30000), 0); + } + else + { + SendMessage(progressboxbar, PBM_SETPOS, (current * 30000) / progressboxmax, 0); + } // ENDIF- Our maximum # over 30000? (Avoiding divide-by-zero error) + if (progressboxmax >= 100) + { + thispct = current / (progressboxmax / 100); + if (thispct != progressboxlastpct) + { + sprintf(progressboxline, "%llu%% CDVDisoEFP Progress", thispct); + SetWindowText(progressboxwindow, progressboxline); + progressboxlastpct = thispct; + } // ENDIF- Change in percentage? (Avoiding title flicker) + } // ENDIF- Our maximum # over 100? (Avoiding divide-by-zero error) - - - -void ProgressBoxTick(off64_t current) { - - off64_t thispct; - - MSG msg; - - BOOL returnbool; - - - - sprintf(progressboxline, "%llu of ", current); - - strcat(progressboxline, progressboxmaxchar); - - SetDlgItemText(progressboxwindow, IDC_0503, progressboxline); - - - - if(progressboxmax >= 30000 ) { - - SendMessage(progressboxbar, PBM_SETPOS, current / (progressboxmax / 30000), 0); - - } else { - - SendMessage(progressboxbar, PBM_SETPOS, (current * 30000) / progressboxmax, 0); - - } // ENDIF- Our maximum # over 30000? (Avoiding divide-by-zero error) - - - - if(progressboxmax >= 100) { - - thispct = current / ( progressboxmax / 100 ); - - if(thispct != progressboxlastpct) { - - sprintf(progressboxline, "%llu%% CDVDisoEFP Progress", thispct); - - SetWindowText(progressboxwindow, progressboxline); - - progressboxlastpct = thispct; - - } // ENDIF- Change in percentage? (Avoiding title flicker) - - } // ENDIF- Our maximum # over 100? (Avoiding divide-by-zero error) - - - - returnbool = PeekMessage(&msg, progressboxwindow, 0, 0, PM_REMOVE); - - while(returnbool != FALSE) { - - TranslateMessage(&msg); - - DispatchMessage(&msg); - - returnbool = PeekMessage(&msg, progressboxwindow, 0, 0, PM_REMOVE); - - } // ENDWHILE- Updating the progress window display as needed - - return; - + returnbool = PeekMessage(&msg, progressboxwindow, 0, 0, PM_REMOVE); + while (returnbool != FALSE) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + returnbool = PeekMessage(&msg, progressboxwindow, 0, 0, PM_REMOVE); + } // ENDWHILE- Updating the progress window display as needed + return; } // END ProgressBoxTick() - - - - -void ProgressBoxStop() { - - ShowWindow(progressboxwindow, SW_HIDE); - - SetWindowText(progressboxwindow, "CDVDisoEFP Progress"); - - return; - +void ProgressBoxStop() +{ + ShowWindow(progressboxwindow, SW_HIDE); + SetWindowText(progressboxwindow, "CDVDisoEFP Progress"); + return; } // END ProgressBoxStop() +void ProgressBoxCancelEvent() +{ + progressboxstop = 1; - - - -void ProgressBoxCancelEvent() { - - progressboxstop = 1; - - - - return; - + return; } // END ProgressBoxCancelEvent() - - - - BOOL CALLBACK ProgressBoxCallback(HWND window, - UINT msg, - WPARAM param, + LPARAM param2) +{ + switch (msg) + { + case WM_INITDIALOG: + return(TRUE); + break; + case WM_CLOSE: // The "X" in the upper right corner is hit. + ProgressBoxCancelEvent(); + return(TRUE); + break; - LPARAM param2) { - - switch(msg) { - - case WM_INITDIALOG: - - return(TRUE); - - break; - - - - case WM_CLOSE: // The "X" in the upper right corner is hit. - - ProgressBoxCancelEvent(); - - return(TRUE); - - break; - - - - case WM_COMMAND: - - switch(LOWORD(param)) { - - case IDC_0504: - - ProgressBoxCancelEvent(); - - return(TRUE); - - break; - - } // ENDSWITCH param- Which item got the message? - - - - // Hmm. Custom control? (for WM_GETFONT and WM_SETFONT msgs?) - - } // ENDSWITCH msg- what message has been sent to this window? - - - - return(FALSE); // Not a recognized message? Tell Windows to handle it. + case WM_COMMAND: + switch (LOWORD(param)) + { + case IDC_0504: + ProgressBoxCancelEvent(); + return(TRUE); + break; + } // ENDSWITCH param- Which item got the message? + // Hmm. Custom control? (for WM_GETFONT and WM_SETFONT msgs?) + } // ENDSWITCH msg- what message has been sent to this window? + return(FALSE); // Not a recognized message? Tell Windows to handle it. } // ENDIF ProgressBoxCallback() +void ProgressBoxDisplay() +{ + // ? progressload + LPARAM range; + InitCommonControls(); + // progressload. + // progressload. = ICC_PROGRESS_CLASS + // InitCommonControlsEx(&progressload); - - - -void ProgressBoxDisplay() { - - // ? progressload - - LPARAM range; - - - - InitCommonControls(); - - // progressload. - - // progressload. = ICC_PROGRESS_CLASS - - // InitCommonControlsEx(&progressload); - - - - progressboxwindow = CreateDialog(progmodule, - - MAKEINTRESOURCE(DLG_0500), - - mainboxwindow, - - (DLGPROC) ProgressBoxCallback); - - - - progressboxbar = GetDlgItem(progressboxwindow, IDC_0502); - - range = MAKELPARAM(0, 30000); // Widen the range for granularity - - SendMessage(progressboxbar, PBM_SETRANGE, 0, range); - - - - ShowWindow(progressboxwindow, SW_SHOWNORMAL); - - ShowWindow(progressboxwindow, SW_HIDE); - - return; - + progressboxwindow = CreateDialog(progmodule, + MAKEINTRESOURCE(DLG_0500), + mainboxwindow, + (DLGPROC) ProgressBoxCallback); + progressboxbar = GetDlgItem(progressboxwindow, IDC_0502); + range = MAKELPARAM(0, 30000); // Widen the range for granularity + SendMessage(progressboxbar, PBM_SETRANGE, 0, range); + ShowWindow(progressboxwindow, SW_SHOWNORMAL); + ShowWindow(progressboxwindow, SW_HIDE); + return; } // END ProgressBoxDisplay() - diff --git a/plugins/CDVDisoEFP/src/Win32/progressbox.h b/plugins/CDVDisoEFP/src/Win32/progressbox.h index c8a2925f3a..eb6dd3a1e6 100644 --- a/plugins/CDVDisoEFP/src/Win32/progressbox.h +++ b/plugins/CDVDisoEFP/src/Win32/progressbox.h @@ -1,76 +1,38 @@ /* progressbox.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef PROGRESSBOX_H - #define PROGRESSBOX_H - - - - #include - - #include // off64_t #include "PS2Etypes.h" - - - - extern const char *compressnames[]; - - extern HWND progressboxwindow; extern int progressboxstop; - - - extern void ProgressBoxStart(char *description, off64_t maximum); extern void ProgressBoxTick(off64_t current); @@ -82,8 +44,5 @@ extern void ProgressBoxDestroy(); extern void ProgressBoxDisplay(); - - - #endif /* MAINBOX_H */ diff --git a/plugins/CDVDisoEFP/src/Win32/screens.h b/plugins/CDVDisoEFP/src/Win32/screens.h index 0c909a77ac..ab42878181 100644 --- a/plugins/CDVDisoEFP/src/Win32/screens.h +++ b/plugins/CDVDisoEFP/src/Win32/screens.h @@ -1,74 +1,37 @@ /* Weditres generated include file. Do NOT edit */ - #include - #define DLG_0100 100 - #define IDC_0104 104 - #define DLG_0200 200 - #define IDC_0202 202 - #define IDC_0203 203 - #define IDC_0204 204 - #define IDC_0205 205 - #define IDC_0206 206 - #define IDC_0207 207 - #define IDC_0208 208 - #define IDC_0209 209 - #define IDC_0210 210 - #define DLG_0300 300 - #define IDC_0302 302 - #define IDC_0303 303 - #define IDC_0305 305 - #define IDC_0306 306 - #define IDC_0307 307 - #define IDC_0309 309 - #define IDC_0311 311 - #define IDC_0312 312 - #define IDC_0313 313 - #define DLG_0400 400 - #define IDC_0402 402 - #define IDC_0403 403 - #define IDC_0404 404 - #define IDC_0406 406 - #define IDC_0408 408 - #define IDC_0409 409 - #define IDC_0410 410 - #define DLG_0500 500 - #define IDC_0501 501 - #define IDC_0502 502 - #define IDC_0503 503 - #define IDC_0504 504 - diff --git a/plugins/CDVDisoEFP/src/Win32/tablerebuild.c b/plugins/CDVDisoEFP/src/Win32/tablerebuild.c index c0b60df868..310cebde91 100644 --- a/plugins/CDVDisoEFP/src/Win32/tablerebuild.c +++ b/plugins/CDVDisoEFP/src/Win32/tablerebuild.c @@ -1,374 +1,199 @@ -/* tablerebuild.c - - * Copyright (C) 2002-2005 PCSX2 Team - - * - - * This program is free software; you can redistribute it and/or modify - - * it under the terms of the GNU General Public License as published by - - * the Free Software Foundation; either version 2 of the License, or - - * (at your option) any later version. - - * - - * This program is distributed in the hope that it will be useful, - - * but WITHOUT ANY WARRANTY; without even the implied warranty of - - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - - * GNU General Public License for more details. - - * - - * You should have received a copy of the GNU General Public License - - * along with this program; if not, write to the Free Software - - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - * - - * PCSX2 members can be contacted through their website at www.pcsx2.net. - - */ - - - - - -#include // NULL - -#include // sprintf() - -#include // malloc() - - - -#include "mainbox.h" - -#include "progressbox.h" - -#include "isofile.h" - -#include "multifile.h" - -#include "isocompress.h" // CompressClose() - -#include "gzipv1.h" - -#include "gzipv2.h" - -#include "bzip2v2.h" - -#include "bzip2v3.h" - -#include "actualfile.h" // ACTUALHANDLENULL - - - - - -void IsoTableRebuild(const char *filename) { - - struct IsoFile *datafile; - - struct IsoFile *tablefile; - - int retval; - - char tempblock[65536]; - - int stop; - - - - struct TableData table; - - - - datafile = IsoFileOpenForRead(filename); - - - - // Note: This is the start of the "Multifile" process. It's commented - - // out so at least we can rebuild 1 part of a multifile at a time. - - // IsoNameStripExt(datafile); - - // IsoNameStripMulti(datafile); - - - - // Prep tablefile to hold ONLY a table (no data) - - tablefile = (struct IsoFile *) malloc(sizeof(struct IsoFile)); - - if(tablefile == NULL) { - - datafile = IsoFileClose(datafile); - - return; - - } // ENDIF- Failed to allocate? Abort. - - - - tablefile->sectorpos = 0; - - tablefile->openforread = 0; - - tablefile->filebytepos = 0; - - tablefile->filebytesize = 0; - - tablefile->filesectorpos = 0; - - tablefile->filesectorsize = 0; - - tablefile->handle = ACTUALHANDLENULL; - - - - tablefile->namepos = 0; - - while((tablefile->namepos < 255) && - - (*(filename + tablefile->namepos) != 0)) { - - tablefile->name[tablefile->namepos] = *(filename + tablefile->namepos); - - tablefile->namepos++; - - } // ENDWHILE- Copying file name into tablefile - - tablefile->name[tablefile->namepos] = 0; // And 0-terminate. - - - - tablefile->imageheader = datafile->imageheader; - - tablefile->blocksize = datafile->blocksize; - - tablefile->blockoffset = datafile->blockoffset; - - tablefile->cdvdtype = 0; // Not important right now. - - - - tablefile->compress = datafile->compress; - - tablefile->compresspos = datafile->compresspos; - - tablefile->numsectors = datafile->numsectors; - - tablefile->tabledata = NULL; - - - - switch(tablefile->compress) { - - case 1: - - retval = GZipV1OpenTableForWrite(tablefile); - - break; - - case 2: - - retval = -1; - - break; - - case 3: - - retval = GZipV2OpenTableForWrite(tablefile); - - break; - - case 4: - - retval = BZip2V2OpenTableForWrite(tablefile); - - break; - - case 5: - - retval = BZip2V3OpenTableForWrite(tablefile); - - break; - - default: - - retval = -1; - - break; - - } // ENDSWITCH compress- Which table are we writing out? - - if(retval < 0) { - - datafile = IsoFileClose(datafile); - - return; - - } // ENDIF- Failed to open table file? Abort - - - - sprintf(tempblock, "Rebuilding table for %s", datafile->name); - - ProgressBoxStart(tempblock, datafile->filebytesize); - - - - stop = 0; - - mainboxstop = 0; - - progressboxstop = 0; - - while((stop == 0) && (datafile->filebytepos < datafile->filebytesize)) { - - switch(datafile->compress) { - - case 1: - - retval = GZipV1Read(datafile, 0, tempblock); - - break; - - case 2: - - retval = -1; - - break; - - case 3: - - retval = GZipV2Read(datafile, 0, tempblock); - - break; - - case 4: - - retval = BZip2V2Read(datafile, 0, tempblock); - - break; - - case 5: - - retval = BZip2V3Read(datafile, 0, tempblock); - - break; - - default: - - retval = -1; - - break; - - } // ENDSWITCH compress- Scanning for the next complete compressed block - - - - if(retval <= 0) { - -#ifdef FUNCTION_WARNING_TABLEREBUILD - - PrintLog("CDVDiso rebuild: failed to decompress - data corrupt"); - -#endif /* FUNCTION_WARNING_TABLEREBUILD */ - - stop = 1; - - } else { - - table.offset = datafile->filebytepos - retval; - - table.size = retval; - - switch(tablefile->compress) { - - case 1: - - retval = GZipV1WriteTable(tablefile, table); - - break; - - case 2: - - retval = -1; - - break; - - case 3: - - retval = GZipV2WriteTable(tablefile, table); - - break; - - case 4: - - retval = BZip2V2WriteTable(tablefile, table); - - break; - - case 5: - - retval = BZip2V3WriteTable(tablefile, table); - - break; - - default: - - retval = -1; - - break; - - } // ENDSWITCH compress- Writing out the relavent table facts - - if(retval < 0) stop = 1; - - } // ENDIF- Do we have a valid record to write an entry for? - - - - ProgressBoxTick(datafile->filebytepos); - - - - if(mainboxstop != 0) stop = 2; - - if(progressboxstop != 0) stop = 2; - - } // ENDWHILE- Read in the data file and writing a table, 1 block at a time - - - - ProgressBoxStop(); - - - - CompressClose(tablefile); // Guarentee the table is flushed and closed. - - if(stop != 0) { - - ActualFileDelete(tablefile->tablename); - - } // ENDIF- Aborted or trouble? Delete the table file - - tablefile = IsoFileClose(tablefile); - - datafile = IsoFileClose(datafile); - - - - return; - -} // END IsoTableRebuild() - +/* tablerebuild.c + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +#include // NULL +#include // sprintf() +#include // malloc() + +#include "mainbox.h" +#include "progressbox.h" +#include "isofile.h" +#include "multifile.h" +#include "isocompress.h" // CompressClose() +#include "gzipv1.h" +#include "gzipv2.h" +#include "bzip2v2.h" +#include "bzip2v3.h" +#include "actualfile.h" // ACTUALHANDLENULL + + +void IsoTableRebuild(const char *filename) +{ + struct IsoFile *datafile; + struct IsoFile *tablefile; + int retval; + char tempblock[65536]; + int stop; + + struct TableData table; + + datafile = IsoFileOpenForRead(filename); + + // Note: This is the start of the "Multifile" process. It's commented + // out so at least we can rebuild 1 part of a multifile at a time. + // IsoNameStripExt(datafile); + // IsoNameStripMulti(datafile); + + // Prep tablefile to hold ONLY a table (no data) + tablefile = (struct IsoFile *) malloc(sizeof(struct IsoFile)); + if (tablefile == NULL) + { + datafile = IsoFileClose(datafile); + return; + } // ENDIF- Failed to allocate? Abort. + + tablefile->sectorpos = 0; + tablefile->openforread = 0; + tablefile->filebytepos = 0; + tablefile->filebytesize = 0; + tablefile->filesectorpos = 0; + tablefile->filesectorsize = 0; + tablefile->handle = ACTUALHANDLENULL; + + tablefile->namepos = 0; + while ((tablefile->namepos < 255) && + (*(filename + tablefile->namepos) != 0)) + { + tablefile->name[tablefile->namepos] = *(filename + tablefile->namepos); + tablefile->namepos++; + } // ENDWHILE- Copying file name into tablefile + tablefile->name[tablefile->namepos] = 0; // And 0-terminate. + + tablefile->imageheader = datafile->imageheader; + tablefile->blocksize = datafile->blocksize; + tablefile->blockoffset = datafile->blockoffset; + tablefile->cdvdtype = 0; // Not important right now. + + tablefile->compress = datafile->compress; + tablefile->compresspos = datafile->compresspos; + tablefile->numsectors = datafile->numsectors; + tablefile->tabledata = NULL; + + switch (tablefile->compress) + { + case 1: + retval = GZipV1OpenTableForWrite(tablefile); + break; + case 2: + retval = -1; + break; + case 3: + retval = GZipV2OpenTableForWrite(tablefile); + break; + case 4: + retval = BZip2V2OpenTableForWrite(tablefile); + break; + case 5: + retval = BZip2V3OpenTableForWrite(tablefile); + break; + default: + retval = -1; + break; + } // ENDSWITCH compress- Which table are we writing out? + if (retval < 0) + { + datafile = IsoFileClose(datafile); + return; + } // ENDIF- Failed to open table file? Abort + + sprintf(tempblock, "Rebuilding table for %s", datafile->name); + ProgressBoxStart(tempblock, datafile->filebytesize); + + stop = 0; + mainboxstop = 0; + progressboxstop = 0; + while ((stop == 0) && (datafile->filebytepos < datafile->filebytesize)) + { + switch (datafile->compress) + { + case 1: + retval = GZipV1Read(datafile, 0, tempblock); + break; + case 2: + retval = -1; + break; + case 3: + retval = GZipV2Read(datafile, 0, tempblock); + break; + case 4: + retval = BZip2V2Read(datafile, 0, tempblock); + break; + case 5: + retval = BZip2V3Read(datafile, 0, tempblock); + break; + default: + retval = -1; + break; + } // ENDSWITCH compress- Scanning for the next complete compressed block + + if (retval <= 0) + { +#ifdef FUNCTION_WARNING_TABLEREBUILD + PrintLog("CDVDiso rebuild: failed to decompress - data corrupt"); +#endif /* FUNCTION_WARNING_TABLEREBUILD */ + stop = 1; + } + else + { + table.offset = datafile->filebytepos - retval; + table.size = retval; + switch (tablefile->compress) + { + case 1: + retval = GZipV1WriteTable(tablefile, table); + break; + case 2: + retval = -1; + break; + case 3: + retval = GZipV2WriteTable(tablefile, table); + break; + case 4: + retval = BZip2V2WriteTable(tablefile, table); + break; + case 5: + retval = BZip2V3WriteTable(tablefile, table); + break; + default: + retval = -1; + break; + } // ENDSWITCH compress- Writing out the relavent table facts + if (retval < 0) stop = 1; + } // ENDIF- Do we have a valid record to write an entry for? + + ProgressBoxTick(datafile->filebytepos); + + if (mainboxstop != 0) stop = 2; + if (progressboxstop != 0) stop = 2; + } // ENDWHILE- Read in the data file and writing a table, 1 block at a time + + ProgressBoxStop(); + + CompressClose(tablefile); // Guarentee the table is flushed and closed. + if (stop != 0) + { + ActualFileDelete(tablefile->tablename); + } // ENDIF- Aborted or trouble? Delete the table file + tablefile = IsoFileClose(tablefile); + datafile = IsoFileClose(datafile); + + return; +} // END IsoTableRebuild() diff --git a/plugins/CDVDisoEFP/src/Win32/tablerebuild.h b/plugins/CDVDisoEFP/src/Win32/tablerebuild.h index bac5ff9578..8baaedd2e6 100644 --- a/plugins/CDVDisoEFP/src/Win32/tablerebuild.h +++ b/plugins/CDVDisoEFP/src/Win32/tablerebuild.h @@ -1,64 +1,28 @@ /* tablerebuild.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef TABLEREBUILD_H - #define TABLEREBUILD_H - - - - // #define FUNCTION_WARNING_TABLEREBUILD - - - - extern void IsoTableRebuild(const char *filename); - - - - #endif /* TABLEREBUILD_H */ - diff --git a/plugins/CDVDisoEFP/src/blockv2.c b/plugins/CDVDisoEFP/src/blockv2.c index 58fa5e28c0..e889110dfe 100644 --- a/plugins/CDVDisoEFP/src/blockv2.c +++ b/plugins/CDVDisoEFP/src/blockv2.c @@ -1,612 +1,308 @@ /* blockv2.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include // NULL - #include // malloc() - #include // off64_t - - #include "zlib/zlib.h" - - #include "convert.h" - #include "logfile.h" - #include "isofile.h" // IsoFile - #include "isocompress.h" // TableData, TableMap - #include "actualfile.h" - #include "blockv2.h" - - - - #ifdef _WIN32 - #pragma pack(1) - #endif /* _WIN32 */ - - -struct BlockV2Header { - - char id[4]; - - unsigned int blocksize; - - unsigned int numblocks; - - unsigned int blockoffset; - +struct BlockV2Header +{ + char id[4]; + unsigned int blocksize; + unsigned int numblocks; + unsigned int blockoffset; #ifdef _WIN32 - }; - #else - -} __attribute__ ((packed)); - +} __attribute__((packed)); #endif /* _WIN32 */ - - - #ifdef _WIN32 - #pragma pack() - #endif /* _WIN32 */ - - - - -int BlockV2OpenTableForRead(struct IsoFile *isofile) { - - int i; - - int j; - - off64_t offset; - - int tableoffset; - - int retval; - - union TableMap tablemap; - - +int BlockV2OpenTableForRead(struct IsoFile *isofile) +{ + int i; + int j; + off64_t offset; + int tableoffset; + int retval; + union TableMap tablemap; #ifdef VERBOSE_FUNCTION_BLOCKV2 - - PrintLog("CDVDiso BlockV2: OpenTableForRead()"); - + PrintLog("CDVDiso BlockV2: OpenTableForRead()"); #endif /* VERBOSE_FUNCTION_BLOCKV2 */ - - - // We pre-read the WHOLE offset table. - - isofile->tabledata = (char *) malloc(isofile->filesectorsize * sizeof(struct TableData)); - - if(isofile->tabledata == NULL) { - + // We pre-read the WHOLE offset table. + isofile->tabledata = (char *) malloc(isofile->filesectorsize * sizeof(struct TableData)); + if (isofile->tabledata == NULL) + { #ifdef VERBOSE_WARNING_BLOCKV2 - - PrintLog("CDVDiso BlockV2: Couldn't allocate internal table!"); - + PrintLog("CDVDiso BlockV2: Couldn't allocate internal table!"); #endif /* VERBOSE_WARNING_BLOCKV2 */ - - return(-1); - - } // ENDIF- Could not get enough memory to hold table data - - - - offset = sizeof(struct BlockV2Header); - - tableoffset = 0; - - for(i = 0; i < isofile->filesectorsize; i++) { - - retval = BlockV2Seek(isofile, offset); - - if(retval != 0) { - + return(-1); + } // ENDIF- Could not get enough memory to hold table data + offset = sizeof(struct BlockV2Header); + tableoffset = 0; + for (i = 0; i < isofile->filesectorsize; i++) + { + retval = BlockV2Seek(isofile, offset); + if (retval != 0) + { #ifdef VERBOSE_WARNING_BLOCKV2 - - PrintLog("CDVDiso BlockV2: Failed to find sector %i!", i); - + PrintLog("CDVDiso BlockV2: Failed to find sector %i!", i); #endif /* VERBOSE_WARNING_BLOCKV2 */ + return(-1); + } // ENDIF- Trouble finding a lsn id? Fail. - return(-1); - - } // ENDIF- Trouble finding a lsn id? Fail. - - - - retval = ActualFileRead(isofile->handle, - - sizeof(int), - - (char *) &j); - - if(retval != sizeof(int)) { - + retval = ActualFileRead(isofile->handle, + sizeof(int), + (char *) & j); + if (retval != sizeof(int)) + { #ifdef VERBOSE_WARNING_BLOCKV2 - - PrintLog("CDVDiso BlockV2: Failed to read in sector %i!", i); - + PrintLog("CDVDiso BlockV2: Failed to read in sector %i!", i); #endif /* VERBOSE_WARNING_BLOCKV2 */ + return(-1); + } // ENDIF- Trouble reading in a lsn id? Table damaged... fail. - return(-1); - - } // ENDIF- Trouble reading in a lsn id? Table damaged... fail. - - - - tablemap.table.offset = ConvertEndianUInt(j); // Actually, a lsn. - - for(j = 0; j < sizeof(struct TableData); j++) - - *(isofile->tabledata + tableoffset + j) = tablemap.ch[j]; - - offset += isofile->blocksize + 4; - - tableoffset += sizeof(struct TableData); - - } // NEXT i- reading in the sizes, and making offset as I go. - - - - isofile->tablehandle = ACTUALHANDLENULL; - - - - return(0); - + tablemap.table.offset = ConvertEndianUInt(j); // Actually, a lsn. + for (j = 0; j < sizeof(struct TableData); j++) + *(isofile->tabledata + tableoffset + j) = tablemap.ch[j]; + offset += isofile->blocksize + 4; + tableoffset += sizeof(struct TableData); + } // NEXT i- reading in the sizes, and making offset as I go. + isofile->tablehandle = ACTUALHANDLENULL; + return(0); } // END BlockV2OpenTableForRead() - - - - -int BlockV2SeekTable(struct IsoFile *isofile, off64_t sector) { - - int i; - - int tableoffset; - - union TableMap tablemap; - - off64_t filesectorstart; - - - +int BlockV2SeekTable(struct IsoFile *isofile, off64_t sector) +{ + int i; + int tableoffset; + union TableMap tablemap; + off64_t filesectorstart; #ifdef VERBOSE_FUNCTION_BLOCKV2 - - PrintLog("CDVDiso BlockV2: SeekTable(%lli)", sector); - + PrintLog("CDVDiso BlockV2: SeekTable(%lli)", sector); #endif /* VERBOSE_FUNCTION_BLOCKV2 */ + if ((isofile->filesectorpos >= 0) && + (isofile->filesectorpos < isofile->filesectorsize)) + { + tableoffset = isofile->filesectorpos * sizeof(struct TableData); + for (i = 0; i < sizeof(struct TableData); i++) + tablemap.ch[i] = *(isofile->tabledata + tableoffset + i); + if (sector == tablemap.table.offset) + { + return(0); + } // ENDIF- Are we already pointing at the right sector? + } + else + { + isofile->filesectorpos = 0; + tablemap.table.offset = -1; + } // ENDIF- Is the file sector pointer within table limits? + filesectorstart = isofile->filesectorpos; + isofile->filesectorpos++; + if (isofile->filesectorpos >= isofile->filesectorsize) + isofile->filesectorpos = 0; + while ((isofile->filesectorpos != filesectorstart) && + (tablemap.table.offset != sector)) + { + tableoffset = isofile->filesectorpos * sizeof(struct TableData); + for (i = 0; i < sizeof(struct TableData); i++) + tablemap.ch[i] = *(isofile->tabledata + tableoffset + i); + if (tablemap.table.offset != sector) + { + isofile->filesectorpos++; + if (isofile->filesectorpos >= isofile->filesectorsize) + isofile->filesectorpos = 0; + } // ENDIF- Still didn't find it? move to next sector. + } // ENDWHILE- Scanning through whole sector list (starting at current pos) + if (isofile->filesectorpos == filesectorstart) + { + return(-1); + } // ENDIF- Did we loop through the whole file... and not find this sector? - if((isofile->filesectorpos >= 0) && - - (isofile->filesectorpos < isofile->filesectorsize)) { - - tableoffset = isofile->filesectorpos * sizeof(struct TableData); - - for(i = 0; i < sizeof(struct TableData); i++) - - tablemap.ch[i] = *(isofile->tabledata + tableoffset + i); - - if(sector == tablemap.table.offset) { - - return(0); - - } // ENDIF- Are we already pointing at the right sector? - - - - } else { - - isofile->filesectorpos = 0; - - tablemap.table.offset = -1; - - } // ENDIF- Is the file sector pointer within table limits? - - - - filesectorstart = isofile->filesectorpos; - - isofile->filesectorpos++; - - if(isofile->filesectorpos >= isofile->filesectorsize) - - isofile->filesectorpos = 0; - - while((isofile->filesectorpos != filesectorstart) && - - (tablemap.table.offset != sector)) { - - tableoffset = isofile->filesectorpos * sizeof(struct TableData); - - for(i = 0; i < sizeof(struct TableData); i++) - - tablemap.ch[i] = *(isofile->tabledata + tableoffset + i); - - - - if(tablemap.table.offset != sector) { - - isofile->filesectorpos++; - - if(isofile->filesectorpos >= isofile->filesectorsize) - - isofile->filesectorpos = 0; - - } // ENDIF- Still didn't find it? move to next sector. - - } // ENDWHILE- Scanning through whole sector list (starting at current pos) - - - - if(isofile->filesectorpos == filesectorstart) { - - return(-1); - - } // ENDIF- Did we loop through the whole file... and not find this sector? - - - - return(0); - + return(0); } // END BlockV2SeekTable() - - - - -int BlockV2ReadTable(struct IsoFile *isofile, struct TableData *table) { - +int BlockV2ReadTable(struct IsoFile *isofile, struct TableData *table) +{ #ifdef VERBOSE_FUNCTION_BLOCKV2 - - PrintLog("CDVDiso BlockV2: ReadTable()"); - + PrintLog("CDVDiso BlockV2: ReadTable()"); #endif /* VERBOSE_FUNCTION_BLOCKV2 */ - - - - table->offset = sizeof(int) + isofile->blocksize; - - table->offset *= isofile->filesectorpos; - - table->offset += sizeof(struct BlockV2Header) + 4; - - table->size = isofile->blocksize; - - isofile->filesectorpos++; - - return(0); - + table->offset = sizeof(int) + isofile->blocksize; + table->offset *= isofile->filesectorpos; + table->offset += sizeof(struct BlockV2Header) + 4; + table->size = isofile->blocksize; + isofile->filesectorpos++; + return(0); } // END BlockV2ReadTable() - - - - -int BlockV2OpenTableForWrite(struct IsoFile *isofile) { - - return(-1); - +int BlockV2OpenTableForWrite(struct IsoFile *isofile) +{ + return(-1); } // END BlockV2OpenTableForWrite() - - - - -int BlockV2WriteTable(struct IsoFile *isofile, struct TableData table) { - - return(-1); - +int BlockV2WriteTable(struct IsoFile *isofile, struct TableData table) +{ + return(-1); } // END BlockV2WriteTable() - - - - -int BlockV2OpenForRead(struct IsoFile *isofile) { - - int retval; - - struct BlockV2Header header; - - +int BlockV2OpenForRead(struct IsoFile *isofile) +{ + int retval; + struct BlockV2Header header; #ifdef VERBOSE_FUNCTION_BLOCKV2 - - PrintLog("CDVDiso BlockV2: OpenForRead()"); - + PrintLog("CDVDiso BlockV2: OpenForRead()"); #endif /* VERBOSE_FUNCTION_BLOCKV2 */ + isofile->handle = ActualFileOpenForRead(isofile->name); + if (isofile->handle == ACTUALHANDLENULL) + { + return(-1); + } // ENDIF- Couldn't open data file? Fail. + isofile->filebytesize = ActualFileSize(isofile->handle); + isofile->filebytepos = 0; - - isofile->handle = ActualFileOpenForRead(isofile->name); - - if(isofile->handle == ACTUALHANDLENULL) { - - return(-1); - - } // ENDIF- Couldn't open data file? Fail. - - - - isofile->filebytesize = ActualFileSize(isofile->handle); - - isofile->filebytepos = 0; - - - - isofile->imageheader = 0; - - isofile->numsectors = 1; // Sectors per block - - - - retval = ActualFileRead(isofile->handle, - - sizeof(struct BlockV2Header), - - (char *) &header); - - if(retval != sizeof(struct BlockV2Header)) { - + isofile->imageheader = 0; + isofile->numsectors = 1; // Sectors per block + retval = ActualFileRead(isofile->handle, + sizeof(struct BlockV2Header), + (char *) & header); + if (retval != sizeof(struct BlockV2Header)) + { #ifdef VERBOSE_WARNING_BLOCKV2 - - PrintLog("CDVDiso BlockV2: Couldn't read header!"); - + PrintLog("CDVDiso BlockV2: Couldn't read header!"); #endif /* VERBOSE_WARNING_BLOCKV2 */ + ActualFileClose(isofile->handle); + isofile->handle = ACTUALHANDLENULL; + return(-1); + } // ENDIF Could not read the first sector? Fail. + isofile->filebytepos += retval; - ActualFileClose(isofile->handle); - - isofile->handle = ACTUALHANDLENULL; - - return(-1); - - } // ENDIF Could not read the first sector? Fail. - - isofile->filebytepos += retval; - - - - if((header.id[0] != 'B') || - - (header.id[1] != 'D') || - - (header.id[2] != 'V') || - - (header.id[3] != '2')) { - + if ((header.id[0] != 'B') || + (header.id[1] != 'D') || + (header.id[2] != 'V') || + (header.id[3] != '2')) + { #ifdef VERBOSE_WARNING_BLOCKV2 - - PrintLog("CDVDiso BlockV2: Not a block dump v2 header!"); - + PrintLog("CDVDiso BlockV2: Not a block dump v2 header!"); #endif /* VERBOSE_WARNING_BLOCKV2 */ + ActualFileClose(isofile->handle); + isofile->handle = ACTUALHANDLENULL; + return(-1); + } // ENDIF- ID for this compression type doesn't match? - ActualFileClose(isofile->handle); - - isofile->handle = ACTUALHANDLENULL; - - return(-1); - - } // ENDIF- ID for this compression type doesn't match? - - - - isofile->blocksize = ConvertEndianUInt(header.blocksize); - - // isofile->filesectorsize = ConvertEndianUInt(header.numblocks); - - isofile->blockoffset = ConvertEndianUInt(header.blockoffset); - - isofile->filesectorsize = isofile->filebytesize; - - isofile->filesectorsize -= 16; - - isofile->filesectorsize /= (isofile->blocksize + sizeof(int)); - - isofile->filesectorpos = 0; - - return(0); - + isofile->blocksize = ConvertEndianUInt(header.blocksize); + // isofile->filesectorsize = ConvertEndianUInt(header.numblocks); + isofile->blockoffset = ConvertEndianUInt(header.blockoffset); + isofile->filesectorsize = isofile->filebytesize; + isofile->filesectorsize -= 16; + isofile->filesectorsize /= (isofile->blocksize + sizeof(int)); + isofile->filesectorpos = 0; + return(0); } // END BlockV2OpenForRead() - - - - -int BlockV2Seek(struct IsoFile *isofile, off64_t position) { - - int retval; - - +int BlockV2Seek(struct IsoFile *isofile, off64_t position) +{ + int retval; #ifdef VERBOSE_FUNCTION_BLOCKV2 - - PrintLog("CDVDiso BlockV2: Seek(%lli)", position); - + PrintLog("CDVDiso BlockV2: Seek(%lli)", position); #endif /* VERBOSE_FUNCTION_BLOCKV2 */ - - - retval = ActualFileSeek(isofile->handle, position); - - if(retval < 0) { - + retval = ActualFileSeek(isofile->handle, position); + if (retval < 0) + { #ifdef VERBOSE_WARNING_BLOCKV2 - - PrintLog("CDVDiso BlockV2: Couldn't find the start of the block!"); - + PrintLog("CDVDiso BlockV2: Couldn't find the start of the block!"); #endif /* VERBOSE_WARNING_BLOCKV2 */ + return(-1); + } // ENDIF- Couldn't find the data entry? Fail. + isofile->filebytepos = position; + return(0); - return(-1); - - } // ENDIF- Couldn't find the data entry? Fail. - - isofile->filebytepos = position; - - return(0); - - - - return(-1); // Fail. (Due to lack of ambition?) - + return(-1); // Fail. (Due to lack of ambition?) } // END BlockV2Seek() - - - - -int BlockV2Read(struct IsoFile *isofile, int bytes, char *buffer) { - - int retval; - - - +int BlockV2Read(struct IsoFile *isofile, int bytes, char *buffer) +{ + int retval; #ifdef VERBOSE_FUNCTION_BLOCKV2 - - PrintLog("CDVDiso BlockV2: Read(%i)", bytes); - + PrintLog("CDVDiso BlockV2: Read(%i)", bytes); #endif /* VERBOSE_FUNCTION_BLOCKV2 */ - - - - retval = ActualFileRead(isofile->handle, isofile->blocksize, buffer); - - if(retval > 0) isofile->filebytepos += retval; - - if(retval != isofile->blocksize) { - + retval = ActualFileRead(isofile->handle, isofile->blocksize, buffer); + if (retval > 0) isofile->filebytepos += retval; + if (retval != isofile->blocksize) + { #ifdef VERBOSE_WARNING_BLOCKV2 - - PrintLog("CDVDiso BlockV2: Cannot read bytes! Returned: (%i)", retval); - + PrintLog("CDVDiso BlockV2: Cannot read bytes! Returned: (%i)", retval); #endif /* VERBOSE_WARNING_BLOCKV2 */ + return(-1); + } // ENDIF- Trouble reading compressed sector? Abort. - return(-1); - - } // ENDIF- Trouble reading compressed sector? Abort. - - - - return(isofile->blocksize); - + return(isofile->blocksize); } // END BlockV2Read() - - - - -int BlockV2OpenForWrite(struct IsoFile *isofile) { - - return(-1); - +int BlockV2OpenForWrite(struct IsoFile *isofile) +{ + return(-1); } // END BlockV2OpenForWrite() - - - - -int BlockV2Write(struct IsoFile *isofile, char *buffer) { - - return(-1); - +int BlockV2Write(struct IsoFile *isofile, char *buffer) +{ + return(-1); } // END BlockV2Write() - - - - -void BlockV2Close(struct IsoFile *isofile) { - +void BlockV2Close(struct IsoFile *isofile) +{ #ifdef VERBOSE_FUNCTION_BLOCKV2 - - PrintLog("CDVDiso BlockV2: Close()"); - + PrintLog("CDVDiso BlockV2: Close()"); #endif /* VERBOSE_FUNCTION_BLOCKV2 */ + if (isofile->handle != ACTUALHANDLENULL) + { + ActualFileClose(isofile->handle); + isofile->handle = ACTUALHANDLENULL; + } // ENDIF- Is there a data file open? Close it. - - - if(isofile->handle != ACTUALHANDLENULL) { - - ActualFileClose(isofile->handle); - - isofile->handle = ACTUALHANDLENULL; - - } // ENDIF- Is there a data file open? Close it. - - - - if(isofile->tabledata != NULL) { - - free(isofile->tabledata); - - isofile->tabledata = NULL; - - } // ENDIF- Do we have a read-in table to clear out? - - - - return; - + if (isofile->tabledata != NULL) + { + free(isofile->tabledata); + isofile->tabledata = NULL; + } // ENDIF- Do we have a read-in table to clear out? + return; } // END BlockV2Close() - diff --git a/plugins/CDVDisoEFP/src/blockv2.h b/plugins/CDVDisoEFP/src/blockv2.h index 8ef1740d70..c9dff05db6 100644 --- a/plugins/CDVDisoEFP/src/blockv2.h +++ b/plugins/CDVDisoEFP/src/blockv2.h @@ -1,104 +1,46 @@ /* blockv2.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef BLOCKV2_H - #define BLOCKV2_H - - - - #include - - #include "isofile.h" - #include "isocompress.h" - - - - // #define VERBOSE_FUNCTION_BLOCKV2 - // #define VERBOSE_WARNING_BLOCKV2 - - - - extern int BlockV2OpenTableForRead(struct IsoFile *isofile); - extern int BlockV2SeekTable(struct IsoFile *isofile, off64_t sector); - extern int BlockV2ReadTable(struct IsoFile *isofile, struct TableData *table); - - extern int BlockV2OpenTableForWrite(struct IsoFile *isofile); - extern int BlockV2WriteTable(struct IsoFile *isofile, struct TableData table); - - - extern int BlockV2OpenForRead(struct IsoFile *isofile); - extern int BlockV2Seek(struct IsoFile *isofile, off64_t sector); - extern int BlockV2Read(struct IsoFile *isofile, int bytes, char *buffer); - extern void BlockV2Close(struct IsoFile *isofile); - - extern int BlockV2OpenForWrite(struct IsoFile *isofile); - extern int BlockV2Write(struct IsoFile *isofile, char *buffer); - - - - #endif /* BLOCKV2_H */ - diff --git a/plugins/CDVDisoEFP/src/bzip2v2.c b/plugins/CDVDisoEFP/src/bzip2v2.c index 5c7ef0baad..59a18638d4 100644 --- a/plugins/CDVDisoEFP/src/bzip2v2.c +++ b/plugins/CDVDisoEFP/src/bzip2v2.c @@ -1,1052 +1,538 @@ /* bzip2v2.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include // NULL - #include // malloc() - #include // off64_t - - #include "bzip2/bzlib.h" - - #include "convert.h" - #include "logfile.h" - #include "isofile.h" // IsoFile - #include "isocompress.h" // TableData, TableMap - #include "actualfile.h" - // #include "convert.h" - #include "bzip2v2.h" - - - - #ifdef _WIN32 - #pragma pack(1) - #endif /* _WIN32 */ - - - -struct BZip2V2Header { - - char id[4]; - - unsigned int blocksize; - - unsigned int numblocks; - - unsigned int blockoffset; - +struct BZip2V2Header +{ + char id[4]; + unsigned int blocksize; + unsigned int numblocks; + unsigned int blockoffset; #ifdef _WIN32 - }; - #else - -} __attribute__ ((packed)); - +} __attribute__((packed)); #endif /* _WIN32 */ - - -struct BZip2V2Table { - - unsigned int size; - +struct BZip2V2Table +{ + unsigned int size; #ifdef _WIN32 - }; - #else - -} __attribute__ ((packed)); - +} __attribute__((packed)); #endif /* _WIN32 */ - - #ifdef _WIN32 - #pragma pack() - #endif /* _WIN32 */ - - - - -int BZip2V2OpenTableForRead(struct IsoFile *isofile) { - - int i; - - int j; - - char tableext[] = ".table\0"; - - off64_t numentries; - - off64_t offset; - - off64_t actual; - - int tableoffset; - - struct BZip2V2Table table; - - int retval; - - union TableMap tablemap; - - - +int BZip2V2OpenTableForRead(struct IsoFile *isofile) +{ + int i; + int j; + char tableext[] = ".table\0"; + off64_t numentries; + off64_t offset; + off64_t actual; + int tableoffset; + struct BZip2V2Table table; + int retval; + union TableMap tablemap; #ifdef VERBOSE_FUNCTION_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: OpenTableForRead()"); - + PrintLog("CDVDiso BZip2V2: OpenTableForRead()"); #endif /* VERBOSE_FUNCTION_BZIP2V2 */ + i = 0; + while ((i < 256) && (isofile->name[i] != 0)) + { + isofile->tablename[i] = isofile->name[i]; + i++; + } // ENDWHILE- Copying the data name to the table name + j = 0; + while ((i < 256) && (tableext[j] != 0)) + { + isofile->tablename[i] = tableext[j]; + i++; + j++; + } // ENDWHILE- Adding the ".table" extension. + isofile->tablename[i] = 0; // And 0-terminate. - - - i = 0; - - while((i < 256) && (isofile->name[i] != 0)) { - - isofile->tablename[i] = isofile->name[i]; - - i++; - - } // ENDWHILE- Copying the data name to the table name - - j = 0; - - while((i < 256) && (tableext[j] != 0)) { - - isofile->tablename[i] = tableext[j]; - - i++; - - j++; - - } // ENDWHILE- Adding the ".table" extension. - - isofile->tablename[i] = 0; // And 0-terminate. - - - - isofile->tablehandle = ActualFileOpenForRead(isofile->tablename); - - if(isofile->tablehandle == ACTUALHANDLENULL) { - + isofile->tablehandle = ActualFileOpenForRead(isofile->tablename); + if (isofile->tablehandle == ACTUALHANDLENULL) + { #ifdef VERBOSE_WARNING_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: Couldn't open table!"); - + PrintLog("CDVDiso BZip2V2: Couldn't open table!"); #endif /* VERBOSE_WARNING_BZIP2V2 */ + return(-2); + } // ENDIF- Couldn't open table file? Fail. - return(-2); - - } // ENDIF- Couldn't open table file? Fail. - - - - numentries = isofile->filesectorsize / 16; - - if((isofile->filesectorsize % 16) != 0) numentries++; - - offset = numentries * sizeof(struct BZip2V2Table); - - actual = ActualFileSize(isofile->tablehandle); - - if(offset != actual) { - + numentries = isofile->filesectorsize / 16; + if ((isofile->filesectorsize % 16) != 0) numentries++; + offset = numentries * sizeof(struct BZip2V2Table); + actual = ActualFileSize(isofile->tablehandle); + if (offset != actual) + { #ifdef VERBOSE_WARNING_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: Table not the correct size! (Should be %lli, is %lli)", - - offset, actual); - + PrintLog("CDVDiso BZip2V2: Table not the correct size! (Should be %lli, is %lli)", + offset, actual); #endif /* VERBOSE_WARNING_BZIP2V2 */ + return(-2); + } // ENDIF- Not the correct-sized table for the data file? Fail. - return(-2); - - } // ENDIF- Not the correct-sized table for the data file? Fail. - - - - // We pre-read the WHOLE offset table. - - isofile->tabledata = (char *) malloc(numentries * sizeof(struct TableData)); - - if(isofile->tabledata == NULL) { - + // We pre-read the WHOLE offset table. + isofile->tabledata = (char *) malloc(numentries * sizeof(struct TableData)); + if (isofile->tabledata == NULL) + { #ifdef VERBOSE_WARNING_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: Couldn't allocate internal table!"); - + PrintLog("CDVDiso BZip2V2: Couldn't allocate internal table!"); #endif /* VERBOSE_WARNING_BZIP2V2 */ - - return(-2); - - } // ENDIF- Could not get enough memory to hold table data - - - - offset = sizeof(struct BZip2V2Header); - - tableoffset = 0; - - for(i = 0; i < numentries; i++) { - - retval = ActualFileRead(isofile->tablehandle, - - sizeof(struct BZip2V2Table), - - (char *) &table); - - if(retval != sizeof(struct BZip2V2Table)) { - + return(-2); + } // ENDIF- Could not get enough memory to hold table data + offset = sizeof(struct BZip2V2Header); + tableoffset = 0; + for (i = 0; i < numentries; i++) + { + retval = ActualFileRead(isofile->tablehandle, + sizeof(struct BZip2V2Table), + (char *) & table); + if (retval != sizeof(struct BZip2V2Table)) + { #ifdef VERBOSE_WARNING_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: Failed to read in entry %i!", i); - + PrintLog("CDVDiso BZip2V2: Failed to read in entry %i!", i); #endif /* VERBOSE_WARNING_BZIP2V2 */ + return(-2); + } // ENDIF- Trouble reading in a size? Table damaged... fail. - return(-2); - - } // ENDIF- Trouble reading in a size? Table damaged... fail. - - - - tablemap.table.offset = offset; - - tablemap.table.size = ConvertEndianUInt(table.size); - - for(j = 0; j < sizeof(struct TableData); j++) - - *(isofile->tabledata + tableoffset + j) = tablemap.ch[j]; - - offset += tablemap.table.size; - - tableoffset += sizeof(struct TableData); - - } // NEXT i- reading in the sizes, and making offset as I go. - - - - ActualFileClose(isofile->tablehandle); - - isofile->tablehandle = ACTUALHANDLENULL; - - return(0); + tablemap.table.offset = offset; + tablemap.table.size = ConvertEndianUInt(table.size); + for (j = 0; j < sizeof(struct TableData); j++) + *(isofile->tabledata + tableoffset + j) = tablemap.ch[j]; + offset += tablemap.table.size; + tableoffset += sizeof(struct TableData); + } // NEXT i- reading in the sizes, and making offset as I go. + ActualFileClose(isofile->tablehandle); + isofile->tablehandle = ACTUALHANDLENULL; + return(0); } // END BZip2V2OpenTableForRead() - - - - -int BZip2V2SeekTable(struct IsoFile *isofile, off64_t sector) { - +int BZip2V2SeekTable(struct IsoFile *isofile, off64_t sector) +{ #ifdef VERBOSE_FUNCTION_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: SeekTable(%lli)", sector); - + PrintLog("CDVDiso BZip2V2: SeekTable(%lli)", sector); #endif /* VERBOSE_FUNCTION_BZIP2V2 */ - - - - isofile->filesectorpos = sector; - - isofile->compsector = isofile->filesectorsize + isofile->numsectors; - - return(0); - + isofile->filesectorpos = sector; + isofile->compsector = isofile->filesectorsize + isofile->numsectors; + return(0); } // END BZip2V2SeekTable() - - - - -int BZip2V2ReadTable(struct IsoFile *isofile, struct TableData *table) { - - off64_t target; - - union TableMap tablemap; - - off64_t i; - - +int BZip2V2ReadTable(struct IsoFile *isofile, struct TableData *table) +{ + off64_t target; + union TableMap tablemap; + off64_t i; #ifdef VERBOSE_FUNCTION_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: ReadTable()"); - + PrintLog("CDVDiso BZip2V2: ReadTable()"); #endif /* VERBOSE_FUNCTION_BZIP2V2 */ - - - target = (isofile->filesectorpos / isofile->numsectors) - - * sizeof(struct TableData); - - for(i = 0; i < sizeof(struct TableData); i++) - - tablemap.ch[i] = *(isofile->tabledata + target + i); - - - - table->offset = tablemap.table.offset; - - table->size = tablemap.table.size; - - return(0); - + target = (isofile->filesectorpos / isofile->numsectors) + * sizeof(struct TableData); + for (i = 0; i < sizeof(struct TableData); i++) + tablemap.ch[i] = *(isofile->tabledata + target + i); + table->offset = tablemap.table.offset; + table->size = tablemap.table.size; + return(0); } // END BZip2V2ReadTable() - - - - -int BZip2V2OpenTableForWrite(struct IsoFile *isofile) { - - int i; - - int j; - - char tableext[] = ".table\0"; - - +int BZip2V2OpenTableForWrite(struct IsoFile *isofile) +{ + int i; + int j; + char tableext[] = ".table\0"; #ifdef VERBOSE_FUNCTION_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: OpenTableForWrite()"); - + PrintLog("CDVDiso BZip2V2: OpenTableForWrite()"); #endif /* VERBOSE_FUNCTION_BZIP2V2 */ - - - i = 0; - - while((i < 256) && (isofile->name[i] != 0)) { - - isofile->tablename[i] = isofile->name[i]; - - i++; - - } // ENDWHILE- Copying the data name to the table name - - j = 0; - - while((i < 256) && (tableext[j] != 0)) { - - isofile->tablename[i] = tableext[j]; - - i++; - - j++; - - } // ENDWHILE- Adding the ".table" extension. - - isofile->tablename[i] = 0; // And 0-terminate. - - - - isofile->tablehandle = ActualFileOpenForWrite(isofile->tablename); - - if(isofile->tablehandle == ACTUALHANDLENULL) { - + i = 0; + while ((i < 256) && (isofile->name[i] != 0)) + { + isofile->tablename[i] = isofile->name[i]; + i++; + } // ENDWHILE- Copying the data name to the table name + j = 0; + while ((i < 256) && (tableext[j] != 0)) + { + isofile->tablename[i] = tableext[j]; + i++; + j++; + } // ENDWHILE- Adding the ".table" extension. + isofile->tablename[i] = 0; // And 0-terminate. + isofile->tablehandle = ActualFileOpenForWrite(isofile->tablename); + if (isofile->tablehandle == ACTUALHANDLENULL) + { #ifdef VERBOSE_WARNING_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: Couldn't open table!"); - + PrintLog("CDVDiso BZip2V2: Couldn't open table!"); #endif /* VERBOSE_WARNING_BZIP2V2 */ - - return(-2); - - } // ENDIF- Couldn't open table file? Fail. - - - - // isofile->filesectorsize = 0; - - return(0); - + return(-2); + } // ENDIF- Couldn't open table file? Fail. + // isofile->filesectorsize = 0; + return(0); } // END BZip2V2OpenTableForWrite() - - - - -int BZip2V2WriteTable(struct IsoFile *isofile, struct TableData table) { - - int retval; - - struct BZip2V2Table bv2table; - - unsigned int tempint; - - - +int BZip2V2WriteTable(struct IsoFile *isofile, struct TableData table) +{ + int retval; + struct BZip2V2Table bv2table; + unsigned int tempint; #ifdef VERBOSE_FUNCTION_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: WriteTable(%lli, %i)", table.offset, table.size); - + PrintLog("CDVDiso BZip2V2: WriteTable(%lli, %i)", table.offset, table.size); #endif /* VERBOSE_FUNCTION_BZIP2V2 */ - - - - tempint = table.size; - - bv2table.size = ConvertEndianUInt(tempint); - - retval = ActualFileWrite(isofile->tablehandle, - - sizeof(struct BZip2V2Table), - - (char *) &bv2table); - - if(retval != sizeof(struct BZip2V2Table)) { - + tempint = table.size; + bv2table.size = ConvertEndianUInt(tempint); + retval = ActualFileWrite(isofile->tablehandle, + sizeof(struct BZip2V2Table), + (char *) & bv2table); + if (retval != sizeof(struct BZip2V2Table)) + { #ifdef VERBOSE_WARNING_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: Couldn't write table entry!"); - + PrintLog("CDVDiso BZip2V2: Couldn't write table entry!"); #endif /* VERBOSE_WARNING_BZIP2V2 */ - - return(-2); - - } // ENDIF- Trouble reading table entry? Fail. - - - - return(0); - + return(-2); + } // ENDIF- Trouble reading table entry? Fail. + return(0); } // END BZip2V2WriteTable() - - - - -int BZip2V2OpenForRead(struct IsoFile *isofile) { - - int retval; - - struct BZip2V2Header header; - - - +int BZip2V2OpenForRead(struct IsoFile *isofile) +{ + int retval; + struct BZip2V2Header header; #ifdef VERBOSE_FUNCTION_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: OpenForRead()"); - + PrintLog("CDVDiso BZip2V2: OpenForRead()"); #endif /* VERBOSE_FUNCTION_BZIP2V2 */ + isofile->handle = ActualFileOpenForRead(isofile->name); + if (isofile->handle == ACTUALHANDLENULL) + { + return(-1); + } // ENDIF- Couldn't open data file? Fail. + isofile->filebytesize = ActualFileSize(isofile->handle); + isofile->filebytepos = 0; + isofile->filesectorpos = 0; - - isofile->handle = ActualFileOpenForRead(isofile->name); - - if(isofile->handle == ACTUALHANDLENULL) { - - return(-1); - - } // ENDIF- Couldn't open data file? Fail. - - - - isofile->filebytesize = ActualFileSize(isofile->handle); - - isofile->filebytepos = 0; - - isofile->filesectorpos = 0; - - - - isofile->imageheader = 0; - - isofile->numsectors = 16; // Sectors per block - - - - retval = ActualFileRead(isofile->handle, - - sizeof(struct BZip2V2Header), - - (char *) &header); - - if(retval != sizeof(struct BZip2V2Header)) { - + isofile->imageheader = 0; + isofile->numsectors = 16; // Sectors per block + retval = ActualFileRead(isofile->handle, + sizeof(struct BZip2V2Header), + (char *) & header); + if (retval != sizeof(struct BZip2V2Header)) + { #ifdef VERBOSE_WARNING_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: Couldn't read header!"); - + PrintLog("CDVDiso BZip2V2: Couldn't read header!"); #endif /* VERBOSE_WARNING_BZIP2V2 */ + ActualFileClose(isofile->handle); + isofile->handle = ACTUALHANDLENULL; + return(-1); + } // ENDIF Could not read the first sector? Fail. + isofile->filebytepos += retval; - ActualFileClose(isofile->handle); - - isofile->handle = ACTUALHANDLENULL; - - return(-1); - - } // ENDIF Could not read the first sector? Fail. - - isofile->filebytepos += retval; - - - - if((header.id[0] != 'B') || - - (header.id[1] != 'Z') || - - (header.id[2] != 'V') || - - (header.id[3] != '2')) { - + if ((header.id[0] != 'B') || + (header.id[1] != 'Z') || + (header.id[2] != 'V') || + (header.id[3] != '2')) + { #ifdef VERBOSE_WARNING_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: Not a bzip2 v2 compression header!"); - + PrintLog("CDVDiso BZip2V2: Not a bzip2 v2 compression header!"); #endif /* VERBOSE_WARNING_BZIP2V2 */ + ActualFileClose(isofile->handle); + isofile->handle = ACTUALHANDLENULL; + return(-1); + } // ENDIF- ID for this compression type doesn't match? - ActualFileClose(isofile->handle); - - isofile->handle = ACTUALHANDLENULL; - - return(-1); - - } // ENDIF- ID for this compression type doesn't match? - - - - isofile->blocksize = ConvertEndianUInt(header.blocksize); - - isofile->filesectorsize = ConvertEndianUInt(header.numblocks); - - isofile->blockoffset = ConvertEndianUInt(header.blockoffset); - - isofile->filesectorpos = 0; - - isofile->compsector = header.numblocks + isofile->numsectors; - - return(0); - + isofile->blocksize = ConvertEndianUInt(header.blocksize); + isofile->filesectorsize = ConvertEndianUInt(header.numblocks); + isofile->blockoffset = ConvertEndianUInt(header.blockoffset); + isofile->filesectorpos = 0; + isofile->compsector = header.numblocks + isofile->numsectors; + return(0); } // END BZip2V2OpenForRead() - - - - -int BZip2V2Seek(struct IsoFile *isofile, off64_t position) { - - int retval; - - +int BZip2V2Seek(struct IsoFile *isofile, off64_t position) +{ + int retval; #ifdef VERBOSE_FUNCTION_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: Seek(%lli)", position); - + PrintLog("CDVDiso BZip2V2: Seek(%lli)", position); #endif /* VERBOSE_FUNCTION_BZIP2V2 */ - - - retval = ActualFileSeek(isofile->handle, position); - - if(retval < 0) { - + retval = ActualFileSeek(isofile->handle, position); + if (retval < 0) + { #ifdef VERBOSE_WARNING_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: Couldn't find the start of the compressed block!"); - + PrintLog("CDVDiso BZip2V2: Couldn't find the start of the compressed block!"); #endif /* VERBOSE_WARNING_BZIP2V2 */ + return(-1); + } // ENDIF- Couldn't find the data entry? Fail. + isofile->filebytepos = position; + return(0); - return(-1); - - } // ENDIF- Couldn't find the data entry? Fail. - - isofile->filebytepos = position; - - return(0); - - - - return(-1); // Fail. (Due to lack of ambition?) - + return(-1); // Fail. (Due to lack of ambition?) } // END BZip2V2Seek() - - - - -int BZip2V2Read(struct IsoFile *isofile, int bytes, char *buffer) { - - int retval; - - unsigned int blocklen; - - bz_stream strm; - - unsigned int tempin; - - char tempblock[65536]; - - unsigned int tempout; - - +int BZip2V2Read(struct IsoFile *isofile, int bytes, char *buffer) +{ + int retval; + unsigned int blocklen; + bz_stream strm; + unsigned int tempin; + char tempblock[65536]; + unsigned int tempout; #ifdef VERBOSE_FUNCTION_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: Read(%i)", bytes); - + PrintLog("CDVDiso BZip2V2: Read(%i)", bytes); #endif /* VERBOSE_FUNCTION_BZIP2V2 */ - - - if(bytes > 0) { - - retval = ActualFileRead(isofile->handle, bytes, tempblock); - - if(retval > 0) isofile->filebytepos += retval; - - if(retval != bytes) { - + if (bytes > 0) + { + retval = ActualFileRead(isofile->handle, bytes, tempblock); + if (retval > 0) isofile->filebytepos += retval; + if (retval != bytes) + { #ifdef VERBOSE_WARNING_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: Cannot read bytes! Returned: (%i)", retval); - + PrintLog("CDVDiso BZip2V2: Cannot read bytes! Returned: (%i)", retval); #endif /* VERBOSE_WARNING_BZIP2V2 */ + return(-1); + } // ENDIF- Trouble reading compressed sector? Abort. - return(-1); - - } // ENDIF- Trouble reading compressed sector? Abort. - - - - blocklen = 65536; - - retval = BZ2_bzBuffToBuffDecompress(buffer, &blocklen, tempblock, bytes, 0, 0); - - if(retval != BZ_OK) { - + blocklen = 65536; + retval = BZ2_bzBuffToBuffDecompress(buffer, &blocklen, tempblock, bytes, 0, 0); + if (retval != BZ_OK) + { #ifdef VERBOSE_WARNING_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: Cannot decode block! Returned: (%i)", retval); - + PrintLog("CDVDiso BZip2V2: Cannot decode block! Returned: (%i)", retval); #endif /* VERBOSE_WARNING_BZIP2V2 */ + return(-1); + } // ENDIF- Trouble decoding the sector? Abort. + return(0); + } // ENDIF- Do we know how many compressed bytes to get for this record? - return(-1); + // Hmm. Don't know the compressed size? Well, we'll just have to find it. - } // ENDIF- Trouble decoding the sector? Abort. + tempin = 0; + tempout = 0; + retval = BZ_OK; + while ((tempin < 65536) && (tempout < isofile->blocksize * isofile->numsectors)) + { + strm.bzalloc = NULL; + strm.bzfree = NULL; + strm.opaque = NULL; + retval = BZ2_bzDecompressInit(&strm, 0, 0); + if (retval != BZ_OK) return(-1); + strm.next_out = buffer; - - return(0); - - } // ENDIF- Do we know how many compressed bytes to get for this record? - - - - // Hmm. Don't know the compressed size? Well, we'll just have to find it. - - - - tempin = 0; - - tempout = 0; - - retval = BZ_OK; - - while((tempin < 65536) && (tempout < isofile->blocksize * isofile->numsectors)) { - - strm.bzalloc = NULL; - - strm.bzfree = NULL; - - strm.opaque = NULL; - - retval = BZ2_bzDecompressInit ( &strm, 0, 0 ); - - if (retval != BZ_OK) return(-1); - - - - strm.next_out = buffer; - - - - strm.avail_in = tempin; - - strm.avail_out = 65536; - - - - retval = BZ_OK; - - while((tempin < 65536) && (retval == BZ_OK)) { - - retval = ActualFileRead(isofile->handle, 1, &tempblock[tempin]); - - if(retval != 1) { - + strm.avail_in = tempin; + strm.avail_out = 65536; + retval = BZ_OK; + while ((tempin < 65536) && (retval == BZ_OK)) + { + retval = ActualFileRead(isofile->handle, 1, &tempblock[tempin]); + if (retval != 1) + { #ifdef VERBOSE_WARNING_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: Cannot read a byte! Returned: (%i)", retval); - + PrintLog("CDVDiso BZip2V2: Cannot read a byte! Returned: (%i)", retval); #endif /* VERBOSE_WARNING_BZIP2V2 */ + BZ2_bzDecompressEnd(&strm); + return(-1); + } // ENDIF- Trouble reading a piece of compressed sector? Abort. + tempin++; + strm.avail_in++; - BZ2_bzDecompressEnd(&strm); - - return(-1); - - } // ENDIF- Trouble reading a piece of compressed sector? Abort. - - tempin++; - - strm.avail_in++; - - - - strm.next_in = &tempblock[tempin - strm.avail_in]; - - retval = BZ2_bzDecompress(&strm); - - } // ENDWHILE- trying to uncompress an increasingly filled buffer - - tempout = 65536 - strm.avail_out; - - BZ2_bzDecompressEnd(&strm); - - - - } // ENDWHILE- trying to uncompress a whole buffer - - if(retval != BZ_STREAM_END) { + strm.next_in = &tempblock[tempin - strm.avail_in]; + retval = BZ2_bzDecompress(&strm); + } // ENDWHILE- trying to uncompress an increasingly filled buffer + tempout = 65536 - strm.avail_out; + BZ2_bzDecompressEnd(&strm); + } // ENDWHILE- trying to uncompress a whole buffer + if (retval != BZ_STREAM_END) + { #ifdef VERBOSE_WARNING_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: Failed to decode block! (Returned %i", retval); - + PrintLog("CDVDiso BZip2V2: Failed to decode block! (Returned %i", retval); #endif /* VERBOSE_WARNING_BZIP2V2 */ + return(-1); + } // ENDIF- Not a clean cutoff of a buffer? Say so. - return(-1); - - } // ENDIF- Not a clean cutoff of a buffer? Say so. - - - - if(tempin == 65536) return(-1); - - isofile->filebytepos += tempin; - - return(tempin); // Send out # of compressed bytes (to record in table) - + if (tempin == 65536) return(-1); + isofile->filebytepos += tempin; + return(tempin); // Send out # of compressed bytes (to record in table) } // END BZip2V2Read() +int BZip2V2OpenForWrite(struct IsoFile *isofile) +{ + char garbage[sizeof(struct BZip2V2Header)]; + int i; - - - -int BZip2V2OpenForWrite(struct IsoFile *isofile) { - - char garbage[sizeof(struct BZip2V2Header)]; - - int i; - - - - if(isofile == NULL) return(-1); - - + if (isofile == NULL) return(-1); #ifdef VERBOSE_FUNCTION_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: OpenForWrite()"); - + PrintLog("CDVDiso BZip2V2: OpenForWrite()"); #endif /* VERBOSE_FUNCTION_BZIP2V2 */ - - - isofile->handle = ActualFileOpenForWrite(isofile->name); - - if(isofile->handle == ACTUALHANDLENULL) { - - return(-1); - - } // ENDIF- Couldn't open data file? Fail. - - for(i = 0; i < sizeof(struct BZip2V2Header); i++) garbage[i] = 0; - - ActualFileWrite(isofile->handle, sizeof(struct BZip2V2Header), garbage); - - - - isofile->filebytesize = 0; - - isofile->filebytepos = sizeof(struct BZip2V2Header); - - isofile->numsectors = 16; - - isofile->filesectorsize = 0; - - isofile->filesectorpos = 0; - - isofile->compsector = 0; - - return(0); - + isofile->handle = ActualFileOpenForWrite(isofile->name); + if (isofile->handle == ACTUALHANDLENULL) + { + return(-1); + } // ENDIF- Couldn't open data file? Fail. + for (i = 0; i < sizeof(struct BZip2V2Header); i++) garbage[i] = 0; + ActualFileWrite(isofile->handle, sizeof(struct BZip2V2Header), garbage); + isofile->filebytesize = 0; + isofile->filebytepos = sizeof(struct BZip2V2Header); + isofile->numsectors = 16; + isofile->filesectorsize = 0; + isofile->filesectorpos = 0; + isofile->compsector = 0; + return(0); } // END BZip2V2OpenForWrite() - - - - -int BZip2V2Write(struct IsoFile *isofile, char *buffer) { - - int retval; - - unsigned int blocklen; - - char tempblock[65536]; - - +int BZip2V2Write(struct IsoFile *isofile, char *buffer) +{ + int retval; + unsigned int blocklen; + char tempblock[65536]; #ifdef VERBOSE_FUNCTION_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: Write()"); - + PrintLog("CDVDiso BZip2V2: Write()"); #endif /* VERBOSE_FUNCTION_BZIP2V2 */ - - - blocklen = 65536; - - retval = BZ2_bzBuffToBuffCompress(tempblock, - - &blocklen, - - buffer, - - isofile->blocksize * isofile->numsectors, - - 9, 0, 250); - - if(retval != BZ_OK) { - + blocklen = 65536; + retval = BZ2_bzBuffToBuffCompress(tempblock, + &blocklen, + buffer, + isofile->blocksize * isofile->numsectors, + 9, 0, 250); + if (retval != BZ_OK) + { #ifdef VERBOSE_FUNCTION_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: Cannot encode block! Returned: (%i)", retval); - + PrintLog("CDVDiso BZip2V2: Cannot encode block! Returned: (%i)", retval); #endif /* VERBOSE_FUNCTION_BZIP2V2 */ - - return(-1); - - } // ENDIF- Trouble compressing a block? Abort. - - - - retval = ActualFileWrite(isofile->handle, blocklen, tempblock); - - if(retval > 0) isofile->filebytepos += retval; - - if(retval < blocklen) { - + return(-1); + } // ENDIF- Trouble compressing a block? Abort. + retval = ActualFileWrite(isofile->handle, blocklen, tempblock); + if (retval > 0) isofile->filebytepos += retval; + if (retval < blocklen) + { #ifdef VERBOSE_FUNCTION_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: Cannot write bytes! Returned: (%i out of %llu)", - - retval, blocklen); - + PrintLog("CDVDiso BZip2V2: Cannot write bytes! Returned: (%i out of %llu)", + retval, blocklen); #endif /* VERBOSE_FUNCTION_BZIP2V2 */ - - return(-1); - - } // ENDIF- Trouble writing out the compressed block? Abort. - - - - return(blocklen); // Not in list? Fail. - + return(-1); + } // ENDIF- Trouble writing out the compressed block? Abort. + return(blocklen); // Not in list? Fail. } // END BZip2V2Write() - - - - -void BZip2V2Close(struct IsoFile *isofile) { - - struct BZip2V2Header header; - - struct TableData table; - - int compptr; - - int i; - - int retval; - - +void BZip2V2Close(struct IsoFile *isofile) +{ + struct BZip2V2Header header; + struct TableData table; + int compptr; + int i; + int retval; #ifdef VERBOSE_FUNCTION_BZIP2V2 - - PrintLog("CDVDiso BZip2V2: Close()"); - + PrintLog("CDVDiso BZip2V2: Close()"); #endif /* VERBOSE_FUNCTION_BZIP2V2 */ + if ((isofile->tablehandle != ACTUALHANDLENULL) && + (isofile->handle != ACTUALHANDLENULL)) + { + if (isofile->openforread == 0) + { + if (isofile->compsector != isofile->filesectorpos) + { + compptr = isofile->filesectorpos - isofile->compsector; + compptr *= isofile->blocksize; + for (i = compptr; i < 65536; i++) isofile->compblock[i] = 0; + retval = BZip2V2Write(isofile, isofile->compblock); + table.offset = isofile->filebytepos - retval; + table.size = retval; + BZip2V2WriteTable(isofile, table); + isofile->compsector = isofile->filesectorpos; + } // ENDIF - still have buffers to write? + } // ENDIF- Opened for write? Don't forget to flush the file buffer! + } // ENDIF- Are both the data file and table files open? + if (isofile->tablehandle != ACTUALHANDLENULL) + { + ActualFileClose(isofile->tablehandle); + isofile->tablehandle = ACTUALHANDLENULL; + } // ENDIF- Is there a table file open? Close it. + if (isofile->handle != ACTUALHANDLENULL) + { + if (isofile->openforread == 0) + { + if (isofile->compsector != isofile->filesectorpos) + { + compptr = isofile->filesectorpos - isofile->compsector; + compptr *= isofile->blocksize; + for (i = compptr; i < 65536; i++) isofile->compblock[i] = 0; + BZip2V2Write(isofile, isofile->compblock); + } // ENDIF - still have buffers to write? + header.id[0] = 'B'; + header.id[1] = 'Z'; + header.id[2] = 'V'; + header.id[3] = '2'; + header.blocksize = ConvertEndianUInt(isofile->blocksize); + header.numblocks = ConvertEndianUInt(isofile->filesectorsize); + header.blockoffset = ConvertEndianUInt(isofile->blockoffset); + ActualFileSeek(isofile->handle, 0); + ActualFileWrite(isofile->handle, + sizeof(struct BZip2V2Header), + (char *) &header); + } // ENDIF- Opened for write? Don't forget to update the header block! - if((isofile->tablehandle != ACTUALHANDLENULL) && - - (isofile->handle != ACTUALHANDLENULL)) { - - if(isofile->openforread == 0) { - - if(isofile->compsector != isofile->filesectorpos) { - - compptr = isofile->filesectorpos - isofile->compsector; - - compptr *= isofile->blocksize; - - for(i = compptr; i < 65536; i++) isofile->compblock[i] = 0; - - retval = BZip2V2Write(isofile, isofile->compblock); - - table.offset = isofile->filebytepos - retval; - - table.size = retval; - - BZip2V2WriteTable(isofile, table); - - isofile->compsector = isofile->filesectorpos; - - } // ENDIF - still have buffers to write? - - } // ENDIF- Opened for write? Don't forget to flush the file buffer! - - } // ENDIF- Are both the data file and table files open? - - - - if(isofile->tablehandle != ACTUALHANDLENULL) { - - ActualFileClose(isofile->tablehandle); - - isofile->tablehandle = ACTUALHANDLENULL; - - } // ENDIF- Is there a table file open? Close it. - - - - if(isofile->handle != ACTUALHANDLENULL) { - - if(isofile->openforread == 0) { - - if(isofile->compsector != isofile->filesectorpos) { - - compptr = isofile->filesectorpos - isofile->compsector; - - compptr *= isofile->blocksize; - - for(i = compptr; i < 65536; i++) isofile->compblock[i] = 0; - - BZip2V2Write(isofile, isofile->compblock); - - } // ENDIF - still have buffers to write? - - header.id[0] = 'B'; - - header.id[1] = 'Z'; - - header.id[2] = 'V'; - - header.id[3] = '2'; - - header.blocksize = ConvertEndianUInt(isofile->blocksize); - - header.numblocks = ConvertEndianUInt(isofile->filesectorsize); - - header.blockoffset = ConvertEndianUInt(isofile->blockoffset); - - ActualFileSeek(isofile->handle, 0); - - ActualFileWrite(isofile->handle, - - sizeof(struct BZip2V2Header), - - (char *) &header); - - } // ENDIF- Opened for write? Don't forget to update the header block! - - - - ActualFileClose(isofile->handle); - - isofile->handle = ACTUALHANDLENULL; - - } // ENDIF- Is there a data file open? Close it. - - - - if(isofile->tabledata != NULL) { - - free(isofile->tabledata); - - isofile->tabledata = NULL; - - } // ENDIF- Do we have a read-in table to clear out? - - - - return; + ActualFileClose(isofile->handle); + isofile->handle = ACTUALHANDLENULL; + } // ENDIF- Is there a data file open? Close it. + if (isofile->tabledata != NULL) + { + free(isofile->tabledata); + isofile->tabledata = NULL; + } // ENDIF- Do we have a read-in table to clear out? + return; } // END BZip2V2Close() - diff --git a/plugins/CDVDisoEFP/src/bzip2v2.h b/plugins/CDVDisoEFP/src/bzip2v2.h index 55c667a2ce..75b4d440ae 100644 --- a/plugins/CDVDisoEFP/src/bzip2v2.h +++ b/plugins/CDVDisoEFP/src/bzip2v2.h @@ -1,104 +1,46 @@ /* bzip2v2.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef BZIP2V2_H - #define BZIP2V2_H - - - - #include - - #include "isofile.h" - #include "isocompress.h" - - - - // #define VERBOSE_FUNCTION_BZIP2V2 - // #define VERBOSE_WARNING_BZIP2V2 - - - - extern int BZip2V2OpenTableForRead(struct IsoFile *isofile); - extern int BZip2V2SeekTable(struct IsoFile *isofile, off64_t sector); - extern int BZip2V2ReadTable(struct IsoFile *isofile, struct TableData *table); - - extern int BZip2V2OpenTableForWrite(struct IsoFile *isofile); - extern int BZip2V2WriteTable(struct IsoFile *isofile, struct TableData table); - - - extern int BZip2V2OpenForRead(struct IsoFile *isofile); - extern int BZip2V2Seek(struct IsoFile *isofile, off64_t sector); - extern int BZip2V2Read(struct IsoFile *isofile, int bytes, char *buffer); - extern void BZip2V2Close(struct IsoFile *isofile); - - extern int BZip2V2OpenForWrite(struct IsoFile *isofile); - extern int BZip2V2Write(struct IsoFile *isofile, char *buffer); - - - - #endif /* BZIP2V2_H */ - diff --git a/plugins/CDVDisoEFP/src/bzip2v3.c b/plugins/CDVDisoEFP/src/bzip2v3.c index 590c5f6d99..59a43ebe90 100644 --- a/plugins/CDVDisoEFP/src/bzip2v3.c +++ b/plugins/CDVDisoEFP/src/bzip2v3.c @@ -1,968 +1,489 @@ /* bzip2v3.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include // NULL - #include // malloc() - #include // off64_t - - #include "bzip2/bzlib.h" - - #include "convert.h" - #include "logfile.h" - #include "isofile.h" // IsoFile - #include "isocompress.h" // TableData, TableMap - #include "actualfile.h" - #include "convert.h" - #include "bzip2v3.h" - - - - #ifdef _WIN32 - #pragma pack(1) - #endif /* _WIN32 */ - - - -struct BZip2V3Header { - - char id[4]; - - unsigned short blocksize; - - off64_t numblocks; - - unsigned short blockoffset; - +struct BZip2V3Header +{ + char id[4]; + unsigned short blocksize; + off64_t numblocks; + unsigned short blockoffset; #ifdef _WIN32 - }; - #else - -} __attribute__ ((packed)); - +} __attribute__((packed)); #endif /* _WIN32 */ - - -struct BZip2V3Table { - - off64_t offset; - +struct BZip2V3Table +{ + off64_t offset; #ifdef _WIN32 - }; - #else - -} __attribute__ ((packed)); - +} __attribute__((packed)); #endif /* _WIN32 */ - - #ifdef _WIN32 - #pragma pack() - #endif /* _WIN32 */ - - - - -int BZip2V3OpenTableForRead(struct IsoFile *isofile) { - - int i; - - int j; - - char tableext[] = ".table\0"; - - off64_t numentries; - - off64_t offset; - - off64_t actual; - - - +int BZip2V3OpenTableForRead(struct IsoFile *isofile) +{ + int i; + int j; + char tableext[] = ".table\0"; + off64_t numentries; + off64_t offset; + off64_t actual; #ifdef VERBOSE_FUNCTION_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: OpenTableForRead()"); - + PrintLog("CDVDiso BZip2V3: OpenTableForRead()"); #endif /* VERBOSE_FUNCTION_BZIP2V3 */ + i = 0; + while ((i < 256) && (isofile->name[i] != 0)) + { + isofile->tablename[i] = isofile->name[i]; + i++; + } // ENDWHILE- Copying the data name to the table name + j = 0; + while ((i < 256) && (tableext[j] != 0)) + { + isofile->tablename[i] = tableext[j]; + i++; + j++; + } // ENDWHILE- Adding the ".table" extension. + isofile->tablename[i] = 0; // And 0-terminate. - - - i = 0; - - while((i < 256) && (isofile->name[i] != 0)) { - - isofile->tablename[i] = isofile->name[i]; - - i++; - - } // ENDWHILE- Copying the data name to the table name - - j = 0; - - while((i < 256) && (tableext[j] != 0)) { - - isofile->tablename[i] = tableext[j]; - - i++; - - j++; - - } // ENDWHILE- Adding the ".table" extension. - - isofile->tablename[i] = 0; // And 0-terminate. - - - - isofile->tablehandle = ActualFileOpenForRead(isofile->tablename); - - if(isofile->tablehandle == ACTUALHANDLENULL) { - + isofile->tablehandle = ActualFileOpenForRead(isofile->tablename); + if (isofile->tablehandle == ACTUALHANDLENULL) + { #ifdef VERBOSE_WARNING_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: Couldn't open table!"); - + PrintLog("CDVDiso BZip2V3: Couldn't open table!"); #endif /* VERBOSE_WARNING_BZIP2V3 */ + return(-2); + } // ENDIF- Couldn't open table file? Fail. - return(-2); - - } // ENDIF- Couldn't open table file? Fail. - - - - numentries = isofile->filesectorsize / isofile->numsectors; - - if((isofile->filesectorsize % isofile->numsectors) != 0) numentries++; - - offset = numentries * sizeof(struct BZip2V3Table); - - actual = ActualFileSize(isofile->tablehandle); - - if(offset != actual) { - + numentries = isofile->filesectorsize / isofile->numsectors; + if ((isofile->filesectorsize % isofile->numsectors) != 0) numentries++; + offset = numentries * sizeof(struct BZip2V3Table); + actual = ActualFileSize(isofile->tablehandle); + if (offset != actual) + { #ifdef VERBOSE_WARNING_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: Table not the correct size! (Should be %lli, is %lli)", - - offset, actual); - + PrintLog("CDVDiso BZip2V3: Table not the correct size! (Should be %lli, is %lli)", + offset, actual); #endif /* VERBOSE_WARNING_BZIP2V3 */ + return(-2); + } // ENDIF- Not the correct-sized table for the data file? Fail. - return(-2); - - } // ENDIF- Not the correct-sized table for the data file? Fail. - - - - return(0); - + return(0); } // END BZip2V3OpenTableForRead() - - - - -int BZip2V3SeekTable(struct IsoFile *isofile, off64_t sector) { - - off64_t target; - - int retval; - - +int BZip2V3SeekTable(struct IsoFile *isofile, off64_t sector) +{ + off64_t target; + int retval; #ifdef VERBOSE_FUNCTION_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: SeekTable(%lli)", sector); - + PrintLog("CDVDiso BZip2V3: SeekTable(%lli)", sector); #endif /* VERBOSE_FUNCTION_BZIP2V3 */ - - - target = sector / isofile->numsectors; - - target *= sizeof(struct BZip2V3Table); - - retval = ActualFileSeek(isofile->tablehandle, target); - - if(retval < 0) { - + target = sector / isofile->numsectors; + target *= sizeof(struct BZip2V3Table); + retval = ActualFileSeek(isofile->tablehandle, target); + if (retval < 0) + { #ifdef VERBOSE_WARNING_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: Couldn't find sector!"); - + PrintLog("CDVDiso BZip2V3: Couldn't find sector!"); #endif /* VERBOSE_WARNING_BZIP2V3 */ + return(-2); + } // ENDIF- Trouble finding the place? Fail. - return(-2); - - } // ENDIF- Trouble finding the place? Fail. - - - - isofile->filesectorpos = sector; - - isofile->compsector = isofile->filesectorsize + isofile->numsectors; - - return(0); - + isofile->filesectorpos = sector; + isofile->compsector = isofile->filesectorsize + isofile->numsectors; + return(0); } // END BZip2V3SeekTable() - - - - -int BZip2V3ReadTable(struct IsoFile *isofile, struct TableData *table) { - - int retval; - - struct BZip2V3Table temptable; - - +int BZip2V3ReadTable(struct IsoFile *isofile, struct TableData *table) +{ + int retval; + struct BZip2V3Table temptable; #ifdef VERBOSE_FUNCTION_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: ReadTable()"); - + PrintLog("CDVDiso BZip2V3: ReadTable()"); #endif /* VERBOSE_FUNCTION_BZIP2V3 */ - - - retval = ActualFileRead(isofile->tablehandle, - - sizeof(struct BZip2V3Table), - - (char *) &temptable); - - if(retval != sizeof(struct BZip2V3Table)) { - + retval = ActualFileRead(isofile->tablehandle, + sizeof(struct BZip2V3Table), + (char *) & temptable); + if (retval != sizeof(struct BZip2V3Table)) + { #ifdef VERBOSE_WARNING_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: Couldn't read table entry!"); - + PrintLog("CDVDiso BZip2V3: Couldn't read table entry!"); #endif /* VERBOSE_WARNING_BZIP2V3 */ + return(-2); + } // ENDIF- Trouble reading table entry? Fail. - return(-2); - - } // ENDIF- Trouble reading table entry? Fail. - - - - table->offset = ConvertEndianOffset(temptable.offset); - - table->size = 0; - - return(0); - + table->offset = ConvertEndianOffset(temptable.offset); + table->size = 0; + return(0); } // END BZip2V3ReadTable() - - - - -int BZip2V3OpenTableForWrite(struct IsoFile *isofile) { - - int i; - - int j; - - char tableext[] = ".table\0"; - - - +int BZip2V3OpenTableForWrite(struct IsoFile *isofile) +{ + int i; + int j; + char tableext[] = ".table\0"; #ifdef VERBOSE_FUNCTION_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: OpenTableForWrite()"); - + PrintLog("CDVDiso BZip2V3: OpenTableForWrite()"); #endif /* VERBOSE_FUNCTION_BZIP2V3 */ + i = 0; + while ((i < 256) && (isofile->name[i] != 0)) + { + isofile->tablename[i] = isofile->name[i]; + i++; + } // ENDWHILE- Copying the data name to the table name + j = 0; + while ((i < 256) && (tableext[j] != 0)) + { + isofile->tablename[i] = tableext[j]; + i++; + j++; + } // ENDWHILE- Adding the ".table" extension. + isofile->tablename[i] = 0; // And 0-terminate. - - - i = 0; - - while((i < 256) && (isofile->name[i] != 0)) { - - isofile->tablename[i] = isofile->name[i]; - - i++; - - } // ENDWHILE- Copying the data name to the table name - - j = 0; - - while((i < 256) && (tableext[j] != 0)) { - - isofile->tablename[i] = tableext[j]; - - i++; - - j++; - - } // ENDWHILE- Adding the ".table" extension. - - isofile->tablename[i] = 0; // And 0-terminate. - - - - isofile->tablehandle = ActualFileOpenForWrite(isofile->tablename); - - if(isofile->tablehandle == ACTUALHANDLENULL) { - + isofile->tablehandle = ActualFileOpenForWrite(isofile->tablename); + if (isofile->tablehandle == ACTUALHANDLENULL) + { #ifdef VERBOSE_WARNING_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: Couldn't open table!"); - + PrintLog("CDVDiso BZip2V3: Couldn't open table!"); #endif /* VERBOSE_WARNING_BZIP2V3 */ + return(-2); + } // ENDIF- Couldn't open table file? Fail. - return(-2); - - } // ENDIF- Couldn't open table file? Fail. - - - - // isofile->filesectorsize = 0; - - return(0); - + // isofile->filesectorsize = 0; + return(0); } // END BZip2V3OpenTableForWrite() - - - - -int BZip2V3WriteTable(struct IsoFile *isofile, struct TableData table) { - - int retval; - - struct BZip2V3Table bv3table; - - - +int BZip2V3WriteTable(struct IsoFile *isofile, struct TableData table) +{ + int retval; + struct BZip2V3Table bv3table; #ifdef VERBOSE_FUNCTION_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: WriteTable(%lli, %i)", table.offset, table.size); - + PrintLog("CDVDiso BZip2V3: WriteTable(%lli, %i)", table.offset, table.size); #endif /* VERBOSE_FUNCTION_BZIP2V3 */ - - - - bv3table.offset = ConvertEndianOffset(table.offset); - - retval = ActualFileWrite(isofile->tablehandle, - - sizeof(struct BZip2V3Table), - - (char *) &bv3table); - - if(retval != sizeof(struct BZip2V3Table)) { - + bv3table.offset = ConvertEndianOffset(table.offset); + retval = ActualFileWrite(isofile->tablehandle, + sizeof(struct BZip2V3Table), + (char *) & bv3table); + if (retval != sizeof(struct BZip2V3Table)) + { #ifdef VERBOSE_WARNING_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: Couldn't write table entry!"); - + PrintLog("CDVDiso BZip2V3: Couldn't write table entry!"); #endif /* VERBOSE_WARNING_BZIP2V3 */ + return(-2); + } // ENDIF- Trouble reading table entry? Fail. - return(-2); - - } // ENDIF- Trouble reading table entry? Fail. - - - - return(0); - + return(0); } // END BZip2V3WriteTable() - - - - -int BZip2V3OpenForRead(struct IsoFile *isofile) { - - int retval; - - struct BZip2V3Header header; - - +int BZip2V3OpenForRead(struct IsoFile *isofile) +{ + int retval; + struct BZip2V3Header header; #ifdef VERBOSE_FUNCTION_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: OpenForRead()"); - + PrintLog("CDVDiso BZip2V3: OpenForRead()"); #endif /* VERBOSE_FUNCTION_BZIP2V3 */ - - - isofile->handle = ActualFileOpenForRead(isofile->name); - - if(isofile->handle == ACTUALHANDLENULL) { - - return(-1); - - } // ENDIF- Couldn't open data file? Fail. - - - - isofile->filebytesize = ActualFileSize(isofile->handle); - - isofile->filebytepos = 0; - - isofile->filesectorpos = 0; - - - - isofile->imageheader = 0; - - - - retval = ActualFileRead(isofile->handle, - - sizeof(struct BZip2V3Header), - - (char *) &header); - - if(retval != sizeof(struct BZip2V3Header)) { - + isofile->handle = ActualFileOpenForRead(isofile->name); + if (isofile->handle == ACTUALHANDLENULL) + { + return(-1); + } // ENDIF- Couldn't open data file? Fail. + isofile->filebytesize = ActualFileSize(isofile->handle); + isofile->filebytepos = 0; + isofile->filesectorpos = 0; + isofile->imageheader = 0; + retval = ActualFileRead(isofile->handle, + sizeof(struct BZip2V3Header), + (char *) & header); + if (retval != sizeof(struct BZip2V3Header)) + { #ifdef VERBOSE_WARNING_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: Couldn't read header!"); - + PrintLog("CDVDiso BZip2V3: Couldn't read header!"); #endif /* VERBOSE_WARNING_BZIP2V3 */ + ActualFileClose(isofile->handle); + isofile->handle = ACTUALHANDLENULL; + return(-1); + } // ENDIF Could not read the first sector? Fail. + isofile->filebytepos += retval; - ActualFileClose(isofile->handle); - - isofile->handle = ACTUALHANDLENULL; - - return(-1); - - } // ENDIF Could not read the first sector? Fail. - - isofile->filebytepos += retval; - - - - if((header.id[0] != 'B') || - - (header.id[1] != 'Z') || - - (header.id[2] != 'V') || - - (header.id[3] != '3')) { - + if ((header.id[0] != 'B') || + (header.id[1] != 'Z') || + (header.id[2] != 'V') || + (header.id[3] != '3')) + { #ifdef VERBOSE_WARNING_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: Not a bzip2 v3 compression header!"); - + PrintLog("CDVDiso BZip2V3: Not a bzip2 v3 compression header!"); #endif /* VERBOSE_WARNING_BZIP2V3 */ + ActualFileClose(isofile->handle); + isofile->handle = ACTUALHANDLENULL; + return(-1); + } // ENDIF- ID for this compression type doesn't match? - ActualFileClose(isofile->handle); - - isofile->handle = ACTUALHANDLENULL; - - return(-1); - - } // ENDIF- ID for this compression type doesn't match? - - - - isofile->blocksize = ConvertEndianUShort(header.blocksize); - - isofile->filesectorsize = ConvertEndianOffset(header.numblocks); - - isofile->blockoffset = ConvertEndianUShort(header.blockoffset); - - isofile->numsectors = (65536 / isofile->blocksize) - 1; - - isofile->filesectorpos = 0; - - isofile->compsector = header.numblocks + isofile->numsectors; - - return(0); - + isofile->blocksize = ConvertEndianUShort(header.blocksize); + isofile->filesectorsize = ConvertEndianOffset(header.numblocks); + isofile->blockoffset = ConvertEndianUShort(header.blockoffset); + isofile->numsectors = (65536 / isofile->blocksize) - 1; + isofile->filesectorpos = 0; + isofile->compsector = header.numblocks + isofile->numsectors; + return(0); } // END BZip2V3OpenForRead() - - - - -int BZip2V3Seek(struct IsoFile *isofile, off64_t position) { - - int retval; - - - +int BZip2V3Seek(struct IsoFile *isofile, off64_t position) +{ + int retval; #ifdef VERBOSE_FUNCTION_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: Seek(%lli)", position); - + PrintLog("CDVDiso BZip2V3: Seek(%lli)", position); #endif /* VERBOSE_FUNCTION_BZIP2V3 */ - - - - retval = ActualFileSeek(isofile->handle, position); - - if(retval < 0) { - + retval = ActualFileSeek(isofile->handle, position); + if (retval < 0) + { #ifdef VERBOSE_WARNING_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: Couldn't find the start of the compressed block!"); - + PrintLog("CDVDiso BZip2V3: Couldn't find the start of the compressed block!"); #endif /* VERBOSE_WARNING_BZIP2V3 */ - - return(-1); - - } // ENDIF- Couldn't find the data entry? Fail. - - isofile->filebytepos = position; - - return(0); - - - - return(-1); // Fail. (Due to lack of ambition?) - + return(-1); + } // ENDIF- Couldn't find the data entry? Fail. + isofile->filebytepos = position; + return(0); + return(-1); // Fail. (Due to lack of ambition?) } // END BZip2V3Seek() - - - - -int BZip2V3Read(struct IsoFile *isofile, int bytes, char *buffer) { - - int retval; - - unsigned short tempsize; - - char tempblock[65536]; - - unsigned int blocklen; - - - +int BZip2V3Read(struct IsoFile *isofile, int bytes, char *buffer) +{ + int retval; + unsigned short tempsize; + char tempblock[65536]; + unsigned int blocklen; #ifdef VERBOSE_FUNCTION_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: Read()"); - + PrintLog("CDVDiso BZip2V3: Read()"); #endif /* VERBOSE_FUNCTION_BZIP2V3 */ - - - - retval = ActualFileRead(isofile->handle, - - sizeof(unsigned short), - - (char *) &tempsize); - - if(retval > 0) isofile->filebytepos += retval; - - if(retval != sizeof(unsigned short)) { - + retval = ActualFileRead(isofile->handle, + sizeof(unsigned short), + (char *) & tempsize); + if (retval > 0) isofile->filebytepos += retval; + if (retval != sizeof(unsigned short)) + { #ifdef VERBOSE_WARNING_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: Cannot read bytes! Returned: (%i)", retval); - + PrintLog("CDVDiso BZip2V3: Cannot read bytes! Returned: (%i)", retval); #endif /* VERBOSE_WARNING_BZIP2V3 */ - - return(-1); - - } // ENDIF- Trouble reading compressed sector? Abort. - - tempsize = ConvertEndianUShort(tempsize); - - - - retval = ActualFileRead(isofile->handle, tempsize, tempblock); - - if(retval > 0) isofile->filebytepos += retval; - - if(retval != tempsize) { - + return(-1); + } // ENDIF- Trouble reading compressed sector? Abort. + tempsize = ConvertEndianUShort(tempsize); + retval = ActualFileRead(isofile->handle, tempsize, tempblock); + if (retval > 0) isofile->filebytepos += retval; + if (retval != tempsize) + { #ifdef VERBOSE_WARNING_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: Cannot read bytes! Returned: (%i)", retval); - + PrintLog("CDVDiso BZip2V3: Cannot read bytes! Returned: (%i)", retval); #endif /* VERBOSE_WARNING_BZIP2V3 */ + return(-1); + } // ENDIF- Trouble reading compressed sector? Abort. - return(-1); - - } // ENDIF- Trouble reading compressed sector? Abort. - - - - blocklen = 65536; - - retval = BZ2_bzBuffToBuffDecompress(buffer, &blocklen, tempblock, tempsize, 0, 0); - - if(retval != BZ_OK) { - + blocklen = 65536; + retval = BZ2_bzBuffToBuffDecompress(buffer, &blocklen, tempblock, tempsize, 0, 0); + if (retval != BZ_OK) + { #ifdef VERBOSE_WARNING_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: Cannot decode block! Returned: (%i)", retval); - + PrintLog("CDVDiso BZip2V3: Cannot decode block! Returned: (%i)", retval); #endif /* VERBOSE_WARNING_BZIP2V3 */ - - return(-1); - - } // ENDIF- Trouble decoding the sector? Abort. - - - - return(tempsize + sizeof(unsigned short)); - + return(-1); + } // ENDIF- Trouble decoding the sector? Abort. + return(tempsize + sizeof(unsigned short)); } // END BZip2V3Read() - - - - -int BZip2V3OpenForWrite(struct IsoFile *isofile) { - - char garbage[sizeof(struct BZip2V3Header)]; - - int i; - - - - if(isofile == NULL) return(-1); - - - +int BZip2V3OpenForWrite(struct IsoFile *isofile) +{ + char garbage[sizeof(struct BZip2V3Header)]; + int i; + if (isofile == NULL) return(-1); #ifdef VERBOSE_FUNCTION_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: OpenForWrite()"); - + PrintLog("CDVDiso BZip2V3: OpenForWrite()"); #endif /* VERBOSE_FUNCTION_BZIP2V3 */ + isofile->handle = ActualFileOpenForWrite(isofile->name); + if (isofile->handle == ACTUALHANDLENULL) + { + return(-1); + } // ENDIF- Couldn't open data file? Fail. + for (i = 0; i < sizeof(struct BZip2V3Header); i++) garbage[i] = 0; + ActualFileWrite(isofile->handle, sizeof(struct BZip2V3Header), garbage); - - - isofile->handle = ActualFileOpenForWrite(isofile->name); - - if(isofile->handle == ACTUALHANDLENULL) { - - return(-1); - - } // ENDIF- Couldn't open data file? Fail. - - for(i = 0; i < sizeof(struct BZip2V3Header); i++) garbage[i] = 0; - - ActualFileWrite(isofile->handle, sizeof(struct BZip2V3Header), garbage); - - - - isofile->filebytesize = 0; - - isofile->filebytepos = sizeof(struct BZip2V3Header); - - isofile->numsectors = (65536 / isofile->blocksize) - 1; - - isofile->filesectorsize = 0; - - isofile->filesectorpos = 0; - - isofile->compsector = 0; - - return(0); - + isofile->filebytesize = 0; + isofile->filebytepos = sizeof(struct BZip2V3Header); + isofile->numsectors = (65536 / isofile->blocksize) - 1; + isofile->filesectorsize = 0; + isofile->filesectorpos = 0; + isofile->compsector = 0; + return(0); } // END BZip2V3OpenForWrite() - - - - -int BZip2V3Write(struct IsoFile *isofile, char *buffer) { - - int retval; - - unsigned int blocklen; - - char tempblock[65536]; - - unsigned short tempsize; - - +int BZip2V3Write(struct IsoFile *isofile, char *buffer) +{ + int retval; + unsigned int blocklen; + char tempblock[65536]; + unsigned short tempsize; #ifdef VERBOSE_FUNCTION_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: Write()"); - + PrintLog("CDVDiso BZip2V3: Write()"); #endif /* VERBOSE_FUNCTION_BZIP2V3 */ - - - blocklen = 65536; - - retval = BZ2_bzBuffToBuffCompress(tempblock, - - &blocklen, - - buffer, - - isofile->blocksize * isofile->numsectors, - - 9, 0, 250); - - if(retval != BZ_OK) { - + blocklen = 65536; + retval = BZ2_bzBuffToBuffCompress(tempblock, + &blocklen, + buffer, + isofile->blocksize * isofile->numsectors, + 9, 0, 250); + if (retval != BZ_OK) + { #ifdef VERBOSE_FUNCTION_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: Cannot encode block! Returned: (%i)", retval); - + PrintLog("CDVDiso BZip2V3: Cannot encode block! Returned: (%i)", retval); #endif /* VERBOSE_FUNCTION_BZIP2V3 */ - - return(-1); - - } // ENDIF- Trouble compressing a block? Abort. - - - - tempsize = blocklen; - - tempsize = ConvertEndianUShort(tempsize); - - retval = ActualFileWrite(isofile->handle, - - sizeof(unsigned short), - - (char *) &tempsize); - - if(retval > 0) isofile->filebytepos += retval; - - if(retval < sizeof(unsigned short)) { - + return(-1); + } // ENDIF- Trouble compressing a block? Abort. + tempsize = blocklen; + tempsize = ConvertEndianUShort(tempsize); + retval = ActualFileWrite(isofile->handle, + sizeof(unsigned short), + (char *) & tempsize); + if (retval > 0) isofile->filebytepos += retval; + if (retval < sizeof(unsigned short)) + { #ifdef VERBOSE_FUNCTION_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: Cannot write bytes! Returned: (%i out of %llu)", - - retval, sizeof(unsigned short)); - + PrintLog("CDVDiso BZip2V3: Cannot write bytes! Returned: (%i out of %llu)", + retval, sizeof(unsigned short)); #endif /* VERBOSE_FUNCTION_BZIP2V3 */ + return(-1); + } // ENDIF- Trouble writing out the compressed block? Abort. - return(-1); - - } // ENDIF- Trouble writing out the compressed block? Abort. - - - - - - retval = ActualFileWrite(isofile->handle, blocklen, tempblock); - - if(retval > 0) isofile->filebytepos += retval; - - if(retval < blocklen) { - + retval = ActualFileWrite(isofile->handle, blocklen, tempblock); + if (retval > 0) isofile->filebytepos += retval; + if (retval < blocklen) + { #ifdef VERBOSE_FUNCTION_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: Cannot write bytes! Returned: (%i out of %llu)", - - retval, blocklen); - + PrintLog("CDVDiso BZip2V3: Cannot write bytes! Returned: (%i out of %llu)", + retval, blocklen); #endif /* VERBOSE_FUNCTION_BZIP2V3 */ + return(-1); + } // ENDIF- Trouble writing out the compressed block? Abort. - return(-1); - - } // ENDIF- Trouble writing out the compressed block? Abort. - - - - return(blocklen + sizeof(unsigned short)); // Not in list? Fail. - + return(blocklen + sizeof(unsigned short)); // Not in list? Fail. } // END BZip2V3Write() - - - - -void BZip2V3Close(struct IsoFile *isofile) { - - struct BZip2V3Header header; - - struct TableData table; - - int compptr; - - int i; - - int retval; - - unsigned short tempsize; - - +void BZip2V3Close(struct IsoFile *isofile) +{ + struct BZip2V3Header header; + struct TableData table; + int compptr; + int i; + int retval; + unsigned short tempsize; #ifdef VERBOSE_FUNCTION_BZIP2V3 - - PrintLog("CDVDiso BZip2V3: Close()"); - + PrintLog("CDVDiso BZip2V3: Close()"); #endif /* VERBOSE_FUNCTION_BZIP2V3 */ + if ((isofile->tablehandle != ACTUALHANDLENULL) && + (isofile->handle != ACTUALHANDLENULL)) + { + if (isofile->openforread == 0) + { + if (isofile->compsector != isofile->filesectorpos) + { + compptr = isofile->filesectorpos - isofile->compsector; + compptr *= isofile->blocksize; + for (i = compptr; i < 65536; i++) isofile->compblock[i] = 0; + retval = BZip2V3Write(isofile, isofile->compblock); + table.offset = isofile->filebytepos - retval; + table.size = retval; + BZip2V3WriteTable(isofile, table); + isofile->compsector = isofile->filesectorpos; + } // ENDIF - still have buffers to write? + } // ENDIF- Opened for write? Don't forget to flush the file buffer! + } // ENDIF- Both data file and table file are open? + if (isofile->tablehandle != ACTUALHANDLENULL) + { + ActualFileClose(isofile->tablehandle); + isofile->tablehandle = ACTUALHANDLENULL; + } // ENDIF- Is there a table file open? Close it. + if (isofile->handle != ACTUALHANDLENULL) + { + if (isofile->openforread == 0) + { + if (isofile->compsector != isofile->filesectorpos) + { + compptr = isofile->filesectorpos - isofile->compsector; + compptr *= isofile->blocksize; + for (i = compptr; i < 65536; i++) isofile->compblock[i] = 0; + BZip2V3Write(isofile, isofile->compblock); + } // ENDIF - still have buffers to write? + header.id[0] = 'B'; + header.id[1] = 'Z'; + header.id[2] = 'V'; + header.id[3] = '3'; + tempsize = isofile->blocksize; + header.blocksize = ConvertEndianUShort(tempsize); + header.numblocks = ConvertEndianOffset(isofile->filesectorsize); + tempsize = isofile->blockoffset; + header.blockoffset = ConvertEndianUShort(tempsize); + ActualFileSeek(isofile->handle, 0); + ActualFileWrite(isofile->handle, + sizeof(struct BZip2V3Header), + (char *) &header); + } // ENDIF- Opened for write? Don't forget to update the header block! - if((isofile->tablehandle != ACTUALHANDLENULL) && - - (isofile->handle != ACTUALHANDLENULL)) { - - if(isofile->openforread == 0) { - - if(isofile->compsector != isofile->filesectorpos) { - - compptr = isofile->filesectorpos - isofile->compsector; - - compptr *= isofile->blocksize; - - for(i = compptr; i < 65536; i++) isofile->compblock[i] = 0; - - retval = BZip2V3Write(isofile, isofile->compblock); - - table.offset = isofile->filebytepos - retval; - - table.size = retval; - - BZip2V3WriteTable(isofile, table); - - isofile->compsector = isofile->filesectorpos; - - } // ENDIF - still have buffers to write? - - } // ENDIF- Opened for write? Don't forget to flush the file buffer! - - } // ENDIF- Both data file and table file are open? - - - - if(isofile->tablehandle != ACTUALHANDLENULL) { - - ActualFileClose(isofile->tablehandle); - - isofile->tablehandle = ACTUALHANDLENULL; - - } // ENDIF- Is there a table file open? Close it. - - - - if(isofile->handle != ACTUALHANDLENULL) { - - if(isofile->openforread == 0) { - - if(isofile->compsector != isofile->filesectorpos) { - - compptr = isofile->filesectorpos - isofile->compsector; - - compptr *= isofile->blocksize; - - for(i = compptr; i < 65536; i++) isofile->compblock[i] = 0; - - BZip2V3Write(isofile, isofile->compblock); - - } // ENDIF - still have buffers to write? - - header.id[0] = 'B'; - - header.id[1] = 'Z'; - - header.id[2] = 'V'; - - header.id[3] = '3'; - - tempsize = isofile->blocksize; - - header.blocksize = ConvertEndianUShort(tempsize); - - header.numblocks = ConvertEndianOffset(isofile->filesectorsize); - - tempsize = isofile->blockoffset; - - header.blockoffset = ConvertEndianUShort(tempsize); - - ActualFileSeek(isofile->handle, 0); - - ActualFileWrite(isofile->handle, - - sizeof(struct BZip2V3Header), - - (char *) &header); - - } // ENDIF- Opened for write? Don't forget to update the header block! - - - - ActualFileClose(isofile->handle); - - isofile->handle = ACTUALHANDLENULL; - - } // ENDIF- Is there a data file open? Close it. - - - - if(isofile->tabledata != NULL) { - - free(isofile->tabledata); - - isofile->tabledata = NULL; - - } // ENDIF- Do we have a read-in table to clear out? - - - - return; + ActualFileClose(isofile->handle); + isofile->handle = ACTUALHANDLENULL; + } // ENDIF- Is there a data file open? Close it. + if (isofile->tabledata != NULL) + { + free(isofile->tabledata); + isofile->tabledata = NULL; + } // ENDIF- Do we have a read-in table to clear out? + return; } // END BZip2V3Close() - diff --git a/plugins/CDVDisoEFP/src/bzip2v3.h b/plugins/CDVDisoEFP/src/bzip2v3.h index 467534a0fd..69fc1a722b 100644 --- a/plugins/CDVDisoEFP/src/bzip2v3.h +++ b/plugins/CDVDisoEFP/src/bzip2v3.h @@ -1,104 +1,46 @@ /* bzip2v3.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef BZIP2V3_H - #define BZIP2V3_H - - - - #include - - #include "isofile.h" - #include "isocompress.h" - - - - // #define VERBOSE_FUNCTION_BZIP2V3 - // #define VERBOSE_WARNING_BZIP2V3 - - - - extern int BZip2V3OpenTableForRead(struct IsoFile *isofile); - extern int BZip2V3SeekTable(struct IsoFile *isofile, off64_t sector); - extern int BZip2V3ReadTable(struct IsoFile *isofile, struct TableData *table); - - extern int BZip2V3OpenTableForWrite(struct IsoFile *isofile); - extern int BZip2V3WriteTable(struct IsoFile *isofile, struct TableData table); - - - extern int BZip2V3OpenForRead(struct IsoFile *isofile); - extern int BZip2V3Seek(struct IsoFile *isofile, off64_t sector); - extern int BZip2V3Read(struct IsoFile *isofile, int bytes, char *buffer); - extern void BZip2V3Close(struct IsoFile *isofile); - - extern int BZip2V3OpenForWrite(struct IsoFile *isofile); - extern int BZip2V3Write(struct IsoFile *isofile, char *buffer); - - - - #endif /* BZIP2V3_H */ - diff --git a/plugins/CDVDisoEFP/src/convert.c b/plugins/CDVDisoEFP/src/convert.c index 1f41c4f2f6..215a952328 100644 --- a/plugins/CDVDisoEFP/src/convert.c +++ b/plugins/CDVDisoEFP/src/convert.c @@ -17,102 +17,95 @@ * * PCSX2 members can be contacted through their website at www.pcsx2.net. */ - - #include #include - #include "convert.h" - - -off64_t ConvertEndianOffset(off64_t number) { +off64_t ConvertEndianOffset(off64_t number) +{ #ifndef CONVERTLITTLEENDIAN - union { - off64_t n; - char c[sizeof(off64_t)]; - } oldnumber, newnumber; - int i; - - oldnumber.n = number; - for(i = 0; i < sizeof(off64_t); i++) - newnumber.c[i] = oldnumber.c[sizeof(off64_t) - 1 - i]; - return(newnumber.n); + union + { + off64_t n; + char c[sizeof(off64_t)]; + } oldnumber, newnumber; + int i; + oldnumber.n = number; + for (i = 0; i < sizeof(off64_t); i++) + newnumber.c[i] = oldnumber.c[sizeof(off64_t) - 1 - i]; + return(newnumber.n); #else - return(number); + return(number); #endif /* CONVERTLITTLEENDIAN */ } // END ConvertEndianOffset() - -unsigned int ConvertEndianUInt(unsigned int number) { +unsigned int ConvertEndianUInt(unsigned int number) +{ #ifndef CONVERTLITTLEENDIAN - union { - unsigned int n; - char c[sizeof(unsigned int)]; - } oldnumber, newnumber; - int i; + union + { + unsigned int n; + char c[sizeof(unsigned int)]; + } oldnumber, newnumber; + int i; - oldnumber.n = number; - for(i = 0; i < sizeof(unsigned int); i++) - newnumber.c[i] = oldnumber.c[sizeof(unsigned int) - 1 - i]; - return(newnumber.n); + oldnumber.n = number; + for (i = 0; i < sizeof(unsigned int); i++) + newnumber.c[i] = oldnumber.c[sizeof(unsigned int) - 1 - i]; + return(newnumber.n); #else - return(number); + return(number); #endif /* CONVERTLITTLEENDIAN */ } // END ConvertEndianUInt() - - -unsigned short ConvertEndianUShort(unsigned short number) { +unsigned short ConvertEndianUShort(unsigned short number) +{ #ifndef CONVERTLITTLEENDIAN - union { - unsigned short n; - char c[sizeof(unsigned short)]; - } oldnumber, newnumber; - int i; - - oldnumber.n = number; - for(i = 0; i < sizeof(unsigned short); i++) - newnumber.c[i] = oldnumber.c[sizeof(unsigned short) - 1 - i]; - return(newnumber.n); + union + { + unsigned short n; + char c[sizeof(unsigned short)]; + } oldnumber, newnumber; + int i; + oldnumber.n = number; + for (i = 0; i < sizeof(unsigned short); i++) + newnumber.c[i] = oldnumber.c[sizeof(unsigned short) - 1 - i]; + return(newnumber.n); #else - return(number); + return(number); #endif /* CONVERTLITTLEENDIAN */ } // END ConvertEndianUShort() - // Note: deposits M/S/F data in buffer[0]/[1]/[2] respectively. -void LBAtoMSF(unsigned long lsn, char *buffer) { - unsigned long templsn; +void LBAtoMSF(unsigned long lsn, char *buffer) +{ + unsigned long templsn; - if(lsn >= 0xFFFFFFFF - 150) { - *(buffer + 2) = 75-1; - *(buffer + 1) = 60-1; - *(buffer) = 100-1; - } // ENDIF- Out of range? + if (lsn >= 0xFFFFFFFF - 150) + { + *(buffer + 2) = 75 - 1; + *(buffer + 1) = 60 - 1; + *(buffer) = 100 - 1; + } // ENDIF- Out of range? - templsn = lsn; - templsn += 150; // 2 second offset (75 Frames * 2 Seconds) - *(buffer + 2) = templsn % 75; // Remainder in frames - templsn -= *(buffer + 2); - templsn /= 75; - *(buffer + 1) = templsn % 60; // Remainder in seconds - templsn -= *(buffer + 1); - templsn /= 60; - *(buffer) = templsn; // Leftover quotient in minutes + templsn = lsn; + templsn += 150; // 2 second offset (75 Frames * 2 Seconds) + *(buffer + 2) = templsn % 75; // Remainder in frames + templsn -= *(buffer + 2); + templsn /= 75; + *(buffer + 1) = templsn % 60; // Remainder in seconds + templsn -= *(buffer + 1); + templsn /= 60; + *(buffer) = templsn; // Leftover quotient in minutes } // END LBAtoMSF() - - -unsigned long MSFtoLBA(char *buffer) { - unsigned long templsn; - - if(buffer == NULL) return(0xFFFFFFFF); - - templsn = *(buffer); // Minutes - templsn *= 60; - templsn += *(buffer + 1); // Seconds - templsn *= 75; - templsn += *(buffer + 2); // Frames - if(templsn < 150) return(0xFFFFFFFF); - templsn -= 150; // Offset - - return(templsn); +unsigned long MSFtoLBA(char *buffer) +{ + unsigned long templsn; + if (buffer == NULL) return(0xFFFFFFFF); + templsn = *(buffer); // Minutes + templsn *= 60; + templsn += *(buffer + 1); // Seconds + templsn *= 75; + templsn += *(buffer + 2); // Frames + if (templsn < 150) return(0xFFFFFFFF); + templsn -= 150; // Offset + return(templsn); } // END MSFtoLBA() diff --git a/plugins/CDVDisoEFP/src/convert.h b/plugins/CDVDisoEFP/src/convert.h index 8eb4bda61f..83c115cf60 100644 --- a/plugins/CDVDisoEFP/src/convert.h +++ b/plugins/CDVDisoEFP/src/convert.h @@ -17,12 +17,9 @@ * * PCSX2 members can be contacted through their website at www.pcsx2.net. */ - - #ifndef CONVERT_H #define CONVERT_H - #include // off64_t #include "PS2Etypes.h" #ifdef __linux__ @@ -31,19 +28,15 @@ #define CONVERTLITTLEENDIAN #endif /* __BYTE_ORDER */ #endif /* __linux__ */ - #ifdef _WIN32 #define CONVERTLITTLEENDIAN #endif /* _WIN32 */ - #define HEXTOBCD(i) (((i)/10*16) + ((i)%10)) #define BCDTOHEX(i) (((i)/16*10) + ((i)%16)) - extern off64_t ConvertEndianOffset(off64_t number); extern unsigned int ConvertEndianUInt(unsigned int number); extern unsigned short ConvertEndianUShort(unsigned short number); - extern void LBAtoMSF(unsigned long lsn, char *buffer); extern unsigned long MSFtoLBA(char *buffer); diff --git a/plugins/CDVDisoEFP/src/ecma119.c b/plugins/CDVDisoEFP/src/ecma119.c index 44ac3ae57d..dcf2e28019 100644 --- a/plugins/CDVDisoEFP/src/ecma119.c +++ b/plugins/CDVDisoEFP/src/ecma119.c @@ -1,118 +1,60 @@ -/* ecma119.c - - * Copyright (C) 2002-2005 PCSX2 Team - - * - - * This program is free software; you can redistribute it and/or modify - - * it under the terms of the GNU General Public License as published by - - * the Free Software Foundation; either version 2 of the License, or - - * (at your option) any later version. - - * - - * This program is distributed in the hope that it will be useful, - - * but WITHOUT ANY WARRANTY; without even the implied warranty of - - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - - * GNU General Public License for more details. - - * - - * You should have received a copy of the GNU General Public License - - * along with this program; if not, write to the Free Software - - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - * - - * PCSX2 members can be contacted through their website at www.pcsx2.net. - - */ - - - - - -#include - - - -// #ifndef __LINUX__ - -// #ifdef __linux__ - -// #define __LINUX__ - -// #endif /* __linux__ */ - -// #endif /* No __LINUX__ */ - - - -// #define CDVDdefs - -// #include "PS2Edefs.h" - - - -#include "ecma119.h" - - - - - -const char ECMA119VolumeIDstdid[] = "CD001\0"; - - - - - -int ValidateECMA119PrimaryVolume(struct ECMA119PrimaryVolume *volume) { - - int i; - - - - if(volume == NULL) return(-1); - - - - // Volume ID - - if(volume->id.voltype != 1) return(-1); // Incorrect volume type - - if(volume->id.version != 1) return(-1); // Not a Standard Version? - - i = 0; - - while((ECMA119VolumeIDstdid[i] != 0) && - - (ECMA119VolumeIDstdid[i] == volume->id.stdid[i])) i++; - - if(ECMA119VolumeIDstdid[i] != 0) return(-1); // "CD001" did not match? - - - - // Looks like numblocksle might give us maximum sector count... - - // Looks like blocksizele can be compared to blocksize stored in isofile... - - - - return(0); - -} // END ValidateECMA119PrimaryVolume() - - - - - -// Not sure the Partition Volume will be much help... - +/* ecma119.c + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +#include + +// #ifndef __LINUX__ +// #ifdef __linux__ +// #define __LINUX__ +// #endif /* __linux__ */ +// #endif /* No __LINUX__ */ + +// #define CDVDdefs +// #include "PS2Edefs.h" + +#include "ecma119.h" + + +const char ECMA119VolumeIDstdid[] = "CD001\0"; + + +int ValidateECMA119PrimaryVolume(struct ECMA119PrimaryVolume *volume) +{ + int i; + + if (volume == NULL) return(-1); + + // Volume ID + if (volume->id.voltype != 1) return(-1); // Incorrect volume type + if (volume->id.version != 1) return(-1); // Not a Standard Version? + i = 0; + while ((ECMA119VolumeIDstdid[i] != 0) && + (ECMA119VolumeIDstdid[i] == volume->id.stdid[i])) i++; + if (ECMA119VolumeIDstdid[i] != 0) return(-1); // "CD001" did not match? + + // Looks like numblocksle might give us maximum sector count... + // Looks like blocksizele can be compared to blocksize stored in isofile... + + return(0); +} // END ValidateECMA119PrimaryVolume() + + +// Not sure the Partition Volume will be much help... diff --git a/plugins/CDVDisoEFP/src/ecma119.h b/plugins/CDVDisoEFP/src/ecma119.h index 1207d8e133..2dd93a9d6c 100644 --- a/plugins/CDVDisoEFP/src/ecma119.h +++ b/plugins/CDVDisoEFP/src/ecma119.h @@ -1,468 +1,217 @@ /* ecma119.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef ECMA119_H - #define ECMA119_H - - - - // #ifndef __LINUX__ - // #ifdef __linux__ - // #define __LINUX__ - // #endif /* __linux__ */ - // #endif /* No __LINUX__ */ - - // #define CDVDdefs - // #include "PS2Edefs.h" - - - - // ECMA119 was sent to ISO to be fast-tracked into ISO 9660 - // ECMA119 can be found at http://www.ecma.ch, somewhere. - - - // Throughout these definitions, number pairs in both big-endian and - // little-endian varieties are stored next to each other. To separate - // the pairs a 'le' suffix has been attached to little-endian numbers, and - // a 'be' suffix to big-endian ones. - - // All 'unused' entries should be set to (or tested for) 0x00. - - - - #ifdef _WIN32 - #pragma pack(1) - #endif /* _WIN32 */ - - - -struct ECMA119ASCIITime { - - char year[4]; - - char month[2]; - - char day[2]; - - char hour[2]; - - char min[2]; - - char sec[2]; - - char hundredthsec[2]; - - char offsetgmt; // 15 min intervals, from -48 to +52 - +struct ECMA119ASCIITime +{ + char year[4]; + char month[2]; + char day[2]; + char hour[2]; + char min[2]; + char sec[2]; + char hundredthsec[2]; + char offsetgmt; // 15 min intervals, from -48 to +52 #ifdef _WIN32 - }; - #else - -} __attribute__ ((packed)); - +} __attribute__((packed)); #endif /* _WIN32 */ - - -struct ECMA119DateTime { - - unsigned char year; // 1900+year, that is. - - unsigned char month; - - unsigned char day; - - unsigned char hour; - - unsigned char minute; - - unsigned char sec; - - signed char offsetgmt; // In 15 min intervals, from -48 to +52 - +struct ECMA119DateTime +{ + unsigned char year; // 1900+year, that is. + unsigned char month; + unsigned char day; + unsigned char hour; + unsigned char minute; + unsigned char sec; + signed char offsetgmt; // In 15 min intervals, from -48 to +52 #ifdef _WIN32 - }; - #else - -} __attribute__ ((packed)); - +} __attribute__((packed)); #endif /* _WIN32 */ +struct ECMA119DirectoryRecord +{ + unsigned char reclen; // Length of this record + unsigned char attlen; // Extended Attribute Record Length + unsigned long externlocle; // Location of Extent + unsigned long externlocbe; + struct ECMA119DateTime recorded; // Recording Date and Time + unsigned char flags; // File Flags + unsigned char interleave; // Interleave Gap Size -struct ECMA119DirectoryRecord { - - unsigned char reclen; // Length of this record - - unsigned char attlen; // Extended Attribute Record Length - - - - unsigned long externlocle; // Location of Extent - - unsigned long externlocbe; - - - - struct ECMA119DateTime recorded; // Recording Date and Time - - - - unsigned char flags; // File Flags - - unsigned char interleave; // Interleave Gap Size - - - - unsigned short seqnole; // Volume Sequence No. - - unsigned short seqnobe; - - - - unsigned short idlen; - - char id[223]; - - // Note: sometimes a OS uses the end of this record for it's own use. - + unsigned short seqnole; // Volume Sequence No. + unsigned short seqnobe; + unsigned short idlen; + char id[223]; + // Note: sometimes a OS uses the end of this record for it's own use. #ifdef _WIN32 - }; - #else - -} __attribute__ ((packed)); - +} __attribute__((packed)); #endif /* _WIN32 */ +struct ECMA119RootDirectoryRecord +{ + unsigned char reclen; // Length of this record + unsigned char attlen; // Extended Attribute Record Length + unsigned long externlocle; // Location of Extent + unsigned long externlocbe; + struct ECMA119DateTime recorded; // Recording Date and Time + unsigned char flags; // File Flags + unsigned char interleave; // Interleave Gap Size -struct ECMA119RootDirectoryRecord { - - unsigned char reclen; // Length of this record - - unsigned char attlen; // Extended Attribute Record Length - - - - unsigned long externlocle; // Location of Extent - - unsigned long externlocbe; - - - - struct ECMA119DateTime recorded; // Recording Date and Time - - - - unsigned char flags; // File Flags - - unsigned char interleave; // Interleave Gap Size - - - - unsigned short seqnole; // Volume Sequence No. - - unsigned short seqnobe; - - - - unsigned short idlen; - - char id[1]; // Probably for the '.' (But I'm just guessing :) - + unsigned short seqnole; // Volume Sequence No. + unsigned short seqnobe; + unsigned short idlen; + char id[1]; // Probably for the '.' (But I'm just guessing :) #ifdef _WIN32 - }; - #else - -} __attribute__ ((packed)); - +} __attribute__((packed)); #endif /* _WIN32 */ +struct ECMA119VolumeID +{ + unsigned char voltype; + // 0 = Boot Record + // 1 = Primary Volume Descriptor (PrimaryVolume below) + // 2 = Supplementary Volume Descriptor + // 3 = Partition Descriptor (PartitionVolume below) + // 4 - 254 Reserved + // 255 = End-of-Descriptor-Set + char stdid[5]; // Standard Identifier. Always "CD001" - -struct ECMA119VolumeID { - - unsigned char voltype; - - // 0 = Boot Record - - // 1 = Primary Volume Descriptor (PrimaryVolume below) - - // 2 = Supplementary Volume Descriptor - - // 3 = Partition Descriptor (PartitionVolume below) - - // 4 - 254 Reserved - - // 255 = End-of-Descriptor-Set - - - - char stdid[5]; // Standard Identifier. Always "CD001" - - - - unsigned char version; - + unsigned char version; #ifdef _WIN32 - }; - #else - -} __attribute__ ((packed)); - +} __attribute__((packed)); #endif /* _WIN32 */ +struct ECMA119PrimaryVolume +{ + struct ECMA119VolumeID id; + // id.voltype should be 1 (for this type of volume) + // id.version should be 1 (standard) + char unused1; + char systemid[32]; + char volumeid[32]; + char unused2[8]; + unsigned long numblocksle; // Total logical blocks. (on Media? or just + unsigned long numblocksbe; // in volume?) -struct ECMA119PrimaryVolume { + char unused3[32]; - struct ECMA119VolumeID id; + unsigned short volumesetsizele; // Volume Set size of the volume. (?) + unsigned short volumesetsizebe; + unsigned short ordinalle; // Count of which descriptor this is in the Volume + unsigned short ordinalbe; // set. - // id.voltype should be 1 (for this type of volume) + unsigned short blocksizele; // Size of a Logical Block + unsigned short blocksizebe; + unsigned long pathtablesizele; // Path Table Size + unsigned long pathtablesizebe; - // id.version should be 1 (standard) + unsigned long typelpathtablelocation; // (le) Location of a Type L Path Table + unsigned long typelopttablelocation; // (le) Location of an Optional Type L + unsigned long typempathtablelocation; // (be) Location of a Type M Path Table - char unused1; + unsigned long typemopttablelocation; // (be) Location of an Optional Type M + struct ECMA119RootDirectoryRecord root; + char volumesetid[128]; // Volume Set ID - char systemid[32]; + char publisher[128]; // Publisher - char volumeid[32]; + char datapreparer[128]; // Data Preparer + char application[128]; // Application ID + char copyrightfile[37]; // Copyright File Identifier - char unused2[8]; + char abstractfile[37]; // Abstract File Identifier + char bibliograchicfile[37]; // Bibliographic File Identifier + struct ECMA119ASCIITime volcreatedate; // Date Created + struct ECMA119ASCIITime volmodifydate; // Last Date Modified + struct ECMA119ASCIITime volexpiredate; // Date data expires + struct ECMA119ASCIITime voleffectivedata; // Date data becomes accurate (effective) + unsigned char filestructversion; // File Structure Version + // Should be 1 = Standard - unsigned long numblocksle; // Total logical blocks. (on Media? or just + char unused4; - unsigned long numblocksbe; // in volume?) - - - - char unused3[32]; - - - - unsigned short volumesetsizele; // Volume Set size of the volume. (?) - - unsigned short volumesetsizebe; - - - - unsigned short ordinalle; // Count of which descriptor this is in the Volume - - unsigned short ordinalbe; // set. - - - - unsigned short blocksizele; // Size of a Logical Block - - unsigned short blocksizebe; - - - - unsigned long pathtablesizele; // Path Table Size - - unsigned long pathtablesizebe; - - - - unsigned long typelpathtablelocation; // (le) Location of a Type L Path Table - - - - unsigned long typelopttablelocation; // (le) Location of an Optional Type L - - - - unsigned long typempathtablelocation; // (be) Location of a Type M Path Table - - - - unsigned long typemopttablelocation; // (be) Location of an Optional Type M - - - - struct ECMA119RootDirectoryRecord root; - - - - char volumesetid[128]; // Volume Set ID - - - - char publisher[128]; // Publisher - - - - char datapreparer[128]; // Data Preparer - - - - char application[128]; // Application ID - - - - char copyrightfile[37]; // Copyright File Identifier - - - - char abstractfile[37]; // Abstract File Identifier - - - - char bibliograchicfile[37]; // Bibliographic File Identifier - - - - struct ECMA119ASCIITime volcreatedate; // Date Created - - struct ECMA119ASCIITime volmodifydate; // Last Date Modified - - struct ECMA119ASCIITime volexpiredate; // Date data expires - - struct ECMA119ASCIITime voleffectivedata; // Date data becomes accurate (effective) - - - - unsigned char filestructversion; // File Structure Version - - // Should be 1 = Standard - - - - char unused4; - - - - char applicationuse[512]; // For use by an application - - - - char unused5[653]; // Rounds this out to 2048 bytes... + char applicationuse[512]; // For use by an application + char unused5[653]; // Rounds this out to 2048 bytes... #ifdef _WIN32 - }; - #else - -} __attribute__ ((packed)); - +} __attribute__((packed)); #endif /* _WIN32 */ - - - // struct ECMA119PartitionVolume { - // struct ECMA119VolumeID id; - // #ifdef _WIN32 - // }; - // #else - // } __attribute__ ((packed)); - // #endif /* _WIN32 */ - - - #ifdef _WIN32 - #pragma pack() - #endif /* _WIN32 */ - - - - extern int ValidateECMA119PrimaryVolume(struct ECMA119PrimaryVolume *volume); - // extern int ValidateECMA119PartitionVolume(struct ECMA119PartitionVolume volume); - - - - #endif /* ECMA119_H */ - diff --git a/plugins/CDVDisoEFP/src/gzipv1.c b/plugins/CDVDisoEFP/src/gzipv1.c index 9c8d438525..92ccea73ec 100644 --- a/plugins/CDVDisoEFP/src/gzipv1.c +++ b/plugins/CDVDisoEFP/src/gzipv1.c @@ -1,844 +1,410 @@ /* gzipv1.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include // NULL - - #include "zlib/zlib.h" - - #include "convert.h" - #include "logfile.h" - #include "isofile.h" - #include "isocompress.h" // TableData - #include "actualfile.h" - #include "gzipv1.h" - - - - #ifdef _WIN32 - #pragma pack(1) - #endif /* _WIN32 */ - - -struct GZipV1Table { - - unsigned int offset; // Data file position - - unsigned short size; // of Compressed data - +struct GZipV1Table +{ + unsigned int offset; // Data file position + unsigned short size; // of Compressed data #ifdef _WIN32 - }; - #else - -} __attribute__ ((packed)); - +} __attribute__((packed)); #endif /* _WIN32 */ - - - #ifdef _WIN32 - #pragma pack() - #endif /* _WIN32 */ - - - - -int GZipV1OpenTableForRead(struct IsoFile *isofile) { - - int i; - - int j; - - char tableext[] = ".table\0"; - - - +int GZipV1OpenTableForRead(struct IsoFile *isofile) +{ + int i; + int j; + char tableext[] = ".table\0"; #ifdef VERBOSE_FUNCTION_GZIPV1 - - PrintLog("CDVDiso GZipV1: OpenTableForRead()"); - + PrintLog("CDVDiso GZipV1: OpenTableForRead()"); #endif /* VERBOSE_FUNCTION_GZIPV1 */ + i = 0; + while ((i < 256) && (isofile->name[i] != 0)) + { + isofile->tablename[i] = isofile->name[i]; + i++; + } // ENDWHILE- Copying the data name to the table name + j = 0; + while ((i < 256) && (tableext[j] != 0)) + { + isofile->tablename[i] = tableext[j]; + i++; + j++; + } // ENDWHILE- Adding the ".table" extension. + isofile->tablename[i] = 0; // And 0-terminate. - - - i = 0; - - while((i < 256) && (isofile->name[i] != 0)) { - - isofile->tablename[i] = isofile->name[i]; - - i++; - - } // ENDWHILE- Copying the data name to the table name - - j = 0; - - while((i < 256) && (tableext[j] != 0)) { - - isofile->tablename[i] = tableext[j]; - - i++; - - j++; - - } // ENDWHILE- Adding the ".table" extension. - - isofile->tablename[i] = 0; // And 0-terminate. - - - - isofile->tablehandle = ActualFileOpenForRead(isofile->tablename); - - if(isofile->tablehandle == ACTUALHANDLENULL) { - + isofile->tablehandle = ActualFileOpenForRead(isofile->tablename); + if (isofile->tablehandle == ACTUALHANDLENULL) + { #ifdef VERBOSE_WARNING_GZIPV1 - - PrintLog("CDVDiso GZipV1: Couldn't open table!"); - + PrintLog("CDVDiso GZipV1: Couldn't open table!"); #endif /* VERBOSE_WARNING_GZIPV1 */ + return(-2); + } // ENDIF- Couldn't open table file? Fail. - return(-2); - - } // ENDIF- Couldn't open table file? Fail. - - - - isofile->filesectorsize = ActualFileSize(isofile->tablehandle) - - / sizeof(struct GZipV1Table); - - - - return(0); - + isofile->filesectorsize = ActualFileSize(isofile->tablehandle) + / sizeof(struct GZipV1Table); + return(0); } // END GZipV1OpenTableForRead() - - - - -int GZipV1SeekTable(struct IsoFile *isofile, off64_t sector) { - - off64_t target; - - int retval; - - - +int GZipV1SeekTable(struct IsoFile *isofile, off64_t sector) +{ + off64_t target; + int retval; #ifdef VERBOSE_FUNCTION_GZIPV1 - - PrintLog("CDVDiso GZipV1: SeekTable(%lli)", sector); - + PrintLog("CDVDiso GZipV1: SeekTable(%lli)", sector); #endif /* VERBOSE_FUNCTION_GZIPV1 */ - - - - target = sector * sizeof(struct GZipV1Table); - - retval = ActualFileSeek(isofile->tablehandle, target); - - if(retval < 0) { - + target = sector * sizeof(struct GZipV1Table); + retval = ActualFileSeek(isofile->tablehandle, target); + if (retval < 0) + { #ifdef VERBOSE_WARNING_GZIPV1 - - PrintLog("CDVDiso GZipV1: Couldn't find sector!"); - + PrintLog("CDVDiso GZipV1: Couldn't find sector!"); #endif /* VERBOSE_WARNING_GZIPV1 */ + return(-2); + } // ENDIF- Trouble finding the place? Fail. - return(-2); - - } // ENDIF- Trouble finding the place? Fail. - - - - isofile->filesectorpos = sector; - - return(0); - + isofile->filesectorpos = sector; + return(0); } // END GZipV1SeekTable() - - - - -int GZipV1ReadTable(struct IsoFile *isofile, struct TableData *table) { - - int retval; - - struct GZipV1Table temptable; - - - +int GZipV1ReadTable(struct IsoFile *isofile, struct TableData *table) +{ + int retval; + struct GZipV1Table temptable; #ifdef VERBOSE_FUNCTION_GZIPV1 - - PrintLog("CDVDiso GZipV1: ReadTable()"); - + PrintLog("CDVDiso GZipV1: ReadTable()"); #endif /* VERBOSE_FUNCTION_GZIPV1 */ - - - - retval = ActualFileRead(isofile->tablehandle, - - sizeof(struct GZipV1Table), - - (char *) &temptable); - - if(retval != sizeof(struct GZipV1Table)) { - + retval = ActualFileRead(isofile->tablehandle, + sizeof(struct GZipV1Table), + (char *) & temptable); + if (retval != sizeof(struct GZipV1Table)) + { #ifdef VERBOSE_WARNING_GZIPV1 - - PrintLog("CDVDiso GZipV1: Couldn't read table entry!"); - + PrintLog("CDVDiso GZipV1: Couldn't read table entry!"); #endif /* VERBOSE_WARNING_GZIPV1 */ - - return(-2); - - } // ENDIF- Trouble reading table entry? Fail. - - - - table->offset = ConvertEndianUInt(temptable.offset); - - table->size = ConvertEndianUShort(temptable.size); - - isofile->filesectorpos++; - - return(0); - + return(-2); + } // ENDIF- Trouble reading table entry? Fail. + table->offset = ConvertEndianUInt(temptable.offset); + table->size = ConvertEndianUShort(temptable.size); + isofile->filesectorpos++; + return(0); } // END GZipV1ReadTable() - - - - -int GZipV1OpenTableForWrite(struct IsoFile *isofile) { - - int i; - - int j; - - char tableext[] = ".table\0"; - - - +int GZipV1OpenTableForWrite(struct IsoFile *isofile) +{ + int i; + int j; + char tableext[] = ".table\0"; #ifdef VERBOSE_FUNCTION_GZIPV1 - - PrintLog("CDVDiso GZipV1: OpenTableForWrite()"); - + PrintLog("CDVDiso GZipV1: OpenTableForWrite()"); #endif /* VERBOSE_FUNCTION_GZIPV1 */ + i = 0; + while ((i < 256) && (isofile->name[i] != 0)) + { + isofile->tablename[i] = isofile->name[i]; + i++; + } // ENDWHILE- Copying the data name to the table name + j = 0; + while ((i < 256) && (tableext[j] != 0)) + { + isofile->tablename[i] = tableext[j]; + i++; + j++; + } // ENDWHILE- Adding the ".table" extension. + isofile->tablename[i] = 0; // And 0-terminate. - - - i = 0; - - while((i < 256) && (isofile->name[i] != 0)) { - - isofile->tablename[i] = isofile->name[i]; - - i++; - - } // ENDWHILE- Copying the data name to the table name - - j = 0; - - while((i < 256) && (tableext[j] != 0)) { - - isofile->tablename[i] = tableext[j]; - - i++; - - j++; - - } // ENDWHILE- Adding the ".table" extension. - - isofile->tablename[i] = 0; // And 0-terminate. - - - - isofile->tablehandle = ActualFileOpenForWrite(isofile->tablename); - - if(isofile->tablehandle == ACTUALHANDLENULL) { - + isofile->tablehandle = ActualFileOpenForWrite(isofile->tablename); + if (isofile->tablehandle == ACTUALHANDLENULL) + { #ifdef VERBOSE_WARNING_GZIPV1 - - PrintLog("CDVDiso GZipV1: Couldn't open table!"); - + PrintLog("CDVDiso GZipV1: Couldn't open table!"); #endif /* VERBOSE_WARNING_GZIPV1 */ + return(-2); + } // ENDIF- Couldn't open table file? Fail. - return(-2); - - } // ENDIF- Couldn't open table file? Fail. - - - - isofile->filesectorsize = 0; - - return(0); - + isofile->filesectorsize = 0; + return(0); } // END GZipV1OpenTableForWrite() - - - - -int GZipV1WriteTable(struct IsoFile *isofile, struct TableData table) { - - int retval; - - struct GZipV1Table temptable; - - unsigned int tempint; - - +int GZipV1WriteTable(struct IsoFile *isofile, struct TableData table) +{ + int retval; + struct GZipV1Table temptable; + unsigned int tempint; #ifdef VERBOSE_FUNCTION_GZIPV1 - - PrintLog("CDVDiso GZipV1: WriteTable(%lli, %i)", table.offset, table.size); - + PrintLog("CDVDiso GZipV1: WriteTable(%lli, %i)", table.offset, table.size); #endif /* VERBOSE_FUNCTION_GZIPV1 */ - - - tempint = table.offset; - - temptable.offset = ConvertEndianUInt(tempint); - - temptable.size = ConvertEndianUShort(table.size); - - retval = ActualFileWrite(isofile->tablehandle, - - sizeof(struct GZipV1Table), - - (char *) &temptable); - - if(retval != sizeof(struct GZipV1Table)) { - + tempint = table.offset; + temptable.offset = ConvertEndianUInt(tempint); + temptable.size = ConvertEndianUShort(table.size); + retval = ActualFileWrite(isofile->tablehandle, + sizeof(struct GZipV1Table), + (char *) & temptable); + if (retval != sizeof(struct GZipV1Table)) + { #ifdef VERBOSE_WARNING_GZIPV1 - - PrintLog("CDVDiso GZipV1: Couldn't write table entry!"); - + PrintLog("CDVDiso GZipV1: Couldn't write table entry!"); #endif /* VERBOSE_WARNING_GZIPV1 */ - - return(-2); - - } // ENDIF- Trouble reading table entry? Fail. - - - - return(0); - + return(-2); + } // ENDIF- Trouble reading table entry? Fail. + return(0); } // END GZipV1WriteTable() - - - - -int GZipV1OpenForRead(struct IsoFile *isofile) { - - int retval; - - char tempblock[2448]; - - - +int GZipV1OpenForRead(struct IsoFile *isofile) +{ + int retval; + char tempblock[2448]; #ifdef VERBOSE_FUNCTION_GZIPV1 - - PrintLog("CDVDiso GZipV1: OpenForRead()"); - + PrintLog("CDVDiso GZipV1: OpenForRead()"); #endif /* VERBOSE_FUNCTION_GZIPV1 */ + isofile->handle = ActualFileOpenForRead(isofile->name); + if (isofile->handle == ACTUALHANDLENULL) + { + return(-1); + } // ENDIF- Couldn't open data file? Fail. + isofile->filebytesize = ActualFileSize(isofile->handle); + isofile->filebytepos = 0; + isofile->filesectorpos = 0; - - isofile->handle = ActualFileOpenForRead(isofile->name); - - if(isofile->handle == ACTUALHANDLENULL) { - - return(-1); - - } // ENDIF- Couldn't open data file? Fail. - - - - isofile->filebytesize = ActualFileSize(isofile->handle); - - isofile->filebytepos = 0; - - isofile->filesectorpos = 0; - - - - isofile->imageheader = 0; - - isofile->blocksize = 2352; - - isofile->blockoffset = 0; // Don't panic. "imagetype.c" will test later. - - isofile->numsectors = 1; // Sectors per block - - - - retval = GZipV1Read(isofile, 2448, tempblock); - - if(retval != 0) { - + isofile->imageheader = 0; + isofile->blocksize = 2352; + isofile->blockoffset = 0; // Don't panic. "imagetype.c" will test later. + isofile->numsectors = 1; // Sectors per block + retval = GZipV1Read(isofile, 2448, tempblock); + if (retval != 0) + { #ifdef VERBOSE_WARNING_GZIPV1 - - PrintLog("CDVDiso GZipV1: Couldn't decode the first block. Not compressed?"); - + PrintLog("CDVDiso GZipV1: Couldn't decode the first block. Not compressed?"); #endif /* VERBOSE_WARNING_GZIPV1 */ - - ActualFileClose(isofile->handle); - - isofile->handle = ACTUALHANDLENULL; - - return(-1); - - } // ENDIF Could not read the first sector? Fail. - - - - ActualFileSeek(isofile->handle, 0); // Restart at top of file - - isofile->filebytepos = 0; - - isofile->filesectorpos = 0; - - return(0); - + ActualFileClose(isofile->handle); + isofile->handle = ACTUALHANDLENULL; + return(-1); + } // ENDIF Could not read the first sector? Fail. + ActualFileSeek(isofile->handle, 0); // Restart at top of file + isofile->filebytepos = 0; + isofile->filesectorpos = 0; + return(0); } // END GZipV1OpenForRead() - - - - -int GZipV1Seek(struct IsoFile *isofile, off64_t position) { - - int retval; - - - +int GZipV1Seek(struct IsoFile *isofile, off64_t position) +{ + int retval; #ifdef VERBOSE_FUNCTION_GZIPV1 - - PrintLog("CDVDiso GZipV1: Seek(%lli)", position); - + PrintLog("CDVDiso GZipV1: Seek(%lli)", position); #endif /* VERBOSE_FUNCTION_GZIPV1 */ - - - - retval = ActualFileSeek(isofile->handle, position); - - if(retval < 0) { - + retval = ActualFileSeek(isofile->handle, position); + if (retval < 0) + { #ifdef VERBOSE_WARNING_GZIPV1 - - PrintLog("CDVDiso GZipV1: Couldn't find the start of the compressed block!"); - + PrintLog("CDVDiso GZipV1: Couldn't find the start of the compressed block!"); #endif /* VERBOSE_WARNING_GZIPV1 */ - - return(-1); - - } // ENDIF- Couldn't find the data entry? Fail. - - isofile->filebytepos = position; - - return(0); - - - - return(-1); // Fail. (Due to lack of ambition?) - + return(-1); + } // ENDIF- Couldn't find the data entry? Fail. + isofile->filebytepos = position; + return(0); + return(-1); // Fail. (Due to lack of ambition?) } // END GZipV1Seek() - - - - -int GZipV1Read(struct IsoFile *isofile, int bytes, char *buffer) { - - int retval; - - unsigned long blocklen; - - z_stream strm; - - unsigned long tempin; - - char tempblock[2800]; - - unsigned long tempout; - - - +int GZipV1Read(struct IsoFile *isofile, int bytes, char *buffer) +{ + int retval; + unsigned long blocklen; + z_stream strm; + unsigned long tempin; + char tempblock[2800]; + unsigned long tempout; #ifdef VERBOSE_FUNCTION_GZIPV1 - - PrintLog("CDVDiso GZipV1: Read(%i)", bytes); - + PrintLog("CDVDiso GZipV1: Read(%i)", bytes); #endif /* VERBOSE_FUNCTION_GZIPV1 */ - - - - if(bytes > 0) { - - retval = ActualFileRead(isofile->handle, bytes, tempblock); - - if(retval > 0) isofile->filebytepos += retval; - - if(retval != bytes) { - + if (bytes > 0) + { + retval = ActualFileRead(isofile->handle, bytes, tempblock); + if (retval > 0) isofile->filebytepos += retval; + if (retval != bytes) + { #ifdef VERBOSE_WARNING_GZIPV1 - - PrintLog("CDVDiso GZipV1: Cannot read bytes! Returned: (%i)", retval); - + PrintLog("CDVDiso GZipV1: Cannot read bytes! Returned: (%i)", retval); #endif /* VERBOSE_WARNING_GZIPV1 */ - - return(-1); - - } // ENDIF- Trouble reading compressed sector? Abort. - - - - blocklen = isofile->blocksize; - - retval = uncompress(buffer, &blocklen, tempblock, bytes); - - if(retval != Z_OK) { - + return(-1); + } // ENDIF- Trouble reading compressed sector? Abort. + blocklen = isofile->blocksize; + retval = uncompress(buffer, &blocklen, tempblock, bytes); + if (retval != Z_OK) + { #ifdef VERBOSE_WARNING_GZIPV1 - - PrintLog("CDVDiso GZipV1: Cannot decode block! Returned: (%i)", retval); - + PrintLog("CDVDiso GZipV1: Cannot decode block! Returned: (%i)", retval); #endif /* VERBOSE_WARNING_GZIPV1 */ + return(-1); + } // ENDIF- Trouble decoding the sector? Abort. - return(-1); + return(0); + } // ENDIF- Do we know how many compressed bytes to get for this record? + // Hmm. Don't know the compressed size? Well, we'll just have to find it. + tempin = 0; + tempout = 0; + retval = Z_OK; + while ((tempin < 2800) && (tempout < 2352)) + { - } // ENDIF- Trouble decoding the sector? Abort. + strm.zalloc = (alloc_func)0; + strm.zfree = (free_func)0; + strm.next_in = tempblock; + strm.next_out = buffer; + strm.avail_in = tempin; + strm.avail_out = 2800; + retval = inflateInit(&strm); + if (retval != Z_OK) return(-1); - - return(0); - - } // ENDIF- Do we know how many compressed bytes to get for this record? - - - - // Hmm. Don't know the compressed size? Well, we'll just have to find it. - - - - tempin = 0; - - tempout = 0; - - retval = Z_OK; - - while((tempin < 2800) && (tempout < 2352)) { - - - - strm.zalloc = (alloc_func)0; - - strm.zfree = (free_func)0; - - - - strm.next_in = tempblock; - - strm.next_out = buffer; - - - - strm.avail_in = tempin; - - strm.avail_out = 2800; - - - - retval = inflateInit(&strm); - - if (retval != Z_OK) return(-1); - - - - while((tempin < 2800) && (retval == Z_OK)) { - - retval = ActualFileRead(isofile->handle, 1, &tempblock[tempin]); - - if(retval != 1) { - + while ((tempin < 2800) && (retval == Z_OK)) + { + retval = ActualFileRead(isofile->handle, 1, &tempblock[tempin]); + if (retval != 1) + { #ifdef VERBOSE_WARNING_GZIPV1 - - PrintLog("CDVDiso GZipV1: Cannot read a byte! Returned: (%i)", retval); - + PrintLog("CDVDiso GZipV1: Cannot read a byte! Returned: (%i)", retval); #endif /* VERBOSE_WARNING_GZIPV1 */ - - return(-1); - - } // ENDIF- Trouble reading compressed sector? Abort. - - tempin++; - - strm.avail_in++; - - - - strm.next_in = &tempblock[tempin - strm.avail_in]; - - retval = inflate(&strm, Z_NO_FLUSH); - - } // ENDWHILE- trying to uncompress an increasingly filled buffer - - tempout = strm.total_out; - - inflateEnd(&strm); - + return(-1); + } // ENDIF- Trouble reading compressed sector? Abort. + tempin++; + strm.avail_in++; + strm.next_in = &tempblock[tempin - strm.avail_in]; + retval = inflate(&strm, Z_NO_FLUSH); + } // ENDWHILE- trying to uncompress an increasingly filled buffer + tempout = strm.total_out; + inflateEnd(&strm); #ifdef VERBOSE_FUNCTION_GZIPV1 - - PrintLog("CDVDiso GZipV1: tempin=%lu tempout=%lu retval=%i", - - tempin, tempout, retval); - + PrintLog("CDVDiso GZipV1: tempin=%lu tempout=%lu retval=%i", + tempin, tempout, retval); #endif /* VERBOSE_FUNCTION_GZIPV1 */ - - - - } // ENDWHILE- trying to uncompress a whole buffer - - if(retval != Z_STREAM_END) { - + } // ENDWHILE- trying to uncompress a whole buffer + if (retval != Z_STREAM_END) + { #ifdef VERBOSE_WARNING_GZIPV1 - - PrintLog("CDVDiso GZipV1: Failed to decode block! Returned: (%i)", retval); - + PrintLog("CDVDiso GZipV1: Failed to decode block! Returned: (%i)", retval); #endif /* VERBOSE_WARNING_GZIPV1 */ - - return(-1); - - } // ENDIF- Trouble reading compressed sector? Abort. - - - - if(tempin == 2800) { - + return(-1); + } // ENDIF- Trouble reading compressed sector? Abort. + if (tempin == 2800) + { #ifdef VERBOSE_WARNING_GZIPV1 - - PrintLog("CDVDiso GZipV1: Overfilled input buffer for only %llu bytes!", tempout); - + PrintLog("CDVDiso GZipV1: Overfilled input buffer for only %llu bytes!", tempout); #endif /* VERBOSE_WARNING_GZIPV1 */ - - return(-1); - - } // ENDIF- Trouble reading compressed sector? Abort. - - isofile->filebytepos += tempin; - - return(tempin); // Send out # of compressed bytes (to record in table) - + return(-1); + } // ENDIF- Trouble reading compressed sector? Abort. + isofile->filebytepos += tempin; + return(tempin); // Send out # of compressed bytes (to record in table) } // END GZipV1Read() - - - - -int GZipV1OpenForWrite(struct IsoFile *isofile) { - - if(isofile == NULL) return(-1); - - - +int GZipV1OpenForWrite(struct IsoFile *isofile) +{ + if (isofile == NULL) return(-1); #ifdef VERBOSE_FUNCTION_GZIPV1 - - PrintLog("CDVDiso GZipV1: OpenForWrite()"); - + PrintLog("CDVDiso GZipV1: OpenForWrite()"); #endif /* VERBOSE_FUNCTION_GZIPV1 */ + isofile->handle = ActualFileOpenForWrite(isofile->name); + if (isofile->handle == ACTUALHANDLENULL) + { + return(-1); + } // ENDIF- Couldn't open data file? Fail. - - - isofile->handle = ActualFileOpenForWrite(isofile->name); - - if(isofile->handle == ACTUALHANDLENULL) { - - return(-1); - - } // ENDIF- Couldn't open data file? Fail. - - - - isofile->filebytesize = 0; - - isofile->filebytepos = 0; - - return(0); - + isofile->filebytesize = 0; + isofile->filebytepos = 0; + return(0); } // END GZipV1OpenForWrite() - - - - -int GZipV1Write(struct IsoFile *isofile, char *buffer) { - - int retval; - - unsigned long blocklen; - - char tempblock[2800]; - - - +int GZipV1Write(struct IsoFile *isofile, char *buffer) +{ + int retval; + unsigned long blocklen; + char tempblock[2800]; #ifdef VERBOSE_FUNCTION_GZIPV1 - - PrintLog("CDVDiso GZipV1: Write()"); - + PrintLog("CDVDiso GZipV1: Write()"); #endif /* VERBOSE_FUNCTION_GZIPV1 */ - - - - blocklen = 2800; - - retval = compress2(tempblock, &blocklen, - - buffer, 2352, - - Z_BEST_COMPRESSION); - - if(retval != Z_OK) { - + blocklen = 2800; + retval = compress2(tempblock, &blocklen, + buffer, 2352, + Z_BEST_COMPRESSION); + if (retval != Z_OK) + { #ifdef VERBOSE_FUNCTION_GZIPV1 - - PrintLog("CDVDiso GZipV1: Cannot encode block! Returned: (%i)", retval); - + PrintLog("CDVDiso GZipV1: Cannot encode block! Returned: (%i)", retval); #endif /* VERBOSE_FUNCTION_GZIPV1 */ + return(-1); + } // ENDIF- Trouble compressing a block? Abort. - return(-1); - - } // ENDIF- Trouble compressing a block? Abort. - - - - retval = ActualFileWrite(isofile->handle, blocklen, tempblock); - - if(retval > 0) isofile->filebytepos += retval; - - if(retval < blocklen) { - + retval = ActualFileWrite(isofile->handle, blocklen, tempblock); + if (retval > 0) isofile->filebytepos += retval; + if (retval < blocklen) + { #ifdef VERBOSE_FUNCTION_GZIPV1 - - PrintLog("CDVDiso GZipV1: Cannot write bytes! Returned: (%i out of %llu)", - - retval, blocklen); - + PrintLog("CDVDiso GZipV1: Cannot write bytes! Returned: (%i out of %llu)", + retval, blocklen); #endif /* VERBOSE_FUNCTION_GZIPV1 */ - - return(-1); - - } // ENDIF- Trouble writing out the compressed block? Abort. - - isofile->filesectorpos++; - - - - return(blocklen); - + return(-1); + } // ENDIF- Trouble writing out the compressed block? Abort. + isofile->filesectorpos++; + return(blocklen); } // END GZipV1Write() - - - - -void GZipV1Close(struct IsoFile *isofile) { - +void GZipV1Close(struct IsoFile *isofile) +{ #ifdef VERBOSE_FUNCTION_GZIPV1 - - PrintLog("CDVDiso GZipV1: Close()"); - + PrintLog("CDVDiso GZipV1: Close()"); #endif /* VERBOSE_FUNCTION_GZIPV1 */ + // Flush Write data... if any was held in the compression block area. + // In this case, though... nothing's held there. + if (isofile->tablehandle != ACTUALHANDLENULL) + { + ActualFileClose(isofile->tablehandle); + isofile->tablehandle = ACTUALHANDLENULL; + } // ENDIF- Is there a table file open? Close it. - - // Flush Write data... if any was held in the compression block area. - - // In this case, though... nothing's held there. - - - - if(isofile->tablehandle != ACTUALHANDLENULL) { - - ActualFileClose(isofile->tablehandle); - - isofile->tablehandle = ACTUALHANDLENULL; - - } // ENDIF- Is there a table file open? Close it. - - - - if(isofile->handle != ACTUALHANDLENULL) { - - ActualFileClose(isofile->handle); - - isofile->handle = ACTUALHANDLENULL; - - } // ENDIF- Is there a data file open? Close it. - - - - return; - + if (isofile->handle != ACTUALHANDLENULL) + { + ActualFileClose(isofile->handle); + isofile->handle = ACTUALHANDLENULL; + } // ENDIF- Is there a data file open? Close it. + return; } // END GZipV1Close() - diff --git a/plugins/CDVDisoEFP/src/gzipv1.h b/plugins/CDVDisoEFP/src/gzipv1.h index 7127cc2e91..3bd9e99618 100644 --- a/plugins/CDVDisoEFP/src/gzipv1.h +++ b/plugins/CDVDisoEFP/src/gzipv1.h @@ -1,104 +1,46 @@ /* gzipv1.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef GZIPV1_H - #define GZIPV1_H - - - - #include - - #include "isofile.h" - #include "isocompress.h" - - - - // #define VERBOSE_FUNCTION_GZIPV1 - // #define VERBOSE_WARNING_GZIPV1 - - - - extern int GZipV1OpenTableForRead(struct IsoFile *isofile); - extern int GZipV1SeekTable(struct IsoFile *isofile, off64_t sector); - extern int GZipV1ReadTable(struct IsoFile *isofile, struct TableData *table); - - extern int GZipV1OpenTableForWrite(struct IsoFile *isofile); - extern int GZipV1WriteTable(struct IsoFile *isofile, struct TableData table); - - - extern int GZipV1OpenForRead(struct IsoFile *isofile); - extern int GZipV1Seek(struct IsoFile *isofile, off64_t sector); - extern int GZipV1Read(struct IsoFile *isofile, int bytes, char *buffer); - extern void GZipV1Close(struct IsoFile *isofile); - - extern int GZipV1OpenForWrite(struct IsoFile *isofile); - extern int GZipV1Write(struct IsoFile *isofile, char *buffer); - - - - #endif /* GZIPV1_H */ - diff --git a/plugins/CDVDisoEFP/src/gzipv2.c b/plugins/CDVDisoEFP/src/gzipv2.c index 548050c5f6..91e000db38 100644 --- a/plugins/CDVDisoEFP/src/gzipv2.c +++ b/plugins/CDVDisoEFP/src/gzipv2.c @@ -1,980 +1,489 @@ /* gzipv2.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include // NULL - #include // malloc() - #include // off64_t - - #include "zlib/zlib.h" - - #include "convert.h" - #include "logfile.h" - #include "isofile.h" // IsoFile - #include "isocompress.h" // TableData, TableMap - #include "actualfile.h" - #include "gzipv2.h" - - - - #ifdef _WIN32 - #pragma pack(1) - #endif /* _WIN32 */ - - -struct GZipV2Header { - - char id[4]; - - unsigned int blocksize; - - unsigned int numblocks; - - unsigned int blockoffset; - +struct GZipV2Header +{ + char id[4]; + unsigned int blocksize; + unsigned int numblocks; + unsigned int blockoffset; #ifdef _WIN32 - }; - #else - -} __attribute__ ((packed)); - +} __attribute__((packed)); #endif /* _WIN32 */ - - - -struct GZipV2Table { - - unsigned int size; - +struct GZipV2Table +{ + unsigned int size; #ifdef _WIN32 - }; - #else - -} __attribute__ ((packed)); - +} __attribute__((packed)); #endif /* _WIN32 */ - - - #ifdef _WIN32 - #pragma pack() - #endif /* _WIN32 */ - - - - -int GZipV2OpenTableForRead(struct IsoFile *isofile) { - - int i; - - int j; - - char tableext[] = ".table\0"; - - off64_t offset; - - off64_t actual; - - int tableoffset; - - struct GZipV2Table table; - - int retval; - - union TableMap tablemap; - - - +int GZipV2OpenTableForRead(struct IsoFile *isofile) +{ + int i; + int j; + char tableext[] = ".table\0"; + off64_t offset; + off64_t actual; + int tableoffset; + struct GZipV2Table table; + int retval; + union TableMap tablemap; #ifdef VERBOSE_FUNCTION_GZIPV2 - - PrintLog("CDVDiso GZipV2: OpenTableForRead()"); - + PrintLog("CDVDiso GZipV2: OpenTableForRead()"); #endif /* VERBOSE_FUNCTION_GZIPV2 */ + i = 0; + while ((i < 256) && (isofile->name[i] != 0)) + { + isofile->tablename[i] = isofile->name[i]; + i++; + } // ENDWHILE- Copying the data name to the table name + j = 0; + while ((i < 256) && (tableext[j] != 0)) + { + isofile->tablename[i] = tableext[j]; + i++; + j++; + } // ENDWHILE- Adding the ".table" extension. + isofile->tablename[i] = 0; // And 0-terminate. - - - i = 0; - - while((i < 256) && (isofile->name[i] != 0)) { - - isofile->tablename[i] = isofile->name[i]; - - i++; - - } // ENDWHILE- Copying the data name to the table name - - j = 0; - - while((i < 256) && (tableext[j] != 0)) { - - isofile->tablename[i] = tableext[j]; - - i++; - - j++; - - } // ENDWHILE- Adding the ".table" extension. - - isofile->tablename[i] = 0; // And 0-terminate. - - - - isofile->tablehandle = ActualFileOpenForRead(isofile->tablename); - - if(isofile->tablehandle == ACTUALHANDLENULL) { - + isofile->tablehandle = ActualFileOpenForRead(isofile->tablename); + if (isofile->tablehandle == ACTUALHANDLENULL) + { #ifdef VERBOSE_WARNING_GZIPV2 - - PrintLog("CDVDiso GZipV2: Couldn't open table!"); - + PrintLog("CDVDiso GZipV2: Couldn't open table!"); #endif /* VERBOSE_WARNING_GZIPV2 */ + return(-2); + } // ENDIF- Couldn't open table file? Fail. - return(-2); - - } // ENDIF- Couldn't open table file? Fail. - - - - offset = isofile->filesectorsize * sizeof(struct GZipV2Table); - - actual = ActualFileSize(isofile->tablehandle); - - if(offset != actual) { - + offset = isofile->filesectorsize * sizeof(struct GZipV2Table); + actual = ActualFileSize(isofile->tablehandle); + if (offset != actual) + { #ifdef VERBOSE_WARNING_GZIPV2 - - PrintLog("CDVDiso GZipV2: Table not the correct size! (Should be %lli, is %lli)", - - offset, actual); - + PrintLog("CDVDiso GZipV2: Table not the correct size! (Should be %lli, is %lli)", + offset, actual); #endif /* VERBOSE_WARNING_GZIPV2 */ + return(-2); + } // ENDIF- Not the correct-sized table for the data file? Fail. - return(-2); - - } // ENDIF- Not the correct-sized table for the data file? Fail. - - - - // We pre-read the WHOLE offset table. - - isofile->tabledata = (char *) malloc(isofile->filesectorsize * sizeof(struct TableData)); - - if(isofile->tabledata == NULL) { - + // We pre-read the WHOLE offset table. + isofile->tabledata = (char *) malloc(isofile->filesectorsize * sizeof(struct TableData)); + if (isofile->tabledata == NULL) + { #ifdef VERBOSE_WARNING_GZIPV2 - - PrintLog("CDVDiso GZipV2: Couldn't allocate internal table!"); - + PrintLog("CDVDiso GZipV2: Couldn't allocate internal table!"); #endif /* VERBOSE_WARNING_GZIPV2 */ - - return(-2); - - } // ENDIF- Could not get enough memory to hold table data - - - - offset = sizeof(struct GZipV2Header); - - tableoffset = 0; - - for(i = 0; i < isofile->filesectorsize; i++) { - - retval = ActualFileRead(isofile->tablehandle, - - sizeof(struct GZipV2Table), - - (char *) &table); - - if(retval != sizeof(struct GZipV2Table)) { - + return(-2); + } // ENDIF- Could not get enough memory to hold table data + offset = sizeof(struct GZipV2Header); + tableoffset = 0; + for (i = 0; i < isofile->filesectorsize; i++) + { + retval = ActualFileRead(isofile->tablehandle, + sizeof(struct GZipV2Table), + (char *) & table); + if (retval != sizeof(struct GZipV2Table)) + { #ifdef VERBOSE_WARNING_GZIPV2 - - PrintLog("CDVDiso GZipV2: Failed to read in sector %i!", i); - + PrintLog("CDVDiso GZipV2: Failed to read in sector %i!", i); #endif /* VERBOSE_WARNING_GZIPV2 */ + return(-2); + } // ENDIF- Trouble reading in a size? Table damaged... fail. - return(-2); - - } // ENDIF- Trouble reading in a size? Table damaged... fail. - - - - tablemap.table.offset = offset; - - tablemap.table.size = ConvertEndianUInt(table.size); - - for(j = 0; j < sizeof(struct TableData); j++) - - *(isofile->tabledata + tableoffset + j) = tablemap.ch[j]; - - offset += table.size; - - tableoffset += sizeof(struct TableData); - - } // NEXT i- reading in the sizes, and making offset as I go. - - - - ActualFileClose(isofile->tablehandle); - - isofile->tablehandle = ACTUALHANDLENULL; - - return(0); + tablemap.table.offset = offset; + tablemap.table.size = ConvertEndianUInt(table.size); + for (j = 0; j < sizeof(struct TableData); j++) + *(isofile->tabledata + tableoffset + j) = tablemap.ch[j]; + offset += table.size; + tableoffset += sizeof(struct TableData); + } // NEXT i- reading in the sizes, and making offset as I go. + ActualFileClose(isofile->tablehandle); + isofile->tablehandle = ACTUALHANDLENULL; + return(0); } // END GZipV2OpenTableForRead() - - - - -int GZipV2SeekTable(struct IsoFile *isofile, off64_t sector) { - +int GZipV2SeekTable(struct IsoFile *isofile, off64_t sector) +{ #ifdef VERBOSE_FUNCTION_GZIPV2 - - PrintLog("CDVDiso GZipV2: SeekTable(%lli)", sector); - + PrintLog("CDVDiso GZipV2: SeekTable(%lli)", sector); #endif /* VERBOSE_FUNCTION_GZIPV2 */ - - - - isofile->filesectorpos = sector; - - return(0); - + isofile->filesectorpos = sector; + return(0); } // END GZipV2SeekTable() - - - - -int GZipV2ReadTable(struct IsoFile *isofile, struct TableData *table) { - - off64_t target; - - union TableMap tablemap; - - off64_t i; - - - +int GZipV2ReadTable(struct IsoFile *isofile, struct TableData *table) +{ + off64_t target; + union TableMap tablemap; + off64_t i; #ifdef VERBOSE_FUNCTION_GZIPV2 - - PrintLog("CDVDiso GZipV2: ReadTable()"); - + PrintLog("CDVDiso GZipV2: ReadTable()"); #endif /* VERBOSE_FUNCTION_GZIPV2 */ - - - - target = isofile->filesectorpos * sizeof(struct TableData); - - for(i = 0; i < sizeof(struct TableData); i++) - - tablemap.ch[i] = *(isofile->tabledata + target + i); - - - - table->offset = tablemap.table.offset; - - table->size = tablemap.table.size; - - isofile->filesectorpos++; - - return(0); - + target = isofile->filesectorpos * sizeof(struct TableData); + for (i = 0; i < sizeof(struct TableData); i++) + tablemap.ch[i] = *(isofile->tabledata + target + i); + table->offset = tablemap.table.offset; + table->size = tablemap.table.size; + isofile->filesectorpos++; + return(0); } // END GZipV2ReadTable() - - - - -int GZipV2OpenTableForWrite(struct IsoFile *isofile) { - - int i; - - int j; - - char tableext[] = ".table\0"; - - - +int GZipV2OpenTableForWrite(struct IsoFile *isofile) +{ + int i; + int j; + char tableext[] = ".table\0"; #ifdef VERBOSE_FUNCTION_GZIPV2 - - PrintLog("CDVDiso GZipV2: OpenTableForWrite()"); - + PrintLog("CDVDiso GZipV2: OpenTableForWrite()"); #endif /* VERBOSE_FUNCTION_GZIPV2 */ + i = 0; + while ((i < 256) && (isofile->name[i] != 0)) + { + isofile->tablename[i] = isofile->name[i]; + i++; + } // ENDWHILE- Copying the data name to the table name + j = 0; + while ((i < 256) && (tableext[j] != 0)) + { + isofile->tablename[i] = tableext[j]; + i++; + j++; + } // ENDWHILE- Adding the ".table" extension. + isofile->tablename[i] = 0; // And 0-terminate. - - - i = 0; - - while((i < 256) && (isofile->name[i] != 0)) { - - isofile->tablename[i] = isofile->name[i]; - - i++; - - } // ENDWHILE- Copying the data name to the table name - - j = 0; - - while((i < 256) && (tableext[j] != 0)) { - - isofile->tablename[i] = tableext[j]; - - i++; - - j++; - - } // ENDWHILE- Adding the ".table" extension. - - isofile->tablename[i] = 0; // And 0-terminate. - - - - isofile->tablehandle = ActualFileOpenForWrite(isofile->tablename); - - if(isofile->tablehandle == ACTUALHANDLENULL) { - + isofile->tablehandle = ActualFileOpenForWrite(isofile->tablename); + if (isofile->tablehandle == ACTUALHANDLENULL) + { #ifdef VERBOSE_WARNING_GZIPV2 - - PrintLog("CDVDiso GZipV2: Couldn't open table!"); - + PrintLog("CDVDiso GZipV2: Couldn't open table!"); #endif /* VERBOSE_WARNING_GZIPV2 */ + return(-2); + } // ENDIF- Couldn't open table file? Fail. - return(-2); - - } // ENDIF- Couldn't open table file? Fail. - - - - isofile->filesectorsize = 0; - - return(0); - + isofile->filesectorsize = 0; + return(0); } // END GZipV2OpenTableForWrite() - - - - -int GZipV2WriteTable(struct IsoFile *isofile, struct TableData table) { - - int retval; - - struct GZipV2Table gv2table; - - unsigned int tempint; - - +int GZipV2WriteTable(struct IsoFile *isofile, struct TableData table) +{ + int retval; + struct GZipV2Table gv2table; + unsigned int tempint; #ifdef VERBOSE_FUNCTION_GZIPV2 - - PrintLog("CDVDiso GZipV2: WriteTable(%lli, %i)", table.offset, table.size); - + PrintLog("CDVDiso GZipV2: WriteTable(%lli, %i)", table.offset, table.size); #endif /* VERBOSE_FUNCTION_GZIPV2 */ - - - tempint = table.size; - - gv2table.size = ConvertEndianUInt(tempint); - - retval = ActualFileWrite(isofile->tablehandle, - - sizeof(struct GZipV2Table), - - (char *) &gv2table); - - if(retval != sizeof(unsigned int)) { - + tempint = table.size; + gv2table.size = ConvertEndianUInt(tempint); + retval = ActualFileWrite(isofile->tablehandle, + sizeof(struct GZipV2Table), + (char *) & gv2table); + if (retval != sizeof(unsigned int)) + { #ifdef VERBOSE_WARNING_GZIPV2 - - PrintLog("CDVDiso GZipV2: Couldn't write table entry!"); - + PrintLog("CDVDiso GZipV2: Couldn't write table entry!"); #endif /* VERBOSE_WARNING_GZIPV2 */ + return(-2); + } // ENDIF- Trouble reading table entry? Fail. - return(-2); - - } // ENDIF- Trouble reading table entry? Fail. - - - - return(0); - + return(0); } // END GZipV2WriteTable() - - - - -int GZipV2OpenForRead(struct IsoFile *isofile) { - - int retval; - - struct GZipV2Header header; - - +int GZipV2OpenForRead(struct IsoFile *isofile) +{ + int retval; + struct GZipV2Header header; #ifdef VERBOSE_FUNCTION_GZIPV2 - - PrintLog("CDVDiso GZipV2: OpenForRead()"); - + PrintLog("CDVDiso GZipV2: OpenForRead()"); #endif /* VERBOSE_FUNCTION_GZIPV2 */ + isofile->handle = ActualFileOpenForRead(isofile->name); + if (isofile->handle == ACTUALHANDLENULL) + { + return(-1); + } // ENDIF- Couldn't open data file? Fail. + isofile->filebytesize = ActualFileSize(isofile->handle); + isofile->filebytepos = 0; + isofile->filesectorpos = 0; + isofile->imageheader = 0; + isofile->numsectors = 1; // Sectors per block - - isofile->handle = ActualFileOpenForRead(isofile->name); - - if(isofile->handle == ACTUALHANDLENULL) { - - return(-1); - - } // ENDIF- Couldn't open data file? Fail. - - - - isofile->filebytesize = ActualFileSize(isofile->handle); - - isofile->filebytepos = 0; - - isofile->filesectorpos = 0; - - - - isofile->imageheader = 0; - - isofile->numsectors = 1; // Sectors per block - - - - retval = ActualFileRead(isofile->handle, - - sizeof(struct GZipV2Header), - - (char *) &header); - - if(retval != sizeof(struct GZipV2Header)) { - + retval = ActualFileRead(isofile->handle, + sizeof(struct GZipV2Header), + (char *) & header); + if (retval != sizeof(struct GZipV2Header)) + { #ifdef VERBOSE_WARNING_GZIPV2 - - PrintLog("CDVDiso GZipV2: Couldn't read header!"); - + PrintLog("CDVDiso GZipV2: Couldn't read header!"); #endif /* VERBOSE_WARNING_GZIPV2 */ - - ActualFileClose(isofile->handle); - - isofile->handle = ACTUALHANDLENULL; - - return(-1); - - } // ENDIF Could not read the first sector? Fail. - - isofile->filebytepos += retval; - - - - if((header.id[0] != 'Z') || - - (header.id[1] != ' ') || - - (header.id[2] != 'V') || - - (header.id[3] != '2')) { - + ActualFileClose(isofile->handle); + isofile->handle = ACTUALHANDLENULL; + return(-1); + } // ENDIF Could not read the first sector? Fail. + isofile->filebytepos += retval; + if ((header.id[0] != 'Z') || + (header.id[1] != ' ') || + (header.id[2] != 'V') || + (header.id[3] != '2')) + { #ifdef VERBOSE_WARNING_GZIPV2 - - PrintLog("CDVDiso GZipV2: Not a gzip v2 compression header!"); - + PrintLog("CDVDiso GZipV2: Not a gzip v2 compression header!"); #endif /* VERBOSE_WARNING_GZIPV2 */ - - ActualFileClose(isofile->handle); - - isofile->handle = ACTUALHANDLENULL; - - return(-1); - - } // ENDIF- ID for this compression type doesn't match? - - - - isofile->blocksize = ConvertEndianUInt(header.blocksize); - - isofile->filesectorsize = ConvertEndianUInt(header.numblocks); - - isofile->blockoffset = ConvertEndianUInt(header.blockoffset); - - isofile->filesectorpos = 0; - - return(0); - + ActualFileClose(isofile->handle); + isofile->handle = ACTUALHANDLENULL; + return(-1); + } // ENDIF- ID for this compression type doesn't match? + isofile->blocksize = ConvertEndianUInt(header.blocksize); + isofile->filesectorsize = ConvertEndianUInt(header.numblocks); + isofile->blockoffset = ConvertEndianUInt(header.blockoffset); + isofile->filesectorpos = 0; + return(0); } // END GZipV2OpenForRead() - - - - -int GZipV2Seek(struct IsoFile *isofile, off64_t position) { - - int retval; - - +int GZipV2Seek(struct IsoFile *isofile, off64_t position) +{ + int retval; #ifdef VERBOSE_FUNCTION_GZIPV2 - - PrintLog("CDVDiso GZipV2: Seek(%lli)", position); - + PrintLog("CDVDiso GZipV2: Seek(%lli)", position); #endif /* VERBOSE_FUNCTION_GZIPV2 */ - - - retval = ActualFileSeek(isofile->handle, position); - - if(retval < 0) { - + retval = ActualFileSeek(isofile->handle, position); + if (retval < 0) + { #ifdef VERBOSE_WARNING_GZIPV2 - - PrintLog("CDVDiso GZipV2: Couldn't find the start of the compressed block!"); - + PrintLog("CDVDiso GZipV2: Couldn't find the start of the compressed block!"); #endif /* VERBOSE_WARNING_GZIPV2 */ + return(-1); + } // ENDIF- Couldn't find the data entry? Fail. + isofile->filebytepos = position; + return(0); - return(-1); - - } // ENDIF- Couldn't find the data entry? Fail. - - isofile->filebytepos = position; - - return(0); - - - - return(-1); // Fail. (Due to lack of ambition?) - + return(-1); // Fail. (Due to lack of ambition?) } // END GZipV2Seek() - - - - -int GZipV2Read(struct IsoFile *isofile, int bytes, char *buffer) { - - int retval; - - unsigned long blocklen; - - z_stream strm; - - unsigned long tempin; - - char tempblock[2800]; - - unsigned long tempout; - - +int GZipV2Read(struct IsoFile *isofile, int bytes, char *buffer) +{ + int retval; + unsigned long blocklen; + z_stream strm; + unsigned long tempin; + char tempblock[2800]; + unsigned long tempout; #ifdef VERBOSE_FUNCTION_GZIPV2 - - PrintLog("CDVDiso GZipV2: Read(%i)", bytes); - + PrintLog("CDVDiso GZipV2: Read(%i)", bytes); #endif /* VERBOSE_FUNCTION_GZIPV2 */ - - - if(bytes > 0) { - - retval = ActualFileRead(isofile->handle, bytes, tempblock); - - if(retval > 0) isofile->filebytepos += retval; - - if(retval != bytes) { - + if (bytes > 0) + { + retval = ActualFileRead(isofile->handle, bytes, tempblock); + if (retval > 0) isofile->filebytepos += retval; + if (retval != bytes) + { #ifdef VERBOSE_WARNING_GZIPV2 - - PrintLog("CDVDiso GZipV2: Cannot read bytes! Returned: (%i)", retval); - + PrintLog("CDVDiso GZipV2: Cannot read bytes! Returned: (%i)", retval); #endif /* VERBOSE_WARNING_GZIPV2 */ + return(-1); + } // ENDIF- Trouble reading compressed sector? Abort. - return(-1); - - } // ENDIF- Trouble reading compressed sector? Abort. - - - - blocklen = isofile->blocksize; - - retval = uncompress(buffer, &blocklen, tempblock, bytes); - - if(retval != Z_OK) { - + blocklen = isofile->blocksize; + retval = uncompress(buffer, &blocklen, tempblock, bytes); + if (retval != Z_OK) + { #ifdef VERBOSE_WARNING_GZIPV2 - - PrintLog("CDVDiso GZipV2: Cannot decode block! Returned: (%i)", retval); - + PrintLog("CDVDiso GZipV2: Cannot decode block! Returned: (%i)", retval); #endif /* VERBOSE_WARNING_GZIPV2 */ + return(-1); + } // ENDIF- Trouble decoding the sector? Abort. + return(0); + } // ENDIF- Do we know how many compressed bytes to get for this record? - return(-1); + // Hmm. Don't know the compressed size? Well, we'll just have to find it. - } // ENDIF- Trouble decoding the sector? Abort. + tempin = 0; + tempout = 0; + retval = Z_OK; + while ((tempin < 2800) && (tempout < isofile->blocksize * isofile->numsectors)) + { + strm.zalloc = (alloc_func)0; + strm.zfree = (free_func)0; + strm.next_in = tempblock; + strm.next_out = buffer; + strm.avail_in = tempin; + strm.avail_out = 2800; - - return(0); - - } // ENDIF- Do we know how many compressed bytes to get for this record? - - - - // Hmm. Don't know the compressed size? Well, we'll just have to find it. - - - - tempin = 0; - - tempout = 0; - - retval = Z_OK; - - while((tempin < 2800) && (tempout < isofile->blocksize * isofile->numsectors)) { - - - - strm.zalloc = (alloc_func)0; - - strm.zfree = (free_func)0; - - - - strm.next_in = tempblock; - - strm.next_out = buffer; - - - - strm.avail_in = tempin; - - strm.avail_out = 2800; - - - - retval = inflateInit(&strm); - - if (retval != Z_OK) return(-1); - - - - while((tempin < 2800) && (retval == Z_OK)) { - - retval = ActualFileRead(isofile->handle, 1, &tempblock[tempin]); - - if(retval != 1) { - + retval = inflateInit(&strm); + if (retval != Z_OK) return(-1); + while ((tempin < 2800) && (retval == Z_OK)) + { + retval = ActualFileRead(isofile->handle, 1, &tempblock[tempin]); + if (retval != 1) + { #ifdef VERBOSE_FUNCTION_GZIPV2 - - PrintLog("CDVDiso GZipV2: Cannot read a byte! Returned: (%i)", retval); - + PrintLog("CDVDiso GZipV2: Cannot read a byte! Returned: (%i)", retval); #endif /* VERBOSE_FUNCTION_GZIPV2 */ + return(-1); + } // ENDIF- Trouble reading compressed sector? Abort. + tempin++; + strm.avail_in++; - return(-1); - - } // ENDIF- Trouble reading compressed sector? Abort. - - tempin++; - - strm.avail_in++; - - - - strm.next_in = &tempblock[tempin - strm.avail_in]; - - retval = inflate(&strm, Z_NO_FLUSH); - - } // ENDWHILE- trying to uncompress an increasingly filled buffer - - tempout = 2800 - strm.avail_out; - - inflateEnd(&strm); - - - - } // ENDWHILE- trying to uncompress a whole buffer - - if(retval != Z_STREAM_END) return(-1); - - - - if(tempin == 2800) return(-1); - - isofile->filebytepos += tempin; - - return(tempin); // Send out # of compressed bytes (to record in table) + strm.next_in = &tempblock[tempin - strm.avail_in]; + retval = inflate(&strm, Z_NO_FLUSH); + } // ENDWHILE- trying to uncompress an increasingly filled buffer + tempout = 2800 - strm.avail_out; + inflateEnd(&strm); + } // ENDWHILE- trying to uncompress a whole buffer + if (retval != Z_STREAM_END) return(-1); + if (tempin == 2800) return(-1); + isofile->filebytepos += tempin; + return(tempin); // Send out # of compressed bytes (to record in table) } // END GZipV2Read() - - - - -int GZipV2OpenForWrite(struct IsoFile *isofile) { - - char garbage[sizeof(struct GZipV2Header)]; - - int i; - - - - if(isofile == NULL) return(-1); - - - +int GZipV2OpenForWrite(struct IsoFile *isofile) +{ + char garbage[sizeof(struct GZipV2Header)]; + int i; + if (isofile == NULL) return(-1); #ifdef VERBOSE_FUNCTION_GZIPV2 - - PrintLog("CDVDiso GZipV2: OpenForWrite()"); - + PrintLog("CDVDiso GZipV2: OpenForWrite()"); #endif /* VERBOSE_FUNCTION_GZIPV2 */ + isofile->handle = ActualFileOpenForWrite(isofile->name); + if (isofile->handle == ACTUALHANDLENULL) + { + return(-1); + } // ENDIF- Couldn't open data file? Fail. + for (i = 0; i < sizeof(struct GZipV2Header); i++) garbage[i] = 0; + ActualFileWrite(isofile->handle, sizeof(struct GZipV2Header), garbage); - - - isofile->handle = ActualFileOpenForWrite(isofile->name); - - if(isofile->handle == ACTUALHANDLENULL) { - - return(-1); - - } // ENDIF- Couldn't open data file? Fail. - - for(i = 0; i < sizeof(struct GZipV2Header); i++) garbage[i] = 0; - - ActualFileWrite(isofile->handle, sizeof(struct GZipV2Header), garbage); - - - - isofile->filebytesize = 0; - - isofile->filebytepos = sizeof(struct GZipV2Header); - - isofile->filesectorpos = 0; - - isofile->filesectorsize = 0; - - return(0); - + isofile->filebytesize = 0; + isofile->filebytepos = sizeof(struct GZipV2Header); + isofile->filesectorpos = 0; + isofile->filesectorsize = 0; + return(0); } // END GZipV2OpenForWrite() - - - - -int GZipV2Write(struct IsoFile *isofile, char *buffer) { - - int retval; - - unsigned long blocklen; - - char tempblock[2800]; - - - +int GZipV2Write(struct IsoFile *isofile, char *buffer) +{ + int retval; + unsigned long blocklen; + char tempblock[2800]; #ifdef VERBOSE_FUNCTION_GZIPV2 - - PrintLog("CDVDiso GZipV2: Write()"); - + PrintLog("CDVDiso GZipV2: Write()"); #endif /* VERBOSE_FUNCTION_GZIPV2 */ - - - - blocklen = 2800; - - retval = compress2(tempblock, &blocklen, - - buffer, isofile->blocksize, - - Z_BEST_COMPRESSION); - - if(retval != Z_OK) { - + blocklen = 2800; + retval = compress2(tempblock, &blocklen, + buffer, isofile->blocksize, + Z_BEST_COMPRESSION); + if (retval != Z_OK) + { #ifdef VERBOSE_FUNCTION_GZIPV2 - - PrintLog("CDVDiso GZipV2: Cannot encode block! Returned: (%i)", retval); - + PrintLog("CDVDiso GZipV2: Cannot encode block! Returned: (%i)", retval); #endif /* VERBOSE_FUNCTION_GZIPV2 */ + return(-1); + } // ENDIF- Trouble compressing a block? Abort. - return(-1); - - } // ENDIF- Trouble compressing a block? Abort. - - - - retval = ActualFileWrite(isofile->handle, blocklen, tempblock); - - if(retval > 0) isofile->filebytepos += retval; - - if(retval < blocklen) { - + retval = ActualFileWrite(isofile->handle, blocklen, tempblock); + if (retval > 0) isofile->filebytepos += retval; + if (retval < blocklen) + { #ifdef VERBOSE_FUNCTION_GZIPV2 - - PrintLog("CDVDiso GZipV2: Cannot write bytes! Returned: (%i out of %llu)", - - retval, blocklen); - + PrintLog("CDVDiso GZipV2: Cannot write bytes! Returned: (%i out of %llu)", + retval, blocklen); #endif /* VERBOSE_FUNCTION_GZIPV2 */ - - return(-1); - - } // ENDIF- Trouble writing out the compressed block? Abort. - - isofile->filesectorpos++; - - - - return(blocklen); // Not in list? Fail. - + return(-1); + } // ENDIF- Trouble writing out the compressed block? Abort. + isofile->filesectorpos++; + return(blocklen); // Not in list? Fail. } // END GZipV2Write() - - - - -void GZipV2Close(struct IsoFile *isofile) { - - struct GZipV2Header header; - - unsigned int tempint; - - - +void GZipV2Close(struct IsoFile *isofile) +{ + struct GZipV2Header header; + unsigned int tempint; #ifdef VERBOSE_FUNCTION_GZIPV2 - - PrintLog("CDVDiso GZipV2: Close()"); - + PrintLog("CDVDiso GZipV2: Close()"); #endif /* VERBOSE_FUNCTION_GZIPV2 */ + if (isofile->tablehandle != ACTUALHANDLENULL) + { + ActualFileClose(isofile->tablehandle); + isofile->tablehandle = ACTUALHANDLENULL; + } // ENDIF- Is there a table file open? Close it. + if (isofile->handle != ACTUALHANDLENULL) + { + if (isofile->openforread == 0) + { + header.id[0] = 'Z'; + header.id[1] = ' '; + header.id[2] = 'V'; + header.id[3] = '2'; + tempint = isofile->blocksize; + header.blocksize = ConvertEndianUInt(tempint); + tempint = isofile->filesectorsize; + header.numblocks = ConvertEndianUInt(tempint); + tempint = isofile->blockoffset; + header.blockoffset = ConvertEndianUInt(tempint); + ActualFileSeek(isofile->handle, 0); + ActualFileWrite(isofile->handle, + sizeof(struct GZipV2Header), + (char *) &header); + } // ENDIF- Opened for write? Don't forget to update the header block! + ActualFileClose(isofile->handle); + isofile->handle = ACTUALHANDLENULL; + } // ENDIF- Is there a data file open? Close it. - if(isofile->tablehandle != ACTUALHANDLENULL) { - - ActualFileClose(isofile->tablehandle); - - isofile->tablehandle = ACTUALHANDLENULL; - - } // ENDIF- Is there a table file open? Close it. - - - - if(isofile->handle != ACTUALHANDLENULL) { - - if(isofile->openforread == 0) { - - header.id[0] = 'Z'; - - header.id[1] = ' '; - - header.id[2] = 'V'; - - header.id[3] = '2'; - - tempint = isofile->blocksize; - - header.blocksize = ConvertEndianUInt(tempint); - - tempint = isofile->filesectorsize; - - header.numblocks = ConvertEndianUInt(tempint); - - tempint = isofile->blockoffset; - - header.blockoffset = ConvertEndianUInt(tempint); - - ActualFileSeek(isofile->handle, 0); - - ActualFileWrite(isofile->handle, - - sizeof(struct GZipV2Header), - - (char *) &header); - - } // ENDIF- Opened for write? Don't forget to update the header block! - - - - ActualFileClose(isofile->handle); - - isofile->handle = ACTUALHANDLENULL; - - } // ENDIF- Is there a data file open? Close it. - - - - if(isofile->tabledata != NULL) { - - free(isofile->tabledata); - - isofile->tabledata = NULL; - - } // ENDIF- Do we have a read-in table to clear out? - - - - return; - + if (isofile->tabledata != NULL) + { + free(isofile->tabledata); + isofile->tabledata = NULL; + } // ENDIF- Do we have a read-in table to clear out? + return; } // END GZipV2Close() - diff --git a/plugins/CDVDisoEFP/src/gzipv2.h b/plugins/CDVDisoEFP/src/gzipv2.h index c6d1d5d330..281ef05b5b 100644 --- a/plugins/CDVDisoEFP/src/gzipv2.h +++ b/plugins/CDVDisoEFP/src/gzipv2.h @@ -1,104 +1,46 @@ /* gzipv2.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef GZIPV2_H - #define GZIPV2_H - - - - #include - - #include "isofile.h" - #include "isocompress.h" - - - - // #define VERBOSE_FUNCTION_GZIPV2 - // #define VERBOSE_WARNING_GZIPV2 - - - - extern int GZipV2OpenTableForRead(struct IsoFile *isofile); - extern int GZipV2SeekTable(struct IsoFile *isofile, off64_t sector); - extern int GZipV2ReadTable(struct IsoFile *isofile, struct TableData *table); - - extern int GZipV2OpenTableForWrite(struct IsoFile *isofile); - extern int GZipV2WriteTable(struct IsoFile *isofile, struct TableData table); - - - extern int GZipV2OpenForRead(struct IsoFile *isofile); - extern int GZipV2Seek(struct IsoFile *isofile, off64_t sector); - extern int GZipV2Read(struct IsoFile *isofile, int bytes, char *buffer); - extern void GZipV2Close(struct IsoFile *isofile); - - extern int GZipV2OpenForWrite(struct IsoFile *isofile); - extern int GZipV2Write(struct IsoFile *isofile, char *buffer); - - - - #endif /* GZIPV2_H */ - diff --git a/plugins/CDVDisoEFP/src/imagetype.c b/plugins/CDVDisoEFP/src/imagetype.c index 4c7924f58a..4aa76487b5 100644 --- a/plugins/CDVDisoEFP/src/imagetype.c +++ b/plugins/CDVDisoEFP/src/imagetype.c @@ -1,306 +1,154 @@ /* imagetype.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include // NULL - #include // off64_t - - - // #ifndef __LINUX__ - // #ifdef __linux__ - // #define __LINUX__ - // #endif /* __linux__ */ - // #endif /* No __LINUX__ */ - - - // #define CDVDdefs - // #include "PS2Edefs.h" - - #include "isofile.h" - #include "actualfile.h" - #include "imagetype.h" - - - - // Based (mostly) off of florin's CDVDbin detection code, twice removed - // with some additions from the header. - -struct ImageTypes imagedata[] = { - - { "ISO 2048", 2048, 0, 0, 0 }, - - { "YellowBook 2064", 2064, 0, 16, 1 }, - - { "RAW 2064", 2064, 0, 0, 2 }, - - { "GreenBook 2072", 2072, 0, 24, 3 }, - - { "RAW 2072", 2072, 0, 0, 4 }, - - { "RAW 2324", 2324, 0, 0, 5 }, - - { "RAW 2328", 2328, 0, 0, 6 }, - - { "RAW 2336", 2336, 0, 0, 7 }, - - { "GreenBook 2352", 2352, 0, 24, 8 }, - - { "YellowBook 2352", 2352, 0, 16, 9 }, - - { "RedBook 2352", 2352, 0, 0, 10 }, - - { "RAWQ 2448", 2448, 0, 0, 11 }, - - - - { "NERO ISO 2048", 2048, 150*2048, 0, 0 }, - - { "NERO GreenBook 2352", 2352, 150*2352, 24, 8 }, - - { "NERO YellowBook 2352", 2352, 150*2352, 16, 9 }, - - { "NERO RedBook 2352", 2352, 150*2352, 0, 10 }, - - { "NERO RAWQ 2448", 2448, 150*2448, 0, 11 }, - - - - { "Alt ISO 2048", 2048, 8, 0, 0 }, - - { "Alt RAW 2336", 2336, 8, 0, 7 }, - - { "Alt GreenBook 2352", 2352, 8, 24, 8 }, - - { "Alt YellowBook 2352", 2352, 8, 16, 9 }, - - { "Alt RedBook 2352", 2352, 8, 0, 10 }, - - { "Alt RAWQ 2448", 2448, 8, 0, 11 }, - - { NULL, 0, 0, 0, 0 } - +struct ImageTypes imagedata[] = +{ + { "ISO 2048", 2048, 0, 0, 0 }, + { "YellowBook 2064", 2064, 0, 16, 1 }, + { "RAW 2064", 2064, 0, 0, 2 }, + { "GreenBook 2072", 2072, 0, 24, 3 }, + { "RAW 2072", 2072, 0, 0, 4 }, + { "RAW 2324", 2324, 0, 0, 5 }, + { "RAW 2328", 2328, 0, 0, 6 }, + { "RAW 2336", 2336, 0, 0, 7 }, + { "GreenBook 2352", 2352, 0, 24, 8 }, + { "YellowBook 2352", 2352, 0, 16, 9 }, + { "RedBook 2352", 2352, 0, 0, 10 }, + { "RAWQ 2448", 2448, 0, 0, 11 }, + { "NERO ISO 2048", 2048, 150*2048, 0, 0 }, + { "NERO GreenBook 2352", 2352, 150*2352, 24, 8 }, + { "NERO YellowBook 2352", 2352, 150*2352, 16, 9 }, + { "NERO RedBook 2352", 2352, 150*2352, 0, 10 }, + { "NERO RAWQ 2448", 2448, 150*2448, 0, 11 }, + { "Alt ISO 2048", 2048, 8, 0, 0 }, + { "Alt RAW 2336", 2336, 8, 0, 7 }, + { "Alt GreenBook 2352", 2352, 8, 24, 8 }, + { "Alt YellowBook 2352", 2352, 8, 16, 9 }, + { "Alt RedBook 2352", 2352, 8, 0, 10 }, + { "Alt RAWQ 2448", 2448, 8, 0, 11 }, + { NULL, 0, 0, 0, 0 } }; - - - - #define REDBOOK2352 10 +void GetImageType(struct IsoFile *isofile, int imagetype) +{ + int temptype; + int i; + temptype = imagetype; + if ((temptype < 0) || (temptype > 22)) temptype = REDBOOK2352; + i = 0; + while ((i < 40) && (*(imagedata[temptype].name + i) != 0)) + { + isofile->imagename[i] = *(imagedata[temptype].name + i); + i++; + } // ENDWHILE- filling in the image name + isofile->imagename[i] = 0; // And 0-terminate. - - -void GetImageType(struct IsoFile *isofile, int imagetype) { - - int temptype; - - int i; - - - - temptype = imagetype; - - if((temptype < 0) || (temptype > 22)) temptype = REDBOOK2352; - - - - i = 0; - - while((i < 40) && (*(imagedata[temptype].name + i) != 0)) { - - isofile->imagename[i] = *(imagedata[temptype].name + i); - - i++; - - } // ENDWHILE- filling in the image name - - isofile->imagename[i] = 0; // And 0-terminate. - - - - isofile->blocksize = imagedata[temptype].blocksize; - - isofile->imageheader = imagedata[temptype].fileoffset; - - isofile->blockoffset = imagedata[temptype].dataoffset; - + isofile->blocksize = imagedata[temptype].blocksize; + isofile->imageheader = imagedata[temptype].fileoffset; + isofile->blockoffset = imagedata[temptype].dataoffset; } // END GetImageType() - - - - -int GetImageTypeConvertTo(int imagetype) { - - return(imagedata[imagetype].conversiontype); - +int GetImageTypeConvertTo(int imagetype) +{ + return(imagedata[imagetype].conversiontype); } // END GetImageTypeConvertTo() +int DetectImageType(struct IsoFile *isofile) +{ + char comparestr[] = "CD001"; + int newtype; + off64_t targetpos; + char teststr[2448]; + int dataoffset; + int i; + int retval; - - - -int DetectImageType(struct IsoFile *isofile) { - - char comparestr[] = "CD001"; - - int newtype; - - off64_t targetpos; - - char teststr[2448]; - - int dataoffset; - - int i; - - int retval; - - - - newtype = 0; - - if(isofile->compress > 0) { - - IsoFileSeek(isofile, 16); - - IsoFileRead(isofile, teststr); - - - - while(imagedata[newtype].name != NULL) { - - if((isofile->blocksize == imagedata[newtype].blocksize) && - - (isofile->imageheader == imagedata[newtype].fileoffset)) { - - dataoffset = imagedata[newtype].dataoffset + 1; - - i = 0; - - while((i < 5) && (teststr[dataoffset + i] == comparestr[i])) i++; - - if(i == 5) { - - GetImageType(isofile, newtype); - - return(newtype); - - } // ENDIF- Did we find a match? - - } // ENDIF- Do these pieces match the compression storage pieces? - - newtype++; - - } // ENDWHILE- looking for the image type that fits the stats - - - - } else { - - while(imagedata[newtype].name != NULL) { - - targetpos = (16 * imagedata[newtype].blocksize) - - + imagedata[newtype].fileoffset - - + imagedata[newtype].dataoffset - - + 1; // Moves to start of string - - retval = ActualFileSeek(isofile->handle, targetpos); - - if(retval == 0) { - - retval = ActualFileRead(isofile->handle, 5, teststr); - - if(retval == 5) { - - i = 0; - - while((i < 5) && (teststr[i] == comparestr[i])) i++; - - if(i == 5) { - - ActualFileSeek(isofile->handle, isofile->imageheader); - - GetImageType(isofile, newtype); - - return(newtype); - - } // ENDIF- Did we find a match? - - } // ENDIF- Could we read in the test string? Cool! Test it. - - } // ENDIF- Could actually get to this point? - - newtype++; - - } // ENDWHILE- looking for the directory header string "CD001" - - ActualFileSeek(isofile->handle, isofile->imageheader); - - } // ENDIF- Do we match type to compression stats? (Or search against raw data?) - - - - GetImageType(isofile, REDBOOK2352); - - return(REDBOOK2352); // Couldn't find it? Guess it's RAW 2352, then. (Audio CD?) - + newtype = 0; + if (isofile->compress > 0) + { + IsoFileSeek(isofile, 16); + IsoFileRead(isofile, teststr); + while (imagedata[newtype].name != NULL) + { + if ((isofile->blocksize == imagedata[newtype].blocksize) && + (isofile->imageheader == imagedata[newtype].fileoffset)) + { + dataoffset = imagedata[newtype].dataoffset + 1; + i = 0; + while ((i < 5) && (teststr[dataoffset + i] == comparestr[i])) i++; + if (i == 5) + { + GetImageType(isofile, newtype); + return(newtype); + } // ENDIF- Did we find a match? + } // ENDIF- Do these pieces match the compression storage pieces? + newtype++; + } // ENDWHILE- looking for the image type that fits the stats + } + else + { + while (imagedata[newtype].name != NULL) + { + targetpos = (16 * imagedata[newtype].blocksize) + + imagedata[newtype].fileoffset + + imagedata[newtype].dataoffset + + 1; // Moves to start of string + retval = ActualFileSeek(isofile->handle, targetpos); + if (retval == 0) + { + retval = ActualFileRead(isofile->handle, 5, teststr); + if (retval == 5) + { + i = 0; + while ((i < 5) && (teststr[i] == comparestr[i])) i++; + if (i == 5) + { + ActualFileSeek(isofile->handle, isofile->imageheader); + GetImageType(isofile, newtype); + return(newtype); + } // ENDIF- Did we find a match? + } // ENDIF- Could we read in the test string? Cool! Test it. + } // ENDIF- Could actually get to this point? + newtype++; + } // ENDWHILE- looking for the directory header string "CD001" + ActualFileSeek(isofile->handle, isofile->imageheader); + } // ENDIF- Do we match type to compression stats? (Or search against raw data?) + GetImageType(isofile, REDBOOK2352); + return(REDBOOK2352); // Couldn't find it? Guess it's RAW 2352, then. (Audio CD?) } // END ImageDetect() - diff --git a/plugins/CDVDisoEFP/src/imagetype.h b/plugins/CDVDisoEFP/src/imagetype.h index af531b6200..2f83932ac0 100644 --- a/plugins/CDVDisoEFP/src/imagetype.h +++ b/plugins/CDVDisoEFP/src/imagetype.h @@ -1,112 +1,51 @@ /* imagetype.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef IMAGETYPE_H - #define IMAGETYPE_H - - - - // #ifndef __LINUX__ - // #ifdef __linux__ - // #define __LINUX__ - // #endif /* __linux__ */ - // #endif /* No __LINUX__ */ - - // #define CDVDdefs - // #include "PS2Edefs.h" - - - #include "isofile.h" - - - - -struct ImageTypes { - - char *name; - - off64_t blocksize; - - off64_t fileoffset; - - int dataoffset; - - int conversiontype; // For conversionbox to write a new file as. - +struct ImageTypes +{ + char *name; + off64_t blocksize; + off64_t fileoffset; + int dataoffset; + int conversiontype; // For conversionbox to write a new file as. }; - - // Note: Worked around since a failure occurred with MSVCRT.DLL. It couldn't - // printf a char string inside an array of structures. Don't know why. - // extern struct ImageTypes imagedata[]; - - - - extern void GetImageType(struct IsoFile *isofile, int imagetype); - extern int GetImageTypeConvertTo(int imagetype); - extern int DetectImageType(struct IsoFile *isofile); - - - - #endif /* IMAGETYPE_H */ - diff --git a/plugins/CDVDisoEFP/src/ini.c b/plugins/CDVDisoEFP/src/ini.c index f1bc58746f..b1d602b3d8 100644 --- a/plugins/CDVDisoEFP/src/ini.c +++ b/plugins/CDVDisoEFP/src/ini.c @@ -1,1378 +1,757 @@ -/* ini.c - - * Copyright (C) 2002-2005 PCSX2 Team - - * - - * This program is free software; you can redistribute it and/or modify - - * it under the terms of the GNU General Public License as published by - - * the Free Software Foundation; either version 2 of the License, or - - * (at your option) any later version. - - * - - * This program is distributed in the hope that it will be useful, - - * but WITHOUT ANY WARRANTY; without even the implied warranty of - - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - - * GNU General Public License for more details. - - * - - * You should have received a copy of the GNU General Public License - - * along with this program; if not, write to the Free Software - - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - * - - * PCSX2 members can be contacted through their website at www.pcsx2.net. - - */ - - - - - -#include // NULL - -#include // sprintf() - - - -#include "logfile.h" - -#include "actualfile.h" - -#include "ini.h" - - - - - -const char INIext[] = ".ini"; - -const char INInewext[] = ".new"; - - - - - -// Returns: position where new extensions should be added. - -int INIRemoveExt(char *argname, char *tempname) { - - int i; - - int j; - - int k; - - - -#ifdef VERBOSE_FUNCTION_INI - - PrintLog("CDVDiso ini: RemoveExt(%s)", argname); - -#endif /* VERBOSE_FUNCTION_INI */ - - - - i = 0; - - while((i <= INIMAXLEN) && (*(argname + i) != 0)) { - - *(tempname + i) = *(argname + i); - - i++; - - } // ENDWHILE- Copying the argument name into a temporary area; - - *(tempname + i) = 0; // And 0-terminate - - k = i; - - k--; - - - - j = 0; - - while((j <= INIMAXLEN) && (INIext[j] != 0)) j++; - - j--; - - - - while((j >= 0) && (*(tempname + k) == INIext[j])) { - - k--; - - j--; - - } // ENDWHILE- Comparing the ending characters to the INI ext. - - if(j < 0) { - - k++; - - i = k; - - *(tempname + i) = 0; // 0-terminate, cutting off ".ini" - - } // ENDIF- Do we have a match? Then remove the end chars. - - - - return(i); - -} // END INIRemoveExt() - - - - - -void INIAddInExt(char *tempname, int temppos) { - - int i; - - - -#ifdef VERBOSE_FUNCTION_INI - - PrintLog("CDVDiso ini: AddInExt(%s, %i)", tempname, temppos); - -#endif /* VERBOSE_FUNCTION_INI */ - - - - i = 0; - - while((i + temppos < INIMAXLEN) && (INIext[i] != 0)) { - - *(tempname + temppos + i) = INIext[i]; - - i++; - - } // ENDWHILE- Attaching extenstion to filename - - *(tempname + temppos + i) = 0; // And 0-terminate - -} // END INIAddInExt() - - - - - -void INIAddOutExt(char *tempname, int temppos) { - - int i; - - - -#ifdef VERBOSE_FUNCTION_INI - - PrintLog("CDVDiso ini: AddOutExt(%s, %i)", tempname, temppos); - -#endif /* VERBOSE_FUNCTION_INI */ - - - - i = 0; - - while((i + temppos < INIMAXLEN) && (INInewext[i] != 0)) { - - *(tempname + temppos + i) = INInewext[i]; - - i++; - - } // ENDWHILE- Attaching extenstion to filename - - *(tempname + temppos + i) = 0; // And 0-terminate - -} // END INIAddInExt() - - - - - -// Returns number of bytes read to get line (0 means end-of-file) - -int INIReadLine(ACTUALHANDLE infile, char *buffer) { - - int charcount; - - int i; - - char tempin[2]; - - int retflag; - - int retval; - - - -#ifdef VERBOSE_FUNCTION_INI - - PrintLog("CDVDiso ini: ReadLine()"); - -#endif /* VERBOSE_FUNCTION_INI */ - - - - charcount = 0; - - i = 0; - - tempin[1] = 0; - - retflag = 0; - - - - while((i < INIMAXLEN) && (retflag < 2)) { - - retval = ActualFileRead(infile, 1, tempin); - - charcount++; - - if(retval != 1) { - - retflag = 2; - - charcount--; - - - - } else if(tempin[0] == '\n') { - - retflag = 2; - - - - } else if(tempin[0] >= ' ') { - - *(buffer + i) = tempin[0]; - - i++; - - } // ENDLONGIF- How do we react to the next character? - - } // ENDWHILE- Loading up on characters until an End-of-Line appears - - *(buffer + i) = 0; // And 0-terminate - - - -#ifdef VERBOSE_FUNCTION_INI - - PrintLog("CDVDiso ini: Line: %s", buffer); - -#endif /* VERBOSE_FUNCTION_INI */ - - - - return(charcount); - -} // END INIReadLine() - -// Note: Do we need to back-skip a char if something other \n follows \r? - - - - - -// Returns: number of bytes to get to start of section (or -1) - -int INIFindSection(ACTUALHANDLE infile, char *section) { - - int charcount; - - int i; - - int retflag; - - int retval; - - char scanbuffer[INIMAXLEN+1]; - - - -#ifdef VERBOSE_FUNCTION_INI - - PrintLog("CDVDiso ini: FindSection(%s)", section); - -#endif /* VERBOSE_FUNCTION_INI */ - - - - charcount = 0; - - retflag = 0; - - - - while(retflag == 0) { - - retval = INIReadLine(infile, scanbuffer); - - if(retval == 0) return(-1); // EOF? Stop here. - - - - if(scanbuffer[0] == '[') { - - i = 0; - - while((i < INIMAXLEN) && - - (*(section + i) != 0) && - - (*(section + i) == scanbuffer[i + 1])) i++; - - if((i < INIMAXLEN - 2) && (*(section + i) == 0)) { - - if((scanbuffer[i + 1] == ']') && (scanbuffer[i + 2] == 0)) { - - retflag = 1; - - } // ENDIF- End marks look good? Return successful. - - } // ENDIF- Do we have a section match? - - } // ENDIF- Does this look like a section header? - - - - if(retflag == 0) charcount += retval; - - } // ENDWHILE- Scanning lines for the correct [Section] header. - - - - return(charcount); - -} // END INIFindSection() - - - - - -// Returns: number of bytes to get to start of keyword (or -1) - -int INIFindKeyword(ACTUALHANDLE infile, char *keyword, char *buffer) { - - int charcount; - - int i; - - int j; - - int retflag; - - int retval; - - char scanbuffer[INIMAXLEN+1]; - - - -#ifdef VERBOSE_FUNCTION_INI - - PrintLog("CDVDiso ini: FindKeyword(%s)", keyword); - -#endif /* VERBOSE_FUNCTION_INI */ - - - - charcount = 0; - - retflag = 0; - - - - while(retflag == 0) { - - retval = INIReadLine(infile, scanbuffer); - - if(retval == 0) return(-1); // EOF? Stop here. - - if(scanbuffer[0] == '[') return(-1); // New section? Stop here. - - - - i = 0; - - while((i < INIMAXLEN) && - - (*(keyword + i) != 0) && - - (*(keyword + i) == scanbuffer[i])) i++; - - if((i < INIMAXLEN - 2) && (*(keyword + i) == 0)) { - - if(scanbuffer[i] == '=') { - - retflag = 1; - - if(buffer != NULL) { - - i++; - - j = 0; - - while((i < INIMAXLEN) && (scanbuffer[i] != 0)) { - - *(buffer + j) = scanbuffer[i]; - - i++; - - j++; - - } // ENDWHILE- Copying the value out to the outbound buffer. - - *(buffer + j) = 0; // And 0-terminate. - - } // ENDIF- Return the value as well? - - } // ENDIF- End marks look good? Return successful. - - } // ENDIF- Do we have a section match? - - - - if(retflag == 0) charcount += retval; - - } // ENDWHILE- Scanning lines for the correct [Section] header. - - - -#ifdef VERBOSE_FUNCTION_INI - - PrintLog("CDVDiso ini: Value: %s", buffer); - -#endif /* VERBOSE_FUNCTION_INI */ - - - - return(charcount); - -} // END INIFindKeyWord() - - - - - -// Returns: number of bytes left to write... (from charcount back) - -int INICopy(ACTUALHANDLE infile, ACTUALHANDLE outfile, int charcount) { - - char buffer[4096]; - - int i; - - int chunk; - - int retval; - - - -#ifdef VERBOSE_FUNCTION_INI - - PrintLog("CDVDiso ini: Copy(%i)", charcount); - -#endif /* VERBOSE_FUNCTION_INI */ - - - - i = charcount; - - chunk = 4096; - - if(i < chunk) chunk = i; - - while(chunk > 0) { - - retval = ActualFileRead(infile, chunk, buffer); - - if(retval <= 0) return(i); // Trouble? Stop here. - - if(retval < chunk) chunk = retval; // Short block? Note it. - - - - retval = ActualFileWrite(outfile, chunk, buffer); - - if(retval <= 0) return(i); // Trouble? Stop here. - - i -= retval; - - if(retval < chunk) return(i); // Short block written? Stop here. - - - - chunk = 4096; - - if(i < chunk) chunk = i; - - } // ENDWHILE- Copying a section of file across, one chunk at a time. - - - - return(0); - -} // END INICopyToPos() - - - - - -int INISaveString(char *file, char *section, char *keyword, char *value) { - - char inname[INIMAXLEN+1]; - - char outname[INIMAXLEN+1]; - - int filepos; - - ACTUALHANDLE infile; - - ACTUALHANDLE outfile; - - int i; - - int retval; - - char templine[INIMAXLEN+1]; - - - - if(file == NULL) return(-1); - - if(section == NULL) return(-1); - - if(keyword == NULL) return(-1); - - if(value == NULL) return(-1); - - - -#ifdef VERBOSE_FUNCTION_INI - - PrintLog("CDVDiso ini: SaveString(%s, %s, %s, %s)", - - file, section, keyword, value); - -#endif /* VERBOSE_FUNCTION_INI */ - - - - filepos = INIRemoveExt(file, inname); - - for(i = 0; i <= filepos; i++) outname[i] = inname[i]; - - INIAddInExt(inname, filepos); - - INIAddOutExt(outname, filepos); - - - - filepos = 0; - - infile = ActualFileOpenForRead(inname); - - if(infile == ACTUALHANDLENULL) { - -#ifdef VERBOSE_FUNCTION_INI - - PrintLog("CDVDiso ini: creating new file"); - -#endif /* VERBOSE_FUNCTION_INI */ - - outfile = ActualFileOpenForWrite(inname); - - if(outfile == ACTUALHANDLENULL) return(-1); // Just a bad name? Abort. - - - - sprintf(templine, "[%s]\r\n", section); - - i = 0; - - while((i < INIMAXLEN) && (templine[i] != 0)) i++; - - retval = ActualFileWrite(outfile, i, templine); - - if(retval < i) { - - ActualFileClose(outfile); - - outfile = ACTUALHANDLENULL; - - ActualFileDelete(inname); - - return(-1); - - } // ENDIF- Trouble writing it out? Abort. - - - - sprintf(templine, "%s=%s\r\n", keyword, value); - - i = 0; - - while((i < INIMAXLEN) && (templine[i] != 0)) i++; - - retval = ActualFileWrite(outfile, i, templine); - - ActualFileClose(outfile); - - outfile = ACTUALHANDLENULL; - - if(retval < i) { - - ActualFileDelete(inname); - - return(-1); - - } // ENDIF- Trouble writing it out? Abort. - - return(0); - - } // ENDIF- No input file? Create a brand new .ini file then. - - - - retval = INIFindSection(infile, section); - - if(retval < 0) { - -#ifdef VERBOSE_FUNCTION_INI - - PrintLog("CDVDiso ini: creating new section"); - -#endif /* VERBOSE_FUNCTION_INI */ - - outfile = ActualFileOpenForWrite(outname); - - if(outfile == ACTUALHANDLENULL) { - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - return(-1); - - } // ENDIF- Couldn't open a temp file? Abort - - - - ActualFileSeek(infile, 0); // Move ini to beginning of file... - - INICopy(infile, outfile, 0x0FFFFFFF); // Copy the whole file out... - - - - sprintf(templine, "\r\n[%s]\r\n", section); - - i = 0; - - while((i < INIMAXLEN) && (templine[i] != 0)) i++; - - retval = ActualFileWrite(outfile, i, templine); - - if(retval < i) { - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - ActualFileClose(outfile); - - outfile = ACTUALHANDLENULL; - - ActualFileDelete(outname); - - return(-1); - - } // ENDIF- Trouble writing it out? Abort. - - - - sprintf(templine, "%s=%s\r\n", keyword, value); - - i = 0; - - while((i < INIMAXLEN) && (templine[i] != 0)) i++; - - retval = ActualFileWrite(outfile, i, templine); - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - ActualFileClose(outfile); - - outfile = ACTUALHANDLENULL; - - if(retval < i) { - - ActualFileDelete(outname); - - return(-1); - - } // ENDIF- Trouble writing it out? Abort. - - - - ActualFileDelete(inname); - - ActualFileRename(outname, inname); - - return(0); - - } // ENDIF- Couldn't find the section? Make a new one! - - - - filepos = retval; - - ActualFileSeek(infile, filepos); - - filepos += INIReadLine(infile, templine); // Get section line's byte count - - - - retval = INIFindKeyword(infile, keyword, NULL); - - if(retval < 0) { - -#ifdef VERBOSE_FUNCTION_INI - - PrintLog("CDVDiso ini: creating new keyword"); - -#endif /* VERBOSE_FUNCTION_INI */ - - ActualFileSeek(infile, filepos); - - retval = INIReadLine(infile, templine); - - i = 0; - - while((i < INIMAXLEN) && (templine[i] != 0) && (templine[i] != '=')) i++; - - while((retval > 0) && (templine[i] == '=')) { - - filepos += retval; - - retval = INIReadLine(infile, templine); - - i = 0; - - while((i < INIMAXLEN) && (templine[i] != 0) && (templine[i] != '=')) i++; - - } // ENDWHILE- skimming to the bottom of the section - - - - outfile = ActualFileOpenForWrite(outname); - - if(outfile == ACTUALHANDLENULL) { - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - return(-1); - - } // ENDIF- Couldn't open a temp file? Abort - - - - ActualFileSeek(infile, 0); - - retval = INICopy(infile, outfile, filepos); - - if(retval > 0) { - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - ActualFileClose(outfile); - - outfile = ACTUALHANDLENULL; - - ActualFileDelete(outname); - - return(-1); - - } // ENDIF- Trouble writing everything up to keyword? Abort. - - - - sprintf(templine, "%s=%s\r\n", keyword, value); - - i = 0; - - while((i < INIMAXLEN) && (templine[i] != 0)) i++; - - retval = ActualFileWrite(outfile, i, templine); - - if(retval < i) { - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - ActualFileClose(outfile); - - outfile = ACTUALHANDLENULL; - - ActualFileDelete(outname); - - return(-1); - - } // ENDIF- Trouble writing it out? Abort. - - - - } else { - -#ifdef VERBOSE_FUNCTION_INI - - PrintLog("CDVDiso ini: replacing keyword"); - -#endif /* VERBOSE_FUNCTION_INI */ - - filepos += retval; // Position just before old version of keyword - - - - outfile = ActualFileOpenForWrite(outname); - - if(outfile == ACTUALHANDLENULL) { - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - return(-1); - - } // ENDIF- Couldn't open a temp file? Abort - - - - ActualFileSeek(infile, 0); - - retval = INICopy(infile, outfile, filepos); - - if(retval > 0) { - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - ActualFileClose(outfile); - - outfile = ACTUALHANDLENULL; - - ActualFileDelete(outname); - - return(-1); - - } // ENDIF- Trouble writing everything up to keyword? Abort. - - - - INIReadLine(infile, templine); // Read past old keyword/value... - - - - // Replace with new value - - sprintf(templine, "%s=%s\r\n", keyword, value); - - i = 0; - - while((i < INIMAXLEN) && (templine[i] != 0)) i++; - - retval = ActualFileWrite(outfile, i, templine); - - if(retval < i) { - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - ActualFileClose(outfile); - - outfile = ACTUALHANDLENULL; - - ActualFileDelete(outname); - - return(-1); - - } // ENDIF- Trouble writing it out? Abort. - - } // ENDIF- Need to add a new keyword? - - - - INICopy(infile, outfile, 0xFFFFFFF); // Write out rest of file - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - ActualFileClose(outfile); - - outfile = ACTUALHANDLENULL; - - ActualFileDelete(inname); - - ActualFileRename(outname, inname); - - return(0); - -} // END INISaveString() - - - - - -int INILoadString(char *file, char *section, char *keyword, char *buffer) { - - char inname[INIMAXLEN+1]; - - int filepos; - - ACTUALHANDLE infile; - - int retval; - - - - if(file == NULL) return(-1); - - if(section == NULL) return(-1); - - if(keyword == NULL) return(-1); - - if(buffer == NULL) return(-1); - - - -#ifdef VERBOSE_FUNCTION_INI - - PrintLog("CDVDiso ini: LoadString(%s, %s, %s)", - - file, section, keyword); - -#endif /* VERBOSE_FUNCTION_INI */ - - - - filepos = INIRemoveExt(file, inname); - - INIAddInExt(inname, filepos); - - - - filepos = 0; - - infile = ActualFileOpenForRead(inname); - - if(infile == ACTUALHANDLENULL) return(-1); - - - - retval = INIFindSection(infile, section); - - if(retval < 0) { - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - return(-1); - - } // ENDIF- Didn't find it? Abort. - - - - retval = INIFindKeyword(infile, keyword, buffer); - - if(retval < 0) { - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - return(-1); - - } // ENDIF- Didn't find it? Abort. - - - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - return(0); - -} // END INILoadString() - - - - - -int INIRemove(char *file, char *section, char *keyword) { - - char inname[INIMAXLEN+1]; - - char outname[INIMAXLEN+1]; - - int filepos; - - ACTUALHANDLE infile; - - ACTUALHANDLE outfile; - - char templine[INIMAXLEN+1]; - - int i; - - int retval; - - - - if(file == NULL) return(-1); - - if(section == NULL) return(-1); - - - -#ifdef VERBOSE_FUNCTION_INI - - PrintLog("CDVDiso ini: Remove(%s, %s, %s)", - - file, section, keyword); - -#endif /* VERBOSE_FUNCTION_INI */ - - - - filepos = INIRemoveExt(file, inname); - - for(i = 0; i <= filepos; i++) outname[i] = inname[i]; - - INIAddInExt(inname, filepos); - - INIAddOutExt(outname, filepos); - - - - infile = ActualFileOpenForRead(inname); - - if(infile == ACTUALHANDLENULL) return(-1); - - - - retval = INIFindSection(infile, section); - - if(retval == -1) { - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - return(-1); - - } // ENDIF- Couldn't even find the section? Abort - - - - filepos = retval; - - if(keyword == NULL) { - -#ifdef VERBOSE_FUNCTION_INI - - PrintLog("CDVDiso ini: removing section"); - -#endif /* VERBOSE_FUNCTION_INI */ - - outfile = ActualFileOpenForWrite(outname); - - if(outfile == ACTUALHANDLENULL) { - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - return(-1); - - } // ENDIF- Couldn't open a temp file? Abort - - - - ActualFileSeek(infile, 0); - - retval = INICopy(infile, outfile, filepos); - - if(retval > 0) { - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - ActualFileClose(outfile); - - outfile = ACTUALHANDLENULL; - - ActualFileDelete(outname); - - return(-1); - - } // ENDIF- Trouble writing everything up to the section? Abort. - - - - templine[0] = 0; - - retval = 1; - - while((retval > 0) && (templine[0] != '[')) { - - retval = INIReadLine(infile, templine); - - } // ENDWHILE- Read to the start of the next section... or EOF. - - - - if(templine[0] == '[') { - - i = 0; - - while((i < INIMAXLEN) && (templine[i] != 0)) i++; - - retval = ActualFileWrite(outfile, i, templine); - - if(retval < i) { - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - ActualFileClose(outfile); - - outfile = ACTUALHANDLENULL; - - ActualFileDelete(outname); - - return(-1); - - } // ENDIF- Trouble writing it out? Abort. - - } // ENDIF- Are there other sections after this one? Save them then. - - - - } else { - - filepos = retval; - - ActualFileSeek(infile, filepos); - - filepos += INIReadLine(infile, templine); // Get section line's byte count - - - - retval = INIFindKeyword(infile, keyword, NULL); - - if(retval == -1) { - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - return(-1); - - } // ENDIF- Couldn't find the keyword? Abort - - filepos += retval; - - - -#ifdef VERBOSE_FUNCTION_INI - - PrintLog("CDVDiso ini: removing keyword"); - -#endif /* VERBOSE_FUNCTION_INI */ - - outfile = ActualFileOpenForWrite(outname); - - if(outfile == ACTUALHANDLENULL) { - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - return(-1); - - } // ENDIF- Couldn't open a temp file? Abort - - - - ActualFileSeek(infile, 0); - - retval = INICopy(infile, outfile, filepos); - - if(retval > 0) { - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - ActualFileClose(outfile); - - outfile = ACTUALHANDLENULL; - - ActualFileDelete(outname); - - return(-1); - - } // ENDIF- Trouble writing everything up to keyword? Abort. - - - - INIReadLine(infile, templine); // Read (and discard) the keyword line - - } // ENDIF- Wipe out the whole section? Or just a keyword? - - - - INICopy(infile, outfile, 0xFFFFFFF); // Write out rest of file - - ActualFileClose(infile); - - infile = ACTUALHANDLENULL; - - ActualFileClose(outfile); - - outfile = ACTUALHANDLENULL; - - ActualFileDelete(inname); - - ActualFileRename(outname, inname); - - return(0); - -} // END INIRemove() - - - - - -int INISaveUInt(char *file, char *section, char *keyword, unsigned int value) { - - char numvalue[INIMAXLEN+1]; - - - - sprintf(numvalue, "%u", value); - - return(INISaveString(file, section, keyword, numvalue)); - -} // END INISaveUInt() - - - - - -int INILoadUInt(char *file, char *section, char *keyword, unsigned int *buffer) { - - char numvalue[INIMAXLEN+1]; - - int retval; - - unsigned int value; - - // unsigned int sign; // Not needed in unsigned numbers - - int pos; - - - - if(buffer == NULL) return(-1); - - *(buffer) = 0; - - - - retval = INILoadString(file, section, keyword, numvalue); - - if(retval < 0) return(retval); - - - - value = 0; - - // sign = 1; // Start positive - - pos = 0; - - - - // Note: skip leading spaces? (Shouldn't have to, I hope) - - - - // if(numvalue[pos] == '-') { - - // pos++; - - // sign = -1; - - // } // ENDIF- Negative sign check - - - - while((pos < INIMAXLEN) && (numvalue[pos] != 0)) { - - if(value > (0xFFFFFFFF / 10)) return(-1); // Overflow? - - - - if((numvalue[pos] >= '0') && (numvalue[pos] <= '9')) { - - value *= 10; - - value += numvalue[pos] - '0'; - - pos++; - - } else { - - numvalue[pos] = 0; - - } // ENDIF- Add a digit in? Or stop searching for digits? - - } // ENDWHILE- Adding digits of info to our ever-increasing value - - - - // value *= sign - - *(buffer) = value; - - return(0); - -} // END INILoadUInt() - +/* ini.c + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +#include // NULL +#include // sprintf() + +#include "logfile.h" +#include "actualfile.h" +#include "ini.h" + + +const char INIext[] = ".ini"; +const char INInewext[] = ".new"; + + +// Returns: position where new extensions should be added. +int INIRemoveExt(char *argname, char *tempname) +{ + int i; + int j; + int k; + +#ifdef VERBOSE_FUNCTION_INI + PrintLog("CDVDiso ini: RemoveExt(%s)", argname); +#endif /* VERBOSE_FUNCTION_INI */ + + i = 0; + while ((i <= INIMAXLEN) && (*(argname + i) != 0)) + { + *(tempname + i) = *(argname + i); + i++; + } // ENDWHILE- Copying the argument name into a temporary area; + *(tempname + i) = 0; // And 0-terminate + k = i; + k--; + + j = 0; + while ((j <= INIMAXLEN) && (INIext[j] != 0)) j++; + j--; + + while ((j >= 0) && (*(tempname + k) == INIext[j])) + { + k--; + j--; + } // ENDWHILE- Comparing the ending characters to the INI ext. + if (j < 0) + { + k++; + i = k; + *(tempname + i) = 0; // 0-terminate, cutting off ".ini" + } // ENDIF- Do we have a match? Then remove the end chars. + + return(i); +} // END INIRemoveExt() + + +void INIAddInExt(char *tempname, int temppos) +{ + int i; + +#ifdef VERBOSE_FUNCTION_INI + PrintLog("CDVDiso ini: AddInExt(%s, %i)", tempname, temppos); +#endif /* VERBOSE_FUNCTION_INI */ + + i = 0; + while ((i + temppos < INIMAXLEN) && (INIext[i] != 0)) + { + *(tempname + temppos + i) = INIext[i]; + i++; + } // ENDWHILE- Attaching extenstion to filename + *(tempname + temppos + i) = 0; // And 0-terminate +} // END INIAddInExt() + + +void INIAddOutExt(char *tempname, int temppos) +{ + int i; + +#ifdef VERBOSE_FUNCTION_INI + PrintLog("CDVDiso ini: AddOutExt(%s, %i)", tempname, temppos); +#endif /* VERBOSE_FUNCTION_INI */ + + i = 0; + while ((i + temppos < INIMAXLEN) && (INInewext[i] != 0)) + { + *(tempname + temppos + i) = INInewext[i]; + i++; + } // ENDWHILE- Attaching extenstion to filename + *(tempname + temppos + i) = 0; // And 0-terminate +} // END INIAddInExt() + + +// Returns number of bytes read to get line (0 means end-of-file) +int INIReadLine(ACTUALHANDLE infile, char *buffer) +{ + int charcount; + int i; + char tempin[2]; + int retflag; + int retval; + +#ifdef VERBOSE_FUNCTION_INI + PrintLog("CDVDiso ini: ReadLine()"); +#endif /* VERBOSE_FUNCTION_INI */ + + charcount = 0; + i = 0; + tempin[1] = 0; + retflag = 0; + + while ((i < INIMAXLEN) && (retflag < 2)) + { + retval = ActualFileRead(infile, 1, tempin); + charcount++; + if (retval != 1) + { + retflag = 2; + charcount--; + + } + else if (tempin[0] == '\n') + { + retflag = 2; + + } + else if (tempin[0] >= ' ') + { + *(buffer + i) = tempin[0]; + i++; + } // ENDLONGIF- How do we react to the next character? + } // ENDWHILE- Loading up on characters until an End-of-Line appears + *(buffer + i) = 0; // And 0-terminate + +#ifdef VERBOSE_FUNCTION_INI + PrintLog("CDVDiso ini: Line: %s", buffer); +#endif /* VERBOSE_FUNCTION_INI */ + + return(charcount); +} // END INIReadLine() +// Note: Do we need to back-skip a char if something other \n follows \r? + + +// Returns: number of bytes to get to start of section (or -1) +int INIFindSection(ACTUALHANDLE infile, char *section) +{ + int charcount; + int i; + int retflag; + int retval; + char scanbuffer[INIMAXLEN+1]; + +#ifdef VERBOSE_FUNCTION_INI + PrintLog("CDVDiso ini: FindSection(%s)", section); +#endif /* VERBOSE_FUNCTION_INI */ + + charcount = 0; + retflag = 0; + + while (retflag == 0) + { + retval = INIReadLine(infile, scanbuffer); + if (retval == 0) return(-1); // EOF? Stop here. + + if (scanbuffer[0] == '[') + { + i = 0; + while ((i < INIMAXLEN) && + (*(section + i) != 0) && + (*(section + i) == scanbuffer[i + 1])) i++; + if ((i < INIMAXLEN - 2) && (*(section + i) == 0)) + { + if ((scanbuffer[i + 1] == ']') && (scanbuffer[i + 2] == 0)) + { + retflag = 1; + } // ENDIF- End marks look good? Return successful. + } // ENDIF- Do we have a section match? + } // ENDIF- Does this look like a section header? + + if (retflag == 0) charcount += retval; + } // ENDWHILE- Scanning lines for the correct [Section] header. + + return(charcount); +} // END INIFindSection() + + +// Returns: number of bytes to get to start of keyword (or -1) +int INIFindKeyword(ACTUALHANDLE infile, char *keyword, char *buffer) +{ + int charcount; + int i; + int j; + int retflag; + int retval; + char scanbuffer[INIMAXLEN+1]; + +#ifdef VERBOSE_FUNCTION_INI + PrintLog("CDVDiso ini: FindKeyword(%s)", keyword); +#endif /* VERBOSE_FUNCTION_INI */ + + charcount = 0; + retflag = 0; + + while (retflag == 0) + { + retval = INIReadLine(infile, scanbuffer); + if (retval == 0) return(-1); // EOF? Stop here. + if (scanbuffer[0] == '[') return(-1); // New section? Stop here. + + i = 0; + while ((i < INIMAXLEN) && + (*(keyword + i) != 0) && + (*(keyword + i) == scanbuffer[i])) i++; + if ((i < INIMAXLEN - 2) && (*(keyword + i) == 0)) + { + if (scanbuffer[i] == '=') + { + retflag = 1; + if (buffer != NULL) + { + i++; + j = 0; + while ((i < INIMAXLEN) && (scanbuffer[i] != 0)) + { + *(buffer + j) = scanbuffer[i]; + i++; + j++; + } // ENDWHILE- Copying the value out to the outbound buffer. + *(buffer + j) = 0; // And 0-terminate. + } // ENDIF- Return the value as well? + } // ENDIF- End marks look good? Return successful. + } // ENDIF- Do we have a section match? + + if (retflag == 0) charcount += retval; + } // ENDWHILE- Scanning lines for the correct [Section] header. + +#ifdef VERBOSE_FUNCTION_INI + PrintLog("CDVDiso ini: Value: %s", buffer); +#endif /* VERBOSE_FUNCTION_INI */ + + return(charcount); +} // END INIFindKeyWord() + + +// Returns: number of bytes left to write... (from charcount back) +int INICopy(ACTUALHANDLE infile, ACTUALHANDLE outfile, int charcount) +{ + char buffer[4096]; + int i; + int chunk; + int retval; + +#ifdef VERBOSE_FUNCTION_INI + PrintLog("CDVDiso ini: Copy(%i)", charcount); +#endif /* VERBOSE_FUNCTION_INI */ + + i = charcount; + chunk = 4096; + if (i < chunk) chunk = i; + while (chunk > 0) + { + retval = ActualFileRead(infile, chunk, buffer); + if (retval <= 0) return(i); // Trouble? Stop here. + if (retval < chunk) chunk = retval; // Short block? Note it. + + retval = ActualFileWrite(outfile, chunk, buffer); + if (retval <= 0) return(i); // Trouble? Stop here. + i -= retval; + if (retval < chunk) return(i); // Short block written? Stop here. + + chunk = 4096; + if (i < chunk) chunk = i; + } // ENDWHILE- Copying a section of file across, one chunk at a time. + + return(0); +} // END INICopyToPos() + + +int INISaveString(char *file, char *section, char *keyword, char *value) +{ + char inname[INIMAXLEN+1]; + char outname[INIMAXLEN+1]; + int filepos; + ACTUALHANDLE infile; + ACTUALHANDLE outfile; + int i; + int retval; + char templine[INIMAXLEN+1]; + + if (file == NULL) return(-1); + if (section == NULL) return(-1); + if (keyword == NULL) return(-1); + if (value == NULL) return(-1); + +#ifdef VERBOSE_FUNCTION_INI + PrintLog("CDVDiso ini: SaveString(%s, %s, %s, %s)", + file, section, keyword, value); +#endif /* VERBOSE_FUNCTION_INI */ + + filepos = INIRemoveExt(file, inname); + for (i = 0; i <= filepos; i++) outname[i] = inname[i]; + INIAddInExt(inname, filepos); + INIAddOutExt(outname, filepos); + + filepos = 0; + infile = ActualFileOpenForRead(inname); + if (infile == ACTUALHANDLENULL) + { +#ifdef VERBOSE_FUNCTION_INI + PrintLog("CDVDiso ini: creating new file"); +#endif /* VERBOSE_FUNCTION_INI */ + outfile = ActualFileOpenForWrite(inname); + if (outfile == ACTUALHANDLENULL) return(-1); // Just a bad name? Abort. + + sprintf(templine, "[%s]\r\n", section); + i = 0; + while ((i < INIMAXLEN) && (templine[i] != 0)) i++; + retval = ActualFileWrite(outfile, i, templine); + if (retval < i) + { + ActualFileClose(outfile); + outfile = ACTUALHANDLENULL; + ActualFileDelete(inname); + return(-1); + } // ENDIF- Trouble writing it out? Abort. + + sprintf(templine, "%s=%s\r\n", keyword, value); + i = 0; + while ((i < INIMAXLEN) && (templine[i] != 0)) i++; + retval = ActualFileWrite(outfile, i, templine); + ActualFileClose(outfile); + outfile = ACTUALHANDLENULL; + if (retval < i) + { + ActualFileDelete(inname); + return(-1); + } // ENDIF- Trouble writing it out? Abort. + return(0); + } // ENDIF- No input file? Create a brand new .ini file then. + + retval = INIFindSection(infile, section); + if (retval < 0) + { +#ifdef VERBOSE_FUNCTION_INI + PrintLog("CDVDiso ini: creating new section"); +#endif /* VERBOSE_FUNCTION_INI */ + outfile = ActualFileOpenForWrite(outname); + if (outfile == ACTUALHANDLENULL) + { + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + return(-1); + } // ENDIF- Couldn't open a temp file? Abort + + ActualFileSeek(infile, 0); // Move ini to beginning of file... + INICopy(infile, outfile, 0x0FFFFFFF); // Copy the whole file out... + + sprintf(templine, "\r\n[%s]\r\n", section); + i = 0; + while ((i < INIMAXLEN) && (templine[i] != 0)) i++; + retval = ActualFileWrite(outfile, i, templine); + if (retval < i) + { + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + ActualFileClose(outfile); + outfile = ACTUALHANDLENULL; + ActualFileDelete(outname); + return(-1); + } // ENDIF- Trouble writing it out? Abort. + + sprintf(templine, "%s=%s\r\n", keyword, value); + i = 0; + while ((i < INIMAXLEN) && (templine[i] != 0)) i++; + retval = ActualFileWrite(outfile, i, templine); + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + ActualFileClose(outfile); + outfile = ACTUALHANDLENULL; + if (retval < i) + { + ActualFileDelete(outname); + return(-1); + } // ENDIF- Trouble writing it out? Abort. + + ActualFileDelete(inname); + ActualFileRename(outname, inname); + return(0); + } // ENDIF- Couldn't find the section? Make a new one! + + filepos = retval; + ActualFileSeek(infile, filepos); + filepos += INIReadLine(infile, templine); // Get section line's byte count + + retval = INIFindKeyword(infile, keyword, NULL); + if (retval < 0) + { +#ifdef VERBOSE_FUNCTION_INI + PrintLog("CDVDiso ini: creating new keyword"); +#endif /* VERBOSE_FUNCTION_INI */ + ActualFileSeek(infile, filepos); + retval = INIReadLine(infile, templine); + i = 0; + while ((i < INIMAXLEN) && (templine[i] != 0) && (templine[i] != '=')) i++; + while ((retval > 0) && (templine[i] == '=')) + { + filepos += retval; + retval = INIReadLine(infile, templine); + i = 0; + while ((i < INIMAXLEN) && (templine[i] != 0) && (templine[i] != '=')) i++; + } // ENDWHILE- skimming to the bottom of the section + + outfile = ActualFileOpenForWrite(outname); + if (outfile == ACTUALHANDLENULL) + { + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + return(-1); + } // ENDIF- Couldn't open a temp file? Abort + + ActualFileSeek(infile, 0); + retval = INICopy(infile, outfile, filepos); + if (retval > 0) + { + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + ActualFileClose(outfile); + outfile = ACTUALHANDLENULL; + ActualFileDelete(outname); + return(-1); + } // ENDIF- Trouble writing everything up to keyword? Abort. + + sprintf(templine, "%s=%s\r\n", keyword, value); + i = 0; + while ((i < INIMAXLEN) && (templine[i] != 0)) i++; + retval = ActualFileWrite(outfile, i, templine); + if (retval < i) + { + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + ActualFileClose(outfile); + outfile = ACTUALHANDLENULL; + ActualFileDelete(outname); + return(-1); + } // ENDIF- Trouble writing it out? Abort. + + } + else + { +#ifdef VERBOSE_FUNCTION_INI + PrintLog("CDVDiso ini: replacing keyword"); +#endif /* VERBOSE_FUNCTION_INI */ + filepos += retval; // Position just before old version of keyword + + outfile = ActualFileOpenForWrite(outname); + if (outfile == ACTUALHANDLENULL) + { + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + return(-1); + } // ENDIF- Couldn't open a temp file? Abort + + ActualFileSeek(infile, 0); + retval = INICopy(infile, outfile, filepos); + if (retval > 0) + { + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + ActualFileClose(outfile); + outfile = ACTUALHANDLENULL; + ActualFileDelete(outname); + return(-1); + } // ENDIF- Trouble writing everything up to keyword? Abort. + + INIReadLine(infile, templine); // Read past old keyword/value... + + // Replace with new value + sprintf(templine, "%s=%s\r\n", keyword, value); + i = 0; + while ((i < INIMAXLEN) && (templine[i] != 0)) i++; + retval = ActualFileWrite(outfile, i, templine); + if (retval < i) + { + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + ActualFileClose(outfile); + outfile = ACTUALHANDLENULL; + ActualFileDelete(outname); + return(-1); + } // ENDIF- Trouble writing it out? Abort. + } // ENDIF- Need to add a new keyword? + + INICopy(infile, outfile, 0xFFFFFFF); // Write out rest of file + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + ActualFileClose(outfile); + outfile = ACTUALHANDLENULL; + ActualFileDelete(inname); + ActualFileRename(outname, inname); + return(0); +} // END INISaveString() + + +int INILoadString(char *file, char *section, char *keyword, char *buffer) +{ + char inname[INIMAXLEN+1]; + int filepos; + ACTUALHANDLE infile; + int retval; + + if (file == NULL) return(-1); + if (section == NULL) return(-1); + if (keyword == NULL) return(-1); + if (buffer == NULL) return(-1); + +#ifdef VERBOSE_FUNCTION_INI + PrintLog("CDVDiso ini: LoadString(%s, %s, %s)", + file, section, keyword); +#endif /* VERBOSE_FUNCTION_INI */ + + filepos = INIRemoveExt(file, inname); + INIAddInExt(inname, filepos); + + filepos = 0; + infile = ActualFileOpenForRead(inname); + if (infile == ACTUALHANDLENULL) return(-1); + + retval = INIFindSection(infile, section); + if (retval < 0) + { + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + return(-1); + } // ENDIF- Didn't find it? Abort. + + retval = INIFindKeyword(infile, keyword, buffer); + if (retval < 0) + { + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + return(-1); + } // ENDIF- Didn't find it? Abort. + + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + return(0); +} // END INILoadString() + + +int INIRemove(char *file, char *section, char *keyword) +{ + char inname[INIMAXLEN+1]; + char outname[INIMAXLEN+1]; + int filepos; + ACTUALHANDLE infile; + ACTUALHANDLE outfile; + char templine[INIMAXLEN+1]; + int i; + int retval; + + if (file == NULL) return(-1); + if (section == NULL) return(-1); + +#ifdef VERBOSE_FUNCTION_INI + PrintLog("CDVDiso ini: Remove(%s, %s, %s)", + file, section, keyword); +#endif /* VERBOSE_FUNCTION_INI */ + + filepos = INIRemoveExt(file, inname); + for (i = 0; i <= filepos; i++) outname[i] = inname[i]; + INIAddInExt(inname, filepos); + INIAddOutExt(outname, filepos); + + infile = ActualFileOpenForRead(inname); + if (infile == ACTUALHANDLENULL) return(-1); + + retval = INIFindSection(infile, section); + if (retval == -1) + { + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + return(-1); + } // ENDIF- Couldn't even find the section? Abort + + filepos = retval; + if (keyword == NULL) + { +#ifdef VERBOSE_FUNCTION_INI + PrintLog("CDVDiso ini: removing section"); +#endif /* VERBOSE_FUNCTION_INI */ + outfile = ActualFileOpenForWrite(outname); + if (outfile == ACTUALHANDLENULL) + { + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + return(-1); + } // ENDIF- Couldn't open a temp file? Abort + + ActualFileSeek(infile, 0); + retval = INICopy(infile, outfile, filepos); + if (retval > 0) + { + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + ActualFileClose(outfile); + outfile = ACTUALHANDLENULL; + ActualFileDelete(outname); + return(-1); + } // ENDIF- Trouble writing everything up to the section? Abort. + + templine[0] = 0; + retval = 1; + while ((retval > 0) && (templine[0] != '[')) + { + retval = INIReadLine(infile, templine); + } // ENDWHILE- Read to the start of the next section... or EOF. + + if (templine[0] == '[') + { + i = 0; + while ((i < INIMAXLEN) && (templine[i] != 0)) i++; + retval = ActualFileWrite(outfile, i, templine); + if (retval < i) + { + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + ActualFileClose(outfile); + outfile = ACTUALHANDLENULL; + ActualFileDelete(outname); + return(-1); + } // ENDIF- Trouble writing it out? Abort. + } // ENDIF- Are there other sections after this one? Save them then. + + } + else + { + filepos = retval; + ActualFileSeek(infile, filepos); + filepos += INIReadLine(infile, templine); // Get section line's byte count + + retval = INIFindKeyword(infile, keyword, NULL); + if (retval == -1) + { + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + return(-1); + } // ENDIF- Couldn't find the keyword? Abort + filepos += retval; + +#ifdef VERBOSE_FUNCTION_INI + PrintLog("CDVDiso ini: removing keyword"); +#endif /* VERBOSE_FUNCTION_INI */ + outfile = ActualFileOpenForWrite(outname); + if (outfile == ACTUALHANDLENULL) + { + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + return(-1); + } // ENDIF- Couldn't open a temp file? Abort + + ActualFileSeek(infile, 0); + retval = INICopy(infile, outfile, filepos); + if (retval > 0) + { + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + ActualFileClose(outfile); + outfile = ACTUALHANDLENULL; + ActualFileDelete(outname); + return(-1); + } // ENDIF- Trouble writing everything up to keyword? Abort. + + INIReadLine(infile, templine); // Read (and discard) the keyword line + } // ENDIF- Wipe out the whole section? Or just a keyword? + + INICopy(infile, outfile, 0xFFFFFFF); // Write out rest of file + ActualFileClose(infile); + infile = ACTUALHANDLENULL; + ActualFileClose(outfile); + outfile = ACTUALHANDLENULL; + ActualFileDelete(inname); + ActualFileRename(outname, inname); + return(0); +} // END INIRemove() + + +int INISaveUInt(char *file, char *section, char *keyword, unsigned int value) +{ + char numvalue[INIMAXLEN+1]; + + sprintf(numvalue, "%u", value); + return(INISaveString(file, section, keyword, numvalue)); +} // END INISaveUInt() + + +int INILoadUInt(char *file, char *section, char *keyword, unsigned int *buffer) +{ + char numvalue[INIMAXLEN+1]; + int retval; + unsigned int value; + // unsigned int sign; // Not needed in unsigned numbers + int pos; + + if (buffer == NULL) return(-1); + *(buffer) = 0; + + retval = INILoadString(file, section, keyword, numvalue); + if (retval < 0) return(retval); + + value = 0; + // sign = 1; // Start positive + pos = 0; + + // Note: skip leading spaces? (Shouldn't have to, I hope) + + // if(numvalue[pos] == '-') { + // pos++; + // sign = -1; + // } // ENDIF- Negative sign check + + while ((pos < INIMAXLEN) && (numvalue[pos] != 0)) + { + if (value > (0xFFFFFFFF / 10)) return(-1); // Overflow? + + if ((numvalue[pos] >= '0') && (numvalue[pos] <= '9')) + { + value *= 10; + value += numvalue[pos] - '0'; + pos++; + } + else + { + numvalue[pos] = 0; + } // ENDIF- Add a digit in? Or stop searching for digits? + } // ENDWHILE- Adding digits of info to our ever-increasing value + + // value *= sign + *(buffer) = value; + return(0); +} // END INILoadUInt() diff --git a/plugins/CDVDisoEFP/src/ini.h b/plugins/CDVDisoEFP/src/ini.h index a666f99659..3ade472613 100644 --- a/plugins/CDVDisoEFP/src/ini.h +++ b/plugins/CDVDisoEFP/src/ini.h @@ -1,128 +1,64 @@ -/* ini.h - - * Copyright (C) 2002-2005 PCSX2 Team - - * - - * This program is free software; you can redistribute it and/or modify - - * it under the terms of the GNU General Public License as published by - - * the Free Software Foundation; either version 2 of the License, or - - * (at your option) any later version. - - * - - * This program is distributed in the hope that it will be useful, - - * but WITHOUT ANY WARRANTY; without even the implied warranty of - - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - - * GNU General Public License for more details. - - * - - * You should have received a copy of the GNU General Public License - - * along with this program; if not, write to the Free Software - - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - * - - * PCSX2 members can be contacted through their website at www.pcsx2.net. - - */ - - - - - -#ifndef INI_H - -#define INI_H - - - - - -// #ifndef __LINUX__ - -// #ifdef __linux__ - -// #define __LINUX__ - -// #endif /* __linux__ */ - -// #endif /* No __LINUX__ */ - - - -// #define CDVDdefs - -// #include "PS2Edefs.h" - - - - - -// File format: - -// [section] - -// keyword=value - - - -// file - Name of the INI file - -// section - Section within the file - -// keyword - Identifier for a value - -// value - value to store with a keyword in a section in the file - -// buffer - place to retrieve the value of a keyword - - - -// return values: 0 = success, -1 = failure - - - - - -// #define VERBOSE_FUNCTION_INI - - - -#define INIMAXLEN 255 - - - - - -extern int INISaveString(char *file, char *section, char *keyword, char *value); - -extern int INILoadString(char *file, char *section, char *keyword, char *buffer); - - - -extern int INISaveUInt(char *file, char *section, char *keyword, unsigned int value); - -extern int INILoadUInt(char *file, char *section, char *keyword, unsigned int *buffer); - - - -// NULL in the keyword below removes the whole section. - -extern int INIRemove(char *file, char *section, char *keyword); - - - - - -#endif /* INI_H */ - +/* ini.h + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +#ifndef INI_H +#define INI_H + + +// #ifndef __LINUX__ +// #ifdef __linux__ +// #define __LINUX__ +// #endif /* __linux__ */ +// #endif /* No __LINUX__ */ + +// #define CDVDdefs +// #include "PS2Edefs.h" + + +// File format: +// [section] +// keyword=value + +// file - Name of the INI file +// section - Section within the file +// keyword - Identifier for a value +// value - value to store with a keyword in a section in the file +// buffer - place to retrieve the value of a keyword + +// return values: 0 = success, -1 = failure + + +// #define VERBOSE_FUNCTION_INI + +#define INIMAXLEN 255 + + +extern int INISaveString(char *file, char *section, char *keyword, char *value); +extern int INILoadString(char *file, char *section, char *keyword, char *buffer); + +extern int INISaveUInt(char *file, char *section, char *keyword, unsigned int value); +extern int INILoadUInt(char *file, char *section, char *keyword, unsigned int *buffer); + +// NULL in the keyword below removes the whole section. +extern int INIRemove(char *file, char *section, char *keyword); + + +#endif /* INI_H */ diff --git a/plugins/CDVDisoEFP/src/isocompress.c b/plugins/CDVDisoEFP/src/isocompress.c index 4ed3c21579..96d4c0a100 100644 --- a/plugins/CDVDisoEFP/src/isocompress.c +++ b/plugins/CDVDisoEFP/src/isocompress.c @@ -1,914 +1,484 @@ /* isocompress.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include // NULL - - // #ifndef __LINUX__ - // #ifdef __linux__ - // #define __LINUX__ - // #endif /* __linux__ */ - // #endif /* No __LINUX__ */ - - // #define CDVDdefs - // #include "PS2Edefs.h" - - - #include "logfile.h" - #include "isofile.h" - #include "actualfile.h" - #include "gzipv1.h" - #include "blockv2.h" - #include "gzipv2.h" - #include "bzip2v2.h" - #include "bzip2v3.h" - #include "isocompress.h" - - - - -const char *compressnames[] = { - - "No Compression", - - ".Z (zlib) for speed", - - ".BZ2 (bzip2) for speed", - - ".bz2 (bzip2) for size", - - NULL }; // Compress types 0, 3, 4, and 5 - - - -const char *compressdesc[] = { - - "", - - " zlib orig", - - " block.dump", - - " zlib speed", - - " bzip2 speed", - - " bzip2 size", - - NULL }; - - - -const char *compressid[] = { - - "BVD2", - - "Z V2", - - "BZV2", - - "BZV3", - - NULL }; // Starts at compress type 2 - - - -struct CompressExt compressext[] = { - - { ".z", 1 }, - - { ".Z", 1 }, - - { ".bz2", 5 }, - - { ".BZ2", 3 }, - - { ".bZ2", 3 }, - - { ".Bz2", 3 }, - - { ".bz", 3 }, - - { ".BZ", 3 }, - - { ".bZ", 3 }, - - { ".Bz", 3 }, - - { ".dump", 2 }, - - { NULL, 0 } - +const char *compressnames[] = +{ + "No Compression", + ".Z (zlib) for speed", + ".BZ2 (bzip2) for speed", + ".bz2 (bzip2) for size", + NULL +}; // Compress types 0, 3, 4, and 5 +const char *compressdesc[] = +{ + "", + " zlib orig", + " block.dump", + " zlib speed", + " bzip2 speed", + " bzip2 size", + NULL }; +const char *compressid[] = +{ + "BVD2", + "Z V2", + "BZV2", + "BZV3", + NULL +}; // Starts at compress type 2 +struct CompressExt compressext[] = +{ + { ".z", 1 }, + { ".Z", 1 }, + { ".bz2", 5 }, + { ".BZ2", 3 }, + { ".bZ2", 3 }, + { ".Bz2", 3 }, + { ".bz", 3 }, + { ".BZ", 3 }, + { ".bZ", 3 }, + { ".Bz", 3 }, + { ".dump", 2 }, + { NULL, 0 } +}; - - - -int IsoNameStripCompress(struct IsoFile *isofile) { - - int tempext; - - int tempnamepos; - - int tempextpos; - - int retmethod; - - - - retmethod = 0; - - tempext = 0; - - while(compressext[tempext].name != NULL) { - - tempextpos = 0; - - while(*(compressext[tempext].name + tempextpos) != 0) tempextpos++; - - - - tempnamepos = isofile->namepos; - - while((tempnamepos > 0) && (tempextpos > 0) && - - (isofile->name[tempnamepos - 1] == *(compressext[tempext].name + tempextpos - 1))) { - - tempnamepos--; - - tempextpos--; - - } // ENDWHILE- Comparing one extension to the end of the file name - - if(tempextpos == 0) { - - isofile->namepos = tempnamepos; // Move name pointer in front of ext. - - return(compressext[tempext].method); // Found a match... say which one. - - } else { - - tempext++; // Next ext in the list to test... - - } // ENDIF- Did we find a match? - - } // ENDWHILE- looking through extension list - - - - return(0); // No compress extension found. - +int IsoNameStripCompress(struct IsoFile *isofile) +{ + int tempext; + int tempnamepos; + int tempextpos; + int retmethod; + retmethod = 0; + tempext = 0; + while (compressext[tempext].name != NULL) + { + tempextpos = 0; + while (*(compressext[tempext].name + tempextpos) != 0) tempextpos++; + tempnamepos = isofile->namepos; + while ((tempnamepos > 0) && (tempextpos > 0) && + (isofile->name[tempnamepos - 1] == *(compressext[tempext].name + tempextpos - 1))) + { + tempnamepos--; + tempextpos--; + } // ENDWHILE- Comparing one extension to the end of the file name + if (tempextpos == 0) + { + isofile->namepos = tempnamepos; // Move name pointer in front of ext. + return(compressext[tempext].method); // Found a match... say which one. + } + else + { + tempext++; // Next ext in the list to test... + } // ENDIF- Did we find a match? + } // ENDWHILE- looking through extension list + return(0); // No compress extension found. } // END IsoNameStripCompress() - - - - -int CompressOpenForRead(struct IsoFile *isofile) { - - int retval; - - +int CompressOpenForRead(struct IsoFile *isofile) +{ + int retval; #ifdef VERBOSE_FUNCTION_ISOCOMPRESS - - PrintLog("CDVDiso compress: OpenForRead()"); - + PrintLog("CDVDiso compress: OpenForRead()"); #endif /* VERBOSE_FUNCTION_ISOCOMPRESS */ + switch (isofile->compress) + { + case 1: + retval = GZipV1OpenForRead(isofile); + if (retval >= 0) retval = GZipV1OpenTableForRead(isofile); + break; + case 2: + retval = BlockV2OpenForRead(isofile); + if (retval >= 0) retval = BlockV2OpenTableForRead(isofile); + break; + case 3: + retval = GZipV2OpenForRead(isofile); + if (retval >= 0) retval = GZipV2OpenTableForRead(isofile); + break; + case 4: + retval = BZip2V2OpenForRead(isofile); + if (retval >= 0) retval = BZip2V2OpenTableForRead(isofile); + break; + case 5: + retval = BZip2V3OpenForRead(isofile); + if (retval >= 0) retval = BZip2V3OpenTableForRead(isofile); + break; + default: + retval = -1; + break; + } // ENDSWITCH compress- which method do we try to get header info from? - - switch(isofile->compress) { - - case 1: - - retval = GZipV1OpenForRead(isofile); - - if(retval >= 0) retval = GZipV1OpenTableForRead(isofile); - - break; - - case 2: - - retval = BlockV2OpenForRead(isofile); - - if(retval >= 0) retval = BlockV2OpenTableForRead(isofile); - - break; - - case 3: - - retval = GZipV2OpenForRead(isofile); - - if(retval >= 0) retval = GZipV2OpenTableForRead(isofile); - - break; - - case 4: - - retval = BZip2V2OpenForRead(isofile); - - if(retval >= 0) retval = BZip2V2OpenTableForRead(isofile); - - break; - - case 5: - - retval = BZip2V3OpenForRead(isofile); - - if(retval >= 0) retval = BZip2V3OpenTableForRead(isofile); - - break; - - default: - - retval = -1; - - break; - - } // ENDSWITCH compress- which method do we try to get header info from? - - - - return(retval); - + return(retval); } // END CompressOpenForRead() - - - - -int CompressSeek(struct IsoFile *isofile, off64_t sector) { - - int retval; - - - +int CompressSeek(struct IsoFile *isofile, off64_t sector) +{ + int retval; #ifdef VERBOSE_FUNCTION_ISOCOMPRESS - - PrintLog("CDVDiso compress: Seek(%lli)", sector); - + PrintLog("CDVDiso compress: Seek(%lli)", sector); #endif /* VERBOSE_FUNCTION_ISOCOMPRESS */ + switch (isofile->compress) + { + case 1: + retval = GZipV1SeekTable(isofile, sector); + break; + case 2: + retval = BlockV2SeekTable(isofile, sector); + break; + case 3: + retval = GZipV2SeekTable(isofile, sector); + break; + case 4: + retval = BZip2V2SeekTable(isofile, sector); + break; + case 5: + retval = BZip2V3SeekTable(isofile, sector); + break; + default: + retval = -1; + break; + } // ENDSWITCH compress- which method do we try to get header info from? - - - switch(isofile->compress) { - - case 1: - - retval = GZipV1SeekTable(isofile, sector); - - break; - - case 2: - - retval = BlockV2SeekTable(isofile, sector); - - break; - - case 3: - - retval = GZipV2SeekTable(isofile, sector); - - break; - - case 4: - - retval = BZip2V2SeekTable(isofile, sector); - - break; - - case 5: - - retval = BZip2V3SeekTable(isofile, sector); - - break; - - default: - - retval = -1; - - break; - - } // ENDSWITCH compress- which method do we try to get header info from? - - - - return(retval); - + return(retval); } // END CompressSeek() - - - - -int CompressRead(struct IsoFile *isofile, char *buffer) { - - struct TableData table; - - int retval; - - int compptr; - - int i; - - +int CompressRead(struct IsoFile *isofile, char *buffer) +{ + struct TableData table; + int retval; + int compptr; + int i; #ifdef VERBOSE_FUNCTION_ISOCOMPRESS - - PrintLog("CDVDiso compress: Read()"); - + PrintLog("CDVDiso compress: Read()"); #endif /* VERBOSE_FUNCTION_ISOCOMPRESS */ - - - switch(isofile->compress) { - - case 1: - - retval = GZipV1ReadTable(isofile, &table); - - if(retval >= 0) { - - if(table.offset != isofile->filebytepos) { - - retval = GZipV1Seek(isofile, table.offset); - - } // ENDIF- The data file not in position? - - } // ENDIF- Did we get a table entry? - - if(retval >= 0) { - - retval = GZipV1Read(isofile, table.size, buffer); - - } // ENDIF- Are we still on track? - - break; - - - - case 2: - - retval = BlockV2ReadTable(isofile, &table); - - if(retval >= 0) { - - if(table.offset != isofile->filebytepos) { - - retval = BlockV2Seek(isofile, table.offset); - - } // ENDIF- The data file not in position? - - } // ENDIF- Did we get a table entry? - - if(retval >= 0) { - - retval = BlockV2Read(isofile, table.size, buffer); - - } // ENDIF- Are we still on track? - - break; - - - - - - case 3: - - retval = GZipV2ReadTable(isofile, &table); - - if(retval >= 0) { - - if(table.offset != isofile->filebytepos) { - - retval = GZipV2Seek(isofile, table.offset); - - } // ENDIF- The data file not in position? - - } // ENDIF- Did we get a table entry? - - if(retval >= 0) { - - retval = GZipV2Read(isofile, table.size, buffer); - - } // ENDIF- Are we still on track? - - break; - - - - case 4: - - retval = 0; - - if((isofile->filesectorpos < isofile->compsector) || - - (isofile->filesectorpos > isofile->compsector + isofile->numsectors - 1)) { - - - - retval = BZip2V2ReadTable(isofile, &table); - - if(retval >= 0) { - - if(table.offset != isofile->filebytepos) { - - retval = BZip2V2Seek(isofile, table.offset); - - } // ENDIF- The data file not in position? - - } // ENDIF- Did we get a table entry? - - if(retval >= 0) { - - retval = BZip2V2Read(isofile, table.size, isofile->compblock); - - isofile->compsector = isofile->filesectorpos / isofile->numsectors; - - isofile->compsector *= isofile->numsectors; - - } // ENDIF- Are we still on track? - - } // ENDIF- Did we have to read in another block? - - - - if(retval >= 0) { - - compptr = isofile->filesectorpos - isofile->compsector; - - compptr *= isofile->blocksize; - - if((compptr < 0) || (compptr > (65535 - isofile->blocksize))) { - - retval = -1; - - } else { - - for(i = 0; i < isofile->blocksize; i++) - - *(buffer + i) = isofile->compblock[compptr + i]; - - isofile->filesectorpos++; - - } // ENDIF- Not a good buffer pointer? Say so. - - } // ENDIF- Do we have a valid buffer to draw from? - - break; - - - - case 5: - - retval = 0; - - if((isofile->filesectorpos < isofile->compsector) || - - (isofile->filesectorpos > isofile->compsector + isofile->numsectors - 1)) { - - - - if(isofile->filesectorpos != isofile->compsector + isofile->numsectors) { - - retval = BZip2V3ReadTable(isofile, &table); - - if(retval >= 0) { - - if(table.offset != isofile->filebytepos) { - - retval = BZip2V3Seek(isofile, table.offset); - - } // ENDIF- The data file not in position? - - } // ENDIF- Did we get a table entry? - - } // ENDIF- Not the next block in the batch? Seek then. - - - - if(retval >= 0) { - - retval = BZip2V3Read(isofile, 0, isofile->compblock); - - isofile->compsector = isofile->filesectorpos / isofile->numsectors; - - isofile->compsector *= isofile->numsectors; - - } // ENDIF- Are we still on track? - - } // ENDIF- Did we have to read in another block? - - - - if(retval >= 0) { - - compptr = isofile->filesectorpos - isofile->compsector; - - compptr *= isofile->blocksize; - - if((compptr < 0) || (compptr > (65535 - isofile->blocksize))) { - - retval = -1; - - } else { - - for(i = 0; i < isofile->blocksize; i++) - - *(buffer + i) = isofile->compblock[compptr + i]; - - isofile->filesectorpos++; - - } // ENDIF- Not a good buffer pointer? Say so. - - } // ENDIF- Do we have a valid buffer to draw from? - - break; - - - - default: - - retval = -1; - - break; - - } // ENDSWITCH compress- which method do we try to get header info from? - - - - if(retval >= 0) retval = isofile->blocksize; - - return(retval); - + switch (isofile->compress) + { + case 1: + retval = GZipV1ReadTable(isofile, &table); + if (retval >= 0) + { + if (table.offset != isofile->filebytepos) + { + retval = GZipV1Seek(isofile, table.offset); + } // ENDIF- The data file not in position? + } // ENDIF- Did we get a table entry? + if (retval >= 0) + { + retval = GZipV1Read(isofile, table.size, buffer); + } // ENDIF- Are we still on track? + break; + case 2: + retval = BlockV2ReadTable(isofile, &table); + if (retval >= 0) + { + if (table.offset != isofile->filebytepos) + { + retval = BlockV2Seek(isofile, table.offset); + } // ENDIF- The data file not in position? + } // ENDIF- Did we get a table entry? + if (retval >= 0) + { + retval = BlockV2Read(isofile, table.size, buffer); + } // ENDIF- Are we still on track? + break; + + case 3: + retval = GZipV2ReadTable(isofile, &table); + if (retval >= 0) + { + if (table.offset != isofile->filebytepos) + { + retval = GZipV2Seek(isofile, table.offset); + } // ENDIF- The data file not in position? + } // ENDIF- Did we get a table entry? + if (retval >= 0) + { + retval = GZipV2Read(isofile, table.size, buffer); + } // ENDIF- Are we still on track? + break; + + case 4: + retval = 0; + if ((isofile->filesectorpos < isofile->compsector) || + (isofile->filesectorpos > isofile->compsector + isofile->numsectors - 1)) + { + retval = BZip2V2ReadTable(isofile, &table); + if (retval >= 0) + { + if (table.offset != isofile->filebytepos) + { + retval = BZip2V2Seek(isofile, table.offset); + } // ENDIF- The data file not in position? + } // ENDIF- Did we get a table entry? + if (retval >= 0) + { + retval = BZip2V2Read(isofile, table.size, isofile->compblock); + isofile->compsector = isofile->filesectorpos / isofile->numsectors; + isofile->compsector *= isofile->numsectors; + } // ENDIF- Are we still on track? + } // ENDIF- Did we have to read in another block? + + if (retval >= 0) + { + compptr = isofile->filesectorpos - isofile->compsector; + compptr *= isofile->blocksize; + if ((compptr < 0) || (compptr > (65535 - isofile->blocksize))) + { + retval = -1; + } + else + { + for (i = 0; i < isofile->blocksize; i++) + *(buffer + i) = isofile->compblock[compptr + i]; + isofile->filesectorpos++; + } // ENDIF- Not a good buffer pointer? Say so. + } // ENDIF- Do we have a valid buffer to draw from? + break; + case 5: + retval = 0; + if ((isofile->filesectorpos < isofile->compsector) || + (isofile->filesectorpos > isofile->compsector + isofile->numsectors - 1)) + { + + if (isofile->filesectorpos != isofile->compsector + isofile->numsectors) + { + retval = BZip2V3ReadTable(isofile, &table); + if (retval >= 0) + { + if (table.offset != isofile->filebytepos) + { + retval = BZip2V3Seek(isofile, table.offset); + } // ENDIF- The data file not in position? + } // ENDIF- Did we get a table entry? + } // ENDIF- Not the next block in the batch? Seek then. + if (retval >= 0) + { + retval = BZip2V3Read(isofile, 0, isofile->compblock); + isofile->compsector = isofile->filesectorpos / isofile->numsectors; + isofile->compsector *= isofile->numsectors; + } // ENDIF- Are we still on track? + } // ENDIF- Did we have to read in another block? + + if (retval >= 0) + { + compptr = isofile->filesectorpos - isofile->compsector; + compptr *= isofile->blocksize; + if ((compptr < 0) || (compptr > (65535 - isofile->blocksize))) + { + retval = -1; + } + else + { + for (i = 0; i < isofile->blocksize; i++) + *(buffer + i) = isofile->compblock[compptr + i]; + isofile->filesectorpos++; + } // ENDIF- Not a good buffer pointer? Say so. + } // ENDIF- Do we have a valid buffer to draw from? + break; + default: + retval = -1; + break; + } // ENDSWITCH compress- which method do we try to get header info from? + + if (retval >= 0) retval = isofile->blocksize; + return(retval); } // END CompressRead() - - - - -void CompressClose(struct IsoFile *isofile) { - - int retval; - - +void CompressClose(struct IsoFile *isofile) +{ + int retval; #ifdef VERBOSE_FUNCTION_ISOCOMPRESS - - PrintLog("CDVDiso compress: Close()"); - + PrintLog("CDVDiso compress: Close()"); #endif /* VERBOSE_FUNCTION_ISOCOMPRESS */ - - - switch(isofile->compress) { - - case 1: - - GZipV1Close(isofile); - - break; - - case 2: - - BlockV2Close(isofile); - - break; - - case 3: - - GZipV2Close(isofile); - - break; - - case 4: - - BZip2V2Close(isofile); - - break; - - case 5: - - BZip2V3Close(isofile); - - break; - - default: - - retval = -1; - - break; - - } // ENDSWITCH compress- which method do we try to get header info from? - - - - return; - + switch (isofile->compress) + { + case 1: + GZipV1Close(isofile); + break; + case 2: + BlockV2Close(isofile); + break; + case 3: + GZipV2Close(isofile); + break; + case 4: + BZip2V2Close(isofile); + break; + case 5: + BZip2V3Close(isofile); + break; + default: + retval = -1; + break; + } // ENDSWITCH compress- which method do we try to get header info from? + return; } // END CompressClose() - - - - -int CompressOpenForWrite(struct IsoFile *isofile) { - - int retval; - - +int CompressOpenForWrite(struct IsoFile *isofile) +{ + int retval; #ifdef VERBOSE_FUNCTION_ISOCOMPRESS - - PrintLog("CDVDiso compress: OpenForWrite()"); - + PrintLog("CDVDiso compress: OpenForWrite()"); #endif /* VERBOSE_FUNCTION_ISOCOMPRESS */ - - - switch(isofile->compress) { - - case 1: - - retval = GZipV1OpenForWrite(isofile); - - if(retval >= 0) retval = GZipV1OpenTableForWrite(isofile); - - break; - - case 2: - - retval = -1; - - break; - - case 3: - - retval = GZipV2OpenForWrite(isofile); - - if(retval >= 0) retval = GZipV2OpenTableForWrite(isofile); - - break; - - case 4: - - retval = BZip2V2OpenForWrite(isofile); - - if(retval >= 0) retval = BZip2V2OpenTableForWrite(isofile); - - break; - - case 5: - - retval = BZip2V3OpenForWrite(isofile); - - if(retval >= 0) retval = BZip2V3OpenTableForWrite(isofile); - - break; - - default: - - retval = -1; - - break; - - } // ENDSWITCH compress- which method do we try to get header info from? - - - - return(retval); - + switch (isofile->compress) + { + case 1: + retval = GZipV1OpenForWrite(isofile); + if (retval >= 0) retval = GZipV1OpenTableForWrite(isofile); + break; + case 2: + retval = -1; + break; + case 3: + retval = GZipV2OpenForWrite(isofile); + if (retval >= 0) retval = GZipV2OpenTableForWrite(isofile); + break; + case 4: + retval = BZip2V2OpenForWrite(isofile); + if (retval >= 0) retval = BZip2V2OpenTableForWrite(isofile); + break; + case 5: + retval = BZip2V3OpenForWrite(isofile); + if (retval >= 0) retval = BZip2V3OpenTableForWrite(isofile); + break; + default: + retval = -1; + break; + } // ENDSWITCH compress- which method do we try to get header info from? + return(retval); } // END CompressOpenForWrite() - - - - -int CompressWrite(struct IsoFile *isofile, char *buffer) { - - struct TableData table; - - int compptr; - - int retval; - - int i; - - - +int CompressWrite(struct IsoFile *isofile, char *buffer) +{ + struct TableData table; + int compptr; + int retval; + int i; #ifdef VERBOSE_FUNCTION_ISOCOMPRESS - - PrintLog("CDVDiso compress: Write()"); - + PrintLog("CDVDiso compress: Write()"); #endif /* VERBOSE_FUNCTION_ISOCOMPRESS */ - - - - switch(isofile->compress) { - - case 1: - - retval = GZipV1Write(isofile, buffer); - - if(retval > 0) { - - table.offset = isofile->filebytepos - retval; - - table.size = retval; - - retval = GZipV1WriteTable(isofile, table); - - } // ENDIF- Wrote the data out? Update the table as well. - - break; - - - - case 2: - - retval = -1; - - break; - - - - case 3: - - retval = GZipV2Write(isofile, buffer); - - if(retval > 0) { - - table.offset = isofile->filebytepos - retval; - - table.size = retval; - - retval = GZipV2WriteTable(isofile, table); - - } // ENDIF- Wrote the data out? Update the table as well. - - break; - - - - case 4: - - retval = 0; - - if((isofile->filesectorpos < isofile->compsector) || - - (isofile->filesectorpos > isofile->compsector + isofile->numsectors - 1)) { - - retval = BZip2V2Write(isofile, isofile->compblock); - - isofile->compsector += isofile->numsectors; - - if(retval > 0) { - - table.offset = isofile->filebytepos - retval; - - table.size = retval; - - retval = BZip2V2WriteTable(isofile, table); - - } // ENDIF- Wrote the data out? Update the table as well. - - } // ENDIF- Do we have a full buffer to write out? - - - - if(retval >= 0) { - - compptr = isofile->filesectorpos - isofile->compsector; - - compptr *= isofile->blocksize; - - for(i = 0; i < isofile->blocksize; i++) - - isofile->compblock[compptr + i] = *(buffer + i); - - } // ENDIF- Do we have a valid buffer to draw from? - - isofile->filesectorpos++; - - break; - - - - case 5: - - retval = 0; - - if((isofile->filesectorpos < isofile->compsector) || - - (isofile->filesectorpos > isofile->compsector + isofile->numsectors - 1)) { - - retval = BZip2V3Write(isofile, isofile->compblock); - - isofile->compsector += isofile->numsectors; - - if(retval > 0) { - - table.offset = isofile->filebytepos - retval; - - table.size = retval; - - retval = BZip2V3WriteTable(isofile, table); - - } // ENDIF- Wrote the data out? Update the table as well. - - } // ENDIF- Do we have a full buffer to write out? - - - - if(retval >= 0) { - - compptr = isofile->filesectorpos - isofile->compsector; - - compptr *= isofile->blocksize; - - for(i = 0; i < isofile->blocksize; i++) - - isofile->compblock[compptr + i] = *(buffer + i); - - } // ENDIF- Do we have a valid buffer to draw from? - - isofile->filesectorpos++; - - break; - - - - default: - - retval = -1; - - break; - - } // ENDSWITCH compress- which method do we try to get header info from? - - - - if(retval >= 0) retval = isofile->blocksize; - - return(retval); - + switch (isofile->compress) + { + case 1: + retval = GZipV1Write(isofile, buffer); + if (retval > 0) + { + table.offset = isofile->filebytepos - retval; + table.size = retval; + retval = GZipV1WriteTable(isofile, table); + } // ENDIF- Wrote the data out? Update the table as well. + break; + case 2: + retval = -1; + break; + case 3: + retval = GZipV2Write(isofile, buffer); + if (retval > 0) + { + table.offset = isofile->filebytepos - retval; + table.size = retval; + retval = GZipV2WriteTable(isofile, table); + } // ENDIF- Wrote the data out? Update the table as well. + break; + + case 4: + retval = 0; + if ((isofile->filesectorpos < isofile->compsector) || + (isofile->filesectorpos > isofile->compsector + isofile->numsectors - 1)) + { + retval = BZip2V2Write(isofile, isofile->compblock); + isofile->compsector += isofile->numsectors; + if (retval > 0) + { + table.offset = isofile->filebytepos - retval; + table.size = retval; + retval = BZip2V2WriteTable(isofile, table); + } // ENDIF- Wrote the data out? Update the table as well. + } // ENDIF- Do we have a full buffer to write out? + if (retval >= 0) + { + compptr = isofile->filesectorpos - isofile->compsector; + compptr *= isofile->blocksize; + for (i = 0; i < isofile->blocksize; i++) + isofile->compblock[compptr + i] = *(buffer + i); + } // ENDIF- Do we have a valid buffer to draw from? + isofile->filesectorpos++; + break; + + case 5: + retval = 0; + if ((isofile->filesectorpos < isofile->compsector) || + (isofile->filesectorpos > isofile->compsector + isofile->numsectors - 1)) + { + retval = BZip2V3Write(isofile, isofile->compblock); + isofile->compsector += isofile->numsectors; + if (retval > 0) + { + table.offset = isofile->filebytepos - retval; + table.size = retval; + retval = BZip2V3WriteTable(isofile, table); + } // ENDIF- Wrote the data out? Update the table as well. + } // ENDIF- Do we have a full buffer to write out? + if (retval >= 0) + { + compptr = isofile->filesectorpos - isofile->compsector; + compptr *= isofile->blocksize; + for (i = 0; i < isofile->blocksize; i++) + isofile->compblock[compptr + i] = *(buffer + i); + } // ENDIF- Do we have a valid buffer to draw from? + isofile->filesectorpos++; + break; + + default: + retval = -1; + break; + } // ENDSWITCH compress- which method do we try to get header info from? + if (retval >= 0) retval = isofile->blocksize; + return(retval); } // END CompressWrite() - diff --git a/plugins/CDVDisoEFP/src/isocompress.h b/plugins/CDVDisoEFP/src/isocompress.h index f7fecfd6b9..e04d17c653 100644 --- a/plugins/CDVDisoEFP/src/isocompress.h +++ b/plugins/CDVDisoEFP/src/isocompress.h @@ -1,158 +1,70 @@ /* isocompress.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef ISOCOMPRESS_H - #define ISOCOMPRESS_H - - - - #include - - #include "isofile.h" - #include "actualfile.h" - - - - // #define VERBOSE_FUNCTION_ISOCOMPRESS - // #define VERBOSE_WARNING_ISOCOMPRESS - - - - -struct CompressExt { - - const char *name; - - int method; - +struct CompressExt +{ + const char *name; + int method; }; - - - #ifdef _WIN32 - #pragma pack(1) - #endif /* _WIN32 */ - - - -struct TableData { - - off64_t offset; - - unsigned short size; - +struct TableData +{ + off64_t offset; + unsigned short size; #ifdef _WIN32 - }; - #else - -} __attribute__ ((packed)); - +} __attribute__((packed)); #endif /* _WIN32 */ - - -union TableMap { - - struct TableData table; - - char ch[sizeof(struct TableData)]; - +union TableMap +{ + struct TableData table; + char ch[sizeof(struct TableData)]; }; - - - - extern const char *compressnames[]; - extern const char *compressdesc[]; - - - extern struct CompressExt compressext[]; - - - - extern int IsoNameStripCompress(struct IsoFile *isofile); - - // 0 = success, -1 = Failure w/data, -2 = Failure w/table - extern int CompressOpenForRead(struct IsoFile *isofile); - - - extern int CompressSeek(struct IsoFile *isofile, off64_t sector); - extern int CompressRead(struct IsoFile *isofile, char *buffer); - extern void CompressClose(struct IsoFile *isofile); - - - extern int CompressOpenForWrite(struct IsoFile *isofile); - extern int CompressWrite(struct IsoFile *isofile, char *buffer); - - - - #endif /* ISOCOMPRESS_H */ - diff --git a/plugins/CDVDisoEFP/src/isofile.c b/plugins/CDVDisoEFP/src/isofile.c index 5122c58c41..af2eb926fd 100644 --- a/plugins/CDVDisoEFP/src/isofile.c +++ b/plugins/CDVDisoEFP/src/isofile.c @@ -1,1292 +1,691 @@ /* isofile.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include // NULL - #include // malloc() - #include // off64_t - - #ifndef __LINUX__ - #ifdef __linux__ - #define __LINUX__ - #endif /* __linux__ */ - #endif /* No __LINUX__ */ - #define CDVDdefs - #include "PS2Edefs.h" - - #include "logfile.h" - #include "multifile.h" - #include "isocompress.h" - #include "actualfile.h" - #include "imagetype.h" - #include "toc.h" - #include "ecma119.h" - #include "isofile.h" - - - - -const char *isofileext[] = { - - ".iso", - - ".bin", - - ".img", - - NULL - +const char *isofileext[] = +{ + ".iso", + ".bin", + ".img", + NULL }; - - - const char *cdname = "CD-XA001\0"; - const char *playstationid = "PLAYSTATION\0"; - // const char ps1/2name? - - - // Internal functions +void IsoNameStripExt(struct IsoFile *isofile) +{ + int tempext; + int tempnamepos; + int tempextpos; - - -void IsoNameStripExt(struct IsoFile *isofile) { - - int tempext; - - int tempnamepos; - - int tempextpos; - - - - tempext = 0; - - while(isofileext[tempext] != NULL) { - - tempextpos = 0; - - while(*(isofileext[tempext] + tempextpos) != 0) tempextpos++; - - - - tempnamepos = isofile->namepos; - - while((tempnamepos > 0) && (tempextpos > 0) && - - (isofile->name[tempnamepos - 1] == *(isofileext[tempext] + tempextpos - 1))) { - - tempnamepos--; - - tempextpos--; - - } // ENDWHILE- Comparing one extension to the end of the file name - - if(tempextpos == 0) { - - isofile->namepos = tempnamepos; // Move name pointer in front of ext. - - tempext = 0; // ... and test the list all over again. - - } else { - - tempext++; // Next ext in the list to test... - - } // ENDIF- Did we find a match? - - } // ENDWHILE- looking through extension list - + tempext = 0; + while (isofileext[tempext] != NULL) + { + tempextpos = 0; + while (*(isofileext[tempext] + tempextpos) != 0) tempextpos++; + tempnamepos = isofile->namepos; + while ((tempnamepos > 0) && (tempextpos > 0) && + (isofile->name[tempnamepos - 1] == *(isofileext[tempext] + tempextpos - 1))) + { + tempnamepos--; + tempextpos--; + } // ENDWHILE- Comparing one extension to the end of the file name + if (tempextpos == 0) + { + isofile->namepos = tempnamepos; // Move name pointer in front of ext. + tempext = 0; // ... and test the list all over again. + } + else + { + tempext++; // Next ext in the list to test... + } // ENDIF- Did we find a match? + } // ENDWHILE- looking through extension list } // END IsoNameStripExt() - - - - // External functions - - - -struct IsoFile *IsoFileOpenForRead(const char *filename) { - - struct IsoFile *newfile; - - int retval; - - int i; - - char tempblock[2448]; - - struct tocTN toctn; - - struct tocTD toctd; - +struct IsoFile *IsoFileOpenForRead(const char *filename) +{ + struct IsoFile *newfile; + int retval; + int i; + char tempblock[2448]; + struct tocTN toctn; + struct tocTD toctd; // union { - // struct ECMA119PrimaryVolume vol; - // char ch[sizeof(struct ECMA119PrimaryVolume)]; - // } *volcheck; - - union { - - struct ECMA119PrimaryVolume *vol; - - char *ch; - - } volcheck; - - - - newfile = NULL; - - - - if(filename == NULL) return(NULL); - - - + union + { + struct ECMA119PrimaryVolume *vol; + char *ch; + } volcheck; + newfile = NULL; + if (filename == NULL) return(NULL); #ifdef VERBOSE_FUNCTION_ISOFILE - - PrintLog("CDVD isofile: IsoFileOpenForRead(%s)", filename); - + PrintLog("CDVD isofile: IsoFileOpenForRead(%s)", filename); #endif /* VERBOSE_FUNCTION_ISOFILE */ - - - - newfile = (struct IsoFile *) malloc(sizeof(struct IsoFile)); - - if(newfile == NULL) return(NULL); - - - - newfile->sectorpos = 0; - - newfile->openforread = 1; // Read-only ISO - - newfile->filebytepos = 0; - - newfile->filesectorpos = 0; - - newfile->blocksize = 0; // Flags as non-detected yet (Compress vs. Image) - - newfile->tabledata = NULL; - - - - newfile->namepos = 0; - - while((newfile->namepos < 255) && - - (*(filename + newfile->namepos) != 0)) { - - newfile->name[newfile->namepos] = *(filename + newfile->namepos); - - newfile->namepos++; - - } // ENDWHILE- copying the file name in... - - newfile->name[newfile->namepos] = 0; // And 0-terminate. - - - - IsoNameStripExt(newfile); // Ex: -I00.Z[.bin] - - - - // File Compression name detection - - newfile->compress = IsoNameStripCompress(newfile); // Ex: -I00.bin[.Z] - - newfile->compresspos = newfile->namepos; - - - - // Test File name compression - - retval = -1; - - if(newfile->compress > 0) { - - retval = CompressOpenForRead(newfile); - - if(retval == -1) CompressClose(newfile); - - } // ENDIF- Have a compression type hint? Test it out - - - - if(retval == -1) { - - newfile->compress = 5; - - while((newfile->compress > 0) && (retval == -1)) { - - retval = CompressOpenForRead(newfile); - - if(retval == -1) { - - CompressClose(newfile); - - newfile->compress--; - - } // ENDIF- Failed to open? Close it... and try the next one. - - } // ENDWHILE- Trying to find a compression scheme that will work... - - - - if(newfile->compress == 0) { - - newfile->handle = ActualFileOpenForRead(newfile->name); - - if(newfile->handle == ACTUALHANDLENULL) { - - free(newfile); - - newfile = NULL; - - return(NULL); - - } // ENDIF- Failed to open? Abort. - - newfile->filebytesize = ActualFileSize(newfile->handle); - - } // ENDIF- No compression? Open it uncompressed. - - } // ENDIF- Temp- failed to open? Abort... - - - - // Compressed data file with no table? Return prematurely... - - // Condition detection: compress > 0, tablehandle == ACTUALHANDLENULL - - if(retval == -2) { - + newfile = (struct IsoFile *) malloc(sizeof(struct IsoFile)); + if (newfile == NULL) return(NULL); + + newfile->sectorpos = 0; + newfile->openforread = 1; // Read-only ISO + newfile->filebytepos = 0; + newfile->filesectorpos = 0; + newfile->blocksize = 0; // Flags as non-detected yet (Compress vs. Image) + newfile->tabledata = NULL; + newfile->namepos = 0; + while ((newfile->namepos < 255) && + (*(filename + newfile->namepos) != 0)) + { + newfile->name[newfile->namepos] = *(filename + newfile->namepos); + newfile->namepos++; + } // ENDWHILE- copying the file name in... + newfile->name[newfile->namepos] = 0; // And 0-terminate. + IsoNameStripExt(newfile); // Ex: -I00.Z[.bin] + // File Compression name detection + newfile->compress = IsoNameStripCompress(newfile); // Ex: -I00.bin[.Z] + newfile->compresspos = newfile->namepos; + // Test File name compression + retval = -1; + if (newfile->compress > 0) + { + retval = CompressOpenForRead(newfile); + if (retval == -1) CompressClose(newfile); + } // ENDIF- Have a compression type hint? Test it out + + if (retval == -1) + { + newfile->compress = 5; + while ((newfile->compress > 0) && (retval == -1)) + { + retval = CompressOpenForRead(newfile); + if (retval == -1) + { + CompressClose(newfile); + newfile->compress--; + } // ENDIF- Failed to open? Close it... and try the next one. + } // ENDWHILE- Trying to find a compression scheme that will work... + + if (newfile->compress == 0) + { + newfile->handle = ActualFileOpenForRead(newfile->name); + if (newfile->handle == ACTUALHANDLENULL) + { + free(newfile); + newfile = NULL; + return(NULL); + } // ENDIF- Failed to open? Abort. + newfile->filebytesize = ActualFileSize(newfile->handle); + } // ENDIF- No compression? Open it uncompressed. + } // ENDIF- Temp- failed to open? Abort... + // Compressed data file with no table? Return prematurely... + // Condition detection: compress > 0, tablehandle == ACTUALHANDLENULL + if (retval == -2) + { #ifdef VERBOSE_FUNCTION_ISOFILE - - PrintLog("CDVD isofile: Data file with no table!"); - + PrintLog("CDVD isofile: Data file with no table!"); #endif /* VERBOSE_FUNCTION_ISOFILE */ + return(newfile); + } // ENDIF- - return(newfile); + newfile->imagetype = DetectImageType(newfile); - } // ENDIF- - - - - newfile->imagetype = DetectImageType(newfile); - - - - if(newfile->compress == 0) { - - newfile->filesectorsize = newfile->filebytesize / newfile->blocksize; - - } // ENDIF- Now that blocksize is known, raw file sectors can be figured out - - - - IsoNameStripExt(newfile); // Ex: -I00[.bin].Z - - - - IsoNameStripMulti(newfile); // Ex: [-I00].bin.Z + if (newfile->compress == 0) + { + newfile->filesectorsize = newfile->filebytesize / newfile->blocksize; + } // ENDIF- Now that blocksize is known, raw file sectors can be figured out + IsoNameStripExt(newfile); // Ex: -I00[.bin].Z + IsoNameStripMulti(newfile); // Ex: [-I00].bin.Z #ifdef VERBOSE_DISC_INFO - - PrintLog("CDVD isofile: Filename: %s", filename); - - if(newfile->multi > 0) PrintLog("CDVD isofile: Multiple <2GB files."); - - PrintLog("CDVD isofile: Compression Method: %s", - - compressdesc[newfile->compress]); - - PrintLog("CDVD isofile: Image Type: %s", - - newfile->imagename); - - PrintLog("CDVD isofile: Block Size: %lli", newfile->blocksize); - - PrintLog("CDVD isofile: Total Sectors (of first file): %lli", - - newfile->filesectorsize); - + PrintLog("CDVD isofile: Filename: %s", filename); + if (newfile->multi > 0) PrintLog("CDVD isofile: Multiple <2GB files."); + PrintLog("CDVD isofile: Compression Method: %s", + compressdesc[newfile->compress]); + PrintLog("CDVD isofile: Image Type: %s", + newfile->imagename); + PrintLog("CDVD isofile: Block Size: %lli", newfile->blocksize); + PrintLog("CDVD isofile: Total Sectors (of first file): %lli", + newfile->filesectorsize); #endif /* VERBOSE_DISC_INFO */ + // Load a TOC from a .toc file (is there is one) + retval = IsoLoadTOC(newfile); + if (retval == 0) return(newfile); + // Get the volume sector for disc type test + retval = IsoFileSeek(newfile, 16); + if (retval < 0) + { + newfile = IsoFileClose(newfile); + return(NULL); + } // ENDIF- Could not find the directory sector? Abort. + retval = IsoFileRead(newfile, tempblock); + if (retval < 0) + { + newfile = IsoFileClose(newfile); + return(NULL); + } // ENDIF- Could not read the directory sector? Abort. - // Load a TOC from a .toc file (is there is one) - - retval = IsoLoadTOC(newfile); - - if(retval == 0) return(newfile); - - - - // Get the volume sector for disc type test - - retval = IsoFileSeek(newfile, 16); - - if(retval < 0) { - - newfile = IsoFileClose(newfile); - - return(NULL); - - } // ENDIF- Could not find the directory sector? Abort. - - retval = IsoFileRead(newfile, tempblock); - - if(retval < 0) { - - newfile = IsoFileClose(newfile); - - return(NULL); - - } // ENDIF- Could not read the directory sector? Abort. - - - - volcheck.ch = tempblock; - - volcheck.ch += newfile->blockoffset; - - if(ValidateECMA119PrimaryVolume(volcheck.vol) != 0) { - + volcheck.ch = tempblock; + volcheck.ch += newfile->blockoffset; + if (ValidateECMA119PrimaryVolume(volcheck.vol) != 0) + { #ifdef VERBOSE_DISC_INFO - - PrintLog("CDVD isofile: Not an ISO9660 disc! Music CD perhaps?"); - + PrintLog("CDVD isofile: Not an ISO9660 disc! Music CD perhaps?"); #endif /* VERBOSE_DISC_INFO */ + newfile->cdvdtype = CDVD_TYPE_CDDA; - newfile->cdvdtype = CDVD_TYPE_CDDA; - - - - } else { - - // Is this a playstation image? - - i = 0; - - while((*(playstationid + i) != 0) && - - (*(playstationid + i) == tempblock[newfile->blockoffset + 8 + i])) i++; - - if(*(playstationid + i) != 0) { - + } + else + { + // Is this a playstation image? + i = 0; + while ((*(playstationid + i) != 0) && + (*(playstationid + i) == tempblock[newfile->blockoffset + 8 + i])) i++; + if (*(playstationid + i) != 0) + { #ifdef VERBOSE_DISC_INFO - - PrintLog("CDVD isofile: Not a Playstation Disc!"); - + PrintLog("CDVD isofile: Not a Playstation Disc!"); #endif /* VERBOSE_DISC_INFO */ - - newfile->cdvdtype = CDVD_TYPE_DVDV; - - } else { - - newfile->cdvdtype = CDVD_TYPE_PS2DVD; - - } // ENDIF- Is this not a Playstation 1 image? - - // Sidenote: if the emulator is just playing Playstation 2 images, we could - - // just invalidate the image file right here. - - } // ENDIF- Not an ISO9660 disc? Assume Music CD. - - - - if(newfile->cdvdtype == CDVD_TYPE_PS2DVD) { - - // Is this a Playstation CD image? - - i = 0; - - while((*(cdname + i) != 0) && - - (*(cdname + i) == tempblock[newfile->blockoffset + 1024 + i])) i++; - - if(*(cdname + i) == 0) { - - newfile->cdvdtype = CDVD_TYPE_PSCD; - + newfile->cdvdtype = CDVD_TYPE_DVDV; + } + else + { + newfile->cdvdtype = CDVD_TYPE_PS2DVD; + } // ENDIF- Is this not a Playstation 1 image? + // Sidenote: if the emulator is just playing Playstation 2 images, we could + // just invalidate the image file right here. + } // ENDIF- Not an ISO9660 disc? Assume Music CD. + if (newfile->cdvdtype == CDVD_TYPE_PS2DVD) + { + // Is this a Playstation CD image? + i = 0; + while ((*(cdname + i) != 0) && + (*(cdname + i) == tempblock[newfile->blockoffset + 1024 + i])) i++; + if (*(cdname + i) == 0) + { + newfile->cdvdtype = CDVD_TYPE_PSCD; #ifdef VERBOSE_DISC_INFO - - PrintLog("CDVD isofile: Image is a Playstation 1 CD."); - + PrintLog("CDVD isofile: Image is a Playstation 1 CD."); #endif /* VERBOSE_DISC_INFO */ - - } else { - - if(newfile->blocksize != 2048) { - - newfile->cdvdtype = CDVD_TYPE_PS2CD; - + } + else + { + if (newfile->blocksize != 2048) + { + newfile->cdvdtype = CDVD_TYPE_PS2CD; #ifdef VERBOSE_DISC_INFO - - PrintLog("CDVD isofile: Image is a Playstation 2 CD."); - + PrintLog("CDVD isofile: Image is a Playstation 2 CD."); #endif /* VERBOSE_DISC_INFO */ - - } else { - + } + else + { #ifdef VERBOSE_DISC_INFO - - PrintLog("CDVD isofile: Image is a DVD."); - + PrintLog("CDVD isofile: Image is a DVD."); #endif /* VERBOSE_DISC_INFO */ + } // ENDIF- Is the blocksize not 2048? CD image then. + } // ENDIF- Is this a PS1 CD image? + } // ENDIF- Is this a Playstation image? + volcheck.ch = NULL; - } // ENDIF- Is the blocksize not 2048? CD image then. - - } // ENDIF- Is this a PS1 CD image? - - } // ENDIF- Is this a Playstation image? - - volcheck.ch = NULL; - - - - if((newfile->cdvdtype == CDVD_TYPE_DVDV) && - - (newfile->blocksize == 2352)) newfile->cdvdtype = CDVD_TYPE_CDDA; - - - - // Slap together a TOC based on the above guesswork. - - IsoInitTOC(newfile); - - if((newfile->cdvdtype != CDVD_TYPE_PS2DVD) && - - (newfile->cdvdtype != CDVD_TYPE_DVDV)) { - - toctn.strack = 1; - - toctn.etrack = 1; - - IsoAddTNToTOC(newfile, toctn); - - - - toctd.type = 0; - - toctd.lsn = newfile->filesectorsize; - - IsoAddTDToTOC(newfile, 0xAA, toctd); - - - - toctd.type = 0; // ? - - if(newfile->cdvdtype == CDVD_TYPE_CDDA) { - - toctd.type = CDVD_AUDIO_TRACK; // Music track assumed - - } else { - - toctd.type = CDVD_MODE1_TRACK; // Data track assumed - - } // ENDIF- Is this track a music or data track? - - toctd.lsn = 0; - - IsoAddTDToTOC(newfile, 1, toctd); - - } // ENDIF- Is this a CD? Single track for all sectors - - - - return(newfile); - + if ((newfile->cdvdtype == CDVD_TYPE_DVDV) && + (newfile->blocksize == 2352)) newfile->cdvdtype = CDVD_TYPE_CDDA; + // Slap together a TOC based on the above guesswork. + IsoInitTOC(newfile); + if ((newfile->cdvdtype != CDVD_TYPE_PS2DVD) && + (newfile->cdvdtype != CDVD_TYPE_DVDV)) + { + toctn.strack = 1; + toctn.etrack = 1; + IsoAddTNToTOC(newfile, toctn); + toctd.type = 0; + toctd.lsn = newfile->filesectorsize; + IsoAddTDToTOC(newfile, 0xAA, toctd); + toctd.type = 0; // ? + if (newfile->cdvdtype == CDVD_TYPE_CDDA) + { + toctd.type = CDVD_AUDIO_TRACK; // Music track assumed + } + else + { + toctd.type = CDVD_MODE1_TRACK; // Data track assumed + } // ENDIF- Is this track a music or data track? + toctd.lsn = 0; + IsoAddTDToTOC(newfile, 1, toctd); + } // ENDIF- Is this a CD? Single track for all sectors + return(newfile); } // END IsoFileOpenForRead() - - - - -int IsIsoFile(const char *filename) { - - int retval; - - struct IsoFile *tempfile; - - - +int IsIsoFile(const char *filename) +{ + int retval; + struct IsoFile *tempfile; #ifdef VERBOSE_FUNCTION_ISOFILE - - PrintLog("CDVD isofile: IsIsoFile()"); - + PrintLog("CDVD isofile: IsIsoFile()"); #endif /* VERBOSE_FUNCTION_ISOFILE */ + retval = IsActualFile(filename); + if (retval < 0) return(retval); // Not a regular file? Report it. + tempfile = NULL; + tempfile = IsoFileOpenForRead(filename); + if (tempfile == NULL) return(-3); // Not an image file? Report it. - - retval = IsActualFile(filename); - - if(retval < 0) return(retval); // Not a regular file? Report it. - - - - tempfile = NULL; - - tempfile = IsoFileOpenForRead(filename); - - if(tempfile == NULL) return(-3); // Not an image file? Report it. - - - - retval = 0; - - if((tempfile->compress > 0) && - - (tempfile->tablehandle == ACTUALHANDLENULL) && - - (tempfile->tabledata == NULL)) retval = -4; - - - - tempfile = IsoFileClose(tempfile); - - return(retval); - + retval = 0; + if ((tempfile->compress > 0) && + (tempfile->tablehandle == ACTUALHANDLENULL) && + (tempfile->tabledata == NULL)) retval = -4; + tempfile = IsoFileClose(tempfile); + return(retval); } // END IsIsoFile() +int IsoFileSeek(struct IsoFile *file, off64_t sector) +{ + int retval; + if (file == NULL) return(-1); + if (sector < 0) return(-1); - - - -int IsoFileSeek(struct IsoFile *file, off64_t sector) { - - int retval; - - - - if(file == NULL) return(-1); - - if(sector < 0) return(-1); - - - - if(sector == file->sectorpos) return(0); - - + if (sector == file->sectorpos) return(0); #ifdef VERBOSE_FUNCTION_ISOFILE - - PrintLog("CDVD isofile: IsoFileSeek(%llu)", sector); - + PrintLog("CDVD isofile: IsoFileSeek(%llu)", sector); #endif /* VERBOSE_FUNCTION_ISOFILE */ - - - if(file->multi > 0) { - - retval = MultiFileSeek(file, sector); - - } else if(file->compress > 0) { - - retval = CompressSeek(file, sector); - - } else { - - retval = ActualFileSeek(file->handle, - - (sector * file->blocksize) + file->imageheader); - - if(retval == 0) { - - file->filesectorpos = sector; - - file->filebytepos = (sector * file->blocksize) + file->imageheader; - - } // ENDIF- Succeeded? Adjust internal pointers - - } // ENDLONGIF- Seek right file? Or compressed block? Or Raw block? - - - - if(retval < 0) { - + if (file->multi > 0) + { + retval = MultiFileSeek(file, sector); + } + else if (file->compress > 0) + { + retval = CompressSeek(file, sector); + } + else + { + retval = ActualFileSeek(file->handle, + (sector * file->blocksize) + file->imageheader); + if (retval == 0) + { + file->filesectorpos = sector; + file->filebytepos = (sector * file->blocksize) + file->imageheader; + } // ENDIF- Succeeded? Adjust internal pointers + } // ENDLONGIF- Seek right file? Or compressed block? Or Raw block? + if (retval < 0) + { #ifdef VERBOSE_FUNCTION_ISOFILE - - PrintLog("CDVD isofile: Trouble finding the sector!"); - + PrintLog("CDVD isofile: Trouble finding the sector!"); #endif /* VERBOSE_FUNCTION_ISOFILE */ + return(-1); + } // ENDIF- Trouble reading the block? Say so! - return(-1); - - } // ENDIF- Trouble reading the block? Say so! - - - - file->sectorpos = sector; - - return(0); - + file->sectorpos = sector; + return(0); } // END IsoFileSeek() +int IsoFileRead(struct IsoFile *file, char *block) +{ + int retval; - - - -int IsoFileRead(struct IsoFile *file, char *block) { - - int retval; - - - - if(file == NULL) return(-1); - - if(block == NULL) return(-1); - - if(file->openforread == 0) return(-1); - - + if (file == NULL) return(-1); + if (block == NULL) return(-1); + if (file->openforread == 0) return(-1); #ifdef VERBOSE_FUNCTION_ISOFILE - - PrintLog("CDVD isofile: IsoFileRead(%i)", file->blocksize); - + PrintLog("CDVD isofile: IsoFileRead(%i)", file->blocksize); #endif /* VERBOSE_FUNCTION_ISOFILE */ - - - if(file->multi > 0) { - - retval = MultiFileRead(file, block); - - } else if(file->compress > 0) { - - retval = CompressRead(file, block); - - } else { - - if(file->sectorpos >= file->filesectorsize) return(-1); - - retval = ActualFileRead(file->handle, - - file->blocksize, - - block); - - if(retval > 0) file->filebytepos += retval; - - if(retval == file->blocksize) file->filesectorpos++; - - } // ENDLONGIF- Read right file? Or compressed block? Or Raw block? - - - - if(retval < 0) { - + if (file->multi > 0) + { + retval = MultiFileRead(file, block); + } + else if (file->compress > 0) + { + retval = CompressRead(file, block); + } + else + { + if (file->sectorpos >= file->filesectorsize) return(-1); + retval = ActualFileRead(file->handle, + file->blocksize, + block); + if (retval > 0) file->filebytepos += retval; + if (retval == file->blocksize) file->filesectorpos++; + } // ENDLONGIF- Read right file? Or compressed block? Or Raw block? + if (retval < 0) + { #ifdef VERBOSE_FUNCTION_ISOFILE - - PrintLog("CDVD isofile: Trouble reading the sector!"); - + PrintLog("CDVD isofile: Trouble reading the sector!"); #endif /* VERBOSE_FUNCTION_ISOFILE */ + return(-1); + } // ENDIF- Trouble reading the block? Say so! - return(-1); - - } // ENDIF- Trouble reading the block? Say so! - - - - if(retval < file->blocksize) { - + if (retval < file->blocksize) + { #ifdef VERBOSE_FUNCTION_ISOFILE - - PrintLog("CDVD isofile: Short block! Got %i out of %i bytes", - - retval, file->blocksize); - + PrintLog("CDVD isofile: Short block! Got %i out of %i bytes", + retval, file->blocksize); #endif /* VERBOSE_FUNCTION_ISOFILE */ + return(-1); + } // ENDIF- Didn't get enough bytes? Say so! - return(-1); - - } // ENDIF- Didn't get enough bytes? Say so! - - - - file->sectorpos++; - - return(0); - + file->sectorpos++; + return(0); } // END IsoFileRead() +struct IsoFile *IsoFileClose(struct IsoFile *file) +{ + if (file == NULL) return(NULL); - - - -struct IsoFile *IsoFileClose(struct IsoFile *file) { - - if(file == NULL) return(NULL); - - - - if(file->handle != ACTUALHANDLENULL) { - + if (file->handle != ACTUALHANDLENULL) + { #ifdef VERBOSE_FUNCTION_ISOFILE - - PrintLog("CDVD isofile: IsoFileClose()"); - + PrintLog("CDVD isofile: IsoFileClose()"); #endif /* VERBOSE_FUNCTION_ISOFILE */ - - - - if(file->compress > 0) { - - CompressClose(file); - - } else { - - ActualFileClose(file->handle); - - file->handle = ACTUALHANDLENULL; - - } // ENDIF- Compressed File? Close (and flush) compression too. - - } // ENDIF- Open Handle? Close the file - - - - free(file); - - return(NULL); - + if (file->compress > 0) + { + CompressClose(file); + } + else + { + ActualFileClose(file->handle); + file->handle = ACTUALHANDLENULL; + } // ENDIF- Compressed File? Close (and flush) compression too. + } // ENDIF- Open Handle? Close the file + free(file); + return(NULL); } // END IsoFileClose() - - - - struct IsoFile *IsoFileOpenForWrite(const char *filename, + int imagetype, + int multi, + int compress) +{ + struct IsoFile *newfile; - int imagetype, - - int multi, - - int compress) { - - struct IsoFile *newfile; - - - - newfile = NULL; - - - - if(filename == NULL) return(NULL); - - if((imagetype < 0) || (imagetype > 11)) return(NULL); - - if((compress < 0) || (compress > 5)) return(NULL); - + newfile = NULL; + if (filename == NULL) return(NULL); + if ((imagetype < 0) || (imagetype > 11)) return(NULL); + if ((compress < 0) || (compress > 5)) return(NULL); #ifdef VERBOSE_FUNCTION_ISOFILE - - PrintLog("CDVD isofile: IsoFileOpenForWrite()"); - + PrintLog("CDVD isofile: IsoFileOpenForWrite()"); #endif /* VERBOSE_FUNCTION_ISOFILE */ - - - newfile = (struct IsoFile *) malloc(sizeof(struct IsoFile)); - - if(newfile == NULL) return(NULL); - - - - newfile->sectorpos = 0; - - newfile->openforread = 0; // Write-only file - - newfile->filebytesize = 0; - - newfile->filebytepos = 0; - - newfile->filesectorsize = 0; - - newfile->filesectorpos = 0; - - - - // if(toc != NULL) { - - // for(i = 0; i < 2048; i++) newfile->toc[i] = *(toc + i); - - // } else { - - // for(i = 0; i < 2048; i++) newfile->toc[i] = 0; - - // } // ENDIF- Do we have a PS2 Table of Contents to save out as well? - - - - newfile->namepos = 0; - - while((newfile->namepos < 255) && - - (*(filename + newfile->namepos) != 0)) { - - newfile->name[newfile->namepos] = *(filename + newfile->namepos); - - newfile->namepos++; - - } // ENDWHILE- copying the file name in... - - newfile->name[newfile->namepos] = 0; // And 0-terminate. - - - - IsoNameStripExt(newfile); - - IsoNameStripCompress(newfile); - - IsoNameStripExt(newfile); - - IsoNameStripMulti(newfile); - - newfile->name[newfile->namepos] = 0; // And 0-terminate. - - - - newfile->imagetype = imagetype; - - GetImageType(newfile, imagetype); - - newfile->cdvdtype = CDVD_TYPE_PS2DVD; // Does it matter here? Nope. - - - - newfile->multi = multi; - - if(newfile->multi > 0) { - - newfile->name[newfile->namepos + 0] = '-'; - - newfile->name[newfile->namepos + 1] = 'I'; - - newfile->name[newfile->namepos + 2] = '0'; - - newfile->name[newfile->namepos + 3] = '0'; - - newfile->name[newfile->namepos + 4] = 0; - - newfile->multipos = newfile->namepos + 3; - - newfile->namepos += 4; - - newfile->multistart = 0; - - newfile->multiend = 0; - - newfile->multinow = 0; - - newfile->multioffset = 0; - - newfile->multisectorend[0] = 0; - - } // ENDIF- Are we creating a multi-file? - - - - newfile->compress = compress; - - switch(newfile->compress) { - - case 1: - - case 3: - - newfile->name[newfile->namepos + 0] = '.'; - - newfile->name[newfile->namepos + 1] = 'Z'; - - newfile->name[newfile->namepos + 2] = 0; - - newfile->namepos += 2; - - break; - - - - case 2: - - newfile->name[newfile->namepos + 0] = '.'; - - newfile->name[newfile->namepos + 1] = 'd'; - - newfile->name[newfile->namepos + 2] = 'u'; - - newfile->name[newfile->namepos + 3] = 'm'; - - newfile->name[newfile->namepos + 4] = 'p'; - - newfile->name[newfile->namepos + 5] = 0; - - newfile->namepos += 5; - - break; - - - - case 4: - - newfile->name[newfile->namepos + 0] = '.'; - - newfile->name[newfile->namepos + 1] = 'B'; - - newfile->name[newfile->namepos + 2] = 'Z'; - - newfile->name[newfile->namepos + 3] = '2'; - - newfile->name[newfile->namepos + 4] = 0; - - newfile->namepos += 4; - - break; - - - - case 5: - - newfile->name[newfile->namepos + 0] = '.'; - - newfile->name[newfile->namepos + 1] = 'b'; - - newfile->name[newfile->namepos + 2] = 'z'; - - newfile->name[newfile->namepos + 3] = '2'; - - newfile->name[newfile->namepos + 4] = 0; - - newfile->namepos += 4; - - break; - - - - case 0: - - default: - - break; - - } // ENDSWITCH compress- which compression extension should we add on? - - - - newfile->name[newfile->namepos + 0] = '.'; - - newfile->name[newfile->namepos + 4] = 0; - - if(newfile->blocksize == 2048) { - - newfile->name[newfile->namepos + 1] = 'i'; - - newfile->name[newfile->namepos + 2] = 's'; - - newfile->name[newfile->namepos + 3] = 'o'; - - } else { - - newfile->name[newfile->namepos + 1] = 'b'; - - newfile->name[newfile->namepos + 2] = 'i'; - - newfile->name[newfile->namepos + 3] = 'n'; - - } // ENDIF- Is this a true ISO (or just a raw BIN file?) - - newfile->namepos += 4; - - - - if(IsActualFile(newfile->name) == 0) { - - free(newfile); - - newfile = NULL; - - return(NULL); - - } // ENDIF- Does the destination file already exist? - - - - if(newfile->compress > 0) { - - CompressOpenForWrite(newfile); - - if((newfile->handle != ACTUALHANDLENULL) && - - (newfile->tablehandle == ACTUALHANDLENULL)) { - - ActualFileClose(newfile->handle); - - newfile->handle = ACTUALHANDLENULL; - - } // ENDIF Data file created, but table file stopped? Close and remove data - - } else { - - newfile->handle = ActualFileOpenForWrite(newfile->name); - - } // ENDIF- Writing out a compressed file? - - - - if(newfile->handle == ACTUALHANDLENULL) { - - free(newfile); - - newfile = NULL; - - return(NULL); - - } // ENDIF- Couldn't create file? Abort - - - - return(newfile); - + newfile = (struct IsoFile *) malloc(sizeof(struct IsoFile)); + if (newfile == NULL) return(NULL); + newfile->sectorpos = 0; + newfile->openforread = 0; // Write-only file + newfile->filebytesize = 0; + newfile->filebytepos = 0; + newfile->filesectorsize = 0; + newfile->filesectorpos = 0; + + // if(toc != NULL) { + // for(i = 0; i < 2048; i++) newfile->toc[i] = *(toc + i); + // } else { + // for(i = 0; i < 2048; i++) newfile->toc[i] = 0; + // } // ENDIF- Do we have a PS2 Table of Contents to save out as well? + + newfile->namepos = 0; + while ((newfile->namepos < 255) && + (*(filename + newfile->namepos) != 0)) + { + newfile->name[newfile->namepos] = *(filename + newfile->namepos); + newfile->namepos++; + } // ENDWHILE- copying the file name in... + newfile->name[newfile->namepos] = 0; // And 0-terminate. + + IsoNameStripExt(newfile); + IsoNameStripCompress(newfile); + IsoNameStripExt(newfile); + IsoNameStripMulti(newfile); + newfile->name[newfile->namepos] = 0; // And 0-terminate. + + newfile->imagetype = imagetype; + GetImageType(newfile, imagetype); + newfile->cdvdtype = CDVD_TYPE_PS2DVD; // Does it matter here? Nope. + + newfile->multi = multi; + if (newfile->multi > 0) + { + newfile->name[newfile->namepos + 0] = '-'; + newfile->name[newfile->namepos + 1] = 'I'; + newfile->name[newfile->namepos + 2] = '0'; + newfile->name[newfile->namepos + 3] = '0'; + newfile->name[newfile->namepos + 4] = 0; + newfile->multipos = newfile->namepos + 3; + newfile->namepos += 4; + newfile->multistart = 0; + newfile->multiend = 0; + newfile->multinow = 0; + newfile->multioffset = 0; + newfile->multisectorend[0] = 0; + } // ENDIF- Are we creating a multi-file? + + newfile->compress = compress; + switch (newfile->compress) + { + case 1: + case 3: + newfile->name[newfile->namepos + 0] = '.'; + newfile->name[newfile->namepos + 1] = 'Z'; + newfile->name[newfile->namepos + 2] = 0; + newfile->namepos += 2; + break; + + case 2: + newfile->name[newfile->namepos + 0] = '.'; + newfile->name[newfile->namepos + 1] = 'd'; + newfile->name[newfile->namepos + 2] = 'u'; + newfile->name[newfile->namepos + 3] = 'm'; + newfile->name[newfile->namepos + 4] = 'p'; + newfile->name[newfile->namepos + 5] = 0; + newfile->namepos += 5; + break; + + case 4: + newfile->name[newfile->namepos + 0] = '.'; + newfile->name[newfile->namepos + 1] = 'B'; + newfile->name[newfile->namepos + 2] = 'Z'; + newfile->name[newfile->namepos + 3] = '2'; + newfile->name[newfile->namepos + 4] = 0; + newfile->namepos += 4; + break; + case 5: + newfile->name[newfile->namepos + 0] = '.'; + newfile->name[newfile->namepos + 1] = 'b'; + newfile->name[newfile->namepos + 2] = 'z'; + newfile->name[newfile->namepos + 3] = '2'; + newfile->name[newfile->namepos + 4] = 0; + newfile->namepos += 4; + break; + + case 0: + default: + break; + } // ENDSWITCH compress- which compression extension should we add on? + newfile->name[newfile->namepos + 0] = '.'; + newfile->name[newfile->namepos + 4] = 0; + if (newfile->blocksize == 2048) + { + newfile->name[newfile->namepos + 1] = 'i'; + newfile->name[newfile->namepos + 2] = 's'; + newfile->name[newfile->namepos + 3] = 'o'; + } + else + { + newfile->name[newfile->namepos + 1] = 'b'; + newfile->name[newfile->namepos + 2] = 'i'; + newfile->name[newfile->namepos + 3] = 'n'; + } // ENDIF- Is this a true ISO (or just a raw BIN file?) + newfile->namepos += 4; + + if (IsActualFile(newfile->name) == 0) + { + free(newfile); + newfile = NULL; + return(NULL); + } // ENDIF- Does the destination file already exist? + + if (newfile->compress > 0) + { + CompressOpenForWrite(newfile); + if ((newfile->handle != ACTUALHANDLENULL) && + (newfile->tablehandle == ACTUALHANDLENULL)) + { + ActualFileClose(newfile->handle); + newfile->handle = ACTUALHANDLENULL; + } // ENDIF Data file created, but table file stopped? Close and remove data + } + else + { + newfile->handle = ActualFileOpenForWrite(newfile->name); + } // ENDIF- Writing out a compressed file? + if (newfile->handle == ACTUALHANDLENULL) + { + free(newfile); + newfile = NULL; + return(NULL); + } // ENDIF- Couldn't create file? Abort + return(newfile); } // END IsoFileOpenForWrite() +int IsoFileWrite(struct IsoFile *file, char *block) +{ + int byteswritten; - - - -int IsoFileWrite(struct IsoFile *file, char *block) { - - int byteswritten; - - - - if(file == NULL) return(-1); - - if(block == NULL) return(-1); - - if(file->openforread == 1) return(-1); - - + if (file == NULL) return(-1); + if (block == NULL) return(-1); + if (file->openforread == 1) return(-1); #ifdef VERBOSE_FUNCTION_ISOFILE - - PrintLog("CDVD isofile: IsoFileWrite()"); - + PrintLog("CDVD isofile: IsoFileWrite()"); #endif /* VERBOSE_FUNCTION_ISOFILE */ - - - byteswritten = 0; - - if(file->multi > 0) { - - byteswritten = MultiFileWrite(file, block); - - } else if(file->compress > 0) { - - byteswritten = CompressWrite(file, block); - - } else { - - byteswritten = ActualFileWrite(file->handle, - - file->blocksize, - - block); - - if(byteswritten > 0) file->filebytepos += byteswritten; - - if(byteswritten == file->blocksize) file->filesectorpos++; - - } // ENDLONGIF- Write to different file? Compressed block? or Raw? - - if(byteswritten < 0) { - + byteswritten = 0; + if (file->multi > 0) + { + byteswritten = MultiFileWrite(file, block); + } + else if (file->compress > 0) + { + byteswritten = CompressWrite(file, block); + } + else + { + byteswritten = ActualFileWrite(file->handle, + file->blocksize, + block); + if (byteswritten > 0) file->filebytepos += byteswritten; + if (byteswritten == file->blocksize) file->filesectorpos++; + } // ENDLONGIF- Write to different file? Compressed block? or Raw? + if (byteswritten < 0) + { #ifdef VERBOSE_FUNCTION_ISOFILE - - PrintLog("CDVD isofile: Trouble writing the sector!"); - + PrintLog("CDVD isofile: Trouble writing the sector!"); #endif /* VERBOSE_FUNCTION_ISOFILE */ - - return(-1); - - } // ENDIF- Trouble reading the block? Say so! - - if(file->filebytepos > file->filebytesize) - - file->filebytesize = file->filebytepos; - - - - if(byteswritten < file->blocksize) { - + return(-1); + } // ENDIF- Trouble reading the block? Say so! + if (file->filebytepos > file->filebytesize) + file->filebytesize = file->filebytepos; + if (byteswritten < file->blocksize) + { #ifdef VERBOSE_FUNCTION_ISOFILE - - PrintLog("CDVD isofile: Short block! Wrote %i out of %i bytes", - - byteswritten, file->blocksize); - + PrintLog("CDVD isofile: Short block! Wrote %i out of %i bytes", + byteswritten, file->blocksize); #endif /* VERBOSE_FUNCTION_ISOFILE */ - - return(-1); - - } // ENDIF- Didn't write enough bytes? Say so! - - if(file->filesectorpos > file->filesectorsize) - - file->filesectorsize = file->filesectorpos; - - - - file->sectorpos++; - - return(0); - + return(-1); + } // ENDIF- Didn't write enough bytes? Say so! + if (file->filesectorpos > file->filesectorsize) + file->filesectorsize = file->filesectorpos; + file->sectorpos++; + return(0); } // END IsoFileWrite() - - - - -struct IsoFile *IsoFileCloseAndDelete(struct IsoFile *file) { - - int i; - - - - if(file == NULL) return(NULL); - - - - if(file->handle != ACTUALHANDLENULL) { - +struct IsoFile *IsoFileCloseAndDelete(struct IsoFile *file) +{ + int i; + if (file == NULL) return(NULL); + if (file->handle != ACTUALHANDLENULL) + { #ifdef VERBOSE_FUNCTION_ISOFILE - - PrintLog("CDVD isofile: IsoFileCloseAndDelete()"); - + PrintLog("CDVD isofile: IsoFileCloseAndDelete()"); #endif /* VERBOSE_FUNCTION_ISOFILE */ + if (file->compress > 0) + { + CompressClose(file); + } + else + { + ActualFileClose(file->handle); + file->handle = ACTUALHANDLENULL; + } // ENDIF- Compressed File? Close (and flush) compression too. + } // ENDIF- Open Handle? Close the file + if (file->multi == 1) + { + for (i = file->multistart; i <= file->multiend; i++) + { + file->name[file->multipos] = '0' + i; + ActualFileDelete(file->name); + if (file->compress > 0) + { + file->tablename[file->multipos] = '0' + i; + ActualFileDelete(file->tablename); + } // ENDIF- Get the table file too? + } // NEXT i- iterate through each multi-file name, removing it. + } + else + { + ActualFileDelete(file->name); + if (file->compress > 0) + { + ActualFileDelete(file->tablename); + } // ENDIF- Get the table file too? + } // ENDIF- Do we have to remove multiple files? - if(file->compress > 0) { - - CompressClose(file); - - } else { - - ActualFileClose(file->handle); - - file->handle = ACTUALHANDLENULL; - - } // ENDIF- Compressed File? Close (and flush) compression too. - - } // ENDIF- Open Handle? Close the file - - - - if(file->multi == 1) { - - for(i = file->multistart; i <= file->multiend; i++) { - - file->name[file->multipos] = '0' + i; - - ActualFileDelete(file->name); - - if(file->compress > 0) { - - file->tablename[file->multipos] = '0' + i; - - ActualFileDelete(file->tablename); - - } // ENDIF- Get the table file too? - - } // NEXT i- iterate through each multi-file name, removing it. - - } else { - - ActualFileDelete(file->name); - - if(file->compress > 0) { - - ActualFileDelete(file->tablename); - - } // ENDIF- Get the table file too? - - } // ENDIF- Do we have to remove multiple files? - - - - free(file); - - return(NULL); - + free(file); + return(NULL); } // END IsoFileCloseAndDelete() - diff --git a/plugins/CDVDisoEFP/src/isofile.h b/plugins/CDVDisoEFP/src/isofile.h index b522fd04cf..c5ae6bd2dc 100644 --- a/plugins/CDVDisoEFP/src/isofile.h +++ b/plugins/CDVDisoEFP/src/isofile.h @@ -1,246 +1,108 @@ /* isofile.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef ISOFILE_H - #define ISOFILE_H - - - - #include // off64_t - - #include "actualfile.h" - - - - // #define VERBOSE_FUNCTION_ISOFILE - #define VERBOSE_DISC_INFO +struct IsoFile +{ + // *** Primary Data area + char name[256]; + int namepos; // Used for detection of components within name + ACTUALHANDLE handle; + off64_t sectorpos; // Overall. + // blocks (char [2352]) provided by users + // *** Derived Stats from Primary Data + int openforread; // 1 = Yes, 0 = No + off64_t filebytesize; + off64_t filebytepos; + off64_t filesectorsize; + off64_t filesectorpos; + int cdvdtype; // for GetDiskType call + char toc[2048]; // for GetTOC call + // From imagetype.h + int imagetype; + char imagename[40]; + off64_t imageheader; // Header bytes in every file... + off64_t blocksize; // sized to add quickly to other off64_t counters + int blockoffset; // Where to place data in block + // from isocompress.h + int compress; // Compression Method used (0 = none, 1...) + int compresspos; // Start pos of ".Z", ".BZ", etc... + char tablename[256]; + ACTUALHANDLE tablehandle; + char compblock[65536]; // Temporary storage of uncompressed sectors. + off64_t compsector; // First sector of the compblock[] + off64_t numsectors; // Number of sectors in a compression block + char *tabledata; // Table holding area + // From multifile.h + int multi; // 0 = Single File, 1 = Multiple Files + int multipos; // Position of Multi # ('0'-'9') + off64_t multisectorend[10]; // Ending sector of each file... + off64_t multioffset; // To help with seek calls. Sector offset. + int multistart; // Starting file number (0-1) + int multiend; // Ending file number (?-9) + int multinow; // Current open file number - - -struct IsoFile { - - // *** Primary Data area - - char name[256]; - - int namepos; // Used for detection of components within name - - ACTUALHANDLE handle; - - off64_t sectorpos; // Overall. - - // blocks (char [2352]) provided by users - - - - // *** Derived Stats from Primary Data - - int openforread; // 1 = Yes, 0 = No - - off64_t filebytesize; - - off64_t filebytepos; - - off64_t filesectorsize; - - off64_t filesectorpos; - - int cdvdtype; // for GetDiskType call - - char toc[2048]; // for GetTOC call - - - - // From imagetype.h - - int imagetype; - - char imagename[40]; - - off64_t imageheader; // Header bytes in every file... - - off64_t blocksize; // sized to add quickly to other off64_t counters - - int blockoffset; // Where to place data in block - - - - // from isocompress.h - - int compress; // Compression Method used (0 = none, 1...) - - int compresspos; // Start pos of ".Z", ".BZ", etc... - - char tablename[256]; - - ACTUALHANDLE tablehandle; - - char compblock[65536]; // Temporary storage of uncompressed sectors. - - off64_t compsector; // First sector of the compblock[] - - off64_t numsectors; // Number of sectors in a compression block - - char *tabledata; // Table holding area - - - - // From multifile.h - - int multi; // 0 = Single File, 1 = Multiple Files - - int multipos; // Position of Multi # ('0'-'9') - - off64_t multisectorend[10]; // Ending sector of each file... - - off64_t multioffset; // To help with seek calls. Sector offset. - - int multistart; // Starting file number (0-1) - - int multiend; // Ending file number (?-9) - - int multinow; // Current open file number - - - - // *** (Specific) Compression Data area - + // *** (Specific) Compression Data area }; - - - - // Read-only section - // IsoFiles opened for read are treated as random-access files - - - extern int IsIsoFile(const char *filename); - // Returns an image type (positive or zero) or an error (negative) - - extern struct IsoFile *IsoFileOpenForRead(const char *filename); - // Will seek blocksize and compression method on it's own. - - - extern int IsoFileSeek(struct IsoFile *file, off64_t sector); - // Sector, not byte. - - extern int IsoFileRead(struct IsoFile *file, char *block); - // Buffers should be at least of "blocksize" size. 2352 bytes, please. - - - - // Write-only section - // IsoFiles opened for write are treated as sequential files (still written - // out a block at a time, though, to be read in later as random-access) - // No plans are made to make writes random-access at this time. - - - extern struct IsoFile *IsoFileOpenForWrite(const char *filename, - - int imagetype, - - int multi, - - int compress); - - + int imagetype, + int multi, + int compress); extern int IsoFileWrite(struct IsoFile *file, char *block); - // Uncompressed buffers, please. - // Will compress with this call (if it's necessary.) - - - - // Calls used for all Isofiles - - - extern struct IsoFile *IsoFileClose(struct IsoFile *file); - // Use return variable to NULL the file pointer. - // Ex: lastfile = IsoFileClose(lastfile); - - - extern struct IsoFile *IsoFileCloseAndDelete(struct IsoFile *file); - // For failure to finish writing out a file(set). - - - - #endif /* ISOFILE_H */ - diff --git a/plugins/CDVDisoEFP/src/multifile.c b/plugins/CDVDisoEFP/src/multifile.c index 5d9d16fa55..b10771e169 100644 --- a/plugins/CDVDisoEFP/src/multifile.c +++ b/plugins/CDVDisoEFP/src/multifile.c @@ -1,578 +1,325 @@ /* multifile.c - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #include // NULL - #include // off64_t - - - // #ifndef __LINUX__ - // #ifdef __linux__ - // #define __LINUX__ - // #endif /* __linux__ */ - // #endif /* No __LINUX__ */ - - - // #define CDVDdefs - // #include "PS2Edefs.h" - - #include "logfile.h" - #include "isofile.h" - #include "isocompress.h" - #include "actualfile.h" - #include "multifile.h" - - - - #define FILESIZELIMIT 2000000000 +char *multinames[] = +{ + "", + "Multiple ", + NULL +}; - - - -char *multinames[] = { - - "", - - "Multiple ", - - NULL }; - - - - - -void IsoNameStripMulti(struct IsoFile *isofile) { - - isofile->multi = 0; - - if(isofile->namepos < 2) return; // Not enough digits - - if(isofile->name[isofile->namepos - 1] < '0') return; // Ex: -I0[0] - - if(isofile->name[isofile->namepos - 1] > '1') return; // Ex: -I0[1] - - if(isofile->name[isofile->namepos - 2] != '0') return; // Ex: -I[0]0 - - - - isofile->multi = 1; - - isofile->multipos = isofile->namepos - 1; - - isofile->namepos -= 2; - - isofile->multistart = isofile->name[isofile->multipos] - '0'; - - isofile->multiend = isofile->multistart; - - isofile->multinow = isofile->multistart; - - isofile->multisectorend[0] = 0; // Sometimes the file name starts with '1' - - isofile->multisectorend[isofile->multistart] = isofile->filesectorsize; - - isofile->multioffset = 0; - - - - if(isofile->namepos < 1) return; - - if(isofile->name[isofile->namepos - 1] != 'I') return; // Ex: -[I]00 - - isofile->namepos--; - - - - if(isofile->namepos < 2) return; // Filename doesn't start with '-' - - if(isofile->name[isofile->namepos - 1] != '-') return; // Ex: [-]I00 - - isofile->namepos--; - - - - return; - +void IsoNameStripMulti(struct IsoFile *isofile) +{ + isofile->multi = 0; + if (isofile->namepos < 2) return; // Not enough digits + if (isofile->name[isofile->namepos - 1] < '0') return; // Ex: -I0[0] + if (isofile->name[isofile->namepos - 1] > '1') return; // Ex: -I0[1] + if (isofile->name[isofile->namepos - 2] != '0') return; // Ex: -I[0]0 + isofile->multi = 1; + isofile->multipos = isofile->namepos - 1; + isofile->namepos -= 2; + isofile->multistart = isofile->name[isofile->multipos] - '0'; + isofile->multiend = isofile->multistart; + isofile->multinow = isofile->multistart; + isofile->multisectorend[0] = 0; // Sometimes the file name starts with '1' + isofile->multisectorend[isofile->multistart] = isofile->filesectorsize; + isofile->multioffset = 0; + if (isofile->namepos < 1) return; + if (isofile->name[isofile->namepos - 1] != 'I') return; // Ex: -[I]00 + isofile->namepos--; + if (isofile->namepos < 2) return; // Filename doesn't start with '-' + if (isofile->name[isofile->namepos - 1] != '-') return; // Ex: [-]I00 + isofile->namepos--; + return; } // END IsoNameStripMulti() - - - - -int MultiFileSeek(struct IsoFile *isofile, off64_t sector) { - - int multinext; - - int retval; - - off64_t tempfilesector; - - +int MultiFileSeek(struct IsoFile *isofile, off64_t sector) +{ + int multinext; + int retval; + off64_t tempfilesector; #ifdef VERBOSE_FUNCTION_MULTIFILE - - PrintLog("CDVD multifile: MultiFileSeek(%llu)", sector); - + PrintLog("CDVD multifile: MultiFileSeek(%llu)", sector); #endif /* VERBOSE_FUNCTION_MULTIFILE */ - - - multinext = isofile->multinow; - - - - // Do we need to back up a file or so? - - while((multinext > isofile->multistart) && - - (sector < isofile->multisectorend[multinext - 1])) multinext--; - - - - // Do we need to go forward a file or two (that we know about?) - - while((multinext < isofile->multiend) && - - (sector >= isofile->multisectorend[multinext])) multinext++; - - - - // Do we need to go forward a file or two (that we *don't* know about?) - - while((multinext < 9) && - - (sector >= isofile->multisectorend[multinext])) { - - if(isofile->compress > 0) { - - CompressClose(isofile); - - } else { - - ActualFileClose(isofile->handle); - - isofile->handle = ACTUALHANDLENULL; - - } // ENDIF- Close a compressed file? (or an uncompressed one?) - - - - multinext++; - - - - isofile->name[isofile->multipos] = '0' + multinext; - - if(isofile->compress > 0) { - - retval = CompressOpenForRead(isofile); - - - - } else { - - isofile->handle = ActualFileOpenForRead(isofile->name); - - retval = 0; - - if(isofile->handle == ACTUALHANDLENULL) { - - retval = -1; - - - - } else { - - isofile->filebytesize = ActualFileSize(isofile->handle); - - isofile->filesectorsize = isofile->filebytesize / isofile->blocksize; - - isofile->filebytepos = 0; - - isofile->filesectorpos = 0; - - } // ENDIF- Failed to open the file raw? - - } // ENDIF- Compressed or non-compressed? What a question. - - - - if(retval < 0) { - - if(isofile->compress > 0) { - - CompressClose(isofile); - - } else { - - ActualFileClose(isofile->handle); - - isofile->handle = ACTUALHANDLENULL; - - } // ENDIF- Close a compressed file? (or an uncompressed one?) - - - - multinext--; - - - - isofile->name[isofile->multipos] = '0' + multinext; - - if(isofile->compress > 0) { - - CompressOpenForRead(isofile); - - } else { - - isofile->handle = ActualFileOpenForRead(isofile->name); - - isofile->filebytesize = ActualFileSize(isofile->handle); - - isofile->filesectorsize = isofile->filebytesize / isofile->blocksize; - - isofile->filebytepos = 0; - - isofile->filesectorpos = 0; - - } // ENDIF- Compressed or non-compressed? What a question. - - - - isofile->multinow = multinext; - - if(isofile->multinow == 0) { - - isofile->multioffset = 0; - - } else { - - isofile->multioffset = isofile->multisectorend[isofile->multinow - 1]; - - } // ENDIF- At the start of the list? Offset 0. - - return(-1); - - } // ENDIF- Failed to open next in series? Revert and abort. - - - - isofile->multinow = multinext; - - isofile->multiend = multinext; - - isofile->multioffset = isofile->multisectorend[multinext - 1]; - - isofile->multisectorend[multinext] = isofile->multisectorend[multinext - 1] - - + isofile->filesectorsize; - + multinext = isofile->multinow; + + // Do we need to back up a file or so? + while ((multinext > isofile->multistart) && + (sector < isofile->multisectorend[multinext - 1])) multinext--; + + // Do we need to go forward a file or two (that we know about?) + while ((multinext < isofile->multiend) && + (sector >= isofile->multisectorend[multinext])) multinext++; + + // Do we need to go forward a file or two (that we *don't* know about?) + while ((multinext < 9) && + (sector >= isofile->multisectorend[multinext])) + { + if (isofile->compress > 0) + { + CompressClose(isofile); + } + else + { + ActualFileClose(isofile->handle); + isofile->handle = ACTUALHANDLENULL; + } // ENDIF- Close a compressed file? (or an uncompressed one?) + + multinext++; + + isofile->name[isofile->multipos] = '0' + multinext; + if (isofile->compress > 0) + { + retval = CompressOpenForRead(isofile); + + } + else + { + isofile->handle = ActualFileOpenForRead(isofile->name); + retval = 0; + if (isofile->handle == ACTUALHANDLENULL) + { + retval = -1; + + } + else + { + isofile->filebytesize = ActualFileSize(isofile->handle); + isofile->filesectorsize = isofile->filebytesize / isofile->blocksize; + isofile->filebytepos = 0; + isofile->filesectorpos = 0; + } // ENDIF- Failed to open the file raw? + } // ENDIF- Compressed or non-compressed? What a question. + + if (retval < 0) + { + if (isofile->compress > 0) + { + CompressClose(isofile); + } + else + { + ActualFileClose(isofile->handle); + isofile->handle = ACTUALHANDLENULL; + } // ENDIF- Close a compressed file? (or an uncompressed one?) + + multinext--; + + isofile->name[isofile->multipos] = '0' + multinext; + if (isofile->compress > 0) + { + CompressOpenForRead(isofile); + } + else + { + isofile->handle = ActualFileOpenForRead(isofile->name); + isofile->filebytesize = ActualFileSize(isofile->handle); + isofile->filesectorsize = isofile->filebytesize / isofile->blocksize; + isofile->filebytepos = 0; + isofile->filesectorpos = 0; + } // ENDIF- Compressed or non-compressed? What a question. + isofile->multinow = multinext; + if (isofile->multinow == 0) + { + isofile->multioffset = 0; + } + else + { + isofile->multioffset = isofile->multisectorend[isofile->multinow - 1]; + } // ENDIF- At the start of the list? Offset 0. + return(-1); + } // ENDIF- Failed to open next in series? Revert and abort. + + isofile->multinow = multinext; + isofile->multiend = multinext; + isofile->multioffset = isofile->multisectorend[multinext - 1]; + isofile->multisectorend[multinext] = isofile->multisectorend[multinext - 1] + + isofile->filesectorsize; #ifdef VERBOSE_DISC_INFO - - PrintLog("CDVD multifile: File %i opened, %llu sectors found (%llu sectors total)", - - multinext, - - isofile->filesectorsize, - - isofile->multisectorend[multinext]); - + PrintLog("CDVD multifile: File %i opened, %llu sectors found (%llu sectors total)", + multinext, + isofile->filesectorsize, + isofile->multisectorend[multinext]); #endif /* VERBOSE_DISC_INFO */ - - } // ENDWHILE- searching through new files for a high enough end-mark - - - - if(multinext != isofile->multinow) { - + } // ENDWHILE- searching through new files for a high enough end-mark + if (multinext != isofile->multinow) + { #ifdef VERBOSE_WARNING_MULTIFILE - - PrintLog("CDVD multifile: Changing to File %i", multinext); - + PrintLog("CDVD multifile: Changing to File %i", multinext); #endif /* VERBOSE_WARNING_MULTIFILE */ + if (isofile->compress > 0) + { + CompressClose(isofile); + } + else + { + ActualFileClose(isofile->handle); + isofile->handle = ACTUALHANDLENULL; + } // ENDIF- Close a compressed file? (or an uncompressed one?) - if(isofile->compress > 0) { + isofile->name[isofile->multipos] = '0' + multinext; + if (isofile->compress > 0) + { + CompressOpenForRead(isofile); + } + else + { + isofile->handle = ActualFileOpenForRead(isofile->name); + if (isofile->handle == ACTUALHANDLENULL) return(-1); // Couldn't re-open? + isofile->filebytesize = ActualFileSize(isofile->handle); + isofile->filesectorsize = isofile->filebytesize / isofile->blocksize; + isofile->filebytepos = 0; + isofile->filesectorpos = 0; + } // ENDIF- Compressed or non-compressed? What a question. - CompressClose(isofile); - - } else { - - ActualFileClose(isofile->handle); - - isofile->handle = ACTUALHANDLENULL; - - } // ENDIF- Close a compressed file? (or an uncompressed one?) - - - - isofile->name[isofile->multipos] = '0' + multinext; - - if(isofile->compress > 0) { - - CompressOpenForRead(isofile); - - } else { - - isofile->handle = ActualFileOpenForRead(isofile->name); - - if(isofile->handle == ACTUALHANDLENULL) return(-1); // Couldn't re-open? - - isofile->filebytesize = ActualFileSize(isofile->handle); - - isofile->filesectorsize = isofile->filebytesize / isofile->blocksize; - - isofile->filebytepos = 0; - - isofile->filesectorpos = 0; - - } // ENDIF- Compressed or non-compressed? What a question. - - - - isofile->multinow = multinext; - - if(multinext == 0) { - - isofile->multioffset = 0; - - } else { - - isofile->multioffset = isofile->multisectorend[multinext - 1]; - - } // ENDIF- At the start of the list? Offset 0. - - } // ENDIF- Not looking at the same file? Change to the new one. - - - - tempfilesector = sector - isofile->multioffset; - - if(isofile->compress > 0) { - - return(CompressSeek(isofile, tempfilesector)); - - } else { - - retval = ActualFileSeek(isofile->handle, - - (tempfilesector * isofile->blocksize) - - + isofile->imageheader); - - if(retval == 0) { - - isofile->filesectorpos = sector; - - isofile->filebytepos = (sector * isofile->blocksize) - - + isofile->imageheader; - - } // ENDIF- Sucessful? Adjust internals - - return(retval); - - } // ENDIF- Seek a position in a compressed file? + isofile->multinow = multinext; + if (multinext == 0) + { + isofile->multioffset = 0; + } + else + { + isofile->multioffset = isofile->multisectorend[multinext - 1]; + } // ENDIF- At the start of the list? Offset 0. + } // ENDIF- Not looking at the same file? Change to the new one. + tempfilesector = sector - isofile->multioffset; + if (isofile->compress > 0) + { + return(CompressSeek(isofile, tempfilesector)); + } + else + { + retval = ActualFileSeek(isofile->handle, + (tempfilesector * isofile->blocksize) + + isofile->imageheader); + if (retval == 0) + { + isofile->filesectorpos = sector; + isofile->filebytepos = (sector * isofile->blocksize) + + isofile->imageheader; + } // ENDIF- Sucessful? Adjust internals + return(retval); + } // ENDIF- Seek a position in a compressed file? } // END MultiFileSeek() - - - - -int MultiFileRead(struct IsoFile *isofile, char *block) { - - int retval; - - +int MultiFileRead(struct IsoFile *isofile, char *block) +{ + int retval; #ifdef VERBOSE_FUNCTION_MULTIFILE - - PrintLog("CDVD multifile: MultiFileRead()"); - + PrintLog("CDVD multifile: MultiFileRead()"); #endif /* VERBOSE_FUNCTION_MULTIFILE */ - - - if(isofile->filesectorpos >= isofile->filesectorsize) - - MultiFileSeek(isofile, isofile->sectorpos); - - - - if(isofile->compress > 0) { - - return(CompressRead(isofile, block)); - - } else { - - retval = ActualFileRead(isofile->handle, isofile->blocksize, block); - - if(retval > 0) isofile->filebytepos += retval; - - if(retval == isofile->blocksize) isofile->filesectorpos++; - - return(retval); - - } // ENDIF- Read a compressed sector? - + if (isofile->filesectorpos >= isofile->filesectorsize) + MultiFileSeek(isofile, isofile->sectorpos); + if (isofile->compress > 0) + { + return(CompressRead(isofile, block)); + } + else + { + retval = ActualFileRead(isofile->handle, isofile->blocksize, block); + if (retval > 0) isofile->filebytepos += retval; + if (retval == isofile->blocksize) isofile->filesectorpos++; + return(retval); + } // ENDIF- Read a compressed sector? } // END MultiFileRead() - - - - -int MultiFileWrite(struct IsoFile *isofile, char *block) { - - int retval; - - - +int MultiFileWrite(struct IsoFile *isofile, char *block) +{ + int retval; #ifdef VERBOSE_FUNCTION_MULTIFILE - - PrintLog("CDVD multifile: MultiFileWrite()"); - + PrintLog("CDVD multifile: MultiFileWrite()"); #endif /* VERBOSE_FUNCTION_MULTIFILE */ + if (isofile->filebytesize + isofile->blocksize > FILESIZELIMIT) + { + if (isofile->compress > 0) + { + CompressClose(isofile); + } + else + { + ActualFileClose(isofile->handle); + isofile->handle = ACTUALHANDLENULL; + } // ENDIF- Close a compressed file? (or an uncompressed one?) + if (isofile->multinow == 9) return(-1); // Over 10 files? Overflow! - - - if(isofile->filebytesize + isofile->blocksize > FILESIZELIMIT) { - - if(isofile->compress > 0) { - - CompressClose(isofile); - - } else { - - ActualFileClose(isofile->handle); - - isofile->handle = ACTUALHANDLENULL; - - } // ENDIF- Close a compressed file? (or an uncompressed one?) - - if(isofile->multinow == 9) return(-1); // Over 10 files? Overflow! - - - - isofile->multioffset += isofile->filesectorsize; - - isofile->multinow++; - - isofile->multiend++; - + isofile->multioffset += isofile->filesectorsize; + isofile->multinow++; + isofile->multiend++; #ifdef VERBOSE_WARNING_MULTIFILE - - PrintLog("CDVD multifile: Changing to File %i", isofile->multinow); - + PrintLog("CDVD multifile: Changing to File %i", isofile->multinow); #endif /* VERBOSE_WARNING_MULTIFILE */ - - - - isofile->name[isofile->multipos] = '0' + isofile->multinow; - - if(isofile->compress > 0) { - - retval = CompressOpenForWrite(isofile); - - } else { - - isofile->handle = ActualFileOpenForWrite(isofile->name); - - if(isofile->handle == ACTUALHANDLENULL) { - - retval = -1; - - } else { - - retval = 0; - - isofile->filebytesize = 0; - - isofile->filesectorsize = 0; - - isofile->filebytepos = 0; - - isofile->filesectorpos = 0; - - } // ENDIF- Trouble opening next file? - - } // ENDIF- Opening the next compressed file? (Or uncompressed?) - - if(retval < 0) return(-1); // Couldn't open another file? Abort. - - } // ENDIF- Hit the size limit? Move on to next file... - - - - if(isofile->compress > 0) { - - return(CompressWrite(isofile, block)); - - } else { - - retval = ActualFileWrite(isofile->handle, isofile->blocksize, block); - - if(retval > 0) isofile->filebytepos += retval; - - if(retval == isofile->blocksize) isofile->filesectorpos++; - - return(retval); - - } // ENDIF- Write a compressed sector? - + isofile->name[isofile->multipos] = '0' + isofile->multinow; + if (isofile->compress > 0) + { + retval = CompressOpenForWrite(isofile); + } + else + { + isofile->handle = ActualFileOpenForWrite(isofile->name); + if (isofile->handle == ACTUALHANDLENULL) + { + retval = -1; + } + else + { + retval = 0; + isofile->filebytesize = 0; + isofile->filesectorsize = 0; + isofile->filebytepos = 0; + isofile->filesectorpos = 0; + } // ENDIF- Trouble opening next file? + } // ENDIF- Opening the next compressed file? (Or uncompressed?) + if (retval < 0) return(-1); // Couldn't open another file? Abort. + } // ENDIF- Hit the size limit? Move on to next file... + if (isofile->compress > 0) + { + return(CompressWrite(isofile, block)); + } + else + { + retval = ActualFileWrite(isofile->handle, isofile->blocksize, block); + if (retval > 0) isofile->filebytepos += retval; + if (retval == isofile->blocksize) isofile->filesectorpos++; + return(retval); + } // ENDIF- Write a compressed sector? } // END MultiFileWrite() - diff --git a/plugins/CDVDisoEFP/src/multifile.h b/plugins/CDVDisoEFP/src/multifile.h index d46a397ff3..585ba62057 100644 --- a/plugins/CDVDisoEFP/src/multifile.h +++ b/plugins/CDVDisoEFP/src/multifile.h @@ -1,106 +1,45 @@ /* multifile.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef MULTIFILE_H - #define MULTIFILE_H - - - - // #ifndef __LINUX__ - // #ifdef __linux__ - // #define __LINUX__ - // #endif /* __linux__ */ - // #endif /* No __LINUX__ */ - - // #define CDVDdefs - // #include "PS2Edefs.h" - - - #include "isofile.h" - - - - // #define VERBOSE_FUNCTION_MULTIFILE - // #define VERBOSE_WARNING_MULTIFILE - - - - extern char *multinames[]; - - - - extern void IsoNameStripMulti(struct IsoFile *isofile); - - - extern int MultiFileSeek(struct IsoFile *isofile, off64_t sector); - extern int MultiFileRead(struct IsoFile *isofile, char *block); - - extern int MultiFileWrite(struct IsoFile *isofile, char *block); - - - - #endif /* MULTIFILE_H */ - diff --git a/plugins/CDVDisoEFP/src/toc.c b/plugins/CDVDisoEFP/src/toc.c index 7a87b87df1..da0d673376 100644 --- a/plugins/CDVDisoEFP/src/toc.c +++ b/plugins/CDVDisoEFP/src/toc.c @@ -17,342 +17,330 @@ * * PCSX2 members can be contacted through their website at www.pcsx2.net. */ - - #include // NULL #include // off64_t - #ifndef __LINUX__ #ifdef __linux__ #define __LINUX__ #endif /* __linux__ */ #endif /* No __LINUX__ */ - #define CDVDdefs #include "PS2Edefs.h" - #include "logfile.h" #include "convert.h" #include "isofile.h" #include "actualfile.h" - #include "toc.h" - - // PCSX2's .toc file format: // 1 unsigned char - CDVD_TYPE_???? // 1 tocTN // As many tocTDs as it takes. +extern void IsoInitTOC(struct IsoFile *isofile) +{ + int i; + off64_t sectorsize; -extern void IsoInitTOC(struct IsoFile *isofile) { - int i; - off64_t sectorsize; - - if(isofile == NULL) return; + if (isofile == NULL) return; #ifdef VERBOSE_FUNCTION_TOC - PrintLog("CDVDiso TOC: IsoInitTOC()"); + PrintLog("CDVDiso TOC: IsoInitTOC()"); #endif /* VERBOSE_FUNCTION_TOC */ - if(isofile->multi > 0) { - sectorsize = isofile->multisectorend[isofile->multiend]; - } else { - sectorsize = isofile->filesectorsize; - } // ENDIF- Establish largest sector from multifile? (or single file?) + if (isofile->multi > 0) + { + sectorsize = isofile->multisectorend[isofile->multiend]; + } + else + { + sectorsize = isofile->filesectorsize; + } // ENDIF- Establish largest sector from multifile? (or single file?) - for(i = 0; i < 2048; i++) isofile->toc[i] = 0; - switch(isofile->cdvdtype) { - case CDVD_TYPE_DVDV: - case CDVD_TYPE_PS2DVD: - if((isofile->filesectorsize > (2048*1024)) || - (isofile->multi > 0)) { - isofile->toc[0] = 0x24; // Dual-Sided DVD (?) - isofile->toc[4] = 0x41; - isofile->toc[5] = 0x95; - } else { - isofile->toc[0] = 0x04; // Single-Sided DVD (?) - isofile->toc[4] = 0x86; - isofile->toc[5] = 0x72; - } // ENDIF- Too many sectors for a single-layered disc? + for (i = 0; i < 2048; i++) isofile->toc[i] = 0; + switch (isofile->cdvdtype) + { + case CDVD_TYPE_DVDV: + case CDVD_TYPE_PS2DVD: + if ((isofile->filesectorsize > (2048*1024)) || + (isofile->multi > 0)) + { + isofile->toc[0] = 0x24; // Dual-Sided DVD (?) + isofile->toc[4] = 0x41; + isofile->toc[5] = 0x95; + } + else + { + isofile->toc[0] = 0x04; // Single-Sided DVD (?) + isofile->toc[4] = 0x86; + isofile->toc[5] = 0x72; + } // ENDIF- Too many sectors for a single-layered disc? + isofile->toc[1] = 0x02; + isofile->toc[2] = 0xF2; + isofile->toc[3] = 0x00; + isofile->toc[16] = 0x00; + isofile->toc[17] = 0x03; + isofile->toc[18] = 0x00; + isofile->toc[19] = 0x00; + return; // DVD's don't have tracks. Might track multisession later... + break; - isofile->toc[1] = 0x02; - isofile->toc[2] = 0xF2; - isofile->toc[3] = 0x00; - - isofile->toc[16] = 0x00; - isofile->toc[17] = 0x03; - isofile->toc[18] = 0x00; - isofile->toc[19] = 0x00; - return; // DVD's don't have tracks. Might track multisession later... - break; - - case CDVD_TYPE_PS2CD: - case CDVD_TYPE_PSCD: - isofile->toc[0] = 0x41; - break; - case CDVD_TYPE_CDDA: - isofile->toc[0] = 0x01; - break; - default: - break; - } // ENDSWITCH isofile->cdvdtype - Which TOC for which type? - - // CD Details here... (tracks and stuff) - isofile->toc[2] = 0xA0; - isofile->toc[7] = 0x01; // Starting Track No. - isofile->toc[12] = 0xA1; - isofile->toc[17] = 0x01; // Ending Track No. - - isofile->toc[22] = 0xA2; - LBAtoMSF(sectorsize, &isofile->toc[27]); - isofile->toc[27] = HEXTOBCD(isofile->toc[27]); - isofile->toc[28] = HEXTOBCD(isofile->toc[28]); - isofile->toc[29] = HEXTOBCD(isofile->toc[29]); - - isofile->toc[40] = 0x02; // YellowBook? Data Mode? - isofile->toc[42] = 0x01; // Track No. - LBAtoMSF(0, &isofile->toc[47]); - isofile->toc[47] = HEXTOBCD(isofile->toc[47]); - isofile->toc[48] = HEXTOBCD(isofile->toc[48]); - isofile->toc[49] = HEXTOBCD(isofile->toc[49]); + case CDVD_TYPE_PS2CD: + case CDVD_TYPE_PSCD: + isofile->toc[0] = 0x41; + break; + case CDVD_TYPE_CDDA: + isofile->toc[0] = 0x01; + break; + default: + break; + } // ENDSWITCH isofile->cdvdtype - Which TOC for which type? + // CD Details here... (tracks and stuff) + isofile->toc[2] = 0xA0; + isofile->toc[7] = 0x01; // Starting Track No. + isofile->toc[12] = 0xA1; + isofile->toc[17] = 0x01; // Ending Track No. + isofile->toc[22] = 0xA2; + LBAtoMSF(sectorsize, &isofile->toc[27]); + isofile->toc[27] = HEXTOBCD(isofile->toc[27]); + isofile->toc[28] = HEXTOBCD(isofile->toc[28]); + isofile->toc[29] = HEXTOBCD(isofile->toc[29]); + isofile->toc[40] = 0x02; // YellowBook? Data Mode? + isofile->toc[42] = 0x01; // Track No. + LBAtoMSF(0, &isofile->toc[47]); + isofile->toc[47] = HEXTOBCD(isofile->toc[47]); + isofile->toc[48] = HEXTOBCD(isofile->toc[48]); + isofile->toc[49] = HEXTOBCD(isofile->toc[49]); } // END IsoInitTOC() - -extern void IsoAddTNToTOC(struct IsoFile *isofile, struct tocTN toctn) { - if(isofile == NULL) return; - +extern void IsoAddTNToTOC(struct IsoFile *isofile, struct tocTN toctn) +{ + if (isofile == NULL) return; #ifdef VERBOSE_FUNCTION_TOC - PrintLog("CDVDiso TOC: IsoAddTNToTOC()"); + PrintLog("CDVDiso TOC: IsoAddTNToTOC()"); #endif /* VERBOSE_FUNCTION_TOC */ - - isofile->toc[7] = HEXTOBCD(toctn.strack); - isofile->toc[17] = HEXTOBCD(toctn.etrack); - return; + isofile->toc[7] = HEXTOBCD(toctn.strack); + isofile->toc[17] = HEXTOBCD(toctn.etrack); + return; } // END IsoAddTNToTOC() - extern void IsoAddTDToTOC(struct IsoFile *isofile, - unsigned char track, - struct tocTD toctd) { - int temptrack; - int position; - + unsigned char track, + struct tocTD toctd) +{ + int temptrack; + int position; #ifdef VERBOSE_FUNCTION_TOC - PrintLog("CDVDiso TOC: IsoAddTNToTOC(%u)", track); + PrintLog("CDVDiso TOC: IsoAddTNToTOC(%u)", track); #endif /* VERBOSE_FUNCTION_TOC */ - - if(isofile == NULL) return; - - temptrack = track; - if(temptrack == 0xAA) temptrack = 0; - if(temptrack > 99) return; // Only up to 99 tracks allowed. - - if(temptrack == 0) { - LBAtoMSF(toctd.lsn, &isofile->toc[27]); - isofile->toc[27] = HEXTOBCD(isofile->toc[27]); - isofile->toc[28] = HEXTOBCD(isofile->toc[28]); - isofile->toc[29] = HEXTOBCD(isofile->toc[29]); - - } else { - position = temptrack * 10; - position += 30; - isofile->toc[position] = toctd.type; - isofile->toc[position + 2] = HEXTOBCD(temptrack); - LBAtoMSF(toctd.lsn, &isofile->toc[position + 7]); - isofile->toc[position + 7] = HEXTOBCD(isofile->toc[position + 7]); - isofile->toc[position + 8] = HEXTOBCD(isofile->toc[position + 8]); - isofile->toc[position + 9] = HEXTOBCD(isofile->toc[position + 9]); - } // ENDIF- Is this a lead-out? (or an actual track?) + if (isofile == NULL) return; + temptrack = track; + if (temptrack == 0xAA) temptrack = 0; + if (temptrack > 99) return; // Only up to 99 tracks allowed. + if (temptrack == 0) + { + LBAtoMSF(toctd.lsn, &isofile->toc[27]); + isofile->toc[27] = HEXTOBCD(isofile->toc[27]); + isofile->toc[28] = HEXTOBCD(isofile->toc[28]); + isofile->toc[29] = HEXTOBCD(isofile->toc[29]); + } + else + { + position = temptrack * 10; + position += 30; + isofile->toc[position] = toctd.type; + isofile->toc[position + 2] = HEXTOBCD(temptrack); + LBAtoMSF(toctd.lsn, &isofile->toc[position + 7]); + isofile->toc[position + 7] = HEXTOBCD(isofile->toc[position + 7]); + isofile->toc[position + 8] = HEXTOBCD(isofile->toc[position + 8]); + isofile->toc[position + 9] = HEXTOBCD(isofile->toc[position + 9]); + } // ENDIF- Is this a lead-out? (or an actual track?) } // END IsoAddTDToTOC() +extern int IsoLoadTOC(struct IsoFile *isofile) +{ + char tocext[] = ".toc\0"; + char tocheader[5]; + ACTUALHANDLE tochandle; + char tocname[256]; + int i; + int j; + int retval; + unsigned char cdvdtype; + struct tocTN toctn; + struct tocTD toctd; + if (isofile == NULL) return(-1); + i = 0; + while ((i < 256) && (isofile->name[i] != 0)) + { + tocname[i] = isofile->name[i]; + i++; + } // ENDWHILE- Copying the data name to the toc name + j = 0; + while ((i < 256) && (tocext[j] != 0)) + { + tocname[i] = tocext[j]; + i++; + j++; + } // ENDWHILE- Append ".toc" to end of name + tocname[i] = 0; // And 0-terminate + tochandle = ActualFileOpenForRead(tocname); + if (tochandle == ACTUALHANDLENULL) return(-1); - -extern int IsoLoadTOC(struct IsoFile *isofile) { - char tocext[] = ".toc\0"; - char tocheader[5]; - ACTUALHANDLE tochandle; - char tocname[256]; - int i; - int j; - int retval; - unsigned char cdvdtype; - struct tocTN toctn; - struct tocTD toctd; - - if(isofile == NULL) return(-1); - - i = 0; - while((i < 256) && (isofile->name[i] != 0)) { - tocname[i] = isofile->name[i]; - i++; - } // ENDWHILE- Copying the data name to the toc name - j = 0; - while((i < 256) && (tocext[j] != 0)) { - tocname[i] = tocext[j]; - i++; - j++; - } // ENDWHILE- Append ".toc" to end of name - tocname[i] = 0; // And 0-terminate - - tochandle = ActualFileOpenForRead(tocname); - if(tochandle == ACTUALHANDLENULL) return(-1); - - retval = ActualFileRead(tochandle, 4, tocheader); - if(retval < 4) { - ActualFileClose(tochandle); - tochandle = ACTUALHANDLENULL; - return(-1); - } // ENDIF- Trouble reading the 'toc' file? - - if((tocheader[0] != 'T') || - (tocheader[1] != 'O') || - (tocheader[2] != 'C') || - (tocheader[3] != '1')) { - ActualFileClose(tochandle); - tochandle = ACTUALHANDLENULL; - return(-1); - } // ENDIF- Not a 'toc' file after all? - + retval = ActualFileRead(tochandle, 4, tocheader); + if (retval < 4) + { + ActualFileClose(tochandle); + tochandle = ACTUALHANDLENULL; + return(-1); + } // ENDIF- Trouble reading the 'toc' file? + if ((tocheader[0] != 'T') || + (tocheader[1] != 'O') || + (tocheader[2] != 'C') || + (tocheader[3] != '1')) + { + ActualFileClose(tochandle); + tochandle = ACTUALHANDLENULL; + return(-1); + } // ENDIF- Not a 'toc' file after all? #ifdef VERBOSE_FUNCTION_TOC - PrintLog("CDVDiso TOC: IsoLoadTOC(%s)", tocname); + PrintLog("CDVDiso TOC: IsoLoadTOC(%s)", tocname); #endif /* VERBOSE_FUNCTION_TOC */ + retval = ActualFileRead(tochandle, 1, (char *) & cdvdtype); + if (retval < 1) + { + ActualFileClose(tochandle); + tochandle = ACTUALHANDLENULL; + return(-1); + } // ENDIF- Trouble reading the 'toc' file? + isofile->cdvdtype = cdvdtype; + IsoInitTOC(isofile); - retval = ActualFileRead(tochandle, 1, (char *) &cdvdtype); - if(retval < 1) { - ActualFileClose(tochandle); - tochandle = ACTUALHANDLENULL; - return(-1); - } // ENDIF- Trouble reading the 'toc' file? + if ((cdvdtype != CDVD_TYPE_PS2DVD) && (cdvdtype != CDVD_TYPE_DVDV)) + { + retval = ActualFileRead(tochandle, sizeof(struct tocTN), (char *) & toctn); + if (retval < sizeof(struct tocTN)) + { + ActualFileClose(tochandle); + tochandle = ACTUALHANDLENULL; + return(-1); + } // ENDIF- Trouble reading the 'toc' file? - isofile->cdvdtype = cdvdtype; - IsoInitTOC(isofile); - - if((cdvdtype != CDVD_TYPE_PS2DVD) && (cdvdtype != CDVD_TYPE_DVDV)) { - retval = ActualFileRead(tochandle, sizeof(struct tocTN), (char *) &toctn); - if(retval < sizeof(struct tocTN)) { - ActualFileClose(tochandle); - tochandle = ACTUALHANDLENULL; - return(-1); - } // ENDIF- Trouble reading the 'toc' file? - - if((toctn.strack > 99) || (toctn.etrack > 99)) { - ActualFileClose(tochandle); - tochandle = ACTUALHANDLENULL; - return(-1); - } // ENDIF- Track numbers out of range? + if ((toctn.strack > 99) || (toctn.etrack > 99)) + { + ActualFileClose(tochandle); + tochandle = ACTUALHANDLENULL; + return(-1); + } // ENDIF- Track numbers out of range? #ifdef VERBOSE_FUNCTION_TOC - PrintLog("CDVDiso TOC: Start Track %u End Track %u", - toctn.strack, toctn.etrack); + PrintLog("CDVDiso TOC: Start Track %u End Track %u", + toctn.strack, toctn.etrack); #endif /* VERBOSE_FUNCTION_TOC */ - IsoAddTNToTOC(isofile, toctn); - - retval = ActualFileRead(tochandle, sizeof(struct tocTD), (char *) &toctd); - if(retval < sizeof(struct tocTD)) { - ActualFileClose(tochandle); - tochandle = ACTUALHANDLENULL; - return(-1); - } // ENDIF- Trouble reading the 'toc' file? - - if(toctd.type != 0) { - ActualFileClose(tochandle); - tochandle = ACTUALHANDLENULL; - return(-1); - } // ENDIF- Track numbers out of range? + IsoAddTNToTOC(isofile, toctn); + retval = ActualFileRead(tochandle, sizeof(struct tocTD), (char *) & toctd); + if (retval < sizeof(struct tocTD)) + { + ActualFileClose(tochandle); + tochandle = ACTUALHANDLENULL; + return(-1); + } // ENDIF- Trouble reading the 'toc' file? + if (toctd.type != 0) + { + ActualFileClose(tochandle); + tochandle = ACTUALHANDLENULL; + return(-1); + } // ENDIF- Track numbers out of range? #ifdef VERBOSE_FUNCTION_TOC - PrintLog("CDVDiso TOC: Total Sectors: %lu", toctd.lsn); + PrintLog("CDVDiso TOC: Total Sectors: %lu", toctd.lsn); #endif /* VERBOSE_FUNCTION_TOC */ - IsoAddTDToTOC(isofile, 0xAA, toctd); - - for(i = toctn.strack; i <= toctn.etrack; i++) { - - retval = ActualFileRead(tochandle, sizeof(struct tocTD), (char *) &toctd); - if(retval < sizeof(struct tocTD)) { - ActualFileClose(tochandle); - tochandle = ACTUALHANDLENULL; - return(-1); - } // ENDIF- Trouble reading the 'toc' file? + IsoAddTDToTOC(isofile, 0xAA, toctd); + for (i = toctn.strack; i <= toctn.etrack; i++) + { + retval = ActualFileRead(tochandle, sizeof(struct tocTD), (char *) & toctd); + if (retval < sizeof(struct tocTD)) + { + ActualFileClose(tochandle); + tochandle = ACTUALHANDLENULL; + return(-1); + } // ENDIF- Trouble reading the 'toc' file? #ifdef VERBOSE_FUNCTION_TOC - PrintLog("CDVDiso TOC: Track %u Type %u Sector Start: %lu", - i, toctd.type, toctd.lsn); + PrintLog("CDVDiso TOC: Track %u Type %u Sector Start: %lu", + i, toctd.type, toctd.lsn); #endif /* VERBOSE_FUNCTION_TOC */ - IsoAddTDToTOC(isofile, i, toctd); - } // NEXT i- read in each track - } // ENDIF- Not a DVD? (Then read in CD track data) - ActualFileClose(tochandle); - tochandle = ACTUALHANDLENULL; - - return(0); + IsoAddTDToTOC(isofile, i, toctd); + } // NEXT i- read in each track + } // ENDIF- Not a DVD? (Then read in CD track data) + ActualFileClose(tochandle); + tochandle = ACTUALHANDLENULL; + return(0); } // END IsoLoadTOC() +extern int IsoSaveTOC(struct IsoFile *isofile) +{ + char tocext[] = ".toc\0"; + char tocheader[] = "TOC1\0"; + ACTUALHANDLE tochandle; + char tocname[256]; + int i; + int j; + int retval; + unsigned char cdvdtype; + struct tocTN toctn; + struct tocTD toctd; + char temptime[3]; + if (isofile == NULL) return(-1); + i = 0; + while ((i < 256) && (isofile->name[i] != 0)) + { + tocname[i] = isofile->name[i]; + i++; + } // ENDWHILE- Copying the data name to the toc name + j = 0; + while ((i < 256) && (tocext[j] != 0)) + { + tocname[i] = tocext[j]; + i++; + j++; + } // ENDWHILE- Append ".toc" to end of name + tocname[i] = 0; // And 0-terminate -extern int IsoSaveTOC(struct IsoFile *isofile) { - char tocext[] = ".toc\0"; - char tocheader[] = "TOC1\0"; - ACTUALHANDLE tochandle; - char tocname[256]; - int i; - int j; - int retval; - unsigned char cdvdtype; - struct tocTN toctn; - struct tocTD toctd; - char temptime[3]; + ActualFileDelete(tocname); + tochandle = ActualFileOpenForWrite(tocname); + if (tochandle == ACTUALHANDLENULL) return(-1); - if(isofile == NULL) return(-1); + retval = ActualFileWrite(tochandle, 4, tocheader); + if (retval < 4) + { + ActualFileClose(tochandle); + tochandle = ACTUALHANDLENULL; + ActualFileDelete(tocname); + return(-1); + } // ENDIF- Trouble writing to the 'toc' file? - i = 0; - while((i < 256) && (isofile->name[i] != 0)) { - tocname[i] = isofile->name[i]; - i++; - } // ENDWHILE- Copying the data name to the toc name - j = 0; - while((i < 256) && (tocext[j] != 0)) { - tocname[i] = tocext[j]; - i++; - j++; - } // ENDWHILE- Append ".toc" to end of name - tocname[i] = 0; // And 0-terminate - - ActualFileDelete(tocname); - tochandle = ActualFileOpenForWrite(tocname); - if(tochandle == ACTUALHANDLENULL) return(-1); - - retval = ActualFileWrite(tochandle, 4, tocheader); - if(retval < 4) { - ActualFileClose(tochandle); - tochandle = ACTUALHANDLENULL; - ActualFileDelete(tocname); - return(-1); - } // ENDIF- Trouble writing to the 'toc' file? - - cdvdtype = isofile->cdvdtype; - ActualFileWrite(tochandle, 1, (char *) &cdvdtype); - - if((cdvdtype != CDVD_TYPE_PS2DVD) && (cdvdtype != CDVD_TYPE_DVDV)) { - toctn.strack = BCDTOHEX(isofile->toc[7]); - toctn.etrack = BCDTOHEX(isofile->toc[17]); - ActualFileWrite(tochandle, sizeof(struct tocTN), (char *) &toctn); - - // Leadout Data - toctd.type = 0; - temptime[0] = BCDTOHEX(isofile->toc[27]); - temptime[1] = BCDTOHEX(isofile->toc[28]); - temptime[2] = BCDTOHEX(isofile->toc[29]); - toctd.lsn = MSFtoLBA(temptime); - ActualFileWrite(tochandle, sizeof(struct tocTD), (char *) &toctd); - - for(i = toctn.strack; i <= toctn.etrack; i++) { - j = i * 10 + 30; - toctd.type = isofile->toc[j]; - temptime[0] = BCDTOHEX(isofile->toc[j + 7]); - temptime[1] = BCDTOHEX(isofile->toc[j + 8]); - temptime[2] = BCDTOHEX(isofile->toc[j + 9]); - toctd.lsn = MSFtoLBA(temptime); - ActualFileWrite(tochandle, sizeof(struct tocTD), (char *) &toctd); - } // NEXT i- write out each track - } // ENDIF- Not a DVD? (Then output CD track data) - ActualFileClose(tochandle); - tochandle = ACTUALHANDLENULL; - - return(0); + cdvdtype = isofile->cdvdtype; + ActualFileWrite(tochandle, 1, (char *) &cdvdtype); + if ((cdvdtype != CDVD_TYPE_PS2DVD) && (cdvdtype != CDVD_TYPE_DVDV)) + { + toctn.strack = BCDTOHEX(isofile->toc[7]); + toctn.etrack = BCDTOHEX(isofile->toc[17]); + ActualFileWrite(tochandle, sizeof(struct tocTN), (char *) &toctn); + // Leadout Data + toctd.type = 0; + temptime[0] = BCDTOHEX(isofile->toc[27]); + temptime[1] = BCDTOHEX(isofile->toc[28]); + temptime[2] = BCDTOHEX(isofile->toc[29]); + toctd.lsn = MSFtoLBA(temptime); + ActualFileWrite(tochandle, sizeof(struct tocTD), (char *) &toctd); + for (i = toctn.strack; i <= toctn.etrack; i++) + { + j = i * 10 + 30; + toctd.type = isofile->toc[j]; + temptime[0] = BCDTOHEX(isofile->toc[j + 7]); + temptime[1] = BCDTOHEX(isofile->toc[j + 8]); + temptime[2] = BCDTOHEX(isofile->toc[j + 9]); + toctd.lsn = MSFtoLBA(temptime); + ActualFileWrite(tochandle, sizeof(struct tocTD), (char *) &toctd); + } // NEXT i- write out each track + } // ENDIF- Not a DVD? (Then output CD track data) + ActualFileClose(tochandle); + tochandle = ACTUALHANDLENULL; + return(0); } // END IsoSaveTOC() diff --git a/plugins/CDVDisoEFP/src/toc.h b/plugins/CDVDisoEFP/src/toc.h index 26dc7e4554..64b770ebad 100644 --- a/plugins/CDVDisoEFP/src/toc.h +++ b/plugins/CDVDisoEFP/src/toc.h @@ -17,12 +17,9 @@ * * PCSX2 members can be contacted through their website at www.pcsx2.net. */ - - #ifndef TOC_H #define TOC_H - // #ifndef __LINUX__ // #ifdef __linux__ // #define __LINUX__ @@ -31,54 +28,46 @@ // #define CDVDdefs // #include "PS2Edefs.h" - #include "isofile.h" - // #define VERBOSE_FUNCTION_TOC - #ifdef _WIN32 #pragma pack(1) #endif /* _WIN32 */ - -struct tocTD { - unsigned long lsn; - unsigned char type; +struct tocTD +{ + unsigned long lsn; + unsigned char type; #ifdef _WIN32 }; #else -} __attribute__ ((packed)); +} __attribute__((packed)); #endif /* _WIN32 */ -struct tocTN { - unsigned char strack; - unsigned char etrack; +struct tocTN +{ + unsigned char strack; + unsigned char etrack; #ifdef _WIN32 }; #else -} __attribute__ ((packed)); +} __attribute__((packed)); #endif /* _WIN32 */ - #ifdef _WIN32 #pragma pack() #endif /* _WIN32 */ - // PCSX2's .toc file format: // 1 unsigned char - CDVD_TYPE_???? // 1 tocTN // As many tocTDs as it takes. - - extern void IsoInitTOC(struct IsoFile *isofile); extern void IsoAddTNToTOC(struct IsoFile *isofile, struct tocTN toctn); extern void IsoAddTDToTOC(struct IsoFile *isofile, - unsigned char track, - struct tocTD toctd); - + unsigned char track, + struct tocTD toctd); extern int IsoLoadTOC(struct IsoFile *isofile); extern int IsoSaveTOC(struct IsoFile *isofile); - #endif /* TOC_H */ diff --git a/plugins/CDVDisoEFP/src/version.c b/plugins/CDVDisoEFP/src/version.c index 44ebe48aa5..35c43596f9 100644 --- a/plugins/CDVDisoEFP/src/version.c +++ b/plugins/CDVDisoEFP/src/version.c @@ -1,72 +1,36 @@ -/* version.c - - * Copyright (C) 2002-2005 PCSX2 Team - - * - - * This program is free software; you can redistribute it and/or modify - - * it under the terms of the GNU General Public License as published by - - * the Free Software Foundation; either version 2 of the License, or - - * (at your option) any later version. - - * - - * This program is distributed in the hope that it will be useful, - - * but WITHOUT ANY WARRANTY; without even the implied warranty of - - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - - * GNU General Public License for more details. - - * - - * You should have received a copy of the GNU General Public License - - * along with this program; if not, write to the Free Software - - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - * - - * PCSX2 members can be contacted through their website at www.pcsx2.net. - - */ - - - - - -#ifndef __LINUX__ - -#ifdef __linux__ - -#define __LINUX__ - -#endif /* __linux__ */ - -#endif /* No __LINUX__ */ - - - -#define CDVDdefs - -#include "PS2Edefs.h" - - - - - -char *libname = "EFP Iso CDVD Driver"; - - - -const unsigned char version = PS2E_CDVD_VERSION; - -const unsigned char revision = 0; - -const unsigned char build = 6; - +/* version.c + * Copyright (C) 2002-2005 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCSX2 members can be contacted through their website at www.pcsx2.net. + */ + + +#ifndef __LINUX__ +#ifdef __linux__ +#define __LINUX__ +#endif /* __linux__ */ +#endif /* No __LINUX__ */ + +#define CDVDdefs +#include "PS2Edefs.h" + + +char *libname = "EFP Iso CDVD Driver"; + +const unsigned char version = PS2E_CDVD_VERSION; +const unsigned char revision = 0; +const unsigned char build = 6; diff --git a/plugins/CDVDisoEFP/src/version.h b/plugins/CDVDisoEFP/src/version.h index 2fb4b2751c..ae31e70502 100644 --- a/plugins/CDVDisoEFP/src/version.h +++ b/plugins/CDVDisoEFP/src/version.h @@ -1,86 +1,39 @@ /* version.h - * Copyright (C) 2002-2005 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * PCSX2 members can be contacted through their website at www.pcsx2.net. - */ - - - - #ifndef VERSION_H - #define VERSION_H - - - - #ifndef __LINUX__ - #ifdef __linux__ - #define __LINUX__ - #endif /* __linux__ */ - #endif /* No __LINUX__ */ - - #define CDVDdefs - #include "PS2Edefs.h" - - - - extern char *libname; - - extern const unsigned char version; - extern const unsigned char revision; - extern const unsigned char build; - - - - #endif /* VERSION_H */ -