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)
#endif
#include "PS2Edefs.h"
#include "common/PS2Etypes.h"
#include "common/PS2Edefs.h"
#include "libiso.h"
#ifdef __cplusplus
@ -82,7 +83,8 @@ void __Log(char *fmt, ...);
#define DEV_DEF ""
#define CDDEV_DEF "/dev/cdrom"
typedef struct {
typedef struct
{
int slsn;
int elsn;
#ifdef _WINDOWS_

View File

@ -38,9 +38,10 @@ FILE *cdvdLog = NULL;
// This var is used to detect resume-style behavior of the Pcsx2 emulator,
// 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",
".BZ - compress better",
NULL
@ -58,43 +59,48 @@ const unsigned char build = 8;
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;
lsn = f;
lsn+=(s - 2) * 75;
lsn+= m * 75 * 60;
lsn += (s - 2) * 75;
lsn += m * 75 * 60;
return lsn;
}
void lba_to_msf(s32 lba, u8* m, u8* s, u8* f) {
void lba_to_msf(s32 lba, u8* m, u8* s, u8* f)
{
lba += 150;
*m = lba / (60*75);
*m = lba / (60 * 75);
*s = (lba / 75) % 60;
*f = lba % 75;
}
#define btoi(b) ((b)/16*10 + (b)%16) /* BCD to u_char */
#define btoi(b) ((b)/16*10 + (b)%16) /* BCD to u_char */
#define itob(i) ((i)/10*16 + (i)%10) /* u_char to BCD */
EXPORT_C(char*) PS2EgetLibName() {
EXPORT_C(char*) PS2EgetLibName()
{
return LibName;
}
EXPORT_C(u32) PS2EgetLibType() {
EXPORT_C(u32) PS2EgetLibType()
{
return PS2E_LT_CDVD;
}
EXPORT_C(u32) PS2EgetLibVersion2(u32 type) {
EXPORT_C(u32) PS2EgetLibVersion2(u32 type)
{
return (version << 16) | (revision << 8) | build;
}
#ifdef _DEBUG
void __Log(char *fmt, ...) {
void __Log(char *fmt, ...)
{
va_list list;
if( cdvdLog == NULL )
return;
if (cdvdLog == NULL) return;
va_start(list, fmt);
vfprintf(cdvdLog, fmt, list);
@ -105,13 +111,17 @@ void __Log(char *fmt, ...) {
#endif
EXPORT_C(s32) CDVDinit() {
EXPORT_C(s32) CDVDinit()
{
#ifdef _DEBUG
cdvdLog = fopen("logs/cdvdLog.txt", "w");
if (cdvdLog == NULL) {
if (cdvdLog == NULL)
{
cdvdLog = fopen("cdvdLog.txt", "w");
if (cdvdLog == NULL) {
SysMessage("Can't create cdvdLog.txt"); return -1;
if (cdvdLog == NULL)
{
SysMessage("Can't create cdvdLog.txt");
return -1;
}
}
setvbuf(cdvdLog, NULL, _IONBF, 0);
@ -123,26 +133,28 @@ 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 (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];
CfgOpenFile();
LoadConf();
strcpy(temp, IsoFile);
*IsoFile = 0;
@ -150,85 +162,90 @@ EXPORT_C(s32) CDVDopen(const char* pTitle) {
strcpy(IsoFile, temp);
}
iso = isoOpen(IsoFile);
if (iso == NULL) {
iso = isoOpen(IsoFile);
if (iso == NULL)
{
SysMessage("Error loading %s\n", IsoFile);
return -1;
}
if (iso->type == ISOTYPE_DVD) {
cdtype = CDVD_TYPE_PS2DVD;
} else
if (iso->type == ISOTYPE_AUDIO) {
cdtype = CDVD_TYPE_CDDA;
} else {
if (iso->type == ISOTYPE_DVD)
cdtype = CDVD_TYPE_PS2DVD;
else if (iso->type == ISOTYPE_AUDIO)
cdtype = CDVD_TYPE_CDDA;
else
cdtype = CDVD_TYPE_PS2CD;
}
if (BlockDump) {
if (BlockDump)
{
char fname_only[MAX_PATH];
char* p, *plast;
char* p, *plast;
#ifdef _WIN32
char fname[MAX_PATH],ext[MAX_PATH];
_splitpath(IsoFile,NULL,NULL,fname,ext);
_makepath(fname_only,NULL,NULL,fname,NULL);
char fname[MAX_PATH], ext[MAX_PATH];
_splitpath(IsoFile, NULL, NULL, fname, ext);
_makepath(fname_only, NULL, NULL, fname, NULL);
#else
plast = p = strchr(IsoFile, '/');
while(p != NULL) {
plast = p;
p = strchr(p+1, '/');
}
plast = p = strchr(IsoFile, '/');
while (p != NULL)
{
plast = p;
p = strchr(p + 1, '/');
}
if( plast != NULL ) strcpy(fname_only, plast+1);
else strcpy(fname_only, IsoFile);
if (plast != NULL)
strcpy(fname_only, plast + 1);
else
strcpy(fname_only, IsoFile);
plast = p = strchr(fname_only, '.');
while(p != NULL) {
plast = p;
p = strchr(p+1, '.');
}
plast = p = strchr(fname_only, '.');
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()
{
strcpy( cdvdCurrentIso, IsoFile );
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)
{
// fake it
u8 min, sec, frm;
subq->ctrl = 4;
subq->mode = 1;
subq->trackNum = itob(1);
subq->trackIndex= itob(1);
subq->trackIndex = itob(1);
lba_to_msf(lsn, &min, &sec, &frm);
subq->trackM = itob(min);
subq->trackS = itob(sec);
subq->trackF = itob(frm);
subq->pad = 0;
lba_to_msf(lsn + (2*75), &min, &sec, &frm);
subq->discM = itob(min);
subq->discS = itob(sec);
@ -236,17 +253,22 @@ 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;
return 0;
}
EXPORT_C(s32) CDVDgetTD(u8 Track, cdvdTD *Buffer) {
if (Track == 0) {
EXPORT_C(s32) CDVDgetTD(u8 Track, cdvdTD *Buffer)
{
if (Track == 0)
{
Buffer->lsn = iso->blocks;
} else {
}
else
{
Buffer->type = CDVD_MODE1_TRACK;
Buffer->lsn = 0;
}
@ -255,99 +277,101 @@ EXPORT_C(s32) CDVDgetTD(u8 Track, cdvdTD *Buffer) {
}
static int layer1start = -1;
EXPORT_C(s32) CDVDgetTOC(void* toc) {
EXPORT_C(s32) CDVDgetTOC(void* toc)
{
u8 type = CDVDgetDiskType();
u8* tocBuff = (u8*)toc;
//__Log("CDVDgetTOC\n");
if( type == CDVD_TYPE_DVDV || type == CDVD_TYPE_PS2DVD)
//__Log("CDVDgetTOC\n");
if (type == CDVD_TYPE_DVDV || type == CDVD_TYPE_PS2DVD)
{
int i;
int i;
// get dvd structure format
// scsi command 0x43
memset(tocBuff, 0, 2048);
if( layer1start != -2 && iso->blocks >= 0x300000 ) {
int off = iso->blockofs;
u8* tempbuffer;
if (layer1start != -2 && iso->blocks >= 0x300000)
{
int off = iso->blockofs;
u8* tempbuffer;
// dual sided
tocBuff[ 0] = 0x24;
tocBuff[ 1] = 0x02;
tocBuff[ 2] = 0xF2;
tocBuff[ 3] = 0x00;
tocBuff[ 4] = 0x41;
tocBuff[ 5] = 0x95;
// dual sided
tocBuff[ 0] = 0x24;
tocBuff[ 1] = 0x02;
tocBuff[ 2] = 0xF2;
tocBuff[ 3] = 0x00;
tocBuff[ 4] = 0x41;
tocBuff[ 5] = 0x95;
tocBuff[14] = 0x60; // dual sided, ptp
tocBuff[14] = 0x60; // dual sided, ptp
tocBuff[16] = 0x00;
tocBuff[17] = 0x03;
tocBuff[18] = 0x00;
tocBuff[19] = 0x00;
tocBuff[16] = 0x00;
tocBuff[17] = 0x03;
tocBuff[18] = 0x00;
tocBuff[19] = 0x00;
// search for it
if( layer1start == -1 ) {
printf("CDVD: searching for layer1...");
tempbuffer = (u8*)malloc(CD_FRAMESIZE_RAW * 10);
for(layer1start = (iso->blocks/2-0x10)&~0xf; layer1start < 0x200010; layer1start += 16) {
isoReadBlock(iso, tempbuffer, layer1start);
// CD001
if( tempbuffer[off+1] == 0x43 && tempbuffer[off+2] == 0x44 && tempbuffer[off+3] == 0x30 && tempbuffer[off+4] == 0x30 && tempbuffer[off+5] == 0x31 ) {
break;
}
}
free(tempbuffer);
// search for it
if (layer1start == -1)
{
printf("CDVD: searching for layer1...");
tempbuffer = (u8*)malloc(CD_FRAMESIZE_RAW * 10);
for (layer1start = (iso->blocks / 2 - 0x10) & ~0xf; layer1start < 0x200010; layer1start += 16)
{
isoReadBlock(iso, tempbuffer, layer1start);
// CD001
if (tempbuffer[off+1] == 0x43 && tempbuffer[off+2] == 0x44 && tempbuffer[off+3] == 0x30 && tempbuffer[off+4] == 0x30 && tempbuffer[off+5] == 0x31)
break;
}
free(tempbuffer);
if( layer1start == 0x200010 ) {
printf("Couldn't find second layer on dual layer... ignoring\n");
// fake it
tocBuff[ 0] = 0x04;
tocBuff[ 1] = 0x02;
tocBuff[ 2] = 0xF2;
tocBuff[ 3] = 0x00;
tocBuff[ 4] = 0x86;
tocBuff[ 5] = 0x72;
if (layer1start == 0x200010)
{
printf("Couldn't find second layer on dual layer... ignoring\n");
// fake it
tocBuff[ 0] = 0x04;
tocBuff[ 1] = 0x02;
tocBuff[ 2] = 0xF2;
tocBuff[ 3] = 0x00;
tocBuff[ 4] = 0x86;
tocBuff[ 5] = 0x72;
tocBuff[16] = 0x00;
tocBuff[17] = 0x03;
tocBuff[18] = 0x00;
tocBuff[19] = 0x00;
layer1start = -2;
return 0;
}
tocBuff[16] = 0x00;
tocBuff[17] = 0x03;
tocBuff[18] = 0x00;
tocBuff[19] = 0x00;
layer1start = -2;
return 0;
}
printf("found at 0x%8.8x\n", layer1start);
layer1start = layer1start+0x30000-1;
}
printf("found at 0x%8.8x\n", layer1start);
layer1start = layer1start + 0x30000 - 1;
}
tocBuff[20] = layer1start>>24;
tocBuff[21] = (layer1start>>16)&0xff;
tocBuff[22] = (layer1start>>8)&0xff;
tocBuff[23] = (layer1start>>0)&0xff;
}
else {
// fake it
tocBuff[ 0] = 0x04;
tocBuff[ 1] = 0x02;
tocBuff[ 2] = 0xF2;
tocBuff[ 3] = 0x00;
tocBuff[ 4] = 0x86;
tocBuff[ 5] = 0x72;
tocBuff[20] = layer1start >> 24;
tocBuff[21] = (layer1start >> 16) & 0xff;
tocBuff[22] = (layer1start >> 8) & 0xff;
tocBuff[23] = (layer1start >> 0) & 0xff;
}
else
{
// fake it
tocBuff[ 0] = 0x04;
tocBuff[ 1] = 0x02;
tocBuff[ 2] = 0xF2;
tocBuff[ 3] = 0x00;
tocBuff[ 4] = 0x86;
tocBuff[ 5] = 0x72;
tocBuff[16] = 0x00;
tocBuff[17] = 0x03;
tocBuff[18] = 0x00;
tocBuff[19] = 0x00;
}
tocBuff[16] = 0x00;
tocBuff[17] = 0x03;
tocBuff[18] = 0x00;
tocBuff[19] = 0x00;
}
}
else if(type == CDVD_TYPE_CDDA ||
type == CDVD_TYPE_PS2CDDA ||
type == CDVD_TYPE_PS2CD ||
type == CDVD_TYPE_PSCDDA ||
type == CDVD_TYPE_PSCD)
else if ((type == CDVD_TYPE_CDDA) || (type == CDVD_TYPE_PS2CDDA) ||
(type == CDVD_TYPE_PS2CD) || (type == CDVD_TYPE_PSCDDA) || (type == CDVD_TYPE_PSCD))
{
// cd toc
// (could be replaced by 1 command that reads the full toc)
@ -356,16 +380,20 @@ EXPORT_C(s32) CDVDgetTOC(void* toc) {
cdvdTN diskInfo;
cdvdTD trackInfo;
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;
tocBuff[0] = 0x41;
tocBuff[1] = 0x00;
//Number of FirstTrack
tocBuff[2] = 0xA0;
tocBuff[7] = itob(diskInfo.strack);
//Number of LastTrack
tocBuff[12] = 0xA1;
tocBuff[17] = itob(diskInfo.etrack);
@ -375,8 +403,8 @@ EXPORT_C(s32) CDVDgetTOC(void* toc) {
tocBuff[22] = 0xA2;
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);
@ -389,59 +417,75 @@ EXPORT_C(s32) CDVDgetTOC(void* toc) {
}
else
return -1;
return 0;
}
EXPORT_C(s32) CDVDreadTrack(u32 lsn, int mode) {
EXPORT_C(s32) CDVDreadTrack(u32 lsn, int mode)
{
int _lsn = lsn;
//__Log("CDVDreadTrack: %x %x\n", lsn, mode);
if (_lsn < 0) {
//__Log("CDVDreadTrack: %x %x\n", lsn, mode);
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) {
case CDVD_MODE_2352: break;
case CDVD_MODE_2340: pbuffer+= 12; break;
case CDVD_MODE_2328: pbuffer+= 24; break;
case CDVD_MODE_2048: pbuffer+= 24; break;
switch (mode)
{
case CDVD_MODE_2352:
break;
case CDVD_MODE_2340:
pbuffer += 12;
break;
case CDVD_MODE_2328:
pbuffer += 24;
break;
case CDVD_MODE_2048:
pbuffer += 24;
break;
}
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() {
if (*IsoFile == 0)
return 0;
EXPORT_C(s32) CDVDtest()
{
if (*IsoFile == 0) return 0;
iso = isoOpen(IsoFile);
if (iso == NULL) return -1;

View File

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

View File

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

View File

@ -44,7 +44,8 @@ extern const unsigned char build;
GtkWidget *FileSel;
void OnFile_Ok() {
void OnFile_Ok()
{
gchar *File;
gtk_widget_hide(FileSel);
@ -53,24 +54,26 @@ void OnFile_Ok() {
gtk_main_quit();
}
void OnFile_Cancel() {
void OnFile_Cancel()
{
gtk_widget_hide(FileSel);
gtk_main_quit();
}
void _CDRopen() {
void _CDRopen()
{
GtkWidget *Ok, *Cancel;
FileSel = gtk_file_selection_new("Select Iso File");
Ok = GTK_FILE_SELECTION(FileSel)->ok_button;
gtk_signal_connect(GTK_OBJECT(Ok), "clicked",
GTK_SIGNAL_FUNC(OnFile_Ok), NULL);
GTK_SIGNAL_FUNC(OnFile_Ok), NULL);
gtk_widget_show(Ok);
Cancel = GTK_FILE_SELECTION(FileSel)->cancel_button;
gtk_signal_connect(GTK_OBJECT(Cancel), "clicked",
GTK_SIGNAL_FUNC(OnFile_Cancel), NULL);
GTK_SIGNAL_FUNC(OnFile_Cancel), NULL);
gtk_widget_show(Cancel);
gtk_widget_show(FileSel);
@ -83,14 +86,16 @@ void _CDRopen() {
GtkWidget *MsgDlg;
void OnMsg_Ok() {
void OnMsg_Ok()
{
gtk_widget_destroy(MsgDlg);
gtk_main_quit();
}
static void SysMessageLoc(char *fmt, ...) {
GtkWidget *Ok,*Txt;
GtkWidget *Box,*Box1;
static void SysMessageLoc(char *fmt, ...)
{
GtkWidget *Ok, *Txt;
GtkWidget *Box, *Box1;
va_list list;
int w;
char msg[512];
@ -103,7 +108,7 @@ static void SysMessageLoc(char *fmt, ...) {
w = strlen(msg) * 6 + 20;
MsgDlg = gtk_window_new (GTK_WINDOW_TOPLEVEL);
MsgDlg = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_usize(MsgDlg, w, 70);
gtk_window_set_position(GTK_WINDOW(MsgDlg), GTK_WIN_POS_CENTER);
gtk_window_set_title(GTK_WINDOW(MsgDlg), "cdriso Msg");
@ -114,7 +119,7 @@ static void SysMessageLoc(char *fmt, ...) {
gtk_widget_show(Box);
Txt = gtk_label_new(msg);
gtk_box_pack_start(GTK_BOX(Box), Txt, FALSE, FALSE, 5);
gtk_widget_show(Txt);
@ -123,12 +128,12 @@ static void SysMessageLoc(char *fmt, ...) {
gtk_widget_show(Box1);
Ok = gtk_button_new_with_label("Ok");
gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnMsg_Ok), NULL);
gtk_signal_connect(GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnMsg_Ok), NULL);
gtk_container_add(GTK_CONTAINER(Box1), Ok);
GTK_WIDGET_SET_FLAGS(Ok, GTK_CAN_DEFAULT);
gtk_widget_show(Ok);
gtk_widget_show(MsgDlg);
gtk_widget_show(MsgDlg);
gtk_main();
}
@ -148,10 +153,11 @@ extern char *methods[];
int stop;
void OnOk(GtkMenuItem * menuitem, gpointer userdata) {
void OnOk(GtkMenuItem * menuitem, gpointer userdata)
{
char *tmp;
stop=1;
stop = 1;
tmp = gtk_entry_get_text(GTK_ENTRY(Edit));
strcpy(IsoFile, tmp);
tmp = gtk_entry_get_text(GTK_ENTRY(CdEdit));
@ -161,13 +167,15 @@ void OnOk(GtkMenuItem * menuitem, gpointer userdata) {
gtk_main_quit();
}
void OnCancel(GtkMenuItem * menuitem, gpointer userdata) {
stop=1;
void OnCancel(GtkMenuItem * menuitem, gpointer userdata)
{
stop = 1;
gtk_widget_destroy(ConfDlg);
gtk_main_quit();
}
void OnFileSel_Ok() {
void OnFileSel_Ok()
{
gchar *File;
File = gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSel));
@ -175,33 +183,37 @@ void OnFileSel_Ok() {
gtk_widget_destroy(FileSel);
}
void OnFileSel_Cancel() {
void OnFileSel_Cancel()
{
gtk_widget_destroy(FileSel);
}
void OnFileSel() {
GtkWidget *Ok,*Cancel;
void OnFileSel()
{
GtkWidget *Ok, *Cancel;
FileSel = gtk_file_selection_new("Select Psx Iso File");
gtk_file_selection_set_filename(GTK_FILE_SELECTION(FileSel), IsoFile);
Ok = GTK_FILE_SELECTION(FileSel)->ok_button;
gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnFileSel_Ok), NULL);
gtk_signal_connect(GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnFileSel_Ok), NULL);
gtk_widget_show(Ok);
Cancel = GTK_FILE_SELECTION(FileSel)->cancel_button;
gtk_signal_connect (GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(OnFileSel_Cancel), NULL);
gtk_signal_connect(GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(OnFileSel_Cancel), NULL);
gtk_widget_show(Cancel);
gtk_widget_show(FileSel);
gdk_window_raise(FileSel->window);
}
void OnStop() {
stop=1;
void OnStop()
{
stop = 1;
}
void UpdZmode() {
void UpdZmode()
{
char *tmp;
tmp = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(Method)->entry));
@ -211,7 +223,8 @@ void UpdZmode() {
char buffer[2352 * 10];
void OnCompress() {
void OnCompress()
{
struct stat buf;
u32 lsn;
u8 cdbuff[10*2352];
@ -228,13 +241,14 @@ void OnCompress() {
if (Zmode == 1) sprintf(Zfile, "%s.Z2", IsoFile);
if (Zmode == 2) sprintf(Zfile, "%s.BZ2", IsoFile);
if (stat(Zfile, &buf) != -1) {
char str[256];
if (stat(Zfile, &buf) != -1)
{
/*char str[256];*/
return;
/* sprintf(str, "'%s' already exists, overwrite?", Zfile);
if (MessageBox(hDlg, str, "Question", MB_YESNO) != IDYES) {
return;
}*/
/* sprintf(str, "'%s' already exists, overwrite?", Zfile);
if (MessageBox(hDlg, str, "Question", MB_YESNO) != IDYES) {
return;
}*/
}
src = isoOpen(IsoFile);
@ -246,9 +260,10 @@ void OnCompress() {
gtk_widget_set_sensitive(BtnDecompress, FALSE);
gtk_widget_set_sensitive(BtnCreate, 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);
putchar(13);
fflush(stdout);
@ -271,20 +286,25 @@ void OnCompress() {
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");
}
}
}
void OnDecompress() {
void OnDecompress()
{
#if 0
struct stat buf;
FILE *f;
unsigned long c=0, p=0, s;
unsigned long c = 0, p = 0, s;
char table[256];
char *tmp;
int blocks;
@ -299,7 +319,8 @@ void OnDecompress() {
if (Zmode == 1) strcat(table, ".table");
else strcat(table, ".index");
if (stat(table, &buf) == -1) {
if (stat(table, &buf) == -1)
{
return;
}
if (Zmode == 1) c = s = buf.st_size / 6;
@ -310,7 +331,8 @@ void OnDecompress() {
fclose(f);
cdHandle[0] = fopen(IsoFile, "rb");
if (cdHandle[0] == NULL) {
if (cdHandle[0] == NULL)
{
return;
}
@ -318,7 +340,8 @@ void OnDecompress() {
else IsoFile[strlen(IsoFile) - 3] = 0;
f = fopen(IsoFile, "wb");
if (f == NULL) {
if (f == NULL)
{
return;
}
@ -326,29 +349,36 @@ void OnDecompress() {
gtk_widget_set_sensitive(BtnDecompress, FALSE);
gtk_widget_set_sensitive(BtnCreate, FALSE);
gtk_widget_set_sensitive(BtnCreateZ, FALSE);
stop=0;
stop = 0;
if (Zmode == 1) {
if (Zmode == 1)
{
blocks = 1;
} else {
}
else
{
blocks = 10;
}
while (c--) {
while (c--)
{
unsigned long size, pos, ssize;
float per;
if (Zmode == 1) {
pos = *(unsigned long*)&Ztable[p * 6];
if (Zmode == 1)
{
pos = *(unsigned long*) & Ztable[p * 6];
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]);
} else {
pos = *(unsigned long*)&Ztable[p * 4];
}
else
{
pos = *(unsigned long*) & Ztable[p * 4];
fseek(cdHandle[0], pos, SEEK_SET);
ssize = *(unsigned long*)&Ztable[p * 4 + 4] - pos;
ssize = *(unsigned long*) & Ztable[p * 4 + 4] - pos;
fread(Zbuf, 1, ssize, cdHandle[0]);
}
@ -368,8 +398,10 @@ void OnDecompress() {
if (!stop) gtk_entry_set_text(GTK_ENTRY(Edit), IsoFile);
fclose(f);
fclose(cdHandle[0]); cdHandle[0] = NULL;
free(Ztable); Ztable = NULL;
fclose(cdHandle[0]);
cdHandle[0] = NULL;
free(Ztable);
Ztable = NULL;
gtk_widget_set_sensitive(BtnCompress, TRUE);
gtk_widget_set_sensitive(BtnDecompress, TRUE);
@ -384,28 +416,34 @@ void OnDecompress() {
unsigned char param[4];
int cddev = -1;
union {
union
{
struct cdrom_msf msf;
unsigned char buf[CD_FRAMESIZE_RAW];
} cr;
void incSector() {
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]++;
}
}
long CDR_open(void) {
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;
}
@ -413,7 +451,8 @@ long CDR_open(void) {
return 0;
}
long CDR_close(void) {
long CDR_close(void)
{
if (cddev == -1) return 0;
close(cddev);
cddev = -1;
@ -425,7 +464,8 @@ long CDR_close(void) {
// buffer:
// byte 0 - start track
// byte 1 - end track
long CDR_getTN(unsigned char *buffer) {
long CDR_getTN(unsigned char *buffer)
{
struct cdrom_tochdr toc;
if (ioctl(cddev, CDROMREADTOCHDR, &toc) == -1) return -1;
@ -441,7 +481,8 @@ long CDR_getTN(unsigned char *buffer) {
// byte 0 - frame
// byte 1 - second
// 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;
if (track == 0) track = 0xaa; // total time
@ -462,7 +503,8 @@ long CDR_getTD(unsigned char track, unsigned char *buffer) {
// byte 0 - minute
// byte 1 - second
// byte 2 - frame
char *CDR_readTrack(unsigned char *time) {
char *CDR_readTrack(unsigned char *time)
{
cr.msf.cdmsf_min0 = time[0];
cr.msf.cdmsf_sec0 = time[1];
cr.msf.cdmsf_frame0 = time[2];
@ -472,20 +514,21 @@ char *CDR_readTrack(unsigned char *time) {
}
void OnCreate() {
void OnCreate()
{
FILE *f;
struct stat buf;
struct tm *Tm;
time_t Ttime;
unsigned long ftrack, ltrack;
unsigned long p=0,s;
unsigned long p = 0, s;
unsigned char *buffer;
unsigned char bufferz[2352];
unsigned char start[4], end[4];
char *tmp;
#ifdef VERBOSE
unsigned long count = 0;
int i=0;
int i = 0;
#endif
memset(bufferz, 0, sizeof(bufferz));
@ -495,37 +538,42 @@ void OnCreate() {
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();
return;
}
f = fopen(IsoFile, "wb");
if (f == NULL) {
if (f == NULL)
{
CDR_close();
printf("Error opening %s", IsoFile);
return;
}
printf("Making Iso: from %2.2d:%2.2d:%2.2d to %2.2d:%2.2d:%2.2d\n",
start[0], start[1], start[2], end[0], end[1], end[2]);
start[0], start[1], start[2], end[0], end[1], end[2]);
memcpy(param, start, 3);
@ -538,20 +586,24 @@ void OnCreate() {
gtk_widget_set_sensitive(BtnCreate, FALSE);
gtk_widget_set_sensitive(BtnCreateZ, FALSE);
for (;;) { /* loop until end */
for (;;) /* loop until end */
{
float per;
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) {
if (buffer == NULL)
{
printf("Error Reading %2d:%2d:%2d\n", param[0], param[1], param[2]);
buffer = bufferz;
buffer[12] = param[0];
@ -562,10 +614,11 @@ void OnCreate() {
}
fwrite(buffer, 1, 2352, f);
#ifdef VERBOSE
count+= CD_FRAMESIZE_RAW;
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);
}
@ -585,7 +638,7 @@ void OnCreate() {
Ttime = time(NULL) - Ttime;
Tm = gmtime(&Ttime);
printf("\nTotal Time used: %d:%d:%d\n", Tm->tm_hour, Tm->tm_min,
Tm->tm_sec);
Tm->tm_sec);
CDR_close();
fclose(f);
@ -598,14 +651,15 @@ void OnCreate() {
if (!stop) SysMessageLoc("Iso Image Created OK");
}
void OnCreateZ() {
void OnCreateZ()
{
FILE *f;
FILE *t;
struct stat buf;
struct tm *Tm;
time_t Ttime;
unsigned long ftrack, ltrack;
unsigned long p=0,s,c=0;
unsigned long p = 0, s, c = 0;
unsigned char *buffer;
unsigned char bufferz[2352];
unsigned char start[4], end[4];
@ -614,7 +668,7 @@ void OnCreateZ() {
int b, blocks;
#ifdef VERBOSE
unsigned long count = 0;
int i=0;
int i = 0;
#endif
memset(bufferz, 0, sizeof(bufferz));
@ -626,53 +680,58 @@ void OnCreateZ() {
UpdZmode();
if (Zmode == 1) {
if (Zmode == 1)
{
blocks = 1;
if (strstr(IsoFile, ".Z") == NULL) strcat(IsoFile, ".Z");
} else {
}
else
{
blocks = 10;
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;
}
strcpy(table, IsoFile);
if (Zmode == 1) strcat(table, ".table");
else strcat(table, ".index");
if (Zmode == 1)
strcat(table, ".table");
else
strcat(table, ".index");
t = fopen(table, "wb");
if (t == NULL) {
return;
}
if (t == NULL) return;
if (CDR_open() == -1) return;
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();
return;
}
f = fopen(IsoFile, "wb");
if (f == NULL) {
if (f == NULL)
{
CDR_close();
printf("Error opening %s", IsoFile);
return;
}
printf("Making Iso: from %2.2d:%2.2d:%2.2d to %2.2d:%2.2d:%2.2d\n",
start[0], start[1], start[2], end[0], end[1], end[2]);
start[0], start[1], start[2], end[0], end[1], end[2]);
memcpy(param, start, 3);
@ -685,23 +744,30 @@ void OnCreateZ() {
gtk_widget_set_sensitive(BtnCreate, FALSE);
gtk_widget_set_sensitive(BtnCreateZ, FALSE);
for (;;) { /* loop until end */
for (;;) /* loop until end */
{
unsigned long size;
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) {
if (buffer == NULL)
{
printf("Error Reading %2d:%2d:%2d\n", param[0], param[1], param[2]);
buffer = bufferz;
buffer[12] = param[0];
@ -718,20 +784,23 @@ void OnCreateZ() {
break;
size = CD_FRAMESIZE_RAW * blocks * 2;
if (Zmode == 1) compress(Zbuf, &size, cdbuffer, CD_FRAMESIZE_RAW);
else BZ2_bzBuffToBuffCompress(Zbuf, (unsigned int*)&size, cdbuffer, CD_FRAMESIZE_RAW * 10, 1, 0, 30);
if (Zmode == 1)
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);
if (Zmode == 1) fwrite(&size, 1, 2, t);
fwrite(Zbuf, 1, size, f);
c+=size;
c += size;
#ifdef VERBOSE
count+= CD_FRAMESIZE_RAW * blocks;
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);
}
@ -741,8 +810,10 @@ void OnCreateZ() {
p++;
per = ((float)p / s);
gtk_progress_bar_update(GTK_PROGRESS_BAR(Progress), per);
while (gtk_events_pending()) gtk_main_iteration();
if (stop) break;
}
if (Zmode == 2) fwrite(&c, 1, 4, f);
@ -752,7 +823,7 @@ void OnCreateZ() {
Ttime = time(NULL) - Ttime;
Tm = gmtime(&Ttime);
printf("\nTotal Time used: %d:%d:%d\n", Tm->tm_hour, Tm->tm_min,
Tm->tm_sec);
Tm->tm_sec);
CDR_close();
fclose(f);
@ -766,7 +837,8 @@ void OnCreateZ() {
if (!stop) SysMessageLoc("Compressed Iso Image Created OK");
}
long CDRconfigure(void) {
long CDRconfigure(void)
{
int i;
LoadConf();
@ -786,12 +858,12 @@ long CDRconfigure(void) {
BtnCreateZ = lookup_widget(ConfDlg, "GtkButton_CreateZ");
methodlist = NULL;
for (i=0; i<2; i++)
for (i = 0; i < 2; i++)
methodlist = g_list_append(methodlist, methods[i]);
Method = lookup_widget(ConfDlg, "GtkCombo_Method");
gtk_combo_set_popdown_strings(GTK_COMBO(Method), methodlist);
if (strstr(IsoFile, ".Z") != NULL)
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(Method)->entry), methods[0]);
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(Method)->entry), methods[0]);
else gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(Method)->entry), methods[1]);
gtk_widget_show_all(ConfDlg);
@ -802,12 +874,14 @@ long CDRconfigure(void) {
GtkWidget *AboutDlg;
void OnAboutOk(GtkMenuItem * menuitem, gpointer userdata) {
void OnAboutOk(GtkMenuItem * menuitem, gpointer userdata)
{
gtk_widget_hide(AboutDlg);
gtk_main_quit();
}
void CDRabout(void) {
void CDRabout(void)
{
GtkWidget *Label;
GtkWidget *Ok;
GtkWidget *Box, *BBox;
@ -835,7 +909,7 @@ void CDRabout(void) {
Ok = gtk_button_new_with_label("Ok");
gtk_signal_connect(GTK_OBJECT(Ok), "clicked",
GTK_SIGNAL_FUNC(OnAboutOk), NULL);
GTK_SIGNAL_FUNC(OnAboutOk), NULL);
gtk_container_add(GTK_CONTAINER(BBox), Ok);
GTK_WIDGET_SET_FLAGS(Ok, GTK_CAN_DEFAULT);
gtk_widget_show(Ok);
@ -844,20 +918,22 @@ void CDRabout(void) {
gtk_main();
}
int main(int argc, char *argv[]) {
int main(int argc, char *argv[])
{
if (argc < 2) return 0;
gtk_init(NULL, NULL);
if (!strcmp(argv[1], "open")) {
if (!strcmp(argv[1], "open"))
_CDRopen();
} else if (!strcmp(argv[1], "configure")) {
else if (!strcmp(argv[1], "configure"))
CDRconfigure();
} else if (!strcmp(argv[1], "message")) {
else if (!strcmp(argv[1], "message"))
{
if (argc > 2) SysMessageLoc(argv[2]);
} else {
CDRabout();
}
else
CDRabout();
return 0;
}

View File

@ -16,7 +16,8 @@
#define SetKeyVdw(name, var) \
SetKeyV(name, var, 4, REG_DWORD);
void SaveConf() {
void SaveConf()
{
HKEY myKey;
DWORD myDisp;
@ -29,14 +30,17 @@ void SaveConf() {
RegCloseKey(myKey);
}
void LoadConf() {
void LoadConf()
{
HKEY myKey;
DWORD type, size;
memset(IsoFile, 0, sizeof(IsoFile));
if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\PS2Eplugin\\CDVD\\CDVDiso", 0, KEY_ALL_ACCESS, &myKey)!=ERROR_SUCCESS) {
SaveConf(); return;
if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\PS2Eplugin\\CDVD\\CDVDiso", 0, KEY_ALL_ACCESS, &myKey) != ERROR_SUCCESS)
{
SaveConf();
return;
}
GetKeyV("IsoFile", IsoFile, sizeof(IsoFile), REG_BINARY);

View File

@ -25,17 +25,19 @@ HWND hMethod;
HWND hBlockDump;
int stop;
void SysMessage(char *fmt, ...) {
void SysMessage(char *fmt, ...)
{
va_list list;
char tmp[512];
va_start(list,fmt);
vsprintf(tmp,fmt,list);
va_start(list, fmt);
vsprintf(tmp, fmt, list);
va_end(list);
MessageBox(0, tmp, "CDVDiso Msg", 0);
}
int _GetFile(char *out) {
int _GetFile(char *out)
{
OPENFILENAME ofn;
char szFileName[MAXFILENAME];
char szFileTitle[MAXFILENAME];
@ -43,29 +45,29 @@ int _GetFile(char *out) {
memset(&szFileName, 0, sizeof(szFileName));
memset(&szFileTitle, 0, sizeof(szFileTitle));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = GetActiveWindow();
ofn.lpstrFilter =
"Supported Formats\0*.bin;*.iso;*.img;*.nrg;*.mdf;*.Z;*.Z2;*.BZ2;*.dump\0"
"Cd Iso Format (*.bin;*.iso;*.img;*.nrg;*.mdf)\0"
"*.bin;*.iso;*.img;*.nrg;*.mdf\0"
"Compressed Z Iso Format (*.Z;*.Z2)\0"
"*.Z;*.Z2\0Compressed BZ Iso Format (*.BZ2)\0"
"*.BZ2\0Block Dumps (*.dump)\0*.dump\0All Files\0*.*\0";
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = GetActiveWindow();
ofn.lpstrFilter =
"Supported Formats\0*.bin;*.iso;*.img;*.nrg;*.mdf;*.Z;*.Z2;*.BZ2;*.dump\0"
"Cd Iso Format (*.bin;*.iso;*.img;*.nrg;*.mdf)\0"
"*.bin;*.iso;*.img;*.nrg;*.mdf\0"
"Compressed Z Iso Format (*.Z;*.Z2)\0"
"*.Z;*.Z2\0Compressed BZ Iso Format (*.BZ2)\0"
"*.BZ2\0Block Dumps (*.dump)\0*.dump\0All Files\0*.*\0";
ofn.lpstrCustomFilter = NULL;
ofn.nMaxCustFilter = 0;
ofn.nFilterIndex = 1;
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAXFILENAME;
ofn.lpstrInitialDir = ( IsoCWD[0] == 0 ) ? NULL : IsoCWD;
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = MAXFILENAME;
ofn.lpstrTitle = NULL;
ofn.lpstrDefExt = NULL;
ofn.Flags = OFN_HIDEREADONLY;
ofn.nMaxCustFilter = 0;
ofn.nFilterIndex = 1;
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAXFILENAME;
ofn.lpstrInitialDir = (IsoCWD[0] == 0) ? NULL : IsoCWD;
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = MAXFILENAME;
ofn.lpstrTitle = NULL;
ofn.lpstrDefExt = NULL;
ofn.Flags = OFN_HIDEREADONLY;
if(GetOpenFileName ((LPOPENFILENAME)&ofn))
if (GetOpenFileName((LPOPENFILENAME)&ofn))
{
strcpy(out, szFileName);
return 1;
@ -74,61 +76,70 @@ int _GetFile(char *out) {
return 0;
}
int _OpenFile( int saveConf ) {
int _OpenFile(int saveConf)
{
int retval = 0;
// for saving the pcsx2 current working directory;
char* cwd_pcsx2 = _getcwd( NULL, MAXFILENAME );
char* cwd_pcsx2 = _getcwd(NULL, MAXFILENAME);
if( IsoCWD[0] != 0 )
_chdir( IsoCWD );
if (IsoCWD[0] != 0)
_chdir(IsoCWD);
if (_GetFile(IsoFile) == 1)
{
// Save the user's new cwd:
if( _getcwd( IsoCWD, MAXFILENAME ) == NULL )
if (_getcwd(IsoCWD, MAXFILENAME) == NULL)
IsoCWD[0] = 0;
if( saveConf )
if (saveConf)
SaveConf();
retval = 1;
}
// Restore Pcsx2's path.
if( cwd_pcsx2 != NULL )
if (cwd_pcsx2 != NULL)
{
_chdir( cwd_pcsx2 );
free( cwd_pcsx2 );
_chdir(cwd_pcsx2);
free(cwd_pcsx2);
cwd_pcsx2 = NULL;
}
return retval;
}
void CfgOpenFile() {
_OpenFile( TRUE );
void CfgOpenFile()
{
_OpenFile(TRUE);
}
void UpdZmode() {
if (ComboBox_GetCurSel(hMethod) == 0) {
void UpdZmode()
{
if (ComboBox_GetCurSel(hMethod) == 0)
{
Zmode = 1;
} else {
}
else
{
Zmode = 2;
}
}
void SysUpdate() {
MSG msg;
void SysUpdate()
{
MSG msg;
while (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) {
while (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
void OnCompress() {
void OnCompress()
{
u32 lsn;
u8 cdbuff[10*2352];
char Zfile[256];
@ -139,17 +150,23 @@ 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 (Zmode == 1)
{
dst = isoCreate(Zfile, ISOFLAGS_Z2);
} else {
}
else
{
dst = isoCreate(Zfile, ISOFLAGS_BZ2);
}
if (dst == NULL) return;
@ -157,9 +174,10 @@ void OnCompress() {
isoSetFormat(dst, src->blockofs, src->blocksize, src->blocks);
Button_Enable(GetDlgItem(hDlg, IDC_COMPRESSISO), 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);
putchar(13);
fflush(stdout);
@ -180,16 +198,21 @@ void OnCompress() {
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");
}
}
}
void OnDecompress() {
void OnDecompress()
{
char file[256];
u8 cdbuff[10*2352];
u32 lsn;
@ -203,18 +226,25 @@ void OnDecompress() {
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) {
file[strlen(file) - 3] = 0;
} else
if (src->flags & ISOFLAGS_BZ2) {
file[strlen(file) - 3] = 0;
} else {
SysMessage("%s is not a compressed image", IsoFile);
return;
}
else
if (src->flags & ISOFLAGS_Z2)
{
file[strlen(file) - 3] = 0;
}
else
if (src->flags & ISOFLAGS_BZ2)
{
file[strlen(file) - 3] = 0;
}
else
{
SysMessage("%s is not a compressed image", IsoFile);
return;
}
dst = isoCreate(file, 0);
if (dst == NULL) return;
@ -222,9 +252,10 @@ void OnDecompress() {
isoSetFormat(dst, src->blockofs, src->blocksize, src->blocks);
Button_Enable(GetDlgItem(hDlg, IDC_COMPRESSISO), 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);
putchar(13);
fflush(stdout);
@ -245,19 +276,25 @@ 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");
}
}
}
BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) {
BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int i;
switch(uMsg) {
switch (uMsg)
{
case WM_INITDIALOG:
hDlg = hW;
LoadConf();
@ -267,23 +304,25 @@ 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]);
}
Edit_SetText(hIsoFile, IsoFile);
ComboBox_SetCurSel(hMethod, 0);
/* if (strstr(IsoFile, ".Z") != NULL)
ComboBox_SetCurSel(hMethod, 1);
else ComboBox_SetCurSel(hMethod, 0);*/
/* if (strstr(IsoFile, ".Z") != NULL)
ComboBox_SetCurSel(hMethod, 1);
else ComboBox_SetCurSel(hMethod, 0);*/
Button_SetCheck(hBlockDump, BlockDump);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam)) {
switch (LOWORD(wParam))
{
case IDC_SELECTISO:
if( _OpenFile(FALSE) == 1 )
if (_OpenFile(FALSE) == 1)
Edit_SetText(hIsoFile, IsoFile);
return TRUE;
@ -315,20 +354,24 @@ BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
return FALSE;
}
EXPORT_C(void) CDVDconfigure() {
DialogBox(hInst,
MAKEINTRESOURCE(IDD_CONFIG),
GetActiveWindow(),
(DLGPROC)ConfigureDlgProc);
EXPORT_C(void) CDVDconfigure()
{
DialogBox(hInst,
MAKEINTRESOURCE(IDD_CONFIG),
GetActiveWindow(),
(DLGPROC)ConfigureDlgProc);
}
BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch(uMsg) {
BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam)) {
switch (LOWORD(wParam))
{
case IDOK:
EndDialog(hW, TRUE);
return FALSE;
@ -337,16 +380,18 @@ BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) {
return FALSE;
}
EXPORT_C(void) CDVDabout() {
DialogBox(hInst,
MAKEINTRESOURCE(IDD_ABOUT),
GetActiveWindow(),
(DLGPROC)AboutDlgProc);
EXPORT_C(void) CDVDabout()
{
DialogBox(hInst,
MAKEINTRESOURCE(IDD_ABOUT),
GetActiveWindow(),
(DLGPROC)AboutDlgProc);
}
BOOL APIENTRY DllMain(HANDLE hModule, // DLL INIT
DWORD dwReason,
LPVOID lpReserved) {
DWORD dwReason,
LPVOID lpReserved)
{
hInst = (HINSTANCE)hModule;
return TRUE; // very quick :)
}

View File

@ -16,7 +16,7 @@
#define IDC_BLOCKDUMP 1007
// Next default values for new objects
//
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 105

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -24,43 +24,52 @@
#include "CDVDiso.h"
void Compress(char *filename, int mode) {
void Compress(char *filename, int mode)
{
struct stat buf;
u32 lsn;
u8 cdbuff[1024*16];
char Zfile[256];
int ret=0;
int ret = 0;
isoFile *src;
isoFile *dst;
if (mode == 1) {
if (mode == 1)
{
sprintf(Zfile, "%s.Z2", filename);
} else {
}
else
{
sprintf(Zfile, "%s.BZ2", filename);
}
if (stat(Zfile, &buf) != -1) {
if (stat(Zfile, &buf) != -1)
{
printf("'%s' already exists\n", Zfile);
return;
/* sprintf(str, "'%s' already exists, overwrite?", Zfile);
if (MessageBox(hDlg, str, "Question", MB_YESNO) != IDYES) {
return;
}*/
/* sprintf(str, "'%s' already exists, overwrite?", Zfile);
if (MessageBox(hDlg, str, "Question", MB_YESNO) != IDYES) {
return;
}*/
}
printf("src %s; dst %s\n", filename, Zfile);
src = isoOpen(filename);
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;
for (lsn = 0; lsn<src->blocks; lsn++) {
for (lsn = 0; lsn < src->blocks; lsn++)
{
printf("block %d ", lsn);
putchar(13);
fflush(stdout);
@ -72,39 +81,44 @@ void Compress(char *filename, int mode) {
isoClose(src);
isoClose(dst);
if (ret == -1) {
if (ret == -1)
{
printf("Error compressing iso image\n");
} else {
}
else
{
printf("Iso image compressed OK\n");
}
}
void Decompress(char *filename) {
void Decompress(char *filename)
{
struct stat buf;
char file[256];
u8 cdbuff[10*2352];
u32 lsn;
isoFile *src;
isoFile *dst;
int ret=0;
int ret = 0;
src = isoOpen(filename);
if (src == NULL) return;
strcpy(file, filename);
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
{
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);
@ -115,7 +129,8 @@ void Decompress(char *filename) {
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);
@ -128,25 +143,23 @@ void Decompress(char *filename) {
isoClose(src);
isoClose(dst);
if (ret == -1) {
if (ret == -1)
printf("Error decompressing iso image\n");
} else {
else
printf("Iso image decompressed OK\n");
}
}
int main(int argc, char *argv[]) {
int main(int argc, char *argv[])
{
if (argc < 3) return 0;
if (argv[1][0] == 'c') {
Compress(argv[2], 1);
} else
if (argv[1][0] == 'C') {
Compress(argv[2], 2);
} else
if (argv[1][0] == 'd') {
Decompress(argv[2]);
switch (argv[1][0])
{
case 'c': Compress(argv[2], 1);
case 'C': Compress(argv[2], 2);
case 'd': Decompress(argv[2]);
default: break;
}
return 0;