Example #1
0
File: chd_cd.c Project: bji/libmame
static DEVICE_IMAGE_LOAD(cdrom)
{
	dev_cdrom_t	*cdrom = get_safe_token(&image.device());
	chd_error	err = (chd_error)0;
	chd_file	*chd = NULL;
	astring tempstring;

	if (image.software_entry() == NULL)
	{
		err = chd_open_file( image.image_core_file(), CHD_OPEN_READ, NULL, &chd );	/* CDs are never writeable */
		if ( err )
			goto error;
	} else {
		chd  = get_disk_handle(image.device().machine, image.device().subtag(tempstring,"cdrom"));
	}

	/* open the CHD file */
	cdrom->cdrom_handle = cdrom_open( chd );
	if ( ! cdrom->cdrom_handle )
		goto error;

	return IMAGE_INIT_PASS;

error:
	if ( chd )
		chd_close( chd );
	if ( err )
		image.seterror( IMAGE_ERROR_UNSPECIFIED, chd_get_error_string( err ) );
	return IMAGE_INIT_FAIL;
}
Example #2
0
static chd_file *get_disc(const device_config *device)
{
	mame_file *image_file = NULL;
	chd_file *image_chd = NULL;
	mame_path *path;

	/* open a path to the ROMs and find the first CHD file */
	path = mame_openpath(mame_options(), OPTION_ROMPATH);
	if (path != NULL)
	{
		const osd_directory_entry *dir;

		/* iterate while we get new objects */
		while ((dir = mame_readpath(path)) != NULL)
		{
			int length = strlen(dir->name);

			/* look for files ending in .chd */
			if (length > 4 &&
				dir->name[length - 4] == '.' &&
				tolower(dir->name[length - 3]) == 'c' &&
				tolower(dir->name[length - 2]) == 'h' &&
				tolower(dir->name[length - 1]) == 'd')
			{
				file_error filerr;
				chd_error chderr;

				/* open the file itself via our search path */
				filerr = mame_fopen(SEARCHPATH_IMAGE, dir->name, OPEN_FLAG_READ, &image_file);
				if (filerr == FILERR_NONE)
				{
					/* try to open the CHD */
					chderr = chd_open_file(mame_core_file(image_file), CHD_OPEN_READ, NULL, &image_chd);
					if (chderr == CHDERR_NONE)
					{
						set_disk_handle(device->machine, "laserdisc", image_file, image_chd);
						filename = astring_dupc(dir->name);
						add_exit_callback(device->machine, free_string);
						break;
					}

					/* close the file on failure */
					mame_fclose(image_file);
					image_file = NULL;
				}
			}
		}
		mame_closepath(path);
	}

	/* if we failed, pop a message and exit */
	if (image_file == NULL)
		fatalerror("No valid image file found!\n");

	return get_disk_handle(device->machine, "laserdisc");
}
Example #3
0
int harddisk_image_device::internal_load_hd(const char *metadata)
{
	chd_error		err = (chd_error)0;
	int				is_writeable;

	/* open the CHD file */
	do
	{
		is_writeable = !is_readonly();
		m_chd = NULL;
		err = chd_open_file(image_core_file(), is_writeable ? CHD_OPEN_READWRITE : CHD_OPEN_READ, NULL, &m_chd);

		/* special case; if we get CHDERR_FILE_NOT_WRITEABLE, make the
         * image read only and repeat */
		if (err == CHDERR_FILE_NOT_WRITEABLE)
			make_readonly();
	}
	while(!m_chd && is_writeable && (err == CHDERR_FILE_NOT_WRITEABLE));
	if (!m_chd)
		goto done;

	/* if we created the image and hence, have metadata to set, set the metadata */
	if (metadata)
	{
		err = chd_set_metadata(m_chd, HARD_DISK_METADATA_TAG, 0, metadata, strlen(metadata) + 1, 0);
		if (err != CHDERR_NONE)
			goto done;
	}

	/* open the hard disk file */
	m_hard_disk_handle = hard_disk_open(m_chd);
	if (!m_hard_disk_handle)
		goto done;

done:
	if (err)
	{
		/* if we had an error, close out the CHD */
		if (m_chd != NULL)
		{
			chd_close(m_chd);
			m_chd = NULL;
		}

		seterror(IMAGE_ERROR_UNSPECIFIED, chd_get_error_string(err));
	}
	return err ? IMAGE_INIT_FAIL : IMAGE_INIT_PASS;
}
Example #4
0
chd_file *ldplayer_state::get_disc()
{
	// open a path to the ROMs and find the first CHD file
	file_enumerator path(machine().options().media_path());

	// iterate while we get new objects
	const osd_directory_entry *dir;
	emu_file *image_file = NULL;
	chd_file *image_chd = NULL;
	while ((dir = path.next()) != NULL)
	{
		int length = strlen(dir->name);

		// look for files ending in .chd
		if (length > 4 &&
			dir->name[length - 4] == '.' &&
			tolower(dir->name[length - 3]) == 'c' &&
			tolower(dir->name[length - 2]) == 'h' &&
			tolower(dir->name[length - 1]) == 'd')
		{
			// open the file itself via our search path
			image_file = auto_alloc(machine(), emu_file(machine().options().media_path(), OPEN_FLAG_READ));
			file_error filerr = image_file->open(dir->name);
			if (filerr == FILERR_NONE)
			{
				// try to open the CHD
				chd_error chderr = chd_open_file(*image_file, CHD_OPEN_READ, NULL, &image_chd);
				if (chderr == CHDERR_NONE)
				{
					set_disk_handle(machine(), "laserdisc", *image_file, *image_chd);
					m_filename.cpy(dir->name);
					break;
				}
			}

			// close the file on failure
			auto_free(machine(), image_file);
			image_file = NULL;
		}
	}

	// if we failed, pop a message and exit
	if (image_file == NULL)
		throw emu_fatalerror("No valid image file found!\n");

	return get_disk_handle(machine(), "laserdisc");
}