reformat CDVDiso

This commit is contained in:
Clang Format 2016-09-04 14:19:01 +02:00 committed by Gregory Hainaut
parent d6ae5bfafa
commit e503534ff4
14 changed files with 2142 additions and 2171 deletions

View File

@ -20,7 +20,7 @@
#define __CDVDISO_H__
#ifdef _MSC_VER
#pragma warning(disable:4018)
#pragma warning(disable : 4018)
#endif
#include "PS2Edefs.h"
@ -31,7 +31,7 @@
#ifdef _MSC_VER
#define EXPORT_C_(type) extern "C" __declspec(dllexport) type CALLBACK
#else
#define EXPORT_C_(type) extern "C" __attribute__((stdcall,externally_visible,visibility("default"))) type
#define EXPORT_C_(type) extern "C" __attribute__((stdcall, externally_visible, visibility("default"))) type
#endif
#else
@ -39,40 +39,61 @@
#ifdef _MSC_VER
#define EXPORT_C_(type) __declspec(dllexport) type __stdcall
#else
#define EXPORT_C_(type) __attribute__((stdcall,externally_visible,visibility("default"))) type
#define EXPORT_C_(type) __attribute__((stdcall, externally_visible, visibility("default"))) type
#endif
#endif
EXPORT_C_(u32) PS2EgetLibType();
EXPORT_C_(u32) PS2EgetLibVersion2(u32 type);
EXPORT_C_(char*) PS2EgetLibName();
EXPORT_C_(u32)
PS2EgetLibType();
EXPORT_C_(u32)
PS2EgetLibVersion2(u32 type);
EXPORT_C_(char *)
PS2EgetLibName();
EXPORT_C_(s32) CDVDinit();
EXPORT_C_(s32) CDVDopen(const char* pTitleFilename);
EXPORT_C_(void) CDVDclose();
EXPORT_C_(void) CDVDshutdown();
EXPORT_C_(s32) CDVDreadTrack(u32 lsn, int mode);
EXPORT_C_(s32)
CDVDinit();
EXPORT_C_(s32)
CDVDopen(const char *pTitleFilename);
EXPORT_C_(void)
CDVDclose();
EXPORT_C_(void)
CDVDshutdown();
EXPORT_C_(s32)
CDVDreadTrack(u32 lsn, int mode);
// return can be NULL (for async modes)
EXPORT_C_(u8*) CDVDgetBuffer();
EXPORT_C_(u8 *)
CDVDgetBuffer();
EXPORT_C_(s32) CDVDreadSubQ(u32 lsn, cdvdSubQ* subq);//read subq from disc (only cds have subq data)
EXPORT_C_(s32) CDVDgetTN(cdvdTN *Buffer); //disk information
EXPORT_C_(s32) CDVDgetTD(u8 Track, cdvdTD *Buffer); //track info: min,sec,frame,type
EXPORT_C_(s32) CDVDgetTOC(void* toc); //gets ps2 style toc from disc
EXPORT_C_(s32) CDVDgetDiskType(); //CDVD_TYPE_xxxx
EXPORT_C_(s32) CDVDgetTrayStatus(); //CDVD_TRAY_xxxx
EXPORT_C_(s32) CDVDctrlTrayOpen(); //open disc tray
EXPORT_C_(s32) CDVDctrlTrayClose(); //close disc tray
EXPORT_C_(s32)
CDVDreadSubQ(u32 lsn, cdvdSubQ *subq); //read subq from disc (only cds have subq data)
EXPORT_C_(s32)
CDVDgetTN(cdvdTN *Buffer); //disk information
EXPORT_C_(s32)
CDVDgetTD(u8 Track, cdvdTD *Buffer); //track info: min,sec,frame,type
EXPORT_C_(s32)
CDVDgetTOC(void *toc); //gets ps2 style toc from disc
EXPORT_C_(s32)
CDVDgetDiskType(); //CDVD_TYPE_xxxx
EXPORT_C_(s32)
CDVDgetTrayStatus(); //CDVD_TRAY_xxxx
EXPORT_C_(s32)
CDVDctrlTrayOpen(); //open disc tray
EXPORT_C_(s32)
CDVDctrlTrayClose(); //close disc tray
// extended funcs
EXPORT_C_(void) CDVDconfigure();
EXPORT_C_(void) CDVDabout();
EXPORT_C_(s32) CDVDtest();
EXPORT_C_(void) CDVDnewDiskCB(void (*callback)());
EXPORT_C_(void)
CDVDconfigure();
EXPORT_C_(void)
CDVDabout();
EXPORT_C_(s32)
CDVDtest();
EXPORT_C_(void)
CDVDnewDiskCB(void (*callback)());
#define CDVD_LOG __Log
extern FILE *cdvdLog;
@ -98,12 +119,12 @@ typedef struct
extern _cdIso cdIso[8];
#define CD_FRAMESIZE_RAW 2352
#define DATA_SIZE (CD_FRAMESIZE_RAW-12)
#define DATA_SIZE (CD_FRAMESIZE_RAW - 12)
#define itob(i) ((i)/10*16 + (i)%10) /* u_char to BCD */
#define btoi(b) ((b)/16*10 + (b)%16) /* BCD to u_char */
#define itob(i) ((i) / 10 * 16 + (i) % 10) /* u_char to BCD */
#define btoi(b) ((b) / 16 * 10 + (b) % 16) /* BCD to u_char */
#define MSF2SECT(m,s,f) (((m)*60+(s)-2)*75+(f))
#define MSF2SECT(m, s, f) (((m)*60 + (s)-2) * 75 + (f))
extern const u8 version;
extern const u8 revision;

View File

