예제 #1
0
파일: isofile.c 프로젝트: madnessw/thesnow
struct IsoFile *IsoFileCloseAndDelete(struct IsoFile *file)
{
	int i;
	if (file == NULL)  return(NULL);
	if (file->handle != ACTUALHANDLENULL)
	{
#ifdef VERBOSE_FUNCTION_ISOFILE
		PrintLog("CDVD isofile: IsoFileCloseAndDelete()");
#endif /* VERBOSE_FUNCTION_ISOFILE */

		if (file->compress > 0)
		{
			CompressClose(file);
		}
		else
		{
			ActualFileClose(file->handle);
			file->handle = ACTUALHANDLENULL;
		} // ENDIF- Compressed File? Close (and flush) compression too.
	} // ENDIF- Open Handle? Close the file

	if (file->multi == 1)
	{
		for (i = file->multistart; i <= file->multiend; i++)
		{
			file->name[file->multipos] = '0' + i;
			ActualFileDelete(file->name);
			if (file->compress > 0)
			{
				file->tablename[file->multipos] = '0' + i;
				ActualFileDelete(file->tablename);
			} // ENDIF- Get the table file too?
		} // NEXT i- iterate through each multi-file name, removing it.
	}
	else
	{
		ActualFileDelete(file->name);
		if (file->compress > 0)
		{
			ActualFileDelete(file->tablename);
		} // ENDIF- Get the table file too?
	} // ENDIF- Do we have to remove multiple files?

