rewrite file code

reset preferences now resets control mappings
improved SMB
This commit is contained in:
dborth 2008-12-19 22:04:55 +00:00
parent d844b56dcb
commit 672f1ac0ba
24 changed files with 880 additions and 923 deletions

View File

@ -114,7 +114,7 @@ u64 dvdsf_last_length = 0;
int dvd_buffered_read(void *dst, u32 len, u64 offset) 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 // only read data if the data inside dvdsf_buffer cannot be used
if(offset != dvdsf_last_offset || len > dvdsf_last_length) if(offset != dvdsf_last_offset || len > dvdsf_last_length)
@ -143,12 +143,12 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset)
} }
else else
{ {
// no errors yet -> ret = 0 // no errors yet -> ret = 1
// the return value of dvd_read will be OR'd with ret // the return value of dvd_read will be AND'd with ret
// because dvd_read does return 1 on error and 0 on success and // because dvd_read does return 0 on error and 1 on success and
// because 0 | 1 = 1 ret will also contain 1 if at least one error // because 1 & 0 = 0 ret will also contain 0 if at least one error
// occured and 0 otherwise ;) // occured and 1 otherwise ;)
int ret = 0; // return value of dvd_read int ret = 1; // return value of dvd_read
// we might need to fix all 3 issues // 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 unsigned char *dst = (unsigned char *)dst_v; // gcc will not allow to use var[num] on void* types
@ -181,7 +181,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset)
} }
// read 32 bytes from the last 32 byte position // 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 // copy the bytes to the output buffer and update currentOffset, bufferOffset and bytesToRead
memcpy(&dst[bufferOffset], &buffer[j], k); memcpy(&dst[bufferOffset], &buffer[j], k);
@ -199,7 +199,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset)
// read data in 2048 byte sector // read data in 2048 byte sector
for(j = 0; j < i; j++) 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 memcpy(&dst[bufferOffset], buffer, DVD_MAX_READ_LENGTH); // copy to output buffer
// update currentOffset, bufferOffset and bytesToRead // update currentOffset, bufferOffset and bytesToRead
@ -212,7 +212,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset)
// fix third issue (length is not a multiply of 32) // fix third issue (length is not a multiply of 32)
if(bytesToRead) 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 memcpy(&dst[bufferOffset], buffer, bytesToRead); // copy bytes to output buffer
} }
return ret; return ret;
@ -299,25 +299,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()) if (!getpvd())
{ {
ShowAction("Loading DVD...");
#ifdef HW_DOL #ifdef HW_DOL
DVD_Mount(); DVD_Mount(); // mount the DVD unit again
#elif WII_DVD #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(); DI_Mount();
while(DI_GetStatus() & DVD_INIT); while(DI_GetStatus() & DVD_INIT);
#endif #endif
if (!getpvd())
return false;
}
if (!getpvd())
{
if(!silent)
WaitPrompt ("Invalid DVD.");
return false;
}
}
return true; return true;
} }
@ -506,6 +519,7 @@ int DirectorySearch(char dir[512])
* SwitchDVDFolder * SwitchDVDFolder
* *
* Recursively searches for any directory path 'dir' specified * 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() * Also loads the directory contents via ParseDVDdirectory()
* It relies on dvddir, dvddirlength, and filelist being pre-populated * It relies on dvddir, dvddirlength, and filelist being pre-populated
***************************************************************************/ ***************************************************************************/
@ -559,7 +573,7 @@ bool SwitchDVDFolder(char origdir[])
if(dir[strlen(dir)-1] == '/') if(dir[strlen(dir)-1] == '/')
dir[strlen(dir)-1] = 0; dir[strlen(dir)-1] = 0;
// start at root of DVD // start searching at root of DVD
dvddir = dvdrootdir; dvddir = dvdrootdir;
dvddirlength = dvdrootlength; dvddirlength = dvdrootlength;
ParseDVDdirectory(); ParseDVDdirectory();
@ -582,6 +596,7 @@ LoadDVDFileOffset (unsigned char *buffer, int length)
int offset; int offset;
int blocks; int blocks;
int i; int i;
int ret = 0;
u64 discoffset; u64 discoffset;
char readbuffer[2048]; char readbuffer[2048];
@ -589,15 +604,19 @@ LoadDVDFileOffset (unsigned char *buffer, int length)
blocks = dvddirlength / 2048; blocks = dvddirlength / 2048;
offset = 0; offset = 0;
discoffset = dvddir; discoffset = dvddir;
ShowAction ((char*) "Loading..."); ShowAction ("Loading...");
if(length > 0 && length <= 2048) // do a partial read (eg: to check file header) 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 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)) if (IsZipFile (readbuffer))
{ {
@ -607,17 +626,22 @@ LoadDVDFileOffset (unsigned char *buffer, int length)
{ {
for (i = 0; i < blocks; i++) 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); memcpy (buffer + offset, readbuffer, 2048);
offset += 2048; offset += 2048;
discoffset += 2048; discoffset += 2048;
ShowProgress ("Loading...", offset, length);
} }
/*** And final cleanup ***/ /*** And final cleanup ***/
if (dvddirlength % 2048) if (dvddirlength % 2048)
{ {
i = 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); memcpy (buffer + offset, readbuffer, i);
} }
} }
@ -635,7 +659,7 @@ LoadDVDFile(char * buffer, char *filepath, int datasize, bool silent)
else else
{ {
if(!silent) if(!silent)
WaitPrompt((char *)"Error loading file!"); WaitPrompt("Error loading file!");
return 0; return 0;
} }
} }

View File

@ -13,13 +13,14 @@
#define _DVD_H_ #define _DVD_H_
int getpvd (); int getpvd ();
bool MountDVD(bool silent);
int ParseDVDdirectory (); int ParseDVDdirectory ();
int LoadDVDFileOffset(unsigned char *buffer, int length); int LoadDVDFileOffset(unsigned char *buffer, int length);
int LoadDVDFile(char * buffer, char *filepath, int datasize, bool silent); int LoadDVDFile(char * buffer, char *filepath, int datasize, bool silent);
bool TestDVD();
int dvd_read (void *dst, unsigned int len, u64 offset); int dvd_read (void *dst, unsigned int len, u64 offset);
int dvd_safe_read (void *dst, unsigned int len, u64 offset); int dvd_safe_read (void *dst, unsigned int len, u64 offset);
bool SwitchDVDFolder(char dir[]); bool SwitchDVDFolder(char dir[]);
void SetDVDDriveType();
#ifdef HW_DOL #ifdef HW_DOL
void dvd_motor_off (); void dvd_motor_off ();
#endif #endif

View File

@ -16,12 +16,15 @@
#include "common.h" #include "common.h"
#include "fceugx.h" #include "fceugx.h"
#include "pad.h"
struct SGCSettings GCSettings; struct SGCSettings GCSettings;
void void
DefaultSettings () DefaultSettings ()
{ {
ResetControls(); // controller button mappings
GCSettings.currpal = 0; GCSettings.currpal = 0;
GCSettings.timing = 0; // 0 - NTSC, 1 - PAL GCSettings.timing = 0; // 0 - NTSC, 1 - PAL
GCSettings.FourScore = 0; GCSettings.FourScore = 0;
@ -53,10 +56,4 @@ DefaultSettings ()
GCSettings.smbuser[19] = 0; GCSettings.smbuser[19] = 0;
GCSettings.smbpwd[19] = 0; GCSettings.smbpwd[19] = 0;
GCSettings.smbshare[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;
} }

View File

@ -30,6 +30,7 @@
#include "menu.h" #include "menu.h"
#include "preferences.h" #include "preferences.h"
#include "fileop.h" #include "fileop.h"
#include "smbop.h"
#include "gcaudio.h" #include "gcaudio.h"
#include "gcvideo.h" #include "gcvideo.h"
#include "pad.h" #include "pad.h"
@ -59,6 +60,16 @@ void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count);
* Shutdown / Reboot / Exit * Shutdown / Reboot / Exit
***************************************************************************/ ***************************************************************************/
void ExitCleanup()
{
UnmountAllFAT();
CloseShare();
#ifdef HW_RVL
DI_Close();
#endif
}
#ifdef HW_DOL #ifdef HW_DOL
#define PSOSDLOADID 0x7c6000a6 #define PSOSDLOADID 0x7c6000a6
int *psoid = (int *) 0x80001800; int *psoid = (int *) 0x80001800;
@ -67,9 +78,8 @@ void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count);
void Reboot() void Reboot()
{ {
UnmountAllFAT(); ExitCleanup();
#ifdef HW_RVL #ifdef HW_RVL
DI_Close();
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
#else #else
#define SOFTRESET_ADR ((volatile u32*)0xCC003024) #define SOFTRESET_ADR ((volatile u32*)0xCC003024)
@ -79,10 +89,9 @@ void Reboot()
void ExitToLoader() void ExitToLoader()
{ {
UnmountAllFAT(); ExitCleanup();
// Exit to Loader // Exit to Loader
#ifdef HW_RVL #ifdef HW_RVL
DI_Close();
exit(0); exit(0);
#else // gamecube #else // gamecube
if (psoid[0] == PSOSDLOADID) if (psoid[0] == PSOSDLOADID)
@ -102,8 +111,7 @@ void ResetCB()
} }
void ShutdownWii() void ShutdownWii()
{ {
UnmountAllFAT(); ExitCleanup();
DI_Close();
SYS_ResetSystem(SYS_POWEROFF, 0, 0); SYS_ResetSystem(SYS_POWEROFF, 0, 0);
} }
#endif #endif
@ -202,7 +210,10 @@ int main(int argc, char *argv[])
} }
InitialiseAudio(); InitialiseAudio();
fatInit (8, false);
// Initialize libFAT for SD and USB
MountAllFAT();
InitDeviceThread();
// Initialize DVD subsystem (GameCube only) // Initialize DVD subsystem (GameCube only)
#ifdef HW_DOL #ifdef HW_DOL
@ -215,7 +226,7 @@ int main(int argc, char *argv[])
/*** Minimal Emulation Loop ***/ /*** Minimal Emulation Loop ***/
if ( !FCEUI_Initialize() ) if ( !FCEUI_Initialize() )
{ {
WaitPrompt((char *)"Unable to initialize FCE Ultra\n"); WaitPrompt("Unable to initialize FCE Ultra\n");
ExitToLoader(); ExitToLoader();
} }
@ -235,7 +246,7 @@ int main(int argc, char *argv[])
// Load preferences // Load preferences
if(!LoadPrefs()) if(!LoadPrefs())
{ {
WaitPrompt((char*) "Preferences reset - check settings!"); WaitPrompt("Preferences reset - check settings!");
selectedMenu = 1; // change to preferences menu selectedMenu = 1; // change to preferences menu
} }
@ -249,9 +260,17 @@ int main(int argc, char *argv[])
ShutdownWii(); ShutdownWii();
#endif #endif
// go back to checking if devices were inserted/removed
// since we're entering the menu
LWP_ResumeThread (devicethread);
MainMenu(selectedMenu); MainMenu(selectedMenu);
selectedMenu = 2; // return to game menu from now on selectedMenu = 2; // return to game menu from now on
// stop checking if devices were removed/inserted
// since we're starting emulation again
LWP_SuspendThread (devicethread);
ResetVideo_Emu(); ResetVideo_Emu();
setFrameTimer(); // set frametimer method before emulation setFrameTimer(); // set frametimer method before emulation
@ -301,7 +320,7 @@ int main(int argc, char *argv[])
} }
// save zoom level // save zoom level
SavePrefs(GCSettings.SaveMethod, SILENT); SavePrefs(SILENT);
ConfigRequested = 0; ConfigRequested = 0;
break; // leave emulation loop break; // leave emulation loop

