コード例 #1
0
ファイル: memcardop.cpp プロジェクト: feraligatr/vbagx
/****************************************************************************
 * LoadMCFile
 * Load savebuffer from Memory Card file
 ***************************************************************************/
int
LoadMCFile (char *buf, int slot, char *filename, bool silent)
{
	int CardError;
	unsigned int blocks;
	unsigned int SectorSize;
    int bytesleft = 0;
    int bytesread = 0;

	/*** Initialize Card System ***/
	memset (SysArea, 0, CARD_WORKAREA);
	CARD_Init ("VBA0", "00");

	/*** Try to mount the card ***/
	CardError = MountCard(slot, NOTSILENT);

	if (CardError == 0)
	{
		/*** Get Sector Size ***/
		CARD_GetSectorSize (slot, &SectorSize);

		if (!CardFileExists (filename, slot))
		{
			if (!silent)
				WaitPrompt("Unable to open file");
			return 0;
		}

		memset (&CardFile, 0, sizeof (CardFile));
		CardError = CARD_Open (slot, filename, &CardFile);

		blocks = CardFile.len;

		if (blocks < SectorSize)
			blocks = SectorSize;

		if (blocks % SectorSize)
			blocks += SectorSize;

		memset (buf, 0, 0x22000);

		bytesleft = blocks;
		bytesread = 0;
		while (bytesleft > 0)
		{
			CARD_Read (&CardFile, buf + bytesread, SectorSize, bytesread);
			bytesleft -= SectorSize;
			bytesread += SectorSize;
		}
		CARD_Close (&CardFile);
		CARD_Unmount (slot);
	}
	else
		if (slot == CARD_SLOTA)
			WaitPrompt("Unable to Mount Slot A Memory Card!");
		else
			WaitPrompt("Unable to Mount Slot B Memory Card!");

	return bytesread;
}
コード例 #2
0
ファイル: smbop.cpp プロジェクト: feraligatr/vbagx
bool InitializeNetwork(bool silent)
{
	ShowAction ((char*) "Initializing network...");
	s32 result;

	while ((result = net_init()) == -EAGAIN);

	if (result >= 0)
	{
		char myIP[16];

		if (if_config(myIP, NULL, NULL, true) < 0)
		{
			if(!silent)
				WaitPrompt((char*) "Error reading IP address.");
			return false;
		}
		else
		{
			return true;
		}
	}

	if(!silent)
		WaitPrompt((char*) "Unable to initialize network.");
	return false;
}
コード例 #3
0
ファイル: fileop.cpp プロジェクト: feraligatr/vbagx
/****************************************************************************
 * LoadFATFile
 ***************************************************************************/
int
LoadFATFile (char * rbuffer, int length)
{
	char zipbuffer[2048];
	char filepath[MAXPATHLEN];
	u32 size;

	/* Check filename length */
	if (!MakeROMPath(filepath, METHOD_SD))
	{
		WaitPrompt((char*) "Maximum filepath length reached!");
		return -1;
	}

	fatfile = fopen (filepath, "rb");
	if (fatfile > 0)
	{
		if(length > 0 && length <= 2048) // do a partial read (eg: to check file header)
		{
			fread (rbuffer, 1, length, fatfile);
			size = length;
		}
		else // load whole file
		{
			fread (zipbuffer, 1, 2048, fatfile);

			if (IsZipFile (zipbuffer))
			{
				size = UnZipBuffer ((unsigned char *)rbuffer, METHOD_SD);	// unzip from FAT
			}
			else
			{
				// Just load the file up
				fseek(fatfile, 0, SEEK_END);
				size = ftell(fatfile);				// get filesize
				fseek(fatfile, 2048, SEEK_SET);		// seek back to point where we left off
				memcpy (rbuffer, zipbuffer, 2048);	// copy what we already read

				ShowProgress ((char *)"Loading...", 2048, size);

				u32 offset = 2048;
				while(offset < size)
				{
					offset += fread (rbuffer + offset, 1, (1024*512), fatfile); // read in 512K chunks
					ShowProgress ((char *)"Loading...", offset, size);
				}
			}
		}
		fclose (fatfile);
		return size;
	}
	else
	{
		WaitPrompt((char*) "Error opening file");
		return 0;
	}
}
コード例 #4
0
ファイル: fileop.cpp プロジェクト: feraligatr/vbagx
/***************************************************************************
 * Browse FAT subdirectories
 **************************************************************************/