	free(file);
	return(NULL);
} // END IsoFileCloseAndDelete()
예제 #2
0
파일: toc.c 프로젝트: Aced14/pcsx2
extern int IsoSaveTOC(struct IsoFile *isofile)
{
	char tocext[] = ".toc\0";
	char tocheader[] = "TOC1\0";
	ACTUALHANDLE tochandle;
	char tocname[256];
	int i;
	int j;
	int retval;
	unsigned char cdvdtype;
	struct tocTN toctn;
	struct tocTD toctd;
	char temptime[3];
	if (isofile == NULL)  return(-1);
	i = 0;
	while ((i < 256) && (isofile->name[i] != 0))
	{
		tocname[i] = isofile->name[i];
		i++;
	} // ENDWHILE- Copying the data name to the toc name
	j = 0;
	while ((i < 256) && (tocext[j] != 0))
	{
		tocname[i] = tocext[j];
		i++;
		j++;
	} // ENDWHILE- Append ".toc" to end of name
	tocname[i] = 0; // And 0-terminate

	ActualFileDelete(tocname);
	tochandle = ActualFileOpenForWrite(tocname);
	if (tochandle == ACTUALHANDLENULL)  return(-1);

	retval = ActualFileWrite(tochandle, 4, tocheader);
	if (retval < 4)
	{
		ActualFileClose(tochandle);
		tochandle = ACTUALHANDLENULL;
		ActualFileDelete(tocname);
		return(-1);
	} // ENDIF- Trouble writing to the 'toc' file?

	cdvdtype = isofile->cdvdtype;
	ActualFileWrite(tochandle, 1, (char *) &cdvdtype);
	if ((cdvdtype != CDVD_TYPE_PS2DVD) && (cdvdtype != CDVD_TYPE_DVDV))
	{
		toctn.strack = BCDTOHEX(isofile->toc[7]);
		toctn.etrack = BCDTOHEX(isofile->toc[17]);
		ActualFileWrite(tochandle, sizeof(struct tocTN), (char *) &toctn);
		// Leadout Data
		toctd.type = 0;
		temptime[0] = BCDTOHEX(isofile->toc[27]);
		temptime[1] = BCDTOHEX(isofile->toc[28]);
		temptime[2] = BCDTOHEX(isofile->toc[29]);
		toctd.lsn = MSFtoLBA(temptime);
		ActualFileWrite(tochandle, sizeof(struct tocTD), (char *) &toctd);
		for (i = toctn.strack; i <= toctn.etrack; i++)
		{
			j = i * 10 + 30;
			toctd.type = isofile->toc[j];
			temptime[0] = BCDTOHEX(isofile->toc[j + 7]);
			temptime[1] = BCDTOHEX(isofile->toc[j + 8]);
			temptime[2] = BCDTOHEX(isofile->toc[j + 9]);
			toctd.lsn = MSFtoLBA(temptime);
			ActualFileWrite(tochandle, sizeof(struct tocTD), (char *) &toctd);
		} // NEXT i- write out each track
	} // ENDIF- Not a DVD? (Then output CD track data)
	ActualFileClose(tochandle);
	tochandle = ACTUALHANDLENULL;
	return(0);
} // END IsoSaveTOC()
예제 #3
0
파일: ini.c 프로젝트: Codyle/pcsx2
int INISaveString(char *file, char *section, char *keyword, char *value)
{
	char inname[INIMAXLEN + 1];
	char outname[INIMAXLEN + 1];
	int filepos;
	ACTUALHANDLE infile;
	ACTUALHANDLE outfile;
	int i;
	int retval;
	char templine[INIMAXLEN + 1];
	if (file == NULL)  return (-1);
	if (section == NULL)  return (-1);
	if (keyword == NULL)  return (-1);
	if (value == NULL)  return (-1);
#ifdef VERBOSE_FUNCTION_INI
	PrintLog("CDVDiso ini: SaveString(%s, %s, %s, %s)",
	         file, section, keyword, value);
#endif /* VERBOSE_FUNCTION_INI */
	filepos = INIRemoveExt(file, inname);
	for (i = 0; i <= filepos; i++)  outname[i] = inname[i];
	INIAddInExt(inname, filepos);
	INIAddOutExt(outname, filepos);
	filepos = 0;
	infile = ActualFileOpenForRead(inname);
	if (infile == ACTUALHANDLENULL) {
#ifdef VERBOSE_FUNCTION_INI
		PrintLog("CDVDiso ini:   creating new file");
#endif /* VERBOSE_FUNCTION_INI */
		outfile = ActualFileOpenForWrite(inname);
		if (outfile == ACTUALHANDLENULL)  return (-1); // Just a bad name? Abort.
		sprintf(templine, "[%s]\r\n", section);
		i = 0;
		while ((i < INIMAXLEN) && (templine[i] != 0)) i++;
		retval = ActualFileWrite(outfile, i, templine);
		if (retval < i) {
			ActualFileClose(outfile);
			outfile = ACTUALHANDLENULL;
			ActualFileDelete(inname);
			return (-1);
		} // ENDIF- Trouble writing it out? Abort.
		sprintf(templine, "%s=%s\r\n", keyword, value);
		i = 0;
		while ((i < INIMAXLEN) && (templine[i] != 0)) i++;
		retval = ActualFileWrite(outfile, i, templine);
		ActualFileClose(outfile);
		outfile = ACTUALHANDLENULL;
		if (retval < i) {
			ActualFileDelete(inname);
			return (-1);
		} // ENDIF- Trouble writing it out? Abort.
		return (0);
	} // ENDIF- No input file? Create a brand new .ini file then.
	retval = INIFindSection(infile, section);
	if (retval < 0) {
#ifdef VERBOSE_FUNCTION_INI
		PrintLog("CDVDiso ini:   creating new section");
#endif /* VERBOSE_FUNCTION_INI */
		outfile = ActualFileOpenForWrite(outname);
		if (outfile == ACTUALHANDLENULL) {
			ActualFileClose(infile);
			infile = ACTUALHANDLENULL;
			return (-1);
		} // ENDIF- Couldn't open a temp file? Abort
		ActualFileSeek(infile, 0); // Move ini to beginning of file...
		INICopy(infile, outfile, 0x0FFFFFFF); // Copy the whole file out...
		sprintf(templine, "\r\n[%s]\r\n", section);
		i = 0;
		while ((i < INIMAXLEN) && (templine[i] != 0)) i++;
		retval = ActualFileWrite(outfile, i, templine);
		if (retval < i) {
			ActualFileClose(infile);
			infile = ACTUALHANDLENULL;
			ActualFileClose(outfile);
			outfile = ACTUALHANDLENULL;
			ActualFileDelete(outname);
			return (-1);
		} // ENDIF- Trouble writing it out? Abort.
		sprintf(templine, "%s=%s\r\n", keyword, value);
		i = 0;
		while ((i < INIMAXLEN) && (templine[i] != 0)) i++;
		retval = ActualFileWrite(outfile, i, templine);
		ActualFileClose(infile);
		infile = ACTUALHANDLENULL;
		ActualFileClose(outfile);
		outfile = ACTUALHANDLENULL;
		if (retval < i) {
			ActualFileDelete(outname);
			return (-1);
		} // ENDIF- Trouble writing it out? Abort.
		ActualFileDelete(inname);
		ActualFileRename(outname, inname);
		return (0);
	} // ENDIF- Couldn't find the section? Make a new one!
	filepos = retval;
	ActualFileSeek(infile, filepos);
	filepos += INIReadLine(infile, templine); // Get section line's byte count
	retval = INIFindKeyword(infile, keyword, NULL);
	if (retval < 0) {
#ifdef VERBOSE_FUNCTION_INI
		PrintLog("CDVDiso ini:   creating new keyword");
#endif /* VERBOSE_FUNCTION_INI */
		ActualFileSeek(infile, filepos);
		retval = INIReadLine(infile, templine);
		i = 0;
		while ((i < INIMAXLEN) && (templine[i] != 0) && (templine[i] != '='))  i++;
		while ((retval > 0) && (templine[i] == '=')) {
			filepos += retval;
			retval = INIReadLine(infile, templine);
			i = 0;
			while ((i < INIMAXLEN) && (templine[i] != 0) && (templine[i] != '='))  i++;
		} // ENDWHILE- skimming to the bottom of the section
		outfile = ActualFileOpenForWrite(outname);
		if (outfile == ACTUALHANDLENULL) {
			ActualFileClose(infile);
			infile = ACTUALHANDLENULL;
			return (-1);
		} // ENDIF- Couldn't open a temp file? Abort
		ActualFileSeek(infile, 0);
		retval = INICopy(infile, outfile, filepos);
		if (retval > 0) {
			ActualFileClose(infile);
			infile = ACTUALHANDLENULL;
			ActualFileClose(outfile);
			outfile = ACTUALHANDLENULL;
			ActualFileDelete(outname);
			return (-1);
		} // ENDIF- Trouble writing everything up to keyword? Abort.
		sprintf(templine, "%s=%s\r\n", keyword, value);
		i = 0;
		while ((i < INIMAXLEN) && (templine[i] != 0)) i++;
		retval = ActualFileWrite(outfile, i, templine);
		if (retval < i) {
			ActualFileClose(infile);
			infile = ACTUALHANDLENULL;
			ActualFileClose(outfile);
			outfile = ACTUALHANDLENULL;
			ActualFileDelete(outname);
			return (-1);
		} // ENDIF- Trouble writing it out? Abort.
	} else {
#ifdef VERBOSE_FUNCTION_INI
		PrintLog("CDVDiso ini:   replacing keyword");
#endif /* VERBOSE_FUNCTION_INI */
		filepos += retval; // Position just before old version of keyword
		outfile = ActualFileOpenForWrite(outname);
		if (outfile == ACTUALHANDLENULL) {
			ActualFileClose(infile);
			infile = ACTUALHANDLENULL;
			return (-1);
		} // ENDIF- Couldn't open a temp file? Abort
		ActualFileSeek(infile, 0);
		retval = INICopy(infile, outfile, filepos);
		if (retval > 0) {
			ActualFileClose(infile);
			infile = ACTUALHANDLENULL;
			ActualFileClose(outfile);
			outfile = ACTUALHANDLENULL;
			ActualFileDelete(outname);
			return (-1);
		} // ENDIF- Trouble writing everything up to keyword? Abort.
		INIReadLine(infile, templine); // Read past old keyword/value...
		// Replace with new value
		sprintf(templine, "%s=%s\r\n", keyword, value);
		i = 0;
		while ((i < INIMAXLEN) && (templine[i] != 0)) i++;
		retval = ActualFileWrite(outfile, i, templine);
		if (retval < i) {
			ActualFileClose(infile);
			infile = ACTUALHANDLENULL;
			ActualFileClose(outfile);
			outfile = ACTUALHANDLENULL;
			ActualFileDelete(outname);
			return (-1);
		} // ENDIF- Trouble writing it out? Abort.
	} // ENDIF- Need to add a new keyword?
	INICopy(infile, outfile, 0xFFFFFFF); // Write out rest of file
	ActualFileClose(infile);
	infile = ACTUALHANDLENULL;
	ActualFileClose(outfile);
	outfile = ACTUALHANDLENULL;
	ActualFileDelete(inname);
	ActualFileRename(outname, inname);
	return (0);
} // END INISaveString()
예제 #4
0
파일: ini.c 프로젝트: Codyle/pcsx2
int INIRemove(char *file, char *section, char *keyword)
{
	char inname[INIMAXLEN + 1];
	char outname[INIMAXLEN + 1];
	int filepos;
	ACTUALHANDLE infile;
	ACTUALHANDLE outfile;
	char templine[INIMAXLEN + 1];
	int i;
	int retval;
	if (file == NULL)  return (-1);
	if (section == NULL)  return (-1);
#ifdef VERBOSE_FUNCTION_INI
	PrintLog("CDVDiso ini: Remove(%s, %s, %s)",
	         file, section, keyword);
#endif /* VERBOSE_FUNCTION_INI */
	filepos = INIRemoveExt(file, inname);
	for (i = 0; i <= filepos; i++)  outname[i] = inname[i];
	INIAddInExt(inname, filepos);
	INIAddOutExt(outname, filepos);
	infile = ActualFileOpenForRead(inname);
	if (infile == ACTUALHANDLENULL)  return (-1);
	retval = INIFindSection(infile, section);
	if (retval == -1) {
		ActualFileClose(infile);
		infile = ACTUALHANDLENULL;
		return (-1);
	} // ENDIF- Couldn't even find the section? Abort
	filepos = retval;
	if (keyword == NULL) {
#ifdef VERBOSE_FUNCTION_INI
		PrintLog("CDVDiso ini:   removing section");
#endif /* VERBOSE_FUNCTION_INI */
		outfile = ActualFileOpenForWrite(outname);
		if (outfile == ACTUALHANDLENULL) {
			ActualFileClose(infile);
			infile = ACTUALHANDLENULL;
			return (-1);
		} // ENDIF- Couldn't open a temp file? Abort
		ActualFileSeek(infile, 0);
		retval = INICopy(infile, outfile, filepos);
		if (retval > 0) {
			ActualFileClose(infile);
			infile = ACTUALHANDLENULL;
			ActualFileClose(outfile);
			outfile = ACTUALHANDLENULL;
			ActualFileDelete(outname);
			return (-1);
		} // ENDIF- Trouble writing everything up to the section? Abort.
		templine[0] = 0;
		retval = 1;
		while ((retval > 0) && (templine[0] != '['))
			retval = INIReadLine(infile, templine); // ENDWHILE- Read to the start of the next section... or EOF.
		if (templine[0] == '[') {
			i = 0;
			while ((i < INIMAXLEN) && (templine[i] != 0)) i++;
			retval = ActualFileWrite(outfile, i, templine);
			if (retval < i) {
				ActualFileClose(infile);
				infile = ACTUALHANDLENULL;
				ActualFileClose(outfile);
				outfile = ACTUALHANDLENULL;
				ActualFileDelete(outname);
				return (-1);
			} // ENDIF- Trouble writing it out? Abort.
		} // ENDIF- Are there other sections after this one? Save them then.
	} else {
		filepos = retval;
		ActualFileSeek(infile, filepos);
		filepos += INIReadLine(infile, templine); // Get section line's byte count
		retval = INIFindKeyword(infile, keyword, NULL);
		if (retval == -1) {
			ActualFileClose(infile);
			infile = ACTUALHANDLENULL;
			return (-1);
		} // ENDIF- Couldn't find the keyword? Abort
		filepos += retval;
#ifdef VERBOSE_FUNCTION_INI
		PrintLog("CDVDiso ini:   removing keyword");
#endif /* VERBOSE_FUNCTION_INI */
		outfile = ActualFileOpenForWrite(outname);
		if (outfile == ACTUALHANDLENULL) {
			ActualFileClose(infile);
			infile = ACTUALHANDLENULL;
			return (-1);
		} // ENDIF- Couldn't open a temp file? Abort
		ActualFileSeek(infile, 0);
		retval = INICopy(infile, outfile, filepos);
		if (retval > 0) {
			ActualFileClose(infile);
			infile = ACTUALHANDLENULL;
			ActualFileClose(outfile);
			outfile = ACTUALHANDLENULL;
			ActualFileDelete(outname);
			return (-1);
		} // ENDIF- Trouble writing everything up to keyword? Abort.
		INIReadLine(infile, templine); // Read (and discard) the keyword line
	} // ENDIF- Wipe out the whole section? Or just a keyword?
	INICopy(infile, outfile, 0xFFFFFFF); // Write out rest of file
	ActualFileClose(infile);
	infile = ACTUALHANDLENULL;
	ActualFileClose(outfile);
	outfile = ACTUALHANDLENULL;
	ActualFileDelete(inname);
	ActualFileRename(outname, inname);
	return (0);
} // END INIRemove()
예제 #5
0
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()