Beispiel #1
0
// called from winui.c to display the background
BOOL LoadDIBBG(HGLOBAL *phDIB, HPALETTE *pPal)
{
	osd_file::error filerr = osd_file::error::NOT_FOUND;
	util::core_file::ptr file = NULL;
	BOOL success = FALSE;
	const char *dir_name;
	if (pPal != NULL )
		DeletePalette(pPal);

	dir_name = GetBgDir();
	filerr = OpenBkgroundFile(dir_name, file);
	if (filerr == osd_file::error::NONE)
	{
		success = png_read_bitmap_gui(*file, phDIB, pPal);
		file.reset();
	}

	return success;
}
Beispiel #2
0
// display a snap, cabinet, title, flyer, marquee, pcb, control panel
static BOOL LoadDIB(const char *filename, HGLOBAL *phDIB, HPALETTE *pPal, int pic_type)
{
	osd_file::error filerr = osd_file::error::NOT_FOUND; // defined in osdcore.h
	util::core_file::ptr file = NULL;
	BOOL success = FALSE;
	const char *dir_name;
	const char *zip_name;
	void *buffer = NULL;
	std::string fname;
	if (pPal != NULL )
		DeletePalette(pPal);

	char *system_name = 0;
	char *file_name = 0;
	char* dir_name1 = 0;
	int i,j;
	bool ok = FALSE; // TRUE indicates split success

	switch (pic_type)
	{
		case TAB_SCREENSHOT:
			dir_name = GetImgDir();
			zip_name = "snap";
			break;
		case TAB_FLYER:
			dir_name = GetFlyerDir();
			zip_name = "flyers";
			break;
		case TAB_CABINET:
			dir_name = GetCabinetDir();
			zip_name = "cabinets";
			break;
		case TAB_MARQUEE:
			dir_name = GetMarqueeDir();
			zip_name = "marquees";
			break;
		case TAB_TITLE:
			dir_name = GetTitlesDir();
			zip_name = "titles";
			break;
		case TAB_CONTROL_PANEL:
			dir_name = GetControlPanelDir();
			zip_name = "cpanel";
			break;
		case TAB_PCB :
			dir_name = GetPcbDir();
			zip_name = "pcb";
			break;
		default :
			// in case a non-image tab gets here, which can happen
			return FALSE;
	}

	// allocate space
	system_name = (char*)malloc(strlen(filename) + 1);
	file_name = (char*)malloc(strlen(filename) + 1);

	// if the filename contains a system, split them

	// get system = find colon and truncate there
	for (i = 0; filename[i] && !ok; i++)
	{
		if (filename[i] != ':')
			system_name[i] = filename[i];
		else
		{
			ok = TRUE;
			system_name[i] = '\0';
		}
	}
	system_name[i] = '\0'; // 'i' is one more here than above but needed if no colon

	// now left-justify the filename
	if (ok)
	{
		for (j = 0; filename[i]; j++,i++)
			file_name[j] = filename[i];
		file_name[j] = '\0';
	}
	else
	// it wasn't a software title, copy over to get around const nonsense
	{
		for (i = 0; filename[i]; i++)
			file_name[i] = filename[i];
		file_name[i] = '\0';
	}

	// another const workaround
	dir_name1 = (char*)malloc(strlen(dir_name) + 2);
	for (i = 0; dir_name[i]; i++)
		dir_name1[i] = dir_name[i];
	dir_name1[i++] = ';';
	dir_name1[i] = '\0';

	// Support multiple paths
	char* dir_one = strtok(dir_name1, ";");

	while (dir_one && filerr != osd_file::error::NONE)
	{
		//Add handling for the displaying of all the different supported snapshot pattern types
		//%g

		// Do software checks first
		if (ok)
		{
			// Try dir/system/game.png
			fname = std::string(system_name) + PATH_SEPARATOR + std::string(file_name) + ".png";
			filerr = OpenRawDIBFile(dir_one, fname.c_str(), file);

			// Try dir/system.zip/game.png
			if (filerr != osd_file::error::NONE)
			{
				fname = std::string(file_name) + ".png";
				filerr = OpenZipDIBFile(dir_one, system_name, fname.c_str(), file, &buffer);
			}

			// Try dir/system.zip/system/game.png
			if (filerr != osd_file::error::NONE)
			{
				fname = std::string(system_name) + "/" + std::string(file_name) + ".png";
				filerr = OpenZipDIBFile(dir_one, system_name, fname.c_str(), file, &buffer);
			}

			// Try dir/zipfile/system/game.png
			if (filerr != osd_file::error::NONE)
			{
				filerr = OpenZipDIBFile(dir_one, zip_name, fname.c_str(), file, &buffer);
			}
		}

		// give up on software-specific, try dir/system.png
		if (filerr != osd_file::error::NONE)
		{
			fname = std::string(system_name) + ".png";
			filerr = OpenRawDIBFile(dir_one, fname.c_str(), file);
		}

		// For SNAPS only, try filenames with 0000.
		if (pic_type == TAB_SCREENSHOT)
		{
			if (filerr != osd_file::error::NONE)
			{
				//%g/%i
				fname = std::string(system_name) + PATH_SEPARATOR + "0000.png";
				filerr = OpenRawDIBFile(dir_one, fname.c_str(), file);
			}
			if (filerr != osd_file::error::NONE)
			{
				//%g%i
				fname = std::string(system_name) + "0000.png";
				filerr = OpenRawDIBFile(dir_one, fname.c_str(), file);
			}
			if (filerr != osd_file::error::NONE)
			{
				//%g/%g%i
				fname = std::string(system_name) + PATH_SEPARATOR + std::string(system_name) + "0000.png";
				filerr = OpenRawDIBFile(dir_one, fname.c_str(), file);
			}
		}

		// Try dir/zipfile/system.png
		if (filerr != osd_file::error::NONE)
		{
			fname = std::string(file_name) + ".png";
			filerr = OpenZipDIBFile(dir_one, zip_name, fname.c_str(), file, &buffer);
		}

		dir_one = strtok(NULL, ";");
	}

	if (filerr == osd_file::error::NONE)
	{
		success = png_read_bitmap_gui(*file, phDIB, pPal);
		file.reset();
	}

	// free the buffer if we have to
	if (buffer != NULL)
		free(buffer);
	free(system_name);
	free(file_name);
	free(dir_name1);

	return success;
}
BOOL LoadDIB(const char *filename, HGLOBAL *phDIB, HPALETTE *pPal, int pic_type)
{
	file_error filerr;
	core_file *file = NULL;
	BOOL success = FALSE;
	const char *dir_name;
	const char *zip_name;
	astring *fname;
	void *buffer = NULL;
	if (pPal != NULL ) {
		DeletePalette(pPal);
	}

	switch (pic_type)
	{
		case TAB_SCREENSHOT:
			dir_name = GetImgDir();
			zip_name = "snap";
			break;
		case TAB_FLYER:
			dir_name = GetFlyerDir();
			zip_name = "flyers";
			break;
		case TAB_CABINET:
			dir_name = GetCabinetDir();
			zip_name = "cabinets";
			break;
		case TAB_MARQUEE:
			dir_name = GetMarqueeDir();
			zip_name = "marquees";
			break;
		case TAB_TITLE:
			dir_name = GetTitlesDir();
			zip_name = "titles";
			break;
		case TAB_CONTROL_PANEL:
			dir_name = GetControlPanelDir();
			zip_name = "cpanel";
			break;
        case TAB_PCB :
			dir_name = GetPcbDir();
		    zip_name = "pcb";
			break;
		case BACKGROUND:
			dir_name = GetBgDir();
			zip_name = "bkground";
			break;
		default :
			// in case a non-image tab gets here, which can happen
			return FALSE;
	}
	//Add handling for the displaying of all the different supported snapshot patterntypes
	//%g
	fname = astring_assemble_2(astring_alloc(), filename, ".png");
	filerr = OpenDIBFile(dir_name, zip_name, astring_c(fname), &file, &buffer);
	astring_free(fname);
	if (filerr != FILERR_NONE) {
		//%g/%i
		fname = astring_assemble_3(astring_alloc(), filename, PATH_SEPARATOR, "0000.png");
		filerr = OpenDIBFile(dir_name, zip_name, astring_c(fname), &file, &buffer);
		astring_free(fname);
	}
	if (filerr != FILERR_NONE) {
		//%g%i
		fname = astring_assemble_2(astring_alloc(), filename, "0000.png");
		filerr = OpenDIBFile(dir_name, zip_name, astring_c(fname), &file, &buffer);
		astring_free(fname);
	}
	if (filerr != FILERR_NONE) {
		//%g/%g
		fname = astring_assemble_4(astring_alloc(), filename, PATH_SEPARATOR, filename, ".png");
		filerr = OpenDIBFile(dir_name, zip_name, astring_c(fname), &file, &buffer);
		astring_free(fname);
	}
	if (filerr != FILERR_NONE) {
		//%g/%g%i
		fname = astring_assemble_4(astring_alloc(), filename, PATH_SEPARATOR, filename, "0000.png");
		filerr = OpenDIBFile(dir_name, zip_name, astring_c(fname), &file, &buffer);
		astring_free(fname);
	}

	if (filerr == FILERR_NONE) {
		success = png_read_bitmap_gui(file, phDIB, pPal);
		core_fclose(file);
	}

	// free the buffer if we have to
	if (buffer != NULL) {
		free(buffer);
	}
	return success;
}
Beispiel #4
0
BOOL LoadDIB(const WCHAR *filename, HGLOBAL *phDIB, HPALETTE *pPal, int pic_type)
{
	file_error filerr;
	core_file *file = NULL;
	BOOL success = FALSE;
	const WCHAR *zip_name;
	const WCHAR *dir_name;
	void *buffer = NULL;
	char *utf8filename;
	char *utf8zip_name;
	char *utf8dir_name;
	if (pPal != NULL ) {
		DeletePalette(pPal);
	}

	switch (pic_type)
	{
	case TAB_SCREENSHOT :
		dir_name = GetImgDir();
		zip_name = TEXT("snap");
		break;
	case TAB_FLYER :
		dir_name = GetFlyerDir();
		zip_name = TEXT("flyers");
		break;
	case TAB_CABINET :
		dir_name = GetCabinetDir();
		zip_name = TEXT("cabinets");
		break;
	case TAB_MARQUEE :
		dir_name = GetMarqueeDir();
		zip_name = TEXT( "marquees");
		break;
	case TAB_TITLE :
		dir_name = GetTitlesDir();
		zip_name = TEXT("titles");
		break;
	case TAB_CONTROL_PANEL :
		dir_name = GetControlPanelDir();
		zip_name = TEXT("cpanel");
		break;
        case TAB_PCB :
		dir_name = GetPcbDir();
		zip_name = TEXT("pcb");
		break;
	case BACKGROUND :
		dir_name = GetBgDir();
		zip_name = TEXT("bkground");
		break;
#ifdef USE_IPS
	case TAB_IPS :
		dir_name = GetIPSDir();
		zip_name = TEXT("ips");
		break;
#endif /* USE_IPS */
	default :
		// in case a non-image tab gets here, which can happen
		return FALSE;
	}

	utf8filename = utf8_from_wstring(filename);
	utf8zip_name = utf8_from_wstring(zip_name);
	utf8dir_name = utf8_from_wstring(dir_name);

	//Add handling for the displaying of all the different supported snapshot patterntypes
	//%g
	astring fname(utf8filename, ".png");
	filerr = OpenDIBFile(utf8dir_name, utf8zip_name, fname, &file, &buffer);
	if (filerr != FILERR_NONE)
	{
		//%g/%i
		astring fname(utf8filename, PATH_SEPARATOR, "0000.png");
		filerr = OpenDIBFile(utf8dir_name, utf8zip_name, fname, &file, &buffer);
	}
	if (filerr != FILERR_NONE)
	{
		//%g%i
		astring fname(utf8filename, "0000.png");
		filerr = OpenDIBFile(utf8dir_name, utf8zip_name, fname, &file, &buffer);
	}
	if (filerr != FILERR_NONE)
	{
		//%g/%g
		astring fname(utf8filename, PATH_SEPARATOR, utf8filename, ".png");
		filerr = OpenDIBFile(utf8dir_name, utf8zip_name, fname, &file, &buffer);
	}
	if (filerr != FILERR_NONE)
	{
		//%g/%g%i
		astring fname(utf8filename, PATH_SEPARATOR, utf8filename, ".png");
		filerr = OpenDIBFile(utf8dir_name, utf8zip_name, fname, &file, &buffer);
	}

	if (filerr == FILERR_NONE)
	{
		success = png_read_bitmap_gui(file, phDIB, pPal);
		core_fclose(file);
	}

	// free the buffer if we have to
	if (buffer != NULL)
	{
		free(buffer);
	}

	osd_free(utf8filename);
	osd_free(utf8zip_name);
	osd_free(utf8dir_name);

	return success;
}