mirror of
https://github.com/dborth/snes9xgx.git
synced 2024-11-01 00:15:14 +01:00
rewrite file code, improved SMB
This commit is contained in:
parent
699d27a4ee
commit
1c12c46122
@ -12,7 +12,7 @@
|
||||
#include "cheats.h"
|
||||
|
||||
#include "snes9xGX.h"
|
||||
#include "filesel.h"
|
||||
#include "fileop.h"
|
||||
#include "menudraw.h"
|
||||
|
||||
extern SCheatData Cheat;
|
||||
|
@ -23,11 +23,10 @@ extern "C" {
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "memmap.h"
|
||||
|
||||
#include "menudraw.h"
|
||||
#include "snes9xGX.h"
|
||||
#include "unzip.h"
|
||||
#include "filesel.h"
|
||||
#include "snes9xGX.h"
|
||||
|
||||
u64 dvddir = 0; // offset of currently selected file or folder
|
||||
int dvddirlength = 0; // length of currently selected file or folder
|
||||
@ -119,7 +118,7 @@ u64 dvdsf_last_length = 0;
|
||||
|
||||
int dvd_buffered_read(void *dst, u32 len, u64 offset)
|
||||
{
|
||||
int ret = 0;
|
||||
int ret = 1;
|
||||
|
||||
// only read data if the data inside dvdsf_buffer cannot be used
|
||||
if(offset != dvdsf_last_offset || len > dvdsf_last_length)
|
||||
@ -148,12 +147,12 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset)
|
||||
}
|
||||
else
|
||||
{
|
||||
// no errors yet -> ret = 0
|
||||
// the return value of dvd_read will be OR'd with ret
|
||||
// because dvd_read does return 1 on error and 0 on success and
|
||||
// because 0 | 1 = 1 ret will also contain 1 if at least one error
|
||||
// occured and 0 otherwise ;)
|
||||
int ret = 0; // return value of dvd_read
|
||||
// no errors yet -> ret = 1
|
||||
// the return value of dvd_read will be AND'd with ret
|
||||
// because dvd_read does return 0 on error and 1 on success and
|
||||
// because 1 & 0 = 0 ret will also contain 0 if at least one error
|
||||
// occured and 1 otherwise ;)
|
||||
int ret = 1; // return value of dvd_read
|
||||
|
||||
// we might need to fix all 3 issues
|
||||
unsigned char *dst = (unsigned char *)dst_v; // gcc will not allow to use var[num] on void* types
|
||||
@ -186,7 +185,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset)
|
||||
}
|
||||
|
||||
// read 32 bytes from the last 32 byte position
|
||||
ret |= dvd_buffered_read(buffer, DVD_OFFSET_MULTIPLY, i);
|
||||
ret &= dvd_buffered_read(buffer, DVD_OFFSET_MULTIPLY, i);
|
||||
|
||||
// copy the bytes to the output buffer and update currentOffset, bufferOffset and bytesToRead
|
||||
memcpy(&dst[bufferOffset], &buffer[j], k);
|
||||
@ -204,7 +203,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset)
|
||||
// read data in 2048 byte sector
|
||||
for(j = 0; j < i; j++)
|
||||
{
|
||||
ret |= dvd_buffered_read(buffer, DVD_MAX_READ_LENGTH, currentOffset); // read sector
|
||||
ret &= dvd_buffered_read(buffer, DVD_MAX_READ_LENGTH, currentOffset); // read sector
|
||||
memcpy(&dst[bufferOffset], buffer, DVD_MAX_READ_LENGTH); // copy to output buffer
|
||||
|
||||
// update currentOffset, bufferOffset and bytesToRead
|
||||
@ -217,7 +216,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset)
|
||||
// fix third issue (length is not a multiply of 32)
|
||||
if(bytesToRead)
|
||||
{
|
||||
ret |= dvd_buffered_read(buffer, DVD_MAX_READ_LENGTH, currentOffset); // read 32 byte from the dvd
|
||||
ret &= dvd_buffered_read(buffer, DVD_MAX_READ_LENGTH, currentOffset); // read 32 byte from the dvd
|
||||
memcpy(&dst[bufferOffset], buffer, bytesToRead); // copy bytes to output buffer
|
||||
}
|
||||
return ret;
|
||||
@ -304,24 +303,38 @@ getpvd ()
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* TestDVD()
|
||||
* MountDVD()
|
||||
*
|
||||
* Tests if a ISO9660 DVD is inserted and available
|
||||
* Tests if a ISO9660 DVD is inserted and available, and mounts it
|
||||
***************************************************************************/
|
||||
bool TestDVD()
|
||||
|
||||
bool MountDVD(bool silent)
|
||||
{
|
||||
if (!getpvd())
|
||||
{
|
||||
ShowAction("Loading DVD...");
|
||||
#ifdef HW_DOL
|
||||
DVD_Mount();
|
||||
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.
|
||||
{
|
||||
if(!silent)
|
||||
WaitPrompt("No disc inserted!");
|
||||
return false;
|
||||
}
|
||||
DI_Mount();
|
||||
while(DI_GetStatus() & DVD_INIT);
|
||||
#endif
|
||||
|
||||
if (!getpvd())
|
||||
{
|
||||
if(!silent)
|
||||
WaitPrompt ("Invalid DVD.");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -509,6 +522,7 @@ int DirectorySearch(char dir[512])
|
||||
* SwitchDVDFolder
|
||||
*
|
||||
* Recursively searches for any directory path 'dir' specified
|
||||
* Also can be used to find and set the offset for a file
|
||||
* Also loads the directory contents via ParseDVDdirectory()
|
||||
* It relies on dvddir, dvddirlength, and filelist being pre-populated
|
||||
***************************************************************************/
|
||||
@ -585,6 +599,7 @@ LoadDVDFileOffset (unsigned char *buffer, int length)
|
||||
int offset;
|
||||
int blocks;
|
||||
int i;
|
||||
int ret = 0;
|
||||
u64 discoffset;
|
||||
char readbuffer[2048];
|
||||
|
||||
@ -592,15 +607,19 @@ LoadDVDFileOffset (unsigned char *buffer, int length)
|
||||
blocks = dvddirlength / 2048;
|
||||
offset = 0;
|
||||
discoffset = dvddir;
|
||||
ShowAction ((char*) "Loading...");
|
||||
ShowAction ("Loading...");
|
||||
|
||||
if(length > 0 && length <= 2048)
|
||||
{
|
||||
dvd_read (buffer, length, discoffset);
|
||||
ret = dvd_read (buffer, length, discoffset);
|
||||
if(ret <= 0) // read failure
|
||||
return 0;
|
||||
}
|
||||
else // load whole file
|
||||
{
|
||||
dvd_read (readbuffer, 2048, discoffset);
|
||||
ret = dvd_read (readbuffer, 2048, discoffset);
|
||||
if(ret <= 0) // read failure
|
||||
return 0;
|
||||
|
||||
if (IsZipFile (readbuffer))
|
||||
{
|
||||
@ -610,18 +629,22 @@ LoadDVDFileOffset (unsigned char *buffer, int length)
|
||||
{
|
||||
for (i = 0; i < blocks; i++)
|
||||
{
|
||||
dvd_read (readbuffer, 2048, discoffset);
|
||||
ret = dvd_read (readbuffer, 2048, discoffset);
|
||||
if(ret <= 0) // read failure
|
||||
return 0;
|
||||
memcpy (buffer + offset, readbuffer, 2048);
|
||||
offset += 2048;
|
||||
discoffset += 2048;
|
||||
ShowProgress ((char *)"Loading...", offset, length);
|
||||
ShowProgress ("Loading...", offset, length);
|
||||
}
|
||||
|
||||
/*** And final cleanup ***/
|
||||
if (dvddirlength % 2048)
|
||||
{
|
||||
i = dvddirlength % 2048;
|
||||
dvd_read (readbuffer, 2048, discoffset);
|
||||
ret = dvd_read (readbuffer, 2048, discoffset);
|
||||
if(ret <= 0) // read failure
|
||||
return 0;
|
||||
memcpy (buffer + offset, readbuffer, i);
|
||||
}
|
||||
}
|
||||
@ -639,7 +662,7 @@ LoadDVDFile(char * buffer, char *filepath, int datasize, bool silent)
|
||||
else
|
||||
{
|
||||
if(!silent)
|
||||
WaitPrompt((char *)"Error loading file!");
|
||||
WaitPrompt("Error loading file!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -10,14 +10,14 @@
|
||||
* DVD I/O functions
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef _NGCDVD_H_
|
||||
#define _NGCDVD_H_
|
||||
#ifndef _NGCDVD_
|
||||
#define _NGCDVD_
|
||||
|
||||
int getpvd ();
|
||||
bool MountDVD(bool silent);
|
||||
int ParseDVDdirectory ();
|
||||
int LoadDVDFileOffset(unsigned char *buffer, int length);
|
||||
int LoadDVDFile(char * buffer, char *filepath, int datasize, bool silent);
|
||||
bool TestDVD();
|
||||
int dvd_read (void *dst, unsigned int len, u64 offset);
|
||||
int dvd_safe_read (void *dst, unsigned int len, u64 offset);
|
||||
bool SwitchDVDFolder(char dir[]);
|
||||
|
@ -13,32 +13,117 @@
|
||||
|
||||
#include <gccore.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ogcsys.h>
|
||||
#include <sys/dir.h>
|
||||
#include <sys/stat.h>
|
||||
#include <zlib.h>
|
||||
#include "memmap.h"
|
||||
#include <sdcard/wiisd_io.h>
|
||||
#include <sdcard/gcsd.h>
|
||||
#include <ogc/usbstorage.h>
|
||||
|
||||
#include "snes9xGX.h"
|
||||
#include "fileop.h"
|
||||
#include "smbop.h"
|
||||
#include "dvd.h"
|
||||
#include "memcardop.h"
|
||||
#include "unzip.h"
|
||||
#include "video.h"
|
||||
#include "menudraw.h"
|
||||
#include "filesel.h"
|
||||
#include "sram.h"
|
||||
#include "preferences.h"
|
||||
#include "snes9xGX.h"
|
||||
|
||||
// FAT file pointer - the only one we should ever use!
|
||||
FILE * fatfile;
|
||||
// file pointer - the only one we should ever use!
|
||||
FILE * file;
|
||||
bool unmountRequired[9] = { false, false, false, false, false, false, false, false, false };
|
||||
bool isMounted[9] = { false, false, false, false, false, false, false, false, false };
|
||||
|
||||
#ifdef HW_RVL
|
||||
const DISC_INTERFACE* sd = &__io_wiisd;
|
||||
const DISC_INTERFACE* usb = &__io_usbstorage;
|
||||
#else
|
||||
const DISC_INTERFACE* carda = &__io_gcsda;
|
||||
const DISC_INTERFACE* cardb = &__io_gcsdb;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* UnmountFAT
|
||||
* Unmounts the FAT device specified
|
||||
* deviceThreading
|
||||
***************************************************************************/
|
||||
void UnmountFAT(PARTITION_INTERFACE part)
|
||||
#define TSTACK 16384
|
||||
lwpq_t devicequeue;
|
||||
lwp_t devicethread;
|
||||
static unsigned char devicestack[TSTACK];
|
||||
|
||||
/****************************************************************************
|
||||
* devicecallback
|
||||
*
|
||||
* This checks our devices for changes (SD/USB removed) and
|
||||
* initializes the network in the background
|
||||
***************************************************************************/
|
||||
static void *
|
||||
devicecallback (void *arg)
|
||||
{
|
||||
if(!fatUnmount(part))
|
||||
fatUnsafeUnmount(part);
|
||||
while (1)
|
||||
{
|
||||
#ifdef HW_RVL
|
||||
if(isMounted[METHOD_SD])
|
||||
{
|
||||
if(!sd->isInserted()) // check if the device was removed
|
||||
{
|
||||
unmountRequired[METHOD_SD] = true;
|
||||
isMounted[METHOD_SD] = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(isMounted[METHOD_USB])
|
||||
{
|
||||
if(!usb->isInserted()) // check if the device was removed - doesn't work on USB!
|
||||
{
|
||||
unmountRequired[METHOD_USB] = true;
|
||||
isMounted[METHOD_USB] = false;
|
||||
}
|
||||
}
|
||||
|
||||
InitializeNetwork(SILENT);
|
||||
#else
|
||||
if(isMounted[METHOD_SD_SLOTA])
|
||||
{
|
||||
if(!carda->isInserted()) // check if the device was removed
|
||||
{
|
||||
unmountRequired[METHOD_SD_SLOTA] = true;
|
||||
isMounted[METHOD_SD_SLOTA] = false;
|
||||
}
|
||||
}
|
||||
if(isMounted[METHOD_SD_SLOTB])
|
||||
{
|
||||
if(!cardb->isInserted()) // check if the device was removed
|
||||
{
|
||||
unmountRequired[METHOD_SD_SLOTB] = true;
|
||||
isMounted[METHOD_SD_SLOTB] = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
usleep(500000); // suspend thread for 1/2 sec
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* InitDeviceThread
|
||||
*
|
||||
* libOGC provides a nice wrapper for LWP access.
|
||||
* This function sets up a new local queue and attaches the thread to it.
|
||||
***************************************************************************/
|
||||
void
|
||||
InitDeviceThread()
|
||||
{
|
||||
/*** Initialise a new queue ***/
|
||||
LWP_InitQueue (&devicequeue);
|
||||
|
||||
/*** Create the thread on this queue ***/
|
||||
LWP_CreateThread (&devicethread, devicecallback, NULL, devicestack, TSTACK, 80);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -48,11 +133,12 @@ void UnmountFAT(PARTITION_INTERFACE part)
|
||||
void UnmountAllFAT()
|
||||
{
|
||||
#ifdef HW_RVL
|
||||
UnmountFAT(PI_INTERNAL_SD);
|
||||
UnmountFAT(PI_USBSTORAGE);
|
||||
fatUnmount("sd");
|
||||
fatUnmount("usb");
|
||||
#else
|
||||
fatUnmount("carda");
|
||||
fatUnmount("cardb");
|
||||
#endif
|
||||
UnmountFAT(PI_SDGECKO_A);
|
||||
UnmountFAT(PI_SDGECKO_B);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -61,67 +147,128 @@ void UnmountAllFAT()
|
||||
* If so, unmounts the device
|
||||
* Attempts to mount the device specified
|
||||
* Sets libfat to use the device by default
|
||||
* Enables read-ahead cache for SD/USB
|
||||
***************************************************************************/
|
||||
bool MountFAT(PARTITION_INTERFACE part)
|
||||
|
||||
bool MountFAT(int method)
|
||||
{
|
||||
UnmountFAT(part);
|
||||
bool mounted = true; // assume our disc is already mounted
|
||||
char name[10];
|
||||
const DISC_INTERFACE* disc = NULL;
|
||||
|
||||
bool mounted = fatMountNormalInterface(part, 8);
|
||||
|
||||
if(mounted)
|
||||
switch(method)
|
||||
{
|
||||
fatSetDefaultInterface(part);
|
||||
#ifdef HW_RVL
|
||||
if(part == PI_INTERNAL_SD || part == PI_USBSTORAGE)
|
||||
fatEnableReadAhead (part, 6, 64);
|
||||
#endif
|
||||
#ifdef HW_RVL
|
||||
case METHOD_SD:
|
||||
sprintf(name, "sd");
|
||||
disc = sd;
|
||||
break;
|
||||
case METHOD_USB:
|
||||
sprintf(name, "usb");
|
||||
disc = usb;
|
||||
break;
|
||||
#else
|
||||
case METHOD_SD_SLOTA:
|
||||
sprintf(name, "carda");
|
||||
disc = carda;
|
||||
break;
|
||||
|
||||
case METHOD_SD_SLOTB:
|
||||
sprintf(name, "cardb");
|
||||
disc = cardb;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return false; // unknown device
|
||||
}
|
||||
|
||||
sprintf(rootdir, "%s:/", name);
|
||||
|
||||
// isInserted doesn't work properly for USB - so we will force a shutdown
|
||||
//unmountRequired[METHOD_USB] = true;
|
||||
|
||||
if(unmountRequired[method])
|
||||
{
|
||||
unmountRequired[method] = false;
|
||||
fatUnmount(name);
|
||||
disc->shutdown();
|
||||
}
|
||||
if(!isMounted[method])
|
||||
{
|
||||
if(!disc->startup())
|
||||
mounted = false;
|
||||
else if(!fatMountSimple(name, disc))
|
||||
mounted = false;
|
||||
else
|
||||
fatEnableReadAhead(name, 6, 64);
|
||||
}
|
||||
|
||||
isMounted[method] = mounted;
|
||||
return mounted;
|
||||
}
|
||||
|
||||
void MountAllFAT()
|
||||
{
|
||||
#ifdef HW_RVL
|
||||
MountFAT(METHOD_SD);
|
||||
MountFAT(METHOD_USB);
|
||||
#else
|
||||
MountFAT(METHOD_SD_SLOTA);
|
||||
MountFAT(METHOD_SD_SLOTB);
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* ChangeFATInterface
|
||||
* Unmounts all devices and attempts to mount/configure the device specified
|
||||
* ChangeInterface
|
||||
* Attempts to mount/configure the device specified
|
||||
***************************************************************************/
|
||||
bool ChangeFATInterface(int method, bool silent)
|
||||
bool ChangeInterface(int method, bool silent)
|
||||
{
|
||||
bool mounted = false;
|
||||
|
||||
if(method == METHOD_SD)
|
||||
{
|
||||
#ifdef HW_RVL
|
||||
mounted = MountFAT(PI_INTERNAL_SD); // try Wii internal SD
|
||||
#endif
|
||||
|
||||
if(!mounted) // internal SD not found
|
||||
mounted = MountFAT(PI_SDGECKO_A); // try SD Gecko on slot A
|
||||
mounted = MountFAT(METHOD_SD); // try Wii internal SD
|
||||
#else
|
||||
mounted = MountFAT(METHOD_SD_SLOTA); // try SD Gecko on slot A
|
||||
if(!mounted) // internal SD and SD Gecko (on slot A) not found
|
||||
mounted = MountFAT(PI_SDGECKO_B); // try SD Gecko on slot B
|
||||
mounted = MountFAT(METHOD_SD_SLOTB); // try SD Gecko on slot B
|
||||
#endif
|
||||
if(!mounted && !silent) // no SD device found
|
||||
WaitPrompt ((char *)"SD card not found!");
|
||||
WaitPrompt ("SD card not found!");
|
||||
}
|
||||
else if(method == METHOD_USB)
|
||||
{
|
||||
#ifdef HW_RVL
|
||||
mounted = MountFAT(PI_USBSTORAGE);
|
||||
mounted = MountFAT(method);
|
||||
|
||||
if(!mounted && !silent)
|
||||
WaitPrompt ((char *)"USB drive not found!");
|
||||
WaitPrompt ("USB drive not found!");
|
||||
#endif
|
||||
}
|
||||
else if(method == METHOD_SMB)
|
||||
{
|
||||
sprintf(rootdir, "smb:/");
|
||||
mounted = ConnectShare(NOTSILENT);
|
||||
}
|
||||
else if(method == METHOD_DVD)
|
||||
{
|
||||
sprintf(rootdir, "/");
|
||||
mounted = MountDVD(NOTSILENT);
|
||||
}
|
||||
|
||||
return mounted;
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* Browse FAT subdirectories
|
||||
* Browse subdirectories
|
||||
**************************************************************************/
|
||||
int
|
||||
ParseFATdirectory(int method)
|
||||
ParseDirectory()
|
||||
{
|
||||
int nbfiles = 0;
|
||||
DIR_ITER *fatdir;
|
||||
DIR_ITER *dir;
|
||||
char fulldir[MAXPATHLEN];
|
||||
char filename[MAXPATHLEN];
|
||||
char tmpname[MAXPATHLEN];
|
||||
struct stat filestat;
|
||||
@ -133,28 +280,32 @@ ParseFATdirectory(int method)
|
||||
// Clear any existing values
|
||||
memset (&filelist, 0, sizeof (FILEENTRIES) * MAXFILES);
|
||||
|
||||
// add device to path
|
||||
sprintf(fulldir, "%s%s", rootdir, currentdir);
|
||||
|
||||
// open the directory
|
||||
fatdir = diropen(currentdir);
|
||||
if (fatdir == NULL)
|
||||
dir = diropen(fulldir);
|
||||
|
||||
if (dir == NULL)
|
||||
{
|
||||
sprintf(msg, "Couldn't open %s", currentdir);
|
||||
sprintf(msg, "Error opening %s", fulldir);
|
||||
WaitPrompt(msg);
|
||||
|
||||
// if we can't open the dir, open root dir
|
||||
sprintf(currentdir,"%s",ROOTFATDIR);
|
||||
sprintf(fulldir,"%s",rootdir);
|
||||
|
||||
fatdir = diropen(currentdir);
|
||||
dir = diropen(currentdir);
|
||||
|
||||
if (fatdir == NULL)
|
||||
if (dir == NULL)
|
||||
{
|
||||
sprintf(msg, "Error opening %s", currentdir);
|
||||
sprintf(msg, "Error opening %s", fulldir);
|
||||
WaitPrompt(msg);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// index files/folders
|
||||
while(dirnext(fatdir,filename,&filestat) == 0)
|
||||
while(dirnext(dir,filename,&filestat) == 0)
|
||||
{
|
||||
if(strcmp(filename,".") != 0)
|
||||
{
|
||||
@ -169,7 +320,7 @@ ParseFATdirectory(int method)
|
||||
}
|
||||
|
||||
// close directory
|
||||
dirclose(fatdir);
|
||||
dirclose(dir);
|
||||
|
||||
// Sort the file list
|
||||
qsort(filelist, nbfiles, sizeof(FILEENTRIES), FileSortCallback);
|
||||
@ -178,109 +329,168 @@ ParseFATdirectory(int method)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* LoadFATSzFile
|
||||
* LoadSzFile
|
||||
* Loads the selected file # from the specified 7z into rbuffer
|
||||
* Returns file size
|
||||
***************************************************************************/
|
||||
int
|
||||
LoadFATSzFile(char * filepath, unsigned char * rbuffer)
|
||||
u32
|
||||
LoadSzFile(char * filepath, unsigned char * rbuffer)
|
||||
{
|
||||
u32 size;
|
||||
fatfile = fopen (filepath, "rb");
|
||||
if (fatfile > 0)
|
||||
file = fopen (filepath, "rb");
|
||||
if (file > 0)
|
||||
{
|
||||
size = SzExtractFile(filelist[selection].offset, rbuffer);
|
||||
fclose (fatfile);
|
||||
fclose (file);
|
||||
return size;
|
||||
}
|
||||
else
|
||||
{
|
||||
WaitPrompt((char*) "Error opening file");
|
||||
WaitPrompt("Error opening file");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* LoadFATFile
|
||||
* LoadFile
|
||||
***************************************************************************/
|
||||
int
|
||||
LoadFATFile (char * rbuffer, char *filepath, int length, bool silent)
|
||||
u32
|
||||
LoadFile (char * rbuffer, char *filepath, u32 length, int method, bool silent)
|
||||
{
|
||||
char zipbuffer[2048];
|
||||
int size = 0;
|
||||
int readsize = 0;
|
||||
u32 size = 0;
|
||||
u32 readsize = 0;
|
||||
|
||||
fatfile = fopen (filepath, "rb");
|
||||
if(!ChangeInterface(method, NOTSILENT))
|
||||
return 0;
|
||||
|
||||
if (fatfile > 0)
|
||||
switch(method)
|
||||
{
|
||||
case METHOD_DVD:
|
||||
return LoadDVDFile (rbuffer, filepath, length, silent);
|
||||
break;
|
||||
case METHOD_MC_SLOTA:
|
||||
return LoadMCFile (rbuffer, CARD_SLOTA, filepath, silent);
|
||||
break;
|
||||
case METHOD_MC_SLOTB:
|
||||
return LoadMCFile (rbuffer, CARD_SLOTB, filepath, silent);
|
||||
break;
|
||||
}
|
||||
|
||||
// add device to filepath
|
||||
char fullpath[1024];
|
||||
sprintf(fullpath, "%s%s", rootdir, filepath);
|
||||
|
||||
file = fopen (fullpath, "rb");
|
||||
|
||||
if (file > 0)
|
||||
{
|
||||
if(length > 0 && length <= 2048) // do a partial read (eg: to check file header)
|
||||
{
|
||||
fread (rbuffer, 1, length, fatfile);
|
||||
size = length;
|
||||
size = fread (rbuffer, 1, length, file);
|
||||
}
|
||||
else // load whole file
|
||||
{
|
||||
readsize = fread (zipbuffer, 1, 2048, fatfile);
|
||||
readsize = fread (zipbuffer, 1, 2048, file);
|
||||
|
||||
if(readsize > 0)
|
||||
{
|
||||
if (IsZipFile (zipbuffer))
|
||||
{
|
||||
size = UnZipBuffer ((unsigned char *)rbuffer, METHOD_SD); // unzip from FAT
|
||||
size = UnZipBuffer ((unsigned char *)rbuffer, method); // unzip
|
||||
}
|
||||
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
|
||||
struct stat fileinfo;
|
||||
fstat(file->_file, &fileinfo);
|
||||
size = fileinfo.st_size;
|
||||
|
||||
memcpy (rbuffer, zipbuffer, 2048); // copy what we already read
|
||||
|
||||
ShowProgress ((char *)"Loading...", 2048, length);
|
||||
ShowProgress ("Loading...", 2048, length);
|
||||
|
||||
int offset = 2048;
|
||||
while(offset < size && readsize != 0)
|
||||
u32 offset = 2048;
|
||||
while(offset < size)
|
||||
{
|
||||
readsize = fread (rbuffer + offset, 1, (1024*512), fatfile); // read in 512K chunks
|
||||
readsize = fread (rbuffer + offset, 1, (1024*512), file); // read in 512K chunks
|
||||
|
||||
if(readsize <= 0 || readsize > (1024*512))
|
||||
break; // read failure
|
||||
|
||||
if(readsize > 0)
|
||||
offset += readsize;
|
||||
ShowProgress ((char *)"Loading...", offset, length);
|
||||
ShowProgress ("Loading...", offset, length);
|
||||
}
|
||||
|
||||
if(offset != size) // # bytes read doesn't match # expected
|
||||
size = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose (file);
|
||||
}
|
||||
fclose (fatfile);
|
||||
return size;
|
||||
}
|
||||
else
|
||||
if(!size && !silent)
|
||||
{
|
||||
if(!silent)
|
||||
WaitPrompt((char*) "Error opening file!");
|
||||
return 0;
|
||||
unmountRequired[method] = true;
|
||||
WaitPrompt("Error loading file!");
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
u32 LoadFile(char filepath[], int method, bool silent)
|
||||
{
|
||||
return LoadFile((char *)savebuffer, filepath, 0, method, silent);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* SaveFATFile
|
||||
* Write buffer to FAT card file
|
||||
* SaveFile
|
||||
* Write buffer to file
|
||||
***************************************************************************/
|
||||
int
|
||||
SaveFATFile (char * buffer, char *filepath, int datasize, bool silent)
|
||||
u32
|
||||
SaveFile (char * buffer, char *filepath, u32 datasize, int method, bool silent)
|
||||
{
|
||||
u32 written = 0;
|
||||
|
||||
if(!ChangeInterface(method, NOTSILENT))
|
||||
return 0;
|
||||
|
||||
switch(method)
|
||||
{
|
||||
case METHOD_MC_SLOTA:
|
||||
return SaveMCFile (buffer, CARD_SLOTA, filepath, datasize, silent);
|
||||
break;
|
||||
case METHOD_MC_SLOTB:
|
||||
return SaveMCFile (buffer, CARD_SLOTB, filepath, datasize, silent);
|
||||
break;
|
||||
}
|
||||
|
||||
if (datasize)
|
||||
{
|
||||
fatfile = fopen (filepath, "wb");
|
||||
// add device to filepath
|
||||
char fullpath[1024];
|
||||
sprintf(fullpath, "%s%s", rootdir, filepath);
|
||||
|
||||
if (fatfile <= 0)
|
||||
// open file for writing
|
||||
file = fopen (filepath, "wb");
|
||||
|
||||
if (file > 0)
|
||||
{
|
||||
char msg[100];
|
||||
sprintf(msg, "Couldn't save %s", filepath);
|
||||
WaitPrompt (msg);
|
||||
return 0;
|
||||
written = fwrite (savebuffer, 1, datasize, file);
|
||||
fclose (file);
|
||||
}
|
||||
|
||||
fwrite (savebuffer, 1, datasize, fatfile);
|
||||
fclose (fatfile);
|
||||
if(!written && !silent)
|
||||
{
|
||||
unmountRequired[method] = true;
|
||||
WaitPrompt ("Error saving file!");
|
||||
}
|
||||
return datasize;
|
||||
}
|
||||
return written;
|
||||
}
|
||||
|
||||
u32 SaveFile(char filepath[], u32 datasize, int method, bool silent)
|
||||
{
|
||||
return SaveFile((char *)savebuffer, filepath, datasize, method, silent);
|
||||
}
|
||||
|
||||
|
@ -8,30 +8,32 @@
|
||||
*
|
||||
* fileop.h
|
||||
*
|
||||
* FAT File operations
|
||||
* File operations
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _FATFILESC_
|
||||
#define _FATFILESC_
|
||||
#ifndef _FILEOP_H_
|
||||
#define _FILEOP_H_
|
||||
|
||||
#include <gccore.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ogcsys.h>
|
||||
#include <fat.h>
|
||||
#include <sys/dir.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define ROOTFATDIR "fat:/"
|
||||
|
||||
void InitDeviceThread();
|
||||
void MountAllFAT();
|
||||
void UnmountAllFAT();
|
||||
bool ChangeFATInterface(int method, bool silent);
|
||||
int ParseFATdirectory(int method);
|
||||
int LoadFATSzFile(char * filepath, unsigned char * rbuffer);
|
||||
int SaveFATFile (char * sbuffer, char *filepath, int length, bool silent);
|
||||
int LoadFATFile (char * sbuffer, char *filepath, int length, bool silent);
|
||||
bool ChangeInterface(int method, bool silent);
|
||||
int ParseDirectory();
|
||||
u32 LoadFile(char * rbuffer, char *filepath, u32 length, int method, bool silent);
|
||||
u32 LoadFile(char filepath[], int method, bool silent);
|
||||
u32 LoadSzFile(char * filepath, unsigned char * rbuffer);
|
||||
u32 SaveFile(char * buffer, char *filepath, u32 datasize, int method, bool silent);
|
||||
u32 SaveFile(char filepath[], u32 datasize, int method, bool silent);
|
||||
|
||||
extern char currFATdir[MAXPATHLEN];
|
||||
extern FILE * fatfile;
|
||||
extern FILE * file;
|
||||
extern bool unmountRequired[];
|
||||
|
||||
#endif
|
||||
|
@ -42,6 +42,7 @@ extern "C" {
|
||||
|
||||
int offset;
|
||||
int selection;
|
||||
char rootdir[10];
|
||||
char currentdir[MAXPATHLEN];
|
||||
char szpath[MAXPATHLEN];
|
||||
int maxfiles;
|
||||
@ -92,19 +93,19 @@ FreeSaveBuffer ()
|
||||
****************************************************************************/
|
||||
int autoLoadMethod()
|
||||
{
|
||||
ShowAction ((char*) "Attempting to determine load method...");
|
||||
ShowAction ("Attempting to determine load method...");
|
||||
|
||||
if(ChangeFATInterface(METHOD_SD, SILENT))
|
||||
if(ChangeInterface(METHOD_SD, SILENT))
|
||||
return METHOD_SD;
|
||||
else if(ChangeFATInterface(METHOD_USB, SILENT))
|
||||
else if(ChangeInterface(METHOD_USB, SILENT))
|
||||
return METHOD_USB;
|
||||
else if(TestDVD())
|
||||
else if(ChangeInterface(METHOD_DVD, SILENT))
|
||||
return METHOD_DVD;
|
||||
else if(ConnectShare (SILENT))
|
||||
else if(ChangeInterface(METHOD_SMB, SILENT))
|
||||
return METHOD_SMB;
|
||||
else
|
||||
{
|
||||
WaitPrompt((char*) "Unable to auto-determine load method!");
|
||||
WaitPrompt("Unable to auto-determine load method!");
|
||||
return 0; // no method found
|
||||
}
|
||||
}
|
||||
@ -116,21 +117,21 @@ int autoLoadMethod()
|
||||
****************************************************************************/
|
||||
int autoSaveMethod()
|
||||
{
|
||||
ShowAction ((char*) "Attempting to determine save method...");
|
||||
ShowAction ("Attempting to determine save method...");
|
||||
|
||||
if(ChangeFATInterface(METHOD_SD, SILENT))
|
||||
if(ChangeInterface(METHOD_SD, SILENT))
|
||||
return METHOD_SD;
|
||||
else if(ChangeFATInterface(METHOD_USB, SILENT))
|
||||
else if(ChangeInterface(METHOD_USB, SILENT))
|
||||
return METHOD_USB;
|
||||
else if(TestCard(CARD_SLOTA, SILENT))
|
||||
return METHOD_MC_SLOTA;
|
||||
else if(TestCard(CARD_SLOTB, SILENT))
|
||||
return METHOD_MC_SLOTB;
|
||||
else if(ConnectShare (SILENT))
|
||||
else if(ChangeInterface(METHOD_SMB, SILENT))
|
||||
return METHOD_SMB;
|
||||
else
|
||||
{
|
||||
WaitPrompt((char*) "Unable to auto-determine save method!");
|
||||
WaitPrompt("Unable to auto-determine save method!");
|
||||
return 0; // no method found
|
||||
}
|
||||
}
|
||||
@ -187,7 +188,7 @@ int UpdateDirName(int method)
|
||||
}
|
||||
else
|
||||
{
|
||||
WaitPrompt((char*)"Directory name is too long!");
|
||||
WaitPrompt("Directory name is too long!");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -204,7 +205,7 @@ bool MakeFilePath(char filepath[], int type, int method)
|
||||
// Check path length
|
||||
if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) >= MAXPATHLEN)
|
||||
{
|
||||
WaitPrompt((char*)"Maximum filepath length reached!");
|
||||
WaitPrompt("Maximum filepath length reached!");
|
||||
filepath[0] = 0;
|
||||
return false;
|
||||
}
|
||||
@ -236,86 +237,20 @@ bool MakeFilePath(char filepath[], int type, int method)
|
||||
}
|
||||
switch(method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
sprintf (temppath, "%s/%s/%s", ROOTFATDIR, folder, file);
|
||||
break;
|
||||
case METHOD_DVD:
|
||||
case METHOD_SMB:
|
||||
sprintf (temppath, "%s/%s", folder, file);
|
||||
break;
|
||||
case METHOD_MC_SLOTA:
|
||||
case METHOD_MC_SLOTB:
|
||||
sprintf (temppath, "%s", file);
|
||||
temppath[31] = 0; // truncate filename
|
||||
break;
|
||||
default:
|
||||
sprintf (temppath, "%s/%s", folder, file);
|
||||
break;
|
||||
}
|
||||
}
|
||||
strcpy(filepath, temppath);
|
||||
return true;
|
||||
}
|
||||
|
||||
int LoadFile(char * buffer, char filepath[], int length, int method, bool silent)
|
||||
{
|
||||
int offset = 0;
|
||||
|
||||
switch(method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
offset = LoadFATFile (buffer, filepath, length, silent);
|
||||
break;
|
||||
case METHOD_SMB:
|
||||
offset = LoadSMBFile (buffer, filepath, length, silent);
|
||||
break;
|
||||
case METHOD_DVD:
|
||||
offset = LoadDVDFile (buffer, filepath, length, silent);
|
||||
break;
|
||||
case METHOD_MC_SLOTA:
|
||||
offset = LoadMCFile (buffer, CARD_SLOTA, filepath, silent);
|
||||
break;
|
||||
case METHOD_MC_SLOTB:
|
||||
offset = LoadMCFile (buffer, CARD_SLOTB, filepath, silent);
|
||||
break;
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
int LoadFile(char filepath[], int method, bool silent)
|
||||
{
|
||||
return LoadFile((char *)savebuffer, filepath, 0, method, silent);
|
||||
}
|
||||
|
||||
int SaveFile(char * buffer, char filepath[], int datasize, int method, bool silent)
|
||||
{
|
||||
int offset = 0;
|
||||
|
||||
switch(method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
offset = SaveFATFile (buffer, filepath, datasize, silent);
|
||||
break;
|
||||
case METHOD_SMB:
|
||||
offset = SaveSMBFile (buffer, filepath, datasize, silent);
|
||||
break;
|
||||
case METHOD_MC_SLOTA:
|
||||
offset = SaveMCFile (buffer, CARD_SLOTA, filepath, datasize, silent);
|
||||
break;
|
||||
case METHOD_MC_SLOTB:
|
||||
offset = SaveMCFile (buffer, CARD_SLOTB, filepath, datasize, silent);
|
||||
break;
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
int SaveFile(char filepath[], int datasize, int method, bool silent)
|
||||
{
|
||||
return SaveFile((char *)savebuffer, filepath, datasize, method, silent);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* FileSortCallback
|
||||
*
|
||||
@ -358,7 +293,7 @@ bool IsValidROM(int method)
|
||||
if(filelist[selection].length < (1024*96) ||
|
||||
filelist[selection].length > (1024*1024*8))
|
||||
{
|
||||
WaitPrompt((char *)"Invalid file size!");
|
||||
WaitPrompt("Invalid file size!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -393,7 +328,7 @@ bool IsValidROM(int method)
|
||||
}
|
||||
}
|
||||
}
|
||||
WaitPrompt((char *)"Unknown file type!");
|
||||
WaitPrompt("Unknown file type!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -513,23 +448,18 @@ int FileSelector (int method)
|
||||
{
|
||||
switch (method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
maxfiles = ParseFATdirectory(method);
|
||||
break;
|
||||
|
||||
case METHOD_DVD:
|
||||
maxfiles = ParseDVDdirectory();
|
||||
break;
|
||||
|
||||
case METHOD_SMB:
|
||||
maxfiles = ParseSMBdirectory(NOTSILENT);
|
||||
default:
|
||||
maxfiles = ParseDirectory();
|
||||
break;
|
||||
}
|
||||
|
||||
if (!maxfiles)
|
||||
{
|
||||
WaitPrompt ((char*) "Error reading directory!");
|
||||
WaitPrompt ("Error reading directory!");
|
||||
haverom = 1; // quit menu
|
||||
}
|
||||
}
|
||||
@ -540,11 +470,6 @@ int FileSelector (int method)
|
||||
}
|
||||
else // this is a file
|
||||
{
|
||||
// better do another unmount/remount, just in case
|
||||
if(method == METHOD_SD || method == METHOD_USB)
|
||||
if(!ChangeFATInterface(method, NOTSILENT))
|
||||
return 0;
|
||||
|
||||
// 7z file - let's open it up to select a file inside
|
||||
if(IsSz())
|
||||
{
|
||||
@ -552,6 +477,11 @@ int FileSelector (int method)
|
||||
if(!MakeFilePath(szpath, FILE_ROM, method))
|
||||
return 0;
|
||||
|
||||
// add device to filepath
|
||||
char fullpath[1024];
|
||||
sprintf(fullpath, "%s%s", rootdir, szpath);
|
||||
strcpy(szpath, fullpath);
|
||||
|
||||
int szfiles = SzParse(szpath, method);
|
||||
if(szfiles)
|
||||
{
|
||||
@ -559,7 +489,7 @@ int FileSelector (int method)
|
||||
inSz = true;
|
||||
}
|
||||
else
|
||||
WaitPrompt((char*) "Error opening archive!");
|
||||
WaitPrompt("Error opening archive!");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -570,7 +500,7 @@ int FileSelector (int method)
|
||||
// store the filename (w/o ext) - used for sram/freeze naming
|
||||
StripExt(Memory.ROMFilename, filelist[selection].filename);
|
||||
|
||||
ShowAction ((char *)"Loading...");
|
||||
ShowAction ("Loading...");
|
||||
|
||||
SNESROMSize = 0;
|
||||
|
||||
@ -587,15 +517,11 @@ int FileSelector (int method)
|
||||
{
|
||||
switch (method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
SNESROMSize = LoadFATSzFile(szpath, (unsigned char *)Memory.ROM);
|
||||
break;
|
||||
case METHOD_DVD:
|
||||
SNESROMSize = SzExtractFile(filelist[selection].offset, (unsigned char *)Memory.ROM);
|
||||
break;
|
||||
case METHOD_SMB:
|
||||
SNESROMSize = LoadSMBSzFile(szpath, (unsigned char *)Memory.ROM);
|
||||
default:
|
||||
SNESROMSize = LoadSzFile(szpath, (unsigned char *)Memory.ROM);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -604,7 +530,7 @@ int FileSelector (int method)
|
||||
if (SNESROMSize > 0)
|
||||
return 1;
|
||||
else
|
||||
WaitPrompt((char*) "Error loading ROM!");
|
||||
WaitPrompt("Error loading ROM!");
|
||||
}
|
||||
}
|
||||
redraw = 1;
|
||||
@ -713,99 +639,32 @@ int FileSelector (int method)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* OpenDVD
|
||||
*
|
||||
* Function to load a DVD directory and display to user.
|
||||
* OpenROM
|
||||
* Opens device specified by method, displays a list of ROMS
|
||||
***************************************************************************/
|
||||
|
||||
int
|
||||
OpenDVD (int method)
|
||||
OpenROM (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(method == METHOD_AUTO)
|
||||
method = autoLoadMethod();
|
||||
|
||||
if (!getpvd())
|
||||
if(ChangeInterface(method, NOTSILENT))
|
||||
{
|
||||
WaitPrompt ((char *)"Invalid DVD.");
|
||||
return 0; // not a ISO9660 DVD
|
||||
}
|
||||
}
|
||||
|
||||
// change current dir to roms directory
|
||||
switch(method)
|
||||
{
|
||||
case METHOD_DVD:
|
||||
currentdir[0] = 0;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* OpenSMB
|
||||
*
|
||||
* Function to load from an SMB share
|
||||
***************************************************************************/
|
||||
int
|
||||
OpenSMB (int method)
|
||||
{
|
||||
// Connect to network share
|
||||
if(ConnectShare (NOTSILENT))
|
||||
{
|
||||
// change current dir to load dir
|
||||
maxfiles = ParseDVDdirectory (); // Parse root directory
|
||||
SwitchDVDFolder(GCSettings.LoadFolder); // switch to ROM folder
|
||||
break;
|
||||
default:
|
||||
sprintf(currentdir, "/%s", GCSettings.LoadFolder);
|
||||
|
||||
maxfiles = ParseSMBdirectory (SILENT);
|
||||
if (maxfiles > 0)
|
||||
{
|
||||
return FileSelector (method);
|
||||
maxfiles = ParseDirectory(); // Parse root directory
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// no entries found
|
||||
WaitPrompt ((char *)"No Files Found!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* OpenFAT
|
||||
*
|
||||
* Function to load from FAT
|
||||
***************************************************************************/
|
||||
int
|
||||
OpenFAT (int method)
|
||||
{
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
{
|
||||
// change current dir to snes roms directory
|
||||
sprintf ( currentdir, "%s/%s", ROOTFATDIR, GCSettings.LoadFolder );
|
||||
|
||||
// Parse initial root directory and get entries list
|
||||
maxfiles = ParseFATdirectory (method);
|
||||
if (maxfiles > 0)
|
||||
{
|
||||
// Select an entry
|
||||
@ -814,41 +673,9 @@ OpenFAT (int method)
|
||||
else
|
||||
{
|
||||
// no entries found
|
||||
WaitPrompt ((char *)"No Files Found!");
|
||||
WaitPrompt ("No Files Found!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* OpenROM
|
||||
* Opens device specified by method, displays a list of ROMS
|
||||
***************************************************************************/
|
||||
|
||||
int
|
||||
OpenROM (int method)
|
||||
{
|
||||
int loadROM = 0;
|
||||
|
||||
if(method == METHOD_AUTO)
|
||||
method = autoLoadMethod();
|
||||
|
||||
switch (method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
loadROM = OpenFAT (method);
|
||||
break;
|
||||
case METHOD_DVD:
|
||||
// Load from DVD
|
||||
loadROM = OpenDVD (method);
|
||||
break;
|
||||
case METHOD_SMB:
|
||||
// Load from Network (SMB)
|
||||
loadROM = OpenSMB (method);
|
||||
break;
|
||||
}
|
||||
|
||||
return loadROM;
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ extern FILEENTRIES filelist[MAXFILES];
|
||||
extern unsigned char *savebuffer;
|
||||
extern int offset;
|
||||
extern int selection;
|
||||
extern char rootdir[10];
|
||||
extern char currentdir[MAXPATHLEN];
|
||||
extern int maxfiles;
|
||||
extern unsigned long SNESROMSize;
|
||||
@ -41,10 +42,6 @@ extern unsigned long SNESROMSize;
|
||||
void AllocSaveBuffer();
|
||||
void FreeSaveBuffer();
|
||||
bool MakeFilePath(char filepath[], int type, int method);
|
||||
int LoadFile(char * buffer, char filepath[], int length, int method, bool silent);
|
||||
int LoadFile(char filepath[], int method, bool silent);
|
||||
int SaveFile(char * buffer, char filepath[], int datasize, int method, bool silent);
|
||||
int SaveFile(char filepath[], int datasize, int method, bool silent);
|
||||
int OpenROM (int method);
|
||||
int autoLoadMethod();
|
||||
int autoSaveMethod();
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include <string.h>
|
||||
#include <fat.h>
|
||||
#include <zlib.h>
|
||||
#include <smb.h>
|
||||
|
||||
#include "snes9x.h"
|
||||
#include "memmap.h"
|
||||
@ -31,7 +30,7 @@
|
||||
#include "snes9xGX.h"
|
||||
#include "images/saveicon.h"
|
||||
#include "freeze.h"
|
||||
#include "filesel.h"
|
||||
#include "fileop.h"
|
||||
#include "menudraw.h"
|
||||
|
||||
extern void S9xSRTCPreSaveState ();
|
||||
@ -128,7 +127,7 @@ NGCFreezeGame (int method, bool8 silent)
|
||||
int woffset = 0; // bytes written (expected)
|
||||
char msg[100];
|
||||
|
||||
ShowAction ((char*) "Saving...");
|
||||
ShowAction ("Saving...");
|
||||
|
||||
if(method == METHOD_AUTO)
|
||||
method = autoSaveMethod();
|
||||
@ -187,7 +186,7 @@ NGCFreezeGame (int method, bool8 silent)
|
||||
if(offset > 0) // save successful!
|
||||
{
|
||||
if(!silent)
|
||||
WaitPrompt((char*) "Save successful");
|
||||
WaitPrompt("Save successful");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@ -244,7 +243,7 @@ NGCUnfreezeGame (int method, bool8 silent)
|
||||
|
||||
bufoffset = 0;
|
||||
|
||||
ShowAction ((char*) "Loading...");
|
||||
ShowAction ("Loading...");
|
||||
|
||||
if(method == METHOD_AUTO)
|
||||
method = autoSaveMethod(); // we use 'Save' because snapshot needs R/W
|
||||
@ -284,7 +283,7 @@ NGCUnfreezeGame (int method, bool8 silent)
|
||||
}
|
||||
else if ( DestBuffSize != decompressedsize )
|
||||
{
|
||||
WaitPrompt((char*) "Unzipped size doesn't match expected size!");
|
||||
WaitPrompt("Unzipped size doesn't match expected size!");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -300,12 +299,12 @@ NGCUnfreezeGame (int method, bool8 silent)
|
||||
if (S9xUnfreezeGame ("AGAME") == SUCCESS)
|
||||
result = 1;
|
||||
else
|
||||
WaitPrompt((char*) "Error thawing");
|
||||
WaitPrompt("Error thawing");
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!silent)
|
||||
WaitPrompt((char*) "Freeze file not found");
|
||||
WaitPrompt("Freeze file not found");
|
||||
}
|
||||
FreeSaveBuffer ();
|
||||
return result;
|
||||
|
@ -220,13 +220,13 @@ gui_draw ()
|
||||
gui_setfontcolour (0,255,0,255);
|
||||
// top bar text
|
||||
setfontsize (32); // 32/24 depending on whether selected or not
|
||||
gui_DrawText (-1, 35, (char *)"Menu");
|
||||
gui_DrawText (-1, 35, "Menu");
|
||||
// main text
|
||||
setfontsize (24);
|
||||
gui_DrawText (75, 113, (char *)"Hello World");
|
||||
gui_DrawText (75, 113, "Hello World");
|
||||
// bottom bar text
|
||||
setfontsize (24);
|
||||
gui_DrawText (75, 400, (char *)"Description");
|
||||
gui_DrawText (75, 400, "Description");
|
||||
}
|
||||
|
||||
void
|
||||
@ -417,7 +417,7 @@ gui_DrawCharacter (FT_Bitmap * bmp, FT_Int x, FT_Int y)
|
||||
* Place the font bitmap on the screen
|
||||
****************************************************************************/
|
||||
void
|
||||
gui_DrawText (int x, int y, char *text)
|
||||
gui_DrawText (int x, int y, const char *text)
|
||||
{
|
||||
int px, n;
|
||||
int i;
|
||||
|
@ -26,7 +26,7 @@ void gui_alphasetup ();
|
||||
void gui_makebg ();
|
||||
void Make_Texture_RGBA8 (void * dst_tex, void * src_data, int width, int height);
|
||||
void gui_drawbox (int x1, int y1, int width, int height, int r, int g, int b, int a);
|
||||
void gui_DrawText (int x, int y, char *text);
|
||||
void gui_DrawText (int x, int y, const char *text);
|
||||
void gui_setfontcolour (int r, int g, int b, int a);
|
||||
void gui_DrawLine (int x1, int y1, int x2, int y2, int r, int g, int b, int a);
|
||||
void gui_clearscreen ();
|
||||
|
@ -82,9 +82,9 @@ bool TestCard(int slot, bool silent)
|
||||
if(!silent)
|
||||
{
|
||||
if (slot == CARD_SLOTA)
|
||||
WaitPrompt((char*) "Mounted Slot A Memory Card!");
|
||||
WaitPrompt("Mounted Slot A Memory Card!");
|
||||
else
|
||||
WaitPrompt((char*) "Mounted Slot B Memory Card!");
|
||||
WaitPrompt("Mounted Slot B Memory Card!");
|
||||
}
|
||||
CARD_Unmount (slot);
|
||||
return true;
|
||||
@ -94,9 +94,9 @@ bool TestCard(int slot, bool silent)
|
||||
if(!silent)
|
||||
{
|
||||
if (slot == CARD_SLOTA)
|
||||
WaitPrompt((char*) "Unable to Mount Slot A Memory Card!");
|
||||
WaitPrompt("Unable to Mount Slot A Memory Card!");
|
||||
else
|
||||
WaitPrompt((char*) "Unable to Mount Slot B Memory Card!");
|
||||
WaitPrompt("Unable to Mount Slot B Memory Card!");
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -154,7 +154,7 @@ VerifyMCFile (char *buf, int slot, char *filename, int datasize)
|
||||
if (!CardFileExists (filename, slot))
|
||||
{
|
||||
CARD_Unmount (slot);
|
||||
WaitPrompt((char*) "Unable to open file for verify!");
|
||||
WaitPrompt("Unable to open file for verify!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -182,7 +182,7 @@ VerifyMCFile (char *buf, int slot, char *filename, int datasize)
|
||||
{
|
||||
CARD_Close (&CardFile);
|
||||
CARD_Unmount (slot);
|
||||
WaitPrompt((char*) "File did not verify!");
|
||||
WaitPrompt("File did not verify!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -199,9 +199,9 @@ VerifyMCFile (char *buf, int slot, char *filename, int datasize)
|
||||
}
|
||||
else
|
||||
if (slot == CARD_SLOTA)
|
||||
WaitPrompt((char*) "Unable to Mount Slot A Memory Card!");
|
||||
WaitPrompt("Unable to Mount Slot A Memory Card!");
|
||||
else
|
||||
WaitPrompt((char*) "Unable to Mount Slot B Memory Card!");
|
||||
WaitPrompt("Unable to Mount Slot B Memory Card!");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -234,7 +234,7 @@ LoadMCFile (char *buf, int slot, char *filename, bool silent)
|
||||
if (!CardFileExists (filename, slot))
|
||||
{
|
||||
if (!silent)
|
||||
WaitPrompt((char*) "Unable to open file");
|
||||
WaitPrompt("Unable to open file");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -264,9 +264,9 @@ LoadMCFile (char *buf, int slot, char *filename, bool silent)
|
||||
}
|
||||
else
|
||||
if (slot == CARD_SLOTA)
|
||||
WaitPrompt((char*) "Unable to Mount Slot A Memory Card!");
|
||||
WaitPrompt("Unable to Mount Slot A Memory Card!");
|
||||
else
|
||||
WaitPrompt((char*) "Unable to Mount Slot B Memory Card!");
|
||||
WaitPrompt("Unable to Mount Slot B Memory Card!");
|
||||
|
||||
return bytesread;
|
||||
}
|
||||
@ -311,7 +311,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
|
||||
if (CardError)
|
||||
{
|
||||
CARD_Unmount (slot);
|
||||
WaitPrompt((char*) "Unable to open card file!");
|
||||
WaitPrompt("Unable to open card file!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -324,7 +324,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
|
||||
if (CardError)
|
||||
{
|
||||
CARD_Unmount (slot);
|
||||
WaitPrompt((char*) "Not enough space to update file!");
|
||||
WaitPrompt("Not enough space to update file!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -334,7 +334,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
|
||||
if (CardError)
|
||||
{
|
||||
CARD_Unmount (slot);
|
||||
WaitPrompt((char*) "Unable to delete temporary file!");
|
||||
WaitPrompt("Unable to delete temporary file!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -343,7 +343,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
|
||||
if (CardError)
|
||||
{
|
||||
CARD_Unmount (slot);
|
||||
WaitPrompt((char*) "Unable to delete existing file!");
|
||||
WaitPrompt("Unable to delete existing file!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -352,7 +352,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
|
||||
if (CardError)
|
||||
{
|
||||
CARD_Unmount (slot);
|
||||
WaitPrompt((char*) "Unable to create updated card file!");
|
||||
WaitPrompt("Unable to create updated card file!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -365,9 +365,9 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
|
||||
{
|
||||
CARD_Unmount (slot);
|
||||
if ( CardError == CARD_ERROR_INSSPACE )
|
||||
WaitPrompt((char*) "Not enough space to create file!");
|
||||
WaitPrompt("Not enough space to create file!");
|
||||
else
|
||||
WaitPrompt((char*) "Unable to create card file!");
|
||||
WaitPrompt("Unable to create card file!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -411,13 +411,13 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
|
||||
}
|
||||
else
|
||||
if ( !silent )
|
||||
WaitPrompt((char*) "This game does not appear to use SRAM");
|
||||
WaitPrompt("This game does not appear to use SRAM");
|
||||
}
|
||||
else
|
||||
if (slot == CARD_SLOTA)
|
||||
WaitPrompt((char*) "Unable to Mount Slot A Memory Card!");
|
||||
WaitPrompt("Unable to Mount Slot A Memory Card!");
|
||||
else
|
||||
WaitPrompt((char*) "Unable to Mount Slot B Memory Card!");
|
||||
WaitPrompt("Unable to Mount Slot B Memory Card!");
|
||||
|
||||
return 0;
|
||||
|
||||
|
@ -259,7 +259,7 @@ void CheatMenu()
|
||||
}
|
||||
else
|
||||
{
|
||||
WaitPrompt((char*)"No cheats found!");
|
||||
WaitPrompt("No cheats found!");
|
||||
}
|
||||
menu = oldmenu;
|
||||
}
|
||||
@ -311,7 +311,7 @@ GameMenu ()
|
||||
if(Cheat.num_cheats == 0)
|
||||
gamemenu[3][0] = '\0';
|
||||
|
||||
ret = RunMenu (gamemenu, gamemenuCount, (char*)"Game Menu");
|
||||
ret = RunMenu (gamemenu, gamemenuCount, "Game Menu");
|
||||
|
||||
switch (ret)
|
||||
{
|
||||
@ -463,7 +463,7 @@ FileOptions ()
|
||||
else if (GCSettings.AutoSave == 2) sprintf (filemenu[5],"Auto Save SNAPSHOT");
|
||||
else if (GCSettings.AutoSave == 3) sprintf (filemenu[5],"Auto Save BOTH");
|
||||
|
||||
ret = RunMenu (filemenu, filemenuCount, (char*)"Save/Load Options");
|
||||
ret = RunMenu (filemenu, filemenuCount, "Save/Load Options");
|
||||
|
||||
switch (ret)
|
||||
{
|
||||
@ -555,7 +555,7 @@ VideoOptions ()
|
||||
|
||||
sprintf (videomenu[7], "Video Shift: %d, %d", GCSettings.xshift, GCSettings.yshift);
|
||||
|
||||
ret = RunMenu (videomenu, videomenuCount, (char*)"Video Options");
|
||||
ret = RunMenu (videomenu, videomenuCount, "Video Options");
|
||||
|
||||
switch (ret)
|
||||
{
|
||||
@ -598,7 +598,7 @@ VideoOptions ()
|
||||
case 8:
|
||||
// reset video shifts
|
||||
GCSettings.xshift = GCSettings.yshift = 0;
|
||||
WaitPrompt((char *)"Video Shift Reset");
|
||||
WaitPrompt("Video Shift Reset");
|
||||
break;
|
||||
|
||||
case -1: // Button B
|
||||
@ -687,21 +687,21 @@ GetButtonMap(u16 ctrlr_type, char* btn_name)
|
||||
|
||||
switch (ctrlr_type) {
|
||||
case CTRLR_NUNCHUK:
|
||||
strncpy (cfg_text[3], (char*)"NUNCHUK", 7);
|
||||
strncpy (cfg_text[3], "NUNCHUK", 7);
|
||||
break;
|
||||
case CTRLR_CLASSIC:
|
||||
strncpy (cfg_text[3], (char*)"CLASSIC", 7);
|
||||
strncpy (cfg_text[3], "CLASSIC", 7);
|
||||
break;
|
||||
case CTRLR_GCPAD:
|
||||
strncpy (cfg_text[3], (char*)"GC PAD", 7);
|
||||
strncpy (cfg_text[3], "GC PAD", 7);
|
||||
break;
|
||||
case CTRLR_WIIMOTE:
|
||||
strncpy (cfg_text[3], (char*)"WIIMOTE", 7);
|
||||
strncpy (cfg_text[3], "WIIMOTE", 7);
|
||||
break;
|
||||
};
|
||||
|
||||
/*** note which button we are remapping ***/
|
||||
sprintf (temp, (char*)"Remapping ");
|
||||
sprintf (temp, "Remapping ");
|
||||
for (k=0; k<9-strlen(btn_name); k++) strcat(temp, " "); // add whitespace padding to align text
|
||||
strncat (temp, btn_name, 9); // snes button we are remapping
|
||||
strncpy (cfg_text[0], temp, 19); // copy this all back to the text we wish to display
|
||||
@ -757,19 +757,19 @@ ConfigureButtons (u16 ctrlr_type)
|
||||
/*** Update Menu Title (based on controller we're configuring) ***/
|
||||
switch (ctrlr_type) {
|
||||
case CTRLR_NUNCHUK:
|
||||
menu_title = (char*)"SNES - NUNCHUK";
|
||||
sprintf(menu_title, "SNES - NUNCHUK");
|
||||
currentpadmap = ncpadmap;
|
||||
break;
|
||||
case CTRLR_CLASSIC:
|
||||
menu_title = (char*)"SNES - CLASSIC";
|
||||
sprintf(menu_title, "SNES - CLASSIC");
|
||||
currentpadmap = ccpadmap;
|
||||
break;
|
||||
case CTRLR_GCPAD:
|
||||
menu_title = (char*)"SNES - GC PAD";
|
||||
sprintf(menu_title, "SNES - GC PAD");
|
||||
currentpadmap = gcpadmap;
|
||||
break;
|
||||
case CTRLR_WIIMOTE:
|
||||
menu_title = (char*)"SNES - WIIMOTE";
|
||||
sprintf(menu_title, "SNES - WIIMOTE");
|
||||
currentpadmap = wmpadmap;
|
||||
break;
|
||||
};
|
||||
@ -793,7 +793,7 @@ ConfigureButtons (u16 ctrlr_type)
|
||||
strncat (temp, ctrlr_def[ctrlr_type].map[j].name, 6); // update button map display
|
||||
}
|
||||
else
|
||||
strcat (temp, (char*)"---"); // otherwise, button is 'unmapped'
|
||||
strcat (temp, "---"); // otherwise, button is 'unmapped'
|
||||
strncpy (cfg_btns_menu[i], temp, 19); // move back updated information
|
||||
|
||||
}
|
||||
@ -878,7 +878,7 @@ ConfigureControllers ()
|
||||
else sprintf (ctlrmenu[3], "Justifiers: OFF");
|
||||
|
||||
/*** Controller Config Menu ***/
|
||||
ret = RunMenu (ctlrmenu, ctlrmenucount, (char*)"Configure Controllers");
|
||||
ret = RunMenu (ctlrmenu, ctlrmenucount, "Configure Controllers");
|
||||
|
||||
switch (ret)
|
||||
{
|
||||
@ -953,7 +953,7 @@ PreferencesMenu ()
|
||||
menu = 0;
|
||||
while (quit == 0)
|
||||
{
|
||||
ret = RunMenu (prefmenu, prefmenuCount, (char*)"Preferences");
|
||||
ret = RunMenu (prefmenu, prefmenuCount, "Preferences");
|
||||
|
||||
switch (ret)
|
||||
{
|
||||
@ -971,7 +971,7 @@ PreferencesMenu ()
|
||||
|
||||
case 3:
|
||||
DefaultSettings ();
|
||||
WaitPrompt((char *)"Preferences Reset");
|
||||
WaitPrompt("Preferences Reset");
|
||||
break;
|
||||
|
||||
case -1: /*** Button B ***/
|
||||
@ -1030,7 +1030,7 @@ MainMenu (int selectedMenu)
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = RunMenu (menuitems, menucount, (char*)"Main Menu");
|
||||
ret = RunMenu (menuitems, menucount, "Main Menu");
|
||||
}
|
||||
|
||||
switch (ret)
|
||||
|
@ -144,7 +144,7 @@ DrawCharacter (FT_Bitmap * bmp, FT_Int x, FT_Int y)
|
||||
* Place the font bitmap on the screen
|
||||
***************************************************************************/
|
||||
void
|
||||
DrawText (int x, int y, char *text)
|
||||
DrawText (int x, int y, const char *text)
|
||||
{
|
||||
int px, n;
|
||||
int i;
|
||||
@ -222,7 +222,7 @@ Credits ()
|
||||
setfontcolour (0x00, 0x00, 0x00);
|
||||
|
||||
setfontsize (28);
|
||||
DrawText (-1, 60, (char*)"Credits");
|
||||
DrawText (-1, 60, "Credits");
|
||||
|
||||
int ypos = 25;
|
||||
|
||||
@ -232,33 +232,33 @@ Credits ()
|
||||
ypos += 32;
|
||||
|
||||
setfontsize (20);
|
||||
DrawText (-1, ypos += 30, (char*)"Technical");
|
||||
DrawText (-1, ypos += 30, "Technical");
|
||||
|
||||
setfontsize (16);
|
||||
|
||||
DrawText (75, ypos += 30, (char*)"Snes9x GX 00x");
|
||||
DrawText (350, ypos, (char*)"michniewski & Tantric");
|
||||
DrawText (75, ypos += 20, (char*)"Snes9X GX 2.0.1 GameCube");
|
||||
DrawText (350, ypos, (char*)"crunchy2, eke-eke, others");
|
||||
DrawText (75, ypos += 20, (char*)"Snes9x GX GameCube Port");
|
||||
DrawText (350, ypos, (char*)"SoftDev");
|
||||
DrawText (75, ypos += 20, (char*)"Snes9x 1.5.1");
|
||||
DrawText (350, ypos, (char*)"Snes9x Team");
|
||||
DrawText (75, ypos += 20, (char*)"GX");
|
||||
DrawText (350, ypos, (char*)"http://www.gc-linux.org");
|
||||
DrawText (75, ypos += 20, (char*)"libogc");
|
||||
DrawText (350, ypos, (char*)"Shagkur & wintermute");
|
||||
DrawText (75, ypos += 30, "Snes9x GX 00x");
|
||||
DrawText (350, ypos, "michniewski & Tantric");
|
||||
DrawText (75, ypos += 20, "Snes9X GX 2.0.1 GameCube");
|
||||
DrawText (350, ypos, "crunchy2, eke-eke, others");
|
||||
DrawText (75, ypos += 20, "Snes9x GX GameCube Port");
|
||||
DrawText (350, ypos, "SoftDev");
|
||||
DrawText (75, ypos += 20, "Snes9x 1.5.1");
|
||||
DrawText (350, ypos, "Snes9x Team");
|
||||
DrawText (75, ypos += 20, "GX");
|
||||
DrawText (350, ypos, "http://www.gc-linux.org");
|
||||
DrawText (75, ypos += 20, "libogc");
|
||||
DrawText (350, ypos, "Shagkur & wintermute");
|
||||
|
||||
setfontsize (20);
|
||||
DrawText (-1, ypos += 40, (char*)"Testing");
|
||||
DrawText (-1, ypos += 40, "Testing");
|
||||
|
||||
setfontsize (16);
|
||||
DrawText (-1, ypos += 30, (char*)"TehSkeen users");
|
||||
DrawText (-1, ypos += 30, "TehSkeen users");
|
||||
|
||||
setfontsize (12);
|
||||
DrawText (-1, ypos += 75, (char*)"Snes9x - Copyright (c) Snes9x Team 1996 - 2006");
|
||||
DrawText (-1, ypos += 15, (char*)"This software is open source and may be copied, distributed, or modified");
|
||||
DrawText (-1, ypos += 15, (char*)"under the terms of the GNU General Public License (GPL) Version 2.");
|
||||
DrawText (-1, ypos += 75, "Snes9x - Copyright (c) Snes9x Team 1996 - 2006");
|
||||
DrawText (-1, ypos += 15, "This software is open source and may be copied, distributed, or modified");
|
||||
DrawText (-1, ypos += 15, "under the terms of the GNU General Public License (GPL) Version 2.");
|
||||
|
||||
showscreen ();
|
||||
}
|
||||
@ -402,7 +402,7 @@ WaitButtonAB ()
|
||||
* Show a prompt
|
||||
***************************************************************************/
|
||||
void
|
||||
WaitPrompt (char *msg)
|
||||
WaitPrompt (const char *msg)
|
||||
{
|
||||
int ypos = (screenheight - 64) >> 1;
|
||||
|
||||
@ -414,7 +414,7 @@ WaitPrompt (char *msg)
|
||||
clearscreen ();
|
||||
DrawText (-1, ypos, msg);
|
||||
ypos += 30;
|
||||
DrawText (-1, ypos, (char*)"Press A to continue");
|
||||
DrawText (-1, ypos, "Press A to continue");
|
||||
showscreen ();
|
||||
WaitButtonA ();
|
||||
}
|
||||
@ -424,7 +424,7 @@ WaitPrompt (char *msg)
|
||||
and 0 if B button was pressed.
|
||||
***************************************************************************/
|
||||
int
|
||||
WaitPromptChoice (char *msg, char *bmsg, char *amsg)
|
||||
WaitPromptChoice (const char *msg, const char *bmsg, const char *amsg)
|
||||
{
|
||||
int ypos = (screenheight - 64) >> 1;
|
||||
|
||||
@ -447,7 +447,7 @@ WaitPromptChoice (char *msg, char *bmsg, char *amsg)
|
||||
* Show an action in progress
|
||||
***************************************************************************/
|
||||
void
|
||||
ShowAction (char *msg)
|
||||
ShowAction (const char *msg)
|
||||
{
|
||||
int ypos = (screenheight - 30) >> 1;
|
||||
|
||||
@ -465,7 +465,7 @@ ShowAction (char *msg)
|
||||
* Generic Menu Routines
|
||||
***************************************************************************/
|
||||
void
|
||||
DrawMenu (char items[][50], char *title, int maxitems, int selected, int fontsize, int x)
|
||||
DrawMenu (char items[][50], const char *title, int maxitems, int selected, int fontsize, int x)
|
||||
{
|
||||
int i, w = 0;
|
||||
int ypos = 0;
|
||||
@ -556,7 +556,7 @@ int FindMenuItem(char items[][50], int maxitems, int currentItem, int direction)
|
||||
int menu = 0;
|
||||
|
||||
int
|
||||
RunMenu (char items[][50], int maxitems, char *title, int fontsize, int x)
|
||||
RunMenu (char items[][50], int maxitems, const char *title, int fontsize, int x)
|
||||
{
|
||||
int redraw = 1;
|
||||
int quit = 0;
|
||||
@ -649,7 +649,7 @@ ShowFiles (FILEENTRIES filelist[], int maxfiles, int offset, int selection)
|
||||
clearscreen ();
|
||||
|
||||
setfontsize (28);
|
||||
DrawText (-1, 60, (char*)"Choose Game");
|
||||
DrawText (-1, 60, "Choose Game");
|
||||
|
||||
setfontsize(18);
|
||||
|
||||
@ -709,7 +709,7 @@ ShowCheats (char items[][50], char itemvalues[][50], int maxitems, int offset, i
|
||||
clearscreen ();
|
||||
|
||||
setfontsize (28);
|
||||
DrawText (-1, 60, (char*)"Cheats");
|
||||
DrawText (-1, 60, "Cheats");
|
||||
|
||||
setfontsize(18);
|
||||
|
||||
@ -758,7 +758,7 @@ void RomInfo()
|
||||
ypos += 32;
|
||||
|
||||
setfontsize (28);
|
||||
DrawText (-1, 60, (char*)"Rom Information");
|
||||
DrawText (-1, 60, "Rom Information");
|
||||
|
||||
setfontsize (16);
|
||||
setfontcolour (0x00, 0x00, 0x00);
|
||||
@ -777,49 +777,49 @@ void RomInfo()
|
||||
char fmtString[1024];
|
||||
|
||||
ypos += 20;
|
||||
DrawText (150, ypos, (char *)MENU_INFO_ROM);
|
||||
DrawText (150, ypos, MENU_INFO_ROM);
|
||||
DrawText (300, ypos, Memory.ROMName);
|
||||
|
||||
ypos += 20;
|
||||
DrawText (150, ypos, (char *)MENU_INFO_ROMID);
|
||||
DrawText (150, ypos, MENU_INFO_ROMID);
|
||||
DrawText (300, ypos, Memory.ROMId);
|
||||
|
||||
ypos += 20;
|
||||
DrawText (150, ypos, (char *)MENU_INFO_COMPANY);
|
||||
DrawText (150, ypos, MENU_INFO_COMPANY);
|
||||
DrawText (300, ypos, Memory.CompanyId);
|
||||
|
||||
ypos += 20;
|
||||
DrawText (150, ypos, (char *)MENU_INFO_SIZE);
|
||||
DrawText (150, ypos, MENU_INFO_SIZE);
|
||||
sprintf(fmtString, "%d", Memory.ROMSize);
|
||||
DrawText (300, ypos, fmtString);
|
||||
|
||||
ypos += 20;
|
||||
DrawText (150, ypos, (char *)MENU_INFO_SRAM);
|
||||
DrawText (150, ypos, MENU_INFO_SRAM);
|
||||
sprintf(fmtString, "%d", Memory.SRAMSize);
|
||||
DrawText (300, ypos, fmtString);
|
||||
|
||||
ypos += 20;
|
||||
DrawText (150, ypos, (char *)MENU_INFO_TYPE);
|
||||
DrawText (150, ypos, MENU_INFO_TYPE);
|
||||
sprintf(fmtString, "%d", Memory.ROMType);
|
||||
DrawText (300, ypos, fmtString);
|
||||
|
||||
ypos += 20;
|
||||
DrawText (150, ypos, (char *)MENU_INFO_CHECKSUM);
|
||||
DrawText (150, ypos, MENU_INFO_CHECKSUM);
|
||||
sprintf(fmtString, "%04x / %04x", Memory.ROMChecksum, Memory.ROMComplementChecksum);
|
||||
DrawText (300, ypos, fmtString);
|
||||
|
||||
ypos += 20;
|
||||
DrawText (150, ypos, (char *)MENU_INFO_TVTYPE);
|
||||
DrawText (150, ypos, MENU_INFO_TVTYPE);
|
||||
sprintf(fmtString, "%s", Settings.PAL ? "PAL" : "NTSC");
|
||||
DrawText (300, ypos, fmtString);
|
||||
|
||||
ypos += 20;
|
||||
DrawText (150, ypos, (char *)MENU_INFO_FRAMES);
|
||||
DrawText (150, ypos, MENU_INFO_FRAMES);
|
||||
sprintf(fmtString, "%d", Memory.ROMFramesPerSecond);
|
||||
DrawText (300, ypos, fmtString);
|
||||
|
||||
ypos += 20;
|
||||
DrawText (150, ypos, (char *)MENU_INFO_CRC32);
|
||||
DrawText (150, ypos, MENU_INFO_CRC32);
|
||||
sprintf(fmtString, "%08X", Memory.ROMCRC32);
|
||||
DrawText (300, ypos, fmtString);
|
||||
|
||||
@ -918,7 +918,7 @@ DrawLine (int x1, int y1, int x2, int y2, u8 r, u8 g, u8 b)
|
||||
* Show the user what's happening
|
||||
***************************************************************************/
|
||||
void
|
||||
ShowProgress (char *msg, int done, int total)
|
||||
ShowProgress (const char *msg, int done, int total)
|
||||
{
|
||||
if(total <= 0) // division by 0 is bad!
|
||||
return;
|
||||
|
@ -27,20 +27,20 @@
|
||||
int FT_Init ();
|
||||
void setfontsize (int pixelsize);
|
||||
void setfontcolour (u8 r, u8 g, u8 b);
|
||||
void DrawText (int x, int y, char *text);
|
||||
void DrawText (int x, int y, const char *text);
|
||||
void unpackbackdrop ();
|
||||
void Credits ();
|
||||
void RomInfo ();
|
||||
void WaitButtonA ();
|
||||
int RunMenu (char items[][50], int maxitems, char *title, int fontsize = 20, int x = -1);
|
||||
void DrawMenu (char items[][50], char *title, int maxitems, int selected, int fontsize = 20, int x = -1);
|
||||
int RunMenu (char items[][50], int maxitems, const char *title, int fontsize = 20, int x = -1);
|
||||
void DrawMenu (char items[][50], const char *title, int maxitems, int selected, int fontsize = 20, int x = -1);
|
||||
void ShowCheats (char items[][50], char itemvalues[][50], int maxitems, int offset, int selection);
|
||||
void ShowFiles (FILEENTRIES filelist[], int maxfiles, int offset, int selection);
|
||||
|
||||
void WaitPrompt (char *msg);
|
||||
int WaitPromptChoice (char *msg, char* bmsg, char* amsg);
|
||||
void ShowAction (char *msg);
|
||||
void ShowProgress (char *msg, int done, int total);
|
||||
void WaitPrompt (const char *msg);
|
||||
int WaitPromptChoice (const char *msg, const char* bmsg, const char* amsg);
|
||||
void ShowAction (const char *msg);
|
||||
void ShowProgress (const char *msg, int done, int total);
|
||||
void DrawPolygon (int vertices, int *varray, u8 r, u8 g, u8 b);
|
||||
void DrawLineFast( int startx, int endx, int y, u8 r, u8 g, u8 b );
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "snes9xGX.h"
|
||||
#include "menudraw.h"
|
||||
#include "memfile.h"
|
||||
#include "filesel.h"
|
||||
#include "fileop.h"
|
||||
|
||||
static int readInt2(MFILE *f) {
|
||||
int res = 0;
|
||||
@ -411,7 +411,7 @@ void LoadPatch(int method)
|
||||
int patchtype;
|
||||
char patchpath[3][512];
|
||||
|
||||
ShowAction((char *)"Loading patch...");
|
||||
ShowAction("Loading patch...");
|
||||
|
||||
AllocSaveBuffer ();
|
||||
|
||||
|
@ -327,7 +327,7 @@ SavePrefs (int method, bool silent)
|
||||
return false;
|
||||
|
||||
if (!silent)
|
||||
ShowAction ((char*) "Saving preferences...");
|
||||
ShowAction ("Saving preferences...");
|
||||
|
||||
AllocSaveBuffer ();
|
||||
datasize = preparePrefsData (method);
|
||||
@ -339,7 +339,7 @@ SavePrefs (int method, bool silent)
|
||||
if (offset > 0)
|
||||
{
|
||||
if (!silent)
|
||||
WaitPrompt ((char *)"Preferences saved");
|
||||
WaitPrompt ("Preferences saved");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -376,17 +376,17 @@ LoadPrefsFromMethod (int method)
|
||||
***************************************************************************/
|
||||
bool LoadPrefs()
|
||||
{
|
||||
ShowAction ((char*) "Loading preferences...");
|
||||
ShowAction ("Loading preferences...");
|
||||
bool prefFound = false;
|
||||
if(ChangeFATInterface(METHOD_SD, SILENT))
|
||||
if(ChangeInterface(METHOD_SD, SILENT))
|
||||
prefFound = LoadPrefsFromMethod(METHOD_SD);
|
||||
if(!prefFound && ChangeFATInterface(METHOD_USB, SILENT))
|
||||
if(!prefFound && ChangeInterface(METHOD_USB, SILENT))
|
||||
prefFound = LoadPrefsFromMethod(METHOD_USB);
|
||||
if(!prefFound && TestCard(CARD_SLOTA, SILENT))
|
||||
prefFound = LoadPrefsFromMethod(METHOD_MC_SLOTA);
|
||||
if(!prefFound && TestCard(CARD_SLOTB, SILENT))
|
||||
prefFound = LoadPrefsFromMethod(METHOD_MC_SLOTB);
|
||||
if(!prefFound && ConnectShare (SILENT))
|
||||
if(!prefFound && ChangeInterface(METHOD_SMB, SILENT))
|
||||
prefFound = LoadPrefsFromMethod(METHOD_SMB);
|
||||
|
||||
return prefFound;
|
||||
|
@ -45,12 +45,6 @@ DefaultSettings ()
|
||||
GCSettings.smbpwd[19] = 0;
|
||||
GCSettings.smbshare[19] = 0;
|
||||
|
||||
GCSettings.gcip[0] = 0;
|
||||
GCSettings.gwip[0] = 0;
|
||||
GCSettings.mask[0] = 0;
|
||||
GCSettings.smbsvid[0] = 0;
|
||||
GCSettings.smbgcid[0] = 0;
|
||||
|
||||
GCSettings.Superscope = 0;
|
||||
GCSettings.Mouse = 0;
|
||||
GCSettings.Justifier = 0;
|
||||
|
@ -12,40 +12,38 @@
|
||||
|
||||
#include <gccore.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ogcsys.h>
|
||||
#include <network.h>
|
||||
#include <smb.h>
|
||||
#include <zlib.h>
|
||||
#include <errno.h>
|
||||
#include "memmap.h"
|
||||
|
||||
#include "smbop.h"
|
||||
#include "snes9xGX.h"
|
||||
#include "fileop.h"
|
||||
#include "unzip.h"
|
||||
#include "video.h"
|
||||
#include "menudraw.h"
|
||||
#include "filesel.h"
|
||||
#include "snes9xGX.h"
|
||||
|
||||
bool networkInit = false;
|
||||
bool networkShareInit = false;
|
||||
unsigned int SMBTimer = 0;
|
||||
#define SMBTIMEOUT ( 3600 ) // Some implementations timeout in 10 minutes
|
||||
|
||||
// SMB connection/file handles - the only ones we should ever use!
|
||||
SMBCONN smbconn;
|
||||
SMBFILE smbfile;
|
||||
|
||||
#define ZIPCHUNK 16384
|
||||
bool networkInitHalt = false;
|
||||
|
||||
/****************************************************************************
|
||||
* InitializeNetwork
|
||||
* Initializes the Wii/GameCube network interface
|
||||
****************************************************************************/
|
||||
|
||||
bool InitializeNetwork(bool silent)
|
||||
void InitializeNetwork(bool silent)
|
||||
{
|
||||
ShowAction ((char*) "Initializing network...");
|
||||
if(networkInit || networkInitHalt)
|
||||
return;
|
||||
|
||||
if(!silent)
|
||||
ShowAction ("Initializing network...");
|
||||
|
||||
s32 result;
|
||||
|
||||
while ((result = net_init()) == -EAGAIN);
|
||||
@ -56,19 +54,28 @@ bool InitializeNetwork(bool silent)
|
||||
|
||||
if (if_config(myIP, NULL, NULL, true) < 0)
|
||||
{
|
||||
networkInitHalt = true; // do not attempt a reconnection again
|
||||
|
||||
if(!silent)
|
||||
WaitPrompt((char*) "Error reading IP address.");
|
||||
return false;
|
||||
WaitPrompt("Error reading IP address.");
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
networkInit = true;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if(!silent)
|
||||
WaitPrompt((char*) "Unable to initialize network.");
|
||||
return false;
|
||||
WaitPrompt("Unable to initialize network.");
|
||||
}
|
||||
}
|
||||
|
||||
void CloseShare()
|
||||
{
|
||||
if(networkShareInit)
|
||||
smbClose();
|
||||
networkShareInit = false;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -90,266 +97,33 @@ ConnectShare (bool silent)
|
||||
strlen(GCSettings.smbip) == 0)
|
||||
{
|
||||
if(!silent)
|
||||
WaitPrompt((char*) "Invalid network settings. Check settings.xml.");
|
||||
WaitPrompt("Invalid network settings. Check settings.xml.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!networkInit)
|
||||
networkInit = InitializeNetwork(silent);
|
||||
InitializeNetwork(silent);
|
||||
|
||||
if(networkInit)
|
||||
{
|
||||
// connection may have expired
|
||||
if (networkShareInit && SMBTimer > SMBTIMEOUT)
|
||||
{
|
||||
networkShareInit = false;
|
||||
SMBTimer = 0;
|
||||
SMB_Close(smbconn);
|
||||
}
|
||||
if(unmountRequired[METHOD_SMB])
|
||||
CloseShare();
|
||||
|
||||
if(!networkShareInit)
|
||||
{
|
||||
if(!silent)
|
||||
ShowAction ((char*) "Connecting to network share...");
|
||||
ShowAction ("Connecting to network share...");
|
||||
|
||||
if(SMB_Connect(&smbconn, GCSettings.smbuser, GCSettings.smbpwd,
|
||||
GCSettings.smbgcid, GCSettings.smbsvid, GCSettings.smbshare, GCSettings.smbip) == SMB_SUCCESS)
|
||||
if(smbInit(GCSettings.smbuser, GCSettings.smbpwd,
|
||||
GCSettings.smbshare, GCSettings.smbip))
|
||||
{
|
||||
networkShareInit = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!networkShareInit && !silent)
|
||||
WaitPrompt ((char*) "Failed to connect to network share.");
|
||||
WaitPrompt ("Failed to connect to network share.");
|
||||
}
|
||||
|
||||
return networkShareInit;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* SMBPath
|
||||
*
|
||||
* Returns a SMB-style path
|
||||
*****************************************************************************/
|
||||
|
||||
char * SMBPath(char * path)
|
||||
{
|
||||
// fix path - replace all '/' with '\'
|
||||
for(uint i=0; i < strlen(path); i++)
|
||||
if(path[i] == '/')
|
||||
path[i] = '\\';
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* parseSMBDirectory
|
||||
*
|
||||
* Load the directory and put in the filelist array
|
||||
*****************************************************************************/
|
||||
int
|
||||
ParseSMBdirectory (bool silent)
|
||||
{
|
||||
if(!ConnectShare (NOTSILENT))
|
||||
return 0;
|
||||
|
||||
int filecount = 0;
|
||||
char searchpath[1024];
|
||||
char tmpname[MAXJOLIET];
|
||||
SMBDIRENTRY smbdir;
|
||||
|
||||
// initialize selection
|
||||
selection = offset = 0;
|
||||
|
||||
// Clear any existing values
|
||||
memset (&filelist, 0, sizeof (FILEENTRIES) * MAXFILES);
|
||||
|
||||
if(strlen(currentdir) <= 1) // root
|
||||
sprintf(searchpath, "*");
|
||||
else
|
||||
sprintf(searchpath, "%s/*", currentdir);
|
||||
|
||||
if (SMB_FindFirst
|
||||
(SMBPath(searchpath), SMB_SRCH_READONLY | SMB_SRCH_DIRECTORY, &smbdir, smbconn) != SMB_SUCCESS)
|
||||
{
|
||||
if(!silent)
|
||||
{
|
||||
char msg[200];
|
||||
sprintf(msg, "Could not open %s", currentdir);
|
||||
WaitPrompt (msg);
|
||||
}
|
||||
|
||||
// if we can't open the dir, open root dir
|
||||
sprintf(searchpath, "/");
|
||||
sprintf(searchpath,"*");
|
||||
sprintf(currentdir,"/");
|
||||
|
||||
if (SMB_FindFirst
|
||||
(SMBPath(searchpath), SMB_SRCH_READONLY | SMB_SRCH_DIRECTORY, &smbdir, smbconn) != SMB_SUCCESS)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// index files/folders
|
||||
do
|
||||
{
|
||||
if(strcmp(smbdir.name,".") != 0 &&
|
||||
!(strlen(currentdir) <= 1 && strcmp(smbdir.name,"..") == 0))
|
||||
{
|
||||
memset (&filelist[filecount], 0, sizeof (FILEENTRIES));
|
||||
filelist[filecount].length = smbdir.size_low;
|
||||
smbdir.name[MAXJOLIET] = 0;
|
||||
|
||||
if(smbdir.attributes == SMB_SRCH_DIRECTORY)
|
||||
filelist[filecount].flags = 1; // flag this as a dir
|
||||
else
|
||||
filelist[filecount].flags = 0;
|
||||
|
||||
StripExt(tmpname, smbdir.name); // hide file extension
|
||||
memcpy (&filelist[filecount].displayname, tmpname, MAXDISPLAY);
|
||||
filelist[filecount].displayname[MAXDISPLAY] = 0;
|
||||
|
||||
strcpy (filelist[filecount].filename, smbdir.name);
|
||||
filecount++;
|
||||
}
|
||||
} while (SMB_FindNext (&smbdir, smbconn) == SMB_SUCCESS);
|
||||
|
||||
// close directory
|
||||
SMB_FindClose (smbconn);
|
||||
|
||||
// Sort the file list
|
||||
qsort(filelist, filecount, sizeof(FILEENTRIES), FileSortCallback);
|
||||
|
||||
return filecount;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Open SMB file
|
||||
***************************************************************************/
|
||||
|
||||
SMBFILE OpenSMBFile(char * filepath)
|
||||
{
|
||||
return SMB_OpenFile (SMBPath(filepath), SMB_OPEN_READING, SMB_OF_OPEN, smbconn);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* LoadSMBSzFile
|
||||
* Loads the selected file # from the specified 7z into rbuffer
|
||||
* Returns file size
|
||||
***************************************************************************/
|
||||
int
|
||||
LoadSMBSzFile(char * filepath, unsigned char * rbuffer)
|
||||
{
|
||||
if(!ConnectShare (NOTSILENT))
|
||||
return 0;
|
||||
|
||||
smbfile = OpenSMBFile(filepath);
|
||||
|
||||
if (smbfile)
|
||||
{
|
||||
u32 size = SzExtractFile(filelist[selection].offset, rbuffer);
|
||||
SMB_CloseFile (smbfile);
|
||||
return size;
|
||||
}
|
||||
else
|
||||
{
|
||||
WaitPrompt((char*) "Error opening file");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* SaveSMBFile
|
||||
* Write buffer to SMB file
|
||||
****************************************************************************/
|
||||
|
||||
int
|
||||
SaveSMBFile (char * sbuffer, char *filepath, int datasize, bool silent)
|
||||
{
|
||||
if(!ConnectShare (NOTSILENT))
|
||||
return 0;
|
||||
|
||||
int dsize = datasize;
|
||||
int wrote = 0;
|
||||
int boffset = 0;
|
||||
|
||||
smbfile =
|
||||
SMB_OpenFile (SMBPath(filepath), SMB_OPEN_WRITING | SMB_DENY_NONE,
|
||||
SMB_OF_CREATE | SMB_OF_TRUNCATE, smbconn);
|
||||
|
||||
if (smbfile)
|
||||
{
|
||||
while (dsize > 0)
|
||||
{
|
||||
if (dsize > 1024)
|
||||
wrote =
|
||||
SMB_WriteFile ((char *) sbuffer + boffset, 1024, boffset, smbfile);
|
||||
else
|
||||
wrote =
|
||||
SMB_WriteFile ((char *) sbuffer + boffset, dsize, boffset, smbfile);
|
||||
|
||||
boffset += wrote;
|
||||
dsize -= wrote;
|
||||
}
|
||||
SMB_CloseFile (smbfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
char msg[100];
|
||||
sprintf(msg, "Couldn't save SMB: %s", SMBPath(filepath));
|
||||
WaitPrompt (msg);
|
||||
}
|
||||
|
||||
return boffset;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* LoadSMBFile
|
||||
* Load up a buffer from SMB file
|
||||
****************************************************************************/
|
||||
|
||||
int
|
||||
LoadSMBFile (char * sbuffer, char *filepath, int length, bool silent)
|
||||
{
|
||||
if(!ConnectShare (NOTSILENT))
|
||||
return 0;
|
||||
|
||||
int ret;
|
||||
int boffset = 0;
|
||||
|
||||
smbfile = OpenSMBFile(filepath);
|
||||
|
||||
if (!smbfile)
|
||||
{
|
||||
if(!silent)
|
||||
{
|
||||
char msg[100];
|
||||
sprintf(msg, "Couldn't open SMB: %s", SMBPath(filepath));
|
||||
WaitPrompt (msg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(length > 0 && length <= 2048) // do a partial read (eg: to check file header)
|
||||
{
|
||||
boffset = SMB_ReadFile (sbuffer, length, 0, smbfile);
|
||||
}
|
||||
else // load whole file
|
||||
{
|
||||
ret = SMB_ReadFile (sbuffer, 1024, boffset, smbfile);
|
||||
|
||||
if (IsZipFile (sbuffer))
|
||||
{
|
||||
boffset = UnZipBuffer ((unsigned char *)sbuffer, METHOD_SMB); // unzip from SMB
|
||||
}
|
||||
else
|
||||
{
|
||||
// Just load the file up
|
||||
while ((ret = SMB_ReadFile (sbuffer + boffset, 2048, boffset, smbfile)) > 0)
|
||||
{
|
||||
boffset += ret;
|
||||
ShowProgress ((char *)"Loading...", boffset, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
SMB_CloseFile (smbfile);
|
||||
|
||||
return boffset;
|
||||
}
|
||||
|
@ -11,21 +11,10 @@
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _NGCSMB_
|
||||
|
||||
#define _NGCSMB_
|
||||
|
||||
#include <smb.h>
|
||||
|
||||
bool InitializeNetwork(bool silent);
|
||||
void InitializeNetwork(bool silent);
|
||||
bool ConnectShare (bool silent);
|
||||
char * SMBPath(char * path);
|
||||
int UpdateSMBdirname();
|
||||
int ParseSMBdirectory (bool silent);
|
||||
SMBFILE OpenSMBFile(char * filepath);
|
||||
int LoadSMBSzFile(char * filepath, unsigned char * rbuffer);
|
||||
int LoadSMBFile (char * sbuffer, char *filepath, int length, bool silent);
|
||||
int SaveSMBFile (char * sbuffer, char *filepath, int length, bool silent);
|
||||
|
||||
extern SMBFILE smbfile;
|
||||
void CloseShare();
|
||||
|
||||
#endif
|
||||
|
@ -19,9 +19,6 @@
|
||||
#include <ogcsys.h>
|
||||
#include <unistd.h>
|
||||
#include <wiiuse/wpad.h>
|
||||
#include <sdcard/card_cmn.h>
|
||||
#include <sdcard/wiisd_io.h>
|
||||
#include <sdcard/card_io.h>
|
||||
#include <fat.h>
|
||||
|
||||
#ifdef WII_DVD
|
||||
@ -76,6 +73,16 @@ extern unsigned int timediffallowed;
|
||||
* Shutdown / Reboot / Exit
|
||||
***************************************************************************/
|
||||
|
||||
void ExitCleanup()
|
||||
{
|
||||
UnmountAllFAT();
|
||||
CloseShare();
|
||||
|
||||
#ifdef HW_RVL
|
||||
DI_Close();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HW_DOL
|
||||
#define PSOSDLOADID 0x7c6000a6
|
||||
int *psoid = (int *) 0x80001800;
|
||||
@ -84,9 +91,8 @@ extern unsigned int timediffallowed;
|
||||
|
||||
void Reboot()
|
||||
{
|
||||
UnmountAllFAT();
|
||||
ExitCleanup();
|
||||
#ifdef HW_RVL
|
||||
DI_Close();
|
||||
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
||||
#else
|
||||
#define SOFTRESET_ADR ((volatile u32*)0xCC003024)
|
||||
@ -96,10 +102,9 @@ void Reboot()
|
||||
|
||||
void ExitToLoader()
|
||||
{
|
||||
UnmountAllFAT();
|
||||
ExitCleanup();
|
||||
// Exit to Loader
|
||||
#ifdef HW_RVL
|
||||
DI_Close();
|
||||
exit(0);
|
||||
#else // gamecube
|
||||
if (psoid[0] == PSOSDLOADID)
|
||||
@ -119,8 +124,7 @@ void ResetCB()
|
||||
}
|
||||
void ShutdownWii()
|
||||
{
|
||||
UnmountAllFAT();
|
||||
DI_Close();
|
||||
ExitCleanup();
|
||||
SYS_ResetSystem(SYS_POWEROFF, 0, 0);
|
||||
}
|
||||
#endif
|
||||
@ -218,12 +222,12 @@ emulate ()
|
||||
}
|
||||
else if ( GCSettings.AutoSave == 2 )
|
||||
{
|
||||
if ( WaitPromptChoice ((char*)"Save Freeze State?", (char*)"Don't Save", (char*)"Save") )
|
||||
if ( WaitPromptChoice ("Save Freeze State?", "Don't Save", "Save") )
|
||||
NGCFreezeGame ( GCSettings.SaveMethod, SILENT );
|
||||
}
|
||||
else if ( GCSettings.AutoSave == 3 )
|
||||
{
|
||||
if ( WaitPromptChoice ((char*)"Save SRAM and Freeze State?", (char*)"Don't Save", (char*)"Save") )
|
||||
if ( WaitPromptChoice ("Save SRAM and Freeze State?", "Don't Save", "Save") )
|
||||
{
|
||||
SaveSRAM(GCSettings.SaveMethod, SILENT );
|
||||
NGCFreezeGame ( GCSettings.SaveMethod, SILENT );
|
||||
@ -414,12 +418,8 @@ main(int argc, char *argv[])
|
||||
while (1);
|
||||
|
||||
// Initialize libFAT for SD and USB
|
||||
fatInit (8, false);
|
||||
|
||||
#ifdef _DEBUG_VIDEO
|
||||
// log stuff
|
||||
debughandle = fopen ("log.txt", "wb");
|
||||
#endif
|
||||
MountAllFAT();
|
||||
InitDeviceThread();
|
||||
|
||||
// Initialize DVD subsystem (GameCube only)
|
||||
#ifdef HW_DOL
|
||||
@ -432,7 +432,7 @@ main(int argc, char *argv[])
|
||||
// Load preferences
|
||||
if(!LoadPrefs())
|
||||
{
|
||||
WaitPrompt((char*) "Preferences reset - check settings!");
|
||||
WaitPrompt("Preferences reset - check settings!");
|
||||
selectedMenu = 1; // change to preferences menu
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,9 @@ enum {
|
||||
METHOD_DVD,
|
||||
METHOD_SMB,
|
||||
METHOD_MC_SLOTA,
|
||||
METHOD_MC_SLOTB
|
||||
METHOD_MC_SLOTB,
|
||||
METHOD_SD_SLOTA,
|
||||
METHOD_SD_SLOTB
|
||||
};
|
||||
|
||||
enum {
|
||||
@ -50,15 +52,12 @@ struct SGCSettings{
|
||||
char LoadFolder[200]; // Path to game files
|
||||
char SaveFolder[200]; // Path to save files
|
||||
char CheatFolder[200]; // Path to cheat files
|
||||
char gcip[16];
|
||||
char gwip[16];
|
||||
char mask[16];
|
||||
|
||||
char smbip[16];
|
||||
char smbuser[20];
|
||||
char smbpwd[20];
|
||||
char smbgcid[20];
|
||||
char smbsvid[20];
|
||||
char smbshare[20];
|
||||
|
||||
int Zoom; // 0 - off, 1 - on
|
||||
float ZoomLevel; // zoom amount
|
||||
int VerifySaves;
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "snes9xGX.h"
|
||||
#include "images/saveicon.h"
|
||||
#include "menudraw.h"
|
||||
#include "filesel.h"
|
||||
#include "fileop.h"
|
||||
|
||||
extern int padcal;
|
||||
extern unsigned short gcpadmap[];
|
||||
@ -131,7 +131,7 @@ decodesavedata (int method, int readsize)
|
||||
}
|
||||
else
|
||||
{
|
||||
WaitPrompt((char*)"Incompatible SRAM save!");
|
||||
WaitPrompt("Incompatible SRAM save!");
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ LoadSRAM (int method, bool silent)
|
||||
if(!MakeFilePath(filepath, FILE_SRAM, method))
|
||||
return 0;
|
||||
|
||||
ShowAction ((char*) "Loading...");
|
||||
ShowAction ("Loading...");
|
||||
|
||||
AllocSaveBuffer();
|
||||
|
||||
@ -169,7 +169,7 @@ LoadSRAM (int method, bool silent)
|
||||
|
||||
// if we reached here, nothing was done!
|
||||
if(!silent)
|
||||
WaitPrompt ((char*) "SRAM file not found");
|
||||
WaitPrompt ("SRAM file not found");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -192,7 +192,7 @@ SaveSRAM (int method, bool silent)
|
||||
if(!MakeFilePath(filepath, FILE_SRAM, method))
|
||||
return false;
|
||||
|
||||
ShowAction ((char*) "Saving...");
|
||||
ShowAction ("Saving...");
|
||||
|
||||
AllocSaveBuffer ();
|
||||
|
||||
@ -205,14 +205,14 @@ SaveSRAM (int method, bool silent)
|
||||
if (offset > 0)
|
||||
{
|
||||
if ( !silent )
|
||||
WaitPrompt((char *)"Save successful");
|
||||
WaitPrompt("Save successful");
|
||||
retval = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!silent)
|
||||
WaitPrompt((char *)"No SRAM data to save!");
|
||||
WaitPrompt("No SRAM data to save!");
|
||||
}
|
||||
|
||||
FreeSaveBuffer ();
|
||||
|
@ -103,32 +103,30 @@ UnZipBuffer (unsigned char *outbuffer, int method)
|
||||
int have = 0;
|
||||
char readbuffer[ZIPCHUNK];
|
||||
u64 discoffset = 0;
|
||||
int sizeread = 0;
|
||||
|
||||
// Read Zip Header
|
||||
switch (method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
fseek(fatfile, 0, SEEK_SET);
|
||||
fread (readbuffer, 1, ZIPCHUNK, fatfile);
|
||||
break;
|
||||
|
||||
case METHOD_DVD:
|
||||
discoffset = dvddir;
|
||||
dvd_read (readbuffer, ZIPCHUNK, discoffset);
|
||||
sizeread = dvd_safe_read (readbuffer, ZIPCHUNK, discoffset);
|
||||
break;
|
||||
|
||||
case METHOD_SMB:
|
||||
SMB_ReadFile(readbuffer, ZIPCHUNK, 0, smbfile);
|
||||
default:
|
||||
fseek(file, 0, SEEK_SET);
|
||||
sizeread = fread (readbuffer, 1, ZIPCHUNK, file);
|
||||
break;
|
||||
}
|
||||
|
||||
if(sizeread <= 0)
|
||||
return 0;
|
||||
|
||||
/*** Copy PKZip header to local, used as info ***/
|
||||
memcpy (&pkzip, readbuffer, sizeof (PKZIPHEADER));
|
||||
|
||||
pkzip.uncompressedSize = FLIP32 (pkzip.uncompressedSize);
|
||||
|
||||
ShowProgress ((char *)"Loading...", 0, pkzip.uncompressedSize);
|
||||
ShowProgress ("Loading...", 0, pkzip.uncompressedSize);
|
||||
|
||||
/*** Prepare the zip stream ***/
|
||||
memset (&zs, 0, sizeof (z_stream));
|
||||
@ -184,22 +182,18 @@ UnZipBuffer (unsigned char *outbuffer, int method)
|
||||
|
||||
switch (method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
fread (readbuffer, 1, ZIPCHUNK, fatfile);
|
||||
break;
|
||||
|
||||
case METHOD_DVD:
|
||||
readoffset += ZIPCHUNK;
|
||||
dvd_read (readbuffer, ZIPCHUNK, discoffset+readoffset);
|
||||
sizeread = dvd_safe_read (readbuffer, ZIPCHUNK, discoffset+readoffset);
|
||||
break;
|
||||
|
||||
case METHOD_SMB:
|
||||
readoffset += ZIPCHUNK;
|
||||
SMB_ReadFile(readbuffer, ZIPCHUNK, readoffset, smbfile);
|
||||
default:
|
||||
sizeread = fread (readbuffer, 1, ZIPCHUNK, file);
|
||||
break;
|
||||
}
|
||||
ShowProgress ((char *)"Loading...", bufferoffset, pkzip.uncompressedSize);
|
||||
if(sizeread <= 0)
|
||||
break; // read failure
|
||||
|
||||
ShowProgress ("Loading...", bufferoffset, pkzip.uncompressedSize);
|
||||
}
|
||||
while (res != Z_STREAM_END);
|
||||
|
||||
@ -234,13 +228,21 @@ GetFirstZipFilename (int method)
|
||||
return NULL;
|
||||
|
||||
// read start of ZIP
|
||||
LoadFile (tempbuffer, filepath, ZIPCHUNK, method, NOTSILENT);
|
||||
|
||||
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;
|
||||
}
|
||||
@ -264,6 +266,7 @@ char szerrormsg[][30] = {
|
||||
"7z: CRC Error",
|
||||
"7z: Not implemented",
|
||||
"7z: Fail",
|
||||
"7z: Data read failure",
|
||||
"7z: Archive error",
|
||||
"7z: Dictionary too large",
|
||||
};
|
||||
@ -312,9 +315,11 @@ void SzDisplayError(SZ_RESULT res)
|
||||
}
|
||||
|
||||
// function used by the 7zip SDK to read data from SD/USB/DVD/SMB
|
||||
|
||||
SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize)
|
||||
{
|
||||
int seekok = 0;
|
||||
int sizeread = 0;
|
||||
|
||||
// the void* object is a SzFileInStream
|
||||
SzFileInStream *s = (SzFileInStream *) object;
|
||||
|
||||
@ -327,26 +332,25 @@ SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, siz
|
||||
// read data
|
||||
switch (szMethod)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
fseek(fatfile, offset, SEEK_SET);
|
||||
fread(sz_buffer, 1, maxRequiredSize, fatfile);
|
||||
break;
|
||||
case METHOD_DVD:
|
||||
dvd_safe_read(sz_buffer, maxRequiredSize, offset);
|
||||
sizeread = dvd_safe_read(sz_buffer, maxRequiredSize, offset);
|
||||
break;
|
||||
case METHOD_SMB:
|
||||
SMB_ReadFile(sz_buffer, maxRequiredSize, offset, smbfile);
|
||||
default:
|
||||
seekok = fseek(file, offset, SEEK_SET);
|
||||
sizeread = fread(sz_buffer, 1, maxRequiredSize, file);
|
||||
break;
|
||||
}
|
||||
|
||||
if(seekok != 0 || sizeread <= 0)
|
||||
return SZE_FAILREAD;
|
||||
|
||||
*buffer = sz_buffer;
|
||||
*processedSize = maxRequiredSize;
|
||||
s->pos += *processedSize;
|
||||
|
||||
if(maxRequiredSize > 1024) // only show progress for large reads
|
||||
// this isn't quite right, but oh well
|
||||
ShowProgress ((char *)"Loading...", s->pos, filelist[selection].length);
|
||||
ShowProgress ("Loading...", s->pos, filelist[selection].length);
|
||||
|
||||
return SZ_OK;
|
||||
}
|
||||
@ -359,10 +363,7 @@ SZ_RESULT SzFileSeekImp(void *object, CFileSize pos)
|
||||
|
||||
// check if the 7z SDK wants to move the pointer to somewhere after the EOF
|
||||
if (pos >= s->len)
|
||||
{
|
||||
WaitPrompt((char *) "7z: Error - attempt to read after EOF!");
|
||||
return SZE_FAIL;
|
||||
}
|
||||
|
||||
// save new position and return
|
||||
s->pos = pos;
|
||||
@ -391,13 +392,9 @@ int SzParse(char * filepath, int method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
fatfile = fopen (filepath, "rb");
|
||||
if(!fatfile)
|
||||
return 0;
|
||||
break;
|
||||
case METHOD_SMB:
|
||||
smbfile = OpenSMBFile(filepath);
|
||||
if(!smbfile)
|
||||
file = fopen (filepath, "rb");
|
||||
if(!file)
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
@ -405,7 +402,7 @@ int SzParse(char * filepath, int method)
|
||||
// set szMethod to current chosen load method
|
||||
szMethod = method;
|
||||
|
||||
// set handler functions for reading data from FAT/SMB/DVD
|
||||
// set handler functions for reading data from SD/USB/SMB/DVD
|
||||
SzArchiveStream.InStream.Read = SzFileReadImp;
|
||||
SzArchiveStream.InStream.Seek = SzFileSeekImp;
|
||||
|
||||
@ -484,10 +481,8 @@ int SzParse(char * filepath, int method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
fclose(fatfile);
|
||||
break;
|
||||
case METHOD_SMB:
|
||||
SMB_CloseFile (smbfile);
|
||||
fclose(file);
|
||||
break;
|
||||
}
|
||||
return nbfiles;
|
||||
|
@ -28,8 +28,6 @@
|
||||
/*** Snes9x GFX Buffer ***/
|
||||
static unsigned char snes9xgfx[1024 * 512 * 2];
|
||||
|
||||
extern unsigned int SMBTimer;
|
||||
|
||||
/*** 2D Video ***/
|
||||
unsigned int *xfb[2] = { NULL, NULL }; // Double buffered
|
||||
int whichfb = 0; // Switch
|
||||
@ -309,7 +307,6 @@ copy_to_xfb (u32 arg)
|
||||
}
|
||||
|
||||
FrameTimer++;
|
||||
SMBTimer++;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -61,10 +61,11 @@ typedef UInt32 CFileSize;
|
||||
|
||||
#define SZE_NOTIMPL (4)
|
||||
#define SZE_FAIL (5)
|
||||
#define SZE_FAILREAD (6)
|
||||
|
||||
#define SZE_ARCHIVE_ERROR (6)
|
||||
#define SZE_ARCHIVE_ERROR (7)
|
||||
|
||||
#define SZE_OUTOFMEMORYDIC (7)
|
||||
#define SZE_OUTOFMEMORYDIC (8)
|
||||
|
||||
#define RINOK(x) { int __result_ = (x); if(__result_ != 0) return __result_; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user