当前位置: 首页>>代码示例>>C++>>正文


C++ EMUFILE_FILE::size方法代码示例

本文整理汇总了C++中EMUFILE_FILE::size方法的典型用法代码示例。如果您正苦于以下问题:C++ EMUFILE_FILE::size方法的具体用法?C++ EMUFILE_FILE::size怎么用?C++ EMUFILE_FILE::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EMUFILE_FILE的用法示例。


在下文中一共展示了EMUFILE_FILE::size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: fread

BackupDevice::BackupDevice()
{
	size_t elements_read, elements_written;
	fpMC = NULL;
	fsize = 0;
	addr_size = 0;
	isMovieMode = false;

	//default for most games; will be altered where appropriate
	//usually 0xFF, but occasionally others. If these exceptions could be related to a particular backup memory type, that would be helpful.
	//at first we assumed it would be 0x00, but baby pals proved that it should be 0xFF:
	// the game reads its initial sound volumes from uninitialized data, and if it is 0, the game will be silent
	// if it is 0xFF then the game starts with its sound and music at max, as presumably it is supposed to.
	// so in r3303 we finally changed it (no$ appears definitely to initialize to 0xFF)
	uninitializedValue = 0xFF;

	if (gameInfo.romsize == 0) return;

	char buf[MAX_PATH] = {0};
	memset(buf, 0, MAX_PATH);
	path.getpathnoext(path.BATTERY, buf);
	filename = std::string(buf) + ".dsv";

	MCLOG("MC: %s\n", filename.c_str());

	bool fexists = (access(filename.c_str(), 0) == 0)?true:false;

	if (fexists && CommonSettings.backupSave)
	{
		std::string tmp_fsav = std::string(buf) + ".dsv.bak";
		EMUFILE_FILE *in = new EMUFILE_FILE(filename, "rb");
		if (!in->fail())
		{
			u32 sz = in->size();
			if (sz > 0)
			{
				EMUFILE_FILE *out = new EMUFILE_FILE(tmp_fsav, "wb");
				if (!out->fail())
				{
					u8 *data = new u8[sz];
					elements_read = fread(data, 1, sz, in->get_fp());
					elements_written = fwrite(data, 1, sz, out->get_fp());
					if (elements_read != sz || elements_written != sz)
						printf("Possibly incomplete data read/write.\n");
					delete [] data;
				}
				delete out;
			}
		}
		delete in;
	}

	if (!fexists)
	{
		printf("DeSmuME .dsv save file not found. Trying to load an old raw .sav file.\n");
		std::string tmp_fsav = std::string(buf) + ".sav";

		EMUFILE_FILE *fpTmp = new EMUFILE_FILE(tmp_fsav, "rb");
		if (!fpTmp->fail())
		{
			u32 sz = fpTmp->size();

			if (sz > 0)
			{
				EMUFILE_FILE *fpOut = new EMUFILE_FILE(filename, "wb");
				if (!fpOut->fail())
				{
					u8 *buf = new u8[sz + 1];
					if ((buf) && (fread(buf, 1, sz, fpTmp->get_fp()) == sz))
					{
						if (no_gba_unpack(buf, sz))
							printf("Converted from no$gba save.\n");
						else
							sz = trim(buf, sz);

						if (fwrite(buf, 1, sz, fpOut->get_fp()) == sz)
						{
							u8 res = searchFileSaveType(sz);
							if (res != 0xFF)
							{
								info.type = (res + 1);
								addr_size = info.addr_size = save_types[info.type].addr_size;
								info.size = fsize = sz;
								ensure(sz, fpOut);
								fsize = 0;
							}
							else
								info.type = 0;
							fexists = true;
						}
					}
					delete [] buf;
				}
				delete fpOut;
			}
		}
		delete fpTmp;
	}

	fpMC = new EMUFILE_FILE(filename, fexists?"rb+":"wb+");
//.........这里部分代码省略.........
开发者ID:krysanto,项目名称:desmume,代码行数:101,代码来源:mc.cpp

示例2: trim

BackupDevice::BackupDevice()
{
	fpMC = NULL;
	fsize = 0;
	addr_size = 0;
	isMovieMode = false;

	if (gameInfo.romsize == 0) return;

	char buf[MAX_PATH] = {0};
	memset(buf, 0, MAX_PATH);
	path.getpathnoext(path.BATTERY, buf);
	filename = std::string(buf) + ".dsv";						// DeSmuME memory card

	MCLOG("MC: %s\n", filename.c_str());

	bool fexists = (access(filename.c_str(), 0) == 0)?true:false;

	if (fexists && CommonSettings.backupSave)
	{
		std::string tmp_fsav = std::string(buf) + ".dsv.bak";
		EMUFILE_FILE *in = new EMUFILE_FILE(filename, "rb");
		if (!in->fail())
		{
			u32 sz = in->size();
			if (sz > 0)
			{
				EMUFILE_FILE *out = new EMUFILE_FILE(tmp_fsav, "wb");
				if (!out->fail())
				{
					u8 *data = new u8[sz];
					fread(data, 1, sz, in->get_fp());
					fwrite(data, 1, sz, out->get_fp());
					delete [] data;
				}
				delete out;
			}
		}
		delete in;
	}

	if (!fexists)
	{
		printf("DeSmuME .dsv save file not found. Trying to load an old raw .sav file.\n");
		std::string tmp_fsav = std::string(buf) + ".sav";

		EMUFILE_FILE *fpTmp = new EMUFILE_FILE(tmp_fsav, "rb");
		if (!fpTmp->fail())
		{
			u32 sz = fpTmp->size();

			if (sz > 0)
			{
				EMUFILE_FILE *fpOut = new EMUFILE_FILE(filename, "wb");
				if (!fpOut->fail())
				{
					u8 *buf = new u8[sz + 1];
					if ((buf) && (fread(buf, 1, sz, fpTmp->get_fp()) == sz))
					{
						if (no_gba_unpack(buf, sz))
							printf("Converted from no$gba save.\n");
						else
							sz = trim(buf, sz);

						if (fwrite(buf, 1, sz, fpOut->get_fp()) == sz)
						{
							u8 res = searchFileSaveType(sz);
							if (res != 0xFF)
							{
								info.type = (res + 1);
								addr_size = info.addr_size = save_types[info.type].addr_size;
								info.size = fsize = sz;
								ensure(sz, fpOut);
								fsize = 0;
							}
							else
								info.type = 0;
							fexists = true;
						}
					}
					delete [] buf;
				}
				delete fpOut;
			}
		}
		delete fpTmp;
	}

	fpMC = new EMUFILE_FILE(filename, fexists?"rb+":"wb+");
	if (!fpMC->fail())
	{
		fsize = fpMC->size();
		if (fsize < saveSizes[0])
			fpMC->truncate(0);

		if (readFooter() == 0)
			fsize -= (strlen(kDesmumeSaveCookie) + strlen(DESMUME_BACKUP_FOOTER_TXT) + 24);
		else
		{
			memset(&info, 0, sizeof(info));
//.........这里部分代码省略.........
开发者ID:Annovae,项目名称:desmume,代码行数:101,代码来源:mc.cpp


注:本文中的EMUFILE_FILE::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。