int
ParseFATdirectory(int method)
{
	int nbfiles = 0;
	DIR_ITER *fatdir;
	char filename[MAXPATHLEN];
	struct stat filestat;
	char msg[128];

	// initialize selection
	selection = offset = 0;

	// Clear any existing values
	memset (&filelist, 0, sizeof (FILEENTRIES) * MAXFILES);

	// open the directory
	fatdir = diropen(currentdir);
	if (fatdir == NULL)
	{
		sprintf(msg, "Couldn't open %s", currentdir);
		WaitPrompt(msg);

		// if we can't open the dir, open root dir
		sprintf(currentdir,"%s",ROOTFATDIR);

		fatdir = diropen(currentdir);

		if (fatdir == NULL)
		{
			sprintf(msg, "Error opening %s", currentdir);
			WaitPrompt(msg);
			return 0;
		}
	}

	// index files/folders
	while(dirnext(fatdir,filename,&filestat) == 0)
	{
		if(strcmp(filename,".") != 0)
		{
			memset(&filelist[nbfiles], 0, sizeof(FILEENTRIES));
			strncpy(filelist[nbfiles].filename, filename, MAXPATHLEN);
			strncpy(filelist[nbfiles].displayname, filename, MAXDISPLAY+1);	// crop name for display
			filelist[nbfiles].length = filestat.st_size;
			filelist[nbfiles].flags = (filestat.st_mode & _IFDIR) == 0 ? 0 : 1; // flag this as a dir
			nbfiles++;
		}
	}

	// close directory
	dirclose(fatdir);

	// Sort the file list
	qsort(filelist, nbfiles, sizeof(FILEENTRIES), FileSortCallback);

	return nbfiles;
}
コード例 #5
0
ファイル: fceuram.c プロジェクト: feraligatr/fceugx
bool SaveRAM (int method, bool silent)
{
	ShowAction ((char*) "Saving...");

	if(method == METHOD_AUTO)
		method = autoSaveMethod();

	bool retval = false;
	char filepath[1024];
	int datasize = 0;
	int offset = 0;

	// save game save to savebuffer
	if(nesGameType == 1)
		datasize = NGCFCEU_GameSave(&iNESCart, 0);
	else if(nesGameType == 2)
		datasize = NGCFCEU_GameSave(&UNIFCart, 0);

	if ( datasize )
	{
		if(method == METHOD_SD || method == METHOD_USB)
		{
			if(ChangeFATInterface(method, NOTSILENT))
			{
				sprintf (filepath, "%s/%s/%s.sav", ROOTFATDIR, GCSettings.SaveFolder, romFilename);
				offset = SaveBufferToFAT (filepath, datasize, silent);
			}
		}
		else if(method == METHOD_SMB)
		{
			sprintf (filepath, "%s/%s.sav", GCSettings.SaveFolder, romFilename);
			offset = SaveBufferToSMB (filepath, datasize, silent);
		}
		else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
		{
			sprintf (filepath, "%08x.sav", iNESGameCRC32);

			if(method == METHOD_MC_SLOTA)
				offset = SaveBufferToMC (savebuffer, CARD_SLOTA, filepath, datasize, silent);
			else
				offset = SaveBufferToMC (savebuffer, CARD_SLOTB, filepath, datasize, silent);
		}

		if (offset > 0)
		{
			if ( !silent )
				WaitPrompt((char *)"Save successful");
			retval = true;
		}
	}
	else
	{
		if ( !silent )
			WaitPrompt((char *)"No data to save!");
	}
	return retval;
}
コード例 #6
0
ファイル: main.c プロジェクト: LPFaint99/gcmm
/****************************************************************************
* RawRestoreMode
*
* Restore a full raw backup to Memory Card from SD Card
****************************************************************************/
void SD_RawRestoreMode ()
{
	int files;
	int selected;
	char msg[64];
	s32 writen = 0;
	int i;

	clearRightPane();
	DrawText(380,130,"R A W   R e s t o r e");
	DrawText(450,150,"M o d e");
	DrawText(380,154,"_____________________");

	writeStatusBar("Reading files... ", "");
	
	files = SDGetFileList (0);

	setfontsize (14);
	writeStatusBar("Pick a file using UP or DOWN", "Press A to restore to Memory Card ");

	if (!files)
	{
		WaitPrompt ("No raw backups in FAT device to restore !");
	}else
	{
		selected = ShowSelector (0);

		if (cancel)
		{
			WaitPrompt ("Restore action cancelled !");
			return;
		}
		else
		{
		#ifdef FLASHIDCHECK
			//Now imageserial and sramex.flash_id[MEM_CARD] variables should hold the proper information
			for (i=0;i<12;i++){
				if (imageserial[i] != sramex->flash_id[MEM_CARD][i]){
					WaitPrompt ("Card and image flash ID don't match !");
					return;
				}
			}
		#endif
			ShowAction ("Reading from FAT device...");
			if (RestoreRawImage(MEM_CARD, (char*)filelist[selected], &writen) == 1)
			{
				sprintf(msg, "Restore complete! Wrote %d bytes to card",writen);
				WaitPrompt(msg);
			}else
			{
				WaitPrompt("Restore failed!");
			}
		}
	}
}
コード例 #7
0
ファイル: sdsupp.c プロジェクト: suloku/gcmm
int SDLoadCardImageHeader(char *sdfilename)
{

	FILE *handle;
	char filename[1024];
	char msg[256];
	long bytesToRead = 0;

	/*** Clear the work buffers ***/
	memset (&cardheader, 0, sizeof(Header));

	/*** Make fullpath filename ***/
	sprintf (filename, "fat:/%s/%s", currFolder, sdfilename);

	/*** Open the SD Card file ***/
	handle = fopen ( filename , "rb" );
	if (handle <= 0)
	{
		sprintf(msg, "Couldn't open %s", filename);
		WaitPrompt (msg);
		return 0;
	}

	// obtain file size:
	fseek (handle , 0 , SEEK_END);
	bytesToRead = ftell (handle);
	rewind (handle);
	if (bytesToRead < 8192) //We don't want to read something smaller than the card header
	{
		sprintf(msg, "Incorrect file size %ld . Not raw image file or header", bytesToRead);
		WaitPrompt (msg);
		return 0;
	}

	char fileType[1024];
	char * dot;
	int pos = 4;
	dot = strrchr(filename,'.');
	strncpy(fileType, dot+1,pos);
	fileType[pos]='\0';

	if(!strcasecmp(fileType, "mci"))
	{
		//MCI files have a 64 byte header
		fseek(handle, 64, SEEK_SET);
	}
	memset(&cardheader, 0, sizeof(cardheader));
	/*** Read the file header ***/
	fread (&cardheader,1,sizeof(cardheader),handle);

	/*** Close the file ***/
	fclose (handle);

	return bytesToRead;
}
コード例 #8
0
ファイル: mcard.c プロジェクト: suloku/gcmm
void MC_FormatMode(s32 slot)
{
	int erase = 1;
	int err;

	//0 = B wass pressed -> ask again
	if (!slot){
		erase = WaitPromptChoice("Are you sure you want to format memory card in slot A?", "Format", "Cancel");
	}else{
		erase = WaitPromptChoice("Are you sure you want to format memory card in slot B?", "Format", "Cancel");
	}

	if (!erase){
		if (!slot){
			erase = WaitPromptChoiceAZ("All contents of memory card in slot A will be erased!", "Format", "Cancel");
		}else{
			erase = WaitPromptChoiceAZ("All contents of memory card in slot B will be erased!", "Format", "Cancel");
		}

		if (!erase)
		{

			/*** Try to mount the card ***/
			err = MountCard(slot);
			if (err < 0)
			{
				WaitCardError("MCFormat Mount", err);
				return; /*** Unable to mount the card ***/
			}
			ShowAction("Formatting card...");
			/*** Format the card ***/
			CARD_Format(slot);
			usleep(1000*1000);

			/*** Try to mount the card ***/
			err = MountCard(slot);
			if (err < 0)
			{
				WaitCardError("MCFormat Mount", err);
				return; /*** Unable to mount the card ***/
			}else
			{
				WaitPrompt("Format completed successfully");
			}

				CARD_Unmount(slot);
				return;
		}
	}

	WaitPrompt("Format operation cancelled");
	return;
}
コード例 #9
0
ファイル: memstate.c プロジェクト: feraligatr/fceugx
void SD_Manage(int mode, int slot){

	sd_file *handle;
	char path[1024];
	char msg[128];
	int offset = 0;
	int filesize = 0;
	int len = 0;
	
	//sprintf (filepath, "dev%d:\\%s\\%08x.fcs", slot, SAVEDIR, iNESGameCRC32);
	sprintf (path, "dev%d:\\%08x.fcs", slot, iNESGameCRC32);
	
	if (mode == 0) ShowAction ("Saving STATE to SD...");
	else ShowAction ("Loading STATE from SD...");
	
	handle = (mode == 0) ? SDCARD_OpenFile (path, "wb") : SDCARD_OpenFile (path, "rb");
	
	if (handle == NULL){        
        sprintf(msg, "Couldn't open %s", path);
        WaitPrompt(msg);
        return;
    }
	
	if (mode == 0){ //Save
		filesize = GCFCEUSS_Save();

		len = SDCARD_WriteFile (handle, statebuffer, filesize);
		SDCARD_CloseFile (handle);

		if (len != filesize){
			sprintf (msg, "Error writing %s", path);
			WaitPrompt (msg);
			return;			
		}

		sprintf (msg, "Saved %d bytes successfully", filesize);
		WaitPrompt (msg);
	}
	else{ //Load
	
		memopen();
		while ((len = SDCARD_ReadFile (handle, &statebuffer[offset], 1024)) > 0) offset += len;
		SDCARD_CloseFile (handle);
		
		sprintf (msg, "Loaded %d bytes successfully", offset);
		WaitPrompt(msg);

		GCFCEUSS_Load();
		return ;
	}
}
コード例 #10
0
ファイル: fileop.cpp プロジェクト: feraligatr/vbagx
/****************************************************************************
 * changeFATInterface
 * Checks if the device (method) specified is available, and
 * sets libfat to use the device
 ***************************************************************************/