View File

@ -26,7 +26,9 @@ enum {
METHOD_DVD, METHOD_DVD,
METHOD_SMB, METHOD_SMB,
METHOD_MC_SLOTA, METHOD_MC_SLOTA,
METHOD_MC_SLOTB METHOD_MC_SLOTB,
METHOD_SD_SLOTA,
METHOD_SD_SLOTB
}; };
enum { enum {
@ -46,15 +48,12 @@ struct SGCSettings{
char LoadFolder[200]; // Path to game files char LoadFolder[200]; // Path to game files
char SaveFolder[200]; // Path to save files char SaveFolder[200]; // Path to save files
char CheatFolder[200]; // Path to cheat files char CheatFolder[200]; // Path to cheat files
char gcip[16];
char gwip[16];
char mask[16];
char smbip[16]; char smbip[16];
char smbuser[20]; char smbuser[20];
char smbpwd[20]; char smbpwd[20];
char smbgcid[20];
char smbsvid[20];
char smbshare[20]; char smbshare[20];
int Zoom; // 0 - off, 1 - on int Zoom; // 0 - off, 1 - on
float ZoomLevel; // zoom amount float ZoomLevel; // zoom amount
int VerifySaves; int VerifySaves;

View File

@ -79,7 +79,7 @@ bool SaveRAM (int method, bool silent)
if(nesGameType == 4) if(nesGameType == 4)
{ {
if(!silent) if(!silent)
WaitPrompt((char *)"Saving is not available for FDS games!"); WaitPrompt("Saving is not available for FDS games!");
return false; return false;
} }
@ -89,7 +89,9 @@ bool SaveRAM (int method, bool silent)
if (!MakeFilePath(filepath, FILE_RAM, method)) if (!MakeFilePath(filepath, FILE_RAM, method))
return false; return false;
ShowAction ((char*) "Saving..."); ShowAction ("Saving...");
AllocSaveBuffer ();
// save game save to savebuffer // save game save to savebuffer
if(nesGameType == 1) if(nesGameType == 1)
@ -104,15 +106,16 @@ bool SaveRAM (int method, bool silent)
if (offset > 0) if (offset > 0)
{ {
if ( !silent ) if ( !silent )
WaitPrompt((char *)"Save successful"); WaitPrompt("Save successful");
retval = true; retval = true;
} }
} }
else else
{ {
if ( !silent ) if ( !silent )
WaitPrompt((char *)"No data to save!"); WaitPrompt("No data to save!");
} }
FreeSaveBuffer ();
return retval; return retval;
} }
@ -120,11 +123,12 @@ bool LoadRAM (int method, bool silent)
{ {
char filepath[1024]; char filepath[1024];
int offset = 0; int offset = 0;
bool retval = false;
if(nesGameType == 4) if(nesGameType == 4)
{ {
if(!silent) if(!silent)
WaitPrompt((char *)"Saving is not available for FDS games!"); WaitPrompt("Saving is not available for FDS games!");
return false; return false;
} }
@ -134,7 +138,9 @@ bool LoadRAM (int method, bool silent)
if (!MakeFilePath(filepath, FILE_RAM, method)) if (!MakeFilePath(filepath, FILE_RAM, method))
return false; return false;
ShowAction ((char*) "Loading..."); ShowAction ("Loading...");
AllocSaveBuffer ();
offset = LoadFile(filepath, method, silent); offset = LoadFile(filepath, method, silent);
@ -146,12 +152,14 @@ bool LoadRAM (int method, bool silent)
NGCFCEU_GameSave(&UNIFCart, 1); NGCFCEU_GameSave(&UNIFCart, 1);
ResetNES(); ResetNES();
return true; retval = true;
} }
else
// if we reached here, nothing was done! {
if(!silent) // if we reached here, nothing was done!
WaitPrompt ((char*) "Save file not found"); if(!silent)
WaitPrompt ("Save file not found");
return false; }
FreeSaveBuffer ();
return retval;
} }

View File

@ -292,7 +292,9 @@ bool SaveState (int method, bool silent)
if (!MakeFilePath(filepath, FILE_STATE, method)) if (!MakeFilePath(filepath, FILE_STATE, method))
return false; return false;
ShowAction ((char*) "Saving..."); ShowAction ("Saving...");
AllocSaveBuffer ();
datasize = GCFCEUSS_Save(); datasize = GCFCEUSS_Save();
@ -303,10 +305,11 @@ bool SaveState (int method, bool silent)
if (offset > 0) if (offset > 0)
{ {
if ( !silent ) if ( !silent )
WaitPrompt((char *)"Save successful"); WaitPrompt("Save successful");
retval = true; retval = true;
} }
} }
FreeSaveBuffer ();
return retval; return retval;
} }
@ -314,6 +317,7 @@ bool LoadState (int method, bool silent)
{ {
char filepath[1024]; char filepath[1024];
int offset = 0; int offset = 0;
bool retval = false;
if(method == METHOD_AUTO) if(method == METHOD_AUTO)
method = autoSaveMethod(); // we use 'Save' because we need R/W method = autoSaveMethod(); // we use 'Save' because we need R/W
@ -321,19 +325,23 @@ bool LoadState (int method, bool silent)
if (!MakeFilePath(filepath, FILE_STATE, method)) if (!MakeFilePath(filepath, FILE_STATE, method))
return false; return false;
ShowAction ((char*) "Loading..."); ShowAction ("Loading...");
AllocSaveBuffer ();
offset = LoadFile(filepath, method, silent); offset = LoadFile(filepath, method, silent);
if (offset > 0) if (offset > 0)
{ {
GCFCEUSS_Load(); GCFCEUSS_Load();
return 1; retval = true;
} }
else
// if we reached here, nothing was done! {
if(!silent) // if we reached here, nothing was done!
WaitPrompt ((char*) "State file not found"); if(!silent)
WaitPrompt ("State file not found");
return 0; }
FreeSaveBuffer ();
return retval;
} }

View File

