Exemplo n.º 1
0
void thread_FileCopy(uint64_t /*arg*/)
{	
	gamePKG->nStatus = STATUS_COPY_START;

	FILE *filer			= NULL;
	FILE *filew			= NULL;
	uint64_t numr		= 0;	// elements read
	uint64_t numw		= 0;	// elements wrote	
	uint64_t nTotalRead = 0;
	double nCopyPct		= 0.0f;
	double nTotDelta	= 0.0f;
	uint32_t nApproxTotDelta = 0;


	char *buffer = NULL;
	buffer = (char*)malloc(BUFF_SIZE);

	filer = fopen(gamePKG->pkglst[gamePKG->nSelectedPKG].path,"rb");

	char szFileOut[256] ="";
	sprintf(
		szFileOut, 
		"/dev_hdd0/vsh/game_pkg/%d/%s", 
		gamePKG->pkglst[gamePKG->nSelectedPKG].nPKGID, 
		gamePKG->pkglst[gamePKG->nSelectedPKG].title
	);
	filew = fopen(szFileOut, "wb");

	if(filer != NULL && filew != NULL)
	{
		bool bCopyError = false;

		while(feof(filer) == 0)
		{
			// read
			if((numr = fread(buffer, 1, BUFF_SIZE, filer)) != BUFF_SIZE) 
			{
				if(ferror(filer) != 0) 
				{
					bCopyError = true;
					break;
				}
				else if(feof(filer) != 0)
				{
					// ...
				}
			}
			
			// write
			if((numw = fwrite(buffer, 1, numr, filew)) != numr) 
			{
				bCopyError = true;
				break;
			}
			
			nTotalRead += numr;			

			nCopyPct = (double)(((double)numr / (double)gamePKG->pkglst[gamePKG->nSelectedPKG].nSize) * 100.0f);
			double nTotalPct = (double)((double)nTotalRead / (double)gamePKG->pkglst[gamePKG->nSelectedPKG].nSize) * 100.0f;

			nTotDelta += nCopyPct;
			nApproxTotDelta += (uint32_t)round(nCopyPct);

			if((double)nApproxTotDelta < nTotalPct) 
			{
				// Compensate loss of float/double data, as for example: approx 70% vs. precise 95%
				nApproxTotDelta += (uint32_t)(nTotalPct - (double)nApproxTotDelta);
				nCopyPct += (nTotalPct - (double)nApproxTotDelta);				
			}
			cellMsgDialogProgressBarInc(CELL_MSGDIALOG_PROGRESSBAR_INDEX_SINGLE, (uint32_t)nCopyPct);

			char msg[256] = "";
			sprintf(
				msg, 
				//"%.2f %s / %.2f %s (%.1f %%)(delta: %d %%)",
				"%.2f %s / %.2f %s",
				GetByteUnit(nTotalRead),
				GetByteUnitStr(nTotalRead),
				GetByteUnit(gamePKG->pkglst[gamePKG->nSelectedPKG].nSize),
				GetByteUnitStr(gamePKG->pkglst[gamePKG->nSelectedPKG].nSize)	//,
				//nTotalPct,
				//nApproxTotDelta
			);
			cellMsgDialogProgressBarSetMsg(CELL_MSGDIALOG_PROGRESSBAR_INDEX_SINGLE, msg);
		}

		nCopyPct = (double)(((double)numr / (double)gamePKG->pkglst[gamePKG->nSelectedPKG].nSize) * 100.0f);
		double nTotalPct = (double)((double)nTotalRead / (double)gamePKG->pkglst[gamePKG->nSelectedPKG].nSize) * 100.0f;

		nTotDelta += nCopyPct;
		nApproxTotDelta += (uint32_t)round(nCopyPct);

		if((double)nApproxTotDelta < nTotalPct) 
		{
			// Compensate loss of float/double data, as for example: approx 70% vs. precise 95%
			nApproxTotDelta += (uint32_t)(nTotalPct - (double)nApproxTotDelta);
			nCopyPct += (nTotalPct - (double)nApproxTotDelta);
		}
		cellMsgDialogProgressBarInc(CELL_MSGDIALOG_PROGRESSBAR_INDEX_SINGLE, (uint32_t)nCopyPct);

		char msg[256] = "";
		sprintf(
			msg, 
			//"%.2f %s / %.2f %s (%.1f %%)(delta: %d %%)",
			"%.2f %s / %.2f %s",
			GetByteUnit(nTotalRead),
			GetByteUnitStr(nTotalRead),
			GetByteUnit(gamePKG->pkglst[gamePKG->nSelectedPKG].nSize),
			GetByteUnitStr(gamePKG->pkglst[gamePKG->nSelectedPKG].nSize)	//,
			//nTotalPct,
			//nApproxTotDelta
		);
		cellMsgDialogProgressBarSetMsg(CELL_MSGDIALOG_PROGRESSBAR_INDEX_SINGLE, msg);

		if(filer) fclose(filer);
		if(filew) fclose(filew);
		
		if(bCopyError)
		{
			cellFsUnlink(szFileOut); // delete file

			gamePKG->nStatus = STATUS_COPY_ERROR;
			sys_ppu_thread_exit(0);
			return;
		}

	} else {

		if(buffer) free(buffer);
		buffer = NULL;

		if(filer) fclose(filer);
		if(filew) 
		{
			fclose(filew);		
			cellFsUnlink(szFileOut); // delete file
		}

		gamePKG->nStatus = STATUS_COPY_ERROR;
		sys_ppu_thread_exit(0);
		return;
	}
	
	if(buffer) 
	{
		free(buffer);
		buffer = NULL;
	}

	sys_timer_usleep(1000000); // wait 1 second

	gamePKG->nStatus = STATUS_COPY_OK;
	sys_ppu_thread_exit(0);
}
Exemplo n.º 2
0
// (re-wrote) this function will just look for specific ROMs on specific locations,
// that means it will NOT process unnecesary files, ex. there could be 40,000 ZIP
// files, but I'm just checking 5,000, not comparing each of the 40,000.
void _ScanROMs(uint64_t /*arg*/)
{
	uint32_t nTotalBurnDrivers = sizeof(fba_drv) / sizeof(FBA_DRV);
	uint32_t nPaths = sizeof(g_opt_szROMPaths) / 2048;
	
	char* pszFilePath = NULL;
	pszFilePath = (char*)malloc(2048);
	memset(pszFilePath, 0, 2048);

	double fDelta = 0.0f;
	double fDeltaCnt = 0.0f;

	// go through all drivers...
	for(uint32_t nDrv = 0; nDrv < nTotalBurnDrivers; nDrv++)
	{
		fbaRL->games[fbaRL->nTotalGames] = new c_game(fbaRL->nTotalGames);	

		// try every path possible...
		for(uint32_t x = 0; x < nPaths; x++)
		{
			if(fbaRL->DirExist(g_opt_szROMPaths[x]))
			{							
				sprintf(pszFilePath, "%s/%s.zip", g_opt_szROMPaths[x], fba_drv[nDrv].szName);
				
				// Available...
				if(fbaRL->FileExist(pszFilePath)) 
				{	
					// TODO: check if zip has all files			
					// Add found game info...									
					sprintf(fbaRL->games[fbaRL->nTotalGames]->title, "%s", fba_drv[nDrv].szTitle);			// title					
					sprintf(fbaRL->games[fbaRL->nTotalGames]->sysmask, "%s", fba_drv[nDrv].szSystemFilter);	// sys filter					
					strcpy(fbaRL->games[fbaRL->nTotalGames]->path, pszFilePath);							// path					
					sprintf(fbaRL->games[fbaRL->nTotalGames]->zipname, "%s.zip", fba_drv[nDrv].szName);		// zip title					
					fbaRL->games[fbaRL->nTotalGames]->nSize = 0/*fbaRL->GetFileSize(pszFilePath)*/;				// Size in bytes					
					fbaRL->games[fbaRL->nTotalGames]->bAvailable = true;
					break;
				}
			}
		}

		// Missing...
		if(!fbaRL->games[fbaRL->nTotalGames]->bAvailable) 
		{
			sprintf(fbaRL->games[fbaRL->nTotalGames]->title		, "%s"		, fba_drv[nDrv].szTitle);			// title
			sprintf(fbaRL->games[fbaRL->nTotalGames]->sysmask	, "%s"		, fba_drv[nDrv].szSystemFilter);	// sys filter
			sprintf(fbaRL->games[fbaRL->nTotalGames]->zipname	, "%s.zip"	, fba_drv[nDrv].szName);		// zip title				
			fbaRL->games[fbaRL->nTotalGames]->nSize = 0;				// Size in bytes
			fbaRL->games[fbaRL->nTotalGames]->bAvailable = false;

			fbaRL->nMissingGames++;			
		}

		fbaRL->nTotalGames++;

		// Progress bar...
		double fTotalPct = ((double)nDrv / (double)nTotalBurnDrivers) * 100.0f;

		fDeltaCnt += (fTotalPct - fDelta);

		char msg[256] = "";
		sprintf(msg,
			"%d / %d (%.1f %%)",
			nDrv, 
			nTotalBurnDrivers, 
			fTotalPct
		);
		cellMsgDialogProgressBarSetMsg(CELL_MSGDIALOG_PROGRESSBAR_INDEX_SINGLE, msg);
					
		if(fDeltaCnt >= 1.0f)
		{
			fDeltaCnt -= 1.0f;
			cellMsgDialogProgressBarInc(CELL_MSGDIALOG_PROGRESSBAR_INDEX_SINGLE, 1);
		}					
					
		fDelta = fTotalPct;
	}
	fbaRL->bProcessingGames = false;
	fbaRL->nStatus = STATUS_ROMSCAN_END;
	sys_ppu_thread_exit(0);
}