bool ChangeFATInterface(int method, bool silent)
{
	bool devFound = false;

	if(method == METHOD_SD)
	{
		// check which SD device is loaded

		#ifdef HW_RVL
		if (FatIsMounted(PI_INTERNAL_SD))
		{
			devFound = true;
			fatSetDefaultInterface(PI_INTERNAL_SD);
		}
		#endif

		if (!devFound && FatIsMounted(PI_SDGECKO_A))
		{
			devFound = true;
			fatSetDefaultInterface(PI_SDGECKO_A);
		}
		if(!devFound && FatIsMounted(PI_SDGECKO_B))
		{
			devFound = true;
			fatSetDefaultInterface(PI_SDGECKO_B);
		}
		if(!devFound)
		{
			if(!silent)
				WaitPrompt ((char *)"SD card not found!");
		}
	}
	else if(method == METHOD_USB)
	{
		#ifdef HW_RVL
		if(FatIsMounted(PI_USBSTORAGE))
		{
			devFound = true;
			fatSetDefaultInterface(PI_USBSTORAGE);
		}
		else
		{
			if(!silent)
				WaitPrompt ((char *)"USB flash drive not found!");
		}
		#endif
	}

	return devFound;
}
コード例 #11
0
ファイル: memstate.c プロジェクト: feraligatr/fceugx
int GCReadChunk( int chunkid, SFORMAT *sf )
{
	int csize;
	static char chunk[6];
	int chunklength;
	int thischunk;
	char info[128];

	memfread(&chunk, 4);
	memfread(&thischunk, 4);
	memfread(&chunklength, 4);

	if ( strcmp(chunk, "CHNK") == 0 )
	{
		if ( chunkid == thischunk )
		{
			/*** Now decode the array of chunks to this one ***/
			while ( sf->v )
			{
				memfread(&chunk, 4);
				if ( memcmp(&chunk, "CHKE", 4) == 0 )
					return 1;
	
				if ( memcmp(&chunk, sf->desc, 4) == 0 )
				{
					memfread(&csize, 4);
					if ( csize == ( sf->s & ( ~RLSB ) ) )
					{
						memfread( sf->v, csize );
						sprintf(info,"%s %d", chunk, csize);
					} else {
						WaitPrompt("Bad chunk link");
						return 0;
					}
				} else {
					sprintf(info, "No Sync %s %s", chunk, sf->desc);
					WaitPrompt(info);
					return 0;
				}

				sf++;
			}	
		}
		else
			return 0;
	} else
		return 0;

	return 1;
}
コード例 #12
0
ファイル: smbop.cpp プロジェクト: feraligatr/vbagx
bool
ConnectShare (bool silent)
{
	// Crashes or stalls system in GameCube mode - so disable
	#ifndef HW_RVL
	return false;
	#endif

	// check that all parameter have been set
	if(strlen(GCSettings.smbuser) == 0 ||
		strlen(GCSettings.smbpwd) == 0 ||
		strlen(GCSettings.smbshare) == 0 ||
		strlen(GCSettings.smbip) == 0)
	{
		if(!silent)
			WaitPrompt((char*) "Invalid network settings. Check SNES9xGX.xml.");
		return false;
	}

	if(!networkInit)
		networkInit = InitializeNetwork(silent);

	if(networkInit)
	{
		// connection may have expired
		if (networkShareInit && SMBTimer > SMBTIMEOUT)
		{
			networkShareInit = false;
			SMBTimer = 0;
			SMB_Close(smbconn);
		}

		if(!networkShareInit)
		{
			if(!silent)
				ShowAction ((char*) "Connecting to network share...");

			if(SMB_Connect(&smbconn, GCSettings.smbuser, GCSettings.smbpwd,
			GCSettings.smbgcid, GCSettings.smbsvid, GCSettings.smbshare, GCSettings.smbip) == SMB_SUCCESS)
				networkShareInit = true;
		}

		if(!networkShareInit && !silent)
			WaitPrompt ((char*) "Failed to connect to network share.");
	}

	return networkShareInit;
}
コード例 #13
0
ファイル: fileop.cpp プロジェクト: feraligatr/vbagx
/****************************************************************************
 * Load savebuffer from FAT file
 ***************************************************************************/