@ -14,26 +14,106 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ogcsys.h> #include <ogcsys.h>
#include <sys/dir.h>
#include <sys/stat.h>
#include <zlib.h> #include <zlib.h>
#include <sdcard/wiisd_io.h>
#include <sdcard/gcsd.h>
#include <ogc/usbstorage.h>
#include "dvd.h"
#include "common.h" #include "common.h"
#include "fceugx.h" #include "fceugx.h"
#include "fileop.h" #include "fileop.h"
#include "memcardop.h"
#include "smbop.h"
#include "gcunzip.h" #include "gcunzip.h"
#include "menudraw.h" #include "menudraw.h"
#include "filesel.h" #include "filesel.h"
// FAT file pointer - the only one we should ever use! // file pointer - the only one we should ever use!
FILE * fatfile; 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 * deviceThreading
* Unmounts the FAT device specified
***************************************************************************/ ***************************************************************************/
void UnmountFAT(PARTITION_INTERFACE part) lwp_t devicethread;
/****************************************************************************
* 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)) while (1)
fatUnsafeUnmount(part); {
#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()
{
LWP_CreateThread (&devicethread, devicecallback, NULL, NULL, 0, 80);
} }
/**************************************************************************** /****************************************************************************
@ -43,11 +123,12 @@ void UnmountFAT(PARTITION_INTERFACE part)
void UnmountAllFAT() void UnmountAllFAT()
{ {
#ifdef HW_RVL #ifdef HW_RVL
UnmountFAT(PI_INTERNAL_SD); fatUnmount("sd");
UnmountFAT(PI_USBSTORAGE); fatUnmount("usb");
#else
fatUnmount("carda");
fatUnmount("cardb");
#endif #endif
UnmountFAT(PI_SDGECKO_A);
UnmountFAT(PI_SDGECKO_B);
} }
/**************************************************************************** /****************************************************************************
@ -56,67 +137,125 @@ void UnmountAllFAT()
* If so, unmounts the device * If so, unmounts the device
* Attempts to mount the device specified * Attempts to mount the device specified
* Sets libfat to use the device by default * 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); switch(method)
if(mounted)
{ {
fatSetDefaultInterface(part); #ifdef HW_RVL
#ifdef HW_RVL case METHOD_SD:
if(part == PI_INTERNAL_SD || part == PI_USBSTORAGE) sprintf(name, "sd");
fatEnableReadAhead (part, 6, 64); disc = sd;
#endif 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);
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; return mounted;
} }
void MountAllFAT()
{
#ifdef HW_RVL
MountFAT(METHOD_SD);
MountFAT(METHOD_USB);
#else
MountFAT(METHOD_SD_SLOTA);
MountFAT(METHOD_SD_SLOTB);
#endif
}
/**************************************************************************** /****************************************************************************
* ChangeFATInterface * ChangeInterface
* Unmounts all devices and attempts to mount/configure the device specified * Attempts to mount/configure the device specified
***************************************************************************/ ***************************************************************************/
bool ChangeFATInterface(int method, bool silent) bool ChangeInterface(int method, bool silent)
{ {
bool mounted = false; bool mounted = false;
if(method == METHOD_SD) if(method == METHOD_SD)
{ {
#ifdef HW_RVL #ifdef HW_RVL
mounted = MountFAT(PI_INTERNAL_SD); // try Wii internal SD mounted = MountFAT(METHOD_SD); // try Wii internal SD
#endif #else
mounted = MountFAT(METHOD_SD_SLOTA); // try SD Gecko on slot A
if(!mounted) // internal SD not found
mounted = MountFAT(PI_SDGECKO_A); // try SD Gecko on slot A
if(!mounted) // internal SD and SD Gecko (on slot A) not found 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 if(!mounted && !silent) // no SD device found
WaitPrompt ((char *)"SD card not found!"); WaitPrompt ("SD card not found!");
} }
else if(method == METHOD_USB) else if(method == METHOD_USB)
{ {
#ifdef HW_RVL #ifdef HW_RVL
mounted = MountFAT(PI_USBSTORAGE); mounted = MountFAT(method);
if(!mounted && !silent) if(!mounted && !silent)
WaitPrompt ((char *)"USB drive not found!"); WaitPrompt ("USB drive not found!");
#endif #endif
} }
else if(method == METHOD_SMB)
{
sprintf(rootdir, "smb:/");
mounted = ConnectShare(NOTSILENT);
}
else if(method == METHOD_DVD)
{
sprintf(rootdir, "/");
mounted = MountDVD(NOTSILENT);
}
return mounted; return mounted;
} }
/*************************************************************************** /***************************************************************************
* Browse FAT subdirectories * Browse subdirectories
**************************************************************************/ **************************************************************************/
int int
ParseFATdirectory(int method) ParseDirectory()
{ {
int nbfiles = 0; int nbfiles = 0;
DIR_ITER *fatdir; DIR_ITER *dir;
char fulldir[MAXPATHLEN];
char filename[MAXPATHLEN]; char filename[MAXPATHLEN];
char tmpname[MAXPATHLEN]; char tmpname[MAXPATHLEN];
struct stat filestat; struct stat filestat;
@ -128,28 +267,32 @@ ParseFATdirectory(int method)
// Clear any existing values // Clear any existing values
memset (&filelist, 0, sizeof (FILEENTRIES) * MAXFILES); memset (&filelist, 0, sizeof (FILEENTRIES) * MAXFILES);
// add device to path
sprintf(fulldir, "%s%s", rootdir, currentdir);
// open the directory // open the directory
fatdir = diropen(currentdir); dir = diropen(fulldir);
if (fatdir == NULL)
if (dir == NULL)
{ {
sprintf(msg, "Couldn't open %s", currentdir); sprintf(msg, "Error opening %s", fulldir);
WaitPrompt(msg); WaitPrompt(msg);
// if we can't open the dir, open root dir // 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); WaitPrompt(msg);
return 0; return 0;
} }
} }
// index files/folders // index files/folders
while(dirnext(fatdir,filename,&filestat) == 0) while(dirnext(dir,filename,&filestat) == 0)
{ {
if(strcmp(filename,".") != 0) if(strcmp(filename,".") != 0)
{ {
@ -164,7 +307,7 @@ ParseFATdirectory(int method)
} }
// close directory // close directory
dirclose(fatdir); dirclose(dir);
// Sort the file list // Sort the file list
qsort(filelist, nbfiles, sizeof(FILEENTRIES), FileSortCallback); qsort(filelist, nbfiles, sizeof(FILEENTRIES), FileSortCallback);
@ -173,99 +316,190 @@ ParseFATdirectory(int method)
} }
/**************************************************************************** /****************************************************************************
* LoadFATSzFile * LoadSzFile
* Loads the selected file # from the specified 7z into rbuffer * Loads the selected file # from the specified 7z into rbuffer
* Returns file size * Returns file size
***************************************************************************/ ***************************************************************************/
int u32
LoadFATSzFile(char * filepath, unsigned char * rbuffer) LoadSzFile(char * filepath, unsigned char * rbuffer)
{ {
u32 size; u32 size = 0;
fatfile = fopen (filepath, "rb");
if (fatfile > 0) // stop checking if devices were removed/inserted
// since we're loading a file
LWP_SuspendThread (devicethread);
file = fopen (filepath, "rb");
if (file > 0)
{ {
size = SzExtractFile(filelist[selection].offset, rbuffer); size = SzExtractFile(filelist[selection].offset, rbuffer);
fclose (fatfile); fclose (file);
return size;
} }
else else
{ {
WaitPrompt((char*) "Error opening file"); WaitPrompt("Error opening file");
return 0;
} }
// go back to checking if devices were inserted/removed
LWP_ResumeThread (devicethread);
return size;
} }
/**************************************************************************** /****************************************************************************
* LoadFATFile * LoadFile
***************************************************************************/ ***************************************************************************/
int u32
LoadFATFile (char * rbuffer, char *filepath, int length, bool silent) LoadFileBuf (char * rbuffer, char *filepath, u32 length, int method, bool silent)
{ {
char zipbuffer[2048]; char zipbuffer[2048];
int size = 0; u32 size = 0;
int readsize = 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;
}
// stop checking if devices were removed/inserted
// since we're loading a file
LWP_SuspendThread (devicethread);
// 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) if(length > 0 && length <= 2048) // do a partial read (eg: to check file header)
{ {
fread (rbuffer, 1, length, fatfile); size = fread (rbuffer, 1, length, file);
size = length;
} }
else // load whole file else // load whole file
{ {
readsize = fread (zipbuffer, 1, 2048, fatfile); readsize = fread (zipbuffer, 1, 2048, file);
if(readsize > 0) if(readsize > 0)
{ {
if (IsZipFile (zipbuffer)) if (IsZipFile (zipbuffer))
{ {
size = UnZipBuffer ((unsigned char *)rbuffer, METHOD_SD); // unzip from FAT size = UnZipBuffer ((unsigned char *)rbuffer, method); // unzip
} }
else else
{ {
// Just load the file up struct stat fileinfo;
fseek(fatfile, 0, SEEK_END); // go to end of file fstat(file->_file, &fileinfo);
size = ftell(fatfile); // get filesize size = fileinfo.st_size;
fseek(fatfile, 0, SEEK_SET); // go to start of file
fread (rbuffer, 1, size, fatfile); memcpy (rbuffer, zipbuffer, 2048); // copy what we already read
ShowProgress ("Loading...", 2048, length);
u32 offset = 2048;
while(offset < size)
{
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 ("Loading...", offset, length);
}
if(offset != size) // # bytes read doesn't match # expected
size = 0;
} }
} }
} }
fclose (fatfile); fclose (file);
return size;
} }
else if(!size && !silent)
{ {
if(!silent) unmountRequired[method] = true;
WaitPrompt((char*) "Error opening file!"); WaitPrompt("Error loading file!");
return 0;
} }
// go back to checking if devices were inserted/removed
LWP_ResumeThread (devicethread);
return size;
}
u32 LoadFile(char filepath[], int method, bool silent)
{
return LoadFileBuf((char *)savebuffer, filepath, 0, method, silent);
} }
/**************************************************************************** /****************************************************************************
* SaveFATFile * SaveFile
* Write buffer to FAT card file * Write buffer to file
***************************************************************************/ ***************************************************************************/
int u32
SaveFATFile (char * buffer, char *filepath, int datasize, bool silent) SaveFileBuf (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) if (datasize)
{ {
fatfile = fopen (filepath, "wb"); // stop checking if devices were removed/inserted
// since we're saving a file
LWP_SuspendThread (devicethread);
if (fatfile <= 0) // add device to filepath
{ char fullpath[1024];
char msg[100]; sprintf(fullpath, "%s%s", rootdir, filepath);
sprintf(msg, "Couldn't save %s", filepath);
WaitPrompt (msg);
return 0;
}
fwrite (savebuffer, 1, datasize, fatfile); // open file for writing
fclose (fatfile); file = fopen (filepath, "wb");
if (file > 0)
{
written = fwrite (savebuffer, 1, datasize, file);
fclose (file);
}
if(!written && !silent)
{
unmountRequired[method] = true;
WaitPrompt ("Error saving file!");
}
// go back to checking if devices were inserted/removed
LWP_ResumeThread (devicethread);
} }
return datasize; return written;
} }
u32 SaveFile(char filepath[], u32 datasize, int method, bool silent)
{
return SaveFileBuf((char *)savebuffer, filepath, datasize, method, silent);
}

View File