@ -41,11 +41,10 @@ FILE *cdvdLog = NULL;
static char cdvdCurrentIso[MAX_PATH];
char *methods[] =
{
{
".Z - compress faster",
".BZ - compress better",
NULL
};
NULL};
#ifdef PCSX2_DEBUG
char *LibName = "Linuz Iso CDVD (Debug) ";
@ -68,7 +67,7 @@ s32 msf_to_lba(u8 m, u8 s, u8 f)
return lsn;
}
void lba_to_msf(s32 lba, u8* m, u8* s, u8* f)
void lba_to_msf(s32 lba, u8 *m, u8 *s, u8 *f)
{
lba += 150;
*m = lba / (60 * 75);
@ -76,21 +75,24 @@ void lba_to_msf(s32 lba, u8* m, u8* s, u8* f)
*f = lba % 75;
}
#define btoi(b) ((b)/16*10 + (b)%16) /* BCD to u_char */
#define itob(i) ((i)/10*16 + (i)%10) /* u_char to BCD */
#define btoi(b) ((b) / 16 * 10 + (b) % 16) /* BCD to u_char */
#define itob(i) ((i) / 10 * 16 + (i) % 10) /* u_char to BCD */
EXPORT_C_(char*) PS2EgetLibName()
EXPORT_C_(char *)
PS2EgetLibName()
{
return LibName;
}
EXPORT_C_(u32) PS2EgetLibType()
EXPORT_C_(u32)
PS2EgetLibType()
{
return PS2E_LT_CDVD;
}
EXPORT_C_(u32) PS2EgetLibVersion2(u32 type)
EXPORT_C_(u32)
PS2EgetLibVersion2(u32 type)
{
return (version << 16) | (revision << 8) | build;
}
@ -100,26 +102,26 @@ void __Log(char *fmt, ...)
{
va_list list;
if (cdvdLog == NULL) return;
if (cdvdLog == NULL)
return;
va_start(list, fmt);
vfprintf(cdvdLog, fmt, list);
va_end(list);
}
#else
#define __Log 0&&
#define __Log 0 &&
#endif
EXPORT_C_(s32) CDVDinit()
EXPORT_C_(s32)
CDVDinit()
{
#ifdef PCSX2_DEBUG
cdvdLog = fopen("logs/cdvdLog.txt", "w");
if (cdvdLog == NULL)
{
if (cdvdLog == NULL) {
cdvdLog = fopen("cdvdLog.txt", "w");
if (cdvdLog == NULL)
{
if (cdvdLog == NULL) {
SysMessage("Can't create cdvdLog.txt");
return -1;
}
@ -133,30 +135,33 @@ EXPORT_C_(s32) CDVDinit()
return 0;
}
EXPORT_C_(void) CDVDshutdown()
EXPORT_C_(void)
CDVDshutdown()
{
cdvdCurrentIso[0] = 0;
#ifdef CDVD_LOG
if (cdvdLog != NULL) fclose(cdvdLog);
if (cdvdLog != NULL)
fclose(cdvdLog);
#endif
}
EXPORT_C_(s32) CDVDopen(const char* pTitle)
EXPORT_C_(s32)
CDVDopen(const char *pTitle)
{
LoadConf();
if (pTitle != NULL) strcpy(IsoFile, pTitle);
if (*IsoFile == 0) strcpy(IsoFile, cdvdCurrentIso);
if (pTitle != NULL)
strcpy(IsoFile, pTitle);
if (*IsoFile == 0)
{
strcpy(IsoFile, cdvdCurrentIso);
if (*IsoFile == 0) {
char temp[256];
CfgOpenFile();
if (IsoFile[0] == 0)
{
if (IsoFile[0] == 0) {
// user pressed CANCEL
return 1;
}
@ -168,8 +173,7 @@ EXPORT_C_(s32) CDVDopen(const char* pTitle)
}
iso = isoOpen(IsoFile);
if (iso == NULL)
{
if (iso == NULL) {
SysMessage("Error loading %s\nMake sure the iso file is not mounted in any disk emulation software!", IsoFile);
return -1;
}
@ -181,8 +185,7 @@ EXPORT_C_(s32) CDVDopen(const char* pTitle)
else
cdtype = CDVD_TYPE_PS2CD;
if (BlockDump)
{
if (BlockDump) {
char fname_only[MAX_PATH];
#ifdef _WIN32
@ -190,11 +193,10 @@ EXPORT_C_(s32) CDVDopen(const char* pTitle)
_splitpath(IsoFile, NULL, NULL, fname, ext);
_makepath(fname_only, NULL, NULL, fname, NULL);
#else
char* p, *plast;
char *p, *plast;
plast = p = strchr(IsoFile, '/');
while (p != NULL)
{
while (p != NULL) {
plast = p;
p = strchr(p + 1, '/');
}
@ -208,40 +210,44 @@ EXPORT_C_(s32) CDVDopen(const char* pTitle)
plast = p = strchr(fname_only, '.');
while (p != NULL)
{
while (p != NULL) {
plast = p;
p = strchr(p + 1, '.');
}
if (plast != NULL) *plast = 0;
if (plast != NULL)
*plast = 0;
#endif
strcat(fname_only, ".dump");
fdump = isoCreate(fname_only, ISOFLAGS_BLOCKDUMP);
if (fdump) isoSetFormat(fdump, iso->blockofs, iso->blocksize, iso->blocks);
}
else
{
if (fdump)
isoSetFormat(fdump, iso->blockofs, iso->blocksize, iso->blocks);
} else {
fdump = NULL;
}
return 0;
}
EXPORT_C_(void) CDVDclose()
EXPORT_C_(void)
CDVDclose()
{
if (!iso) return;
if (!iso)
return;
strcpy(cdvdCurrentIso, IsoFile);
isoClose(iso);
if (fdump != NULL) isoClose(fdump);
if (fdump != NULL)
isoClose(fdump);
}
EXPORT_C_(s32) CDVDreadSubQ(u32 lsn, cdvdSubQ* subq)
EXPORT_C_(s32)
CDVDreadSubQ(u32 lsn, cdvdSubQ *subq)
{
if (!iso) return -1;
if (!iso)
return -1;
// fake it
u8 min, sec, frm;
@ -257,14 +263,15 @@ EXPORT_C_(s32) CDVDreadSubQ(u32 lsn, cdvdSubQ* subq)
subq->pad = 0;
lba_to_msf(lsn + (2*75), &min, &sec, &frm);
lba_to_msf(lsn + (2 * 75), &min, &sec, &frm);
subq->discM = itob(min);
subq->discS = itob(sec);
subq->discF = itob(frm);
return 0;
}
EXPORT_C_(s32) CDVDgetTN(cdvdTN *Buffer)
EXPORT_C_(s32)
CDVDgetTN(cdvdTN *Buffer)
{
Buffer->strack = 1;
Buffer->etrack = 1;
@ -272,16 +279,15 @@ EXPORT_C_(s32) CDVDgetTN(cdvdTN *Buffer)
return 0;
}
EXPORT_C_(s32) CDVDgetTD(u8 Track, cdvdTD *Buffer)
EXPORT_C_(s32)
CDVDgetTD(u8 Track, cdvdTD *Buffer)
{
if (!iso) return -1;
if (!iso)
return -1;
if (Track == 0)
{
if (Track == 0) {
Buffer->lsn = iso->blocks;
}
else
{
} else {
Buffer->type = CDVD_MODE1_TRACK;
Buffer->lsn = 0;
}
@ -291,46 +297,45 @@ EXPORT_C_(s32) CDVDgetTD(u8 Track, cdvdTD *Buffer)
static s32 layer1start = -1;
static bool testForPartitionInfo( const u8 (&tempbuffer)[CD_FRAMESIZE_RAW] )
static bool testForPartitionInfo(const u8 (&tempbuffer)[CD_FRAMESIZE_RAW])
{
const int off = iso->blockofs;
// test for: CD001
return (
(tempbuffer[off+1] == 0x43) &&
(tempbuffer[off+2] == 0x44) &&
(tempbuffer[off+3] == 0x30) &&
(tempbuffer[off+4] == 0x30) &&
(tempbuffer[off+5] == 0x31)
);
(tempbuffer[off + 1] == 0x43) &&
(tempbuffer[off + 2] == 0x44) &&
(tempbuffer[off + 3] == 0x30) &&
(tempbuffer[off + 4] == 0x30) &&
(tempbuffer[off + 5] == 0x31));
}
EXPORT_C_(s32) CDVDgetTOC(void* toc)
EXPORT_C_(s32)
CDVDgetTOC(void *toc)
{
if (!iso) return -1;
if (!iso)
return -1;
u8 type = CDVDgetDiskType();
u8* tocBuff = (u8*)toc;
u8 *tocBuff = (u8 *)toc;
//__Log("CDVDgetTOC\n");
if (type == CDVD_TYPE_DVDV || type == CDVD_TYPE_PS2DVD)
{
if (type == CDVD_TYPE_DVDV || type == CDVD_TYPE_PS2DVD) {
// get dvd structure format
// scsi command 0x43
memset(tocBuff, 0, 2048);
if (layer1start != -2 && iso->blocks >= 0x300000)
{
if (layer1start != -2 && iso->blocks >= 0x300000) {
//int off = iso->blockofs;
// dual sided
tocBuff[ 0] = 0x24;
tocBuff[ 1] = 0x02;
tocBuff[ 2] = 0xF2;
tocBuff[ 3] = 0x00;
tocBuff[ 4] = 0x41;
tocBuff[ 5] = 0x95;
tocBuff[0] = 0x24;
tocBuff[1] = 0x02;
tocBuff[2] = 0xF2;
tocBuff[3] = 0x00;
tocBuff[4] = 0x41;
tocBuff[5] = 0x95;
tocBuff[14] = 0x60; // dual sided, ptp
@ -340,8 +345,7 @@ EXPORT_C_(s32) CDVDgetTOC(void* toc)
tocBuff[19] = 0x00;
// search for it
if (layer1start == -1)
{
if (layer1start == -1) {
printf("CDVD: searching for layer1...");
/*tempbuffer = (u8*)malloc(CD_FRAMESIZE_RAW * 10);
@ -361,41 +365,36 @@ EXPORT_C_(s32) CDVDgetTOC(void* toc)
uint midsector = (iso->blocks / 2) & ~0xf;
uint deviation = 0;
while( (layer1start == -1) && (deviation < midsector-16) )
{
while ((layer1start == -1) && (deviation < midsector - 16)) {
u8 tempbuffer[CD_FRAMESIZE_RAW];
isoReadBlock(iso, tempbuffer, midsector-deviation);
isoReadBlock(iso, tempbuffer, midsector - deviation);
if(testForPartitionInfo( tempbuffer ))
layer1start = midsector-deviation;
else
{
isoReadBlock(iso, tempbuffer, midsector+deviation);
if( testForPartitionInfo( tempbuffer ) )
layer1start = midsector+deviation;
if (testForPartitionInfo(tempbuffer))
layer1start = midsector - deviation;
else {
isoReadBlock(iso, tempbuffer, midsector + deviation);
if (testForPartitionInfo(tempbuffer))
layer1start = midsector + deviation;
}
if( layer1start != -1 )
{
if( tempbuffer[iso->blockofs] != 0x01 )
{
fprintf( stderr, "(LinuzCDVDiso): Invalid partition type on layer 1!? (type=0x%x)", tempbuffer[iso->blockofs] );
if (layer1start != -1) {
if (tempbuffer[iso->blockofs] != 0x01) {
fprintf(stderr, "(LinuzCDVDiso): Invalid partition type on layer 1!? (type=0x%x)", tempbuffer[iso->blockofs]);
}
}
deviation += 16;
}
if (layer1start == -1)
{
if (layer1start == -1) {
printf("(LinuzCDVDiso): Couldn't find second layer on dual layer... ignoring\n");
// fake it
tocBuff[ 0] = 0x04;
tocBuff[ 1] = 0x02;
tocBuff[ 2] = 0xF2;
tocBuff[ 3] = 0x00;
tocBuff[ 4] = 0x86;
tocBuff[ 5] = 0x72;
tocBuff[0] = 0x04;
tocBuff[1] = 0x02;
tocBuff[2] = 0xF2;
tocBuff[3] = 0x00;
tocBuff[4] = 0x86;
tocBuff[5] = 0x72;
tocBuff[16] = 0x00;
tocBuff[17] = 0x03;
@ -413,26 +412,22 @@ EXPORT_C_(s32) CDVDgetTOC(void* toc)
tocBuff[21] = (layer1start >> 16) & 0xff;
tocBuff[22] = (layer1start >> 8) & 0xff;
tocBuff[23] = (layer1start >> 0) & 0xff;
}
else
{
} else {
// fake it
tocBuff[ 0] = 0x04;
tocBuff[ 1] = 0x02;
tocBuff[ 2] = 0xF2;
tocBuff[ 3] = 0x00;
tocBuff[ 4] = 0x86;
tocBuff[ 5] = 0x72;
tocBuff[0] = 0x04;
tocBuff[1] = 0x02;
tocBuff[2] = 0xF2;
tocBuff[3] = 0x00;
tocBuff[4] = 0x86;
tocBuff[5] = 0x72;
tocBuff[16] = 0x00;
tocBuff[17] = 0x03;
tocBuff[18] = 0x00;
tocBuff[19] = 0x00;
}
}
else if ((type == CDVD_TYPE_CDDA) || (type == CDVD_TYPE_PS2CDDA) ||
(type == CDVD_TYPE_PS2CD) || (type == CDVD_TYPE_PSCDDA) || (type == CDVD_TYPE_PSCD))
{
} else if ((type == CDVD_TYPE_CDDA) || (type == CDVD_TYPE_PS2CDDA) ||
(type == CDVD_TYPE_PS2CD) || (type == CDVD_TYPE_PSCDDA) || (type == CDVD_TYPE_PSCD)) {
// cd toc
// (could be replaced by 1 command that reads the full toc)
u8 min, sec, frm;
@ -440,12 +435,12 @@ EXPORT_C_(s32) CDVDgetTOC(void* toc)
cdvdTN diskInfo;
cdvdTD trackInfo;
memset(tocBuff, 0, 1024);
if (CDVDgetTN(&diskInfo) == -1)
{
if (CDVDgetTN(&diskInfo) == -1) {
diskInfo.etrack = 0;
diskInfo.strack = 1;
}
if (CDVDgetTD(0, &trackInfo) == -1) trackInfo.lsn = 0;
if (CDVDgetTD(0, &trackInfo) == -1)
trackInfo.lsn = 0;
tocBuff[0] = 0x41;
tocBuff[1] = 0x00;
@ -464,46 +459,43 @@ EXPORT_C_(s32) CDVDgetTOC(void* toc)
tocBuff[27] = itob(min);
tocBuff[28] = itob(sec);
for (i = diskInfo.strack; i <= diskInfo.etrack; i++)
{
for (i = diskInfo.strack; i <= diskInfo.etrack; i++) {
err = CDVDgetTD(i, &trackInfo);
lba_to_msf(trackInfo.lsn, &min, &sec, &frm);
tocBuff[i*10+30] = trackInfo.type;
tocBuff[i*10+32] = err == -1 ? 0 : itob(i); //number
tocBuff[i*10+37] = itob(min);
tocBuff[i*10+38] = itob(sec);
tocBuff[i*10+39] = itob(frm);
tocBuff[i * 10 + 30] = trackInfo.type;
tocBuff[i * 10 + 32] = err == -1 ? 0 : itob(i); //number
tocBuff[i * 10 + 37] = itob(min);
tocBuff[i * 10 + 38] = itob(sec);
tocBuff[i * 10 + 39] = itob(frm);
}
}
else
} else
return -1;
return 0;
}
EXPORT_C_(s32) CDVDreadTrack(u32 lsn, int mode)
EXPORT_C_(s32)
CDVDreadTrack(u32 lsn, int mode)
{
if (!iso) return -1;
if (!iso)
return -1;
int _lsn = lsn;
//__Log("CDVDreadTrack: %x %x\n", lsn, mode);
if (_lsn < 0)
{
// lsn = 2097152 + (-_lsn);
if (_lsn < 0) {
// lsn = 2097152 + (-_lsn);
lsn = iso->blocks - (-_lsn);
}
// printf ("CDRreadTrack %d\n", lsn);
// printf ("CDRreadTrack %d\n", lsn);
isoReadBlock(iso, cdbuffer, lsn);
if (fdump != NULL)
{
if (fdump != NULL) {
isoWriteBlock(fdump, cdbuffer, lsn);
}
pbuffer = cdbuffer;
switch (mode)
{
switch (mode) {
case CDVD_MODE_2352:
break;
case CDVD_MODE_2340:
@ -520,39 +512,46 @@ EXPORT_C_(s32) CDVDreadTrack(u32 lsn, int mode)
return 0;
}
EXPORT_C_(u8*) CDVDgetBuffer()
EXPORT_C_(u8 *)
CDVDgetBuffer()
{
return pbuffer;
}
EXPORT_C_(s32) CDVDgetDiskType()
EXPORT_C_(s32)
CDVDgetDiskType()
{
return cdtype;
}
EXPORT_C_(s32) CDVDgetTrayStatus()
EXPORT_C_(s32)
CDVDgetTrayStatus()
{
return CDVD_TRAY_CLOSE;
}
EXPORT_C_(s32) CDVDctrlTrayOpen()
EXPORT_C_(s32)
CDVDctrlTrayOpen()
{
return 0;
}
EXPORT_C_(s32) CDVDctrlTrayClose()
EXPORT_C_(s32)
CDVDctrlTrayClose()
{
return 0;
}
EXPORT_C_(s32) CDVDtest()
EXPORT_C_(s32)
CDVDtest()
{
if (*IsoFile == 0) return 0;
if (*IsoFile == 0)
return 0;
iso = isoOpen(IsoFile);
if (iso == NULL) return -1;
if (iso == NULL)
return -1;
isoClose(iso);
return 0;
}

View File

@ -18,7 +18,7 @@
#include "Config.h"
const char *s_strIniPath="./inis/CDVDiso.ini";
const char *s_strIniPath = "./inis/CDVDiso.ini";
GtkWidget *AboutDlg, *ConfDlg, *MsgDlg, *FileSel;
GtkWidget *Edit, *CdEdit;
@ -31,8 +31,7 @@ void LoadConf()
strcpy(cfg, s_strIniPath);
f = fopen(cfg, "r");
if (f == NULL)
{
if (f == NULL) {
printf("Unable to load %s\n", cfg);
strcpy(IsoFile, DEV_DEF);
strcpy(CdDev, CDDEV_DEF);
@ -45,8 +44,10 @@ void LoadConf()
fscanf(f, "CdDev = %[^\n]\n", CdDev);
fscanf(f, "BlockDump = %d\n", &BlockDump);
if (!strncmp(IsoFile, "CdDev =", 9)) *IsoFile = 0; // quick fix
if (*CdDev == 0) strcpy(CdDev, CDDEV_DEF);
if (!strncmp(IsoFile, "CdDev =", 9))
*IsoFile = 0; // quick fix
if (*CdDev == 0)
strcpy(CdDev, CDDEV_DEF);
fclose(f);
}
@ -63,8 +64,7 @@ void SaveConf()
strcpy(cfg, s_strIniPath);
f = fopen(cfg, "w");
if (f == NULL)
{
if (f == NULL) {
printf("Unable to save %s\n", cfg);
return;
}
@ -147,7 +147,8 @@ void SysMessageLoc(char *fmt, ...)
vsprintf(msg, fmt, list);
va_end(list);
if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0;
if (msg[strlen(msg) - 1] == '\n')
msg[strlen(msg) - 1] = 0;
w = strlen(msg) * 6 + 20;
@ -181,7 +182,7 @@ void SysMessageLoc(char *fmt, ...)
gtk_main();
}
void OnOk (GtkButton *button, gpointer user_data)
void OnOk(GtkButton *button, gpointer user_data)
{
const char *tmp;
@ -191,7 +192,8 @@ void OnOk (GtkButton *button, gpointer user_data)
tmp = gtk_entry_get_text(GTK_ENTRY(CdEdit));
strcpy(CdDev, tmp);
if is_checked(ConfDlg, "checkBlockDump")
if
is_checked(ConfDlg, "checkBlockDump")
BlockDump = 1;
else
BlockDump = 0;
@ -242,7 +244,8 @@ void OnFileSel(GtkButton *button, gpointer user_data)
}
EXPORT_C_(void) CDVDconfigure()
EXPORT_C_(void)
CDVDconfigure()
{
int i;
@ -277,16 +280,16 @@ EXPORT_C_(void) CDVDconfigure()
gtk_widget_show_all(ConfDlg);
gtk_main();
}
void OnAboutOk(GtkMenuItem * menuitem, gpointer userdata)
void OnAboutOk(GtkMenuItem *menuitem, gpointer userdata)
{
gtk_widget_hide(AboutDlg);
gtk_main_quit();
}
EXPORT_C_(void) CDVDabout()
EXPORT_C_(void)
CDVDabout()
{
GtkWidget *Label;
GtkWidget *Ok;

View File

@ -31,9 +31,8 @@
#include <bzlib.h>
#include <gtk/gtk.h>
#ifdef __cplusplus
extern "C"
{
#ifdef __cplusplus
extern "C" {
#endif
#include "support.h"
@ -59,7 +58,7 @@ extern GtkWidget *AboutDlg, *ConfDlg, *MsgDlg, *FileSel;
extern GtkWidget *Edit, *CdEdit;
extern bool stop;
extern GtkWidget *Method,*Progress;
extern GtkWidget *Method, *Progress;
extern GtkWidget *BtnCompress, *BtnDecompress;
extern GtkWidget *BtnCreate, *BtnCreateZ;
@ -67,7 +66,7 @@ extern GList *methodlist;
// Make it easier to check and set checkmarks in the gui
#define is_checked(main_widget, widget_name) (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(main_widget, widget_name))))
#define set_checked(main_widget,widget_name, state) gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(lookup_widget(main_widget, widget_name)), state)
#define set_checked(main_widget, widget_name, state) gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(lookup_widget(main_widget, widget_name)), state)
extern void OnFileSel(GtkButton *button, gpointer user_data);
@ -78,4 +77,3 @@ extern void OnCreate(GtkButton *button, gpointer user_data);
extern void OnCreateZ(GtkButton *button, gpointer user_data);
extern void OnOk(GtkButton *button, gpointer user_data);
extern void OnCancel(GtkButton *button, gpointer user_data);

View File

@ -20,7 +20,7 @@
unsigned char Zbuf[CD_FRAMESIZE_RAW * 10 * 2];
GtkWidget *Method,*Progress;
GtkWidget *Method, *Progress;
GtkWidget *BtnCompress, *BtnDecompress;
GtkWidget *BtnCreate, *BtnCreateZ;
@ -48,8 +48,10 @@ void UpdZmode()
const char *tmp;
tmp = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(Method)->entry));
if (!strcmp(tmp, methods[0])) Zmode = 1;
else Zmode = 2;
if (!strcmp(tmp, methods[0]))
Zmode = 1;
else
Zmode = 2;
}
char buffer[2352 * 10];
@ -58,7 +60,7 @@ void OnCompress(GtkButton *button, gpointer user_data)
{
struct stat buf;
u32 lsn;
u8 cdbuff[10*2352];
u8 cdbuff[10 * 2352];
char Zfile[256];
const char *tmp;
int ret = 0;
@ -69,11 +71,12 @@ void OnCompress(GtkButton *button, gpointer user_data)
strcpy(IsoFile, tmp);
UpdZmode();
if (Zmode == 1) sprintf(Zfile, "%s.Z2", IsoFile);
if (Zmode == 2) sprintf(Zfile, "%s.BZ2", IsoFile);
if (Zmode == 1)
sprintf(Zfile, "%s.Z2", IsoFile);
if (Zmode == 2)
sprintf(Zfile, "%s.BZ2", IsoFile);
if (stat(Zfile, &buf) != -1)
{
if (stat(Zfile, &buf) != -1) {
/*char str[256];*/
return;
/* sprintf(str, "'%s' already exists, overwrite?", Zfile);
@ -83,9 +86,11 @@ void OnCompress(GtkButton *button, gpointer user_data)
}
src = isoOpen(IsoFile);
if (src == NULL) return;
if (src == NULL)
return;
dst = isoCreate(Zfile, Zmode == 1 ? ISOFLAGS_Z2 : ISOFLAGS_BZ2);
if (dst == NULL) return;
if (dst == NULL)
return;
gtk_widget_set_sensitive(BtnCompress, FALSE);
gtk_widget_set_sensitive(BtnDecompress, FALSE);
@ -93,38 +98,38 @@ void OnCompress(GtkButton *button, gpointer user_data)
gtk_widget_set_sensitive(BtnCreateZ, FALSE);
stop = false;
for (lsn = 0; lsn < src->blocks; lsn++)
{
for (lsn = 0; lsn < src->blocks; lsn++) {
printf("block %d ", lsn);
putchar(13);
fflush(stdout);
ret = isoReadBlock(src, cdbuff, lsn);
if (ret == -1) break;
if (ret == -1)
break;
ret = isoWriteBlock(dst, cdbuff, lsn);
if (ret == -1) break;
if (ret == -1)
break;
gtk_progress_bar_update(GTK_PROGRESS_BAR(Progress), (lsn * 100) / src->blocks);
while (gtk_events_pending()) gtk_main_iteration();
if (stop) break;
while (gtk_events_pending())
gtk_main_iteration();
if (stop)
break;
}
isoClose(src);
isoClose(dst);
if (!stop) gtk_entry_set_text(GTK_ENTRY(Edit), IsoFile);
if (!stop)
gtk_entry_set_text(GTK_ENTRY(Edit), IsoFile);
gtk_widget_set_sensitive(BtnCompress, TRUE);
gtk_widget_set_sensitive(BtnDecompress, TRUE);
gtk_widget_set_sensitive(BtnCreate, TRUE);
gtk_widget_set_sensitive(BtnCreateZ, TRUE);
if (!stop)
{
if (ret == -1)
{
if (!stop) {
if (ret == -1) {
SysMessageLoc("Error compressing iso image");
}
else
{
} else {
SysMessageLoc("Iso image compressed OK");
}
}
@ -256,13 +261,11 @@ void OnDecompress(GtkButton *button, gpointer user_data)
void incSector()
{
param[2]++;
if (param[2] == 75)
{
if (param[2] == 75) {
param[2] = 0;
param[1]++;
}
if (param[1] == 60)
{
if (param[1] == 60) {
param[1] = 0;
param[0]++;
}
@ -273,8 +276,7 @@ long CDR_open(void)
if (cddev != -1)
return 0;
cddev = open(CdDev, O_RDONLY);
if (cddev == -1)
{
if (cddev == -1) {
printf("CDR: Could not open %s\n", CdDev);
return -1;
}
@ -284,7 +286,8 @@ long CDR_open(void)
long CDR_close(void)
{
if (cddev == -1) return 0;
if (cddev == -1)
return 0;
close(cddev);
cddev = -1;
@ -299,7 +302,8 @@ long CDR_getTN(unsigned char *buffer)
{
struct cdrom_tochdr toc;
if (ioctl(cddev, CDROMREADTOCHDR, &toc) == -1) return -1;
if (ioctl(cddev, CDROMREADTOCHDR, &toc) == -1)
return -1;
buffer[0] = toc.cdth_trk0; // start track
buffer[1] = toc.cdth_trk1; // end track
@ -316,11 +320,13 @@ long CDR_getTD(unsigned char track, unsigned char *buffer)
{
struct cdrom_tocentry entry;
if (track == 0) track = 0xaa; // total time
if (track == 0)
track = 0xaa; // total time
entry.cdte_track = track;
entry.cdte_format = CDROM_MSF;
if (ioctl(cddev, CDROMREADTOCENTRY, &entry) == -1) return -1;
if (ioctl(cddev, CDROMREADTOCENTRY, &entry) == -1)
return -1;
buffer[0] = entry.cdte_addr.msf.minute; /* minute */
buffer[1] = entry.cdte_addr.msf.second; /* second */
@ -340,7 +346,8 @@ unsigned char *CDR_readTrack(unsigned char *time)
cr.msf.cdmsf_sec0 = time[1];
cr.msf.cdmsf_frame0 = time[2];
if (ioctl(cddev, CDROMREADRAW, &cr) == -1) return NULL;
if (ioctl(cddev, CDROMREADRAW, &cr) == -1)
return NULL;
return cr.buf;
}
@ -369,26 +376,22 @@ void OnCreate(GtkButton *button, gpointer user_data)
tmp = gtk_entry_get_text(GTK_ENTRY(Edit));
strcpy(IsoFile, tmp);
if (stat(IsoFile, &buf) == 0)
{
if (stat(IsoFile, &buf) == 0) {
printf("File %s Already exists\n", IsoFile);
return;
}
if (CDR_open() == -1)
{
if (CDR_open() == -1) {
return;
}
if (CDR_getTD(ftrack, start) == -1)
{
if (CDR_getTD(ftrack, start) == -1) {
printf("Error getting TD\n");
CDR_close();
return;
}
if (CDR_getTD(ltrack, end) == -1)
{
if (CDR_getTD(ltrack, end) == -1) {
printf("Error getting TD\n");
CDR_close();
@ -396,8 +399,7 @@ void OnCreate(GtkButton *button, gpointer user_data)
}
f = fopen(IsoFile, "wb");
if (f == NULL)
{
if (f == NULL) {
CDR_close();
printf("Error opening %s", IsoFile);
return;
@ -424,17 +426,15 @@ void OnCreate(GtkButton *button, gpointer user_data)
if ((param[0] == end[0]) & (param[1] == end[1]) & (param[2] == end[2]))
break;
buffer = CDR_readTrack(param);
if (buffer == NULL)
{
if (buffer == NULL) {
int i;
for (i = 0; i < 10; i++)
{
for (i = 0; i < 10; i++) {
buffer = CDR_readTrack(param);
if (buffer != NULL) break;
if (buffer != NULL)
break;
}
if (buffer == NULL)
{
if (buffer == NULL) {
printf("Error Reading %2d:%2d:%2d\n", param[0], param[1], param[2]);
buffer = bufferz;
buffer[12] = param[0];
@ -448,8 +448,7 @@ void OnCreate(GtkButton *button, gpointer user_data)
count += CD_FRAMESIZE_RAW;
printf("reading %2d:%2d:%2d ", param[0], param[1], param[2]);
if ((time(NULL) - Ttime) != 0)
{
if ((time(NULL) - Ttime) != 0) {
i = (count / 1024) / (time(NULL) - Ttime);
printf("( %5dKbytes/s, %dX)", i, i / 150);
}
@ -462,8 +461,10 @@ void OnCreate(GtkButton *button, gpointer user_data)
p++;
per = ((float)p / s);
gtk_progress_bar_update(GTK_PROGRESS_BAR(Progress), per);
while (gtk_events_pending()) gtk_main_iteration();
if (stop) break;
while (gtk_events_pending())
gtk_main_iteration();
if (stop)
break;
}
Ttime = time(NULL) - Ttime;
@ -479,7 +480,8 @@ void OnCreate(GtkButton *button, gpointer user_data)
gtk_widget_set_sensitive(BtnCreate, TRUE);
gtk_widget_set_sensitive(BtnCreateZ, TRUE);
if (!stop) SysMessageLoc("Iso Image Created OK");
if (!stop)
SysMessageLoc("Iso Image Created OK");
}
void OnCreateZ(GtkButton *button, gpointer user_data)
@ -511,19 +513,17 @@ void OnCreateZ(GtkButton *button, gpointer user_data)
UpdZmode();
if (Zmode == 1)
{
if (Zmode == 1) {
blocks = 1;
if (strstr(IsoFile, ".Z") == NULL) strcat(IsoFile, ".Z");
}
else
{
if (strstr(IsoFile, ".Z") == NULL)
strcat(IsoFile, ".Z");
} else {
blocks = 10;
if (strstr(IsoFile, ".bz") == NULL) strcat(IsoFile, ".bz");
if (strstr(IsoFile, ".bz") == NULL)
strcat(IsoFile, ".bz");
}
if (stat(IsoFile, &buf) == 0)
{
if (stat(IsoFile, &buf) == 0) {
printf("File %s Already exists\n", IsoFile);
return;
}
@ -536,22 +536,20 @@ void OnCreateZ(GtkButton *button, gpointer user_data)
t = fopen(table, "wb");
if (t == NULL) return;
if (CDR_open() == -1)
{
if (t == NULL)
return;
if (CDR_open() == -1) {
fclose(t);
return;
}
if (CDR_getTD(ftrack, start) == -1)
{
if (CDR_getTD(ftrack, start) == -1) {
printf("Error getting TD\n");
CDR_close();
fclose(t);
return;
}
if (CDR_getTD(ltrack, end) == -1)
{
if (CDR_getTD(ltrack, end) == -1) {
printf("Error getting TD\n");
CDR_close();
fclose(t);
@ -559,8 +557,7 @@ void OnCreateZ(GtkButton *button, gpointer user_data)
}
f = fopen(IsoFile, "wb");
if (f == NULL)
{
if (f == NULL) {
CDR_close();
fclose(t);
printf("Error opening %s", IsoFile);
@ -587,24 +584,21 @@ void OnCreateZ(GtkButton *button, gpointer user_data)
unsigned char Zbuf[CD_FRAMESIZE_RAW * 10 * 2];
float per;
for (b = 0; b < blocks; b++)
{
for (b = 0; b < blocks; b++) {
if ((param[0] == end[0]) & (param[1] == end[1]) & (param[2] == end[2]))
break;
buffer = CDR_readTrack(param);
if (buffer == NULL)
{
if (buffer == NULL) {
int i;
for (i = 0; i < 10; i++)
{
for (i = 0; i < 10; i++) {
buffer = CDR_readTrack(param);
if (buffer != NULL) break;
if (buffer != NULL)
break;
}
if (buffer == NULL)
{
if (buffer == NULL) {
printf("Error Reading %2d:%2d:%2d\n", param[0], param[1], param[2]);
buffer = bufferz;
buffer[12] = param[0];
@ -624,10 +618,11 @@ void OnCreateZ(GtkButton *button, gpointer user_data)
if (Zmode == 1)
compress(Zbuf, &size, cdbuffer, CD_FRAMESIZE_RAW);
else
BZ2_bzBuffToBuffCompress((char*)Zbuf, (unsigned int*)&size, (char*)cdbuffer, CD_FRAMESIZE_RAW * 10, 1, 0, 30);
BZ2_bzBuffToBuffCompress((char *)Zbuf, (unsigned int *)&size, (char *)cdbuffer, CD_FRAMESIZE_RAW * 10, 1, 0, 30);
fwrite(&c, 1, 4, t);
if (Zmode == 1) fwrite(&size, 1, 2, t);
if (Zmode == 1)
fwrite(&size, 1, 2, t);
fwrite(Zbuf, 1, size, f);
@ -636,8 +631,7 @@ void OnCreateZ(GtkButton *button, gpointer user_data)
count += CD_FRAMESIZE_RAW * blocks;
printf("reading %2d:%2d:%2d ", param[0], param[1], param[2]);
if ((time(NULL) - Ttime) != 0)
{
if ((time(NULL) - Ttime) != 0) {
i = (count / 1024) / (time(NULL) - Ttime);
printf("( %5dKbytes/s, %dX)", i, i / 150);
}
@ -649,13 +643,17 @@ void OnCreateZ(GtkButton *button, gpointer user_data)
per = ((float)p / s);
gtk_progress_bar_update(GTK_PROGRESS_BAR(Progress), per);
while (gtk_events_pending()) gtk_main_iteration();
while (gtk_events_pending())
gtk_main_iteration();
if (stop) break;
if (stop)
break;
}
if (Zmode == 2) fwrite(&c, 1, 4, f);
if (Zmode == 2)
fwrite(&c, 1, 4, f);
if (!stop) gtk_entry_set_text(GTK_ENTRY(Edit), IsoFile);
if (!stop)
gtk_entry_set_text(GTK_ENTRY(Edit), IsoFile);
Ttime = time(NULL) - Ttime;
Tm = gmtime(&Ttime);
@ -671,5 +669,6 @@ void OnCreateZ(GtkButton *button, gpointer user_data)
gtk_widget_set_sensitive(BtnCreate, TRUE);
gtk_widget_set_sensitive(BtnCreateZ, TRUE);
if (!stop) SysMessageLoc("Compressed Iso Image Created OK");
if (!stop)
SysMessageLoc("Compressed Iso Image Created OK");
}

View File

@ -1,34 +1,26 @@
#include <gtk/gtk.h>
void
OnFileSel (GtkButton *button,
void OnFileSel(GtkButton *button,
gpointer user_data);
void
OnStop (GtkButton *button,
void OnStop(GtkButton *button,
gpointer user_data);
void
OnCompress (GtkButton *button,
void OnCompress(GtkButton *button,
gpointer user_data);
void
OnDecompress (GtkButton *button,
void OnDecompress(GtkButton *button,
gpointer user_data);
void
OnCreate (GtkButton *button,
void OnCreate(GtkButton *button,
gpointer user_data);
void
OnCreateZ (GtkButton *button,
void OnCreateZ(GtkButton *button,
gpointer user_data);
void
OnOk (GtkButton *button,
void OnOk(GtkButton *button,
gpointer user_data);
void
OnCancel (GtkButton *button,
void OnCancel(GtkButton *button,
gpointer user_data);

View File

@ -2,4 +2,4 @@
* DO NOT EDIT THIS FILE - it is generated by Glade.
*/
GtkWidget* create_Config (void);
GtkWidget *create_Config(void);

View File

@ -3,7 +3,7 @@
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#include <config.h>
#endif
#include <gtk/gtk.h>
@ -12,24 +12,24 @@
* Standard gettext macros.
*/
#ifdef ENABLE_NLS
# include <libintl.h>
# undef _
# define _(String) dgettext (PACKAGE, String)
# define Q_(String) g_strip_context ((String), gettext (String))
# ifdef gettext_noop
# define N_(String) gettext_noop (String)
# else
# define N_(String) (String)
# endif
#include <libintl.h>
#undef _
#define _(String) dgettext(PACKAGE, String)
#define Q_(String) g_strip_context((String), gettext(String))
#ifdef gettext_noop
#define N_(String) gettext_noop(String)
#else
# define textdomain(String) (String)
# define gettext(String) (String)
# define dgettext(Domain,Message) (Message)
# define dcgettext(Domain,Message,Type) (Message)
# define bindtextdomain(Domain,Directory) (Domain)
# define _(String) (String)
# define Q_(String) g_strip_context ((String), (String))
# define N_(String) (String)
#define N_(String) (String)
#endif
#else
#define textdomain(String) (String)
#define gettext(String) (String)
#define dgettext(Domain, Message) (Message)
#define dcgettext(Domain, Message, Type) (Message)
#define bindtextdomain(Domain, Directory) (Domain)
#define _(String) (String)
#define Q_(String) g_strip_context((String), (String))
#define N_(String) (String)
#endif
@ -43,12 +43,12 @@
* or alternatively any widget in the component, and the name of the widget
* you want returned.
*/
GtkWidget* lookup_widget (GtkWidget *widget,
GtkWidget *lookup_widget(GtkWidget *widget,
const gchar *widget_name);
/* Use this function to set the directory containing installed pixmaps. */
void add_pixmap_directory (const gchar *directory);
void add_pixmap_directory(const gchar *directory);
/*
@ -56,14 +56,13 @@ void add_pixmap_directory (const gchar *directory);
*/
/* This is used to create the pixmaps used in the interface. */
GtkWidget* create_pixmap (GtkWidget *widget,
GtkWidget *create_pixmap(GtkWidget *widget,
const gchar *filename);
/* This is used to create the pixbufs used in the interface. */
GdkPixbuf* create_pixbuf (const gchar *filename);
GdkPixbuf *create_pixbuf(const gchar *filename);
/* This is used to set ATK action descriptions. */
void glade_set_atk_action_description (AtkAction *action,
void glade_set_atk_action_description(AtkAction *action,
const gchar *action_name,
const gchar *description);

View File

@ -4,14 +4,15 @@
#include "../CDVDiso.h"
#define GetKeyV(name, var, s, t) \
size = s; type = t; \
RegQueryValueEx(myKey, name, 0, &type, (LPBYTE) var, &size);
size = s; \
type = t; \
RegQueryValueEx(myKey, name, 0, &type, (LPBYTE)var, &size);
#define GetKeyVdw(name, var) \
GetKeyV(name, var, 4, REG_DWORD);
#define SetKeyV(name, var, s, t) \
RegSetValueEx(myKey, name, 0, t, (LPBYTE) var, s);
RegSetValueEx(myKey, name, 0, t, (LPBYTE)var, s);
#define SetKeyVdw(name, var) \
SetKeyV(name, var, 4, REG_DWORD);
@ -37,8 +38,7 @@ void LoadConf()
memset(IsoFile, 0, sizeof(IsoFile));
if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\PS2Eplugin\\CDVD\\CDVDiso", 0, KEY_ALL_ACCESS, &myKey) != ERROR_SUCCESS)
{
if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\PS2Eplugin\\CDVD\\CDVDiso", 0, KEY_ALL_ACCESS, &myKey) != ERROR_SUCCESS) {
SaveConf();
return;
}

View File

@ -1,3 +1,2 @@
void SaveConf();
void LoadConf();

View File

@ -67,8 +67,7 @@ int _GetFile(char *out)
ofn.lpstrDefExt = NULL;
ofn.Flags = OFN_HIDEREADONLY;
if (GetOpenFileName((LPOPENFILENAME)&ofn))
{
if (GetOpenFileName((LPOPENFILENAME)&ofn)) {
strcpy(out, szFileName);
return 1;
}
@ -82,13 +81,12 @@ int _OpenFile(int saveConf)
int retval = 0;
// for saving the pcsx2 current working directory;
char* cwd_pcsx2 = _getcwd(NULL, MAXFILENAME);
char *cwd_pcsx2 = _getcwd(NULL, MAXFILENAME);
if (IsoCWD[0] != 0)
_chdir(IsoCWD);
if (_GetFile(IsoFile) == 1)
{
if (_GetFile(IsoFile) == 1) {
// Save the user's new cwd:
if (_getcwd(IsoCWD, MAXFILENAME) == NULL)
IsoCWD[0] = 0;
@ -100,8 +98,7 @@ int _OpenFile(int saveConf)
}
// Restore Pcsx2's path.
if (cwd_pcsx2 != NULL)
{
if (cwd_pcsx2 != NULL) {
_chdir(cwd_pcsx2);
free(cwd_pcsx2);
cwd_pcsx2 = NULL;
@ -116,12 +113,9 @@ void CfgOpenFile()
void UpdZmode()
{
if (ComboBox_GetCurSel(hMethod) == 0)
{
if (ComboBox_GetCurSel(hMethod) == 0) {
Zmode = 1;
}
else
{
} else {
Zmode = 2;
}
}
@ -131,8 +125,7 @@ void SysUpdate()
{
MSG msg;
while (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
{
while (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
@ -141,7 +134,7 @@ void SysUpdate()
void OnCompress()
{
u32 lsn;
u8 cdbuff[10*2352];
u8 cdbuff[10 * 2352];
char Zfile[256];
int ret;
isoFile *src;
@ -150,62 +143,57 @@ void OnCompress()
Edit_GetText(hIsoFile, IsoFile, 256);
UpdZmode();
if (Zmode == 1)
{
if (Zmode == 1) {
sprintf(Zfile, "%s.Z2", IsoFile);
}
else
{
} else {
sprintf(Zfile, "%s.BZ2", IsoFile);
}
src = isoOpen(IsoFile);
if (src == NULL) return;
if (Zmode == 1)
{
if (src == NULL)
return;
if (Zmode == 1) {
dst = isoCreate(Zfile, ISOFLAGS_Z2);
}
else
{
} else {
dst = isoCreate(Zfile, ISOFLAGS_BZ2);
}
if (dst == NULL) return;
if (dst == NULL)
return;
isoSetFormat(dst, src->blockofs, src->blocksize, src->blocks);
Button_Enable(GetDlgItem(hDlg, IDC_COMPRESSISO), FALSE);
Button_Enable(GetDlgItem(hDlg, IDC_DECOMPRESSISO), FALSE);
stop = 0;
for (lsn = 0; lsn < src->blocks; lsn++)
{
for (lsn = 0; lsn < src->blocks; lsn++) {
//printf("block %d ", lsn);
//putchar(13);
//fflush(stdout);
ret = isoReadBlock(src, cdbuff, lsn);
if (ret == -1) break;
if (ret == -1)
break;
ret = isoWriteBlock(dst, cdbuff, lsn);
if (ret == -1) break;
if (ret == -1)
break;
SendMessage(hProgress, PBM_SETPOS, (lsn * 100) / src->blocks, 0);
SysUpdate();
if (stop) break;
if (stop)
break;
}
isoClose(src);
isoClose(dst);
if (!stop) Edit_SetText(hIsoFile, Zfile);
if (!stop)
Edit_SetText(hIsoFile, Zfile);
Button_Enable(GetDlgItem(hDlg, IDC_COMPRESSISO), TRUE);
Button_Enable(GetDlgItem(hDlg, IDC_DECOMPRESSISO), TRUE);
if (!stop)
{
if (ret == -1)
{
if (!stop) {
if (ret == -1) {
SysMessage("Error compressing iso image");
}
else
{
} else {
SysMessage("Iso image compressed OK");
}
}
@ -214,7 +202,7 @@ void OnCompress()
void OnDecompress()
{
char file[256];
u8 cdbuff[10*2352];
u8 cdbuff[10 * 2352];
u32 lsn;
isoFile *src;
isoFile *dst;
@ -223,52 +211,48 @@ void OnDecompress()
Edit_GetText(hIsoFile, IsoFile, 256);
src = isoOpen(IsoFile);
if (src == NULL) return;
if (src == NULL)
return;
strcpy(file, IsoFile);
if (src->flags & ISOFLAGS_Z)
{
if (src->flags & ISOFLAGS_Z) {
file[strlen(file) - 2] = 0;
}
else
if (src->flags & ISOFLAGS_Z2)
{
} else if (src->flags & ISOFLAGS_Z2) {
file[strlen(file) - 3] = 0;
}
else
if (src->flags & ISOFLAGS_BZ2)
{
} else if (src->flags & ISOFLAGS_BZ2) {
file[strlen(file) - 3] = 0;
}
else
{
} else {
SysMessage("%s is not a compressed image", IsoFile);
return;
}
dst = isoCreate(file, 0);
if (dst == NULL) return;
if (dst == NULL)
return;
isoSetFormat(dst, src->blockofs, src->blocksize, src->blocks);
Button_Enable(GetDlgItem(hDlg, IDC_COMPRESSISO), FALSE);
Button_Enable(GetDlgItem(hDlg, IDC_DECOMPRESSISO), FALSE);
stop = 0;
for (lsn = 0; lsn < src->blocks; lsn++)
{
for (lsn = 0; lsn < src->blocks; lsn++) {
printf("block %d ", lsn);
putchar(13);
fflush(stdout);
ret = isoReadBlock(src, cdbuff, lsn);
if (ret == -1) break;
if (ret == -1)
break;
ret = isoWriteBlock(dst, cdbuff, lsn);
if (ret == -1) break;
if (ret == -1)
break;
SendMessage(hProgress, PBM_SETPOS, (lsn * 100) / src->blocks, 0);
SysUpdate();
if (stop) break;
if (stop)
break;
}
if (!stop) Edit_SetText(hIsoFile, file);
if (!stop)
Edit_SetText(hIsoFile, file);
isoClose(src);
isoClose(dst);
@ -276,14 +260,10 @@ void OnDecompress()
Button_Enable(GetDlgItem(hDlg, IDC_COMPRESSISO), TRUE);
Button_Enable(GetDlgItem(hDlg, IDC_DECOMPRESSISO), TRUE);
if (!stop)
{
if (ret == -1)
{
if (!stop) {
if (ret == -1) {
SysMessage("Error decompressing iso image");
}
else
{
} else {
SysMessage("Iso image decompressed OK");
}
}
@ -293,8 +273,7 @@ BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int i;
switch (uMsg)
{
switch (uMsg) {
case WM_INITDIALOG:
hDlg = hW;
LoadConf();
@ -304,8 +283,7 @@ BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
hMethod = GetDlgItem(hW, IDC_METHOD);
hBlockDump = GetDlgItem(hW, IDC_BLOCKDUMP);
for (i = 0; methods[i] != NULL; i++)
{
for (i = 0; methods[i] != NULL; i++) {
ComboBox_AddString(hMethod, methods[i]);
}
@ -319,8 +297,7 @@ BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
switch (LOWORD(wParam)) {
case IDC_SELECTISO:
if (_OpenFile(FALSE) == 1)
Edit_SetText(hIsoFile, IsoFile);
@ -354,7 +331,8 @@ BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
return FALSE;
}
EXPORT_C_(void) CDVDconfigure()
EXPORT_C_(void)
CDVDconfigure()
{
DialogBox(hInst,
MAKEINTRESOURCE(IDD_CONFIG),
@ -364,14 +342,12 @@ EXPORT_C_(void) CDVDconfigure()
BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
switch (uMsg) {
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
switch (LOWORD(wParam)) {
case IDOK:
EndDialog(hW, TRUE);
return FALSE;
@ -380,7 +356,8 @@ BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
return FALSE;
}
EXPORT_C_(void) CDVDabout()
EXPORT_C_(void)
CDVDabout()
{
DialogBox(hInst,
MAKEINTRESOURCE(IDD_ABOUT),
@ -395,4 +372,3 @@ BOOL APIENTRY DllMain(HANDLE hModule, // DLL INIT
hInst = (HINSTANCE)hModule;
return TRUE; // very quick :)
}

View File

@ -3,13 +3,13 @@
#define _FILE_OFFSET_BITS 64
#ifdef __GNUC__
# ifndef _LARGEFILE_SOURCE
# define _LARGEFILE_SOURCE
# endif
#ifndef _LARGEFILE_SOURCE
#define _LARGEFILE_SOURCE
#endif
# ifndef _LARGEFILE64_SOURCE
# define _LARGEFILE64_SOURCE
# endif
#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE64_SOURCE
#endif
#endif
#ifdef _WIN32
@ -116,15 +116,13 @@ void *_openfile(const char *filename, int flags)
{
HANDLE handle;
// printf("_openfile %s, %d\n", filename, flags & O_RDONLY);
if (flags & O_WRONLY)
{
// printf("_openfile %s, %d\n", filename, flags & O_RDONLY);
if (flags & O_WRONLY) {
int _flags = CREATE_NEW;
if (flags & O_CREAT) _flags = CREATE_ALWAYS;
if (flags & O_CREAT)
_flags = CREATE_ALWAYS;
handle = CreateFile(filename, GENERIC_WRITE, 0, NULL, _flags, 0, NULL);
}
else
{
} else {
handle = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
}
@ -134,7 +132,7 @@ void *_openfile(const char *filename, int flags)
u64 _tellfile(void *handle)
{
u64 ofs;
PLONG _ofs = (LONG*) & ofs;
PLONG _ofs = (LONG *)&ofs;
_ofs[1] = 0;
_ofs[0] = SetFilePointer(handle, 0, &_ofs[1], FILE_CURRENT);
return ofs;
@ -143,14 +141,11 @@ u64 _tellfile(void *handle)
int _seekfile(void *handle, u64 offset, int whence)
{
u64 ofs = (u64)offset;
PLONG _ofs = (LONG*) & ofs;
// printf("_seekfile %p, %d_%d\n", handle, _ofs[1], _ofs[0]);
if (whence == SEEK_SET)
{
PLONG _ofs = (LONG *)&ofs;
// printf("_seekfile %p, %d_%d\n", handle, _ofs[1], _ofs[0]);
if (whence == SEEK_SET) {
SetFilePointer(handle, _ofs[0], &_ofs[1], FILE_BEGIN);
}
else
{
} else {
SetFilePointer(handle, _ofs[0], &_ofs[1], FILE_END);
}
return 0;
@ -160,9 +155,9 @@ int _readfile(void *handle, void *dst, int size)
{
DWORD ret;
// printf("_readfile %p %d\n", handle, size);
// printf("_readfile %p %d\n", handle, size);
ReadFile(handle, dst, size, &ret, NULL);
// printf("_readfile ret %d; %d\n", ret, GetLastError());
// printf("_readfile ret %d; %d\n", ret, GetLastError());
return ret;
}
@ -170,10 +165,10 @@ int _writefile(void *handle, const void *src, int size)
{
DWORD ret;
// printf("_writefile %p, %d\n", handle, size);
// _seekfile(handle, _tellfile(handle));
// printf("_writefile %p, %d\n", handle, size);
// _seekfile(handle, _tellfile(handle));
WriteFile(handle, src, size, &ret, NULL);
// printf("_writefile ret %d\n", ret);
// printf("_writefile ret %d\n", ret);
return ret;
}
@ -198,14 +193,12 @@ void *_openfile(const char *filename, int flags)
u64 _tellfile(void *handle)
{
FILE* fp = (FILE*)handle;
FILE *fp = (FILE *)handle;
s64 cursize = ftell(fp);
if (cursize == -1)
{
if (cursize == -1) {
// try 64bit
cursize = ftello64(fp);
if (cursize < -1)
{
if (cursize < -1) {
// zero top 32 bits
cursize &= 0xffffffff;
}
@ -215,26 +208,27 @@ u64 _tellfile(void *handle)
int _seekfile(void *handle, u64 offset, int whence)
{
int seekerr = fseeko64((FILE*)handle, offset, whence);
int seekerr = fseeko64((FILE *)handle, offset, whence);
if (seekerr == -1) printf("failed to seek\n");
if (seekerr == -1)
printf("failed to seek\n");
return seekerr;
}
int _readfile(void *handle, void *dst, int size)
{
return fread(dst, 1, size, (FILE*)handle);
return fread(dst, 1, size, (FILE *)handle);
}
int _writefile(void *handle, const void *src, int size)
{
return fwrite(src, 1, size, (FILE*)handle);
return fwrite(src, 1, size, (FILE *)handle);
}
void _closefile(void *handle)
{
fclose((FILE*)handle);
fclose((FILE *)handle);
}
#endif
@ -244,11 +238,13 @@ int detect(isoFile *iso)
u8 buf[2448];
struct cdVolDesc *volDesc;
if (isoReadBlock(iso, buf, 16) == -1) return -1;
if (isoReadBlock(iso, buf, 16) == -1)
return -1;
volDesc = (struct cdVolDesc *)(buf + 24);
if (strncmp((char*)volDesc->volID, "CD001", 5)) return 0;
if (strncmp((char *)volDesc->volID, "CD001", 5))
return 0;
if (volDesc->rootToc.tocSize == 2048)
iso->type = ISOTYPE_CD;
@ -266,18 +262,16 @@ int _isoReadZtable(isoFile *iso)
sprintf(table, "%s.table", iso->filename);
handle = _openfile(table, O_RDONLY);
if (handle == NULL)
{
if (handle == NULL) {
printf("Error loading %s\n", table);
return -1;
}
_seekfile(handle, 0, SEEK_END);
size = _tellfile(handle);
iso->Ztable = (char*)malloc(size);
iso->Ztable = (char *)malloc(size);
if (iso->Ztable == NULL)
{
if (iso->Ztable == NULL) {
return -1;
}
@ -300,18 +294,16 @@ int _isoReadZ2table(isoFile *iso)
sprintf(table, "%s.table", iso->filename);
handle = _openfile(table, O_RDONLY);
if (handle == NULL)
{
if (handle == NULL) {
printf("Error loading %s\n", table);
return -1;
}
_seekfile(handle, 0, SEEK_END);
size = _tellfile(handle);
Ztable = (u32*)malloc(size);
Ztable = (u32 *)malloc(size);
if (Ztable == NULL)
{
if (Ztable == NULL) {
return -1;
}
@ -319,20 +311,18 @@ int _isoReadZ2table(isoFile *iso)
_readfile(handle, Ztable, size);
_closefile(handle);
iso->Ztable = (char*)malloc(iso->blocks * 8);
iso->Ztable = (char *)malloc(iso->blocks * 8);
if (iso->Ztable == NULL)
{
if (iso->Ztable == NULL) {
free(Ztable);
return -1;
}
ofs = 16;
for (i = 0; i < iso->blocks; i++)
{
*(u32*)&iso->Ztable[i*8+0] = ofs;
*(u32*)&iso->Ztable[i*8+4] = Ztable[i];
for (i = 0; i < iso->blocks; i++) {
*(u32 *)&iso->Ztable[i * 8 + 0] = ofs;
*(u32 *)&iso->Ztable[i * 8 + 4] = Ztable[i];
ofs += Ztable[i];
}
@ -352,23 +342,23 @@ int _isoReadBZ2table(isoFile *iso)
sprintf(table, "%s.table", iso->filename);
handle = _openfile(table, O_RDONLY);
if (handle == NULL)
{
if (handle == NULL) {
printf("Error loading %s\n", table);
return -1;
}
_seekfile(handle, 0, SEEK_END);
size = _tellfile(handle);
Ztable = (u32*)malloc(size);
if (Ztable == NULL) return -1;
Ztable = (u32 *)malloc(size);
if (Ztable == NULL)
return -1;
_seekfile(handle, 0, SEEK_SET);
_readfile(handle, Ztable, size);
_closefile(handle);
iso->Ztable = (char*)malloc(iso->blocks * 8);
if (iso->Ztable == NULL){
iso->Ztable = (char *)malloc(iso->blocks * 8);
if (iso->Ztable == NULL) {
free(Ztable);
return -1;
}
@ -376,17 +366,15 @@ int _isoReadBZ2table(isoFile *iso)
ofs = 16;
for (i = 0; i < iso->blocks / 16; i++)
{
*(u32*)&iso->Ztable[i*8+0] = ofs;
*(u32*)&iso->Ztable[i*8+4] = Ztable[i];
for (i = 0; i < iso->blocks / 16; i++) {
*(u32 *)&iso->Ztable[i * 8 + 0] = ofs;
*(u32 *)&iso->Ztable[i * 8 + 4] = Ztable[i];
ofs += Ztable[i];
}
if (iso->blocks & 0xf)
{
*(u32*)&iso->Ztable[i*8+0] = ofs;
*(u32*)&iso->Ztable[i*8+4] = Ztable[i];
if (iso->blocks & 0xf) {
*(u32 *)&iso->Ztable[i * 8 + 0] = ofs;
*(u32 *)&iso->Ztable[i * 8 + 4] = Ztable[i];
ofs += Ztable[i];
}
@ -402,13 +390,13 @@ int _isoReadDtable(isoFile *iso)
_seekfile(iso->handle, 0, SEEK_END);
iso->dtablesize = (_tellfile(iso->handle) - 16) / (iso->blocksize + 4);
iso->dtable = (u32*)malloc(iso->dtablesize * 4);
iso->dtable = (u32 *)malloc(iso->dtablesize * 4);
for (i = 0; i < iso->dtablesize; i++)
{
_seekfile(iso->handle, 16 + (iso->blocksize + 4)*i, SEEK_SET);
for (i = 0; i < iso->dtablesize; i++) {
_seekfile(iso->handle, 16 + (iso->blocksize + 4) * i, SEEK_SET);
ret = _readfile(iso->handle, &iso->dtable[i], 4);
if (ret < 4) return -1;
if (ret < 4)
return -1;
}
return 0;
@ -422,10 +410,8 @@ int isoDetect(isoFile *iso) // based on florin's CDVDbin detection code :)
iso->type = ISOTYPE_ILLEGAL;
len = strlen(iso->filename);
if (len >= 2)
{
if (!strncmp(iso->filename + (len - 2), ".Z", 2))
{
if (len >= 2) {
if (!strncmp(iso->filename + (len - 2), ".Z", 2)) {
iso->flags = ISOFLAGS_Z;
iso->blocksize = 2352;
_isoReadZtable(iso);
@ -436,38 +422,32 @@ int isoDetect(isoFile *iso) // based on florin's CDVDbin detection code :)
_seekfile(iso->handle, 0, SEEK_SET);
_readfile(iso->handle, buf, 4);
if (strncmp(buf, "BDV2", 4) == 0)
{
if (strncmp(buf, "BDV2", 4) == 0) {
iso->flags = ISOFLAGS_BLOCKDUMP;
_readfile(iso->handle, &iso->blocksize, 4);
_readfile(iso->handle, &iso->blocks, 4);
_readfile(iso->handle, &iso->blockofs, 4);
_isoReadDtable(iso);
return detect(iso) == 1 ? 0 : -1;
}
else if (strncmp(buf, "Z V2", 4) == 0)
{
} else if (strncmp(buf, "Z V2", 4) == 0) {
iso->flags = ISOFLAGS_Z2;
_readfile(iso->handle, &iso->blocksize, 4);
_readfile(iso->handle, &iso->blocks, 4);
_readfile(iso->handle, &iso->blockofs, 4);
_isoReadZ2table(iso);
return detect(iso) == 1 ? 0 : -1;
}
else if (strncmp(buf, "BZV2", 4) == 0)
{
} else if (strncmp(buf, "BZV2", 4) == 0) {
iso->flags = ISOFLAGS_BZ2;
_readfile(iso->handle, &iso->blocksize, 4);
_readfile(iso->handle, &iso->blocks, 4);
_readfile(iso->handle, &iso->blockofs, 4);
iso->buflsn = -1;
iso->buffer = (u8*)malloc(iso->blocksize * 16);
if (iso->buffer == NULL) return -1;
iso->buffer = (u8 *)malloc(iso->blocksize * 16);
if (iso->buffer == NULL)
return -1;
_isoReadBZ2table(iso);
return detect(iso) == 1 ? 0 : -1;
}
else
{
} else {
iso->blocks = 16;
}
@ -475,61 +455,71 @@ int isoDetect(isoFile *iso) // based on florin's CDVDbin detection code :)
iso->blocksize = 2048;
iso->offset = 0;
iso->blockofs = 24;
if (detect(iso) == 1) return 0;
if (detect(iso) == 1)
return 0;
// RAW 2336
iso->blocksize = 2336;
iso->offset = 0;
iso->blockofs = 16;
if (detect(iso) == 1) return 0;
if (detect(iso) == 1)
return 0;
// RAW 2352
iso->blocksize = 2352;
iso->offset = 0;
iso->blockofs = 0;
if (detect(iso) == 1) return 0;
if (detect(iso) == 1)
return 0;
// RAWQ 2448
iso->blocksize = 2448;
iso->offset = 0;
iso->blockofs = 0;
if (detect(iso) == 1) return 0;
if (detect(iso) == 1)
return 0;
// NERO ISO 2048
iso->blocksize = 2048;
iso->offset = 150 * 2048;
iso->blockofs = 24;
if (detect(iso) == 1) return 0;
if (detect(iso) == 1)
return 0;
// NERO RAW 2352
iso->blocksize = 2352;
iso->offset = 150 * 2048;
iso->blockofs = 0;
if (detect(iso) == 1) return 0;
if (detect(iso) == 1)
return 0;
// NERO RAWQ 2448
iso->blocksize = 2448;
iso->offset = 150 * 2048;
iso->blockofs = 0;
if (detect(iso) == 1) return 0;
if (detect(iso) == 1)
return 0;
// ISO 2048
iso->blocksize = 2048;
iso->offset = -8;
iso->blockofs = 24;
if (detect(iso) == 1) return 0;
if (detect(iso) == 1)
return 0;
// RAW 2352
iso->blocksize = 2352;
iso->offset = -8;
iso->blockofs = 0;
if (detect(iso) == 1) return 0;
if (detect(iso) == 1)
return 0;
// RAWQ 2448
iso->blocksize = 2448;
iso->offset = -8;
iso->blockofs = 0;
if (detect(iso) == 1) return 0;
if (detect(iso) == 1)
return 0;
iso->offset = 0;
iso->blocksize = 2352;
@ -544,35 +534,33 @@ isoFile *isoOpen(const char *filename)
isoFile *iso;
int i;
iso = (isoFile*)malloc(sizeof(isoFile));
if (iso == NULL) return NULL;
iso = (isoFile *)malloc(sizeof(isoFile));
if (iso == NULL)
return NULL;
memset(iso, 0, sizeof(isoFile));
strcpy(iso->filename, filename);
iso->handle = _openfile(iso->filename, O_RDONLY);
if (iso->handle == NULL)
{
if (iso->handle == NULL) {
printf("Error loading %s\n", iso->filename);
free(iso);
return NULL;
}
if (isoDetect(iso) == -1) return NULL;
if (isoDetect(iso) == -1)
return NULL;
printf("detected blocksize = %d\n", iso->blocksize);
if (strlen(iso->filename) > 3 && strncmp(iso->filename + (strlen(iso->filename) - 3), "I00", 3) == 0)
{
if (strlen(iso->filename) > 3 && strncmp(iso->filename + (strlen(iso->filename) - 3), "I00", 3) == 0) {
_closefile(iso->handle);
iso->flags |= ISOFLAGS_MULTI;
iso->blocks = 0;
for (i = 0; i < 8; i++)
{
for (i = 0; i < 8; i++) {
iso->filename[strlen(iso->filename) - 1] = '0' + i;
iso->multih[i].handle = _openfile(iso->filename, O_RDONLY);
if (iso->multih[i].handle == NULL)
{
if (iso->multih[i].handle == NULL) {
break;
}
iso->multih[i].slsn = iso->blocks;
@ -582,14 +570,12 @@ isoFile *isoOpen(const char *filename)
iso->multih[i].elsn = iso->blocks - 1;
}
if (i == 0)
{
if (i == 0) {
return NULL;
}
}
if (iso->flags == 0)
{
if (iso->flags == 0) {
_seekfile(iso->handle, 0, SEEK_END);
iso->blocks = (u32)((_tellfile(iso->handle) - iso->offset) /
(iso->blocksize));
@ -611,8 +597,9 @@ isoFile *isoCreate(const char *filename, int flags)
isoFile *iso;
char Zfile[256];
iso = (isoFile*)malloc(sizeof(isoFile));
if (iso == NULL) return NULL;
iso = (isoFile *)malloc(sizeof(isoFile));
if (iso == NULL)
return NULL;
memset(iso, 0, sizeof(isoFile));
strcpy(iso->filename, filename);
@ -622,20 +609,17 @@ isoFile *isoCreate(const char *filename, int flags)
iso->blocksize = CD_FRAMESIZE_RAW;
iso->blocksize = 2048;
if (iso->flags & (ISOFLAGS_Z | ISOFLAGS_Z2 | ISOFLAGS_BZ2))
{
if (iso->flags & (ISOFLAGS_Z | ISOFLAGS_Z2 | ISOFLAGS_BZ2)) {
sprintf(Zfile, "%s.table", iso->filename);
iso->htable = _openfile(Zfile, O_WRONLY);
if (iso->htable == NULL)
{
if (iso->htable == NULL) {
free(iso);
return NULL;
}
}
iso->handle = _openfile(iso->filename, O_WRONLY | O_CREAT);
if (iso->handle == NULL)
{
if (iso->handle == NULL) {
printf("Error loading %s\n", iso->filename);
free(iso);
return NULL;
@ -654,29 +638,39 @@ int isoSetFormat(isoFile *iso, int blockofs, int blocksize, int blocks)
printf("blockofs = %d\n", iso->blockofs);
printf("blocksize = %d\n", iso->blocksize);
printf("blocks = %d\n", iso->blocks);
if (iso->flags & ISOFLAGS_Z2)
{
if (_writefile(iso->handle, "Z V2", 4) < 4) return -1;
if (_writefile(iso->handle, &blocksize, 4) < 4) return -1;
if (_writefile(iso->handle, &blocks, 4) < 4) return -1;
if (_writefile(iso->handle, &blockofs, 4) < 4) return -1;
if (iso->flags & ISOFLAGS_Z2) {
if (_writefile(iso->handle, "Z V2", 4) < 4)
return -1;
if (_writefile(iso->handle, &blocksize, 4) < 4)
return -1;
if (_writefile(iso->handle, &blocks, 4) < 4)
return -1;
if (_writefile(iso->handle, &blockofs, 4) < 4)
return -1;
}
if (iso->flags & ISOFLAGS_BZ2)
{
if (_writefile(iso->handle, "BZV2", 4) < 4) return -1;
if (_writefile(iso->handle, &blocksize, 4) < 4) return -1;
if (_writefile(iso->handle, &blocks, 4) < 4) return -1;
if (_writefile(iso->handle, &blockofs, 4) < 4) return -1;
if (iso->flags & ISOFLAGS_BZ2) {
if (_writefile(iso->handle, "BZV2", 4) < 4)
return -1;
if (_writefile(iso->handle, &blocksize, 4) < 4)
return -1;
if (_writefile(iso->handle, &blocks, 4) < 4)
return -1;
if (_writefile(iso->handle, &blockofs, 4) < 4)
return -1;
iso->buflsn = -1;
iso->buffer = (u8*)malloc(iso->blocksize * 16);
if (iso->buffer == NULL) return -1;
iso->buffer = (u8 *)malloc(iso->blocksize * 16);
if (iso->buffer == NULL)
return -1;
}
if (iso->flags & ISOFLAGS_BLOCKDUMP)
{
if (_writefile(iso->handle, "BDV2", 4) < 4) return -1;
if (_writefile(iso->handle, &blocksize, 4) < 4) return -1;
if (_writefile(iso->handle, &blocks, 4) < 4) return -1;
if (_writefile(iso->handle, &blockofs, 4) < 4) return -1;
if (iso->flags & ISOFLAGS_BLOCKDUMP) {
if (_writefile(iso->handle, "BDV2", 4) < 4)
return -1;
if (_writefile(iso->handle, &blocksize, 4) < 4)
return -1;
if (_writefile(iso->handle, &blocks, 4) < 4)
return -1;
if (_writefile(iso->handle, &blockofs, 4) < 4)
return -1;
}
return 0;
@ -711,12 +705,11 @@ int _isoReadBlock(isoFile *iso, u8 *dst, int lsn)
u64 ofs = (u64)lsn * iso->blocksize + iso->offset;
int ret;
// printf("_isoReadBlock %d, blocksize=%d, blockofs=%d\n", lsn, iso->blocksize, iso->blockofs);
// printf("_isoReadBlock %d, blocksize=%d, blockofs=%d\n", lsn, iso->blocksize, iso->blockofs);
memset(dst, 0, iso->blockofs);
_seekfile(iso->handle, ofs, SEEK_SET);
ret = _readfile(iso->handle, dst + iso->blockofs, iso->blocksize);
if (ret < iso->blocksize)
{
if (ret < iso->blocksize) {
printf("read error %d\n", ret);
return -1;
}
@ -728,17 +721,16 @@ int _isoReadBlockZ(isoFile *iso, u8 *dst, int lsn)
{
u32 pos, p;
uLongf size;
u8 Zbuf[CD_FRAMESIZE_RAW*2];
u8 Zbuf[CD_FRAMESIZE_RAW * 2];
int ret;
// printf("_isoReadBlockZ %d, %d\n", lsn, iso->blocksize);
pos = *(unsigned long*) & iso->Ztable[lsn * 6];
p = *(unsigned short*) & iso->Ztable[lsn * 6 + 4];
// printf("%d, %d\n", pos, p);
// printf("_isoReadBlockZ %d, %d\n", lsn, iso->blocksize);
pos = *(unsigned long *)&iso->Ztable[lsn * 6];
p = *(unsigned short *)&iso->Ztable[lsn * 6 + 4];
// printf("%d, %d\n", pos, p);
_seekfile(iso->handle, pos, SEEK_SET);
ret = _readfile(iso->handle, Zbuf, p);
if (ret < p)
{
if (ret < p) {
printf("error reading block!!\n");
return -1;
}
@ -753,17 +745,16 @@ int _isoReadBlockZ2(isoFile *iso, u8 *dst, int lsn)
{
u32 pos, p;
uLongf size;
u8 Zbuf[16*1024];
u8 Zbuf[16 * 1024];
int ret;
// printf("_isoReadBlockZ2 %d, %d\n", lsn, iso->blocksize);
pos = *(u32*) & iso->Ztable[lsn*8];
p = *(u32*) & iso->Ztable[lsn*8+4];
// printf("%d, %d\n", pos, p);
// printf("_isoReadBlockZ2 %d, %d\n", lsn, iso->blocksize);
pos = *(u32 *)&iso->Ztable[lsn * 8];
p = *(u32 *)&iso->Ztable[lsn * 8 + 4];
// printf("%d, %d\n", pos, p);
_seekfile(iso->handle, pos, SEEK_SET);
ret = _readfile(iso->handle, Zbuf, p);
if (ret < p)
{
if (ret < p) {
printf("error reading block!!\n");
return -1;
}
@ -778,42 +769,39 @@ int _isoReadBlockBZ2(isoFile *iso, u8 *dst, int lsn)
{
u32 pos, p;
u32 size;
u8 Zbuf[64*1024];
u8 Zbuf[64 * 1024];
int ret;
if ((lsn / 16) == iso->buflsn)
{
if ((lsn / 16) == iso->buflsn) {
memset(dst, 0, iso->blockofs);
memcpy(dst + iso->blockofs, iso->buffer + (iso->blocksize*(lsn&0xf)), iso->blocksize);
memcpy(dst + iso->blockofs, iso->buffer + (iso->blocksize * (lsn & 0xf)), iso->blocksize);
return 0;
}
iso->buflsn = lsn / 16;
// printf("_isoReadBlockBZ2 %d, %d\n", lsn, iso->blocksize);
pos = *(u32*) & iso->Ztable[(lsn/16)*8];
p = *(u32*) & iso->Ztable[(lsn/16)*8+4];
// printf("%d, %d\n", pos, p);
// printf("_isoReadBlockBZ2 %d, %d\n", lsn, iso->blocksize);
pos = *(u32 *)&iso->Ztable[(lsn / 16) * 8];
p = *(u32 *)&iso->Ztable[(lsn / 16) * 8 + 4];
// printf("%d, %d\n", pos, p);
_seekfile(iso->handle, pos, SEEK_SET);
ret = _readfile(iso->handle, Zbuf, p);
if (ret < p)
{
if (ret < p) {
printf("error reading block!!\n");
return -1;
}
size = iso->blocksize * 64;
ret = BZ2_bzBuffToBuffDecompress((s8*)iso->buffer, &size, (s8*)Zbuf, p, 0, 0);
ret = BZ2_bzBuffToBuffDecompress((s8 *)iso->buffer, &size, (s8 *)Zbuf, p, 0, 0);
if (ret != BZ_OK)
{
if (ret != BZ_OK) {
printf("_isoReadBlockBZ2 %d, %d\n", lsn, iso->blocksize);
printf("%d, %d\n", pos, p);
printf("error on BZ2: %d\n", ret);
}
memset(dst, 0, iso->blockofs);
memcpy(dst + iso->blockofs, iso->buffer + (iso->blocksize*(lsn&0xf)), iso->blocksize);
memcpy(dst + iso->blockofs, iso->buffer + (iso->blocksize * (lsn & 0xf)), iso->blocksize);
return 0;
}
@ -823,15 +811,16 @@ int _isoReadBlockD(isoFile *iso, u8 *dst, int lsn)
int ret;
int i;
// printf("_isoReadBlockD %d, blocksize=%d, blockofs=%d\n", lsn, iso->blocksize, iso->blockofs);
// printf("_isoReadBlockD %d, blocksize=%d, blockofs=%d\n", lsn, iso->blocksize, iso->blockofs);
memset(dst, 0, iso->blockofs);
for (i = 0; i < iso->dtablesize;i++)
{
if (iso->dtable[i] != lsn) continue;
for (i = 0; i < iso->dtablesize; i++) {
if (iso->dtable[i] != lsn)
continue;
_seekfile(iso->handle, 16 + i*(iso->blocksize + 4) + 4, SEEK_SET);
_seekfile(iso->handle, 16 + i * (iso->blocksize + 4) + 4, SEEK_SET);
ret = _readfile(iso->handle, dst + iso->blockofs, iso->blocksize);
if (ret < iso->blocksize) return -1;
if (ret < iso->blocksize)
return -1;
return 0;
}
@ -846,24 +835,22 @@ int _isoReadBlockM(isoFile *iso, u8 *dst, int lsn)
int ret;
int i;
for (i = 0; i < 8; i++)
{
for (i = 0; i < 8; i++) {
if (lsn >= iso->multih[i].slsn &&
lsn <= iso->multih[i].elsn)
{
lsn <= iso->multih[i].elsn) {
break;
}
}
if (i == 8) return -1;
if (i == 8)
return -1;
ofs = (u64)(lsn - iso->multih[i].slsn) * iso->blocksize + iso->offset;
// printf("_isoReadBlock %d, blocksize=%d, blockofs=%d\n", lsn, iso->blocksize, iso->blockofs);
// printf("_isoReadBlock %d, blocksize=%d, blockofs=%d\n", lsn, iso->blocksize, iso->blockofs);
memset(dst, 0, iso->blockofs);
_seekfile(iso->multih[i].handle, ofs, SEEK_SET);
ret = _readfile(iso->multih[i].handle, dst + iso->blockofs, iso->blocksize);
if (ret < iso->blocksize)
{
if (ret < iso->blocksize) {
printf("read error %d\n", ret);
return -1;
}
@ -875,8 +862,7 @@ int isoReadBlock(isoFile *iso, u8 *dst, int lsn)
{
int ret;
if (lsn > iso->blocks)
{
if (lsn > iso->blocks) {
printf("isoReadBlock: %d > %d\n", lsn, iso->blocks);
return -1;
}
@ -894,10 +880,10 @@ int isoReadBlock(isoFile *iso, u8 *dst, int lsn)
else
ret = _isoReadBlock(iso, dst, lsn);
if (ret == -1) return ret;
if (ret == -1)
return ret;
if (iso->type == ISOTYPE_CD)
{
if (iso->type == ISOTYPE_CD) {
LSNtoMSF(dst + 12, lsn);
dst[15] = 2;
}
@ -911,11 +897,12 @@ int _isoWriteBlock(isoFile *iso, u8 *src, int lsn)
u64 ofs = (u64)lsn * iso->blocksize + iso->offset;
int ret;
// printf("_isoWriteBlock %d (ofs=%d)\n", iso->blocksize, ofs);
// printf("_isoWriteBlock %d (ofs=%d)\n", iso->blocksize, ofs);
_seekfile(iso->handle, ofs, SEEK_SET);
ret = _writefile(iso->handle, src + iso->blockofs, iso->blocksize);
// printf("_isoWriteBlock %d\n", ret);
if (ret < iso->blocksize) return -1;
// printf("_isoWriteBlock %d\n", ret);
if (ret < iso->blocksize)
return -1;
return 0;
}
@ -927,21 +914,22 @@ int _isoWriteBlockZ(isoFile *iso, u8 *src, int lsn)
u8 Zbuf[CD_FRAMESIZE_RAW];
int ret;
// printf("_isoWriteBlockZ %d\n", iso->blocksize);
// printf("_isoWriteBlockZ %d\n", iso->blocksize);
size = 2352;
compress(Zbuf, &size, src, 2352);
// printf("_isoWriteBlockZ %d\n", size);
// printf("_isoWriteBlockZ %d\n", size);
pos = (u32)_tellfile(iso->handle);
ret = _writefile(iso->htable, &pos, 4);
if (ret < 4) return -1;
if (ret < 4)
return -1;
ret = _writefile(iso->htable, &size, 2);
if (ret < 2) return -1;
if (ret < 2)
return -1;
ret = _writefile(iso->handle, Zbuf, size);
// printf("_isoWriteBlockZ %d\n", ret);
if (ret < size)
{
// printf("_isoWriteBlockZ %d\n", ret);
if (ret < size) {
printf("error writing block!!\n");
return -1;
}
@ -952,20 +940,20 @@ int _isoWriteBlockZ(isoFile *iso, u8 *src, int lsn)
int _isoWriteBlockZ2(isoFile *iso, u8 *src, int lsn)
{
uLongf size;
u8 Zbuf[1024*16];
u8 Zbuf[1024 * 16];
int ret;
// printf("_isoWriteBlockZ %d\n", iso->blocksize);
// printf("_isoWriteBlockZ %d\n", iso->blocksize);
size = 1024 * 16;
compress(Zbuf, &size, src + iso->blockofs, iso->blocksize);
// printf("_isoWriteBlockZ %d\n", size);
// printf("_isoWriteBlockZ %d\n", size);
ret = _writefile(iso->htable, (u8*) & size, 4);
if (ret < 4) return -1;
ret = _writefile(iso->htable, (u8 *)&size, 4);
if (ret < 4)
return -1;
ret = _writefile(iso->handle, Zbuf, size);
// printf("_isoWriteBlockZ %d\n", ret);
if (ret < size)
{
// printf("_isoWriteBlockZ %d\n", ret);
if (ret < size) {
printf("error writing block!!\n");
return -1;
}
@ -977,12 +965,14 @@ int _isoWriteBlockD(isoFile *iso, u8 *src, int lsn)
{
int ret;
// printf("_isoWriteBlock %d (ofs=%d)\n", iso->blocksize, ofs);
// printf("_isoWriteBlock %d (ofs=%d)\n", iso->blocksize, ofs);
ret = _writefile(iso->handle, &lsn, 4);
if (ret < 4) return -1;
if (ret < 4)
return -1;
ret = _writefile(iso->handle, src + iso->blockofs, iso->blocksize);
// printf("_isoWriteBlock %d\n", ret);
if (ret < iso->blocksize) return -1;
// printf("_isoWriteBlock %d\n", ret);
if (ret < iso->blocksize)
return -1;
return 0;
}
@ -990,40 +980,37 @@ int _isoWriteBlockD(isoFile *iso, u8 *src, int lsn)
int _isoWriteBlockBZ2(isoFile *iso, u8 *src, int lsn)
{
u32 size;
u8 Zbuf[64*1024];
u8 Zbuf[64 * 1024];
int blocks;
int ret;
memcpy(iso->buffer + (iso->blocksize*(lsn&0xf)), src + iso->blockofs, iso->blocksize);
memcpy(iso->buffer + (iso->blocksize * (lsn & 0xf)), src + iso->blockofs, iso->blocksize);
if (lsn == (iso->blocks - 1))
{
if (lsn == (iso->blocks - 1)) {
blocks = (lsn & 0xf) + 1;
}
else
{
} else {
blocks = 16;
if ((lsn & 0xf) != 0xf) return 0;
if ((lsn & 0xf) != 0xf)
return 0;
}
// printf("_isoWriteBlockBZ2 %d\n", iso->blocksize);
// printf("_isoWriteBlockBZ2 %d\n", iso->blocksize);
size = 64 * 1024;
ret = BZ2_bzBuffToBuffCompress((s8*)Zbuf, (u32*) & size, (s8*)iso->buffer, iso->blocksize * blocks, 9, 0, 30);
ret = BZ2_bzBuffToBuffCompress((s8 *)Zbuf, (u32 *)&size, (s8 *)iso->buffer, iso->blocksize * blocks, 9, 0, 30);
if (ret != BZ_OK)
{
if (ret != BZ_OK) {
printf("error on BZ2: %d\n", ret);
}
// printf("_isoWriteBlockBZ2 %d\n", size);
// printf("_isoWriteBlockBZ2 %d\n", size);
ret = _writefile(iso->htable, (u8*) & size, 4);
if (ret < 4) return -1;
ret = _writefile(iso->htable, (u8 *)&size, 4);
if (ret < 4)
return -1;
ret = _writefile(iso->handle, Zbuf, size);
// printf("_isoWriteBlockZ %d\n", ret);
// printf("_isoWriteBlockZ %d\n", ret);
if (ret < size)
{
if (ret < size) {
printf("error writing block!!\n");
return -1;
}
@ -1046,15 +1033,19 @@ int isoWriteBlock(isoFile *iso, u8 *src, int lsn)
else
ret = _isoWriteBlock(iso, src, lsn);
if (ret == -1) return ret;
if (ret == -1)
return ret;
return 0;
}
void isoClose(isoFile *iso)
{
if (iso->handle) _closefile(iso->handle);
if (iso->htable) _closefile(iso->htable);
if (iso->buffer) free(iso->buffer);
if (iso->handle)
_closefile(iso->handle);
if (iso->htable)
_closefile(iso->htable);
if (iso->buffer)
free(iso->buffer);
free(iso);
}

View File

@ -2,7 +2,7 @@
#define __LIBISO_H__
#ifdef _MSC_VER
#pragma warning(disable:4018)
#pragma warning(disable : 4018)
#endif
#define ISOTYPE_ILLEGAL 0
@ -17,10 +17,10 @@
#define ISOFLAGS_BZ2 0x0010
#define CD_FRAMESIZE_RAW 2352
#define DATA_SIZE (CD_FRAMESIZE_RAW-12)
#define DATA_SIZE (CD_FRAMESIZE_RAW - 12)
#define itob(i) ((i)/10*16 + (i)%10) /* u_char to BCD */
#define btoi(b) ((b)/16*10 + (b)%16) /* BCD to u_char */
#define itob(i) ((i) / 10 * 16 + (i) % 10) /* u_char to BCD */
#define btoi(b) ((b) / 16 * 10 + (b) % 16) /* BCD to u_char */
typedef struct
{

View File

@ -29,23 +29,19 @@ void Compress(char *filename, int mode)
{
struct stat buf;
u32 lsn;
u8 cdbuff[1024*16];
u8 cdbuff[1024 * 16];
char Zfile[256];
int ret = 0;
isoFile *src;
isoFile *dst;
if (mode == 1)
{
if (mode == 1) {
sprintf(Zfile, "%s.Z2", filename);
}
else
{
} else {
sprintf(Zfile, "%s.BZ2", filename);
}
if (stat(Zfile, &buf) != -1)
{
if (stat(Zfile, &buf) != -1) {
printf("'%s' already exists\n", Zfile);
return;
/* sprintf(str, "'%s' already exists, overwrite?", Zfile);
@ -56,38 +52,35 @@ void Compress(char *filename, int mode)
printf("src %s; dst %s\n", filename, Zfile);
src = isoOpen(filename);
if (src == NULL) return;
if (src == NULL)
return;
if (mode == 1)
{
if (mode == 1) {
dst = isoCreate(Zfile, ISOFLAGS_Z2);
}
else
{
} else {
dst = isoCreate(Zfile, ISOFLAGS_BZ2);
}
isoSetFormat(dst, src->blockofs, src->blocksize, src->blocks);
if (dst == NULL) return;
if (dst == NULL)
return;
for (lsn = 0; lsn < src->blocks; lsn++)
{
for (lsn = 0; lsn < src->blocks; lsn++) {
printf("block %d ", lsn);
putchar(13);
fflush(stdout);
ret = isoReadBlock(src, cdbuff, lsn);
if (ret == -1) break;
if (ret == -1)
break;
ret = isoWriteBlock(dst, cdbuff, lsn);
if (ret == -1) break;
if (ret == -1)
break;
}
isoClose(src);
isoClose(dst);
if (ret == -1)
{
if (ret == -1) {
printf("Error compressing iso image\n");
}
else
{
} else {
printf("Iso image compressed OK\n");
}
}
@ -96,14 +89,15 @@ void Decompress(char *filename)
{
struct stat buf;
char file[256];
u8 cdbuff[10*2352];
u8 cdbuff[10 * 2352];
u32 lsn;
isoFile *src;
isoFile *dst;
int ret = 0;
src = isoOpen(filename);
if (src == NULL) return;
if (src == NULL)
return;
strcpy(file, filename);
if (src->flags & ISOFLAGS_Z)
@ -112,14 +106,12 @@ void Decompress(char *filename)
file[strlen(file) - 3] = 0;
else if (src->flags & ISOFLAGS_BZ2)
file[strlen(file) - 3] = 0;
else
{
else {
printf("%s is not a compressed image\n", filename);
return;
}
if (stat(file, &buf) != -1)
{
if (stat(file, &buf) != -1) {
char str[256];
sprintf(str, "'%s' already exists", file);
isoClose(src);
@ -127,18 +119,20 @@ void Decompress(char *filename)
}
dst = isoCreate(file, 0);
if (dst == NULL) return;
if (dst == NULL)
return;
isoSetFormat(dst, src->blockofs, src->blocksize, src->blocks);
for (lsn = 0; lsn < src->blocks; lsn++)
{
for (lsn = 0; lsn < src->blocks; lsn++) {
printf("block %d ", lsn);
putchar(13);
fflush(stdout);
ret = isoReadBlock(src, cdbuff, lsn);
if (ret == -1) break;
if (ret == -1)
break;
ret = isoWriteBlock(dst, cdbuff, lsn);
if (ret == -1) break;
if (ret == -1)
break;
}
isoClose(src);