Пример #1
0
void emu_file::close()
{
	// close files and free memory
	if (m__7zfile != nullptr)
		_7z_file_close(m__7zfile);
	m__7zfile = nullptr;

	if (m_zipfile != nullptr)
		zip_file_close(m_zipfile);
	m_zipfile = nullptr;

	if (m_file != nullptr)
		core_fclose(m_file);
	m_file = nullptr;

	m__7zdata.clear();
	m_zipdata.clear();

	if (m_remove_on_close)
		osd_rmfile(m_fullpath.c_str());
	m_remove_on_close = false;

	// reset our hashes and path as well
	m_hashes.reset();
	m_fullpath.clear();
}
Пример #2
0
void emu_file::close()
{
    // close files and free memory
    if (m__7zfile != NULL)
        _7z_file_close(m__7zfile);
    m__7zfile = NULL;

    if (m_zipfile != NULL)
        zip_file_close(m_zipfile);
    m_zipfile = NULL;

    if (m_file != NULL)
        core_fclose(m_file);
    m_file = NULL;

    m__7zdata.reset();
    m_zipdata.reset();

    if (m_remove_on_close)
        osd_rmfile(m_fullpath);
    m_remove_on_close = false;

    // reset our hashes and path as well
    m_hashes.reset();
    m_fullpath.reset();
}
Пример #3
0
static int rmdir_recursive(const char *dir_path)
{
	osd_directory *dir;
	const osd_directory_entry *ent;
	osd_directory_entry *ent2;
	char *newpath;

	dir = osd_opendir(dir_path);
	if (dir)
	{
		while((ent = osd_readdir(dir)) != NULL)
		{
			if (strcmp(ent->name, ".") && strcmp(ent->name, ".."))
			{
				newpath = (char*)malloc(strlen(dir_path) + 1 + strlen(ent->name) + 1);
				if (!newpath)
					return -1;

				strcpy(newpath, dir_path);
				strcat(newpath, PATH_SEPARATOR);
				strcat(newpath, ent->name);

				ent2 = osd_stat(newpath);
				if (ent2)
				{
					if (ent2->type == ENTTYPE_DIR)
						rmdir_recursive(newpath);
					else
						osd_rmfile(newpath);
					free(ent2);
				}
				free(newpath);
			}
		}
		osd_closedir(dir);
	}
	osd_rmdir(dir_path);
	return 0;
}
Пример #4
0
void running_machine::handle_saveload()
{
	UINT32 openflags = (m_saveload_schedule == SLS_LOAD) ? OPEN_FLAG_READ : (OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
	const char *opnamed = (m_saveload_schedule == SLS_LOAD) ? "loaded" : "saved";
	const char *opname = (m_saveload_schedule == SLS_LOAD) ? "load" : "save";
	file_error filerr = FILERR_NONE;

	/* if no name, bail */
	if (m_saveload_pending_file.len() == 0)
		goto cancel;

	/* if there are anonymous timers, we can't save just yet, and we can't load yet either
	   because the timers might overwrite data we have loaded */
	if (timer_count_anonymous(this) > 0)
	{
		/* if more than a second has passed, we're probably screwed */
		if (attotime_sub(timer_get_time(this), m_saveload_schedule_time).seconds > 0)
		{
			popmessage("Unable to %s due to pending anonymous timers. See error.log for details.", opname);
			goto cancel;
		}
		return;
	}

	/* open the file */
	mame_file *file;
	filerr = mame_fopen(m_saveload_searchpath, m_saveload_pending_file, openflags, &file);
	if (filerr == FILERR_NONE)
	{
		astring fullname(mame_file_full_name(file));

		/* read/write the save state */
		state_save_error staterr = (m_saveload_schedule == SLS_LOAD) ? state_save_read_file(this, file) : state_save_write_file(this, file);

		/* handle the result */
		switch (staterr)
		{
			case STATERR_ILLEGAL_REGISTRATIONS:
				popmessage("Error: Unable to %s state due to illegal registrations. See error.log for details.", opname);
				break;

			case STATERR_INVALID_HEADER:
				popmessage("Error: Unable to %s state due to an invalid header. Make sure the save state is correct for this game.", opname);
				break;

			case STATERR_READ_ERROR:
				popmessage("Error: Unable to %s state due to a read error (file is likely corrupt).", opname);
				break;

			case STATERR_WRITE_ERROR:
				popmessage("Error: Unable to %s state due to a write error. Verify there is enough disk space.", opname);
				break;

			case STATERR_NONE:
				if (!(m_game.flags & GAME_SUPPORTS_SAVE))
					popmessage("State successfully %s.\nWarning: Save states are not officially supported for this game.", opnamed);
				else
					popmessage("State successfully %s.", opnamed);
				break;

			default:
				popmessage("Error: Unknown error during state %s.", opnamed);
				break;
		}

		/* close and perhaps delete the file */
		mame_fclose(file);
		if (staterr != STATERR_NONE && m_saveload_schedule == SLS_SAVE)
			osd_rmfile(fullname);
	}
	else
		popmessage("Error: Failed to open file for %s operation.", opname);

	/* unschedule the operation */
cancel:
	m_saveload_pending_file.reset();
	m_saveload_searchpath = NULL;
	m_saveload_schedule = SLS_NONE;
}
Пример #5
0
static int generate_png_diff(const summary_file *curfile, astring &destdir, const char *destname)
{
	bitmap_argb32 bitmaps[MAX_COMPARES];
	astring srcimgname;
	astring dstfilename;
	astring tempname;
	bitmap_argb32 finalbitmap;
	int width, height, maxwidth;
	int bitmapcount = 0;
	int listnum, bmnum;
	core_file *file = NULL;
	file_error filerr;
	png_error pngerr;
	int error = -1;
	int starty;

	/* generate the common source filename */
	dstfilename.printf("%s" PATH_SEPARATOR "%s", destdir.c_str(), destname);
	srcimgname.printf("snap" PATH_SEPARATOR "%s" PATH_SEPARATOR "final.png", curfile->name);

	/* open and load all unique bitmaps */
	for (listnum = 0; listnum < list_count; listnum++)
		if (curfile->matchbitmap[listnum] == listnum)
		{
			tempname.printf("%s" PATH_SEPARATOR "%s", lists[listnum].dir, srcimgname.c_str());

			/* open the source image */
			filerr = core_fopen(tempname.c_str(), OPEN_FLAG_READ, &file);
			if (filerr != FILERR_NONE)
				goto error;

			/* load the source image */
			pngerr = png_read_bitmap(file, bitmaps[bitmapcount++]);
			core_fclose(file);
			if (pngerr != PNGERR_NONE)
				goto error;
		}

	/* if there's only one unique bitmap, skip it */
	if (bitmapcount <= 1)
		goto error;

	/* determine the size of the final bitmap */
	height = width = 0;
	maxwidth = bitmaps[0].width();
	for (bmnum = 1; bmnum < bitmapcount; bmnum++)
	{
		int curwidth;

		/* determine the maximal width */
		maxwidth = MAX(maxwidth, bitmaps[bmnum].width());
		curwidth = bitmaps[0].width() + BITMAP_SPACE + maxwidth + BITMAP_SPACE + maxwidth;
		width = MAX(width, curwidth);

		/* add to the height */
		height += MAX(bitmaps[0].height(), bitmaps[bmnum].height());
		if (bmnum != 1)
			height += BITMAP_SPACE;
	}

	/* allocate the final bitmap */
	finalbitmap.allocate(width, height);

	/* now copy and compare each set of bitmaps */
	starty = 0;
	for (bmnum = 1; bmnum < bitmapcount; bmnum++)
	{
		bitmap_argb32 &bitmap1 = bitmaps[0];
		bitmap_argb32 &bitmap2 = bitmaps[bmnum];
		int curheight = MAX(bitmap1.height(), bitmap2.height());
		int x, y;

		/* iterate over rows in these bitmaps */
		for (y = 0; y < curheight; y++)
		{
			UINT32 *src1 = (y < bitmap1.height()) ? &bitmap1.pix32(y) : NULL;
			UINT32 *src2 = (y < bitmap2.height()) ? &bitmap2.pix32(y) : NULL;
			UINT32 *dst1 = &finalbitmap.pix32(starty + y, 0);
			UINT32 *dst2 = &finalbitmap.pix32(starty + y, bitmap1.width() + BITMAP_SPACE);
			UINT32 *dstdiff = &finalbitmap.pix32(starty + y, bitmap1.width() + BITMAP_SPACE + maxwidth + BITMAP_SPACE);

			/* now iterate over columns */
			for (x = 0; x < maxwidth; x++)
			{
				int pix1 = -1, pix2 = -2;

				if (src1 != NULL && x < bitmap1.width())
					pix1 = dst1[x] = src1[x];
				if (src2 != NULL && x < bitmap2.width())
					pix2 = dst2[x] = src2[x];
				dstdiff[x] = (pix1 != pix2) ? 0xffffffff : 0xff000000;
			}
		}

		/* update the starting Y position */
		starty += BITMAP_SPACE + MAX(bitmap1.height(), bitmap2.height());
	}

	/* write the final PNG */
	filerr = core_fopen(dstfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
	if (filerr != FILERR_NONE)
		goto error;
	pngerr = png_write_bitmap(file, NULL, finalbitmap, 0, NULL);
	core_fclose(file);
	if (pngerr != PNGERR_NONE)
		goto error;

	/* if we get here, we are error free */
	error = 0;

error:
	if (error)
		osd_rmfile(dstfilename.c_str());
	return error;
}
Пример #6
0
static int generate_png_diff(const summary_file *curfile, const astring *destdir, const char *destname)
{
	bitmap_t *bitmaps[MAX_COMPARES] = { NULL };
	astring *srcimgname = astring_alloc();
	astring *dstfilename = astring_alloc();
	astring *tempname = astring_alloc();
	bitmap_t *finalbitmap = NULL;
	int width, height, maxwidth;
	int bitmapcount = 0;
	int listnum, bmnum;
	core_file *file = NULL;
	file_error filerr;
	png_error pngerr;
	int error = -1;
	int starty;

	/* generate the common source filename */
	astring_printf(dstfilename, "%s" PATH_SEPARATOR "%s", astring_c(destdir), destname);
	astring_printf(srcimgname, "snap" PATH_SEPARATOR "%s" PATH_SEPARATOR "final.png", curfile->name);

	/* open and load all unique bitmaps */
	for (listnum = 0; listnum < list_count; listnum++)
		if (curfile->matchbitmap[listnum] == listnum)
		{
			astring_printf(tempname, "%s" PATH_SEPARATOR "%s", lists[listnum].dir, astring_c(srcimgname));

			/* open the source image */
			filerr = core_fopen(astring_c(tempname), OPEN_FLAG_READ, &file);
			if (filerr != FILERR_NONE)
				goto error;

			/* load the source image */
			pngerr = png_read_bitmap(file, &bitmaps[bitmapcount++]);
			core_fclose(file);
			if (pngerr != PNGERR_NONE)
				goto error;
		}

	/* if there's only one unique bitmap, skip it */
	if (bitmapcount <= 1)
		goto error;

	/* determine the size of the final bitmap */
	height = width = 0;
	maxwidth = bitmaps[0]->width;
	for (bmnum = 1; bmnum < bitmapcount; bmnum++)
	{
		int curwidth;

		/* determine the maximal width */
		maxwidth = MAX(maxwidth, bitmaps[bmnum]->width);
		curwidth = bitmaps[0]->width + BITMAP_SPACE + maxwidth + BITMAP_SPACE + maxwidth;
		width = MAX(width, curwidth);

		/* add to the height */
		height += MAX(bitmaps[0]->height, bitmaps[bmnum]->height);
		if (bmnum != 1)
			height += BITMAP_SPACE;
	}

	/* allocate the final bitmap */
	finalbitmap = bitmap_alloc(width, height, BITMAP_FORMAT_ARGB32);
	if (finalbitmap == NULL)
		goto error;

	/* now copy and compare each set of bitmaps */
	starty = 0;
	for (bmnum = 1; bmnum < bitmapcount; bmnum++)
	{
		bitmap_t *bitmap1 = bitmaps[0];
		bitmap_t *bitmap2 = bitmaps[bmnum];
		int curheight = MAX(bitmap1->height, bitmap2->height);
		int x, y;

		/* iterate over rows in these bitmaps */
		for (y = 0; y < curheight; y++)
		{
			UINT32 *src1 = (y < bitmap1->height) ? BITMAP_ADDR32(bitmap1, y, 0) : NULL;
			UINT32 *src2 = (y < bitmap2->height) ? BITMAP_ADDR32(bitmap2, y, 0) : NULL;
			UINT32 *dst1 = BITMAP_ADDR32(finalbitmap, starty + y, 0);
			UINT32 *dst2 = BITMAP_ADDR32(finalbitmap, starty + y, bitmap1->width + BITMAP_SPACE);
			UINT32 *dstdiff = BITMAP_ADDR32(finalbitmap, starty + y, bitmap1->width + BITMAP_SPACE + maxwidth + BITMAP_SPACE);

			/* now iterate over columns */
			for (x = 0; x < maxwidth; x++)
			{
				int pix1 = -1, pix2 = -2;

				if (src1 != NULL && x < bitmap1->width)
					pix1 = dst1[x] = src1[x];
				if (src2 != NULL && x < bitmap2->width)
					pix2 = dst2[x] = src2[x];
				dstdiff[x] = (pix1 != pix2) ? 0xffffffff : 0xff000000;
			}
		}

		/* update the starting Y position */
		starty += BITMAP_SPACE + MAX(bitmap1->height, bitmap2->height);
	}

	/* write the final PNG */
	filerr = core_fopen(astring_c(dstfilename), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
	if (filerr != FILERR_NONE)
		goto error;
	pngerr = png_write_bitmap(file, NULL, finalbitmap, 0, NULL);
	core_fclose(file);
	if (pngerr != PNGERR_NONE)
		goto error;

	/* if we get here, we are error free */
	error = 0;

error:
	if (finalbitmap != NULL)
		bitmap_free(finalbitmap);
	for (bmnum = 0; bmnum < bitmapcount; bmnum++)
		if (bitmaps[bmnum] != NULL)
			bitmap_free(bitmaps[bmnum]);
	if (error)
		osd_rmfile(astring_c(dstfilename));
	astring_free(dstfilename);
	astring_free(srcimgname);
	astring_free(tempname);
	return error;
}
Пример #7
0
static bool render_font_save_cached(render_font &font, const char *filename, UINT32 hash)
{
	// attempt to open the file
	core_file *file;
	file_error filerr = core_fopen(filename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
	if (filerr != FILERR_NONE)
		return true;

	try
	{
		// determine the number of characters
		int numchars = 0;
		for (int chnum = 0; chnum < 65536; chnum++)
			if (font.chars[chnum].width > 0)
				numchars++;

		// write the header
		dynamic_buffer tempbuffer(65536);
		UINT8 *dest = &tempbuffer[0];
		*dest++ = 'f';
		*dest++ = 'o';
		*dest++ = 'n';
		*dest++ = 't';
		*dest++ = hash >> 24;
		*dest++ = hash >> 16;
		*dest++ = hash >> 8;
		*dest++ = hash & 0xff;
		*dest++ = font.height >> 8;
		*dest++ = font.height & 0xff;
		*dest++ = font.yoffs >> 8;
		*dest++ = font.yoffs & 0xff;
		*dest++ = numchars >> 24;
		*dest++ = numchars >> 16;
		*dest++ = numchars >> 8;
		*dest++ = numchars & 0xff;
		write_data(*file, tempbuffer, dest);

		// write the empty table to the beginning of the file
		dynamic_buffer chartable(numchars * CACHED_CHAR_SIZE + 1, 0);
		write_data(*file, &chartable[0], &chartable[numchars * CACHED_CHAR_SIZE]);

		// loop over all characters
		int tableindex = 0;
		for (int chnum = 0; chnum < 65536; chnum++)
		{
			render_font_char &ch = font.chars[chnum];
			if (ch.width > 0)
			{
				// write out a bit-compressed bitmap if we have one
				if (ch.bitmap != NULL)
				{
					// write the data to the tempbuffer
					dest = tempbuffer;
					UINT8 accum = 0;
					UINT8 accbit = 7;

					// bit-encode the character data
					for (int y = 0; y < ch.bmheight; y++)
					{
						int desty = y + font.height + font.yoffs - ch.yoffs - ch.bmheight;
						const UINT32 *src = (desty >= 0 && desty < font.height) ? &ch.bitmap->pix32(desty) : NULL;
						for (int x = 0; x < ch.bmwidth; x++)
						{
							if (src != NULL && src[x] != 0)
								accum |= 1 << accbit;
							if (accbit-- == 0)
							{
								*dest++ = accum;
								accum = 0;
								accbit = 7;
							}
						}
					}

					// flush any extra
					if (accbit != 7)
						*dest++ = accum;

					// write the data
					write_data(*file, tempbuffer, dest);

					// free the bitmap and texture
					global_free(ch.bitmap);
					ch.bitmap = NULL;
				}

				// compute the table entry
				dest = &chartable[tableindex++ * CACHED_CHAR_SIZE];
				*dest++ = chnum >> 8;
				*dest++ = chnum & 0xff;
				*dest++ = ch.width >> 8;
				*dest++ = ch.width & 0xff;
				*dest++ = ch.xoffs >> 8;
				*dest++ = ch.xoffs & 0xff;
				*dest++ = ch.yoffs >> 8;
				*dest++ = ch.yoffs & 0xff;
				*dest++ = ch.bmwidth >> 8;
				*dest++ = ch.bmwidth & 0xff;
				*dest++ = ch.bmheight >> 8;
				*dest++ = ch.bmheight & 0xff;
			}
		}

		// seek back to the beginning and rewrite the table
		core_fseek(file, CACHED_HEADER_SIZE, SEEK_SET);
		write_data(*file, &chartable[0], &chartable[numchars * CACHED_CHAR_SIZE]);

		// all done
		core_fclose(file);
		return false;
	}
	catch (...)
	{
		core_fclose(file);
		osd_rmfile(filename);
		return true;
	}
}
Пример #8
0
static int generate_png_diff(const astring& imgfile1, const astring& imgfile2, const astring& outfilename)
{
	bitmap_argb32 bitmap1;
	bitmap_argb32 bitmap2;
	bitmap_argb32 finalbitmap;
	int width, height, maxwidth;
	core_file *file = NULL;
	file_error filerr;
	png_error pngerr;
	int error = 100;
	bool bitmaps_differ;
	int x, y;

	/* open the source image */
	filerr = core_fopen(imgfile1, OPEN_FLAG_READ, &file);
	if (filerr != FILERR_NONE)
	{
		printf("Could not open %s (%d)\n", imgfile1.cstr(), filerr);
		goto error;
	}

	/* load the source image */
	pngerr = png_read_bitmap(file, bitmap1);
	core_fclose(file);
	if (pngerr != PNGERR_NONE)
	{
		printf("Could not read %s (%d)\n", imgfile1.cstr(), pngerr);
		goto error;
	}

	/* open the source image */
	filerr = core_fopen(imgfile2, OPEN_FLAG_READ, &file);
	if (filerr != FILERR_NONE)
	{
		printf("Could not open %s (%d)\n", imgfile2.cstr(), filerr);
		goto error;
	}

	/* load the source image */
	pngerr = png_read_bitmap(file, bitmap2);
	core_fclose(file);
	if (pngerr != PNGERR_NONE)
	{
		printf("Could not read %s (%d)\n", imgfile2.cstr(), pngerr);
		goto error;
	}

	/* if the sizes are different, we differ; otherwise start off assuming we are the same */
	bitmaps_differ = (bitmap2.width() != bitmap1.width() || bitmap2.height() != bitmap1.height());

	/* compare scanline by scanline */
	for (y = 0; y < bitmap2.height() && !bitmaps_differ; y++)
	{
		UINT32 *base = &bitmap1.pix32(y);
		UINT32 *curr = &bitmap2.pix32(y);

		/* scan the scanline */
		for (x = 0; x < bitmap2.width(); x++)
			if (*base++ != *curr++)
				break;
		bitmaps_differ = (x != bitmap2.width());
	}

	if (bitmaps_differ)
	{
		/* determine the size of the final bitmap */
		height = width = 0;
		{
			/* determine the maximal width */
			maxwidth = MAX(bitmap1.width(), bitmap2.width());
			width = bitmap1.width() + BITMAP_SPACE + maxwidth + BITMAP_SPACE + maxwidth;

			/* add to the height */
			height += MAX(bitmap1.height(), bitmap2.height());
		}

		/* allocate the final bitmap */
		finalbitmap.allocate(width, height);

		/* now copy and compare each set of bitmaps */
		int curheight = MAX(bitmap1.height(), bitmap2.height());
		/* iterate over rows in these bitmaps */
		for (y = 0; y < curheight; y++)
		{
			UINT32 *src1 = (y < bitmap1.height()) ? &bitmap1.pix32(y) : NULL;
			UINT32 *src2 = (y < bitmap2.height()) ? &bitmap2.pix32(y) : NULL;
			UINT32 *dst1 = &finalbitmap.pix32(y);
			UINT32 *dst2 = &finalbitmap.pix32(y, bitmap1.width() + BITMAP_SPACE);
			UINT32 *dstdiff = &finalbitmap.pix32(y, bitmap1.width() + BITMAP_SPACE + maxwidth + BITMAP_SPACE);

			/* now iterate over columns */
			for (x = 0; x < maxwidth; x++)
			{
				int pix1 = -1, pix2 = -2;

				if (src1 != NULL && x < bitmap1.width())
					pix1 = dst1[x] = src1[x];
				if (src2 != NULL && x < bitmap2.width())
					pix2 = dst2[x] = src2[x];
				dstdiff[x] = (pix1 != pix2) ? 0xffffffff : 0xff000000;
			}
		}

		/* write the final PNG */
		filerr = core_fopen(outfilename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
		if (filerr != FILERR_NONE)
		{
			printf("Could not open %s (%d)\n", outfilename.cstr(), filerr);
			goto error;
		}
		pngerr = png_write_bitmap(file, NULL, finalbitmap, 0, NULL);
		core_fclose(file);
		if (pngerr != PNGERR_NONE)
		{
			printf("Could not write %s (%d)\n", outfilename.cstr(), pngerr);
			goto error;
		}
	}

	/* if we get here, we are error free */
	if (bitmaps_differ)
		error = 1;
	else
		error = 0;

error:
	if (error == -1)
		osd_rmfile(outfilename);
	return error;
}