int
LoadBufferFromFAT (char *filepath, bool silent)
{
	FILE *handle;
    int boffset = 0;
    int read = 0;

    ClearSaveBuffer ();

    handle = fopen (filepath, "rb");

    if (handle <= 0)
    {
        if ( !silent )
        {
            char msg[100];
            sprintf(msg, "Couldn't open %s", filepath);
            WaitPrompt (msg);
        }
        return 0;
    }

    /*** This is really nice, just load the file and decode it ***/
    while ((read = fread (savebuffer + boffset, 1, 1024, handle)) > 0)
    {
        boffset += read;
    }

    fclose (handle);

    return boffset;
}
コード例 #14
0
ファイル: ogc_input.c プロジェクト: thecrazyboy/smsplus-gx
static void wpad_config(u8 num)
{
  int i,j;
  int max = MAX_KEYS;
  u8 quit;
  char msg[30];
  u32 current = 255;

  /* check wiimote status */
  if (WPAD_Probe(num, &current) != WPAD_ERR_NONE)
  {
    WaitPrompt("Wiimote is not connected !");
    return;
  }

  /* index for wpad_keymap */
  u8 index = current + (num * 3);

  /* loop on each mapped keys */
  for (i=0; i<max; i++)
  {
    /* remove any pending buttons */
    while (WPAD_ButtonsHeld(num))
    {
      WPAD_ScanPads();
      VIDEO_WaitVSync();
    }

    /* user information */
    ClearScreen();
    sprintf(msg,"Press key for %s",keys_name[i]);
    WriteCentre(254, msg);
    SetScreen();

    /* wait for input */
    quit = 0;
    while (quit == 0)
    {
      WPAD_ScanPads();

      /* get buttons */
      for (j=0; j<20; j++)
      {
        if (WPAD_ButtonsDown(num) & wpad_keys[j])
        {
          wpad_keymap[index][i]  = wpad_keys[j];
          quit = 1;
          j = 20;    /* leave loop */
        }
      }
    } /* wait for input */ 
  } /* loop for all keys */

  /* removed any pending buttons */
  while (WPAD_ButtonsHeld(num))
  {
    WPAD_ScanPads();
    VIDEO_WaitVSync();
  }
}
コード例 #15
0
ファイル: sdload.cpp プロジェクト: feraligatr/snes9xgx
/****************************************************************************
 * Load Preferences from SD Card
 ****************************************************************************/
