Example #1
0
// Look for new file names in the provided file, and add them to the end of the list.
bool SearchForNewFiles(TFileList &fileList, const char *pFileName)
{
	// Don't search in .wav's and .pcx's for other files
	AnsiString fileExt = ExtractFileExt(AnsiString(pFileName));
	if ((fileExt.AnsiCompareIC(".WAV") == 0) ||
		(fileExt.AnsiCompareIC(".PCX") == 0))
		return true;

	string sResult;

	sResult = "Searching in file ";
	sResult += pFileName;
	OutputResult(sResult.begin());

	FILE *fin = fopen(pFileName, "rb");
	if(!fin) {
        string sError = "** Unable to open file ";
        sError += pFileName;
		OutputResult(sError.begin(), true);
		return false;
	}

	// Get file size
	fseek(fin, 0, SEEK_END);
	int fileLen = ftell(fin);
	fseek(fin, 0, SEEK_SET);

	// Read in entire file
    vector<char> fileBuf(fileLen + 20);
    if(!fileBuf.capacity()) {
        fclose(fin);
        OutputResult("** Error allocating memory", true);
        return false;
    }
    fileBuf.resize(fileLen);
    fread(fileBuf.begin(), 1, fileLen, fin);
    fclose(fin);

    SetCurrentFile(pFileName);

    // Process it
    SearchInFileBuffer(fileList, fileBuf);

    return true;
}