s32 CALLBACK CDVDctrlTrayOpen() { int i; #ifdef VERBOSE_FUNCTION_INTERFACE PrintLog("CDVDiso interface: CDVDctrlTrayOpen()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ // Close() isofile = IsoFileClose(isofile); deviceopencount = 50; // and re-Open() if ((conf.isoname[0] == 0) || ((conf.restartconfigure != 0) && (deviceopencount > 0))) { ExecCfg("configure"); LoadConf(); } // ENDIF- Haven't initialized the configure program yet? Do so now. isofile = IsoFileOpenForRead(conf.isoname); if (isofile == NULL) { #ifdef VERBOSE_FUNCTION_INTERFACE PrintLog("CDVDiso interface: Failed to open ISO file!"); #endif /* VERBOSE_FUNCTION_INTERFACE */ } // ENDIF- Trouble opening file? Abort. if (deviceopencount > 0) { i = 0; while ((i < 2048) && (isocdcheck[i] == isobuffer[i])) i++; if (i == 2048) deviceopencount = 0; // Same CD/DVD? No delay. } // ENDIF- Is this a restart? Check for disc change. for (i = 0; i < 2048; i++) isocdcheck[i] = isobuffer[i]; return (0); } // END CDVDctrlTrayOpen()
gint DeviceBoxFileEvent(GtkWidget *widget, GdkEvent event, gpointer data) { int returnval; char templine[256]; struct IsoFile *tempfile; returnval = IsIsoFile(gtk_entry_get_text(GTK_ENTRY(devicebox.file))); if (returnval == -1) { gtk_label_set_text(GTK_LABEL(devicebox.filedesc), "File Type: ---"); return (TRUE); } // ENDIF- Not a name of any sort? if (returnval == -2) { gtk_label_set_text(GTK_LABEL(devicebox.filedesc), "File Type: Not a file"); return (TRUE); } // ENDIF- Not a regular file? if (returnval == -3) { gtk_label_set_text(GTK_LABEL(devicebox.filedesc), "File Type: Not a valid image file"); return (TRUE); } // ENDIF- Not an image file? if (returnval == -4) { gtk_label_set_text(GTK_LABEL(devicebox.filedesc), "File Type: Missing Table File (will rebuild)"); return (TRUE); } // ENDIF- Not a regular file? tempfile = IsoFileOpenForRead(gtk_entry_get_text(GTK_ENTRY(devicebox.file))); sprintf(templine, "File Type: %s%s%s", multinames[tempfile->multi], tempfile->imagename, compressdesc[tempfile->compress]); gtk_label_set_text(GTK_LABEL(devicebox.filedesc), templine); tempfile = IsoFileClose(tempfile); return (TRUE); } // END DeviceBoxFileEvent()
s32 CALLBACK CDVDctrlTrayOpen() { HWND lastwindow; int i; int retval; #ifdef VERBOSE_FUNCTION_INTERFACE PrintLog("CDVDiso interface: CDVDctrlTrayOpen()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ // CDVDclose(); isofile = IsoFileClose(isofile); deviceopencount = 50; // CDVDopen(); lastwindow = GetActiveWindow(); LoadConf(); if((conf.isoname[0] == 0) || (conf.isoname[0] == '[') || ((conf.restartconfigure == 1) && (deviceopencount > 0))) { DialogBox(progmodule, MAKEINTRESOURCE(DLG_0200), lastwindow, (DLGPROC)MainBoxCallback); SetActiveWindow(lastwindow); LoadConf(); // Blank out the name in config file afterwards? Seems excessive. } // ENDIF- Haven't initialized the configure program yet? Do so now. lastwindow = NULL; deviceopencount = 0; // Temp line! // NOTE: What happened to repetitive polling when disc not in drive? isofile = IsoFileOpenForRead(conf.isoname); if(isofile == NULL) { #ifdef VERBOSE_FUNCTION_INTERFACE PrintLog("CDVDiso interface: Failed to open ISO file!"); #endif /* VERBOSE_FUNCTION_INTERFACE */ // return(-1); // Removed to simulate disc not in drive. for(i = 0; i < 2048; i++) isocdcheck[i] = 0; return(0); } // ENDIF- Trouble opening file? Abort. retval = IsoFileSeek(isofile, 16); if(retval != 0) return(-1); retval = IsoFileRead(isofile, isobuffer); if(retval != 0) return(-1); if(deviceopencount > 0) { i = 0; while((i < 2048) && (isocdcheck[i] == isobuffer[i])) i++; if(i == 2048) deviceopencount = 0; // Same CD/DVD? No delay. } // ENDIF- Is this a restart? Check for disc change. for(i = 0; i < 2048; i++) isocdcheck[i] = isobuffer[i]; return(0); } // END CDVDctrlTrayOpen()
int IsIsoFile(const char *filename) { int retval; struct IsoFile *tempfile; #ifdef VERBOSE_FUNCTION_ISOFILE PrintLog("CDVD isofile: IsIsoFile()"); #endif /* VERBOSE_FUNCTION_ISOFILE */ retval = IsActualFile(filename); if(retval < 0) return(retval); // Not a regular file? Report it. tempfile = NULL; tempfile = IsoFileOpenForRead(filename); if(tempfile == NULL) return(-3); // Not an image file? Report it. retval = 0; if((tempfile->compress > 0) && (tempfile->tablehandle == ACTUALHANDLENULL) && (tempfile->tabledata == NULL)) retval = -4; tempfile = IsoFileClose(tempfile); return(retval); } // END IsIsoFile()
void MainBoxFileEvent() { int returnval; char templine[256]; struct IsoFile *tempfile; GetDlgItemText(mainboxwindow, IDC_0202, templine, 256); returnval = IsIsoFile(templine); if (returnval == -1) { SetDlgItemText(mainboxwindow, IDC_0204, "File Type: ---"); return; } // ENDIF- Not a name of any sort? if (returnval == -2) { SetDlgItemText(mainboxwindow, IDC_0204, "File Type: Not a file"); return; } // ENDIF- Not a regular file? if (returnval == -3) { SetDlgItemText(mainboxwindow, IDC_0204, "File Type: Not a valid image file"); return; } // ENDIF- Not an Image file? if (returnval == -4) { SetDlgItemText(mainboxwindow, IDC_0204, "File Type: Missing Table File (will rebuild)"); return; } // ENDIF- Missing Compression seek table? tempfile = IsoFileOpenForRead(templine); sprintf(templine, "File Type: %s%s%s", multinames[tempfile->multi], tempfile->imagename, compressdesc[tempfile->compress]); SetDlgItemText(mainboxwindow, IDC_0204, templine); tempfile = IsoFileClose(tempfile); return; } // END MainBoxFileEvent()
s32 CALLBACK CDVDopen(const char* pTitleFilename) { int retval; int i; #ifdef VERBOSE_FUNCTION_INTERFACE PrintLog("CDVDiso interface: CDVDopen()"); #endif /* VERBOSE_FUNCTION_INTERFACE */ LoadConf(); if (pTitleFilename != NULL) strcpy(conf.isoname, pTitleFilename); if ((conf.isoname[0] == 0) || ((conf.startconfigure != 0) && (deviceopencount == 0)) || ((conf.restartconfigure != 0) && (deviceopencount > 0))) { ExecCfg("configure"); LoadConf(); } // ENDIF- Haven't initialized the configure program yet? Do so now. isofile = IsoFileOpenForRead(conf.isoname); if (isofile == NULL) { #ifdef VERBOSE_FUNCTION_INTERFACE PrintLog("CDVDiso interface: Failed to open ISO file!"); #endif /* VERBOSE_FUNCTION_INTERFACE */ // return(-1); // Taken out for "NULL" device simulation for (i = 0; i < 2048; i++) isocdcheck[i] = 0; return (0); } // ENDIF- Trouble opening file? Abort. retval = IsoFileSeek(isofile, 16); if (retval != 0) return (-1); retval = IsoFileRead(isofile, isobuffer); if (retval != 0) return (-1); if (deviceopencount > 0) { i = 0; while ((i < 2048) && (isocdcheck[i] == isobuffer[i])) i++; if (i == 2048) deviceopencount = 0; // Same CD/DVD? No delay. } // ENDIF- Is this a restart? Check for disc change. for (i = 0; i < 2048; i++) isocdcheck[i] = isobuffer[i]; return (0); } // END CDVDopen()
gint ConversionBoxOKEvent(GtkWidget *widget, GdkEvent event, gpointer data) { char templine[256]; char tempblock[2352]; const char *filename; int compressmethod; int multi; struct IsoFile *fromfile; struct IsoFile *tofile; int i; off64_t endsector; int stop; int retval; ConversionBoxUnfocus(); filename = gtk_entry_get_text(GTK_ENTRY(conversionbox.file)); if (IsIsoFile(filename) < 0) { filename = NULL; MessageBoxShow("Not a valid file", 3); return(TRUE); } // ENDIF- Not an Iso File? Stop early. compressmethod = gtk_combo_box_get_active(GTK_COMBO_BOX(conversionbox.compress)); if (compressmethod > 0) compressmethod += 2; multi = 0; if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(conversionbox.multi)) == TRUE) multi = 1; fromfile = NULL; fromfile = IsoFileOpenForRead(filename); if (fromfile == NULL) { filename = NULL; MessageBoxShow("Cannot opening the source file", 3); return(TRUE); } // ENDIF- Not an Iso File? Stop early. if ((compressmethod == fromfile->compress) && (multi == fromfile->multi)) { fromfile = IsoFileClose(fromfile); filename = NULL; MessageBoxShow("Compress/Multifile methods match - no need to convert", 3); return(TRUE); } // ENDIF- Not an Iso File? Stop early. tofile = IsoFileOpenForWrite(filename, GetImageTypeConvertTo(fromfile->imagetype), multi, compressmethod); if (tofile == NULL) { fromfile = IsoFileClose(fromfile); filename = NULL; MessageBoxShow("Cannot create the new file", 3); return(TRUE); } // ENDIF- Not an Iso File? Stop early. if (fromfile->multi == 1) { i = 0; while ((i < 10) && (IsoFileSeek(fromfile, fromfile->multisectorend[i] + 1) == 0)) i++; endsector = fromfile->multisectorend[fromfile->multiend]; } else { endsector = fromfile->filesectorsize; } // ENDIF- Get ending sector from multifile? (Or single file?) IsoFileSeek(fromfile, 0); // Open Progress Bar sprintf(templine, "%s: %s%s -> %s%s", filename, multinames[fromfile->multi], compressdesc[fromfile->compress], multinames[tofile->multi], compressdesc[tofile->compress]); ProgressBoxStart(templine, endsector); tofile->cdvdtype = fromfile->cdvdtype; for (i = 0; i < 2048; i++) tofile->toc[i] = fromfile->toc[i]; stop = 0; mainbox.stop = 0; progressbox.stop = 0; while ((stop == 0) && (tofile->sectorpos < endsector)) { retval = IsoFileRead(fromfile, tempblock); if (retval < 0) { MessageBoxShow("Trouble reading source file", 3); stop = 1; } else { retval = IsoFileWrite(tofile, tempblock); if (retval < 0) { MessageBoxShow("Trouble writing new file", 3); stop = 1; } // ENDIF- Trouble writing out the next block? } // ENDIF- Trouble reading in the next block? ProgressBoxTick(tofile->sectorpos); while (gtk_events_pending()) gtk_main_iteration(); if (mainbox.stop != 0) stop = 2; if (progressbox.stop != 0) stop = 2; } // ENDWHILE- Not stopped for some reason... ProgressBoxStop(); if (stop == 0) { if (tofile->multi == 1) tofile->name[tofile->multipos] = '0'; // First file strcpy(templine, tofile->name); // fromfile = IsoFileCloseAndDelete(fromfile); fromfile = IsoFileClose(fromfile); IsoSaveTOC(tofile); tofile = IsoFileClose(tofile); gtk_entry_set_text(GTK_ENTRY(mainbox.file), templine); } else { fromfile = IsoFileClose(fromfile); tofile = IsoFileCloseAndDelete(tofile); } // ENDIF- Did we succeed in the transfer? if (stop != 1) ConversionBoxRefocus(); if (stop == 0) ConversionBoxCancelEvent(widget, event, data); return(TRUE); } // END ConversionBoxOKEvent()
gint MainBoxOKEvent(GtkWidget *widget, GdkEvent event, gpointer data) { const char *tempisoname1; const char *tempisoname2; struct IsoFile *tempiso1; struct IsoFile *tempiso2; int stop; off64_t endsector; off64_t sector; int retval; char tempblock1[2448]; char tempblock2[2448]; int i; MainBoxUnfocus(); tempisoname1 = gtk_entry_get_text(GTK_ENTRY(mainbox.file1)); tempisoname2 = gtk_entry_get_text(GTK_ENTRY(mainbox.file2)); tempiso1 = NULL; tempiso2 = NULL; tempiso1 = IsoFileOpenForRead(tempisoname1); if (tempiso1 == NULL) { MainBoxRefocus(); MessageBoxShow("First file is not a Valid Image File.", 0); tempisoname1 = NULL; tempisoname2 = NULL; return(TRUE); } // ENDIF- Not an ISO file? Message and Stop here. tempiso2 = IsoFileOpenForRead(tempisoname2); if (tempiso2 == NULL) { MainBoxRefocus(); MessageBoxShow("Second file is not a Valid Image File.", 0); tempiso1 = IsoFileClose(tempiso1); tempisoname1 = NULL; tempisoname2 = NULL; return(TRUE); } // ENDIF- Not an ISO file? Message and Stop here. if (tempiso1->blocksize != tempiso2->blocksize) { MainBoxRefocus(); MessageBoxShow("Block sizes in Image files do not match.", 0); tempiso1 = IsoFileClose(tempiso1); tempiso2 = IsoFileClose(tempiso2); tempisoname1 = NULL; tempisoname2 = NULL; return(TRUE); } // ENDIF- Not an ISO file? Message and Stop here. if (tempiso1->multi == 1) { i = 0; while ((i < 10) && (IsoFileSeek(tempiso1, tempiso1->multisectorend[i] + 1) == 0)) i++; endsector = tempiso1->multisectorend[tempiso1->multiend]; } else { endsector = tempiso1->filesectorsize; } // ENDIF- Get ending sector from multifile? (Or single file?) IsoFileSeek(tempiso1, 0); if (tempiso2->multi == 1) { i = 0; while ((i < 10) && (IsoFileSeek(tempiso2, tempiso2->multisectorend[i] + 1) == 0)) i++; sector = tempiso2->multisectorend[tempiso2->multiend]; } else { sector = tempiso2->filesectorsize; } // ENDIF- Get ending sector from multifile? (Or single file?) IsoFileSeek(tempiso2, 0); if (sector != endsector) { MainBoxRefocus(); MessageBoxShow("Number of blocks in Image files do not match.", 0); tempiso1 = IsoFileClose(tempiso1); tempiso2 = IsoFileClose(tempiso2); tempisoname1 = NULL; tempisoname2 = NULL; return(TRUE); } // ENDIF- Number of blocks don't match? Say so. sprintf(tempblock1, "%s == %s ?", tempisoname1, tempisoname2); ProgressBoxStart(tempblock1, endsector); stop = 0; mainbox.stop = 0; progressbox.stop = 0; while ((stop == 0) && (tempiso1->sectorpos < endsector)) { retval = IsoFileRead(tempiso1, tempblock1); if (retval < 0) { MainBoxRefocus(); MessageBoxShow("Trouble reading first file.", 0); stop = 1; } else { retval = IsoFileRead(tempiso2, tempblock2); if (retval < 0) { MainBoxRefocus(); MessageBoxShow("Trouble reading second file.", 0); stop = 1; } else { i = 0; while ((i < tempiso1->blocksize) && (tempblock1[i] == tempblock2[i])) i++; if (i < tempiso1->blocksize) { MainBoxRefocus(); MessageBoxShow("Trouble reading second file.", 0); stop = 1; } // ENDIF- Sectors don't match? Say so. } // ENDIF- Trouble reading second file? } // ENDIF- Trouble reading first file? ProgressBoxTick(tempiso1->sectorpos); while (gtk_events_pending()) gtk_main_iteration(); if (mainbox.stop != 0) stop = 2; if (progressbox.stop != 0) stop = 2; } // ENDWHILE- Comparing two files... sector by sector if (stop == 0) { MainBoxRefocus(); MessageBoxShow("Images Match.", 0); } // ENDIF- Everything checked out? Say so. tempiso1 = IsoFileClose(tempiso1); tempiso2 = IsoFileClose(tempiso2); tempisoname1 = NULL; tempisoname2 = NULL; return(TRUE); } // END MainBoxOKEvent()
void IsoTableRebuild(const char *filename) { struct IsoFile *datafile; struct IsoFile *tablefile; int retval; char tempblock[65536]; int stop; struct TableData table; datafile = IsoFileOpenForRead(filename); // Note: This is the start of the "Multifile" process. It's commented // out so at least we can rebuild 1 part of a multifile at a time. // IsoNameStripExt(datafile); // IsoNameStripMulti(datafile); // Prep tablefile to hold ONLY a table (no data) tablefile = (struct IsoFile *) malloc(sizeof(struct IsoFile)); if (tablefile == NULL) { datafile = IsoFileClose(datafile); return; } // ENDIF- Failed to allocate? Abort. tablefile->sectorpos = 0; tablefile->openforread = 0; tablefile->filebytepos = 0; tablefile->filebytesize = 0; tablefile->filesectorpos = 0; tablefile->filesectorsize = 0; tablefile->handle = ACTUALHANDLENULL; tablefile->namepos = 0; while ((tablefile->namepos < 255) && (*(filename + tablefile->namepos) != 0)) { tablefile->name[tablefile->namepos] = *(filename + tablefile->namepos); tablefile->namepos++; } // ENDWHILE- Copying file name into tablefile tablefile->name[tablefile->namepos] = 0; // And 0-terminate. tablefile->imageheader = datafile->imageheader; tablefile->blocksize = datafile->blocksize; tablefile->blockoffset = datafile->blockoffset; tablefile->cdvdtype = 0; // Not important right now. tablefile->compress = datafile->compress; tablefile->compresspos = datafile->compresspos; tablefile->numsectors = datafile->numsectors; tablefile->tabledata = NULL; switch (tablefile->compress) { case 1: retval = GZipV1OpenTableForWrite(tablefile); break; case 2: retval = -1; break; case 3: retval = GZipV2OpenTableForWrite(tablefile); break; case 4: retval = BZip2V2OpenTableForWrite(tablefile); break; case 5: retval = BZip2V3OpenTableForWrite(tablefile); break; default: retval = -1; break; } // ENDSWITCH compress- Which table are we writing out? if (retval < 0) { datafile = IsoFileClose(datafile); return; } // ENDIF- Failed to open table file? Abort sprintf(tempblock, "Rebuilding table for %s", datafile->name); ProgressBoxStart(tempblock, datafile->filebytesize); stop = 0; mainbox.stop = 0; progressbox.stop = 0; while ((stop == 0) && (datafile->filebytepos < datafile->filebytesize)) { switch (datafile->compress) { case 1: retval = GZipV1Read(datafile, 0, tempblock); break; case 2: retval = -1; break; case 3: retval = GZipV2Read(datafile, 0, tempblock); break; case 4: retval = BZip2V2Read(datafile, 0, tempblock); break; case 5: retval = BZip2V3Read(datafile, 0, tempblock); break; default: retval = -1; break; } // ENDSWITCH compress- Scanning for the next complete compressed block if (retval <= 0) { #ifdef FUNCTION_WARNING_TABLEREBUILD PrintLog("CDVDiso rebuild: failed to decompress - data corrupt"); #endif /* FUNCTION_WARNING_TABLEREBUILD */ stop = 1; } else { table.offset = datafile->filebytepos - retval; table.size = retval; switch (tablefile->compress) { case 1: retval = GZipV1WriteTable(tablefile, table); break; case 2: retval = -1; break; case 3: retval = GZipV2WriteTable(tablefile, table); break; case 4: retval = BZip2V2WriteTable(tablefile, table); break; case 5: retval = BZip2V3WriteTable(tablefile, table); break; default: retval = -1; break; } // ENDSWITCH compress- Writing out the relavent table facts if (retval < 0) stop = 1; } // ENDIF- Do we have a valid record to write an entry for? ProgressBoxTick(datafile->filebytepos); // while(gtk_events_pending()) gtk_main_iteration(); if (mainbox.stop != 0) stop = 2; if (progressbox.stop != 0) stop = 2; } // ENDWHILE- Read in the data file and writing a table, 1 block at a time ProgressBoxStop(); CompressClose(tablefile); // Guarentee the table is flushed and closed. if (stop != 0) { ActualFileDelete(tablefile->tablename); } // ENDIF- Aborted or trouble? Delete the table file tablefile = IsoFileClose(tablefile); datafile = IsoFileClose(datafile); return; } // END IsoTableRebuild()