void
LoadPrefsFromSD (int slot, bool silent)
{
    char filepath[1024];
    int offset = 0;
    
    ShowAction ((char*) "Loading prefs from SD...");
    
#ifdef SDUSE_LFN
    sprintf (filepath, "%s/%s/%s", rootSDdir, SNESSAVEDIR, PREFS_FILE_NAME);
#else
    sprintf (filepath, "%s/%s/%s", rootSDdir, SNESSAVEDIR, PREFS_FILE_NAME);
#endif
    
    offset = LoadBufferFromSD (filepath, silent);
    
    if (offset > 0)
    {
        decodePrefsData ();
        if ( !silent )
        {
            sprintf (filepath, "Loaded %d bytes", offset);
            WaitPrompt(filepath);
        }
    }
}
コード例 #16
0
ファイル: sdload.cpp プロジェクト: feraligatr/snes9xgx
/****************************************************************************
 * Load SRAM From SD Card
 ****************************************************************************/
void
LoadSRAMFromSD (int slot, bool silent)
{
    char filepath[1024];
    int offset = 0;
    
    ShowAction ((char*) "Loading SRAM from SD...");
    
#ifdef SDUSE_LFN
    sprintf (filepath, "%s/%s/%s.srm", rootSDdir, SNESSAVEDIR, Memory.ROMName);
#else
    sprintf (filepath, "%s/%s/%08x.srm", rootSDdir, SNESSAVEDIR, Memory.ROMCRC32);
#endif
    
    offset = LoadBufferFromSD (filepath, silent);
    
    if (offset > 0)
    {
        decodesavedata (offset);
        if ( !silent )
        {
            sprintf (filepath, "Loaded %d bytes", offset);
            WaitPrompt(filepath);
        }
        S9xSoftReset();
    }
}
コード例 #17
0
ファイル: sdload.cpp プロジェクト: feraligatr/snes9xgx
/****************************************************************************
 * Save SRAM to SD Card
 ****************************************************************************/
