예제 #1
0
파일: isofile.c 프로젝트: madnessw/thesnow
int IsoFileSeek(struct IsoFile *file, off64_t sector)
{
	int retval;
	if (file == NULL)  return(-1);
	if (sector < 0)  return(-1);

	if (sector == file->sectorpos)  return(0);

#ifdef VERBOSE_FUNCTION_ISOFILE
	PrintLog("CDVD isofile: IsoFileSeek(%llu)", sector);
#endif /* VERBOSE_FUNCTION_ISOFILE */

	if (file->multi > 0)
	{
		retval = MultiFileSeek(file, sector);
	}
	else if (file->compress > 0)
	{
		retval = CompressSeek(file, sector);
	}
	else
	{
		retval = ActualFileSeek(file->handle,
		                        (sector * file->blocksize) + file->imageheader);
		if (retval == 0)
		{
			file->filesectorpos = sector;
			file->filebytepos = (sector * file->blocksize) + file->imageheader;
		} // ENDIF- Succeeded? Adjust internal pointers
	} // ENDLONGIF- Seek right file? Or compressed block? Or Raw block?
	if (retval < 0)
	{
#ifdef VERBOSE_FUNCTION_ISOFILE
		PrintLog("CDVD isofile:   Trouble finding the sector!");
#endif /* VERBOSE_FUNCTION_ISOFILE */
		return(-1);
	} // ENDIF- Trouble reading the block? Say so!

	file->sectorpos = sector;
	return(0);
} // END IsoFileSeek()
예제 #2
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()
예제 #3
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()
예제 #4
0
int DetectImageType(struct IsoFile *isofile) {

    char comparestr[] = "CD001";

    int newtype;

    off64_t targetpos;

    char teststr[2448];

    int dataoffset;

    int i;

    int retval;



    newtype = 0;

    if(isofile->compress > 0) {

        IsoFileSeek(isofile, 16);

        IsoFileRead(isofile, teststr);



        while(imagedata[newtype].name != NULL) {

            if((isofile->blocksize == imagedata[newtype].blocksize) &&

                    (isofile->imageheader == imagedata[newtype].fileoffset)) {

                dataoffset = imagedata[newtype].dataoffset + 1;

                i = 0;

                while((i < 5) && (teststr[dataoffset + i] == comparestr[i])) i++;

                if(i == 5) {

                    GetImageType(isofile, newtype);

                    return(newtype);

                } // ENDIF- Did we find a match?

            } // ENDIF- Do these pieces match the compression storage pieces?

            newtype++;

        } // ENDWHILE- looking for the image type that fits the stats



    } else {

        while(imagedata[newtype].name != NULL) {

            targetpos = (16 * imagedata[newtype].blocksize)

                        + imagedata[newtype].fileoffset

                        + imagedata[newtype].dataoffset

                        + 1; // Moves to start of string

            retval = ActualFileSeek(isofile->handle, targetpos);

            if(retval == 0) {

                retval = ActualFileRead(isofile->handle, 5, teststr);

                if(retval == 5) {

                    i = 0;

                    while((i < 5) && (teststr[i] == comparestr[i]))  i++;

                    if(i == 5) {

                        ActualFileSeek(isofile->handle, isofile->imageheader);

                        GetImageType(isofile, newtype);

                        return(newtype);

                    } // ENDIF- Did we find a match?

                } // ENDIF- Could we read in the test string? Cool! Test it.

            } // ENDIF- Could actually get to this point?

            newtype++;

        } // ENDWHILE- looking for the directory header string "CD001"

        ActualFileSeek(isofile->handle, isofile->imageheader);

    } // ENDIF- Do we match type to compression stats? (Or search against raw data?)



    GetImageType(isofile, REDBOOK2352);

    return(REDBOOK2352); // Couldn't find it? Guess it's RAW 2352, then. (Audio CD?)

} // END ImageDetect()