Reformat CDVDiso's code, and get it to use a real ini file instead of writing inside one of the plugins binaries. Prep work for hunting down some bugs and modernizing it that I've been procrastinating about doing.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@441 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2009-02-07 03:13:59 +00:00
parent 9f75e5b825
commit 44c2fdf719
11 changed files with 999 additions and 669 deletions

View File

@ -21,7 +21,8 @@
#pragma warning(disable:4018) #pragma warning(disable:4018)
#endif #endif
#include "PS2Edefs.h" #include "common/PS2Etypes.h"
#include "common/PS2Edefs.h"
#include "libiso.h" #include "libiso.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -82,7 +83,8 @@ void __Log(char *fmt, ...);
#define DEV_DEF "" #define DEV_DEF ""
#define CDDEV_DEF "/dev/cdrom" #define CDDEV_DEF "/dev/cdrom"
typedef struct { typedef struct
{
int slsn; int slsn;
int elsn; int elsn;
#ifdef _WINDOWS_ #ifdef _WINDOWS_

View File

@ -40,7 +40,8 @@ FILE *cdvdLog = NULL;
// and skip prompting the user for a new CD when it's likely they want to run the existing one. // and skip prompting the user for a new CD when it's likely they want to run the existing one.
static char cdvdCurrentIso[MAX_PATH]; static char cdvdCurrentIso[MAX_PATH];
char *methods[] = { char *methods[] =
{
".Z - compress faster", ".Z - compress faster",
".BZ - compress better", ".BZ - compress better",
NULL NULL
@ -58,7 +59,8 @@ const unsigned char build = 8;
unsigned char cdbuffer[CD_FRAMESIZE_RAW * 10] = {0}; unsigned char cdbuffer[CD_FRAMESIZE_RAW * 10] = {0};
s32 msf_to_lba(u8 m, u8 s, u8 f) { s32 msf_to_lba(u8 m, u8 s, u8 f)
{
u32 lsn; u32 lsn;
lsn = f; lsn = f;
lsn += (s - 2) * 75; lsn += (s - 2) * 75;
@ -66,7 +68,8 @@ s32 msf_to_lba(u8 m, u8 s, u8 f) {
return lsn; 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; lba += 150;
*m = lba / (60 * 75); *m = lba / (60 * 75);
*s = (lba / 75) % 60; *s = (lba / 75) % 60;
@ -77,24 +80,27 @@ void lba_to_msf(s32 lba, u8* m, u8* s, u8* f) {
#define itob(i) ((i)/10*16 + (i)%10) /* u_char to BCD */ #define itob(i) ((i)/10*16 + (i)%10) /* u_char to BCD */
EXPORT_C(char*) PS2EgetLibName() { EXPORT_C(char*) PS2EgetLibName()
{
return LibName; return LibName;
} }
EXPORT_C(u32) PS2EgetLibType() { EXPORT_C(u32) PS2EgetLibType()
{
return PS2E_LT_CDVD; return PS2E_LT_CDVD;
} }
EXPORT_C(u32) PS2EgetLibVersion2(u32 type) { EXPORT_C(u32) PS2EgetLibVersion2(u32 type)
{
return (version << 16) | (revision << 8) | build; return (version << 16) | (revision << 8) | build;
} }
#ifdef _DEBUG #ifdef _DEBUG
void __Log(char *fmt, ...) { void __Log(char *fmt, ...)
{
va_list list; va_list list;
if( cdvdLog == NULL ) if (cdvdLog == NULL) return;
return;
va_start(list, fmt); va_start(list, fmt);
vfprintf(cdvdLog, fmt, list); vfprintf(cdvdLog, fmt, list);
@ -105,13 +111,17 @@ void __Log(char *fmt, ...) {
#endif #endif
EXPORT_C(s32) CDVDinit() { EXPORT_C(s32) CDVDinit()
{
#ifdef _DEBUG #ifdef _DEBUG
cdvdLog = fopen("logs/cdvdLog.txt", "w"); cdvdLog = fopen("logs/cdvdLog.txt", "w");
if (cdvdLog == NULL) { if (cdvdLog == NULL)
{
cdvdLog = fopen("cdvdLog.txt", "w"); cdvdLog = fopen("cdvdLog.txt", "w");
if (cdvdLog == NULL) { if (cdvdLog == NULL)
SysMessage("Can't create cdvdLog.txt"); return -1; {
SysMessage("Can't create cdvdLog.txt");
return -1;
} }
} }
setvbuf(cdvdLog, NULL, _IONBF, 0); setvbuf(cdvdLog, NULL, _IONBF, 0);
@ -123,22 +133,24 @@ EXPORT_C(s32) CDVDinit() {
return 0; return 0;
} }
EXPORT_C(void) CDVDshutdown() { EXPORT_C(void) CDVDshutdown()
{
cdvdCurrentIso[0] = 0; cdvdCurrentIso[0] = 0;
#ifdef CDVD_LOG #ifdef CDVD_LOG
if( cdvdLog != NULL ) if (cdvdLog != NULL) fclose(cdvdLog);
fclose(cdvdLog);
#endif #endif
} }
EXPORT_C(s32) CDVDopen(const char* pTitle) { EXPORT_C(s32) CDVDopen(const char* pTitle)
{
LoadConf(); LoadConf();
if (pTitle != NULL) strcpy(IsoFile, pTitle); if (pTitle != NULL) strcpy(IsoFile, pTitle);
if (*IsoFile == 0) strcpy(IsoFile, cdvdCurrentIso); if (*IsoFile == 0) strcpy(IsoFile, cdvdCurrentIso);
if (*IsoFile == 0) { if (*IsoFile == 0)
{
char temp[256]; char temp[256];
CfgOpenFile(); CfgOpenFile();
@ -151,21 +163,21 @@ EXPORT_C(s32) CDVDopen(const char* pTitle) {
} }
iso = isoOpen(IsoFile); iso = isoOpen(IsoFile);
if (iso == NULL) { if (iso == NULL)
{
SysMessage("Error loading %s\n", IsoFile); SysMessage("Error loading %s\n", IsoFile);
return -1; return -1;
} }
if (iso->type == ISOTYPE_DVD) { if (iso->type == ISOTYPE_DVD)
cdtype = CDVD_TYPE_PS2DVD; cdtype = CDVD_TYPE_PS2DVD;
} else else if (iso->type == ISOTYPE_AUDIO)
if (iso->type == ISOTYPE_AUDIO) {
cdtype = CDVD_TYPE_CDDA; cdtype = CDVD_TYPE_CDDA;
} else { else
cdtype = CDVD_TYPE_PS2CD; cdtype = CDVD_TYPE_PS2CD;
}
if (BlockDump) { if (BlockDump)
{
char fname_only[MAX_PATH]; char fname_only[MAX_PATH];
char* p, *plast; char* p, *plast;
@ -175,16 +187,21 @@ EXPORT_C(s32) CDVDopen(const char* pTitle) {
_makepath(fname_only, NULL, NULL, fname, NULL); _makepath(fname_only, NULL, NULL, fname, NULL);
#else #else
plast = p = strchr(IsoFile, '/'); plast = p = strchr(IsoFile, '/');
while(p != NULL) { while (p != NULL)
{
plast = p; plast = p;
p = strchr(p + 1, '/'); p = strchr(p + 1, '/');
} }
if( plast != NULL ) strcpy(fname_only, plast+1); if (plast != NULL)
else strcpy(fname_only, IsoFile); strcpy(fname_only, plast + 1);
else
strcpy(fname_only, IsoFile);
plast = p = strchr(fname_only, '.'); plast = p = strchr(fname_only, '.');
while(p != NULL) {
while (p != NULL)
{
plast = p; plast = p;
p = strchr(p + 1, '.'); p = strchr(p + 1, '.');
} }
@ -194,27 +211,27 @@ EXPORT_C(s32) CDVDopen(const char* pTitle) {
#endif #endif
strcat(fname_only, ".dump"); strcat(fname_only, ".dump");
fdump = isoCreate(fname_only, ISOFLAGS_BLOCKDUMP); fdump = isoCreate(fname_only, ISOFLAGS_BLOCKDUMP);
if (fdump) { if (fdump) isoSetFormat(fdump, iso->blockofs, iso->blocksize, iso->blocks);
isoSetFormat(fdump, iso->blockofs, iso->blocksize, iso->blocks);
} }
} else { else
{
fdump = NULL; fdump = NULL;
} }
return 0; return 0;
} }
EXPORT_C(void) CDVDclose() { EXPORT_C(void) CDVDclose()
{
strcpy(cdvdCurrentIso, IsoFile); strcpy(cdvdCurrentIso, IsoFile);
isoClose(iso); isoClose(iso);
if (fdump != NULL) { if (fdump != NULL) isoClose(fdump);
isoClose(fdump);
}
} }
EXPORT_C(s32) CDVDreadSubQ(u32 lsn, cdvdSubQ* subq) { EXPORT_C(s32) CDVDreadSubQ(u32 lsn, cdvdSubQ* subq)
{
// fake it // fake it
u8 min, sec, frm; u8 min, sec, frm;
subq->ctrl = 4; subq->ctrl = 4;
@ -236,17 +253,22 @@ EXPORT_C(s32) CDVDreadSubQ(u32 lsn, cdvdSubQ* subq) {
return 0; return 0;
} }
EXPORT_C(s32) CDVDgetTN(cdvdTN *Buffer) { EXPORT_C(s32) CDVDgetTN(cdvdTN *Buffer)
{
Buffer->strack = 1; Buffer->strack = 1;
Buffer->etrack = 1; Buffer->etrack = 1;
return 0; return 0;
} }
EXPORT_C(s32) CDVDgetTD(u8 Track, cdvdTD *Buffer) { EXPORT_C(s32) CDVDgetTD(u8 Track, cdvdTD *Buffer)
if (Track == 0) { {
if (Track == 0)
{
Buffer->lsn = iso->blocks; Buffer->lsn = iso->blocks;
} else { }
else
{
Buffer->type = CDVD_MODE1_TRACK; Buffer->type = CDVD_MODE1_TRACK;
Buffer->lsn = 0; Buffer->lsn = 0;
} }
@ -255,7 +277,8 @@ EXPORT_C(s32) CDVDgetTD(u8 Track, cdvdTD *Buffer) {
} }
static int layer1start = -1; static int layer1start = -1;
EXPORT_C(s32) CDVDgetTOC(void* toc) { EXPORT_C(s32) CDVDgetTOC(void* toc)
{
u8 type = CDVDgetDiskType(); u8 type = CDVDgetDiskType();
u8* tocBuff = (u8*)toc; u8* tocBuff = (u8*)toc;
@ -269,7 +292,8 @@ EXPORT_C(s32) CDVDgetTOC(void* toc) {
// scsi command 0x43 // scsi command 0x43
memset(tocBuff, 0, 2048); memset(tocBuff, 0, 2048);
if( layer1start != -2 && iso->blocks >= 0x300000 ) { if (layer1start != -2 && iso->blocks >= 0x300000)
{
int off = iso->blockofs; int off = iso->blockofs;
u8* tempbuffer; u8* tempbuffer;
@ -289,19 +313,21 @@ EXPORT_C(s32) CDVDgetTOC(void* toc) {
tocBuff[19] = 0x00; tocBuff[19] = 0x00;
// search for it // search for it
if( layer1start == -1 ) { if (layer1start == -1)
{
printf("CDVD: searching for layer1..."); printf("CDVD: searching for layer1...");
tempbuffer = (u8*)malloc(CD_FRAMESIZE_RAW * 10); tempbuffer = (u8*)malloc(CD_FRAMESIZE_RAW * 10);
for(layer1start = (iso->blocks/2-0x10)&~0xf; layer1start < 0x200010; layer1start += 16) { for (layer1start = (iso->blocks / 2 - 0x10) & ~0xf; layer1start < 0x200010; layer1start += 16)
{
isoReadBlock(iso, tempbuffer, layer1start); isoReadBlock(iso, tempbuffer, layer1start);
// CD001 // CD001
if( tempbuffer[off+1] == 0x43 && tempbuffer[off+2] == 0x44 && tempbuffer[off+3] == 0x30 && tempbuffer[off+4] == 0x30 && tempbuffer[off+5] == 0x31 ) { if (tempbuffer[off+1] == 0x43 && tempbuffer[off+2] == 0x44 && tempbuffer[off+3] == 0x30 && tempbuffer[off+4] == 0x30 && tempbuffer[off+5] == 0x31)
break; break;
} }
}
free(tempbuffer); free(tempbuffer);
if( layer1start == 0x200010 ) { if (layer1start == 0x200010)
{
printf("Couldn't find second layer on dual layer... ignoring\n"); printf("Couldn't find second layer on dual layer... ignoring\n");
// fake it // fake it
tocBuff[ 0] = 0x04; tocBuff[ 0] = 0x04;
@ -328,7 +354,8 @@ EXPORT_C(s32) CDVDgetTOC(void* toc) {
tocBuff[22] = (layer1start >> 8) & 0xff; tocBuff[22] = (layer1start >> 8) & 0xff;
tocBuff[23] = (layer1start >> 0) & 0xff; tocBuff[23] = (layer1start >> 0) & 0xff;
} }
else { else
{
// fake it // fake it
tocBuff[ 0] = 0x04; tocBuff[ 0] = 0x04;
tocBuff[ 1] = 0x02; tocBuff[ 1] = 0x02;
@ -343,11 +370,8 @@ EXPORT_C(s32) CDVDgetTOC(void* toc) {
tocBuff[19] = 0x00; tocBuff[19] = 0x00;
} }
} }
else if(type == CDVD_TYPE_CDDA || else if ((type == CDVD_TYPE_CDDA) || (type == CDVD_TYPE_PS2CDDA) ||
type == CDVD_TYPE_PS2CDDA || (type == CDVD_TYPE_PS2CD) || (type == CDVD_TYPE_PSCDDA) || (type == CDVD_TYPE_PSCD))
type == CDVD_TYPE_PS2CD ||
type == CDVD_TYPE_PSCDDA ||
type == CDVD_TYPE_PSCD)
{ {
// cd toc // cd toc
// (could be replaced by 1 command that reads the full toc) // (could be replaced by 1 command that reads the full toc)
@ -356,7 +380,11 @@ EXPORT_C(s32) CDVDgetTOC(void* toc) {
cdvdTN diskInfo; cdvdTN diskInfo;
cdvdTD trackInfo; cdvdTD trackInfo;
memset(tocBuff, 0, 1024); memset(tocBuff, 0, 1024);
if (CDVDgetTN(&diskInfo) == -1) { diskInfo.etrack = 0;diskInfo.strack = 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[0] = 0x41;
@ -393,55 +421,71 @@ EXPORT_C(s32) CDVDgetTOC(void* toc) {
return 0; return 0;
} }
EXPORT_C(s32) CDVDreadTrack(u32 lsn, int mode) { EXPORT_C(s32) CDVDreadTrack(u32 lsn, int mode)
{
int _lsn = lsn; int _lsn = lsn;
//__Log("CDVDreadTrack: %x %x\n", lsn, mode); //__Log("CDVDreadTrack: %x %x\n", lsn, mode);
if (_lsn < 0) { if (_lsn < 0)
{
// lsn = 2097152 + (-_lsn); // lsn = 2097152 + (-_lsn);
lsn = iso->blocks - (-_lsn); lsn = iso->blocks - (-_lsn);
} }
// printf ("CDRreadTrack %d\n", lsn); // printf ("CDRreadTrack %d\n", lsn);
isoReadBlock(iso, cdbuffer, lsn); isoReadBlock(iso, cdbuffer, lsn);
if (fdump != NULL) { if (fdump != NULL)
{
isoWriteBlock(fdump, cdbuffer, lsn); isoWriteBlock(fdump, cdbuffer, lsn);
} }
pbuffer = cdbuffer; pbuffer = cdbuffer;
switch (mode) { switch (mode)
case CDVD_MODE_2352: break; {
case CDVD_MODE_2340: pbuffer+= 12; break; case CDVD_MODE_2352:
case CDVD_MODE_2328: pbuffer+= 24; break; break;
case CDVD_MODE_2048: pbuffer+= 24; break; case CDVD_MODE_2340:
pbuffer += 12;
break;
case CDVD_MODE_2328:
pbuffer += 24;
break;
case CDVD_MODE_2048:
pbuffer += 24;
break;
} }
return 0; return 0;
} }
EXPORT_C(u8*) CDVDgetBuffer() { EXPORT_C(u8*) CDVDgetBuffer()
{
return pbuffer; return pbuffer;
} }
EXPORT_C(s32) CDVDgetDiskType() { EXPORT_C(s32) CDVDgetDiskType()
{
return cdtype; return cdtype;
} }
EXPORT_C(s32) CDVDgetTrayStatus() { EXPORT_C(s32) CDVDgetTrayStatus()
{
return CDVD_TRAY_CLOSE; return CDVD_TRAY_CLOSE;
} }
EXPORT_C(s32) CDVDctrlTrayOpen() { EXPORT_C(s32) CDVDctrlTrayOpen()
{
return 0; return 0;
} }
EXPORT_C(s32) CDVDctrlTrayClose() { EXPORT_C(s32) CDVDctrlTrayClose()
{
return 0; return 0;
} }
EXPORT_C(s32) CDVDtest() { EXPORT_C(s32) CDVDtest()
if (*IsoFile == 0) {
return 0; if (*IsoFile == 0) return 0;
iso = isoOpen(IsoFile); iso = isoOpen(IsoFile);
if (iso == NULL) return -1; if (iso == NULL) return -1;

View File

@ -24,36 +24,59 @@
#include "CDVDiso.h" #include "CDVDiso.h"
void LoadConf() {
const char *s_strIniPath="../inis/CDVDiso.ini";
void LoadConf()
{
FILE *f; FILE *f;
char cfg[256]; char cfg[256];
sprintf(cfg, "%s/.PS2E/CDVDiso.cfg", getenv("HOME")); //sprintf(cfg, "%s/.PS2E/CDVDiso.cfg", getenv("HOME"));
strcpy(cfg, s_strIniPath);
f = fopen(cfg, "r"); f = fopen(cfg, "r");
if (f == NULL) {
if (f == NULL)
{
printf("Unable to load %s\n", cfg);
strcpy(IsoFile, DEV_DEF); strcpy(IsoFile, DEV_DEF);
strcpy(CdDev, CDDEV_DEF); strcpy(CdDev, CDDEV_DEF);
BlockDump = 0;
SaveConf();
return; return;
} }
fscanf(f, "IsoFile = %[^\n]\n", IsoFile); fscanf(f, "IsoFile = %[^\n]\n", IsoFile);
fscanf(f, "CdDev = %[^\n]\n", CdDev); fscanf(f, "CdDev = %[^\n]\n", CdDev);
fscanf(f, "BlockDump = %[^\n]\n", &BlockDump);
if (!strncmp(IsoFile, "CdDev =", 9)) *IsoFile = 0; // quick fix if (!strncmp(IsoFile, "CdDev =", 9)) *IsoFile = 0; // quick fix
if (*CdDev == 0) strcpy(CdDev, CDDEV_DEF); if (*CdDev == 0) strcpy(CdDev, CDDEV_DEF);
fclose(f); fclose(f);
} }
void SaveConf() { void SaveConf()
{
FILE *f; FILE *f;
char cfg[256]; char cfg[256];
sprintf(cfg, "%s/.PS2E", getenv("HOME")); //sprintf(cfg, "%s/.PS2E", getenv("HOME"));
mkdir(cfg, 0755);
sprintf(cfg, "%s/.PS2E/CDVDiso.cfg", getenv("HOME")); //mkdir(cfg, 0755);
//sprintf(cfg, "%s/.PS2E/CDVDiso.cfg", getenv("HOME"));
strcpy(cfg, s_strIniPath);
f = fopen(cfg, "w"); f = fopen(cfg, "w");
if (f == NULL) if (f == NULL)
{
printf("Unable to save %s\n", cfg);
return; return;
}
fprintf(f, "IsoFile = %s\n", IsoFile); fprintf(f, "IsoFile = %s\n", IsoFile);
fprintf(f, "CdDev = %s\n", CdDev); fprintf(f, "CdDev = %s\n", CdDev);
fprintf(f, "BlockDump = %s\n", &BlockDump);
fclose(f); fclose(f);
} }

View File

@ -25,44 +25,55 @@
#include "Config.h" #include "Config.h"
#include "CDVDiso.h" #include "CDVDiso.h"
void ExecCfg(char *arg) { void ExecCfg(char *arg)
{
char cfg[256]; char cfg[256];
struct stat buf; struct stat buf;
strcpy(cfg, "./cfgCDVDiso"); strcpy(cfg, "./cfgCDVDiso");
if (stat(cfg, &buf) != -1) { if (stat(cfg, &buf) != -1)
{
sprintf(cfg, "%s %s", cfg, arg); sprintf(cfg, "%s %s", cfg, arg);
system(cfg); return; system(cfg);
return;
} }
strcpy(cfg, "./cfg/cfgCDVDiso"); strcpy(cfg, "./cfg/cfgCDVDiso");
if (stat(cfg, &buf) != -1) { if (stat(cfg, &buf) != -1)
{
sprintf(cfg, "%s %s", cfg, arg); sprintf(cfg, "%s %s", cfg, arg);
system(cfg); return; system(cfg);
return;
} }
sprintf(cfg, "%s/cfgCDVDiso", getenv("HOME")); sprintf(cfg, "%s/cfgCDVDiso", getenv("HOME"));
if (stat(cfg, &buf) != -1) { if (stat(cfg, &buf) != -1)
{
sprintf(cfg, "%s %s", cfg, arg); sprintf(cfg, "%s %s", cfg, arg);
system(cfg); return; system(cfg);
return;
} }
printf("cfgCDVDiso file not found!\n"); printf("cfgCDVDiso file not found!\n");
} }
void CDVDconfigure() { void CDVDconfigure()
{
ExecCfg("configure"); ExecCfg("configure");
} }
void CDVDabout() { void CDVDabout()
{
ExecCfg("about"); ExecCfg("about");
} }
void CfgOpenFile() { void CfgOpenFile()
{
ExecCfg("open"); ExecCfg("open");
} }
void SysMessage(char *fmt, ...) { void SysMessage(char *fmt, ...)
{
va_list list; va_list list;
char tmp[256]; char tmp[256];
char cmd[256]; char cmd[256];

View File

@ -44,7 +44,8 @@ extern const unsigned char build;
GtkWidget *FileSel; GtkWidget *FileSel;
void OnFile_Ok() { void OnFile_Ok()
{
gchar *File; gchar *File;
gtk_widget_hide(FileSel); gtk_widget_hide(FileSel);
@ -53,12 +54,14 @@ void OnFile_Ok() {
gtk_main_quit(); gtk_main_quit();
} }
void OnFile_Cancel() { void OnFile_Cancel()
{
gtk_widget_hide(FileSel); gtk_widget_hide(FileSel);
gtk_main_quit(); gtk_main_quit();
} }
void _CDRopen() { void _CDRopen()
{
GtkWidget *Ok, *Cancel; GtkWidget *Ok, *Cancel;
FileSel = gtk_file_selection_new("Select Iso File"); FileSel = gtk_file_selection_new("Select Iso File");
@ -83,12 +86,14 @@ void _CDRopen() {
GtkWidget *MsgDlg; GtkWidget *MsgDlg;
void OnMsg_Ok() { void OnMsg_Ok()
{
gtk_widget_destroy(MsgDlg); gtk_widget_destroy(MsgDlg);
gtk_main_quit(); gtk_main_quit();
} }
static void SysMessageLoc(char *fmt, ...) { static void SysMessageLoc(char *fmt, ...)
{
GtkWidget *Ok, *Txt; GtkWidget *Ok, *Txt;
GtkWidget *Box, *Box1; GtkWidget *Box, *Box1;
va_list list; va_list list;
@ -148,7 +153,8 @@ extern char *methods[];
int stop; int stop;
void OnOk(GtkMenuItem * menuitem, gpointer userdata) { void OnOk(GtkMenuItem * menuitem, gpointer userdata)
{
char *tmp; char *tmp;
stop = 1; stop = 1;
@ -161,13 +167,15 @@ void OnOk(GtkMenuItem * menuitem, gpointer userdata) {
gtk_main_quit(); gtk_main_quit();
} }
void OnCancel(GtkMenuItem * menuitem, gpointer userdata) { void OnCancel(GtkMenuItem * menuitem, gpointer userdata)
{
stop = 1; stop = 1;
gtk_widget_destroy(ConfDlg); gtk_widget_destroy(ConfDlg);
gtk_main_quit(); gtk_main_quit();
} }
void OnFileSel_Ok() { void OnFileSel_Ok()
{
gchar *File; gchar *File;
File = gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSel)); File = gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSel));
@ -175,11 +183,13 @@ void OnFileSel_Ok() {
gtk_widget_destroy(FileSel); gtk_widget_destroy(FileSel);
} }
void OnFileSel_Cancel() { void OnFileSel_Cancel()
{
gtk_widget_destroy(FileSel); gtk_widget_destroy(FileSel);
} }
void OnFileSel() { void OnFileSel()
{
GtkWidget *Ok, *Cancel; GtkWidget *Ok, *Cancel;
FileSel = gtk_file_selection_new("Select Psx Iso File"); FileSel = gtk_file_selection_new("Select Psx Iso File");
@ -197,11 +207,13 @@ void OnFileSel() {
gdk_window_raise(FileSel->window); gdk_window_raise(FileSel->window);
} }
void OnStop() { void OnStop()
{
stop = 1; stop = 1;
} }
void UpdZmode() { void UpdZmode()
{
char *tmp; char *tmp;
tmp = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(Method)->entry)); tmp = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(Method)->entry));
@ -211,7 +223,8 @@ void UpdZmode() {
char buffer[2352 * 10]; char buffer[2352 * 10];
void OnCompress() { void OnCompress()
{
struct stat buf; struct stat buf;
u32 lsn; u32 lsn;
u8 cdbuff[10*2352]; u8 cdbuff[10*2352];
@ -228,8 +241,9 @@ void OnCompress() {
if (Zmode == 1) sprintf(Zfile, "%s.Z2", IsoFile); if (Zmode == 1) sprintf(Zfile, "%s.Z2", IsoFile);
if (Zmode == 2) sprintf(Zfile, "%s.BZ2", IsoFile); if (Zmode == 2) sprintf(Zfile, "%s.BZ2", IsoFile);
if (stat(Zfile, &buf) != -1) { if (stat(Zfile, &buf) != -1)
char str[256]; {
/*char str[256];*/
return; return;
/* sprintf(str, "'%s' already exists, overwrite?", Zfile); /* sprintf(str, "'%s' already exists, overwrite?", Zfile);
if (MessageBox(hDlg, str, "Question", MB_YESNO) != IDYES) { if (MessageBox(hDlg, str, "Question", MB_YESNO) != IDYES) {
@ -248,7 +262,8 @@ void OnCompress() {
gtk_widget_set_sensitive(BtnCreateZ, FALSE); gtk_widget_set_sensitive(BtnCreateZ, FALSE);
stop = 0; stop = 0;
for (lsn = 0; lsn<src->blocks; lsn++) { for (lsn = 0; lsn < src->blocks; lsn++)
{
printf("block %d ", lsn); printf("block %d ", lsn);
putchar(13); putchar(13);
fflush(stdout); fflush(stdout);
@ -271,16 +286,21 @@ void OnCompress() {
gtk_widget_set_sensitive(BtnCreate, TRUE); gtk_widget_set_sensitive(BtnCreate, TRUE);
gtk_widget_set_sensitive(BtnCreateZ, TRUE); gtk_widget_set_sensitive(BtnCreateZ, TRUE);
if (!stop) { if (!stop)
if (ret == -1) { {
if (ret == -1)
{
SysMessageLoc("Error compressing iso image"); SysMessageLoc("Error compressing iso image");
} else { }
else
{
SysMessageLoc("Iso image compressed OK"); SysMessageLoc("Iso image compressed OK");
} }
} }
} }
void OnDecompress() { void OnDecompress()
{
#if 0 #if 0
struct stat buf; struct stat buf;
FILE *f; FILE *f;
@ -299,7 +319,8 @@ void OnDecompress() {
if (Zmode == 1) strcat(table, ".table"); if (Zmode == 1) strcat(table, ".table");
else strcat(table, ".index"); else strcat(table, ".index");
if (stat(table, &buf) == -1) { if (stat(table, &buf) == -1)
{
return; return;
} }
if (Zmode == 1) c = s = buf.st_size / 6; if (Zmode == 1) c = s = buf.st_size / 6;
@ -310,7 +331,8 @@ void OnDecompress() {
fclose(f); fclose(f);
cdHandle[0] = fopen(IsoFile, "rb"); cdHandle[0] = fopen(IsoFile, "rb");
if (cdHandle[0] == NULL) { if (cdHandle[0] == NULL)
{
return; return;
} }
@ -318,7 +340,8 @@ void OnDecompress() {
else IsoFile[strlen(IsoFile) - 3] = 0; else IsoFile[strlen(IsoFile) - 3] = 0;
f = fopen(IsoFile, "wb"); f = fopen(IsoFile, "wb");
if (f == NULL) { if (f == NULL)
{
return; return;
} }
@ -328,23 +351,30 @@ void OnDecompress() {
gtk_widget_set_sensitive(BtnCreateZ, FALSE); gtk_widget_set_sensitive(BtnCreateZ, FALSE);
stop = 0; stop = 0;
if (Zmode == 1) { if (Zmode == 1)
{
blocks = 1; blocks = 1;
} else { }
else
{
blocks = 10; blocks = 10;
} }
while (c--) { while (c--)
{
unsigned long size, pos, ssize; unsigned long size, pos, ssize;
float per; float per;
if (Zmode == 1) { if (Zmode == 1)
{
pos = *(unsigned long*) & Ztable[p * 6]; pos = *(unsigned long*) & Ztable[p * 6];
fseek(cdHandle[0], pos, SEEK_SET); fseek(cdHandle[0], pos, SEEK_SET);
ssize = *(unsigned short*) & Ztable[p * 6 + 4]; ssize = *(unsigned short*) & Ztable[p * 6 + 4];
fread(Zbuf, 1, ssize, cdHandle[0]); fread(Zbuf, 1, ssize, cdHandle[0]);
} else { }
else
{
pos = *(unsigned long*) & Ztable[p * 4]; pos = *(unsigned long*) & Ztable[p * 4];
fseek(cdHandle[0], pos, SEEK_SET); fseek(cdHandle[0], pos, SEEK_SET);
@ -368,8 +398,10 @@ void OnDecompress() {
if (!stop) gtk_entry_set_text(GTK_ENTRY(Edit), IsoFile); if (!stop) gtk_entry_set_text(GTK_ENTRY(Edit), IsoFile);
fclose(f); fclose(f);
fclose(cdHandle[0]); cdHandle[0] = NULL; fclose(cdHandle[0]);
free(Ztable); Ztable = NULL; cdHandle[0] = NULL;
free(Ztable);
Ztable = NULL;
gtk_widget_set_sensitive(BtnCompress, TRUE); gtk_widget_set_sensitive(BtnCompress, TRUE);
gtk_widget_set_sensitive(BtnDecompress, TRUE); gtk_widget_set_sensitive(BtnDecompress, TRUE);
@ -384,28 +416,34 @@ void OnDecompress() {
unsigned char param[4]; unsigned char param[4];
int cddev = -1; int cddev = -1;
union { union
{
struct cdrom_msf msf; struct cdrom_msf msf;
unsigned char buf[CD_FRAMESIZE_RAW]; unsigned char buf[CD_FRAMESIZE_RAW];
} cr; } cr;
void incSector() { void incSector()
{
param[2]++; param[2]++;
if (param[2] == 75) { if (param[2] == 75)
{
param[2] = 0; param[2] = 0;
param[1]++; param[1]++;
} }
if (param[1] == 60) { if (param[1] == 60)
{
param[1] = 0; param[1] = 0;
param[0]++; param[0]++;
} }
} }
long CDR_open(void) { long CDR_open(void)
{
if (cddev != -1) if (cddev != -1)
return 0; return 0;
cddev = open(CdDev, O_RDONLY); cddev = open(CdDev, O_RDONLY);
if (cddev == -1) { if (cddev == -1)
{
printf("CDR: Could not open %s\n", CdDev); printf("CDR: Could not open %s\n", CdDev);
return -1; return -1;
} }
@ -413,7 +451,8 @@ long CDR_open(void) {
return 0; return 0;
} }
long CDR_close(void) { long CDR_close(void)
{
if (cddev == -1) return 0; if (cddev == -1) return 0;
close(cddev); close(cddev);
cddev = -1; cddev = -1;
@ -425,7 +464,8 @@ long CDR_close(void) {
// buffer: // buffer:
// byte 0 - start track // byte 0 - start track
// byte 1 - end track // byte 1 - end track
long CDR_getTN(unsigned char *buffer) { long CDR_getTN(unsigned char *buffer)
{
struct cdrom_tochdr toc; struct cdrom_tochdr toc;
if (ioctl(cddev, CDROMREADTOCHDR, &toc) == -1) return -1; if (ioctl(cddev, CDROMREADTOCHDR, &toc) == -1) return -1;
@ -441,7 +481,8 @@ long CDR_getTN(unsigned char *buffer) {
// byte 0 - frame // byte 0 - frame
// byte 1 - second // byte 1 - second
// byte 2 - minute // byte 2 - minute
long CDR_getTD(unsigned char track, unsigned char *buffer) { long CDR_getTD(unsigned char track, unsigned char *buffer)
{
struct cdrom_tocentry entry; struct cdrom_tocentry entry;
if (track == 0) track = 0xaa; // total time if (track == 0) track = 0xaa; // total time
@ -462,7 +503,8 @@ long CDR_getTD(unsigned char track, unsigned char *buffer) {
// byte 0 - minute // byte 0 - minute
// byte 1 - second // byte 1 - second
// byte 2 - frame // byte 2 - frame
char *CDR_readTrack(unsigned char *time) { char *CDR_readTrack(unsigned char *time)
{
cr.msf.cdmsf_min0 = time[0]; cr.msf.cdmsf_min0 = time[0];
cr.msf.cdmsf_sec0 = time[1]; cr.msf.cdmsf_sec0 = time[1];
cr.msf.cdmsf_frame0 = time[2]; cr.msf.cdmsf_frame0 = time[2];
@ -472,7 +514,8 @@ char *CDR_readTrack(unsigned char *time) {
} }
void OnCreate() { void OnCreate()
{
FILE *f; FILE *f;
struct stat buf; struct stat buf;
struct tm *Tm; struct tm *Tm;
@ -495,22 +538,26 @@ void OnCreate() {
tmp = gtk_entry_get_text(GTK_ENTRY(Edit)); tmp = gtk_entry_get_text(GTK_ENTRY(Edit));
strcpy(IsoFile, tmp); strcpy(IsoFile, tmp);
if (stat(IsoFile, &buf) == 0) { if (stat(IsoFile, &buf) == 0)
{
printf("File %s Already exists\n", IsoFile); printf("File %s Already exists\n", IsoFile);
return; return;
} }
if (CDR_open() == -1) { if (CDR_open() == -1)
{
return; return;
} }
if (CDR_getTD(ftrack, start) == -1) { if (CDR_getTD(ftrack, start) == -1)
{
printf("Error getting TD\n"); printf("Error getting TD\n");
CDR_close(); CDR_close();
return; return;
} }
if (CDR_getTD(ltrack, end) == -1) { if (CDR_getTD(ltrack, end) == -1)
{
printf("Error getting TD\n"); printf("Error getting TD\n");
CDR_close(); CDR_close();
@ -518,7 +565,8 @@ void OnCreate() {
} }
f = fopen(IsoFile, "wb"); f = fopen(IsoFile, "wb");
if (f == NULL) { if (f == NULL)
{
CDR_close(); CDR_close();
printf("Error opening %s", IsoFile); printf("Error opening %s", IsoFile);
return; return;
@ -538,20 +586,24 @@ void OnCreate() {
gtk_widget_set_sensitive(BtnCreate, FALSE); gtk_widget_set_sensitive(BtnCreate, FALSE);
gtk_widget_set_sensitive(BtnCreateZ, FALSE); gtk_widget_set_sensitive(BtnCreateZ, FALSE);
for (;;) { /* loop until end */ for (;;) /* loop until end */
{
float per; float per;
if ((param[0] == end[0]) & (param[1] == end[1]) & (param[2] == end[2])) if ((param[0] == end[0]) & (param[1] == end[1]) & (param[2] == end[2]))
break; break;
buffer = CDR_readTrack(param); buffer = CDR_readTrack(param);
if (buffer == NULL) { if (buffer == NULL)
{
int i; int i;
for (i=0; i<10; i++) { for (i = 0; i < 10; i++)
{
buffer = CDR_readTrack(param); 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]); printf("Error Reading %2d:%2d:%2d\n", param[0], param[1], param[2]);
buffer = bufferz; buffer = bufferz;
buffer[12] = param[0]; buffer[12] = param[0];
@ -565,7 +617,8 @@ void OnCreate() {
count += CD_FRAMESIZE_RAW; count += CD_FRAMESIZE_RAW;
printf("reading %2d:%2d:%2d ", param[0], param[1], param[2]); 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); i = (count / 1024) / (time(NULL) - Ttime);
printf("( %5dKbytes/s, %dX)", i, i / 150); printf("( %5dKbytes/s, %dX)", i, i / 150);
} }
@ -598,7 +651,8 @@ void OnCreate() {
if (!stop) SysMessageLoc("Iso Image Created OK"); if (!stop) SysMessageLoc("Iso Image Created OK");
} }
void OnCreateZ() { void OnCreateZ()
{
FILE *f; FILE *f;
FILE *t; FILE *t;
struct stat buf; struct stat buf;
@ -626,46 +680,51 @@ void OnCreateZ() {
UpdZmode(); UpdZmode();
if (Zmode == 1) { if (Zmode == 1)
{
blocks = 1; blocks = 1;
if (strstr(IsoFile, ".Z") == NULL) strcat(IsoFile, ".Z"); if (strstr(IsoFile, ".Z") == NULL) strcat(IsoFile, ".Z");
} else { }
else
{
blocks = 10; 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); printf("File %s Already exists\n", IsoFile);
return; return;
} }
strcpy(table, IsoFile); strcpy(table, IsoFile);
if (Zmode == 1) strcat(table, ".table"); if (Zmode == 1)
else strcat(table, ".index"); strcat(table, ".table");
else
strcat(table, ".index");
t = fopen(table, "wb"); t = fopen(table, "wb");
if (t == NULL) {
return;
}
if (CDR_open() == -1) { if (t == NULL) return;
return; if (CDR_open() == -1) return;
}
if (CDR_getTD(ftrack, start) == -1) { if (CDR_getTD(ftrack, start) == -1)
{
printf("Error getting TD\n"); printf("Error getting TD\n");
CDR_close(); CDR_close();
return; return;
} }
if (CDR_getTD(ltrack, end) == -1) {
printf("Error getting TD\n");
if (CDR_getTD(ltrack, end) == -1)
{
printf("Error getting TD\n");
CDR_close(); CDR_close();
return; return;
} }
f = fopen(IsoFile, "wb"); f = fopen(IsoFile, "wb");
if (f == NULL) { if (f == NULL)
{
CDR_close(); CDR_close();
printf("Error opening %s", IsoFile); printf("Error opening %s", IsoFile);
return; return;
@ -685,23 +744,30 @@ void OnCreateZ() {
gtk_widget_set_sensitive(BtnCreate, FALSE); gtk_widget_set_sensitive(BtnCreate, FALSE);
gtk_widget_set_sensitive(BtnCreateZ, FALSE); gtk_widget_set_sensitive(BtnCreateZ, FALSE);
for (;;) { /* loop until end */ for (;;) /* loop until end */
{
unsigned long size; unsigned long size;
unsigned char Zbuf[CD_FRAMESIZE_RAW * 10 * 2]; unsigned char Zbuf[CD_FRAMESIZE_RAW * 10 * 2];
float per; 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])) if ((param[0] == end[0]) & (param[1] == end[1]) & (param[2] == end[2]))
break; break;
buffer = CDR_readTrack(param); buffer = CDR_readTrack(param);
if (buffer == NULL) { if (buffer == NULL)
{
int i; int i;
for (i=0; i<10; i++) { for (i = 0; i < 10; i++)
{
buffer = CDR_readTrack(param); 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]); printf("Error Reading %2d:%2d:%2d\n", param[0], param[1], param[2]);
buffer = bufferz; buffer = bufferz;
buffer[12] = param[0]; buffer[12] = param[0];
@ -718,8 +784,10 @@ void OnCreateZ() {
break; break;
size = CD_FRAMESIZE_RAW * blocks * 2; size = CD_FRAMESIZE_RAW * blocks * 2;
if (Zmode == 1) compress(Zbuf, &size, cdbuffer, CD_FRAMESIZE_RAW); if (Zmode == 1)
else BZ2_bzBuffToBuffCompress(Zbuf, (unsigned int*)&size, cdbuffer, CD_FRAMESIZE_RAW * 10, 1, 0, 30); compress(Zbuf, &size, cdbuffer, CD_FRAMESIZE_RAW);
else
BZ2_bzBuffToBuffCompress(Zbuf, (unsigned int*)&size, cdbuffer, CD_FRAMESIZE_RAW * 10, 1, 0, 30);
fwrite(&c, 1, 4, t); fwrite(&c, 1, 4, t);
if (Zmode == 1) fwrite(&size, 1, 2, t); if (Zmode == 1) fwrite(&size, 1, 2, t);
@ -731,7 +799,8 @@ void OnCreateZ() {
count += CD_FRAMESIZE_RAW * blocks; count += CD_FRAMESIZE_RAW * blocks;
printf("reading %2d:%2d:%2d ", param[0], param[1], param[2]); 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); i = (count / 1024) / (time(NULL) - Ttime);
printf("( %5dKbytes/s, %dX)", i, i / 150); printf("( %5dKbytes/s, %dX)", i, i / 150);
} }
@ -741,8 +810,10 @@ void OnCreateZ() {
p++; p++;
per = ((float)p / s); per = ((float)p / s);
gtk_progress_bar_update(GTK_PROGRESS_BAR(Progress), per); 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);
@ -766,7 +837,8 @@ void OnCreateZ() {
if (!stop) SysMessageLoc("Compressed Iso Image Created OK"); if (!stop) SysMessageLoc("Compressed Iso Image Created OK");
} }
long CDRconfigure(void) { long CDRconfigure(void)
{
int i; int i;
LoadConf(); LoadConf();
@ -802,12 +874,14 @@ long CDRconfigure(void) {
GtkWidget *AboutDlg; GtkWidget *AboutDlg;
void OnAboutOk(GtkMenuItem * menuitem, gpointer userdata) { void OnAboutOk(GtkMenuItem * menuitem, gpointer userdata)
{
gtk_widget_hide(AboutDlg); gtk_widget_hide(AboutDlg);
gtk_main_quit(); gtk_main_quit();
} }
void CDRabout(void) { void CDRabout(void)
{
GtkWidget *Label; GtkWidget *Label;
GtkWidget *Ok; GtkWidget *Ok;
GtkWidget *Box, *BBox; GtkWidget *Box, *BBox;
@ -844,20 +918,22 @@ void CDRabout(void) {
gtk_main(); gtk_main();
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[])
{
if (argc < 2) return 0; if (argc < 2) return 0;
gtk_init(NULL, NULL); gtk_init(NULL, NULL);
if (!strcmp(argv[1], "open")) { if (!strcmp(argv[1], "open"))
_CDRopen(); _CDRopen();
} else if (!strcmp(argv[1], "configure")) { else if (!strcmp(argv[1], "configure"))
CDRconfigure(); CDRconfigure();
} else if (!strcmp(argv[1], "message")) { else if (!strcmp(argv[1], "message"))
{
if (argc > 2) SysMessageLoc(argv[2]); if (argc > 2) SysMessageLoc(argv[2]);
} else {
CDRabout();
} }
else
CDRabout();
return 0; return 0;
} }

View File

@ -16,7 +16,8 @@
#define SetKeyVdw(name, var) \ #define SetKeyVdw(name, var) \
SetKeyV(name, var, 4, REG_DWORD); SetKeyV(name, var, 4, REG_DWORD);
void SaveConf() { void SaveConf()
{
HKEY myKey; HKEY myKey;
DWORD myDisp; DWORD myDisp;
@ -29,14 +30,17 @@ void SaveConf() {
RegCloseKey(myKey); RegCloseKey(myKey);
} }
void LoadConf() { void LoadConf()
{
HKEY myKey; HKEY myKey;
DWORD type, size; DWORD type, size;
memset(IsoFile, 0, sizeof(IsoFile)); 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; {
SaveConf();
return;
} }
GetKeyV("IsoFile", IsoFile, sizeof(IsoFile), REG_BINARY); GetKeyV("IsoFile", IsoFile, sizeof(IsoFile), REG_BINARY);

View File

@ -25,7 +25,8 @@ HWND hMethod;
HWND hBlockDump; HWND hBlockDump;
int stop; int stop;
void SysMessage(char *fmt, ...) { void SysMessage(char *fmt, ...)
{
va_list list; va_list list;
char tmp[512]; char tmp[512];
@ -35,7 +36,8 @@ void SysMessage(char *fmt, ...) {
MessageBox(0, tmp, "CDVDiso Msg", 0); MessageBox(0, tmp, "CDVDiso Msg", 0);
} }
int _GetFile(char *out) { int _GetFile(char *out)
{
OPENFILENAME ofn; OPENFILENAME ofn;
char szFileName[MAXFILENAME]; char szFileName[MAXFILENAME];
char szFileTitle[MAXFILENAME]; char szFileTitle[MAXFILENAME];
@ -74,7 +76,8 @@ int _GetFile(char *out) {
return 0; return 0;
} }
int _OpenFile( int saveConf ) { int _OpenFile(int saveConf)
{
int retval = 0; int retval = 0;
@ -106,29 +109,37 @@ int _OpenFile( int saveConf ) {
return retval; return retval;
} }
void CfgOpenFile() { void CfgOpenFile()
{
_OpenFile(TRUE); _OpenFile(TRUE);
} }
void UpdZmode() { void UpdZmode()
if (ComboBox_GetCurSel(hMethod) == 0) { {
if (ComboBox_GetCurSel(hMethod) == 0)
{
Zmode = 1; Zmode = 1;
} else { }
else
{
Zmode = 2; Zmode = 2;
} }
} }
void SysUpdate() { void SysUpdate()
{
MSG msg; MSG msg;
while (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { while (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
{
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessage(&msg); DispatchMessage(&msg);
} }
} }
void OnCompress() { void OnCompress()
{
u32 lsn; u32 lsn;
u8 cdbuff[10*2352]; u8 cdbuff[10*2352];
char Zfile[256]; char Zfile[256];
@ -139,17 +150,23 @@ void OnCompress() {
Edit_GetText(hIsoFile, IsoFile, 256); Edit_GetText(hIsoFile, IsoFile, 256);
UpdZmode(); UpdZmode();
if (Zmode == 1) { if (Zmode == 1)
{
sprintf(Zfile, "%s.Z2", IsoFile); sprintf(Zfile, "%s.Z2", IsoFile);
} else { }
else
{
sprintf(Zfile, "%s.BZ2", IsoFile); sprintf(Zfile, "%s.BZ2", IsoFile);
} }
src = isoOpen(IsoFile); src = isoOpen(IsoFile);
if (src == NULL) return; if (src == NULL) return;
if (Zmode == 1) { if (Zmode == 1)
{
dst = isoCreate(Zfile, ISOFLAGS_Z2); dst = isoCreate(Zfile, ISOFLAGS_Z2);
} else { }
else
{
dst = isoCreate(Zfile, ISOFLAGS_BZ2); dst = isoCreate(Zfile, ISOFLAGS_BZ2);
} }
if (dst == NULL) return; if (dst == NULL) return;
@ -159,7 +176,8 @@ void OnCompress() {
Button_Enable(GetDlgItem(hDlg, IDC_DECOMPRESSISO), FALSE); Button_Enable(GetDlgItem(hDlg, IDC_DECOMPRESSISO), FALSE);
stop = 0; stop = 0;
for (lsn = 0; lsn<src->blocks; lsn++) { for (lsn = 0; lsn < src->blocks; lsn++)
{
printf("block %d ", lsn); printf("block %d ", lsn);
putchar(13); putchar(13);
fflush(stdout); fflush(stdout);
@ -180,16 +198,21 @@ void OnCompress() {
Button_Enable(GetDlgItem(hDlg, IDC_COMPRESSISO), TRUE); Button_Enable(GetDlgItem(hDlg, IDC_COMPRESSISO), TRUE);
Button_Enable(GetDlgItem(hDlg, IDC_DECOMPRESSISO), TRUE); Button_Enable(GetDlgItem(hDlg, IDC_DECOMPRESSISO), TRUE);
if (!stop) { if (!stop)
if (ret == -1) { {
if (ret == -1)
{
SysMessage("Error compressing iso image"); SysMessage("Error compressing iso image");
} else { }
else
{
SysMessage("Iso image compressed OK"); SysMessage("Iso image compressed OK");
} }
} }
} }
void OnDecompress() { void OnDecompress()
{
char file[256]; char file[256];
u8 cdbuff[10*2352]; u8 cdbuff[10*2352];
u32 lsn; u32 lsn;
@ -203,15 +226,22 @@ void OnDecompress() {
if (src == NULL) return; if (src == NULL) return;
strcpy(file, IsoFile); strcpy(file, IsoFile);
if (src->flags & ISOFLAGS_Z) { if (src->flags & ISOFLAGS_Z)
{
file[strlen(file) - 2] = 0; file[strlen(file) - 2] = 0;
} else }
if (src->flags & ISOFLAGS_Z2) { else
if (src->flags & ISOFLAGS_Z2)
{
file[strlen(file) - 3] = 0; file[strlen(file) - 3] = 0;
} else }
if (src->flags & ISOFLAGS_BZ2) { else
if (src->flags & ISOFLAGS_BZ2)
{
file[strlen(file) - 3] = 0; file[strlen(file) - 3] = 0;
} else { }
else
{
SysMessage("%s is not a compressed image", IsoFile); SysMessage("%s is not a compressed image", IsoFile);
return; return;
} }
@ -224,7 +254,8 @@ void OnDecompress() {
Button_Enable(GetDlgItem(hDlg, IDC_DECOMPRESSISO), FALSE); Button_Enable(GetDlgItem(hDlg, IDC_DECOMPRESSISO), FALSE);
stop = 0; stop = 0;
for (lsn = 0; lsn<src->blocks; lsn++) { for (lsn = 0; lsn < src->blocks; lsn++)
{
printf("block %d ", lsn); printf("block %d ", lsn);
putchar(13); putchar(13);
fflush(stdout); fflush(stdout);
@ -245,19 +276,25 @@ void OnDecompress() {
Button_Enable(GetDlgItem(hDlg, IDC_COMPRESSISO), TRUE); Button_Enable(GetDlgItem(hDlg, IDC_COMPRESSISO), TRUE);
Button_Enable(GetDlgItem(hDlg, IDC_DECOMPRESSISO), TRUE); Button_Enable(GetDlgItem(hDlg, IDC_DECOMPRESSISO), TRUE);
if (!stop) { if (!stop)
if (ret == -1) { {
if (ret == -1)
{
SysMessage("Error decompressing iso image"); SysMessage("Error decompressing iso image");
} else { }
else
{
SysMessage("Iso image decompressed OK"); SysMessage("Iso image decompressed OK");
} }
} }
} }
BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int i; int i;
switch(uMsg) { switch (uMsg)
{
case WM_INITDIALOG: case WM_INITDIALOG:
hDlg = hW; hDlg = hW;
LoadConf(); LoadConf();
@ -267,7 +304,8 @@ BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
hMethod = GetDlgItem(hW, IDC_METHOD); hMethod = GetDlgItem(hW, IDC_METHOD);
hBlockDump = GetDlgItem(hW, IDC_BLOCKDUMP); hBlockDump = GetDlgItem(hW, IDC_BLOCKDUMP);
for (i=0; methods[i] != NULL; i++) { for (i = 0; methods[i] != NULL; i++)
{
ComboBox_AddString(hMethod, methods[i]); ComboBox_AddString(hMethod, methods[i]);
} }
@ -281,7 +319,8 @@ BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
return TRUE; return TRUE;
case WM_COMMAND: case WM_COMMAND:
switch(LOWORD(wParam)) { switch (LOWORD(wParam))
{
case IDC_SELECTISO: case IDC_SELECTISO:
if (_OpenFile(FALSE) == 1) if (_OpenFile(FALSE) == 1)
Edit_SetText(hIsoFile, IsoFile); Edit_SetText(hIsoFile, IsoFile);
@ -315,20 +354,24 @@ BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
return FALSE; return FALSE;
} }
EXPORT_C(void) CDVDconfigure() { EXPORT_C(void) CDVDconfigure()
{
DialogBox(hInst, DialogBox(hInst,
MAKEINTRESOURCE(IDD_CONFIG), MAKEINTRESOURCE(IDD_CONFIG),
GetActiveWindow(), GetActiveWindow(),
(DLGPROC)ConfigureDlgProc); (DLGPROC)ConfigureDlgProc);
} }
BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
switch(uMsg) { {
switch (uMsg)
{
case WM_INITDIALOG: case WM_INITDIALOG:
return TRUE; return TRUE;
case WM_COMMAND: case WM_COMMAND:
switch(LOWORD(wParam)) { switch (LOWORD(wParam))
{
case IDOK: case IDOK:
EndDialog(hW, TRUE); EndDialog(hW, TRUE);
return FALSE; return FALSE;
@ -337,7 +380,8 @@ BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) {
return FALSE; return FALSE;
} }
EXPORT_C(void) CDVDabout() { EXPORT_C(void) CDVDabout()
{
DialogBox(hInst, DialogBox(hInst,
MAKEINTRESOURCE(IDD_ABOUT), MAKEINTRESOURCE(IDD_ABOUT),
GetActiveWindow(), GetActiveWindow(),
@ -346,7 +390,8 @@ EXPORT_C(void) CDVDabout() {
BOOL APIENTRY DllMain(HANDLE hModule, // DLL INIT BOOL APIENTRY DllMain(HANDLE hModule, // DLL INIT
DWORD dwReason, DWORD dwReason,
LPVOID lpReserved) { LPVOID lpReserved)
{
hInst = (HINSTANCE)hModule; hInst = (HINSTANCE)hModule;
return TRUE; // very quick :) return TRUE; // very quick :)
} }

View File

@ -15,7 +15,6 @@
#include "3rdparty/zlib/zlib.h" #include "3rdparty/zlib/zlib.h"
#include "3rdparty/bzip2/bzlib.h" #include "3rdparty/bzip2/bzlib.h"
#include "common/PS2Etypes.h"
#include "CDVDiso.h" #include "CDVDiso.h"
#include "libiso.h" #include "libiso.h"
@ -102,22 +101,27 @@ struct cdVolDesc
#ifdef _WIN32 #ifdef _WIN32
void *_openfile(const char *filename, int flags) { void *_openfile(const char *filename, int flags)
{
HANDLE handle; HANDLE handle;
// printf("_openfile %s, %d\n", filename, flags & O_RDONLY); // printf("_openfile %s, %d\n", filename, flags & O_RDONLY);
if (flags & O_WRONLY) { if (flags & O_WRONLY)
{
int _flags = CREATE_NEW; 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); handle = CreateFile(filename, GENERIC_WRITE, 0, NULL, _flags, 0, NULL);
} else { }
else
{
handle = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); handle = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
} }
return handle == INVALID_HANDLE_VALUE ? NULL : handle; return handle == INVALID_HANDLE_VALUE ? NULL : handle;
} }
u64 _tellfile(void *handle) { u64 _tellfile(void *handle)
{
u64 ofs; u64 ofs;
PLONG _ofs = (LONG*) & ofs; PLONG _ofs = (LONG*) & ofs;
_ofs[1] = 0; _ofs[1] = 0;
@ -125,19 +129,24 @@ u64 _tellfile(void *handle) {
return ofs; return ofs;
} }
int _seekfile(void *handle, u64 offset, int whence) { int _seekfile(void *handle, u64 offset, int whence)
{
u64 ofs = (u64)offset; u64 ofs = (u64)offset;
PLONG _ofs = (LONG*) & ofs; PLONG _ofs = (LONG*) & ofs;
// printf("_seekfile %p, %d_%d\n", handle, _ofs[1], _ofs[0]); // 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); SetFilePointer(handle, _ofs[0], &_ofs[1], FILE_BEGIN);
} else { }
else
{
SetFilePointer(handle, _ofs[0], &_ofs[1], FILE_END); SetFilePointer(handle, _ofs[0], &_ofs[1], FILE_END);
} }
return 0; return 0;
} }
int _readfile(void *handle, void *dst, int size) { int _readfile(void *handle, void *dst, int size)
{
DWORD ret; DWORD ret;
// printf("_readfile %p %d\n", handle, size); // printf("_readfile %p %d\n", handle, size);
@ -146,7 +155,8 @@ int _readfile(void *handle, void *dst, int size) {
return ret; return ret;
} }
int _writefile(void *handle, void *src, int size) { int _writefile(void *handle, void *src, int size)
{
DWORD ret; DWORD ret;
// printf("_writefile %p, %d\n", handle, size); // printf("_writefile %p, %d\n", handle, size);
@ -156,34 +166,34 @@ int _writefile(void *handle, void *src, int size) {
return ret; return ret;
} }
void _closefile(void *handle) { void _closefile(void *handle)
{
CloseHandle(handle); CloseHandle(handle);
} }
#else #else
void *_openfile(const char *filename, int flags) { void *_openfile(const char *filename, int flags)
{
printf("_openfile %s %x\n", filename, flags); printf("_openfile %s %x\n", filename, flags);
#ifdef _WIN32
if (flags & O_WRONLY) if (flags & O_WRONLY)
return fopen64(filename, "wb"); return fopen64(filename, "wb");
else return fopen64(filename, "rb"); else
#else return fopen64(filename, "rb");
if (flags & O_WRONLY)
return fopen64(filename, "wb");
else return fopen64(filename, "rb");
#endif
} }
#include <errno.h> #include <errno.h>
u64 _tellfile(void *handle) { u64 _tellfile(void *handle)
{
u64 cursize = ftell(handle); u64 cursize = ftell(handle);
if(cursize == -1 ) { if (cursize == -1)
{
// try 64bit // try 64bit
cursize = ftello64(handle); cursize = ftello64(handle);
if( cursize < -1 ) { if (cursize < -1)
{
// zero top 32 bits // zero top 32 bits
cursize &= 0xffffffff; cursize &= 0xffffffff;
} }
@ -191,52 +201,61 @@ u64 _tellfile(void *handle) {
return cursize; return cursize;
} }
int _seekfile(void *handle, u64 offset, int whence) { int _seekfile(void *handle, u64 offset, int whence)
{
int seekerr = fseeko64(handle, offset, whence); int seekerr = fseeko64(handle, offset, whence);
if( seekerr == -1 )
printf("failed to seek\n"); if (seekerr == -1) printf("failed to seek\n");
return seekerr; return seekerr;
} }
int _readfile(void *handle, void *dst, int size) { int _readfile(void *handle, void *dst, int size)
{
return fread(dst, 1, size, handle); return fread(dst, 1, size, handle);
} }
int _writefile(void *handle, void *src, int size) { int _writefile(void *handle, void *src, int size)
{
return fwrite(src, 1, size, handle); return fwrite(src, 1, size, handle);
} }
void _closefile(void *handle) { void _closefile(void *handle)
{
fclose(handle); fclose(handle);
} }
#endif #endif
int detect(isoFile *iso) { int detect(isoFile *iso)
{
u8 buf[2448]; u8 buf[2448];
struct cdVolDesc *volDesc; struct cdVolDesc *volDesc;
if (isoReadBlock(iso, buf, 16) == -1) return -1; if (isoReadBlock(iso, buf, 16) == -1) return -1;
volDesc = (struct cdVolDesc *)(buf + 24); 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) { if (volDesc->rootToc.tocSize == 2048)
iso->type = ISOTYPE_CD; iso->type = ISOTYPE_CD;
} else { else
iso->type = ISOTYPE_DVD; iso->type = ISOTYPE_DVD;
}
return 1; return 1;
} }
int _isoReadZtable(isoFile *iso) { int _isoReadZtable(isoFile *iso)
{
void *handle; void *handle;
char table[256]; char table[256];
int size; int size;
sprintf(table, "%s.table", iso->filename); sprintf(table, "%s.table", iso->filename);
handle = _openfile(table, O_RDONLY); handle = _openfile(table, O_RDONLY);
if (handle == NULL) { if (handle == NULL)
{
printf("Error loading %s\n", table); printf("Error loading %s\n", table);
return -1; return -1;
} }
@ -244,7 +263,9 @@ int _isoReadZtable(isoFile *iso) {
_seekfile(handle, 0, SEEK_END); _seekfile(handle, 0, SEEK_END);
size = _tellfile(handle); size = _tellfile(handle);
iso->Ztable = (char*)malloc(size); iso->Ztable = (char*)malloc(size);
if (iso->Ztable == NULL) {
if (iso->Ztable == NULL)
{
return -1; return -1;
} }
@ -257,7 +278,8 @@ int _isoReadZtable(isoFile *iso) {
return 0; return 0;
} }
int _isoReadZ2table(isoFile *iso) { int _isoReadZ2table(isoFile *iso)
{
void *handle; void *handle;
char table[256]; char table[256];
u32 *Ztable; u32 *Ztable;
@ -267,7 +289,9 @@ int _isoReadZ2table(isoFile *iso) {
sprintf(table, "%s.table", iso->filename); sprintf(table, "%s.table", iso->filename);
handle = _openfile(table, O_RDONLY); handle = _openfile(table, O_RDONLY);
if (handle == NULL) {
if (handle == NULL)
{
printf("Error loading %s\n", table); printf("Error loading %s\n", table);
return -1; return -1;
} }
@ -275,7 +299,9 @@ int _isoReadZ2table(isoFile *iso) {
_seekfile(handle, 0, SEEK_END); _seekfile(handle, 0, SEEK_END);
size = _tellfile(handle); size = _tellfile(handle);
Ztable = (u32*)malloc(size); Ztable = (u32*)malloc(size);
if (Ztable == NULL) {
if (Ztable == NULL)
{
return -1; return -1;
} }
@ -284,22 +310,28 @@ int _isoReadZ2table(isoFile *iso) {
_closefile(handle); _closefile(handle);
iso->Ztable = (char*)malloc(iso->blocks * 8); iso->Ztable = (char*)malloc(iso->blocks * 8);
if (iso->Ztable == NULL) {
if (iso->Ztable == NULL)
{
return -1; return -1;
} }
ofs = 16; 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+0] = ofs;
*(u32*)&iso->Ztable[i*8+4] = Ztable[i]; *(u32*)&iso->Ztable[i*8+4] = Ztable[i];
ofs += Ztable[i]; ofs += Ztable[i];
} }
free(Ztable); free(Ztable);
return 0; return 0;
} }
int _isoReadBZ2table(isoFile *iso) { int _isoReadBZ2table(isoFile *iso)
{
void *handle; void *handle;
char table[256]; char table[256];
u32 *Ztable; u32 *Ztable;
@ -309,7 +341,8 @@ int _isoReadBZ2table(isoFile *iso) {
sprintf(table, "%s.table", iso->filename); sprintf(table, "%s.table", iso->filename);
handle = _openfile(table, O_RDONLY); handle = _openfile(table, O_RDONLY);
if (handle == NULL) { if (handle == NULL)
{
printf("Error loading %s\n", table); printf("Error loading %s\n", table);
return -1; return -1;
} }
@ -317,36 +350,38 @@ int _isoReadBZ2table(isoFile *iso) {
_seekfile(handle, 0, SEEK_END); _seekfile(handle, 0, SEEK_END);
size = _tellfile(handle); size = _tellfile(handle);
Ztable = (u32*)malloc(size); Ztable = (u32*)malloc(size);
if (Ztable == NULL) { if (Ztable == NULL) return -1;
return -1;
}
_seekfile(handle, 0, SEEK_SET); _seekfile(handle, 0, SEEK_SET);
_readfile(handle, Ztable, size); _readfile(handle, Ztable, size);
_closefile(handle); _closefile(handle);
iso->Ztable = (char*)malloc(iso->blocks * 8); iso->Ztable = (char*)malloc(iso->blocks * 8);
if (iso->Ztable == NULL) { if (iso->Ztable == NULL) return -1;
return -1;
}
ofs = 16; 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+0] = ofs;
*(u32*)&iso->Ztable[i*8+4] = Ztable[i]; *(u32*)&iso->Ztable[i*8+4] = Ztable[i];
ofs += 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+0] = ofs;
*(u32*)&iso->Ztable[i*8+4] = Ztable[i]; *(u32*)&iso->Ztable[i*8+4] = Ztable[i];
ofs += Ztable[i]; ofs += Ztable[i];
} }
free(Ztable); free(Ztable);
return 0; return 0;
} }
int _isoReadDtable(isoFile *iso) { int _isoReadDtable(isoFile *iso)
{
int ret; int ret;
int i; int i;
@ -354,26 +389,28 @@ int _isoReadDtable(isoFile *iso) {
iso->dtablesize = (_tellfile(iso->handle) - 16) / (iso->blocksize + 4); 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++) { for (i = 0; i < iso->dtablesize; i++)
{
_seekfile(iso->handle, 16 + (iso->blocksize + 4)*i, SEEK_SET); _seekfile(iso->handle, 16 + (iso->blocksize + 4)*i, SEEK_SET);
ret = _readfile(iso->handle, &iso->dtable[i], 4); ret = _readfile(iso->handle, &iso->dtable[i], 4);
if (ret < 4) { if (ret < 4) return -1;
return -1;
}
} }
return 0; return 0;
} }
int isoDetect(isoFile *iso) { // based on florin's CDVDbin detection code :) int isoDetect(isoFile *iso) // based on florin's CDVDbin detection code :)
{
char buf[32]; char buf[32];
int len; int len;
iso->type = ISOTYPE_ILLEGAL; iso->type = ISOTYPE_ILLEGAL;
len = strlen(iso->filename); len = strlen(iso->filename);
if (len >= 2) { if (len >= 2)
if (!strncmp(iso->filename+(len-2), ".Z", 2)) { {
if (!strncmp(iso->filename + (len - 2), ".Z", 2))
{
iso->flags = ISOFLAGS_Z; iso->flags = ISOFLAGS_Z;
iso->blocksize = 2352; iso->blocksize = 2352;
_isoReadZtable(iso); _isoReadZtable(iso);
@ -383,23 +420,27 @@ int isoDetect(isoFile *iso) { // based on florin's CDVDbin detection code :)
_seekfile(iso->handle, 0, SEEK_SET); _seekfile(iso->handle, 0, SEEK_SET);
_readfile(iso->handle, buf, 4); _readfile(iso->handle, buf, 4);
if (strncmp(buf, "BDV2", 4) == 0) {
if (strncmp(buf, "BDV2", 4) == 0)
{
iso->flags = ISOFLAGS_BLOCKDUMP; iso->flags = ISOFLAGS_BLOCKDUMP;
_readfile(iso->handle, &iso->blocksize, 4); _readfile(iso->handle, &iso->blocksize, 4);
_readfile(iso->handle, &iso->blocks, 4); _readfile(iso->handle, &iso->blocks, 4);
_readfile(iso->handle, &iso->blockofs, 4); _readfile(iso->handle, &iso->blockofs, 4);
_isoReadDtable(iso); _isoReadDtable(iso);
return detect(iso) == 1 ? 0 : -1; 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; iso->flags = ISOFLAGS_Z2;
_readfile(iso->handle, &iso->blocksize, 4); _readfile(iso->handle, &iso->blocksize, 4);
_readfile(iso->handle, &iso->blocks, 4); _readfile(iso->handle, &iso->blocks, 4);
_readfile(iso->handle, &iso->blockofs, 4); _readfile(iso->handle, &iso->blockofs, 4);
_isoReadZ2table(iso); _isoReadZ2table(iso);
return detect(iso) == 1 ? 0 : -1; return detect(iso) == 1 ? 0 : -1;
} else }
if (strncmp(buf, "BZV2", 4) == 0) { else if (strncmp(buf, "BZV2", 4) == 0)
{
iso->flags = ISOFLAGS_BZ2; iso->flags = ISOFLAGS_BZ2;
_readfile(iso->handle, &iso->blocksize, 4); _readfile(iso->handle, &iso->blocksize, 4);
_readfile(iso->handle, &iso->blocks, 4); _readfile(iso->handle, &iso->blocks, 4);
@ -409,48 +450,70 @@ int isoDetect(isoFile *iso) { // based on florin's CDVDbin detection code :)
if (iso->buffer == NULL) return -1; if (iso->buffer == NULL) return -1;
_isoReadBZ2table(iso); _isoReadBZ2table(iso);
return detect(iso) == 1 ? 0 : -1; return detect(iso) == 1 ? 0 : -1;
} else { }
else
{
iso->blocks = 16; iso->blocks = 16;
} }
// ISO 2048 // ISO 2048
iso->blocksize = 2048; iso->offset = 0; iso->blockofs = 24; iso->blocksize = 2048;
iso->offset = 0;
iso->blockofs = 24;
if (detect(iso) == 1) return 0; if (detect(iso) == 1) return 0;
// RAW 2336 // RAW 2336
iso->blocksize = 2336; iso->offset = 0; iso->blockofs = 16; iso->blocksize = 2336;
iso->offset = 0;
iso->blockofs = 16;
if (detect(iso) == 1) return 0; if (detect(iso) == 1) return 0;
// RAW 2352 // RAW 2352
iso->blocksize = 2352; iso->offset = 0; iso->blockofs = 0; iso->blocksize = 2352;
iso->offset = 0;
iso->blockofs = 0;
if (detect(iso) == 1) return 0; if (detect(iso) == 1) return 0;
// RAWQ 2448 // RAWQ 2448
iso->blocksize = 2448; iso->offset = 0; iso->blockofs = 0; iso->blocksize = 2448;
iso->offset = 0;
iso->blockofs = 0;
if (detect(iso) == 1) return 0; if (detect(iso) == 1) return 0;
// NERO ISO 2048 // NERO ISO 2048
iso->blocksize = 2048; iso->offset = 150*2048; iso->blockofs = 24; 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 // NERO RAW 2352
iso->blocksize = 2352; iso->offset = 150*2048; iso->blockofs = 0; 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 // NERO RAWQ 2448
iso->blocksize = 2448; iso->offset = 150*2048; iso->blockofs = 0; 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 2048
iso->blocksize = 2048; iso->offset = -8; iso->blockofs = 24; iso->blocksize = 2048;
iso->offset = -8;
iso->blockofs = 24;
if (detect(iso) == 1) return 0; if (detect(iso) == 1) return 0;
// RAW 2352 // RAW 2352
iso->blocksize = 2352; iso->offset = -8; iso->blockofs = 0; iso->blocksize = 2352;
iso->offset = -8;
iso->blockofs = 0;
if (detect(iso) == 1) return 0; if (detect(iso) == 1) return 0;
// RAWQ 2448 // RAWQ 2448
iso->blocksize = 2448; iso->offset = -8; iso->blockofs = 0; 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->offset = 0;
@ -461,7 +524,8 @@ int isoDetect(isoFile *iso) { // based on florin's CDVDbin detection code :)
return -1; return -1;
} }
isoFile *isoOpen(const char *filename) { isoFile *isoOpen(const char *filename)
{
isoFile *iso; isoFile *iso;
int i; int i;
@ -472,8 +536,9 @@ isoFile *isoOpen(const char *filename) {
strcpy(iso->filename, filename); strcpy(iso->filename, filename);
iso->handle = _openfile(iso->filename, O_RDONLY); iso->handle = _openfile(iso->filename, O_RDONLY);
if (iso->handle == NULL) { if (iso->handle == NULL)
printf("Errorr loading %s\n", iso->filename); {
printf("Error loading %s\n", iso->filename);
return NULL; return NULL;
} }
@ -481,15 +546,17 @@ isoFile *isoOpen(const char *filename) {
printf("detected blocksize = %d\n", iso->blocksize); printf("detected blocksize = %d\n", iso->blocksize);
if (strlen(iso->filename) > 3 && if (strlen(iso->filename) > 3 && strncmp(iso->filename + (strlen(iso->filename) - 3), "I00", 3) == 0)
strncmp(iso->filename + (strlen(iso->filename) - 3), "I00", 3) == 0) { {
_closefile(iso->handle); _closefile(iso->handle);
iso->flags |= ISOFLAGS_MULTI; iso->flags |= ISOFLAGS_MULTI;
iso->blocks = 0; iso->blocks = 0;
for (i=0; i<8; i++) { for (i = 0; i < 8; i++)
{
iso->filename[strlen(iso->filename) - 1] = '0' + i; iso->filename[strlen(iso->filename) - 1] = '0' + i;
iso->multih[i].handle = _openfile(iso->filename, O_RDONLY); iso->multih[i].handle = _openfile(iso->filename, O_RDONLY);
if (iso->multih[i].handle == NULL) { if (iso->multih[i].handle == NULL)
{
break; break;
} }
iso->multih[i].slsn = iso->blocks; iso->multih[i].slsn = iso->blocks;
@ -499,12 +566,14 @@ isoFile *isoOpen(const char *filename) {
iso->multih[i].elsn = iso->blocks - 1; iso->multih[i].elsn = iso->blocks - 1;
} }
if (i == 0) { if (i == 0)
{
return NULL; return NULL;
} }
} }
if (iso->flags == 0) { if (iso->flags == 0)
{
_seekfile(iso->handle, 0, SEEK_END); _seekfile(iso->handle, 0, SEEK_END);
iso->blocks = (u32)((_tellfile(iso->handle) - iso->offset) / iso->blocks = (u32)((_tellfile(iso->handle) - iso->offset) /
(iso->blocksize)); (iso->blocksize));
@ -521,7 +590,8 @@ isoFile *isoOpen(const char *filename) {
return iso; return iso;
} }
isoFile *isoCreate(const char *filename, int flags) { isoFile *isoCreate(const char *filename, int flags)
{
isoFile *iso; isoFile *iso;
char Zfile[256]; char Zfile[256];
@ -536,16 +606,19 @@ isoFile *isoCreate(const char *filename, int flags) {
iso->blocksize = CD_FRAMESIZE_RAW; iso->blocksize = CD_FRAMESIZE_RAW;
iso->blocksize = 2048; 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); sprintf(Zfile, "%s.table", iso->filename);
iso->htable = _openfile(Zfile, O_WRONLY); iso->htable = _openfile(Zfile, O_WRONLY);
if (iso->htable == NULL) { if (iso->htable == NULL)
{
return NULL; return NULL;
} }
} }
iso->handle = _openfile(iso->filename, O_WRONLY | O_CREAT); iso->handle = _openfile(iso->filename, O_WRONLY | O_CREAT);
if (iso->handle == NULL) { if (iso->handle == NULL)
{
printf("Error loading %s\n", iso->filename); printf("Error loading %s\n", iso->filename);
return NULL; return NULL;
} }
@ -555,20 +628,23 @@ isoFile *isoCreate(const char *filename, int flags) {
return iso; return iso;
} }
int isoSetFormat(isoFile *iso, int blockofs, int blocksize, int blocks) { int isoSetFormat(isoFile *iso, int blockofs, int blocksize, int blocks)
{
iso->blocksize = blocksize; iso->blocksize = blocksize;
iso->blocks = blocks; iso->blocks = blocks;
iso->blockofs = blockofs; iso->blockofs = blockofs;
printf("blockofs = %d\n", iso->blockofs); printf("blockofs = %d\n", iso->blockofs);
printf("blocksize = %d\n", iso->blocksize); printf("blocksize = %d\n", iso->blocksize);
printf("blocks = %d\n", iso->blocks); printf("blocks = %d\n", iso->blocks);
if (iso->flags & ISOFLAGS_Z2) { if (iso->flags & ISOFLAGS_Z2)
{
if (_writefile(iso->handle, "Z V2", 4) < 4) return -1; if (_writefile(iso->handle, "Z V2", 4) < 4) return -1;
if (_writefile(iso->handle, &blocksize, 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, &blocks, 4) < 4) return -1;
if (_writefile(iso->handle, &blockofs, 4) < 4) return -1; if (_writefile(iso->handle, &blockofs, 4) < 4) return -1;
} }
if (iso->flags & ISOFLAGS_BZ2) { if (iso->flags & ISOFLAGS_BZ2)
{
if (_writefile(iso->handle, "BZV2", 4) < 4) return -1; if (_writefile(iso->handle, "BZV2", 4) < 4) return -1;
if (_writefile(iso->handle, &blocksize, 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, &blocks, 4) < 4) return -1;
@ -577,7 +653,8 @@ int isoSetFormat(isoFile *iso, int blockofs, int blocksize, int blocks) {
iso->buffer = (u8*)malloc(iso->blocksize * 16); 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 (iso->flags & ISOFLAGS_BLOCKDUMP)
{
if (_writefile(iso->handle, "BDV2", 4) < 4) return -1; if (_writefile(iso->handle, "BDV2", 4) < 4) return -1;
if (_writefile(iso->handle, &blocksize, 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, &blocks, 4) < 4) return -1;
@ -587,7 +664,8 @@ int isoSetFormat(isoFile *iso, int blockofs, int blocksize, int blocks) {
return 0; return 0;
} }
s32 MSFtoLSN(u8 *Time) { s32 MSFtoLSN(u8 *Time)
{
u32 lsn; u32 lsn;
lsn = Time[2]; lsn = Time[2];
@ -596,7 +674,8 @@ s32 MSFtoLSN(u8 *Time) {
return lsn; return lsn;
} }
void LSNtoMSF(u8 *Time, s32 lsn) { void LSNtoMSF(u8 *Time, s32 lsn)
{
u8 m, s, f; u8 m, s, f;
lsn += 150; lsn += 150;
@ -604,10 +683,13 @@ void LSNtoMSF(u8 *Time, s32 lsn) {
lsn = lsn - m * 4500; // minuten rest lsn = lsn - m * 4500; // minuten rest
s = lsn / 75; // sekunden s = lsn / 75; // sekunden
f = lsn - (s * 75); // sekunden rest f = lsn - (s * 75); // sekunden rest
Time[0] = itob(m); Time[1] = itob(s); Time[2] = itob(f); Time[0] = itob(m);
Time[1] = itob(s);
Time[2] = itob(f);
} }
int _isoReadBlock(isoFile *iso, u8 *dst, int lsn) { int _isoReadBlock(isoFile *iso, u8 *dst, int lsn)
{
u64 ofs = (u64)lsn * iso->blocksize + iso->offset; u64 ofs = (u64)lsn * iso->blocksize + iso->offset;
int ret; int ret;
@ -615,7 +697,8 @@ int _isoReadBlock(isoFile *iso, u8 *dst, int lsn) {
memset(dst, 0, iso->blockofs); memset(dst, 0, iso->blockofs);
_seekfile(iso->handle, ofs, SEEK_SET); _seekfile(iso->handle, ofs, SEEK_SET);
ret = _readfile(iso->handle, dst + iso->blockofs, iso->blocksize); ret = _readfile(iso->handle, dst + iso->blockofs, iso->blocksize);
if (ret < iso->blocksize) { if (ret < iso->blocksize)
{
printf("read error %d\n", ret); printf("read error %d\n", ret);
return -1; return -1;
} }
@ -623,7 +706,8 @@ int _isoReadBlock(isoFile *iso, u8 *dst, int lsn) {
return 0; return 0;
} }
int _isoReadBlockZ(isoFile *iso, u8 *dst, int lsn) { int _isoReadBlockZ(isoFile *iso, u8 *dst, int lsn)
{
u32 pos, p; u32 pos, p;
uLongf size; uLongf size;
u8 Zbuf[CD_FRAMESIZE_RAW*2]; u8 Zbuf[CD_FRAMESIZE_RAW*2];
@ -635,7 +719,8 @@ int _isoReadBlockZ(isoFile *iso, u8 *dst, int lsn) {
// printf("%d, %d\n", pos, p); // printf("%d, %d\n", pos, p);
_seekfile(iso->handle, pos, SEEK_SET); _seekfile(iso->handle, pos, SEEK_SET);
ret = _readfile(iso->handle, Zbuf, p); ret = _readfile(iso->handle, Zbuf, p);
if (ret < p) { if (ret < p)
{
printf("error reading block!!\n"); printf("error reading block!!\n");
return -1; return -1;
} }
@ -646,7 +731,8 @@ int _isoReadBlockZ(isoFile *iso, u8 *dst, int lsn) {
return 0; return 0;
} }
int _isoReadBlockZ2(isoFile *iso, u8 *dst, int lsn) { int _isoReadBlockZ2(isoFile *iso, u8 *dst, int lsn)
{
u32 pos, p; u32 pos, p;
uLongf size; uLongf size;
u8 Zbuf[16*1024]; u8 Zbuf[16*1024];
@ -658,7 +744,8 @@ int _isoReadBlockZ2(isoFile *iso, u8 *dst, int lsn) {
// printf("%d, %d\n", pos, p); // printf("%d, %d\n", pos, p);
_seekfile(iso->handle, pos, SEEK_SET); _seekfile(iso->handle, pos, SEEK_SET);
ret = _readfile(iso->handle, Zbuf, p); ret = _readfile(iso->handle, Zbuf, p);
if (ret < p) { if (ret < p)
{
printf("error reading block!!\n"); printf("error reading block!!\n");
return -1; return -1;
} }
@ -669,13 +756,15 @@ int _isoReadBlockZ2(isoFile *iso, u8 *dst, int lsn) {
return 0; return 0;
} }
int _isoReadBlockBZ2(isoFile *iso, u8 *dst, int lsn) { int _isoReadBlockBZ2(isoFile *iso, u8 *dst, int lsn)
{
u32 pos, p; u32 pos, p;
u32 size; u32 size;
u8 Zbuf[64*1024]; u8 Zbuf[64*1024];
int ret; int ret;
if ((lsn/16) == iso->buflsn) { if ((lsn / 16) == iso->buflsn)
{
memset(dst, 0, iso->blockofs); 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; return 0;
@ -688,14 +777,18 @@ int _isoReadBlockBZ2(isoFile *iso, u8 *dst, int lsn) {
// printf("%d, %d\n", pos, p); // printf("%d, %d\n", pos, p);
_seekfile(iso->handle, pos, SEEK_SET); _seekfile(iso->handle, pos, SEEK_SET);
ret = _readfile(iso->handle, Zbuf, p); ret = _readfile(iso->handle, Zbuf, p);
if (ret < p) {
if (ret < p)
{
printf("error reading block!!\n"); printf("error reading block!!\n");
return -1; return -1;
} }
size = iso->blocksize * 64; 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("_isoReadBlockBZ2 %d, %d\n", lsn, iso->blocksize);
printf("%d, %d\n", pos, p); printf("%d, %d\n", pos, p);
printf("error on BZ2: %d\n", ret); printf("error on BZ2: %d\n", ret);
@ -707,13 +800,15 @@ int _isoReadBlockBZ2(isoFile *iso, u8 *dst, int lsn) {
return 0; return 0;
} }
int _isoReadBlockD(isoFile *iso, u8 *dst, int lsn) { int _isoReadBlockD(isoFile *iso, u8 *dst, int lsn)
{
int ret; int ret;
int i; 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); memset(dst, 0, iso->blockofs);
for (i=0; i<iso->dtablesize;i++) { for (i = 0; i < iso->dtablesize;i++)
{
if (iso->dtable[i] != lsn) continue; 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);
@ -727,14 +822,17 @@ int _isoReadBlockD(isoFile *iso, u8 *dst, int lsn) {
return -1; return -1;
} }
int _isoReadBlockM(isoFile *iso, u8 *dst, int lsn) { int _isoReadBlockM(isoFile *iso, u8 *dst, int lsn)
{
u64 ofs; u64 ofs;
int ret; int ret;
int i; int i;
for (i=0; i<8; i++) { for (i = 0; i < 8; i++)
{
if (lsn >= iso->multih[i].slsn && if (lsn >= iso->multih[i].slsn &&
lsn <= iso->multih[i].elsn) { lsn <= iso->multih[i].elsn)
{
break; break;
} }
} }
@ -745,7 +843,9 @@ int _isoReadBlockM(isoFile *iso, u8 *dst, int lsn) {
memset(dst, 0, iso->blockofs); memset(dst, 0, iso->blockofs);
_seekfile(iso->multih[i].handle, ofs, SEEK_SET); _seekfile(iso->multih[i].handle, ofs, SEEK_SET);
ret = _readfile(iso->multih[i].handle, dst + iso->blockofs, iso->blocksize); 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); printf("read error %d\n", ret);
return -1; return -1;
} }
@ -753,32 +853,33 @@ int _isoReadBlockM(isoFile *iso, u8 *dst, int lsn) {
return 0; return 0;
} }
int isoReadBlock(isoFile *iso, u8 *dst, int lsn) { int isoReadBlock(isoFile *iso, u8 *dst, int lsn)
{
int ret; int ret;
if (lsn > iso->blocks) { if (lsn > iso->blocks)
{
printf("isoReadBlock: %d > %d\n", lsn, iso->blocks); printf("isoReadBlock: %d > %d\n", lsn, iso->blocks);
return -1; return -1;
} }
if (iso->flags & ISOFLAGS_Z) {
if (iso->flags & ISOFLAGS_Z)
ret = _isoReadBlockZ(iso, dst, lsn); ret = _isoReadBlockZ(iso, dst, lsn);
} else else if (iso->flags & ISOFLAGS_Z2)
if (iso->flags & ISOFLAGS_Z2) {
ret = _isoReadBlockZ2(iso, dst, lsn); ret = _isoReadBlockZ2(iso, dst, lsn);
} else else if (iso->flags & ISOFLAGS_BLOCKDUMP)
if (iso->flags & ISOFLAGS_BLOCKDUMP) {
ret = _isoReadBlockD(iso, dst, lsn); ret = _isoReadBlockD(iso, dst, lsn);
} else else if (iso->flags & ISOFLAGS_MULTI)
if (iso->flags & ISOFLAGS_MULTI) {
ret = _isoReadBlockM(iso, dst, lsn); ret = _isoReadBlockM(iso, dst, lsn);
} else else if (iso->flags & ISOFLAGS_BZ2)
if (iso->flags & ISOFLAGS_BZ2) {
ret = _isoReadBlockBZ2(iso, dst, lsn); ret = _isoReadBlockBZ2(iso, dst, lsn);
} else else
ret = _isoReadBlock(iso, dst, lsn); 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); LSNtoMSF(dst + 12, lsn);
dst[15] = 2; dst[15] = 2;
} }
@ -787,7 +888,8 @@ int isoReadBlock(isoFile *iso, u8 *dst, int lsn) {
} }
int _isoWriteBlock(isoFile *iso, u8 *src, int lsn) { int _isoWriteBlock(isoFile *iso, u8 *src, int lsn)
{
u64 ofs = (u64)lsn * iso->blocksize + iso->offset; u64 ofs = (u64)lsn * iso->blocksize + iso->offset;
int ret; int ret;
@ -800,7 +902,8 @@ int _isoWriteBlock(isoFile *iso, u8 *src, int lsn) {
return 0; return 0;
} }
int _isoWriteBlockZ(isoFile *iso, u8 *src, int lsn) { int _isoWriteBlockZ(isoFile *iso, u8 *src, int lsn)
{
u32 pos; u32 pos;
uLongf size; uLongf size;
u8 Zbuf[CD_FRAMESIZE_RAW]; u8 Zbuf[CD_FRAMESIZE_RAW];
@ -819,7 +922,8 @@ int _isoWriteBlockZ(isoFile *iso, u8 *src, int lsn) {
ret = _writefile(iso->handle, Zbuf, size); 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"); printf("error writing block!!\n");
return -1; return -1;
} }
@ -827,7 +931,8 @@ int _isoWriteBlockZ(isoFile *iso, u8 *src, int lsn) {
return 0; return 0;
} }
int _isoWriteBlockZ2(isoFile *iso, u8 *src, int lsn) { int _isoWriteBlockZ2(isoFile *iso, u8 *src, int lsn)
{
uLongf size; uLongf size;
u8 Zbuf[1024*16]; u8 Zbuf[1024*16];
int ret; int ret;
@ -841,7 +946,8 @@ int _isoWriteBlockZ2(isoFile *iso, u8 *src, int lsn) {
if (ret < 4) return -1; if (ret < 4) return -1;
ret = _writefile(iso->handle, Zbuf, size); 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"); printf("error writing block!!\n");
return -1; return -1;
} }
@ -849,7 +955,8 @@ int _isoWriteBlockZ2(isoFile *iso, u8 *src, int lsn) {
return 0; return 0;
} }
int _isoWriteBlockD(isoFile *iso, u8 *src, int lsn) { int _isoWriteBlockD(isoFile *iso, u8 *src, int lsn)
{
int ret; int ret;
// printf("_isoWriteBlock %d (ofs=%d)\n", iso->blocksize, ofs); // printf("_isoWriteBlock %d (ofs=%d)\n", iso->blocksize, ofs);
@ -862,7 +969,8 @@ int _isoWriteBlockD(isoFile *iso, u8 *src, int lsn) {
return 0; return 0;
} }
int _isoWriteBlockBZ2(isoFile *iso, u8 *src, int lsn) { int _isoWriteBlockBZ2(isoFile *iso, u8 *src, int lsn)
{
u32 size; u32 size;
u8 Zbuf[64*1024]; u8 Zbuf[64*1024];
int blocks; int blocks;
@ -870,9 +978,12 @@ int _isoWriteBlockBZ2(isoFile *iso, u8 *src, int lsn) {
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; blocks = (lsn & 0xf) + 1;
} else { }
else
{
blocks = 16; blocks = 16;
if ((lsn & 0xf) != 0xf) return 0; if ((lsn & 0xf) != 0xf) return 0;
} }
@ -880,16 +991,21 @@ int _isoWriteBlockBZ2(isoFile *iso, u8 *src, int lsn) {
// printf("_isoWriteBlockBZ2 %d\n", iso->blocksize); // printf("_isoWriteBlockBZ2 %d\n", iso->blocksize);
size = 64 * 1024; 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("error on BZ2: %d\n", ret);
} }
// printf("_isoWriteBlockBZ2 %d\n", size); // printf("_isoWriteBlockBZ2 %d\n", size);
ret = _writefile(iso->htable, (u8*) & size, 4); ret = _writefile(iso->htable, (u8*) & size, 4);
if (ret < 4) return -1; if (ret < 4) return -1;
ret = _writefile(iso->handle, Zbuf, size); 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"); printf("error writing block!!\n");
return -1; return -1;
} }
@ -897,37 +1013,31 @@ int _isoWriteBlockBZ2(isoFile *iso, u8 *src, int lsn) {
return 0; return 0;
} }
int isoWriteBlock(isoFile *iso, u8 *src, int lsn) { int isoWriteBlock(isoFile *iso, u8 *src, int lsn)
{
int ret; int ret;
if (iso->flags & ISOFLAGS_Z) { if (iso->flags & ISOFLAGS_Z)
ret = _isoWriteBlockZ(iso, src, lsn); ret = _isoWriteBlockZ(iso, src, lsn);
} else else if (iso->flags & ISOFLAGS_Z2)
if (iso->flags & ISOFLAGS_Z2) {
ret = _isoWriteBlockZ2(iso, src, lsn); ret = _isoWriteBlockZ2(iso, src, lsn);
} else else if (iso->flags & ISOFLAGS_BLOCKDUMP)
if (iso->flags & ISOFLAGS_BLOCKDUMP) {
ret = _isoWriteBlockD(iso, src, lsn); ret = _isoWriteBlockD(iso, src, lsn);
} else else if (iso->flags & ISOFLAGS_BZ2)
if (iso->flags & ISOFLAGS_BZ2) {
ret = _isoWriteBlockBZ2(iso, src, lsn); ret = _isoWriteBlockBZ2(iso, src, lsn);
} else else
ret = _isoWriteBlock(iso, src, lsn); ret = _isoWriteBlock(iso, src, lsn);
if (ret == -1) return ret;
if (ret == -1) return ret;
return 0; return 0;
} }
void isoClose(isoFile *iso) { void isoClose(isoFile *iso)
if (iso->handle) { {
_closefile(iso->handle); if (iso->handle) _closefile(iso->handle);
} if (iso->htable) _closefile(iso->htable);
if (iso->htable) { if (iso->buffer) free(iso->buffer);
_closefile(iso->htable);
}
if (iso->buffer) {
free(iso->buffer);
}
free(iso); free(iso);
} }

View File

@ -22,13 +22,15 @@
#define itob(i) ((i)/10*16 + (i)%10) /* u_char to BCD */ #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 btoi(b) ((b)/16*10 + (b)%16) /* BCD to u_char */
typedef struct { typedef struct
{
u32 slsn; u32 slsn;
u32 elsn; u32 elsn;
void *handle; void *handle;
} _multih; } _multih;
typedef struct { typedef struct
{
char filename[256]; char filename[256];
u32 type; u32 type;
u32 flags; u32 flags;

View File

@ -24,7 +24,8 @@
#include "CDVDiso.h" #include "CDVDiso.h"
void Compress(char *filename, int mode) { void Compress(char *filename, int mode)
{
struct stat buf; struct stat buf;
u32 lsn; u32 lsn;
u8 cdbuff[1024*16]; u8 cdbuff[1024*16];
@ -33,13 +34,17 @@ void Compress(char *filename, int mode) {
isoFile *src; isoFile *src;
isoFile *dst; isoFile *dst;
if (mode == 1) { if (mode == 1)
{
sprintf(Zfile, "%s.Z2", filename); sprintf(Zfile, "%s.Z2", filename);
} else { }
else
{
sprintf(Zfile, "%s.BZ2", filename); sprintf(Zfile, "%s.BZ2", filename);
} }
if (stat(Zfile, &buf) != -1) { if (stat(Zfile, &buf) != -1)
{
printf("'%s' already exists\n", Zfile); printf("'%s' already exists\n", Zfile);
return; return;
/* sprintf(str, "'%s' already exists, overwrite?", Zfile); /* sprintf(str, "'%s' already exists, overwrite?", Zfile);
@ -52,15 +57,19 @@ void Compress(char *filename, int mode) {
src = isoOpen(filename); src = isoOpen(filename);
if (src == NULL) return; if (src == NULL) return;
if (mode == 1) { if (mode == 1)
{
dst = isoCreate(Zfile, ISOFLAGS_Z2); dst = isoCreate(Zfile, ISOFLAGS_Z2);
} else { }
else
{
dst = isoCreate(Zfile, ISOFLAGS_BZ2); dst = isoCreate(Zfile, ISOFLAGS_BZ2);
} }
isoSetFormat(dst, src->blockofs, src->blocksize, src->blocks); 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); printf("block %d ", lsn);
putchar(13); putchar(13);
fflush(stdout); fflush(stdout);
@ -72,14 +81,18 @@ void Compress(char *filename, int mode) {
isoClose(src); isoClose(src);
isoClose(dst); isoClose(dst);
if (ret == -1) { if (ret == -1)
{
printf("Error compressing iso image\n"); printf("Error compressing iso image\n");
} else { }
else
{
printf("Iso image compressed OK\n"); printf("Iso image compressed OK\n");
} }
} }
void Decompress(char *filename) { void Decompress(char *filename)
{
struct stat buf; struct stat buf;
char file[256]; char file[256];
u8 cdbuff[10*2352]; u8 cdbuff[10*2352];
@ -92,19 +105,20 @@ void Decompress(char *filename) {
if (src == NULL) return; if (src == NULL) return;
strcpy(file, filename); strcpy(file, filename);
if (src->flags & ISOFLAGS_Z) { if (src->flags & ISOFLAGS_Z)
file[strlen(file) - 2] = 0; file[strlen(file) - 2] = 0;
} else else if (src->flags & ISOFLAGS_Z2)
if (src->flags & ISOFLAGS_Z2) {
file[strlen(file) - 3] = 0; file[strlen(file) - 3] = 0;
} else else if (src->flags & ISOFLAGS_BZ2)
if (src->flags & ISOFLAGS_BZ2) {
file[strlen(file) - 3] = 0; file[strlen(file) - 3] = 0;
} else { else
{
printf("%s is not a compressed image\n", filename); printf("%s is not a compressed image\n", filename);
return; return;
} }
if (stat(file, &buf) != -1) {
if (stat(file, &buf) != -1)
{
char str[256]; char str[256];
sprintf(str, "'%s' already exists", file); sprintf(str, "'%s' already exists", file);
isoClose(src); isoClose(src);
@ -115,7 +129,8 @@ void Decompress(char *filename) {
if (dst == NULL) return; if (dst == NULL) return;
isoSetFormat(dst, src->blockofs, src->blocksize, src->blocks); 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); printf("block %d ", lsn);
putchar(13); putchar(13);
fflush(stdout); fflush(stdout);
@ -128,25 +143,23 @@ void Decompress(char *filename) {
isoClose(src); isoClose(src);
isoClose(dst); isoClose(dst);
if (ret == -1) { if (ret == -1)
printf("Error decompressing iso image\n"); printf("Error decompressing iso image\n");
} else { else
printf("Iso image decompressed OK\n"); printf("Iso image decompressed OK\n");
} }
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[])
{
if (argc < 3) return 0; if (argc < 3) return 0;
if (argv[1][0] == 'c') { switch (argv[1][0])
Compress(argv[2], 1); {
} else case 'c': Compress(argv[2], 1);
if (argv[1][0] == 'C') { case 'C': Compress(argv[2], 2);
Compress(argv[2], 2); case 'd': Decompress(argv[2]);
} else default: break;
if (argv[1][0] == 'd') {
Decompress(argv[2]);
} }
return 0; return 0;