void SaveSRAMToSD (int slot, bool silent)
{
    char filepath[1024];
    int datasize;
    int offset;

    ShowAction ((char*) "Saving SRAM to SD...");
    
#ifdef SDUSE_LFN
    sprintf (filepath, "%s/%s/%s.srm", rootSDdir, SNESSAVEDIR, Memory.ROMName);
#else
    sprintf (filepath, "%s/SNESSAVE/%08x.srm", rootSDdir, Memory.ROMCRC32);
#endif
    
    datasize = prepareEXPORTsavedata ();

    if ( datasize )
    {
        offset = SaveBufferToSD (filepath, datasize, silent);
        
        if ( (offset > 0) && (!silent) )
        {
            sprintf (filepath, "Wrote %d bytes", offset);
            WaitPrompt (filepath);
        }
    }
}
コード例 #18
0
ファイル: fileop.cpp プロジェクト: feraligatr/vbagx
/****************************************************************************
 * Load savebuffer from FAT file
 ***************************************************************************/
int
LoadBufferFromFAT (char *filepath, bool silent)
{
    int size = 0;

    fatfile = fopen (filepath, "rb");

    if (fatfile <= 0)
    {
        if ( !silent )
        {
            char msg[100];
            sprintf(msg, "Couldn't open %s", filepath);
            WaitPrompt (msg);
        }
        return 0;
    }

	fseek(fatfile, 0, SEEK_END); // go to end of file
	size = ftell(fatfile); // get filesize
	fseek(fatfile, 0, SEEK_SET); // go to start of file
	fread (savebuffer, 1, size, fatfile);
	fclose (fatfile);

    return size;
}
コード例 #19
0
ファイル: gcunzip.cpp プロジェクト: askotx/snes9xgx143
char *
GetFirstZipFilename (int method)
{
	char * firstFilename = NULL;
	char tempbuffer[ZIPCHUNK];
	char filepath[1024];

	if(!MakeFilePath(filepath, FILE_ROM, method))
		return NULL;

	// read start of ZIP
	if(LoadFile (tempbuffer, filepath, ZIPCHUNK, method, NOTSILENT))
	{
		tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27)
		int namelength = tempbuffer[26]; // filename length starts 26 bytes in

		if(namelength > 0 && namelength < 200) // the filename is a reasonable length
		{
			firstFilename = &tempbuffer[30]; // first filename of a ZIP starts 31 bytes in
			firstFilename[namelength] = 0; // truncate at filename length
		}
		else
		{
			WaitPrompt("Error - Invalid ZIP file!");
		}
	}

	return firstFilename;
}
コード例 #20
0
ファイル: networkop.cpp プロジェクト: feraligatr/vbagx
void InitializeNetwork(bool silent)
{
	// stop if we're already initialized, or if auto-init has failed before
	// in which case, manual initialization is required
	if(networkInit || !autoNetworkInit)
		return;

	if(!silent)
		ShowAction ("Initializing network...");

	char ip[16];
	s32 initResult = if_config(ip, NULL, NULL, true);

	if(initResult == 0)
	{
		networkInit = true;
	}
	else
	{
		// do not automatically attempt a reconnection
		autoNetworkInit = false;

		if(!silent)
		{
			char msg[150];
			sprintf(msg, "Unable to initialize network (Error #: %i)", initResult);
			WaitPrompt(msg);
		}
	}
}
コード例 #21
0
ファイル: fileop.c プロジェクト: feraligatr/fceugx
/****************************************************************************
 * LoadFATFile
 ****************************************************************************/
