コード例 #1
0
ファイル: GameSavedFile.cpp プロジェクト: lweberk/s25client
/**
 *
 *  @author OLiver
 */
bool SavedFile::ValidateFile(BinaryFile& file, unsigned int signature_length, const char* signature, unsigned short version)
{
    char read_signature[32];

    file.ReadRawData(read_signature, signature_length);

    // Signatur überprüfen
    if(memcmp(read_signature, signature, signature_length))
    {
        // unterscheiden sich! --> raus
        LOG.lprintf("SavedFile::Load: ERROR: Not a valid file!\n");
        return false;
    }

    // Programmversion überspringen
    file.Seek(8, SEEK_CUR);

    // Version überprüfen
    unsigned short read_version = file.ReadUnsignedShort();
    if(read_version != version)
    {
        // anderes Dateiformat --> raus
        LOG.lprintf("SavedFile::Load: ERROR: Old file version (version: %u; expected: %u)!\n", read_version, version);
        return false;
    }

    return true;
}
コード例 #2
0
bool SavedFile::ValidateFile(BinaryFile& file, unsigned int signature_length, const char* signature, unsigned short version)
{
    char read_signature[32];

    file.ReadRawData(read_signature, signature_length);

    // Signatur überprüfen
    if(memcmp(read_signature, signature, signature_length) != 0)
    {
        // unterscheiden sich! --> raus
        LOG.lprintf("Error: File is not in a valid format! File path: %s\n", file.getFilePath().c_str());
        return false;
    }

    // Programmversion überspringen
    file.Seek(8, SEEK_CUR);

    // Version überprüfen
    unsigned short read_version = file.ReadUnsignedShort();
    if(read_version != version)
    {
        // anderes Dateiformat --> raus
        LOG.lprintf("Warning: File has an old version and cannot be used (version: %u; expected: %u, file path: %s)!\n", read_version, version, file.getFilePath().c_str());
        return false;
    }

    return true;
}