Пример #1
0
int BArchiveOpen(bool bootApp)
{
	if (szBArchiveName == NULL) {
		return 1;
	}

	BArchiveClose(); // Make sure nothing is open

	// Count the number of roms needed
	for (nRomCount = 0; ; nRomCount++) {
		if (BurnDrvGetRomInfo(NULL, nRomCount)) {
			break;
		}
	}
	if (nRomCount <= 0) {
		return 1;
	}

	// Create an array for holding lookups for each rom -> archive entries
	unsigned int nMemLen = nRomCount * sizeof(ROMFIND);
	RomFind = (ROMFIND*)malloc(nMemLen);
	if (RomFind == NULL) {
		return 1;
	}
	memset(RomFind, 0, nMemLen);

	// Locate each archive file
	bool bFound = false;
	int checkvalue = ARC_NONE;
	TCHAR szFullName[MAX_PATH] = _T("");
	char* szName = NULL;

	for (int y = 0, z = 0; y < BZIP_MAX && z < BZIP_MAX; y++) {
		// Get archive name without extension
		if (BurnDrvGetArchiveName(&szName, y, false)) {
			break;
		}

		bFound = false;

		for (int d = 0; d < DIRS_MAX; d++) {
//			if (bFound) {
//				break;
//			}

			if (!_tcsicmp(szAppRomPaths[d], _T(""))) {
				continue; // skip empty path
			}

			// check the archived rom file, modified by regret
			_stprintf(szFullName, _T("%s%hs"), szAppRomPaths[d], szName);

			checkvalue = archiveCheck(szFullName, (nLoadMenuShowX & CHECK7ZIP) ? 0 : 1);
			if (checkvalue == ARC_NONE) {
				continue;
			}

			bFound = true;

			szBArchiveName[z] = (TCHAR*)malloc(MAX_PATH * sizeof(TCHAR));
			if (!szBArchiveName[z]) {
				continue;
			}
			_tcscpy(szBArchiveName[z], szFullName);
			if (!bootApp) {
				FBAPopupAddText(PUF_TEXT_DEFAULT, MAKEINTRESOURCE(IDS_ERR_LOAD_FOUND), szName, szBArchiveName[z]);
			}
			z++;

#if 0
			// Look further in the last path specified, so you can put files with ROMs
			// used only by FB Alpha there without causing problems with dat files
			if (d < DIRS_MAX - 2) {
				d = DIRS_MAX - 2;
			} else {
				if (d >= DIRS_MAX - 1) {
					break;
				}
			}
#endif
		}

		if (!bootApp && !bFound) {
			FBAPopupAddText(PUF_TEXT_DEFAULT, MAKEINTRESOURCE(IDS_ERR_LOAD_NOTFOUND), szName);
		}
	}

	if (!bootApp) {
		FBAPopupAddText(PUF_TEXT_DEFAULT, _T("\n"));
	}

	// Locate the ROM data in the archive files
	int nFind = -1;
	BurnRomInfo ri;

	for (int z = 0; z < BZIP_MAX; z++) {
		if (!szBArchiveName[z]) {
			continue;
		}

		if (archiveOpen(szBArchiveName[z])) {
			continue;
		}
		archiveGetList(&List, &nListCount);	// Get the list of entries

		nCurrentArc = z;

		for (int i = 0; i < nRomCount; i++) {
			if (RomFind[i].nState == STAT_OK) {
				continue;					// Already found this and it's okay
			}

			nFind = findRom(i, List, nListCount);
			if (nFind < 0) {				// Couldn't find this rom at all
				continue;
			}

			RomFind[i].nArchive = z;		// Remember which archive file it is in
			RomFind[i].nPos = nFind;
			RomFind[i].nState = STAT_OK;	// Set to found okay

			memset(&ri, 0, sizeof(ri));
			BurnDrvGetRomInfo(&ri, i);		// Get info about the rom

			// if size good & nodump, try to load the file with correct filename
			if (!(ri.nType & BRF_OPT) && (ri.nCrc != 0)) {
				nTotalSize += ri.nLen;
			}

			if (List[nFind].nLen == ri.nLen) {
				if (ri.nCrc) {									// If we know the CRC
					if (List[nFind].nCrc != ri.nCrc) {			// Length okay, but CRC wrong
						if (!(nLoadMenuShowX & DISABLECRC)) {	// disable crc check
							RomFind[i].nState = STAT_CRC;
						}
					}
				}
			} else {
				if (nLoadMenuShowX & DISABLECRC) {
					ri.nLen = List[nFind].nLen;					// disable size check
				} else {
					if (List[nFind].nLen < ri.nLen) {
						RomFind[i].nState = STAT_SMALL;			// Too small
					} else {
						RomFind[i].nState = STAT_LARGE;			// Too big
					}
				}
			}

			if (!bootApp) {
				if (RomFind[i].nState != STAT_OK) {
					RomDescribe(&ri);

					if (RomFind[i].nState == STAT_CRC) {
						FBAPopupAddText(PUF_TEXT_DEFAULT, MAKEINTRESOURCE(IDS_ERR_LOAD_CRC),
							getFilenameA(List[nFind].szName), List[nFind].nCrc, ri.nCrc);
					}
					if (RomFind[i].nState == STAT_SMALL) {
						FBAPopupAddText(PUF_TEXT_DEFAULT, MAKEINTRESOURCE(IDS_ERR_LOAD_SMALL),
							getFilenameA(List[nFind].szName), List[nFind].nLen >> 10, ri.nLen >> 10);
					}
					if (RomFind[i].nState == STAT_LARGE) {
						FBAPopupAddText(PUF_TEXT_DEFAULT, MAKEINTRESOURCE(IDS_ERR_LOAD_LARGE),
							getFilenameA(List[nFind].szName), List[nFind].nLen >> 10, ri.nLen >> 10);
					}
				}
			}
Пример #2
0
static int getArchiveInfo(const char* path, const char* name)
{
	if (!name || !path) {
		return 1;
	}

	// omit extension
	string _name = name;
	lowerString(_name); // case-insensitive
	size_t pos = _name.rfind(".");
	_name = _name.substr(0, pos);

//	if (_name == "sf2m13") {
//		int dummy = 0;
//	}

	// set progress
	//checkScanThread();
	//romsSetProgress();

	// find name
	map<string, GameInfo*>::iterator _it = allGameMap.find(_name);
	if (_it == allGameMap.end()) {
		return 1;
	}

	GameInfo* gameInfo = _it->second;
	if (!gameInfo) {
		return 1;
	}

	static char fileName[MAX_PATH];
	sprintf(fileName, "%s%s", path, name);

	if (archiveOpenA(fileName)) {
		return 1;
	}

	if (archiveGetList(&List, &listCount)) {
		freeArchiveList();
		return 1;
	}

	RomInfo* romInfo = NULL;
	map<unsigned int, RomInfo>::iterator iter;

	for (int i = 0; i < listCount; i++) {
		// check roms
		iter = gameInfo->roms.find(List[i].nCrc);
		if (iter != gameInfo->roms.end()) {
			romInfo = &iter->second;
			if (!romInfo) {
				continue;
			}

			if (romInfo->size != List[i].nLen) {
				if (List[i].nLen < romInfo->size) {
					romInfo->state = STAT_SMALL;
				} else {
					romInfo->state = STAT_LARGE;
				}
			} else {
				romInfo->state = STAT_OK;
			}
		} else {
			// wrong CRC
			if (nLoadMenuShowX & DISABLECRC) {
				RomInfo* rom = getSetHasRom(gameInfo, List[i].szName);
				if (rom) {
					rom->state = STAT_OK;
				}
			}
		}

		// check all clones
		setCloneRomInfo(gameInfo, List[i]);
	}

	archiveClose();

	freeArchiveList();

	return 0;
}