int
LoadFATFile (char *filename, int length)
{
	char zipbuffer[2048];
	char filepath[MAXPATHLEN];
	FILE *handle;
	u32 size;

	/* Check filename length */
	if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) < MAXPATHLEN)
		sprintf(filepath, "%s/%s",currentdir,filelist[selection].filename);
	else
	{
		WaitPrompt((char*) "Maximum filepath length reached!");
		return -1;
	}

	handle = fopen (filepath, "rb");
	if (handle > 0)
	{
		fread (zipbuffer, 1, 2048, handle);

		if (IsZipFile (zipbuffer))
		{
			size = UnZipFATFile (nesromptr, handle);	// unzip from FAT
		}
		else
		{
			// Just load the file up
			fseek(handle, 0, SEEK_END);
			length = ftell(handle);				// get filesize
			fseek(handle, 2048, SEEK_SET);		// seek back to point where we left off
			memcpy (nesromptr, zipbuffer, 2048);	// copy what we already read
			fread (nesromptr + 2048, 1, length - 2048, handle);
			size = length;
		}
		fclose (handle);
		return size;
	}
	else
	{
		WaitPrompt((char*) "Error opening file");
		return 0;
	}

	return 0;
}
コード例 #22
0
ファイル: main.c プロジェクト: LPFaint99/gcmm
/****************************************************************************
* BackupModeAllFiles - SD Mode
* Copy all files on the Memory Card to the SD card
****************************************************************************/
void SD_BackupModeAllFiles ()
{
	int memitems;
	int selected = 0;
	int bytestodo;

	char buffer[128];

	clearRightPane();
	DrawText(386,130," B a c k u p   A l l ");
	DrawText(386,134,"_____________________");

	setfontsize (14);
	writeStatusBar("Backing up all files.", "This may take a while.");
	/*** Get the directory listing from the memory card ***/
	memitems = CardGetDirectory (MEM_CARD);

	/*** If it's a blank card, get out of here ***/
	if (!memitems)
	{
		WaitPrompt ("No saved games to backup!");
	}
	else
	{
		for ( selected = 0; selected < memitems; selected++ ) {
			/*** Backup files ***/
			sprintf(buffer, "[%d/%d] Reading from MC slot B", selected+1, memitems);
			ShowAction(buffer);
			bytestodo = CardReadFile(MEM_CARD, selected);
			if (bytestodo)
			{
				sprintf(buffer, "[%d/%d] Saving to FAT device", selected+1, memitems);
				ShowAction(buffer);
				SDSaveMCImage();
			}
			else
			{
				WaitPrompt ("Error reading MC file");
				return;
			}
		}

		WaitPrompt("Full card backup done!");
	}
}
コード例 #23
0
ファイル: fceustate.c プロジェクト: feraligatr/fceugx
/*** Write to the file ***/
void memfwrite( void *buffer, int len ) {
    if ( (sboffset + len ) > SAVEBUFFERSIZE)
        WaitPrompt("Buffer Exceeded");

    if ( len > 0 ) {
        memcpy(&savebuffer[sboffset], buffer, len );
        sboffset += len;
    }
}
コード例 #24
0
ファイル: memstate.c プロジェクト: feraligatr/fceugx
/*** Write to the file ***/
void memfwrite( void *buffer, int len )
{
	if ( (sboffset + len ) > sizeof(statebuffer))
		WaitPrompt("Buffer Exceeded");

	if ( len > 0 ) {
		memcpy(&statebuffer[sboffset], buffer, len );
		sboffset += len;
	}
}
コード例 #25
0
ファイル: fceustate.c プロジェクト: feraligatr/fceugx
/*** Read from a file ***/
void memfread( void *buffer, int len ) {

    if ( ( sboffset + len ) > SAVEBUFFERSIZE)
        WaitPrompt("Buffer exceeded");

    if ( len > 0 ) {
        memcpy(buffer, &savebuffer[sboffset], len);
        sboffset += len;
    }
}
コード例 #26
0
ファイル: filesel.c プロジェクト: feraligatr/fceugx
/****************************************************************************
 * OpenDVD
 *
 * Function to load a DVD directory and display to user.
****************************************************************************/
int
OpenDVD (int method)
{
	if (!getpvd())
	{
		ShowAction((char*) "Loading DVD...");
		#ifdef HW_DOL
		DVD_Mount(); // mount the DVD unit again
		#elif WII_DVD
		u32 val;
		DI_GetCoverRegister(&val);
		if(val & 0x1)	// True if no disc inside, use (val & 0x2) for true if disc inside.
		{
			WaitPrompt((char *)"No disc inserted!");
			return 0;
		}
		DI_Mount();
		while(DI_GetStatus() & DVD_INIT);
		#endif

		if (!getpvd())
		{
			WaitPrompt ((char *)"Invalid DVD.");
			return 0; // not a ISO9660 DVD
		}
	}

	maxfiles = ParseDVDdirectory(); // load root folder

	// switch to rom folder
	SwitchDVDFolder(GCSettings.LoadFolder);

	if (maxfiles > 0)
	{
		return FileSelector (method);
	}
	else
	{
		// no entries found
		WaitPrompt ((char *)"No Files Found!");
		return 0;
	}
}
コード例 #27
0
ファイル: networkop.cpp プロジェクト: feraligatr/vbagx
bool DownloadUpdate()
{
	bool result = false;
	if(strlen(updateURL) > 0)
	{
		// stop checking if devices were removed/inserted
		// since we're saving a file
		LWP_SuspendThread (devicethread);

		FILE * hfile;
		char updateFile[50];
		sprintf(updateFile, "sd:/%s Update.zip", APPNAME);
		hfile = fopen (updateFile, "wb");

		if (hfile > 0)
		{
			int retval;
			retval = http_request(updateURL, hfile, NULL, (1024*1024*5));
			fclose (hfile);
		}

		bool unzipResult = unzipArchive(updateFile, (char *)"sd:/");
		remove(updateFile); // delete update file

		if(unzipResult)
		{
			result = true;
			WaitPrompt("Update successful!");
		}
		else
		{
			result = false;
			WaitPrompt("Update failed!");
		}

		updateFound = false; // updating is finished (successful or not!)

		// go back to checking if devices were inserted/removed
		LWP_ResumeThread (devicethread);
	}
	return result;
}
コード例 #28
0
ファイル: filesel.c プロジェクト: feraligatr/fceugx
/***************************************************************************
 * Update curent directory name
 ***************************************************************************/
