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

@ -44,35 +44,56 @@
#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;

View File

@ -44,8 +44,7 @@ char *methods[] =
{
".Z - compress faster",
".BZ - compress better",
NULL
};
NULL};
#ifdef PCSX2_DEBUG
char *LibName = "Linuz Iso CDVD (Debug) ";
@ -80,17 +79,20 @@ void lba_to_msf(s32 lba, u8* m, u8* s, u8* f)
#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,7 +102,8 @@ void __Log(char *fmt, ...)
{
va_list list;
if (cdvdLog == NULL) return;
if (cdvdLog == NULL)
return;
va_start(list, fmt);
vfprintf(cdvdLog, fmt, list);
@ -111,15 +114,14 @@ void __Log(char *fmt, ...)
#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
@ -193,8 +196,7 @@ EXPORT_C_(s32) CDVDopen(const char* pTitle)
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;
@ -264,7 +270,8 @@ EXPORT_C_(s32) CDVDreadSubQ(u32 lsn, cdvdSubQ* subq)
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;
}
@ -301,27 +307,26 @@ static bool testForPartitionInfo( const u8 (&tempbuffer)[CD_FRAMESIZE_RAW] )
(tempbuffer[off + 2] == 0x44) &&
(tempbuffer[off + 3] == 0x30) &&
(tempbuffer[off + 4] == 0x30) &&
(tempbuffer[off+5] == 0x31)
);
(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;
//__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
@ -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,24 +365,20 @@ 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);
if (testForPartitionInfo(tempbuffer))
layer1start = midsector - deviation;
else
{
else {
isoReadBlock(iso, tempbuffer, midsector + deviation);
if (testForPartitionInfo(tempbuffer))
layer1start = midsector + deviation;
}
if( layer1start != -1 )
{
if( tempbuffer[iso->blockofs] != 0x01 )
{
if (layer1start != -1) {
if (tempbuffer[iso->blockofs] != 0x01) {
fprintf(stderr, "(LinuzCDVDiso): Invalid partition type on layer 1!? (type=0x%x)", tempbuffer[iso->blockofs]);
}
}
@ -386,8 +386,7 @@ EXPORT_C_(s32) CDVDgetTOC(void* toc)
}
if (layer1start == -1)
{
if (layer1start == -1) {
printf("(LinuzCDVDiso): Couldn't find second layer on dual layer... ignoring\n");
// fake it
tocBuff[0] = 0x04;
@ -413,9 +412,7 @@ 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;
@ -429,10 +426,8 @@ EXPORT_C_(s32) CDVDgetTOC(void* toc)
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,8 +459,7 @@ 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;
@ -474,36 +468,34 @@ EXPORT_C_(s32) CDVDgetTOC(void* toc)
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)
{
if (_lsn < 0) {
// lsn = 2097152 + (-_lsn);
lsn = iso->blocks - (-_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

@ -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;
@ -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,7 +280,6 @@ EXPORT_C_(void) CDVDconfigure()
gtk_widget_show_all(ConfDlg);
gtk_main();
}
void OnAboutOk(GtkMenuItem *menuitem, gpointer userdata)
@ -286,7 +288,8 @@ void OnAboutOk(GtkMenuItem * menuitem, gpointer userdata)
gtk_main_quit();
}
EXPORT_C_(void) CDVDabout()
EXPORT_C_(void)
CDVDabout()
{
GtkWidget *Label;
GtkWidget *Ok;

View File

@ -32,8 +32,7 @@
#include <gtk/gtk.h>
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
#include "support.h"
@ -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

@ -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];
@ -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];
@ -627,7 +621,8 @@ void OnCreateZ(GtkButton *button, gpointer user_data)
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

@ -66,4 +66,3 @@ GdkPixbuf* create_pixbuf (const gchar *filename);
void glade_set_atk_action_description(AtkAction *action,
const gchar *action_name,
const gchar *description);

View File

@ -4,7 +4,8 @@
#include "../CDVDiso.h"
#define GetKeyV(name, var, s, t) \
size = s; type = t; \
size = s; \
type = t; \
RegQueryValueEx(myKey, name, 0, &type, (LPBYTE)var, &size);
#define GetKeyVdw(name, var) \
@ -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;
}
@ -87,8 +86,7 @@ int _OpenFile(int saveConf)
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);
}
@ -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");
}
}
@ -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