@ -16,20 +16,22 @@
#include <string.h> #include <string.h>
#include <ogcsys.h> #include <ogcsys.h>
#include <fat.h> #include <fat.h>
#include <sys/dir.h>
#include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#define ROOTFATDIR "fat:/" void InitDeviceThread();
void MountAllFAT();
void UnmountAllFAT(); void UnmountAllFAT();
bool ChangeFATInterface(int method, bool silent); bool ChangeInterface(int method, bool silent);
int ParseFATdirectory(int method); int ParseDirectory();
int LoadFATSzFile(char * filepath, unsigned char * rbuffer); u32 LoadFileBuf(char * rbuffer, char *filepath, u32 length, int method, bool silent);
int SaveFATFile (char * sbuffer, char *filepath, int length, bool silent); u32 LoadFile(char filepath[], int method, bool silent);
int LoadFATFile (char * sbuffer, char *filepath, int length, bool silent); u32 LoadSzFile(char * filepath, unsigned char * rbuffer);
u32 SaveFileBuf(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 char currFATdir[MAXPATHLEN];
extern FILE * fatfile; extern FILE * file;
extern bool unmountRequired[];
extern lwp_t devicethread;
#endif #endif

View File

@ -33,6 +33,7 @@
int offset; int offset;
int selection; int selection;
char rootdir[10];
char currentdir[MAXPATHLEN]; char currentdir[MAXPATHLEN];
char szpath[MAXPATHLEN]; char szpath[MAXPATHLEN];
char romFilename[200]; char romFilename[200];
@ -44,15 +45,33 @@ extern int screenheight;
FILEENTRIES filelist[MAXFILES]; FILEENTRIES filelist[MAXFILES];
bool inSz = false; bool inSz = false;
unsigned char savebuffer[SAVEBUFFERSIZE]; unsigned char *savebuffer = NULL;
/**************************************************************************** /****************************************************************************
* Clear the savebuffer * AllocSaveBuffer ()
****************************************************************************/ * Allocate and clear the savebuffer
***************************************************************************/
void void
ClearSaveBuffer () AllocSaveBuffer ()
{ {
memset (savebuffer, 0, SAVEBUFFERSIZE); if (savebuffer != NULL)
free(savebuffer);
savebuffer = (unsigned char *) malloc(SAVEBUFFERSIZE);
memset (savebuffer, 0, SAVEBUFFERSIZE);
}
/****************************************************************************
* FreeSaveBuffer ()
* Free the savebuffer memory
***************************************************************************/
void
FreeSaveBuffer ()
{
if (savebuffer != NULL)
free(savebuffer);
savebuffer = NULL;
} }
/**************************************************************************** /****************************************************************************
@ -62,19 +81,19 @@ ClearSaveBuffer ()
****************************************************************************/ ****************************************************************************/
int autoLoadMethod() 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; return METHOD_SD;
else if(ChangeFATInterface(METHOD_USB, SILENT)) else if(ChangeInterface(METHOD_USB, SILENT))
return METHOD_USB; return METHOD_USB;
else if(TestDVD()) else if(ChangeInterface(METHOD_DVD, SILENT))
return METHOD_DVD; return METHOD_DVD;
else if(ConnectShare (SILENT)) else if(ChangeInterface(METHOD_SMB, SILENT))
return METHOD_SMB; return METHOD_SMB;
else else
{ {
WaitPrompt((char*) "Unable to auto-determine load method!"); WaitPrompt("Unable to auto-determine load method!");
return 0; // no method found return 0; // no method found
} }
} }
@ -86,27 +105,28 @@ int autoLoadMethod()
****************************************************************************/ ****************************************************************************/
int autoSaveMethod() 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; return METHOD_SD;
else if(ChangeFATInterface(METHOD_USB, SILENT)) else if(ChangeInterface(METHOD_USB, SILENT))
return METHOD_USB; return METHOD_USB;
else if(TestCard(CARD_SLOTA, SILENT)) else if(TestCard(CARD_SLOTA, SILENT))
return METHOD_MC_SLOTA; return METHOD_MC_SLOTA;
else if(TestCard(CARD_SLOTB, SILENT)) else if(TestCard(CARD_SLOTB, SILENT))
return METHOD_MC_SLOTB; return METHOD_MC_SLOTB;
else if(ConnectShare (SILENT)) else if(ChangeInterface(METHOD_SMB, SILENT))
return METHOD_SMB; return METHOD_SMB;
else else
{ {
WaitPrompt((char*) "Unable to auto-determine save method!"); WaitPrompt("Unable to auto-determine save method!");
return 0; // no method found return 0; // no method found
} }
} }
/*************************************************************************** /****************************************************************************
* Update curent directory name * UpdateDirName()
* Update curent directory name for file browser
***************************************************************************/ ***************************************************************************/
int UpdateDirName(int method) int UpdateDirName(int method)
{ {
@ -156,7 +176,7 @@ int UpdateDirName(int method)
} }
else else
{ {
WaitPrompt((char*)"Directory name is too long!"); WaitPrompt("Directory name is too long!");
return -1; return -1;
} }
} }
@ -173,7 +193,7 @@ bool MakeFilePath(char filepath[], int type, int method)
// Check path length // Check path length
if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) >= MAXPATHLEN) if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) >= MAXPATHLEN)
{ {
WaitPrompt((char*)"Maximum filepath length reached!"); WaitPrompt("Maximum filepath length reached!");
filepath[0] = 0; filepath[0] = 0;
return false; return false;
} }
@ -205,86 +225,20 @@ bool MakeFilePath(char filepath[], int type, int method)
} }
switch(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_SLOTA:
case METHOD_MC_SLOTB: case METHOD_MC_SLOTB:
sprintf (temppath, "%s", file); sprintf (temppath, "%s", file);
temppath[31] = 0; // truncate filename temppath[31] = 0; // truncate filename
break; break;
default:
sprintf (temppath, "%s/%s", folder, file);
break;
} }
} }
strcpy(filepath, temppath); strcpy(filepath, temppath);
return true; return true;
} }
int LoadFileBuf(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 LoadFileBuf((char *)savebuffer, filepath, 0, method, silent);
}
int SaveFileBuf(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 SaveFileBuf((char *)savebuffer, filepath, datasize, method, silent);
}
/*************************************************************************** /***************************************************************************
* FileSortCallback * FileSortCallback
* *
@ -327,7 +281,7 @@ bool IsValidROM(int method)
if(filelist[selection].length < (1024*10) || if(filelist[selection].length < (1024*10) ||
filelist[selection].length > (1024*1024*3)) filelist[selection].length > (1024*1024*3))
{ {
WaitPrompt((char *)"Invalid file size!"); WaitPrompt("Invalid file size!");
return false; return false;
} }
@ -366,7 +320,7 @@ bool IsValidROM(int method)
} }
} }
} }
WaitPrompt((char *)"Unknown file type!"); WaitPrompt("Unknown file type!");
return false; return false;
} }
@ -488,23 +442,18 @@ int FileSelector (int method)
{ {
switch (method) switch (method)
{ {
case METHOD_SD:
case METHOD_USB:
maxfiles = ParseFATdirectory(method);
break;
case METHOD_DVD: case METHOD_DVD:
maxfiles = ParseDVDdirectory(); maxfiles = ParseDVDdirectory();
break; break;
case METHOD_SMB: default:
maxfiles = ParseSMBdirectory(NOTSILENT); maxfiles = ParseDirectory();
break; break;
} }
if (!maxfiles) if (!maxfiles)
{ {
WaitPrompt ((char*) "Error reading directory!"); WaitPrompt ("Error reading directory!");
haverom = 1; // quit menu haverom = 1; // quit menu
} }
} }
@ -515,11 +464,6 @@ int FileSelector (int method)
} }
else // this is a file 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 // 7z file - let's open it up to select a file inside
if(IsSz()) if(IsSz())
{ {
@ -527,6 +471,11 @@ int FileSelector (int method)
if(!MakeFilePath(szpath, FILE_ROM, method)) if(!MakeFilePath(szpath, FILE_ROM, method))
return 0; return 0;
// add device to filepath
char fullpath[1024];
sprintf(fullpath, "%s%s", rootdir, szpath);
strcpy(szpath, fullpath);
int szfiles = SzParse(szpath, method); int szfiles = SzParse(szpath, method);
if(szfiles) if(szfiles)
{ {
@ -534,7 +483,7 @@ int FileSelector (int method)
inSz = true; inSz = true;
} }
else else
WaitPrompt((char*) "Error opening archive!"); WaitPrompt("Error opening archive!");
} }
else else
{ {
@ -545,7 +494,7 @@ int FileSelector (int method)
// store the filename (w/o ext) - used for state saving // store the filename (w/o ext) - used for state saving
StripExt(romFilename, filelist[selection].filename); StripExt(romFilename, filelist[selection].filename);
ShowAction ((char *)"Loading..."); ShowAction ("Loading...");
int size = 0; int size = 0;
@ -562,15 +511,11 @@ int FileSelector (int method)
{ {
switch (method) switch (method)
{ {
case METHOD_SD:
case METHOD_USB:
size = LoadFATSzFile(szpath, nesrom);
break;
case METHOD_DVD: case METHOD_DVD:
size = SzExtractFile(filelist[selection].offset, nesrom); size = SzExtractFile(filelist[selection].offset, nesrom);
break; break;
case METHOD_SMB: default:
size = LoadSMBSzFile(szpath, nesrom); size = LoadSzFile(szpath, nesrom);
break; break;
} }
} }
@ -586,7 +531,7 @@ int FileSelector (int method)
} }
else else
{ {
WaitPrompt((char*) "Error loading ROM!"); WaitPrompt("Error loading ROM!");
return 0; return 0;
} }
} }
@ -696,99 +641,32 @@ int FileSelector (int method)
} }
/**************************************************************************** /****************************************************************************
* OpenDVD * OpenROM
* * Opens device specified by method, displays a list of ROMS
* Function to load a DVD directory and display to user. ***************************************************************************/
****************************************************************************/
int int
OpenDVD (int method) OpenROM (int method)
{ {
if (!getpvd()) if(method == METHOD_AUTO)
method = autoLoadMethod();
if(ChangeInterface(method, NOTSILENT))
{ {
ShowAction((char*) "Loading DVD..."); // change current dir to roms directory
#ifdef HW_DOL switch(method)
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!"); case METHOD_DVD:
return 0; currentdir[0] = 0;
maxfiles = ParseDVDdirectory (); // Parse root directory
SwitchDVDFolder(GCSettings.LoadFolder); // switch to ROM folder
break;
default:
sprintf(currentdir, "/%s", GCSettings.LoadFolder);
maxfiles = ParseDirectory(); // Parse root directory
break;
} }
DI_Mount();
while(DI_GetStatus() & DVD_INIT);
#endif
if (!getpvd())
{
WaitPrompt ((char *)"Invalid DVD.");
return 0; // not a ISO9660 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 root dir
sprintf(currentdir, "/%s", GCSettings.LoadFolder);
maxfiles = ParseSMBdirectory (SILENT);
if (maxfiles > 0)
{
return FileSelector (method);
}
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) if (maxfiles > 0)
{ {
// Select an entry // Select an entry
@ -797,41 +675,9 @@ OpenFAT (int method)
else else
{ {
// no entries found // no entries found
WaitPrompt ((char *)"No Files Found!"); WaitPrompt ("No Files Found!");
return 0; return 0;
} }
} }
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;
}

View File

@ -32,18 +32,16 @@ extern FILEENTRIES filelist[MAXFILES];
extern bool isWii; extern bool isWii;
extern int offset; extern int offset;
extern int selection; extern int selection;
extern char rootdir[10];
extern char currentdir[MAXPATHLEN]; extern char currentdir[MAXPATHLEN];
extern int maxfiles; extern int maxfiles;
extern unsigned char savebuffer[]; extern unsigned char *savebuffer;
extern char romFilename[]; extern char romFilename[];
extern int nesGameType; extern int nesGameType;
void ClearSaveBuffer (); void AllocSaveBuffer();
void FreeSaveBuffer();
bool MakeFilePath(char filepath[], int type, int method); bool MakeFilePath(char filepath[], int type, int method);
int LoadFileBuf(char * buffer, char filepath[], int length, int method, bool silent);
int LoadFile(char filepath[], int method, bool silent);
int SaveFileBuf(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 OpenROM (int method);
int autoLoadMethod(); int autoLoadMethod();
int autoSaveMethod(); int autoSaveMethod();

View File

@ -29,6 +29,7 @@
/* /*
* PKWare Zip Header - adopted into zip standard * PKWare Zip Header - adopted into zip standard
*/ */
#define PKZIPID 0x504b0304
#define MAXROM 0x500000 #define MAXROM 0x500000
#define ZIPCHUNK 2048 #define ZIPCHUNK 2048
@ -63,25 +64,26 @@ FLIP16 (u16 b)
/**************************************************************************** /****************************************************************************
* IsZipFile * IsZipFile
* *
* Returns 1 when Zip signature is found * Returns TRUE when PKZIPID is first four characters of buffer
****************************************************************************/ ***************************************************************************/
int int
IsZipFile (char *buffer) IsZipFile (char *buffer)
{ {
unsigned int *check; unsigned int *check;
check = (unsigned int *) buffer; check = (unsigned int *) buffer;
if (check[0] == 0x504b0304) // ZIP file if (check[0] == PKZIPID)
return 1; return 1;
return 0; return 0;
} }
/***************************************************************************** /*****************************************************************************
* UnZipBuffer * UnZipBuffer
* *
* It should be noted that there is a limit of 5MB total size for any ROM * It should be noted that there is a limit of 5MB total size for any ROM
******************************************************************************/ ******************************************************************************/
int int
UnZipBuffer (unsigned char *outbuffer, int method) UnZipBuffer (unsigned char *outbuffer, int method)
@ -97,31 +99,31 @@ UnZipBuffer (unsigned char *outbuffer, int method)
int have = 0; int have = 0;
char readbuffer[ZIPCHUNK]; char readbuffer[ZIPCHUNK];
u64 discoffset = 0; u64 discoffset = 0;
int sizeread = 0;
// Read Zip Header // Read Zip Header
switch (method) switch (method)
{ {
case METHOD_SD:
case METHOD_USB:
fseek(fatfile, 0, SEEK_SET);
fread (readbuffer, 1, ZIPCHUNK, fatfile);
break;
case METHOD_DVD: case METHOD_DVD:
discoffset = dvddir; discoffset = dvddir;
dvd_read (readbuffer, ZIPCHUNK, discoffset); sizeread = dvd_safe_read (readbuffer, ZIPCHUNK, discoffset);
break; break;
default:
case METHOD_SMB: fseek(file, 0, SEEK_SET);
SMB_ReadFile(readbuffer, ZIPCHUNK, 0, smbfile); sizeread = fread (readbuffer, 1, ZIPCHUNK, file);
break; break;
} }
if(sizeread <= 0)
return 0;
/*** Copy PKZip header to local, used as info ***/ /*** Copy PKZip header to local, used as info ***/
memcpy (&pkzip, readbuffer, sizeof (PKZIPHEADER)); memcpy (&pkzip, readbuffer, sizeof (PKZIPHEADER));
pkzip.uncompressedSize = FLIP32 (pkzip.uncompressedSize); pkzip.uncompressedSize = FLIP32 (pkzip.uncompressedSize);
ShowProgress ("Loading...", 0, pkzip.uncompressedSize);
/*** Prepare the zip stream ***/ /*** Prepare the zip stream ***/
memset (&zs, 0, sizeof (z_stream)); memset (&zs, 0, sizeof (z_stream));
zs.zalloc = Z_NULL; zs.zalloc = Z_NULL;
@ -176,21 +178,18 @@ UnZipBuffer (unsigned char *outbuffer, int method)
switch (method) switch (method)
{ {
case METHOD_SD:
case METHOD_USB:
fread (readbuffer, 1, ZIPCHUNK, fatfile);
break;
case METHOD_DVD: case METHOD_DVD:
readoffset += ZIPCHUNK; readoffset += ZIPCHUNK;
dvd_read (readbuffer, ZIPCHUNK, discoffset+readoffset); sizeread = dvd_safe_read (readbuffer, ZIPCHUNK, discoffset+readoffset);
break; break;
default:
case METHOD_SMB: sizeread = fread (readbuffer, 1, ZIPCHUNK, file);
readoffset += ZIPCHUNK;
SMB_ReadFile(readbuffer, ZIPCHUNK, readoffset, smbfile);
break; break;
} }
if(sizeread <= 0)
break; // read failure
ShowProgress ("Loading...", bufferoffset, pkzip.uncompressedSize);
} }
while (res != Z_STREAM_END); while (res != Z_STREAM_END);
@ -225,13 +224,21 @@ GetFirstZipFilename (int method)
return NULL; return NULL;
// read start of ZIP // read start of ZIP
LoadFileBuf (tempbuffer, filepath, ZIPCHUNK, method, NOTSILENT); if(LoadFileBuf (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
tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27) if(namelength > 0 && namelength < 200) // the filename is a reasonable length
int namelength = tempbuffer[26]; // filename length starts 26 bytes in {
firstFilename = &tempbuffer[30]; // first filename of a ZIP starts 31 bytes in
firstFilename = &tempbuffer[30]; // first filename of a ZIP starts 31 bytes in firstFilename[namelength] = 0; // truncate at filename length
firstFilename[namelength] = 0; // truncate at filename length }
else
{
WaitPrompt("Error - Invalid ZIP file!");
}
}
return firstFilename; return firstFilename;
} }
@ -255,6 +262,7 @@ char szerrormsg[][30] = {
"7z: CRC Error", "7z: CRC Error",
"7z: Not implemented", "7z: Not implemented",
"7z: Fail", "7z: Fail",
"7z: Data read failure",
"7z: Archive error", "7z: Archive error",
"7z: Dictionary too large", "7z: Dictionary too large",
}; };
@ -303,9 +311,11 @@ void SzDisplayError(SZ_RESULT res)
} }
// function used by the 7zip SDK to read data from SD/USB/DVD/SMB // 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) SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize)
{ {
u32 seekok = 0;
u32 sizeread = 0;
// the void* object is a SzFileInStream // the void* object is a SzFileInStream
SzFileInStream *s = (SzFileInStream *) object; SzFileInStream *s = (SzFileInStream *) object;
@ -318,23 +328,31 @@ SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, siz
// read data // read data
switch (szMethod) switch (szMethod)
{ {
case METHOD_SD:
case METHOD_USB:
fseek(fatfile, offset, SEEK_SET);
fread(sz_buffer, 1, maxRequiredSize, fatfile);
break;
case METHOD_DVD: case METHOD_DVD:
dvd_safe_read(sz_buffer, maxRequiredSize, offset); sizeread = dvd_safe_read(sz_buffer, maxRequiredSize, offset);
break; break;
case METHOD_SMB: default:
SMB_ReadFile(sz_buffer, maxRequiredSize, offset, smbfile); seekok = fseek(file, offset, SEEK_SET);
sizeread = fread(sz_buffer, 1, maxRequiredSize, file);
break; break;
} }
if(seekok != 0 || sizeread <= 0)
{
char msg[150];
sprintf(msg, "sizeread: %u", sizeread);
WaitPrompt(msg);
return SZE_FAILREAD;
}
*buffer = sz_buffer; *buffer = sz_buffer;
*processedSize = maxRequiredSize; *processedSize = maxRequiredSize;
s->pos += *processedSize; s->pos += *processedSize;
if(maxRequiredSize > 1024) // only show progress for large reads
// this isn't quite right, but oh well
ShowProgress ("Loading...", s->pos, filelist[selection].length);
return SZ_OK; return SZ_OK;
} }
@ -346,10 +364,7 @@ SZ_RESULT SzFileSeekImp(void *object, CFileSize pos)
// check if the 7z SDK wants to move the pointer to somewhere after the EOF // check if the 7z SDK wants to move the pointer to somewhere after the EOF
if (pos >= s->len) if (pos >= s->len)
{
WaitPrompt((char *) "7z: Error - attempt to read after EOF!");
return SZE_FAIL; return SZE_FAIL;
}
// save new position and return // save new position and return
s->pos = pos; s->pos = pos;
@ -378,13 +393,9 @@ int SzParse(char * filepath, int method)
{ {
case METHOD_SD: case METHOD_SD:
case METHOD_USB: case METHOD_USB:
fatfile = fopen (filepath, "rb");
if(!fatfile)
return 0;
break;
case METHOD_SMB: case METHOD_SMB:
smbfile = OpenSMBFile(filepath); file = fopen (filepath, "rb");
if(!smbfile) if(!file)
return 0; return 0;
break; break;
} }
@ -392,7 +403,7 @@ int SzParse(char * filepath, int method)
// set szMethod to current chosen load method // set szMethod to current chosen load method
szMethod = 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.Read = SzFileReadImp;
SzArchiveStream.InStream.Seek = SzFileSeekImp; SzArchiveStream.InStream.Seek = SzFileSeekImp;
@ -471,10 +482,8 @@ int SzParse(char * filepath, int method)
{ {
case METHOD_SD: case METHOD_SD:
case METHOD_USB: case METHOD_USB:
fclose(fatfile);
break;
case METHOD_SMB: case METHOD_SMB:
SMB_CloseFile (smbfile); fclose(file);
break; break;
} }
return nbfiles; return nbfiles;
@ -508,16 +517,16 @@ int SzExtractFile(int i, unsigned char *buffer)
// Unzip the file // Unzip the file
SzRes = SzExtract2( SzRes = SzExtract2(
&SzArchiveStream.InStream, &SzArchiveStream.InStream,
&SzDb, &SzDb,
i, // index of file i, // index of file
&SzBlockIndex, // index of solid block &SzBlockIndex, // index of solid block
&buffer, &buffer,
&SzBufferSize, &SzBufferSize,
&SzOffset, // offset of stream for required file in *outBuffer &SzOffset, // offset of stream for required file in *outBuffer
&SzOutSizeProcessed, // size of file in *outBuffer &SzOutSizeProcessed, // size of file in *outBuffer
&SzAllocImp, &SzAllocImp,
&SzAllocTempImp); &SzAllocTempImp);
// close 7Zip archive and free memory // close 7Zip archive and free memory
SzClose(); SzClose();
@ -534,3 +543,4 @@ int SzExtractFile(int i, unsigned char *buffer)
return SzOutSizeProcessed; return SzOutSizeProcessed;
} }
} }