int UpdateDirName(int method)
{
	int size=0;
	char *test;
	char temp[1024];

	// update DVD directory (does not utilize 'currentdir')
	if(method == METHOD_DVD)
	{
		dvddir = filelist[selection].offset;
		dvddirlength = filelist[selection].length;
		return 1;
	}

	/* current directory doesn't change */
	if (strcmp(filelist[selection].filename,".") == 0)
	{
		return 0;
	}
	/* go up to parent directory */
	else if (strcmp(filelist[selection].filename,"..") == 0)
	{
		/* determine last subdirectory namelength */
		sprintf(temp,"%s",currentdir);
		test = strtok(temp,"/");
		while (test != NULL)
		{
			size = strlen(test);
			test = strtok(NULL,"/");
		}

		/* remove last subdirectory name */
		size = strlen(currentdir) - size - 1;
		currentdir[size] = 0;

		return 1;
	}
	/* Open a directory */
	else
	{
		/* test new directory namelength */
		if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) < MAXPATHLEN)
		{
			/* update current directory name */
			sprintf(currentdir, "%s/%s",currentdir, filelist[selection].filename);
			return 1;
		}
		else
		{
			WaitPrompt((char*)"Directory name is too long !");
			return -1;
		}
	}
}
コード例 #29
0
ファイル: memstate.c プロジェクト: feraligatr/fceugx
/*** Read from a file ***/
void memfread( void *buffer, int len )
{

	if ( ( sboffset + len ) > sizeof(statebuffer))
		WaitPrompt("Buffer exceeded");

	if ( len > 0 ) {
		memcpy(buffer, &statebuffer[sboffset], len);
		sboffset += len;
	}
}
コード例 #30
0
ファイル: sdload.cpp プロジェクト: feraligatr/snes9xgx
/***************************************************************************
 * Browse SDCARD subdirectories 
 ***************************************************************************/ 
int parseSDdirectory() {
    int nbfiles = 0;
    DIR_ITER *sddir;
    char filename[MAXPATHLEN];
    struct stat filestat;
        char msg[128];
    
    /* initialize selection */
    selection = offset = 0;

    /* open the directory */ 
    sddir = diropen(currSDdir);
    if (sddir == NULL) {
        sprintf(currSDdir,"%s",rootSDdir);	// if we can't open the previous dir, open root dir
        sddir = diropen(currSDdir);
        WaitPrompt(msg);
        if (sddir == NULL) {
            sprintf(msg, "Error opening %s", currSDdir);
            WaitPrompt(msg);
            return 0;
        }
    }
    
  /* Move to DVD structure - this is required for the file selector */ 
    while(dirnext(sddir,filename,&filestat) == 0) {
        if(strcmp(filename,".") != 0) {
            memset(&filelist[nbfiles], 0, sizeof(FILEENTRIES));
            strncpy(filelist[nbfiles].filename, filename, MAXPATHLEN);
			strncpy(filelist[nbfiles].displayname, filename, MAXDISPLAY+1);	// crop name for display
            filelist[nbfiles].length = filestat.st_size;
            filelist[nbfiles].flags = (filestat.st_mode & _IFDIR) == 0 ? 0 : 1;
            nbfiles++;
        }
	}
  
    /*** close directory ***/
    dirclose(sddir);
  
    return nbfiles;
}