Пример #1
0
int CacheList::reg(char const *filename, char const *name, int type, int rm_dups)
{
    int fn = crc_manager.get_filenumber(filename);
    int offset = 0;

    if (type == SPEC_EXTERN_SFX)
    {
    	// Missing sound effect is not a critical error, so we don't
    	// quit when error happens.
        bFILE *check = open_file(filename, "rb");
        if (!check->open_failure())
        {
        	printf("Unable to open sfx file '%s' for reading, ignoring.\n", filename);
        }
        delete check;
    }
    else
    {
        // If a classic spec item, look for it in the archive.
        spec_directory *sd = sd_cache.get_spec_directory(filename);

        if (!sd)
        {
            printf("Unable to open file %s for item %s\n", filename, name);
            assert(false);
            exit(0);
        }

        spec_entry *se = NULL;
        if (type != -1)
            se = sd->find(name, type);
        if (!se)
            se = sd->find(name);
        if (!se)
        {
            printf("No such item %s in file %s\n", name, filename);
            assert(false);
            exit(0);
        }

        if (type >= 0 && type != se->type &&
             ((type != SPEC_CHARACTER2 && type != SPEC_CHARACTER)
               || (se->type != SPEC_CHARACTER && se->type != SPEC_CHARACTER2)))
        {
            printf("Item %s of file %s should be type %s\n",
                   name, filename, spec_types[type]);
            assert(false);
            exit(0);
        }

        type = se->type;
        offset = se->offset;
    }

    // Check whether there is another entry pointing to the same
    // file and offset, and return it as a shortcut.
    if (rm_dups)
    {
        for (int i = 0; i < total; i++)
            if (list[i].file_number == fn && list[i].offset == offset)
                return i;
    }

    int id = AllocId();

    CHECK(id < total && list[id].file_number < 0);

    list[id].file_number = fn;
    list[id].last_access = -1;
    list[id].data = NULL;
    list[id].offset = offset;
    list[id].type = type;

    return id;
}
Пример #2
0
int CacheList::reg(char const *filename, char const *name, int type,
		int rm_dups) {
	int fn = crc_manager.get_filenumber(filename);
	int offset = 0;

	if (type == SPEC_EXTERN_SFX) {
		// If an extern sound effect then just make sure it's there. If sound
		// is disabled, ignore the load error, just pretend it's all OK.
		bFILE *check = open_file(filename, "rb");
		if (!check->open_failure()) {
			char buf[4];
			check->read(buf, 4);
			if (memcmp(buf, "RIFF", 4)) {
				printf("File %s is not a WAV file\n", filename);
				exit(0);
			}
		} else if (sound_avail) {
			printf("Unable to open file '%s' for reading\n", filename);
			exit(0);
		}
		delete check;
	} else {
		// If a classic spec item, look for it in the archive.
		spec_directory *sd = sd_cache.get_spec_directory(filename);

		if (!sd) {
			printf("Unable to open file %s for item %s\n", filename, name);
			exit(0);
		}

		spec_entry *se = NULL;
		if (type != -1)
			se = sd->find(name, type);
		if (!se)
			se = sd->find(name);
		if (!se) {
			printf("No such item %s in file %s\n", name, filename);
			exit(0);
		}

		if (type >= 0 && type != se->type
				&& ((type != SPEC_CHARACTER2 && type != SPEC_CHARACTER)
						|| (se->type != SPEC_CHARACTER
								&& se->type != SPEC_CHARACTER2))) {
			printf("Item %s of file %s should be type %s\n", name, filename,
					spec_types[type]);
			exit(0);
		}

		type = se->type;
		offset = se->offset;
	}

	// Check whether there is another entry pointing to the same
	// file and offset, and return it as a shortcut.
	if (rm_dups) {
		for (int i = 0; i < total; i++)
			if (list[i].file_number == fn && list[i].offset == offset)
				return i;
	}

	int id = AllocId();

	CHECK(id < total && list[id].file_number < 0);

	list[id].file_number = fn;
	list[id].last_access = -1;
	list[id].data = NULL;
	list[id].offset = offset;
	list[id].type = type;

	return id;
}