View File

@ -25,7 +25,6 @@
extern void FCEU_ResetPalette(void); extern void FCEU_ResetPalette(void);
extern unsigned int SMBTimer;
int FDSTimer = 0; int FDSTimer = 0;
u32 FrameTimer = 0; u32 FrameTimer = 0;
int FDSSwitchRequested; int FDSSwitchRequested;
@ -275,7 +274,6 @@ copy_to_xfb (u32 arg)
copynow = GX_FALSE; copynow = GX_FALSE;
} }
SMBTimer++;
FrameTimer++; FrameTimer++;
// FDS switch disk requested - need to eject, select, and insert // FDS switch disk requested - need to eject, select, and insert

View File

@ -77,9 +77,9 @@ bool TestCard(int slot, bool silent)
if(!silent) if(!silent)
{ {
if (slot == CARD_SLOTA) if (slot == CARD_SLOTA)
WaitPrompt((char*) "Mounted Slot A Memory Card!"); WaitPrompt("Mounted Slot A Memory Card!");
else else
WaitPrompt((char*) "Mounted Slot B Memory Card!"); WaitPrompt("Mounted Slot B Memory Card!");
} }
CARD_Unmount (slot); CARD_Unmount (slot);
return true; return true;
@ -89,9 +89,9 @@ bool TestCard(int slot, bool silent)
if(!silent) if(!silent)
{ {
if (slot == CARD_SLOTA) if (slot == CARD_SLOTA)
WaitPrompt((char*) "Unable to Mount Slot A Memory Card!"); WaitPrompt("Unable to Mount Slot A Memory Card!");
else else
WaitPrompt((char*) "Unable to Mount Slot B Memory Card!"); WaitPrompt("Unable to Mount Slot B Memory Card!");
} }
return false; return false;
@ -149,7 +149,7 @@ VerifyMCFile (char *buf, int slot, char *filename, int datasize)
if (!CardFileExists (filename, slot)) if (!CardFileExists (filename, slot))
{ {
CARD_Unmount (slot); CARD_Unmount (slot);
WaitPrompt((char*) "Unable to open file for verify!"); WaitPrompt("Unable to open file for verify!");
return 0; return 0;
} }
@ -177,7 +177,7 @@ VerifyMCFile (char *buf, int slot, char *filename, int datasize)
{ {
CARD_Close (&CardFile); CARD_Close (&CardFile);
CARD_Unmount (slot); CARD_Unmount (slot);
WaitPrompt((char*) "File did not verify!"); WaitPrompt("File did not verify!");
return 0; return 0;
} }
@ -194,9 +194,9 @@ VerifyMCFile (char *buf, int slot, char *filename, int datasize)
} }
else else
if (slot == CARD_SLOTA) if (slot == CARD_SLOTA)
WaitPrompt((char*) "Unable to Mount Slot A Memory Card!"); WaitPrompt("Unable to Mount Slot A Memory Card!");
else else
WaitPrompt((char*) "Unable to Mount Slot B Memory Card!"); WaitPrompt("Unable to Mount Slot B Memory Card!");
return 0; return 0;
} }
@ -229,7 +229,7 @@ LoadMCFile (char *buf, int slot, char *filename, bool silent)
if (!CardFileExists (filename, slot)) if (!CardFileExists (filename, slot))
{ {
if (!silent) if (!silent)
WaitPrompt((char*) "Unable to open file"); WaitPrompt("Unable to open file");
return 0; return 0;
} }
@ -259,9 +259,9 @@ LoadMCFile (char *buf, int slot, char *filename, bool silent)
} }
else else
if (slot == CARD_SLOTA) if (slot == CARD_SLOTA)
WaitPrompt((char*) "Unable to Mount Slot A Memory Card!"); WaitPrompt("Unable to Mount Slot A Memory Card!");
else else
WaitPrompt((char*) "Unable to Mount Slot B Memory Card!"); WaitPrompt("Unable to Mount Slot B Memory Card!");
return bytesread; return bytesread;
} }
@ -306,7 +306,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
if (CardError) if (CardError)
{ {
CARD_Unmount (slot); CARD_Unmount (slot);
WaitPrompt((char*) "Unable to open card file!"); WaitPrompt("Unable to open card file!");
return 0; return 0;
} }
@ -319,7 +319,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
if (CardError) if (CardError)
{ {
CARD_Unmount (slot); CARD_Unmount (slot);
WaitPrompt((char*) "Not enough space to update file!"); WaitPrompt("Not enough space to update file!");
return 0; return 0;
} }
@ -329,7 +329,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
if (CardError) if (CardError)
{ {
CARD_Unmount (slot); CARD_Unmount (slot);
WaitPrompt((char*) "Unable to delete temporary file!"); WaitPrompt("Unable to delete temporary file!");
return 0; return 0;
} }
@ -338,7 +338,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
if (CardError) if (CardError)
{ {
CARD_Unmount (slot); CARD_Unmount (slot);
WaitPrompt((char*) "Unable to delete existing file!"); WaitPrompt("Unable to delete existing file!");
return 0; return 0;
} }
@ -347,7 +347,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
if (CardError) if (CardError)
{ {
CARD_Unmount (slot); CARD_Unmount (slot);
WaitPrompt((char*) "Unable to create updated card file!"); WaitPrompt("Unable to create updated card file!");
return 0; return 0;
} }
} }
@ -360,9 +360,9 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
{ {
CARD_Unmount (slot); CARD_Unmount (slot);
if ( CardError == CARD_ERROR_INSSPACE ) if ( CardError == CARD_ERROR_INSSPACE )
WaitPrompt((char*) "Not enough space to create file!"); WaitPrompt("Not enough space to create file!");
else else
WaitPrompt((char*) "Unable to create card file!"); WaitPrompt("Unable to create card file!");
return 0; return 0;
} }
} }
@ -406,13 +406,13 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
} }
else else
if ( !silent ) if ( !silent )
WaitPrompt((char*) "This game does not appear to use RAM"); WaitPrompt("This game does not appear to use RAM");
} }
else else
if (slot == CARD_SLOTA) if (slot == CARD_SLOTA)
WaitPrompt((char*) "Unable to Mount Slot A Memory Card!"); WaitPrompt("Unable to Mount Slot A Memory Card!");
else else
WaitPrompt((char*) "Unable to Mount Slot B Memory Card!"); WaitPrompt("Unable to Mount Slot B Memory Card!");
return 0; return 0;

