Exemplo n.º 1
0
int c_gamePKG::RemoveAllDirFiles(char* szDirectory)
{
	int fd;
	CellFsDirent dirEntry;
	
	CellFsErrno res = cellFsOpendir(szDirectory, &fd);
	
	if (res == CELL_FS_SUCCEEDED) 
	{
		uint64_t nread;

		while(cellFsReaddir(fd, &dirEntry, &nread) == CELL_FS_SUCCEEDED) 
		{
			if(nread == 0) break;

			if (dirEntry.d_type == CELL_FS_TYPE_DIRECTORY)
			{
				// DIRECTORY
			} else {
				
				if(dirEntry.d_type != CELL_FS_TYPE_REGULAR) break;
				
				// FILE
				char szFile[256] = "";
				sprintf(szFile, "%s/%s", szDirectory, dirEntry.d_name);

				cellFsUnlink(szFile);
			}
		}
	}
	cellFsClosedir(fd);

	return 1;
}
Exemplo n.º 2
0
int retro_readdir(struct RDIR *rdir)
{
#if defined(_WIN32)
   return (FindNextFile(rdir->directory, &rdir->entry) != 0);
#elif defined(VITA) || defined(PSP)
   return (sceIoDread(rdir->directory, &rdir->entry) > 0);
#elif defined(__CELLOS_LV2__)
   uint64_t nread;
   rdir->error = cellFsReaddir(rdir->directory, &rdir->entry, &nread);
   return (nread != 0);
#else
   return ((rdir->entry = readdir(rdir->directory)) != NULL);
#endif
}
Exemplo n.º 3
0
int c_gamePKG::ParsePKGList()
{
	char szDir[][256] = {
		"PKG"		, "pkg"		, "Pkg"		,
		"PACKAGE"	, "package"	, "Package"	,
		"PACKAGES"	, "packages", "Packages"
	};

	char szDevice[][256] = { 
		"/dev_hdd0",
		"/dev_usb000", "/dev_usb001", "/dev_usb002", "/dev_usb003",
		"/dev_cf",
		"/dev_sd",
		"/dev_ms"
	};

	// Scan each device for directories...
	for(unsigned int nDev = 0; nDev < (sizeof(szDevice) / 256); nDev++)
	{
		int device;
		
		// device is mounted
		if(cellFsOpendir(szDevice[nDev], &device) == CELL_FS_SUCCEEDED) 
		{
			CellFsDirent dirEntry;
			uint64_t nread = 0;

			// start scanning for directories...
			while(cellFsReaddir(device, &dirEntry, &nread) == CELL_FS_SUCCEEDED)			
			{
				if(nread == 0) break;

				// found a directory...
				if (dirEntry.d_type == CELL_FS_TYPE_DIRECTORY)
				{					
					// check if its one of the directories we are looking for...					
					for(unsigned int nDir = 0; nDir < (sizeof(szDir) / 256); nDir++) 
					{
						// if we got a winner, then look for PKG files inside the directory...
						if(strcmp(dirEntry.d_name, szDir[nDir]) == 0)
						{
							// ---
							int d;
							char szDirectory[256] = "";
							sprintf(szDirectory, "%s/%s", szDevice[nDev], szDir[nDir]);
							
							if(cellFsOpendir(szDirectory, &d) == CELL_FS_SUCCEEDED)
							{
								CellFsDirent dirEntry2;

								uint64_t nread2 = 0;

								while(cellFsReaddir(d, &dirEntry2, &nread2) == CELL_FS_SUCCEEDED)			
								{
									if (dirEntry2.d_type == CELL_FS_TYPE_DIRECTORY)
									{
										// DIRECTORY

										// we're not looking for directories here...
									
									} else {
				
										if(dirEntry2.d_type != CELL_FS_TYPE_REGULAR) break;

										// FILE

										int nNameLen = strlen(dirEntry2.d_name);
										if (nNameLen < 5) continue;

										char* pszFilename = NULL;
										
										pszFilename = (char*)malloc(nNameLen+1);										
										memcpy(pszFilename, dirEntry2.d_name, nNameLen);
										pszFilename[nNameLen] = 0;

										// Check file extension...
										if(NULL != strstr(toLowerCase(pszFilename, strlen(pszFilename)), ".pkg")) 
										{
											// Add entry values to game list

											if(NULL != strstr(szDirectory, "/dev_hdd0"))
											{
												pkglst[nTotalPKG].bInternal = true;
											}

											// PKG Path
											if(szDirectory[strlen(szDirectory)-1] == '/')
											{
												szDirectory[strlen(szDirectory)-1] = 0;
											}

											sprintf(pkglst[nTotalPKG].path, "%s/%s", szDirectory, dirEntry2.d_name);				
					
											// PKG Filename
											sprintf(pkglst[nTotalPKG].title, "%s", dirEntry2.d_name);

											// PKG directory ID (ex. 80000000)
											while(pkglst[nTotalPKG].nPKGID == 0)
											{
												pkglst[nTotalPKG].nPKGID = GetPKGDirId();
											}

											// PKG Size in bytes
											pkglst[nTotalPKG].nSize = GetPKGSize(pkglst[nTotalPKG].path);
					
											nTotalPKG++;
											nPKGID++;
										}

										if(pszFilename) {
											free(pszFilename);
											pszFilename = NULL;
										}
									}
								}
								cellFsClosedir(d);
								d = NULL;
							}
							// ---
						}
					}

				} else {
					// FILE
				}
			}
			cellFsClosedir(device);
			device = NULL;
		}
	}

	// Scan devices again, but only root directory...
	// Have to do it this way because SONY SDK doesn't have 'telldir()' and 'seekdir()' implemented

	for(unsigned int nDev = 0; nDev < (sizeof(szDevice) / 256); nDev++)
	{
		int device;		

		// device is mounted
		if(cellFsOpendir(szDevice[nDev], &device) == CELL_FS_SUCCEEDED) 
		{
			CellFsDirent dirEntry;
			uint64_t nread = 0;

			// start scanning for directories...
			while(cellFsReaddir(device, &dirEntry, &nread) == CELL_FS_SUCCEEDED)			
			{
				if(nread == 0) break;

				// found a directory...
				if (dirEntry.d_type == CELL_FS_TYPE_DIRECTORY)
				{
					// ...
				} else {
	
					if(dirEntry.d_type != CELL_FS_TYPE_REGULAR) break;

					// FILE

					int nNameLen = strlen(dirEntry.d_name);
					if (nNameLen < 5) continue;

					char* pszFilename = NULL;
										
					pszFilename = (char*)malloc(nNameLen+1);										
					memcpy(pszFilename, dirEntry.d_name, nNameLen);
					pszFilename[nNameLen] = 0;

					// Check file extension...
					if(NULL != strstr(toLowerCase(pszFilename, strlen(pszFilename)), ".pkg")) 
					{
						// Add entry values to game list

						if(NULL != strstr(szDevice[nDev], "/dev_hdd0"))
						{
							pkglst[nTotalPKG].bInternal = true;
						}

						// PKG Path
						if(szDevice[nDev][strlen(szDevice[nDev])-1] == '/')
						{
							szDevice[nDev][strlen(szDevice[nDev])-1] = 0;
						}

						sprintf(pkglst[nTotalPKG].path, "%s/%s", szDevice[nDev], dirEntry.d_name);				
					
						// PKG Filename
						sprintf(pkglst[nTotalPKG].title, "%s", dirEntry.d_name);

						// PKG directory ID (ex. 80000000)
						while(pkglst[nTotalPKG].nPKGID == 0)
						{
							pkglst[nTotalPKG].nPKGID = GetPKGDirId();
						}

						// PKG Size in bytes
						pkglst[nTotalPKG].nSize = GetPKGSize(pkglst[nTotalPKG].path);
					
						nTotalPKG++;
						nPKGID++;
					}

					if(pszFilename) {
						free(pszFilename);
						pszFilename = NULL;
					}
				}
			}
			cellFsClosedir(device);
			device = NULL;
		}
	}

	return 1;
}