@ -117,14 +117,12 @@ void *_openfile(const char *filename, int flags)
HANDLE handle;
// printf("_openfile %s, %d\n", filename, flags & O_RDONLY);
if (flags & O_WRONLY)
{
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);
}
@ -145,12 +143,9 @@ 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)
{
if (whence == SEEK_SET) {
SetFilePointer(handle, _ofs[0], &_ofs[1], FILE_BEGIN);
}
else
{
} else {
SetFilePointer(handle, _ofs[0], &_ofs[1], FILE_END);
}
return 0;
@ -200,12 +195,10 @@ u64 _tellfile(void *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;
}
@ -217,7 +210,8 @@ int _seekfile(void *handle, u64 offset, int 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;
}
@ -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,8 +262,7 @@ 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;
}
@ -276,8 +271,7 @@ int _isoReadZtable(isoFile *iso)
size = _tellfile(handle);
iso->Ztable = (char *)malloc(size);
if (iso->Ztable == NULL)
{
if (iso->Ztable == NULL) {
return -1;
}
@ -300,8 +294,7 @@ 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;
}
@ -310,8 +303,7 @@ int _isoReadZ2table(isoFile *iso)
size = _tellfile(handle);
Ztable = (u32 *)malloc(size);
if (Ztable == NULL)
{
if (Ztable == NULL) {
return -1;
}
@ -321,16 +313,14 @@ int _isoReadZ2table(isoFile *iso)
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++)
{
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,8 +342,7 @@ 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;
}
@ -361,7 +350,8 @@ int _isoReadBZ2table(isoFile *iso)
_seekfile(handle, 0, SEEK_END);
size = _tellfile(handle);
Ztable = (u32 *)malloc(size);
if (Ztable == NULL) return -1;
if (Ztable == NULL)
return -1;
_seekfile(handle, 0, SEEK_SET);
_readfile(handle, Ztable, size);
@ -376,15 +366,13 @@ int _isoReadBZ2table(isoFile *iso)
ofs = 16;
for (i = 0; i < iso->blocks / 16; 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)
{
if (iso->blocks & 0xf) {
*(u32 *)&iso->Ztable[i * 8 + 0] = ofs;
*(u32 *)&iso->Ztable[i * 8 + 4] = Ztable[i];
ofs += Ztable[i];
@ -404,11 +392,11 @@ int _isoReadDtable(isoFile *iso)
iso->dtablesize = (_tellfile(iso->handle) - 16) / (iso->blocksize + 4);
iso->dtable = (u32 *)malloc(iso->dtablesize * 4);
for (i = 0; i < iso->dtablesize; i++)
{
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;
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;
@ -545,34 +535,32 @@ isoFile *isoOpen(const char *filename)
int i;
iso = (isoFile *)malloc(sizeof(isoFile));
if (iso == NULL) return NULL;
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));
@ -612,7 +598,8 @@ isoFile *isoCreate(const char *filename, int flags)
char Zfile[256];
iso = (isoFile *)malloc(sizeof(isoFile));
if (iso == NULL) return NULL;
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;
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;
@ -715,8 +709,7 @@ int _isoReadBlock(isoFile *iso, u8 *dst, int lsn)
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;
}
@ -737,8 +730,7 @@ int _isoReadBlockZ(isoFile *iso, u8 *dst, int lsn)
// 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;
}
@ -762,8 +754,7 @@ int _isoReadBlockZ2(isoFile *iso, u8 *dst, int lsn)
// 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;
}
@ -781,8 +772,7 @@ int _isoReadBlockBZ2(isoFile *iso, u8 *dst, int lsn)
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);
return 0;
@ -796,8 +786,7 @@ int _isoReadBlockBZ2(isoFile *iso, u8 *dst, int lsn)
_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;
}
@ -805,8 +794,7 @@ int _isoReadBlockBZ2(isoFile *iso, u8 *dst, int lsn)
size = iso->blocksize * 64;
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);
@ -825,13 +813,14 @@ int _isoReadBlockD(isoFile *iso, u8 *dst, int lsn)
// 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);
ret = _readfile(iso->handle, dst + iso->blockofs, iso->blocksize);
if (ret < iso->blocksize) return -1;
if (ret < iso->blocksize)
return -1;
return 0;
}
@ -846,15 +835,14 @@ 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);
@ -862,8 +850,7 @@ int _isoReadBlockM(isoFile *iso, u8 *dst, int lsn)
_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;
}
@ -915,7 +901,8 @@ int _isoWriteBlock(isoFile *iso, u8 *src, int lsn)
_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;
if (ret < iso->blocksize)
return -1;
return 0;
}
@ -934,14 +921,15 @@ int _isoWriteBlockZ(isoFile *iso, u8 *src, int lsn)
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)
{
if (ret < size) {
printf("error writing block!!\n");
return -1;
}
@ -961,11 +949,11 @@ int _isoWriteBlockZ2(isoFile *iso, u8 *src, int lsn)
// printf("_isoWriteBlockZ %d\n", size);
ret = _writefile(iso->htable, (u8 *)&size, 4);
if (ret < 4) return -1;
if (ret < 4)
return -1;
ret = _writefile(iso->handle, Zbuf, size);
// printf("_isoWriteBlockZ %d\n", ret);
if (ret < size)
{
if (ret < size) {
printf("error writing block!!\n");
return -1;
}
@ -979,10 +967,12 @@ int _isoWriteBlockD(isoFile *iso, u8 *src, int lsn)
// 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;
if (ret < iso->blocksize)
return -1;
return 0;
}
@ -996,34 +986,31 @@ int _isoWriteBlockBZ2(isoFile *iso, u8 *src, int lsn)
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);
size = 64 * 1024;
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);
ret = _writefile(iso->htable, (u8 *)&size, 4);
if (ret < 4) return -1;
if (ret < 4)
return -1;
ret = _writefile(iso->handle, Zbuf, size);
// 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

@ -35,17 +35,13 @@ void Compress(char *filename, int mode)
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");
}
}
@ -103,7 +96,8 @@ void Decompress(char *filename)
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);