View File

@ -125,7 +125,7 @@ VideoOptions ()
sprintf (videomenu[6], "8 Sprite Limit - %s", sprintf (videomenu[6], "8 Sprite Limit - %s",
GCSettings.slimit == true ? " ON" : "OFF"); GCSettings.slimit == true ? " ON" : "OFF");
ret = RunMenu (videomenu, videomenuCount, (char*)"Video Options", 20, -1); ret = RunMenu (videomenu, videomenuCount, "Video Options", 20, -1);
switch (ret) switch (ret)
{ {
@ -275,7 +275,7 @@ FileOptions()
else if (GCSettings.AutoSave == 2) sprintf (filemenu[5],"Auto Save STATE"); else if (GCSettings.AutoSave == 2) sprintf (filemenu[5],"Auto Save STATE");
else if (GCSettings.AutoSave == 3) sprintf (filemenu[5],"Auto Save BOTH"); else if (GCSettings.AutoSave == 3) sprintf (filemenu[5],"Auto Save BOTH");
ret = RunMenu (filemenu, filemenuCount, (char*)"Save/Load Options", 20, -1); ret = RunMenu (filemenu, filemenuCount, "Save/Load Options", 20, -1);
switch (ret) switch (ret)
{ {
@ -374,7 +374,7 @@ GameMenu ()
if(!GCSettings.Zoom) if(!GCSettings.Zoom)
gamemenu[7][0] = '\0'; gamemenu[7][0] = '\0';
ret = RunMenu (gamemenu, gamemenuCount, (char*)"Game Menu", 20, -1); ret = RunMenu (gamemenu, gamemenuCount, "Game Menu", 20, -1);
switch (ret) switch (ret)
{ {
@ -502,21 +502,21 @@ GetButtonMap(u16 ctrlr_type, char* btn_name)
switch (ctrlr_type) { switch (ctrlr_type) {
case CTRLR_NUNCHUK: case CTRLR_NUNCHUK:
strncpy (cfg_text[3], (char*)"NUNCHUK", 7); strncpy (cfg_text[3], "NUNCHUK", 7);
break; break;
case CTRLR_CLASSIC: case CTRLR_CLASSIC:
strncpy (cfg_text[3], (char*)"CLASSIC", 7); strncpy (cfg_text[3], "CLASSIC", 7);
break; break;
case CTRLR_GCPAD: case CTRLR_GCPAD:
strncpy (cfg_text[3], (char*)"GC PAD", 7); strncpy (cfg_text[3], "GC PAD", 7);
break; break;
case CTRLR_WIIMOTE: case CTRLR_WIIMOTE:
strncpy (cfg_text[3], (char*)"WIIMOTE", 7); strncpy (cfg_text[3], "WIIMOTE", 7);
break; break;
}; };
/*** note which button we are remapping ***/ /*** 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 for (k=0; k<9-strlen(btn_name); k++) strcat(temp, " "); // add whitespace padding to align text
strncat (temp, btn_name, 9); // nes button we are remapping strncat (temp, btn_name, 9); // nes button we are remapping
strncpy (cfg_text[0], temp, 19); // copy this all back to the text we wish to display strncpy (cfg_text[0], temp, 19); // copy this all back to the text we wish to display
@ -560,7 +560,7 @@ ConfigureButtons (u16 ctrlr_type)
int ret = 0; int ret = 0;
int oldmenu = menu; int oldmenu = menu;
menu = 0; menu = 0;
char* menu_title = NULL; char menu_title[50];
u32 pressed; u32 pressed;
unsigned int* currentpadmap = 0; unsigned int* currentpadmap = 0;
@ -571,19 +571,19 @@ ConfigureButtons (u16 ctrlr_type)
/*** Update Menu Title (based on controller we're configuring) ***/ /*** Update Menu Title (based on controller we're configuring) ***/
switch (ctrlr_type) { switch (ctrlr_type) {
case CTRLR_NUNCHUK: case CTRLR_NUNCHUK:
menu_title = (char*)"NES - NUNCHUK"; sprintf(menu_title, "NES - NUNCHUK");
currentpadmap = ncpadmap; currentpadmap = ncpadmap;
break; break;
case CTRLR_CLASSIC: case CTRLR_CLASSIC:
menu_title = (char*)"NES - CLASSIC"; sprintf(menu_title, "NES - CLASSIC");
currentpadmap = ccpadmap; currentpadmap = ccpadmap;
break; break;
case CTRLR_GCPAD: case CTRLR_GCPAD:
menu_title = (char*)"NES - GC PAD"; sprintf(menu_title, "NES - GC PAD");
currentpadmap = gcpadmap; currentpadmap = gcpadmap;
break; break;
case CTRLR_WIIMOTE: case CTRLR_WIIMOTE:
menu_title = (char*)"NES - WIIMOTE"; sprintf(menu_title, "NES - WIIMOTE");
currentpadmap = wmpadmap; currentpadmap = wmpadmap;
break; break;
}; };
@ -607,7 +607,7 @@ ConfigureButtons (u16 ctrlr_type)
strncat (temp, ctrlr_def[ctrlr_type].map[j].name, 6); // update button map display strncat (temp, ctrlr_def[ctrlr_type].map[j].name, 6); // update button map display
} }
else 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 strncpy (cfg_btns_menu[i], temp, 19); // move back updated information
} }
@ -687,7 +687,7 @@ ConfigureControllers ()
GCSettings.crosshair == true ? " ON" : "OFF"); GCSettings.crosshair == true ? " ON" : "OFF");
/*** Controller Config Menu ***/ /*** Controller Config Menu ***/
ret = RunMenu (ctlrmenu, ctlrmenucount, (char*)"Configure Controllers", 20, -1); ret = RunMenu (ctlrmenu, ctlrmenucount, "Configure Controllers", 20, -1);
switch (ret) switch (ret)
{ {
@ -759,7 +759,7 @@ PreferencesMenu ()
menu = 0; menu = 0;
while (quit == 0) while (quit == 0)
{ {
ret = RunMenu (prefmenu, prefmenuCount, (char*)"Preferences", 20, -1); ret = RunMenu (prefmenu, prefmenuCount, "Preferences", 20, -1);
switch (ret) switch (ret)
{ {
@ -777,12 +777,12 @@ PreferencesMenu ()
case 3: case 3:
DefaultSettings (); DefaultSettings ();
WaitPrompt((char *)"Preferences Reset"); WaitPrompt("Preferences Reset");
break; break;
case -1: /*** Button B ***/ case -1: /*** Button B ***/
case 4: case 4:
SavePrefs(GCSettings.SaveMethod, SILENT); SavePrefs(SILENT);
quit = 1; quit = 1;
break; break;
@ -836,7 +836,7 @@ MainMenu (int selectedMenu)
} }
else else
{ {
ret = RunMenu (menuitems, menucount, (char*)"Main Menu", 20, -1); ret = RunMenu (menuitems, menucount, "Main Menu", 20, -1);
} }
switch (ret) switch (ret)

View File

@ -134,7 +134,7 @@ DrawCharacter (FT_Bitmap * bmp, FT_Int x, FT_Int y)
* Place the font bitmap on the screen * Place the font bitmap on the screen
****************************************************************************/ ****************************************************************************/
void void
DrawText (int x, int y, char *text) DrawText (int x, int y, const char *text)
{ {
int px, n; int px, n;
int i; int i;
@ -212,7 +212,7 @@ Credits ()
setfontcolour (0xFF, 0xFF, 0xFF); setfontcolour (0xFF, 0xFF, 0xFF);
setfontsize (28); setfontsize (28);
DrawText (-1, 145, (char*)"Credits"); DrawText (-1, 145, "Credits");
int ypos = 140; int ypos = 140;
@ -220,26 +220,26 @@ Credits ()
ypos += 20; ypos += 20;
setfontsize (14); setfontsize (14);
DrawText (125, ypos += 22, (char*)"GameCube/Wii Port v2.x"); DrawText (125, ypos += 22, "GameCube/Wii Port v2.x");
DrawText (350, ypos, (char*)"Tantric"); DrawText (350, ypos, "Tantric");
DrawText (125, ypos += 18, (char*)"GameCube/Wii Port v1.0.9"); DrawText (125, ypos += 18, "GameCube/Wii Port v1.0.9");
DrawText (350, ypos, (char*)"askot & dsbomb"); DrawText (350, ypos, "askot & dsbomb");
DrawText (125, ypos += 18, (char*)"GameCube Port v1.0.8"); DrawText (125, ypos += 18, "GameCube Port v1.0.8");
DrawText (350, ypos, (char*)"SoftDev"); DrawText (350, ypos, "SoftDev");
DrawText (125, ypos += 18, (char*)"FCE Ultra"); DrawText (125, ypos += 18, "FCE Ultra");
DrawText (350, ypos, (char*)"Xodnizel"); DrawText (350, ypos, "Xodnizel");
DrawText (125, ypos += 18, (char*)"Original FCE"); DrawText (125, ypos += 18, "Original FCE");
DrawText (350, ypos, (char*)"BERO"); DrawText (350, ypos, "BERO");
DrawText (125, ypos += 18, (char*)"libogc"); DrawText (125, ypos += 18, "libogc");
DrawText (350, ypos, (char*)"Shagkur & wintermute"); DrawText (350, ypos, "Shagkur & wintermute");
DrawText (125, ypos += 18, (char*)"Testing"); DrawText (125, ypos += 18, "Testing");
DrawText (350, ypos, (char*)"tehskeen users"); DrawText (350, ypos, "tehskeen users");
DrawText (-1, ypos += 36, (char*)"And many others who have contributed over the years!"); DrawText (-1, ypos += 36, "And many others who have contributed over the years!");
setfontsize (12); setfontsize (12);
DrawText (-1, ypos += 50, (char*)"This software is open source and may be copied, distributed, or modified"); DrawText (-1, ypos += 50, "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 += 15, "under the terms of the GNU General Public License (GPL) Version 2.");
showscreen (); showscreen ();
} }
@ -336,7 +336,7 @@ WaitButtonAB ()
* Show a prompt * Show a prompt
****************************************************************************/ ****************************************************************************/
void void
WaitPrompt (char *msg) WaitPrompt (const char *msg)
{ {
int ypos = (screenheight - 64) >> 1; int ypos = (screenheight - 64) >> 1;
@ -348,7 +348,7 @@ WaitPrompt (char *msg)
clearscreen (); clearscreen ();
DrawText (-1, ypos, msg); DrawText (-1, ypos, msg);
ypos += 30; ypos += 30;
DrawText (-1, ypos, (char*)"Press A to continue"); DrawText (-1, ypos, "Press A to continue");
showscreen (); showscreen ();
WaitButtonA (); WaitButtonA ();
} }
@ -358,7 +358,7 @@ WaitPrompt (char *msg)
and 0 if B button was pressed. and 0 if B button was pressed.
****************************************************************************/ ****************************************************************************/
int int
WaitPromptChoice (char *msg, char *bmsg, char *amsg) WaitPromptChoice (const char *msg, const char *bmsg, const char *amsg)
{ {
int ypos = (screenheight - 64) >> 1; int ypos = (screenheight - 64) >> 1;
@ -381,7 +381,7 @@ WaitPromptChoice (char *msg, char *bmsg, char *amsg)
* Show an action in progress * Show an action in progress
****************************************************************************/ ****************************************************************************/
void void
ShowAction (char *msg) ShowAction (const char *msg)
{ {
int ypos = (screenheight - 30) >> 1; int ypos = (screenheight - 30) >> 1;
@ -399,7 +399,7 @@ ShowAction (char *msg)
* Generic Menu Routines * Generic Menu Routines
****************************************************************************/ ****************************************************************************/
void 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 i, w = 0;
int ypos = 0; int ypos = 0;
@ -488,7 +488,7 @@ int FindMenuItem(char items[][50], int maxitems, int currentItem, int direction)
int menu = 0; int menu = 0;
int 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 redraw = 1;
int quit = 0; int quit = 0;
@ -581,7 +581,7 @@ ShowFiles (FILEENTRIES filelist[], int maxfiles, int offset, int selection)
clearscreen (); clearscreen ();
setfontsize (28); setfontsize (28);
DrawText (-1, 145, (char*)"Choose Game"); DrawText (-1, 145, "Choose Game");
setfontsize(18); setfontsize(18);
@ -654,7 +654,7 @@ void RomInfo()
ypos += 20; ypos += 20;
setfontsize (28); setfontsize (28);
DrawText (-1, 145, (char*)"Rom Information"); DrawText (-1, 145, "Rom Information");
setfontsize (16); setfontsize (16);
setfontcolour (0xFF, 0xFF, 0xFF); setfontcolour (0xFF, 0xFF, 0xFF);
@ -786,34 +786,46 @@ DrawLine (int x1, int y1, int x2, int y2, u8 r, u8 g, u8 b)
* Progress Bar * Progress Bar
* *
* Show the user what's happening * Show the user what's happening
****************************************************************************/ ***************************************************************************/
void void
ShowProgress (char *msg, int done, int total) ShowProgress (const char *msg, int done, int total)
{ {
int ypos = (screenheight - 30) >> 1; if(total <= 0) // division by 0 is bad!
return;
else if(done > total) // this shouldn't happen
done = total;
if (screenheight == 480) int xpos, ypos;
ypos += 52; int i;
else
ypos += 32;
int xpos; if(done < 5000) // we just started!
int i; {
ypos = (screenheight - 30) >> 1;
clearscreen (); if (screenheight == 480)
DrawText (-1, ypos, msg); ypos += 52;
else
ypos += 32;
/*** Draw a white outline box ***/ clearscreen ();
for (i = 380; i < 401; i++) setfontsize(20);
DrawLine (100, i, 540, i, 0xff, 0xff, 0xff); DrawText (-1, ypos, msg);
/*** Draw a white outline box ***/
for (i = 380; i < 401; i++)
DrawLine (100, i, 540, i, 0xff, 0xff, 0xff);
}
/*** Show progess ***/ /*** Show progess ***/
xpos = (int) (((float) done / (float) total) * 438); xpos = (int) (((float) done / (float) total) * 438);
for (i = 381; i < 400; i++) for (i = 381; i < 400; i++)
DrawLine (101, i, 101 + xpos, i, 0x00, 0x00, 0x80); DrawLine (101, i, 101 + xpos, i, 0x00, 0x00, 0x80);
showscreen (); if(done < 5000) // we just started!
{
showscreen ();
}
} }
/**************************************************************************** /****************************************************************************

View File

@ -19,20 +19,20 @@
int FT_Init (); int FT_Init ();
void setfontsize (int pixelsize); void setfontsize (int pixelsize);
void setfontcolour (u8 r, u8 g, u8 b); 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 Credits (); void Credits ();
void RomInfo (); void RomInfo ();
void WaitButtonA (); void WaitButtonA ();
int RunMenu (char items[][50], int maxitems, char *title, int fontsize, int x); int RunMenu (char items[][50], int maxitems, const char *title, int fontsize, int x);
void DrawMenu (char items[][50], char *title, int maxitems, int selected, int fontsize, int x); void DrawMenu (char items[][50], const char *title, int maxitems, int selected, int fontsize, int x);
void ShowCheats (char items[][50], char itemvalues[][50], int maxitems, int offset, int selection); 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 ShowFiles (FILEENTRIES filelist[], int maxfiles, int offset, int selection);
void WaitPrompt (char *msg); void WaitPrompt (const char *msg);
int WaitPromptChoice (char *msg, char* bmsg, char* amsg); int WaitPromptChoice (const char *msg, const char* bmsg, const char* amsg);
void ShowAction (char *msg); void ShowAction (const char *msg);
void ShowProgress (char *msg, int done, int total); void ShowProgress (const char *msg, int done, int total);
void DrawPolygon (int vertices, int *varray, u8 r, u8 g, u8 b); 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 ); void DrawLineFast( int startx, int endx, int y, u8 r, u8 g, u8 b);
#endif #endif

View File

@ -25,54 +25,6 @@
extern bool romLoaded; extern bool romLoaded;
// Original NES controller buttons
// All other pads are mapped to this
unsigned int nespadmap[] = {
JOY_B, JOY_A,
RAPID_B, RAPID_A, // rapid press A/B buttons
JOY_SELECT, JOY_START,
JOY_UP, JOY_DOWN,
JOY_LEFT, JOY_RIGHT,
0 // insert coin for VS games, insert/eject/select disk for FDS
};
/*** Gamecube controller Padmap ***/
unsigned int gcpadmap[] = {
PAD_BUTTON_B, PAD_BUTTON_A,
PAD_BUTTON_Y, PAD_BUTTON_X,
PAD_TRIGGER_Z, PAD_BUTTON_START,
PAD_BUTTON_UP, PAD_BUTTON_DOWN,
PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT,
PAD_TRIGGER_L
};
/*** Wiimote Padmap ***/
unsigned int wmpadmap[] = {
WPAD_BUTTON_1, WPAD_BUTTON_2,
0, 0,
WPAD_BUTTON_MINUS, WPAD_BUTTON_PLUS,
WPAD_BUTTON_RIGHT, WPAD_BUTTON_LEFT,
WPAD_BUTTON_UP, WPAD_BUTTON_DOWN,
WPAD_BUTTON_A
};
/*** Classic Controller Padmap ***/
unsigned int ccpadmap[] = {
WPAD_CLASSIC_BUTTON_Y, WPAD_CLASSIC_BUTTON_B,
WPAD_CLASSIC_BUTTON_X, WPAD_CLASSIC_BUTTON_A,
WPAD_CLASSIC_BUTTON_MINUS, WPAD_CLASSIC_BUTTON_PLUS,
WPAD_CLASSIC_BUTTON_UP, WPAD_CLASSIC_BUTTON_DOWN,
WPAD_CLASSIC_BUTTON_LEFT, WPAD_CLASSIC_BUTTON_RIGHT,
WPAD_CLASSIC_BUTTON_FULL_L
};
/*** Nunchuk + wiimote Padmap ***/
unsigned int ncpadmap[] = {
WPAD_NUNCHUK_BUTTON_C, WPAD_NUNCHUK_BUTTON_Z,
0, 0,
WPAD_BUTTON_MINUS, WPAD_BUTTON_PLUS,
WPAD_BUTTON_UP, WPAD_BUTTON_DOWN,
WPAD_BUTTON_LEFT, WPAD_BUTTON_RIGHT,
WPAD_BUTTON_A
};
static uint32 JSReturn = 0; static uint32 JSReturn = 0;
void *InputDPR; void *InputDPR;
@ -81,6 +33,88 @@ unsigned int myzappers[2][3];
extern INPUTC *FCEU_InitZapper(int w); extern INPUTC *FCEU_InitZapper(int w);
unsigned int nespadmap[11]; // Original NES controller buttons
unsigned int gcpadmap[11]; // Gamecube controller Padmap
unsigned int wmpadmap[11]; // Wiimote Padmap
unsigned int ccpadmap[11]; // Classic Controller Padmap
unsigned int ncpadmap[11]; // Nunchuk + wiimote Padmap
void ResetControls()
{
int i = 0;
// Original NES controller buttons
// All other pads are mapped to this
i=0;
nespadmap[i++] = JOY_B;
nespadmap[i++] = JOY_A;
nespadmap[i++] = RAPID_B;
nespadmap[i++] = RAPID_A; // rapid press A/B buttons
nespadmap[i++] = JOY_SELECT;
nespadmap[i++] = JOY_START;
nespadmap[i++] = JOY_UP;
nespadmap[i++] = JOY_DOWN;
nespadmap[i++] = JOY_LEFT;
nespadmap[i++] = JOY_RIGHT;
nespadmap[i++] = 0; // insert coin for VS games, insert/eject/select disk for FDS
/*** Gamecube controller Padmap ***/
i=0;
gcpadmap[i++] = PAD_BUTTON_B;
gcpadmap[i++] = PAD_BUTTON_A;
gcpadmap[i++] = PAD_BUTTON_Y;
gcpadmap[i++] = PAD_BUTTON_X;
gcpadmap[i++] = PAD_TRIGGER_Z;
gcpadmap[i++] = PAD_BUTTON_START;
gcpadmap[i++] = PAD_BUTTON_UP;
gcpadmap[i++] = PAD_BUTTON_DOWN;
gcpadmap[i++] = PAD_BUTTON_LEFT;
gcpadmap[i++] = PAD_BUTTON_RIGHT;
gcpadmap[i++] = PAD_TRIGGER_L;
/*** Wiimote Padmap ***/
i=0;
wmpadmap[i++] = WPAD_BUTTON_1;
wmpadmap[i++] = WPAD_BUTTON_2;
wmpadmap[i++] = 0;
wmpadmap[i++] = 0;
wmpadmap[i++] = WPAD_BUTTON_MINUS;
wmpadmap[i++] = WPAD_BUTTON_PLUS;
wmpadmap[i++] = WPAD_BUTTON_RIGHT;
wmpadmap[i++] = WPAD_BUTTON_LEFT;
wmpadmap[i++] = WPAD_BUTTON_UP;
wmpadmap[i++] = WPAD_BUTTON_DOWN;
wmpadmap[i++] = WPAD_BUTTON_A;
/*** Classic Controller Padmap ***/
i=0;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_Y;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_B;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_X;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_A;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_MINUS;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_PLUS;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_UP;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_DOWN;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_LEFT;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_RIGHT;
ccpadmap[i++] = WPAD_CLASSIC_BUTTON_FULL_L;
/*** Nunchuk + wiimote Padmap ***/
i=0;
ncpadmap[i++] = WPAD_NUNCHUK_BUTTON_C;
ncpadmap[i++] = WPAD_NUNCHUK_BUTTON_Z;
ncpadmap[i++] = 0;
ncpadmap[i++] = 0;
ncpadmap[i++] = WPAD_BUTTON_MINUS;
ncpadmap[i++] = WPAD_BUTTON_PLUS;
ncpadmap[i++] = WPAD_BUTTON_UP;
ncpadmap[i++] = WPAD_BUTTON_DOWN;
ncpadmap[i++] = WPAD_BUTTON_LEFT;
ncpadmap[i++] = WPAD_BUTTON_RIGHT;
ncpadmap[i++] = WPAD_BUTTON_A;
}
/**************************************************************************** /****************************************************************************
* Initialise Pads * Initialise Pads
****************************************************************************/ ****************************************************************************/

View File

@ -25,6 +25,7 @@ extern unsigned int wmpadmap[];
extern unsigned int ccpadmap[]; extern unsigned int ccpadmap[];
extern unsigned int ncpadmap[]; extern unsigned int ncpadmap[];
void ResetControls();
s8 WPAD_StickX(u8 chan,u8 right); s8 WPAD_StickX(u8 chan,u8 right);
s8 WPAD_StickY(u8 chan, u8 right); s8 WPAD_StickY(u8 chan, u8 right);
void InitialisePads(); void InitialisePads();

View File

@ -18,13 +18,10 @@
#include "menudraw.h" #include "menudraw.h"
#include "memcardop.h" #include "memcardop.h"
#include "fileop.h" #include "fileop.h"
#include "smbop.h"
#include "filesel.h"
#include "fceugx.h" #include "fceugx.h"
#include "pad.h" #include "pad.h"
extern const unsigned short saveicon[1024]; extern const unsigned short saveicon[1024];
extern unsigned char savebuffer[];
extern int currconfig[4]; extern int currconfig[4];
// button map configurations // button map configurations
@ -319,33 +316,35 @@ decodePrefsData (int method)
/**************************************************************************** /****************************************************************************
* Save Preferences * Save Preferences
****************************************************************************/ ***************************************************************************/
bool bool
SavePrefs (int method, bool silent) SavePrefs (bool silent)
{ {
char filepath[1024]; char filepath[1024];
int datasize; int datasize;
int offset = 0; int offset = 0;
// there's no point in saving SMB settings TO SMB, because then we'll have no way to load them the next time! // We'll save using the first available method (probably SD) since this
// so instead we'll save using whatever other method is available (eg: SD) // is the method preferences will be loaded from by default
if(method == METHOD_AUTO || method == METHOD_SMB) int method = autoSaveMethod();
method = autoSaveMethod();
if(!MakeFilePath(filepath, FILE_PREF, method)) if(!MakeFilePath(filepath, FILE_PREF, method))
return false; return false;
if (!silent) if (!silent)
ShowAction ((char*) "Saving preferences..."); ShowAction ("Saving preferences...");
AllocSaveBuffer ();
datasize = preparePrefsData (method); datasize = preparePrefsData (method);
offset = SaveFile(filepath, datasize, method, silent); offset = SaveFile(filepath, datasize, method, silent);
FreeSaveBuffer ();
if (offset > 0) if (offset > 0)
{ {
if (!silent) if (!silent)
WaitPrompt ((char *)"Preferences saved"); WaitPrompt ("Preferences saved");
return true; return true;
} }
return false; return false;
@ -353,8 +352,7 @@ SavePrefs (int method, bool silent)
/**************************************************************************** /****************************************************************************
* Load Preferences from specified method * Load Preferences from specified method
****************************************************************************/ ***************************************************************************/
bool bool
LoadPrefsFromMethod (int method) LoadPrefsFromMethod (int method)
{ {
@ -365,32 +363,35 @@ LoadPrefsFromMethod (int method)
if(!MakeFilePath(filepath, FILE_PREF, method)) if(!MakeFilePath(filepath, FILE_PREF, method))
return false; return false;
AllocSaveBuffer ();
offset = LoadFile(filepath, method, SILENT); offset = LoadFile(filepath, method, SILENT);
if (offset > 0) if (offset > 0)
{
retval = decodePrefsData (method); retval = decodePrefsData (method);
}
FreeSaveBuffer ();
return retval; return retval;
} }
/**************************************************************************** /****************************************************************************
* Load Preferences * Load Preferences
* Checks sources consecutively until we find a preference file * Checks sources consecutively until we find a preference file
****************************************************************************/ ***************************************************************************/
bool LoadPrefs() bool LoadPrefs()
{ {
ShowAction ("Loading preferences...");
bool prefFound = false; bool prefFound = false;
if(ChangeFATInterface(METHOD_SD, SILENT)) if(ChangeInterface(METHOD_SD, SILENT))
prefFound = LoadPrefsFromMethod(METHOD_SD); prefFound = LoadPrefsFromMethod(METHOD_SD);
if(!prefFound && ChangeFATInterface(METHOD_USB, SILENT)) if(!prefFound && ChangeInterface(METHOD_USB, SILENT))
prefFound = LoadPrefsFromMethod(METHOD_USB); prefFound = LoadPrefsFromMethod(METHOD_USB);
if(!prefFound && TestCard(CARD_SLOTA, SILENT)) if(!prefFound && TestCard(CARD_SLOTA, SILENT))
prefFound = LoadPrefsFromMethod(METHOD_MC_SLOTA); prefFound = LoadPrefsFromMethod(METHOD_MC_SLOTA);
if(!prefFound && TestCard(CARD_SLOTB, SILENT)) if(!prefFound && TestCard(CARD_SLOTB, SILENT))
prefFound = LoadPrefsFromMethod(METHOD_MC_SLOTB); prefFound = LoadPrefsFromMethod(METHOD_MC_SLOTB);
if(!prefFound && ConnectShare (SILENT)) if(!prefFound && ChangeInterface(METHOD_SMB, SILENT))
prefFound = LoadPrefsFromMethod(METHOD_SMB); prefFound = LoadPrefsFromMethod(METHOD_SMB);
return prefFound; return prefFound;

View File

@ -9,5 +9,5 @@
* Preferences save/load preferences utilities * Preferences save/load preferences utilities
****************************************************************************/ ****************************************************************************/
bool SavePrefs (int method, bool silent); bool SavePrefs (bool silent);
bool LoadPrefs (); bool LoadPrefs ();

View File

@ -21,30 +21,28 @@
#include "common.h" #include "common.h"
#include "fceugx.h" #include "fceugx.h"
#include "smbop.h" #include "fileop.h"
#include "gcunzip.h" #include "gcunzip.h"
#include "menudraw.h" #include "menudraw.h"
#include "filesel.h" #include "filesel.h"
bool networkInit = false; bool networkInit = false;
bool networkShareInit = false; bool networkShareInit = false;
unsigned int SMBTimer = 0; bool networkInitHalt = false;
#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
/**************************************************************************** /****************************************************************************
* InitializeNetwork * InitializeNetwork
* Initializes the Wii/GameCube network interface * 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; s32 result;
while ((result = net_init()) == -EAGAIN); while ((result = net_init()) == -EAGAIN);
@ -55,19 +53,28 @@ bool InitializeNetwork(bool silent)
if (if_config(myIP, NULL, NULL, true) < 0) if (if_config(myIP, NULL, NULL, true) < 0)
{ {
networkInitHalt = true; // do not attempt a reconnection again
if(!silent) if(!silent)
WaitPrompt((char*) "Error reading IP address."); WaitPrompt("Error reading IP address.");
return false;
} }
else else
{ {
return true; networkInit = true;
} }
} }
else
{
if(!silent)
WaitPrompt("Unable to initialize network.");
}
}
if(!silent) void CloseShare()
WaitPrompt((char*) "Unable to initialize network."); {
return false; if(networkShareInit)
smbClose();
networkShareInit = false;
} }
/**************************************************************************** /****************************************************************************
@ -89,266 +96,33 @@ ConnectShare (bool silent)
strlen(GCSettings.smbip) == 0) strlen(GCSettings.smbip) == 0)
{ {
if(!silent) if(!silent)
WaitPrompt((char*) "Invalid network settings. Check settings.xml."); WaitPrompt("Invalid network settings. Check settings.xml.");
return false; return false;
} }
if(!networkInit) if(!networkInit)
networkInit = InitializeNetwork(silent); InitializeNetwork(silent);
if(networkInit) if(networkInit)
{ {
// connection may have expired if(unmountRequired[METHOD_SMB])
if (networkShareInit && SMBTimer > SMBTIMEOUT) CloseShare();
{
networkShareInit = false;
SMBTimer = 0;
SMB_Close(smbconn);
}
if(!networkShareInit) if(!networkShareInit)
{ {
if(!silent) if(!silent)
ShowAction ((char*) "Connecting to network share..."); ShowAction ("Connecting to network share...");
if(SMB_Connect(&smbconn, GCSettings.smbuser, GCSettings.smbpwd, if(smbInit(GCSettings.smbuser, GCSettings.smbpwd,
GCSettings.smbgcid, GCSettings.smbsvid, GCSettings.smbshare, GCSettings.smbip) == SMB_SUCCESS) GCSettings.smbshare, GCSettings.smbip))
{
networkShareInit = true; networkShareInit = true;
}
} }
if(!networkShareInit && !silent) if(!networkShareInit && !silent)
WaitPrompt ((char*) "Failed to connect to network share."); WaitPrompt ("Failed to connect to network share.");
} }
return networkShareInit; return networkShareInit;
} }
/****************************************************************************
* SMBPath
*
* Returns a SMB-style path
*****************************************************************************/
char * SMBPath(char * path)
{
// fix path - replace all '/' with '\'
int i;
for(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, 2048, 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;
}
}
}
SMB_CloseFile (smbfile);
return boffset;
}

View File

@ -9,21 +9,11 @@
* SMB support routines * SMB support routines
****************************************************************************/ ****************************************************************************/
#ifndef _SMBOP_H_ #ifndef _NGCSMB_
#define _SMBOP_H_ #define _NGCSMB_
#include <smb.h> void InitializeNetwork(bool silent);
bool InitializeNetwork(bool silent);
bool ConnectShare (bool silent); bool ConnectShare (bool silent);
char * SMBPath(char * path); void CloseShare();
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;
#endif #endif

View File

@ -61,10 +61,11 @@ typedef UInt32 CFileSize;
#define SZE_NOTIMPL (4) #define SZE_NOTIMPL (4)
#define SZE_FAIL (5) #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_; } #define RINOK(x) { int __result_ = (x); if(__result_ != 0) return __result_; }