Example #1
0
int
main(int argc, char *argv[]) {
    Archive *archive;
    char dataname[1024];
    int i;

    if (argc != 2) {
        printf("Usage: ndxdec <datfile>\n");
        return 1;
    }

    archive = archive_ndx_open(argv[1]);

    for (i = 0; i < archive->size; ++i) {
        int size = 0;
        Uint8 *data = 0;
        FILE *out;

        if (archive_data_size(archive, i) > 0)
            data = decompress_ndxarchive(archive, i, &size);

        snprintf(dataname, sizeof(dataname), "%s.%03d", argv[1], i);
        if ((out = fopen(dataname, "wb")) == NULL) {
            perror(dataname);
            exit(1);
        }
        fwrite(data, 1, size, out);
        fclose(out);
        free(data);
    }

    archive_close(archive);

    return 0;
}
Example #2
0
void CFileListView::CloseArchive()
{
	if(m_pArchive != NULL)
	{
		DeleteAllItems();

		archive_close(m_pArchive);
		m_pArchive = NULL;

		m_FileStack.clear();
		m_FileList.Chlids.clear();

		if(m_pParent != NULL)
		{
			HWND hWnd = GetDlgItem(m_pParent->GetWnd(), IDC_STATUS_TEXT);
			if(IsWindow(hWnd))
				::SetWindowText(hWnd, "");

			m_pParent->SetWindowText("JArchiveEditor");
		}
	}
}
Example #3
0
int split_rom_load(struct emu *emu, const char *filename, struct rom **romptr)
{
	struct archive *archive;
	uint8_t *buffer;
	size_t size;
	struct rom_info *rom_info;
	struct rom *rom;
	int *chip_list;
	int i;

	if (!romptr)
		return -1;

	chip_list = NULL;

	*romptr = NULL;

	if (archive_open(&archive, filename))
		return -1;

	chip_list = malloc(archive->file_list->count * sizeof(*chip_list));
	if (!chip_list)
		return -1;

	rom_info = NULL;
	rom = NULL;
	buffer = NULL;
	do {
		rom_info = db_lookup_split_rom(archive, chip_list, rom_info);
		if (!rom_info)
			break;

		if (load_split_rom_parts(archive, chip_list, rom_info, &buffer,
		                         &size)) {
			break;
		}

		if (!buffer)
			continue;

		rom = rom_alloc(filename, buffer, size);
		if (!rom)
			break;

		/* Store the filename of the first PRG chip as the empty string;
		   this allows patches to be included with split roms as well,
		   but they need to be located in the top-level directory of the
		   archive.
		*/
		rom->compressed_filename = strdup("");

		buffer = NULL;
		memcpy(&rom->info, rom_info, sizeof(*rom_info));
		if (rom_info->name)
			rom->info.name = strdup(rom_info->name);
		else
			rom->info.name = NULL;

		rom->offset = INES_HEADER_SIZE;
		rom_calculate_checksum(rom);

		for (i = 0; i < archive->file_list->count; i++) {
			char *basename;

			if (!archive->file_list->entries[i].name)
				continue;

			basename = strrchr(archive->file_list->entries[i].name, '/');
			if (!basename)
				basename = archive->file_list->entries[i].name;

			/* Hack for PlayChoice ROMs; most of these are the same as NES
			   carts, so check for a file called 'security.prm' to distinguish
			   them.
			*/
			if (!strcasecmp(basename, "security.prm")) {
				if (rom->info.flags & ROM_FLAG_PLAYCHOICE)
					rom->info.system_type = EMU_SYSTEM_TYPE_PLAYCHOICE;
			}
		}

		/* Validate individual chip CRCs or SHA1s if present, then
		   the combined CRC and/or SHA1, if present.
		*/
		if (!validate_checksums(rom, rom_info))
			goto invalid;

		if ((rom->info.flags & ROM_FLAG_HAS_CRC) &&
		    (rom->info.combined_crc != rom_info->combined_crc)) {
			goto invalid;
		}

		if ((rom->info.flags & ROM_FLAG_HAS_SHA1) &&
		    memcmp(rom->info.combined_sha1, rom_info->combined_sha1, 20)) {
			goto invalid;
		}
		
		break;

	invalid:
		rom_free(rom);
		rom = NULL;
	} while (rom_info);

	archive_close(&archive);

	if (chip_list)
		free(chip_list);

	if (buffer)
		free(buffer);

	if (!rom)
		return -1;

	*romptr = rom;

	return 0;

}
Example #4
0
CFileListView::~CFileListView(void)
{
	if(m_pArchive != NULL)
		archive_close(m_pArchive);
}