From 18e267b1f0278de08cda3e367e380a2881ee62c7 Mon Sep 17 00:00:00 2001 From: dborth Date: Thu, 18 Dec 2008 18:58:30 +0000 Subject: [PATCH] rewrite file code --- source/ngc/dvd.cpp | 71 ++++--- source/ngc/dvd.h | 2 +- source/ngc/fileop.cpp | 403 +++++++++++++++++++++++++++---------- source/ngc/fileop.h | 30 +-- source/ngc/filesel.cpp | 274 +++++-------------------- source/ngc/filesel.h | 5 +- source/ngc/gcunzip.cpp | 155 +++++++------- source/ngc/memcardop.cpp | 42 ++-- source/ngc/menu.cpp | 32 +-- source/ngc/menudraw.cpp | 60 +++--- source/ngc/menudraw.h | 13 +- source/ngc/preferences.cpp | 12 +- source/ngc/smbop.cpp | 294 ++++----------------------- source/ngc/smbop.h | 15 +- source/ngc/vba.cpp | 32 +-- source/ngc/vba.h | 15 +- source/ngc/vbaconfig.cpp | 7 - source/ngc/vbasupport.cpp | 38 ++-- source/ngc/video.cpp | 2 - source/ngc/vmmem.cpp | 23 +-- source/sz/7zTypes.h | 5 +- 21 files changed, 668 insertions(+), 862 deletions(-) diff --git a/source/ngc/dvd.cpp b/source/ngc/dvd.cpp index 5efb34f..e056fd2 100644 --- a/source/ngc/dvd.cpp +++ b/source/ngc/dvd.cpp @@ -116,7 +116,7 @@ u64 dvdsf_last_length = 0; int dvd_buffered_read(void *dst, u32 len, u64 offset) { - int ret = 0; + int ret = 1; // only read data if the data inside dvdsf_buffer cannot be used if(offset != dvdsf_last_offset || len > dvdsf_last_length) @@ -145,12 +145,12 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset) } else { - // no errors yet -> ret = 0 - // the return value of dvd_read will be OR'd with ret - // because dvd_read does return 1 on error and 0 on success and - // because 0 | 1 = 1 ret will also contain 1 if at least one error - // occured and 0 otherwise ;) - int ret = 0; // return value of dvd_read + // no errors yet -> ret = 1 + // the return value of dvd_read will be AND'd with ret + // because dvd_read does return 0 on error and 1 on success and + // because 1 & 0 = 0 ret will also contain 0 if at least one error + // occured and 1 otherwise ;) + int ret = 1; // return value of dvd_read // we might need to fix all 3 issues unsigned char *dst = (unsigned char *)dst_v; // gcc will not allow to use var[num] on void* types @@ -183,7 +183,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset) } // read 32 bytes from the last 32 byte position - ret |= dvd_buffered_read(buffer, DVD_OFFSET_MULTIPLY, i); + ret &= dvd_buffered_read(buffer, DVD_OFFSET_MULTIPLY, i); // copy the bytes to the output buffer and update currentOffset, bufferOffset and bytesToRead memcpy(&dst[bufferOffset], &buffer[j], k); @@ -201,7 +201,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset) // read data in 2048 byte sector for(j = 0; j < i; j++) { - ret |= dvd_buffered_read(buffer, DVD_MAX_READ_LENGTH, currentOffset); // read sector + ret &= dvd_buffered_read(buffer, DVD_MAX_READ_LENGTH, currentOffset); // read sector memcpy(&dst[bufferOffset], buffer, DVD_MAX_READ_LENGTH); // copy to output buffer // update currentOffset, bufferOffset and bytesToRead @@ -214,7 +214,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset) // fix third issue (length is not a multiply of 32) if(bytesToRead) { - ret |= dvd_buffered_read(buffer, DVD_MAX_READ_LENGTH, currentOffset); // read 32 byte from the dvd + ret &= dvd_buffered_read(buffer, DVD_MAX_READ_LENGTH, currentOffset); // read 32 byte from the dvd memcpy(&dst[bufferOffset], buffer, bytesToRead); // copy bytes to output buffer } return ret; @@ -301,24 +301,38 @@ getpvd () } /**************************************************************************** - * TestDVD() + * MountDVD() * - * Tests if a ISO9660 DVD is inserted and available + * Tests if a ISO9660 DVD is inserted and available, and mounts it ***************************************************************************/ -bool TestDVD() + +bool MountDVD(bool silent) { if (!getpvd()) { + ShowAction("Loading DVD..."); #ifdef HW_DOL - DVD_Mount(); + DVD_Mount(); // mount the DVD unit again #elif WII_DVD + u32 val; + DI_GetCoverRegister(&val); + if(val & 0x1) // True if no disc inside, use (val & 0x2) for true if disc inside. + { + if(!silent) + WaitPrompt("No disc inserted!"); + return false; + } DI_Mount(); while(DI_GetStatus() & DVD_INIT); #endif - if (!getpvd()) - return false; - } + if (!getpvd()) + { + if(!silent) + WaitPrompt ("Invalid DVD."); + return false; + } + } return true; } @@ -583,6 +597,7 @@ LoadDVDFileOffset (unsigned char *buffer, int length) int offset; int blocks; int i; + int ret = 0; u64 discoffset; char readbuffer[2048]; @@ -590,15 +605,19 @@ LoadDVDFileOffset (unsigned char *buffer, int length) blocks = dvddirlength / 2048; offset = 0; discoffset = dvddir; - ShowAction ((char*) "Loading..."); + ShowAction ("Loading..."); if(length > 0 && length <= 2048) { - dvd_read (buffer, length, discoffset); + ret = dvd_read (buffer, length, discoffset); + if(ret <= 0) // read failure + return 0; } else // load whole file { - dvd_read (readbuffer, 2048, discoffset); + ret = dvd_read (readbuffer, 2048, discoffset); + if(ret <= 0) // read failure + return 0; if (IsZipFile (readbuffer)) { @@ -608,18 +627,22 @@ LoadDVDFileOffset (unsigned char *buffer, int length) { for (i = 0; i < blocks; i++) { - dvd_read (readbuffer, 2048, discoffset); + ret = dvd_read (readbuffer, 2048, discoffset); + if(ret <= 0) // read failure + return 0; memcpy (buffer + offset, readbuffer, 2048); offset += 2048; discoffset += 2048; - ShowProgress ((char *)"Loading...", offset, length); + ShowProgress ("Loading...", offset, length); } /*** And final cleanup ***/ if (dvddirlength % 2048) { i = dvddirlength % 2048; - dvd_read (readbuffer, 2048, discoffset); + ret = dvd_read (readbuffer, 2048, discoffset); + if(ret <= 0) // read failure + return 0; memcpy (buffer + offset, readbuffer, i); } } @@ -637,7 +660,7 @@ LoadDVDFile(char * buffer, char *filepath, int datasize, bool silent) else { if(!silent) - WaitPrompt((char *)"Error loading file!"); + WaitPrompt("Error loading file!"); return 0; } } diff --git a/source/ngc/dvd.h b/source/ngc/dvd.h index 06df91a..27d89ad 100644 --- a/source/ngc/dvd.h +++ b/source/ngc/dvd.h @@ -12,10 +12,10 @@ #define _NGCDVD_ int getpvd (); +bool MountDVD(bool silent); int ParseDVDdirectory (); int LoadDVDFileOffset(unsigned char *buffer, int length); int LoadDVDFile(char * buffer, char *filepath, int datasize, bool silent); -bool TestDVD(); int dvd_read (void *dst, unsigned int len, u64 offset); int dvd_safe_read (void *dst, unsigned int len, u64 offset); bool SwitchDVDFolder(char dir[]); diff --git a/source/ngc/fileop.cpp b/source/ngc/fileop.cpp index 840a155..5ad8435 100644 --- a/source/ngc/fileop.cpp +++ b/source/ngc/fileop.cpp @@ -5,7 +5,7 @@ * * fileop.cpp * - * FAT File operations + * File operations ***************************************************************************/ #include @@ -13,29 +13,108 @@ #include #include #include +#include +#include #include +#include +#include +#include #include "vba.h" #include "vbasupport.h" #include "fileop.h" +#include "smbop.h" +#include "dvd.h" +#include "memcardop.h" #include "gcunzip.h" #include "video.h" #include "menudraw.h" #include "filesel.h" #include "preferences.h" -// FAT file pointer - the only one we should ever use! -FILE * fatfile; +// file pointer - the only one we should ever use! +FILE * file; +bool unmountRequired[9] = { false, false, false, false, false, false, false, false, false }; +bool isMounted[9] = { false, false, false, false, false, false, false, false, false }; +#ifdef HW_RVL + const DISC_INTERFACE* sd = &__io_wiisd; + const DISC_INTERFACE* usb = &__io_usbstorage; +#else + const DISC_INTERFACE* carda = &__io_gcsda; + const DISC_INTERFACE* cardb = &__io_gcsdb; +#endif /**************************************************************************** - * UnmountFAT - * Unmounts the FAT device specified + * deviceThreading ***************************************************************************/ -void UnmountFAT(PARTITION_INTERFACE part) +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)) - fatUnsafeUnmount(part); + while (1) + { +#ifdef HW_RVL + if(isMounted[METHOD_SD]) + { + if(!sd->isInserted()) // check if the device was removed + { + unmountRequired[METHOD_SD] = true; + isMounted[METHOD_SD] = false; + } + } + + if(isMounted[METHOD_USB]) + { + if(!usb->isInserted()) // check if the device was removed - doesn't work on USB! + { + unmountRequired[METHOD_USB] = true; + isMounted[METHOD_USB] = false; + } + } + + InitializeNetwork(SILENT); +#else + if(isMounted[METHOD_SD_SLOTA]) + { + if(!carda->isInserted()) // check if the device was removed + { + unmountRequired[METHOD_SD_SLOTA] = true; + isMounted[METHOD_SD_SLOTA] = false; + } + } + if(isMounted[METHOD_SD_SLOTB]) + { + if(!cardb->isInserted()) // check if the device was removed + { + unmountRequired[METHOD_SD_SLOTB] = true; + isMounted[METHOD_SD_SLOTB] = false; + } + } +#endif + usleep(500000); // suspend thread for 1/2 sec + } + + return NULL; +} + +/**************************************************************************** + * InitDeviceThread + * + * libOGC provides a nice wrapper for LWP access. + * This function sets up a new local queue and attaches the thread to it. + ***************************************************************************/ +void +InitDeviceThread() +{ + LWP_CreateThread (&devicethread, devicecallback, NULL, NULL, 0, 80); } /**************************************************************************** @@ -45,11 +124,12 @@ void UnmountFAT(PARTITION_INTERFACE part) void UnmountAllFAT() { #ifdef HW_RVL - UnmountFAT(PI_INTERNAL_SD); - UnmountFAT(PI_USBSTORAGE); + fatUnmount("sd"); + fatUnmount("usb"); +#else + fatUnmount("carda"); + fatUnmount("cardb"); #endif - UnmountFAT(PI_SDGECKO_A); - UnmountFAT(PI_SDGECKO_B); } /**************************************************************************** @@ -58,71 +138,128 @@ void UnmountAllFAT() * If so, unmounts the device * Attempts to mount the device specified * Sets libfat to use the device by default - * Enables read-ahead cache for SD/USB ***************************************************************************/ -bool MountFAT(PARTITION_INTERFACE part) + +bool MountFAT(int method) { - UnmountFAT(part); + bool mounted = true; // assume our disc is already mounted + char name[10]; + const DISC_INTERFACE* disc = NULL; - bool mounted = fatMountNormalInterface(part, 8); - - if(mounted) + switch(method) { - fatSetDefaultInterface(part); - #ifdef HW_RVL - if(part == PI_INTERNAL_SD || part == PI_USBSTORAGE) - fatEnableReadAhead (part, 6, 64); - #endif +#ifdef HW_RVL + case METHOD_SD: + sprintf(name, "sd"); + disc = sd; + break; + case METHOD_USB: + sprintf(name, "usb"); + disc = usb; + break; +#else + case METHOD_SD_SLOTA: + sprintf(name, "carda"); + disc = carda; + break; + + case METHOD_SD_SLOTB: + sprintf(name, "cardb"); + disc = cardb; + break; +#endif + default: + return false; // unknown device } + + sprintf(rootdir, "%s:/", name); + + // isInserted doesn't work properly for USB - so we will force a shutdown + //unmountRequired[METHOD_USB] = true; + + if(unmountRequired[method]) + { + unmountRequired[method] = false; + fatUnmount(name); + disc->shutdown(); + } + if(!isMounted[method]) + { + if(!disc->startup()) + mounted = false; + else if(!fatMountSimple(name, disc)) + mounted = false; + else + fatEnableReadAhead(name, 6, 64); + } + + isMounted[method] = mounted; return mounted; } -/**************************************************************************** - * ChangeFATInterface - * Unmounts all devices and attempts to mount/configure the device specified - ***************************************************************************/ -bool ChangeFATInterface(int method, bool silent) +void MountAllFAT() { - #ifdef USE_VM - return true; // we don't want to unmount/remount since a file is loaded! - #endif +#ifdef HW_RVL + MountFAT(METHOD_SD); + MountFAT(METHOD_USB); +#else + MountFAT(METHOD_SD_SLOTA); + MountFAT(METHOD_SD_SLOTB); +#endif +} +/**************************************************************************** + * ChangeInterface + * Attempts to mount/configure the device specified + ***************************************************************************/ +bool ChangeInterface(int method, bool silent) +{ bool mounted = false; if(method == METHOD_SD) { #ifdef HW_RVL - mounted = MountFAT(PI_INTERNAL_SD); // try Wii internal SD - #endif - - if(!mounted) // internal SD not found - mounted = MountFAT(PI_SDGECKO_A); // try SD Gecko on slot A + mounted = MountFAT(METHOD_SD); // try Wii internal SD + #else + mounted = MountFAT(METHOD_SD_SLOTA); // try SD Gecko on slot A if(!mounted) // internal SD and SD Gecko (on slot A) not found - mounted = MountFAT(PI_SDGECKO_B); // try SD Gecko on slot B + mounted = MountFAT(METHOD_SD_SLOTB); // try SD Gecko on slot B + #endif if(!mounted && !silent) // no SD device found - WaitPrompt ((char *)"SD card not found!"); + WaitPrompt ("SD card not found!"); } else if(method == METHOD_USB) { #ifdef HW_RVL - mounted = MountFAT(PI_USBSTORAGE); + mounted = MountFAT(method); if(!mounted && !silent) - WaitPrompt ((char *)"USB drive not found!"); + WaitPrompt ("USB drive not found!"); #endif } + else if(method == METHOD_SMB) + { + sprintf(rootdir, "smb:/"); + mounted = ConnectShare(NOTSILENT); + } + else if(method == METHOD_DVD) + { + sprintf(rootdir, "/"); + mounted = MountDVD(NOTSILENT); + } return mounted; } /*************************************************************************** - * Browse FAT subdirectories + * Browse subdirectories **************************************************************************/ int -ParseFATdirectory(int method) +ParseDirectory() { int nbfiles = 0; - DIR_ITER *fatdir; + DIR_ITER *dir; + char fulldir[MAXPATHLEN]; char filename[MAXPATHLEN]; char tmpname[MAXPATHLEN]; struct stat filestat; @@ -134,28 +271,32 @@ ParseFATdirectory(int method) // Clear any existing values memset (&filelist, 0, sizeof (FILEENTRIES) * MAXFILES); + // add device to path + sprintf(fulldir, "%s%s", rootdir, currentdir); + // open the directory - fatdir = diropen(currentdir); - if (fatdir == NULL) + dir = diropen(fulldir); + + if (dir == NULL) { - sprintf(msg, "Couldn't open %s", currentdir); + sprintf(msg, "Error opening %s", fulldir); WaitPrompt(msg); // if we can't open the dir, open root dir - sprintf(currentdir,"%s",ROOTFATDIR); + sprintf(fulldir,"%s",rootdir); - fatdir = diropen(currentdir); + dir = diropen(currentdir); - if (fatdir == NULL) + if (dir == NULL) { - sprintf(msg, "Error opening %s", currentdir); + sprintf(msg, "Error opening %s", fulldir); WaitPrompt(msg); return 0; } } // index files/folders - while(dirnext(fatdir,filename,&filestat) == 0) + while(dirnext(dir,filename,&filestat) == 0) { if(strcmp(filename,".") != 0) { @@ -170,7 +311,7 @@ ParseFATdirectory(int method) } // close directory - dirclose(fatdir); + dirclose(dir); // Sort the file list qsort(filelist, nbfiles, sizeof(FILEENTRIES), FileSortCallback); @@ -179,109 +320,167 @@ ParseFATdirectory(int method) } /**************************************************************************** - * LoadFATSzFile + * LoadSzFile * Loads the selected file # from the specified 7z into rbuffer * Returns file size ***************************************************************************/ -int -LoadFATSzFile(char * filepath, unsigned char * rbuffer) +u32 +LoadSzFile(char * filepath, unsigned char * rbuffer) { u32 size; - fatfile = fopen (filepath, "rb"); - if (fatfile > 0) + file = fopen (filepath, "rb"); + if (file > 0) { size = SzExtractFile(filelist[selection].offset, rbuffer); - fclose (fatfile); + fclose (file); return size; } else { - WaitPrompt((char*) "Error opening file"); + WaitPrompt("Error opening file"); return 0; } } /**************************************************************************** - * LoadFATFile + * LoadFile ***************************************************************************/ -int -LoadFATFile (char * rbuffer, char *filepath, int length, bool silent) +u32 +LoadFile (char * rbuffer, char *filepath, u32 length, int method, bool silent) { char zipbuffer[2048]; - int size = 0; - int readsize = 0; + u32 size = 0; + u32 readsize = 0; - fatfile = fopen (filepath, "rb"); + if(!ChangeInterface(method, NOTSILENT)) + return 0; - if (fatfile > 0) + switch(method) + { + case METHOD_DVD: + return LoadDVDFile (rbuffer, filepath, length, silent); + break; + case METHOD_MC_SLOTA: + return LoadMCFile (rbuffer, CARD_SLOTA, filepath, silent); + break; + case METHOD_MC_SLOTB: + return LoadMCFile (rbuffer, CARD_SLOTB, filepath, silent); + break; + } + + // add device to filepath + char fullpath[1024]; + sprintf(fullpath, "%s%s", rootdir, filepath); + + file = fopen (fullpath, "rb"); + + if (file > 0) { if(length > 0 && length <= 2048) // do a partial read (eg: to check file header) { - fread (rbuffer, 1, length, fatfile); - size = length; + size = fread (rbuffer, 1, length, file); } else // load whole file { - readsize = fread (zipbuffer, 1, 2048, fatfile); + readsize = fread (zipbuffer, 1, 2048, file); if(readsize > 0) { if (IsZipFile (zipbuffer)) { - size = UnZipBuffer ((unsigned char *)rbuffer, METHOD_SD); // unzip from FAT + size = UnZipBuffer ((unsigned char *)rbuffer, method); // unzip } else { - // Just load the file up - fseek(fatfile, 0, SEEK_END); - size = ftell(fatfile); // get filesize - fseek(fatfile, 2048, SEEK_SET); // seek back to point where we left off - memcpy (rbuffer, zipbuffer, 2048); // copy what we already read + struct stat fileinfo; + fstat(file->_file, &fileinfo); + size = fileinfo.st_size; - ShowProgress ((char *)"Loading...", 2048, length); + memcpy (rbuffer, zipbuffer, 2048); // copy what we already read - int offset = 2048; - while(offset < size && readsize != 0) + ShowProgress ("Loading...", 2048, length); + + u32 offset = 2048; + while(offset < size) { - readsize = fread (rbuffer + offset, 1, (1024*512), fatfile); // read in 512K chunks - offset += readsize; - ShowProgress ((char *)"Loading...", offset, length); + 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); - return size; + fclose (file); } - else + if(!size && !silent) { - if(!silent) - WaitPrompt((char*) "Error opening file!"); - return 0; + unmountRequired[method] = true; + WaitPrompt("Error loading file!"); } + + return size; +} + +u32 LoadFile(char filepath[], int method, bool silent) +{ + return LoadFile((char *)savebuffer, filepath, 0, method, silent); } /**************************************************************************** - * SaveFATFile - * Write buffer to FAT card file + * SaveFile + * Write buffer to file ***************************************************************************/ -int -SaveFATFile (char * buffer, char *filepath, int datasize, bool silent) +u32 +SaveFile (char * buffer, char *filepath, u32 datasize, int method, bool silent) { + u32 written = 0; + + if(!ChangeInterface(method, NOTSILENT)) + return 0; + + switch(method) + { + case METHOD_MC_SLOTA: + return SaveMCFile (buffer, CARD_SLOTA, filepath, datasize, silent); + break; + case METHOD_MC_SLOTB: + return SaveMCFile (buffer, CARD_SLOTB, filepath, datasize, silent); + break; + } + if (datasize) { - fatfile = fopen (filepath, "wb"); + // add device to filepath + char fullpath[1024]; + sprintf(fullpath, "%s%s", rootdir, filepath); - if (fatfile <= 0) - { - char msg[100]; - sprintf(msg, "Couldn't save %s", filepath); - WaitPrompt (msg); - return 0; - } + // open file for writing + file = fopen (filepath, "wb"); - fwrite (savebuffer, 1, datasize, fatfile); - fclose (fatfile); + if (file > 0) + { + written = fwrite (savebuffer, 1, datasize, file); + fclose (file); + } + + if(!written && !silent) + { + unmountRequired[method] = true; + WaitPrompt ("Error saving file!"); + } } - return datasize; + return written; +} + +u32 SaveFile(char filepath[], u32 datasize, int method, bool silent) +{ + return SaveFile((char *)savebuffer, filepath, datasize, method, silent); } diff --git a/source/ngc/fileop.h b/source/ngc/fileop.h index 48d4834..07b7925 100644 --- a/source/ngc/fileop.h +++ b/source/ngc/fileop.h @@ -5,30 +5,32 @@ * * fileop.h * - * FAT File operations + * File operations ****************************************************************************/ -#ifndef _FATFILESC_ -#define _FATFILESC_ +#ifndef _FILEOP_H_ +#define _FILEOP_H_ + #include #include #include #include #include -#include -#include #include -#define ROOTFATDIR "fat:/" - +void InitDeviceThread(); +void MountAllFAT(); void UnmountAllFAT(); -bool ChangeFATInterface(int method, bool silent); -int ParseFATdirectory(int method); -int LoadFATSzFile(char * filepath, unsigned char * rbuffer); -int SaveFATFile (char * sbuffer, char *filepath, int length, bool silent); -int LoadFATFile (char * sbuffer, char *filepath, int length, bool silent); +bool ChangeInterface(int method, bool silent); +int ParseDirectory(); +u32 LoadFile(char * rbuffer, char *filepath, u32 length, int method, bool silent); +u32 LoadFile(char filepath[], int method, bool silent); +u32 LoadSzFile(char * filepath, unsigned char * rbuffer); +u32 SaveFile(char * buffer, char *filepath, u32 datasize, int method, bool silent); +u32 SaveFile(char filepath[], u32 datasize, int method, bool silent); -extern char currFATdir[MAXPATHLEN]; -extern FILE * fatfile; +extern char currdir[MAXPATHLEN]; +extern FILE * file; +extern bool unmountRequired[]; #endif diff --git a/source/ngc/filesel.cpp b/source/ngc/filesel.cpp index 3193eb2..fda9dc7 100644 --- a/source/ngc/filesel.cpp +++ b/source/ngc/filesel.cpp @@ -36,6 +36,7 @@ extern "C" { int offset; int selection; +char rootdir[10]; char currentdir[MAXPATHLEN]; char szpath[MAXPATHLEN]; int maxfiles; @@ -90,19 +91,19 @@ FreeSaveBuffer () ****************************************************************************/ int autoLoadMethod() { - ShowAction ((char*) "Attempting to determine load method..."); + ShowAction ("Attempting to determine load method..."); - if(ChangeFATInterface(METHOD_SD, SILENT)) + if(ChangeInterface(METHOD_SD, SILENT)) return METHOD_SD; - else if(ChangeFATInterface(METHOD_USB, SILENT)) + else if(ChangeInterface(METHOD_USB, SILENT)) return METHOD_USB; - else if(TestDVD()) + else if(ChangeInterface(METHOD_DVD, SILENT)) return METHOD_DVD; - else if(ConnectShare (SILENT)) + else if(ChangeInterface(METHOD_SMB, SILENT)) return METHOD_SMB; else { - WaitPrompt((char*) "Unable to auto-determine load method!"); + WaitPrompt("Unable to auto-determine load method!"); return 0; // no method found } } @@ -114,21 +115,21 @@ int autoLoadMethod() ****************************************************************************/ int autoSaveMethod() { - ShowAction ((char*) "Attempting to determine save method..."); + ShowAction ("Attempting to determine save method..."); - if(ChangeFATInterface(METHOD_SD, SILENT)) + if(ChangeInterface(METHOD_SD, SILENT)) return METHOD_SD; - else if(ChangeFATInterface(METHOD_USB, SILENT)) + else if(ChangeInterface(METHOD_USB, SILENT)) return METHOD_USB; else if(TestCard(CARD_SLOTA, SILENT)) return METHOD_MC_SLOTA; else if(TestCard(CARD_SLOTB, SILENT)) return METHOD_MC_SLOTB; - else if(ConnectShare (SILENT)) + else if(ChangeInterface(METHOD_SMB, SILENT)) return METHOD_SMB; else { - WaitPrompt((char*) "Unable to auto-determine save method!"); + WaitPrompt("Unable to auto-determine save method!"); return 0; // no method found } } @@ -185,13 +186,12 @@ int UpdateDirName(int method) } else { - WaitPrompt((char*)"Directory name is too long!"); + WaitPrompt("Directory name is too long!"); return -1; } } } - bool MakeFilePath(char filepath[], int type, int method) { char file[512]; @@ -203,7 +203,7 @@ bool MakeFilePath(char filepath[], int type, int method) // Check path length if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) >= MAXPATHLEN) { - WaitPrompt((char*)"Maximum filepath length reached!"); + WaitPrompt("Maximum filepath length reached!"); filepath[0] = 0; return false; } @@ -235,86 +235,20 @@ bool MakeFilePath(char filepath[], int type, int method) } switch(method) { - case METHOD_SD: - case METHOD_USB: - sprintf (temppath, "%s/%s/%s", ROOTFATDIR, folder, file); - break; - case METHOD_DVD: - case METHOD_SMB: - sprintf (temppath, "%s/%s", folder, file); - break; case METHOD_MC_SLOTA: case METHOD_MC_SLOTB: sprintf (temppath, "%s", file); temppath[31] = 0; // truncate filename break; + default: + sprintf (temppath, "%s/%s", folder, file); + break; } } strcpy(filepath, temppath); return true; } -int LoadFile(char * buffer, char filepath[], int length, int method, bool silent) -{ - int offset = 0; - - switch(method) - { - case METHOD_SD: - case METHOD_USB: - if(ChangeFATInterface(method, NOTSILENT)) - offset = LoadFATFile (buffer, filepath, length, silent); - break; - case METHOD_SMB: - offset = LoadSMBFile (buffer, filepath, length, silent); - break; - case METHOD_DVD: - offset = LoadDVDFile (buffer, filepath, length, silent); - break; - case METHOD_MC_SLOTA: - offset = LoadMCFile (buffer, CARD_SLOTA, filepath, silent); - break; - case METHOD_MC_SLOTB: - offset = LoadMCFile (buffer, CARD_SLOTB, filepath, silent); - break; - } - return offset; -} - -int LoadFile(char filepath[], int method, bool silent) -{ - return LoadFile((char *)savebuffer, filepath, 0, method, silent); -} - -int SaveFile(char * buffer, char filepath[], int datasize, int method, bool silent) -{ - int offset = 0; - - switch(method) - { - case METHOD_SD: - case METHOD_USB: - if(ChangeFATInterface(method, NOTSILENT)) - offset = SaveFATFile (buffer, filepath, datasize, silent); - break; - case METHOD_SMB: - offset = SaveSMBFile (buffer, filepath, datasize, silent); - break; - case METHOD_MC_SLOTA: - offset = SaveMCFile (buffer, CARD_SLOTA, filepath, datasize, silent); - break; - case METHOD_MC_SLOTB: - offset = SaveMCFile (buffer, CARD_SLOTB, filepath, datasize, silent); - break; - } - return offset; -} - -int SaveFile(char filepath[], int datasize, int method, bool silent) -{ - return SaveFile((char *)savebuffer, filepath, datasize, method, silent); -} - /**************************************************************************** * FileSortCallback * @@ -458,23 +392,18 @@ int FileSelector (int method) { switch (method) { - case METHOD_SD: - case METHOD_USB: - maxfiles = ParseFATdirectory(method); - break; - case METHOD_DVD: - maxfiles = ParseDVDdirectory(); - break; + maxfiles = ParseDVDdirectory(); + break; - case METHOD_SMB: - maxfiles = ParseSMBdirectory(NOTSILENT); - break; + default: + maxfiles = ParseDirectory(); + break; } if (!maxfiles) { - WaitPrompt ((char*) "Error reading directory!"); + WaitPrompt ("Error reading directory!"); haverom = 1; // quit menu } } @@ -485,11 +414,6 @@ int FileSelector (int method) } else // this is a file { - // better do another unmount/remount, just in case - if(method == METHOD_SD || method == METHOD_USB) - if(!ChangeFATInterface(method, NOTSILENT)) - return 0; - // 7z file - let's open it up to select a file inside if(IsSz()) { @@ -497,6 +421,11 @@ int FileSelector (int method) if(!MakeFilePath(szpath, FILE_ROM, method)) return 0; + // add device to filepath + char fullpath[1024]; + sprintf(fullpath, "%s%s", rootdir, szpath); + strcpy(szpath, fullpath); + int szfiles = SzParse(szpath, method); if(szfiles) { @@ -504,14 +433,14 @@ int FileSelector (int method) inSz = true; } else - WaitPrompt((char*) "Error opening archive!"); + WaitPrompt("Error opening archive!"); } else { // store the filename (w/o ext) - used for sram/freeze naming StripExt(ROMFilename, filelist[selection].filename); - ShowAction ((char *)"Loading..."); + ShowAction ("Loading..."); ROMLoaded = LoadVBAROM(method); inSz = false; @@ -520,10 +449,6 @@ int FileSelector (int method) { return 1; } - else - { - WaitPrompt((char*) "Error loading ROM!"); - } } } redraw = 1; @@ -630,99 +555,32 @@ int FileSelector (int method) } /**************************************************************************** - * OpenDVD - * - * Function to load a DVD directory and display to user. + * OpenROM + * Opens device specified by method, displays a list of ROMS ***************************************************************************/ + int -OpenDVD (int method) +OpenROM (int method) { - if (!getpvd()) + if(method == METHOD_AUTO) + method = autoLoadMethod(); + + if(ChangeInterface(method, NOTSILENT)) { - ShowAction((char*) "Loading DVD..."); - #ifdef HW_DOL - DVD_Mount(); // mount the DVD unit again - #elif WII_DVD - u32 val; - DI_GetCoverRegister(&val); - if(val & 0x1) // True if no disc inside, use (val & 0x2) for true if disc inside. + // change current dir to roms directory + switch(method) { - WaitPrompt((char *)"No disc inserted!"); - return 0; + case METHOD_DVD: + 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 load 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 vba roms directory - sprintf ( currentdir, "%s/%s", ROOTFATDIR, GCSettings.LoadFolder ); - - // Parse initial root directory and get entries list - maxfiles = ParseFATdirectory (method); if (maxfiles > 0) { // Select an entry @@ -731,41 +589,9 @@ OpenFAT (int method) else { // no entries found - WaitPrompt ((char *)"No Files Found!"); + WaitPrompt ("No Files Found!"); return 0; } } return 0; } - -/**************************************************************************** - * OpenROM - * Opens device specified by method, displays a list of ROMS - ***************************************************************************/ - -int -OpenROM (int method) -{ - int loadROM = 0; - - if(method == METHOD_AUTO) - method = autoLoadMethod(); - - switch (method) - { - case METHOD_SD: - case METHOD_USB: - loadROM = OpenFAT (method); - break; - case METHOD_DVD: - // Load from DVD - loadROM = OpenDVD (method); - break; - case METHOD_SMB: - // Load from Network (SMB) - loadROM = OpenSMB (method); - break; - } - - return loadROM; -} diff --git a/source/ngc/filesel.h b/source/ngc/filesel.h index bed21a7..a2759e8 100644 --- a/source/ngc/filesel.h +++ b/source/ngc/filesel.h @@ -31,6 +31,7 @@ extern FILEENTRIES filelist[MAXFILES]; extern unsigned char *savebuffer; extern int offset; extern int selection; +extern char rootdir[10]; extern char currentdir[MAXPATHLEN]; extern char szpath[MAXPATHLEN]; extern bool inSz; @@ -40,10 +41,6 @@ extern char ROMFilename[512]; void AllocSaveBuffer(); void FreeSaveBuffer(); bool MakeFilePath(char filepath[], int type, int method); -int LoadFile(char * buffer, char filepath[], int length, int method, bool silent); -int LoadFile(char filepath[], int method, bool silent); -int SaveFile(char * buffer, char filepath[], int datasize, int method, bool silent); -int SaveFile(char filepath[], int datasize, int method, bool silent); int OpenROM (int method); int autoLoadMethod(); int autoSaveMethod(); diff --git a/source/ngc/gcunzip.cpp b/source/ngc/gcunzip.cpp index 2b31ca8..9093b82 100644 --- a/source/ngc/gcunzip.cpp +++ b/source/ngc/gcunzip.cpp @@ -101,32 +101,30 @@ UnZipBuffer (unsigned char *outbuffer, int method) int have = 0; char readbuffer[ZIPCHUNK]; u64 discoffset = 0; + int sizeread = 0; // Read Zip Header switch (method) { - case METHOD_SD: - case METHOD_USB: - fseek(fatfile, 0, SEEK_SET); - fread (readbuffer, 1, ZIPCHUNK, fatfile); - break; - case METHOD_DVD: discoffset = dvddir; - dvd_read (readbuffer, ZIPCHUNK, discoffset); + sizeread = dvd_safe_read (readbuffer, ZIPCHUNK, discoffset); break; - - case METHOD_SMB: - SMB_ReadFile(readbuffer, ZIPCHUNK, 0, smbfile); + default: + fseek(file, 0, SEEK_SET); + sizeread = fread (readbuffer, 1, ZIPCHUNK, file); break; } + if(sizeread <= 0) + return 0; + /*** Copy PKZip header to local, used as info ***/ memcpy (&pkzip, readbuffer, sizeof (PKZIPHEADER)); pkzip.uncompressedSize = FLIP32 (pkzip.uncompressedSize); - ShowProgress ((char *)"Loading...", 0, pkzip.uncompressedSize); + ShowProgress ("Loading...", 0, pkzip.uncompressedSize); /*** Prepare the zip stream ***/ memset (&zs, 0, sizeof (z_stream)); @@ -182,22 +180,18 @@ UnZipBuffer (unsigned char *outbuffer, int method) switch (method) { - case METHOD_SD: - case METHOD_USB: - fread (readbuffer, 1, ZIPCHUNK, fatfile); - break; - case METHOD_DVD: readoffset += ZIPCHUNK; - dvd_safe_read (readbuffer, ZIPCHUNK, discoffset+readoffset); + sizeread = dvd_safe_read (readbuffer, ZIPCHUNK, discoffset+readoffset); break; - - case METHOD_SMB: - readoffset += ZIPCHUNK; - SMB_ReadFile(readbuffer, ZIPCHUNK, readoffset, smbfile); + default: + sizeread = fread (readbuffer, 1, ZIPCHUNK, file); break; } - ShowProgress ((char *)"Loading...", bufferoffset, pkzip.uncompressedSize); + if(sizeread <= 0) + break; // read failure + + ShowProgress ("Loading...", bufferoffset, pkzip.uncompressedSize); } while (res != Z_STREAM_END); @@ -232,13 +226,21 @@ GetFirstZipFilename (int method) return NULL; // read start of ZIP - LoadFile (tempbuffer, filepath, ZIPCHUNK, method, NOTSILENT); + if(LoadFile (tempbuffer, filepath, ZIPCHUNK, method, NOTSILENT)) + { + tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27) + int namelength = tempbuffer[26]; // filename length starts 26 bytes in - tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27) - int namelength = tempbuffer[26]; // filename length starts 26 bytes in - - firstFilename = &tempbuffer[30]; // first filename of a ZIP starts 31 bytes in - firstFilename[namelength] = 0; // truncate at filename length + if(namelength > 0 && namelength < 200) // the filename is a reasonable length + { + firstFilename = &tempbuffer[30]; // first filename of a ZIP starts 31 bytes in + firstFilename[namelength] = 0; // truncate at filename length + } + else + { + WaitPrompt("Error - Invalid ZIP file!"); + } + } return firstFilename; } @@ -262,6 +264,7 @@ char szerrormsg[][30] = { "7z: CRC Error", "7z: Not implemented", "7z: Fail", + "7z: Data read failure", "7z: Archive error", "7z: Dictionary too large", }; @@ -312,6 +315,9 @@ void SzDisplayError(SZ_RESULT res) // function used by the 7zip SDK to read data from SD/USB/DVD/SMB SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize) { + u32 seekok = 0; + u32 sizeread = 0; + // the void* object is a SzFileInStream SzFileInStream *s = (SzFileInStream *) object; @@ -324,26 +330,30 @@ SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, siz // read data switch (szMethod) { - case METHOD_SD: - case METHOD_USB: - fseek(fatfile, offset, SEEK_SET); - fread(sz_buffer, 1, maxRequiredSize, fatfile); - break; case METHOD_DVD: - dvd_safe_read(sz_buffer, maxRequiredSize, offset); + sizeread = dvd_safe_read(sz_buffer, maxRequiredSize, offset); break; - case METHOD_SMB: - SMB_ReadFile(sz_buffer, maxRequiredSize, offset, smbfile); + default: + seekok = fseek(file, offset, SEEK_SET); + sizeread = fread(sz_buffer, 1, maxRequiredSize, file); break; } + if(seekok != 0 || sizeread <= 0) + { + char msg[150]; + sprintf(msg, "sizeread: %u", sizeread); + WaitPrompt(msg); + return SZE_FAILREAD; + } + *buffer = sz_buffer; *processedSize = maxRequiredSize; s->pos += *processedSize; if(maxRequiredSize > 1024) // only show progress for large reads // this isn't quite right, but oh well - ShowProgress ((char *)"Loading...", s->pos, filelist[selection].length); + ShowProgress ("Loading...", s->pos, filelist[selection].length); return SZ_OK; } @@ -356,10 +366,7 @@ SZ_RESULT SzFileSeekImp(void *object, CFileSize pos) // check if the 7z SDK wants to move the pointer to somewhere after the EOF if (pos >= s->len) - { - WaitPrompt((char *) "7z: Error - attempt to read after EOF!"); return SZE_FAIL; - } // save new position and return s->pos = pos; @@ -388,13 +395,9 @@ int SzParse(char * filepath, int method) { case METHOD_SD: case METHOD_USB: - fatfile = fopen (filepath, "rb"); - if(!fatfile) - return 0; - break; case METHOD_SMB: - smbfile = OpenSMBFile(filepath); - if(!smbfile) + file = fopen (filepath, "rb"); + if(!file) return 0; break; } @@ -402,7 +405,7 @@ int SzParse(char * filepath, int method) // set szMethod to current chosen load method szMethod = method; - // set handler functions for reading data from FAT/SMB/DVD + // set handler functions for reading data from SD/USB/SMB/DVD SzArchiveStream.InStream.Read = SzFileReadImp; SzArchiveStream.InStream.Seek = SzFileSeekImp; @@ -481,10 +484,8 @@ int SzParse(char * filepath, int method) { case METHOD_SD: case METHOD_USB: - fclose(fatfile); - break; case METHOD_SMB: - SMB_CloseFile (smbfile); + fclose(file); break; } return nbfiles; @@ -511,36 +512,36 @@ void SzClose() int SzExtractFile(int i, unsigned char *buffer) { - // prepare some variables - SzBlockIndex = 0xFFFFFFFF; - SzOffset = 0; + // prepare some variables + SzBlockIndex = 0xFFFFFFFF; + SzOffset = 0; - // Unzip the file + // Unzip the file - SzRes = SzExtract2( - &SzArchiveStream.InStream, - &SzDb, - i, // index of file - &SzBlockIndex, // index of solid block - &buffer, - &SzBufferSize, - &SzOffset, // offset of stream for required file in *outBuffer - &SzOutSizeProcessed, // size of file in *outBuffer - &SzAllocImp, - &SzAllocTempImp); + SzRes = SzExtract2( + &SzArchiveStream.InStream, + &SzDb, + i, // index of file + &SzBlockIndex, // index of solid block + &buffer, + &SzBufferSize, + &SzOffset, // offset of stream for required file in *outBuffer + &SzOutSizeProcessed, // size of file in *outBuffer + &SzAllocImp, + &SzAllocTempImp); - // close 7Zip archive and free memory + // close 7Zip archive and free memory SzClose(); - // check for errors - if(SzRes != SZ_OK) - { - // display error message - SzDisplayError(SzRes); - return 0; - } - else - { - return SzOutSizeProcessed; - } + // check for errors + if(SzRes != SZ_OK) + { + // display error message + SzDisplayError(SzRes); + return 0; + } + else + { + return SzOutSizeProcessed; + } } diff --git a/source/ngc/memcardop.cpp b/source/ngc/memcardop.cpp index dbb34dd..1012fc1 100644 --- a/source/ngc/memcardop.cpp +++ b/source/ngc/memcardop.cpp @@ -76,9 +76,9 @@ bool TestCard(int slot, bool silent) if(!silent) { if (slot == CARD_SLOTA) - WaitPrompt((char*) "Mounted Slot A Memory Card!"); + WaitPrompt("Mounted Slot A Memory Card!"); else - WaitPrompt((char*) "Mounted Slot B Memory Card!"); + WaitPrompt("Mounted Slot B Memory Card!"); } CARD_Unmount (slot); return true; @@ -88,9 +88,9 @@ bool TestCard(int slot, bool silent) if(!silent) { if (slot == CARD_SLOTA) - WaitPrompt((char*) "Unable to Mount Slot A Memory Card!"); + WaitPrompt("Unable to Mount Slot A Memory Card!"); else - WaitPrompt((char*) "Unable to Mount Slot B Memory Card!"); + WaitPrompt("Unable to Mount Slot B Memory Card!"); } return false; @@ -148,7 +148,7 @@ VerifyMCFile (char *buf, int slot, char *filename, int datasize) if (!CardFileExists (filename, slot)) { CARD_Unmount (slot); - WaitPrompt((char*) "Unable to open file for verify!"); + WaitPrompt("Unable to open file for verify!"); return 0; } @@ -176,7 +176,7 @@ VerifyMCFile (char *buf, int slot, char *filename, int datasize) { CARD_Close (&CardFile); CARD_Unmount (slot); - WaitPrompt((char*) "File did not verify!"); + WaitPrompt("File did not verify!"); return 0; } @@ -193,9 +193,9 @@ VerifyMCFile (char *buf, int slot, char *filename, int datasize) } else if (slot == CARD_SLOTA) - WaitPrompt((char*) "Unable to Mount Slot A Memory Card!"); + WaitPrompt("Unable to Mount Slot A Memory Card!"); else - WaitPrompt((char*) "Unable to Mount Slot B Memory Card!"); + WaitPrompt("Unable to Mount Slot B Memory Card!"); return 0; } @@ -228,7 +228,7 @@ LoadMCFile (char *buf, int slot, char *filename, bool silent) if (!CardFileExists (filename, slot)) { if (!silent) - WaitPrompt((char*) "Unable to open file"); + WaitPrompt("Unable to open file"); return 0; } @@ -258,9 +258,9 @@ LoadMCFile (char *buf, int slot, char *filename, bool silent) } else if (slot == CARD_SLOTA) - WaitPrompt((char*) "Unable to Mount Slot A Memory Card!"); + WaitPrompt("Unable to Mount Slot A Memory Card!"); else - WaitPrompt((char*) "Unable to Mount Slot B Memory Card!"); + WaitPrompt("Unable to Mount Slot B Memory Card!"); return bytesread; } @@ -305,7 +305,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent) if (CardError) { CARD_Unmount (slot); - WaitPrompt((char*) "Unable to open card file!"); + WaitPrompt("Unable to open card file!"); return 0; } @@ -318,7 +318,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent) if (CardError) { CARD_Unmount (slot); - WaitPrompt((char*) "Not enough space to update file!"); + WaitPrompt("Not enough space to update file!"); return 0; } @@ -328,7 +328,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent) if (CardError) { CARD_Unmount (slot); - WaitPrompt((char*) "Unable to delete temporary file!"); + WaitPrompt("Unable to delete temporary file!"); return 0; } @@ -337,7 +337,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent) if (CardError) { CARD_Unmount (slot); - WaitPrompt((char*) "Unable to delete existing file!"); + WaitPrompt("Unable to delete existing file!"); return 0; } @@ -346,7 +346,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent) if (CardError) { CARD_Unmount (slot); - WaitPrompt((char*) "Unable to create updated card file!"); + WaitPrompt("Unable to create updated card file!"); return 0; } } @@ -359,9 +359,9 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent) { CARD_Unmount (slot); if ( CardError == CARD_ERROR_INSSPACE ) - WaitPrompt((char*) "Not enough space to create file!"); + WaitPrompt("Not enough space to create file!"); else - WaitPrompt((char*) "Unable to create card file!"); + WaitPrompt("Unable to create card file!"); return 0; } } @@ -405,13 +405,13 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent) } else if ( !silent ) - WaitPrompt((char*) "This game does not appear to use SRAM"); + WaitPrompt("This game does not appear to use SRAM"); } else if (slot == CARD_SLOTA) - WaitPrompt((char*) "Unable to Mount Slot A Memory Card!"); + WaitPrompt("Unable to Mount Slot A Memory Card!"); else - WaitPrompt((char*) "Unable to Mount Slot B Memory Card!"); + WaitPrompt("Unable to Mount Slot B Memory Card!"); return 0; diff --git a/source/ngc/menu.cpp b/source/ngc/menu.cpp index f9696ea..474f18e 100644 --- a/source/ngc/menu.cpp +++ b/source/ngc/menu.cpp @@ -194,7 +194,7 @@ PreferencesMenu () sprintf (prefmenu[9], "Video Scaling %s", GCSettings.widescreen == true ? "16:9 Correction" : "Default"); - ret = RunMenu (prefmenu, prefmenuCount, (char*)"Preferences", 16); + ret = RunMenu (prefmenu, prefmenuCount, "Preferences", 16); switch (ret) { @@ -246,7 +246,7 @@ PreferencesMenu () case 10: DefaultSettings (); - WaitPrompt((char *)"Preferences Reset"); + WaitPrompt("Preferences Reset"); break; case 11: @@ -304,7 +304,7 @@ GameMenu () if(!GCSettings.Zoom) gamemenu[6][0] = '\0'; - ret = RunMenu (gamemenu, gamemenuCount, (char*)"Game Menu"); + ret = RunMenu (gamemenu, gamemenuCount, "Game Menu"); switch (ret) { @@ -418,21 +418,21 @@ GetButtonMap(u16 ctrlr_type, char* btn_name) switch (ctrlr_type) { case CTRLR_NUNCHUK: - strncpy (cfg_text[3], (char*)"NUNCHUK", 7); + strncpy (cfg_text[3], "NUNCHUK", 7); break; case CTRLR_CLASSIC: - strncpy (cfg_text[3], (char*)"CLASSIC", 7); + strncpy (cfg_text[3], "CLASSIC", 7); break; case CTRLR_GCPAD: - strncpy (cfg_text[3], (char*)"GC PAD", 7); + strncpy (cfg_text[3], "GC PAD", 7); break; case CTRLR_WIIMOTE: - strncpy (cfg_text[3], (char*)"WIIMOTE", 7); + strncpy (cfg_text[3], "WIIMOTE", 7); break; }; /*** note which button we are remapping ***/ - sprintf (temp, (char*)"Remapping "); + sprintf (temp, "Remapping "); for (k=0; k<9-strlen(btn_name); k++) strcat(temp, " "); // add whitespace padding to align text strncat (temp, btn_name, 9); // snes button we are remapping strncpy (cfg_text[0], temp, 19); // copy this all back to the text we wish to display @@ -470,7 +470,7 @@ ConfigureButtons (u16 ctrlr_type) int ret = 0; int oldmenu = menu; menu = 0; - char* menu_title = NULL; + char menu_title[50]; u32 pressed; unsigned int* currentpadmap = 0; @@ -481,19 +481,19 @@ ConfigureButtons (u16 ctrlr_type) /*** Update Menu Title (based on controller we're configuring) ***/ switch (ctrlr_type) { case CTRLR_NUNCHUK: - menu_title = (char*)"VBA - NUNCHUK"; + sprintf(menu_title, "VBA - NUNCHUK"); currentpadmap = ncpadmap; break; case CTRLR_CLASSIC: - menu_title = (char*)"VBA - CLASSIC"; + sprintf(menu_title, "VBA - CLASSIC"); currentpadmap = ccpadmap; break; case CTRLR_GCPAD: - menu_title = (char*)"VBA - GC PAD"; + sprintf(menu_title, "VBA - GC PAD"); currentpadmap = gcpadmap; break; case CTRLR_WIIMOTE: - menu_title = (char*)"VBA - WIIMOTE"; + sprintf(menu_title, "VBA - WIIMOTE"); currentpadmap = wmpadmap; break; }; @@ -517,7 +517,7 @@ ConfigureButtons (u16 ctrlr_type) strncat (temp, ctrlr_def[ctrlr_type].map[j].name, 6); // update button map display } else - strcat (temp, (char*)"---"); // otherwise, button is 'unmapped' + strcat (temp, "---"); // otherwise, button is 'unmapped' strncpy (cfg_btns_menu[i], temp, 19); // move back updated information } @@ -585,7 +585,7 @@ ConfigureControllers () { /*** Controller Config Menu ***/ - ret = RunMenu (ctlrmenu, ctlrmenucount, (char*)"Configure Controllers"); + ret = RunMenu (ctlrmenu, ctlrmenucount, "Configure Controllers"); switch (ret) { @@ -675,7 +675,7 @@ MainMenu (int selectedMenu) } else { - ret = RunMenu (menuitems, menucount, (char*)"Main Menu"); + ret = RunMenu (menuitems, menucount, "Main Menu"); } switch (ret) diff --git a/source/ngc/menudraw.cpp b/source/ngc/menudraw.cpp index 41b52d6..1f082f1 100644 --- a/source/ngc/menudraw.cpp +++ b/source/ngc/menudraw.cpp @@ -133,7 +133,7 @@ DrawCharacter (FT_Bitmap * bmp, FT_Int x, FT_Int y) * Place the font bitmap on the screen ***************************************************************************/ void -DrawText (int x, int y, char *text) +DrawText (int x, int y, const char *text) { int px, n; int i; @@ -222,7 +222,7 @@ Credits () setfontcolour (0x00, 0x00, 0x00); setfontsize (26); - DrawText (-1, 150, (char*)"Credits"); + DrawText (-1, 150, "Credits"); int ypos = 110; @@ -233,29 +233,29 @@ Credits () setfontsize (14); - DrawText (-1, ypos += 18, (char*)"Official Site: http://code.google.com/p/vba-wii/"); + DrawText (-1, ypos += 18, "Official Site: http://code.google.com/p/vba-wii/"); - DrawText (90, ypos += 36, (char*)"Visual Boy Advance GX"); - DrawText (380, ypos, (char*)"Tantric"); - DrawText (90, ypos += 18, (char*)"GameCube/Wii Port Improvements"); - DrawText (380, ypos, (char*)"emukidid"); - DrawText (90, ypos += 18, (char*)"Original GameCube Port"); - DrawText (380, ypos, (char*)"SoftDev"); - DrawText (90, ypos += 18, (char*)"Visual Boy Advance - M"); - DrawText (380, ypos, (char*)"VBA-M Team"); - DrawText (90, ypos += 18, (char*)"Visual Boy Advance 1.7.2"); - DrawText (380, ypos, (char*)"Forgotten"); - DrawText (90, ypos += 18, (char*)"libogc"); - DrawText (380, ypos, (char*)"Shagkur & wintermute"); - DrawText (90, ypos += 18, (char*)"Testing"); - DrawText (380, ypos, (char*)"tehskeen users"); + DrawText (90, ypos += 36, "Visual Boy Advance GX"); + DrawText (380, ypos, "Tantric"); + DrawText (90, ypos += 18, "GameCube/Wii Port Improvements"); + DrawText (380, ypos, "emukidid"); + DrawText (90, ypos += 18, "Original GameCube Port"); + DrawText (380, ypos, "SoftDev"); + DrawText (90, ypos += 18, "Visual Boy Advance - M"); + DrawText (380, ypos, "VBA-M Team"); + DrawText (90, ypos += 18, "Visual Boy Advance 1.7.2"); + DrawText (380, ypos, "Forgotten"); + DrawText (90, ypos += 18, "libogc"); + DrawText (380, ypos, "Shagkur & wintermute"); + DrawText (90, ypos += 18, "Testing"); + DrawText (380, 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); - DrawText (-1, ypos += 30, (char*)"This software is open source and may be copied,"); - DrawText (-1, ypos += 15, (char*)"distributed, or modified under the terms of"); - DrawText (-1, ypos += 15, (char*)"the GNU General Public License (GPL) Version 2."); + DrawText (-1, ypos += 30, "This software is open source and may be copied,"); + DrawText (-1, ypos += 15, "distributed, or modified under the terms of"); + DrawText (-1, ypos += 15, "the GNU General Public License (GPL) Version 2."); DrawVersion(); showscreen (); @@ -353,7 +353,7 @@ WaitButtonAB () * Show a prompt ***************************************************************************/ void -WaitPrompt (char *msg) +WaitPrompt (const char *msg) { int ypos = (screenheight - 64) >> 1; @@ -366,7 +366,7 @@ WaitPrompt (char *msg) setfontsize(16); DrawText (-1, ypos, msg); ypos += 30; - DrawText (-1, ypos, (char*)"Press A to continue"); + DrawText (-1, ypos, "Press A to continue"); DrawVersion(); showscreen (); @@ -378,7 +378,7 @@ WaitPrompt (char *msg) and 0 if B button was pressed. ***************************************************************************/ int -WaitPromptChoice (char *msg, char *bmsg, char *amsg) +WaitPromptChoice (const char *msg, const char *bmsg, const char *amsg) { int ypos = (screenheight - 64) >> 1; @@ -404,7 +404,7 @@ WaitPromptChoice (char *msg, char *bmsg, char *amsg) * Show an action in progress ***************************************************************************/ void -ShowAction (char *msg) +ShowAction (const char *msg) { int ypos = (screenheight - 30) >> 1; @@ -425,7 +425,7 @@ ShowAction (char *msg) * Generic Menu Routines ***************************************************************************/ void -DrawMenu (char items[][50], char *title, int maxitems, int selected, int fontsize, int x) +DrawMenu (char items[][50], const char *title, int maxitems, int selected, int fontsize, int x) { int i, w = 0; int ypos = 0; @@ -513,7 +513,7 @@ int FindMenuItem(char items[][50], int maxitems, int currentItem, int direction) int menu = 0; int -RunMenu (char items[][50], int maxitems, char *title, int fontsize, int x) +RunMenu (char items[][50], int maxitems, const char *title, int fontsize, int x) { int redraw = 1; int quit = 0; @@ -606,7 +606,7 @@ ShowFiles (FILEENTRIES filelist[], int maxfiles, int offset, int selection) clearscreen (); setfontsize (26); - DrawText (-1, 150, (char*)"Choose Game"); + DrawText (-1, 150, "Choose Game"); setfontsize(18); @@ -667,7 +667,7 @@ ShowCheats (char items[][50], char itemvalues[][50], int maxitems, int offset, i clearscreen (); setfontsize (26); - DrawText (-1, 150, (char*)"Cheats"); + DrawText (-1, 150, "Cheats"); setfontsize(18); @@ -794,7 +794,7 @@ DrawLine (int x1, int y1, int x2, int y2, u8 r, u8 g, u8 b) * Show the user what's happening ***************************************************************************/ void -ShowProgress (char *msg, int done, int total) +ShowProgress (const char *msg, int done, int total) { if(total <= 0) // division by 0 is bad! return; diff --git a/source/ngc/menudraw.h b/source/ngc/menudraw.h index 1d6b73d..8c89b09 100644 --- a/source/ngc/menudraw.h +++ b/source/ngc/menudraw.h @@ -24,20 +24,19 @@ int FT_Init (); void setfontsize (int pixelsize); void setfontcolour (u8 r, u8 g, u8 b); -void DrawText (int x, int y, char *text); void unpackbackdrop (); void Credits (); void RomInfo (); void WaitButtonA (); -int RunMenu (char items[][50], int maxitems, char *title, int fontsize = 20, int x = -1); -void DrawMenu (char items[][50], char *title, int maxitems, int selected, int fontsize = 20, int x = -1); +int RunMenu (char items[][50], int maxitems, const char *title, int fontsize = 20, int x = -1); +void DrawMenu (char items[][50], const char *title, int maxitems, int selected, int fontsize = 20, int x = -1); void ShowCheats (char items[][50], char itemvalues[][50], int maxitems, int offset, int selection); void ShowFiles (FILEENTRIES filelist[], int maxfiles, int offset, int selection); -void WaitPrompt (char *msg); -int WaitPromptChoice (char *msg, char* bmsg, char* amsg); -void ShowAction (char *msg); -void ShowProgress (char *msg, int done, int total); +void WaitPrompt (const char *msg); +int WaitPromptChoice (const char *msg, const char* bmsg, const char* amsg); +void ShowAction (const char *msg); +void ShowProgress (const char *msg, int done, int total); void DrawPolygon (int vertices, int *varray, u8 r, u8 g, u8 b); void DrawLineFast( int startx, int endx, int y, u8 r, u8 g, u8 b ); diff --git a/source/ngc/preferences.cpp b/source/ngc/preferences.cpp index 5b5a8fe..09a2598 100644 --- a/source/ngc/preferences.cpp +++ b/source/ngc/preferences.cpp @@ -323,7 +323,7 @@ SavePrefs (int method, bool silent) return false; if (!silent) - ShowAction ((char*) "Saving preferences..."); + ShowAction ("Saving preferences..."); AllocSaveBuffer (); datasize = preparePrefsData (method); @@ -335,7 +335,7 @@ SavePrefs (int method, bool silent) if (offset > 0) { if (!silent) - WaitPrompt ((char *)"Preferences saved"); + WaitPrompt ("Preferences saved"); return true; } return false; @@ -372,17 +372,17 @@ LoadPrefsFromMethod (int method) ***************************************************************************/ bool LoadPrefs() { - ShowAction ((char*) "Loading preferences..."); + ShowAction ("Loading preferences..."); bool prefFound = false; - if(ChangeFATInterface(METHOD_SD, SILENT)) + if(ChangeInterface(METHOD_SD, SILENT)) prefFound = LoadPrefsFromMethod(METHOD_SD); - if(!prefFound && ChangeFATInterface(METHOD_USB, SILENT)) + if(!prefFound && ChangeInterface(METHOD_USB, SILENT)) prefFound = LoadPrefsFromMethod(METHOD_USB); if(!prefFound && TestCard(CARD_SLOTA, SILENT)) prefFound = LoadPrefsFromMethod(METHOD_MC_SLOTA); if(!prefFound && TestCard(CARD_SLOTB, SILENT)) prefFound = LoadPrefsFromMethod(METHOD_MC_SLOTB); - if(!prefFound && ConnectShare (SILENT)) + if(!prefFound && ChangeInterface(METHOD_SMB, SILENT)) prefFound = LoadPrefsFromMethod(METHOD_SMB); return prefFound; diff --git a/source/ngc/smbop.cpp b/source/ngc/smbop.cpp index a8f88f1..1521078 100644 --- a/source/ngc/smbop.cpp +++ b/source/ngc/smbop.cpp @@ -19,7 +19,7 @@ #include #include "vba.h" -#include "smbop.h" +#include "fileop.h" #include "gcunzip.h" #include "video.h" #include "menudraw.h" @@ -27,23 +27,21 @@ bool networkInit = false; bool networkShareInit = false; -unsigned int SMBTimer = 0; -#define SMBTIMEOUT ( 3600 ) // Some implementations timeout in 10 minutes - -// SMB connection/file handles - the only ones we should ever use! -SMBCONN smbconn; -SMBFILE smbfile; - -#define ZIPCHUNK 16384 +bool networkInitHalt = false; /**************************************************************************** * InitializeNetwork * Initializes the Wii/GameCube network interface ****************************************************************************/ -bool InitializeNetwork(bool silent) +void InitializeNetwork(bool silent) { - ShowAction ((char*) "Initializing network..."); + if(networkInit || networkInitHalt) + return; + + if(!silent) + ShowAction ("Initializing network..."); + s32 result; while ((result = net_init()) == -EAGAIN); @@ -54,19 +52,28 @@ bool InitializeNetwork(bool silent) if (if_config(myIP, NULL, NULL, true) < 0) { + networkInitHalt = true; // do not attempt a reconnection again + if(!silent) - WaitPrompt((char*) "Error reading IP address."); - return false; + WaitPrompt("Error reading IP address."); } else { - return true; + networkInit = true; } } + else + { + if(!silent) + WaitPrompt("Unable to initialize network."); + } +} - if(!silent) - WaitPrompt((char*) "Unable to initialize network."); - return false; +void CloseShare() +{ + if(networkShareInit) + smbClose(); + networkShareInit = false; } /**************************************************************************** @@ -88,266 +95,33 @@ ConnectShare (bool silent) strlen(GCSettings.smbip) == 0) { if(!silent) - WaitPrompt((char*) "Invalid network settings. Check settings.xml."); + WaitPrompt("Invalid network settings. Check settings.xml."); return false; } if(!networkInit) - networkInit = InitializeNetwork(silent); + InitializeNetwork(silent); if(networkInit) { - // connection may have expired - if (networkShareInit && SMBTimer > SMBTIMEOUT) - { - networkShareInit = false; - SMBTimer = 0; - SMB_Close(smbconn); - } + if(unmountRequired[METHOD_SMB]) + CloseShare(); if(!networkShareInit) { if(!silent) - ShowAction ((char*) "Connecting to network share..."); + ShowAction ("Connecting to network share..."); - if(SMB_Connect(&smbconn, GCSettings.smbuser, GCSettings.smbpwd, - GCSettings.smbgcid, GCSettings.smbsvid, GCSettings.smbshare, GCSettings.smbip) == SMB_SUCCESS) + if(smbInit(GCSettings.smbuser, GCSettings.smbpwd, + GCSettings.smbshare, GCSettings.smbip)) + { networkShareInit = true; + } } if(!networkShareInit && !silent) - WaitPrompt ((char*) "Failed to connect to network share."); + WaitPrompt ("Failed to connect to network share."); } return networkShareInit; } - -/**************************************************************************** - * SMBPath - * - * Returns a SMB-style path - *****************************************************************************/ - -char * SMBPath(char * path) -{ - // fix path - replace all '/' with '\' - for(uint i=0; i < strlen(path); i++) - if(path[i] == '/') - path[i] = '\\'; - - return path; -} - -/**************************************************************************** - * parseSMBDirectory - * - * Load the directory and put in the filelist array - *****************************************************************************/ -int -ParseSMBdirectory (bool silent) -{ - if(!ConnectShare (NOTSILENT)) - return 0; - - int filecount = 0; - char searchpath[1024]; - char tmpname[MAXJOLIET]; - SMBDIRENTRY smbdir; - - // initialize selection - selection = offset = 0; - - // Clear any existing values - memset (&filelist, 0, sizeof (FILEENTRIES) * MAXFILES); - - if(strlen(currentdir) <= 1) // root - sprintf(searchpath, "*"); - else - sprintf(searchpath, "%s/*", currentdir); - - if (SMB_FindFirst - (SMBPath(searchpath), SMB_SRCH_READONLY | SMB_SRCH_DIRECTORY, &smbdir, smbconn) != SMB_SUCCESS) - { - if(!silent) - { - char msg[200]; - sprintf(msg, "Could not open %s", currentdir); - WaitPrompt (msg); - } - - // if we can't open the dir, open root dir - sprintf(searchpath, "/"); - sprintf(searchpath,"*"); - sprintf(currentdir,"/"); - - if (SMB_FindFirst - (SMBPath(searchpath), SMB_SRCH_READONLY | SMB_SRCH_DIRECTORY, &smbdir, smbconn) != SMB_SUCCESS) - return 0; - } - - // index files/folders - do - { - if(strcmp(smbdir.name,".") != 0 && - !(strlen(currentdir) <= 1 && strcmp(smbdir.name,"..") == 0)) - { - memset (&filelist[filecount], 0, sizeof (FILEENTRIES)); - filelist[filecount].length = smbdir.size_low; - smbdir.name[MAXJOLIET] = 0; - - if(smbdir.attributes == SMB_SRCH_DIRECTORY) - filelist[filecount].flags = 1; // flag this as a dir - else - filelist[filecount].flags = 0; - - StripExt(tmpname, smbdir.name); // hide file extension - memcpy (&filelist[filecount].displayname, tmpname, MAXDISPLAY); - filelist[filecount].displayname[MAXDISPLAY] = 0; - - strcpy (filelist[filecount].filename, smbdir.name); - filecount++; - } - } while (SMB_FindNext (&smbdir, smbconn) == SMB_SUCCESS); - - // close directory - SMB_FindClose (smbconn); - - // Sort the file list - qsort(filelist, filecount, sizeof(FILEENTRIES), FileSortCallback); - - return filecount; -} - -/**************************************************************************** - * Open SMB file - ***************************************************************************/ - -SMBFILE OpenSMBFile(char * filepath) -{ - return SMB_OpenFile (SMBPath(filepath), SMB_OPEN_READING, SMB_OF_OPEN, smbconn); -} - -/**************************************************************************** - * LoadSMBSzFile - * Loads the selected file # from the specified 7z into rbuffer - * Returns file size - ***************************************************************************/ -int -LoadSMBSzFile(char * filepath, unsigned char * rbuffer) -{ - if(!ConnectShare (NOTSILENT)) - return 0; - - smbfile = OpenSMBFile(filepath); - - if (smbfile) - { - u32 size = SzExtractFile(filelist[selection].offset, rbuffer); - SMB_CloseFile (smbfile); - return size; - } - else - { - WaitPrompt((char*) "Error opening file"); - return 0; - } -} - -/**************************************************************************** - * SaveSMBFile - * Write buffer to SMB file - ****************************************************************************/ - -int -SaveSMBFile (char * sbuffer, char *filepath, int datasize, bool silent) -{ - if(!ConnectShare (NOTSILENT)) - return 0; - - int dsize = datasize; - int wrote = 0; - int boffset = 0; - - smbfile = - SMB_OpenFile (SMBPath(filepath), SMB_OPEN_WRITING | SMB_DENY_NONE, - SMB_OF_CREATE | SMB_OF_TRUNCATE, smbconn); - - if (smbfile) - { - while (dsize > 0) - { - if (dsize > 1024) - wrote = - SMB_WriteFile ((char *) sbuffer + boffset, 1024, boffset, smbfile); - else - wrote = - SMB_WriteFile ((char *) sbuffer + boffset, dsize, boffset, smbfile); - - boffset += wrote; - dsize -= wrote; - } - SMB_CloseFile (smbfile); - } - else - { - char msg[100]; - sprintf(msg, "Couldn't save SMB: %s", SMBPath(filepath)); - WaitPrompt (msg); - } - - return boffset; -} - -/**************************************************************************** - * LoadSMBFile - * Load up a buffer from SMB file - ****************************************************************************/ - -int -LoadSMBFile (char * sbuffer, char *filepath, int length, bool silent) -{ - if(!ConnectShare (NOTSILENT)) - return 0; - - int ret; - int boffset = 0; - - smbfile = OpenSMBFile(filepath); - - if (!smbfile) - { - if(!silent) - { - char msg[100]; - sprintf(msg, "Couldn't open SMB: %s", SMBPath(filepath)); - WaitPrompt (msg); - } - return 0; - } - - if(length > 0 && length <= 2048) // do a partial read (eg: to check file header) - { - boffset = SMB_ReadFile (sbuffer, length, 0, smbfile); - } - else // load whole file - { - ret = SMB_ReadFile (sbuffer, 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; - ShowProgress ((char *)"Loading...", boffset, length); - } - } - } - SMB_CloseFile (smbfile); - - return boffset; -} diff --git a/source/ngc/smbop.h b/source/ngc/smbop.h index 3c441d6..ae7eace 100644 --- a/source/ngc/smbop.h +++ b/source/ngc/smbop.h @@ -9,21 +9,10 @@ ****************************************************************************/ #ifndef _NGCSMB_ - #define _NGCSMB_ -#include - -bool InitializeNetwork(bool silent); +void InitializeNetwork(bool silent); bool ConnectShare (bool silent); -char * SMBPath(char * path); -int UpdateSMBdirname(); -int ParseSMBdirectory (bool silent); -SMBFILE OpenSMBFile(char * filepath); -int LoadSMBSzFile(char * filepath, unsigned char * rbuffer); -int LoadSMBFile (char * sbuffer, char *filepath, int length, bool silent); -int SaveSMBFile (char * sbuffer, char *filepath, int length, bool silent); - -extern SMBFILE smbfile; +void CloseShare(); #endif diff --git a/source/ngc/vba.cpp b/source/ngc/vba.cpp index 68d54b1..90ff35d 100644 --- a/source/ngc/vba.cpp +++ b/source/ngc/vba.cpp @@ -12,14 +12,9 @@ #include #include #include - #include #include #include -#include -#include -#include -#include #ifdef WII_DVD extern "C" { @@ -32,6 +27,7 @@ extern "C" { #include "preferences.h" #include "audio.h" #include "dvd.h" +#include "smbop.h" #include "fileop.h" #include "menu.h" #include "menudraw.h" @@ -50,6 +46,16 @@ char appPath[1024]; * Shutdown / Reboot / Exit ***************************************************************************/ +void ExitCleanup() +{ + UnmountAllFAT(); + CloseShare(); + +#ifdef HW_RVL + DI_Close(); +#endif +} + #ifdef HW_DOL #define PSOSDLOADID 0x7c6000a6 int *psoid = (int *) 0x80001800; @@ -58,9 +64,8 @@ char appPath[1024]; void Reboot() { - UnmountAllFAT(); + ExitCleanup(); #ifdef HW_RVL - DI_Close(); SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); #else #define SOFTRESET_ADR ((volatile u32*)0xCC003024) @@ -70,14 +75,13 @@ void Reboot() void ExitToLoader() { - UnmountAllFAT(); + ExitCleanup(); // Exit to Loader #ifdef HW_RVL - DI_Close(); exit(0); #else // gamecube if (psoid[0] == PSOSDLOADID) - PSOReload (); + PSOReload(); #endif } @@ -93,8 +97,7 @@ void ResetCB() } void ShutdownWii() { - UnmountAllFAT(); - DI_Close(); + ExitCleanup(); SYS_ResetSystem(SYS_POWEROFF, 0, 0); } #endif @@ -193,7 +196,8 @@ int main(int argc, char *argv[]) } // Initialize libFAT for SD and USB - fatInit (8, false); + MountAllFAT(); + InitDeviceThread(); // Initialize DVD subsystem (GameCube only) #ifdef HW_DOL @@ -218,7 +222,7 @@ int main(int argc, char *argv[]) // Load preferences if(!LoadPrefs()) { - WaitPrompt((char*) "Preferences reset - check settings!"); + WaitPrompt("Preferences reset - check settings!"); selectedMenu = 2; // change to preferences menu } diff --git a/source/ngc/vba.h b/source/ngc/vba.h index 461607c..130ddd3 100644 --- a/source/ngc/vba.h +++ b/source/ngc/vba.h @@ -7,8 +7,8 @@ * * This file controls overall program flow. Most things start and end here! ***************************************************************************/ -#ifndef _VBA_H_ -#define _VBA_H_ +#ifndef _VBAGX_H_ +#define _VBAGX_H_ #include #define VERSIONNUM "1.0.5" @@ -26,7 +26,9 @@ enum { METHOD_DVD, METHOD_SMB, METHOD_MC_SLOTA, - METHOD_MC_SLOTB + METHOD_MC_SLOTB, + METHOD_SD_SLOTA, + METHOD_SD_SLOTB }; enum { @@ -45,15 +47,12 @@ struct SGCSettings{ char LoadFolder[200]; // Path to game files char SaveFolder[200]; // Path to save files char CheatFolder[200]; // Path to cheat files - char gcip[16]; - char gwip[16]; - char mask[16]; + char smbip[16]; char smbuser[20]; char smbpwd[20]; - char smbgcid[20]; - char smbsvid[20]; char smbshare[20]; + int Zoom; // 0 - off, 1 - on float ZoomLevel; // zoom amount int widescreen; diff --git a/source/ngc/vbaconfig.cpp b/source/ngc/vbaconfig.cpp index d5fa628..b1a7fc9 100644 --- a/source/ngc/vbaconfig.cpp +++ b/source/ngc/vbaconfig.cpp @@ -12,7 +12,6 @@ #include #include #include "vba.h" -#include "smbop.h" struct SGCSettings GCSettings; @@ -39,12 +38,6 @@ DefaultSettings () GCSettings.smbpwd[19] = 0; GCSettings.smbshare[19] = 0; - GCSettings.gcip[0] = 0; - GCSettings.gwip[0] = 0; - GCSettings.mask[0] = 0; - GCSettings.smbsvid[0] = 0; - GCSettings.smbgcid[0] = 0; - GCSettings.VerifySaves = 0; GCSettings.Zoom = 0; // zooming default off GCSettings.ZoomLevel = 1.0; // zoom level diff --git a/source/ngc/vbasupport.cpp b/source/ngc/vbasupport.cpp index a7972af..6957abe 100644 --- a/source/ngc/vbasupport.cpp +++ b/source/ngc/vbasupport.cpp @@ -266,7 +266,7 @@ bool LoadBatteryOrState(int method, int action, bool silent) if(!MakeFilePath(filepath, action, method)) return false; - ShowAction ((char*) "Loading..."); + ShowAction ("Loading..."); AllocSaveBuffer(); @@ -305,16 +305,16 @@ bool LoadBatteryOrState(int method, int action, bool silent) if(offset == 0) { if(action == FILE_SRAM) - WaitPrompt ((char*) "Save file not found"); + WaitPrompt ("Save file not found"); else - WaitPrompt ((char*) "State file not found"); + WaitPrompt ("State file not found"); } else { if(action == FILE_SRAM) - WaitPrompt ((char*) "Invalid save file"); + WaitPrompt ("Invalid save file"); else - WaitPrompt ((char*) "Invalid state file"); + WaitPrompt ("Invalid state file"); } } return result; @@ -341,7 +341,7 @@ bool SaveBatteryOrState(int method, int action, bool silent) if(!MakeFilePath(filepath, action, method)) return false; - ShowAction ((char*) "Saving..."); + ShowAction ("Saving..."); AllocSaveBuffer(); @@ -425,14 +425,14 @@ bool SaveBatteryOrState(int method, int action, bool silent) if(offset > 0) { if(!silent) - WaitPrompt ((char*) "Save successful"); + WaitPrompt ("Save successful"); result = true; } } else { if(!silent) - WaitPrompt((char *)"No data to save!"); + WaitPrompt("No data to save!"); } FreeSaveBuffer(); @@ -498,8 +498,8 @@ int systemGetSensorY() void systemUpdateMotionSensor() { - int chan = 0; // first wiimote -/* + /* int chan = 0; // first wiimote + WPADData *Data = WPAD_Data(chan); WPADData data = *Data; @@ -631,7 +631,7 @@ void LoadPatch(int method) int patchsize = 0; int patchtype; - ShowAction((char *)"Loading patch..."); + ShowAction("Loading patch..."); AllocSaveBuffer (); @@ -703,14 +703,12 @@ bool LoadGBROM(int method) { case METHOD_SD: case METHOD_USB: - gbRomSize = LoadFATSzFile(szpath, (unsigned char *)gbRom); + case METHOD_SMB: + gbRomSize = LoadSzFile(szpath, (unsigned char *)gbRom); break; case METHOD_DVD: gbRomSize = SzExtractFile(filelist[selection].offset, (unsigned char *)gbRom); break; - case METHOD_SMB: - gbRomSize = LoadSMBSzFile(szpath, (unsigned char *)gbRom); - break; } } @@ -735,19 +733,23 @@ bool LoadVBAROM(int method) // we need to check the file extension of the first file in the archive char * zippedFilename = GetFirstZipFilename (method); - if(strlen(zippedFilename) > 0) + if(zippedFilename != NULL) { if(utilIsGBAImage(zippedFilename)) type = 2; else if(utilIsGBImage(zippedFilename)) type = 1; } + else // loading the file failed + { + return false; + } } // leave before we do anything if(type != 1 && type != 2) { - WaitPrompt((char *)"Unknown game image!"); + WaitPrompt("Unknown game image!"); return false; } @@ -813,7 +815,7 @@ bool LoadVBAROM(int method) if(!loaded) { - WaitPrompt((char *)"Error loading game!"); + WaitPrompt("Error loading game!"); return false; } else diff --git a/source/ngc/video.cpp b/source/ngc/video.cpp index 3da261a..9da677b 100644 --- a/source/ngc/video.cpp +++ b/source/ngc/video.cpp @@ -21,7 +21,6 @@ #include "vba.h" #include "menudraw.h" -extern unsigned int SMBTimer; // timer to reset SMB connection u32 FrameTimer = 0; /*** External 2D Video ***/ @@ -137,7 +136,6 @@ copy_to_xfb (u32 arg) } FrameTimer++; - SMBTimer++; } /**************************************************************************** diff --git a/source/ngc/vmmem.cpp b/source/ngc/vmmem.cpp index 095a713..79c2b69 100644 --- a/source/ngc/vmmem.cpp +++ b/source/ngc/vmmem.cpp @@ -154,7 +154,7 @@ static void VMAllocGBA( void ) paletteRAM == NULL || vram == NULL || oam == NULL || pix == NULL || ioMem == NULL) { - WaitPrompt((char *)"Out of memory!"); + WaitPrompt("Out of memory!"); VMClose(); } } @@ -188,14 +188,12 @@ bool VMCPULoadROM(int method) { case METHOD_SD: case METHOD_USB: - GBAROMSize = LoadFATSzFile(szpath, (unsigned char *)rom); + case METHOD_SMB: + GBAROMSize = LoadSzFile(szpath, (unsigned char *)rom); break; case METHOD_DVD: GBAROMSize = SzExtractFile(filelist[selection].offset, (unsigned char *)rom); break; - case METHOD_SMB: - GBAROMSize = LoadSMBSzFile(szpath, (unsigned char *)rom); - break; } } @@ -319,14 +317,14 @@ int VMCPULoadROM(int method) sprintf(filepath, "%s/%s",currentdir,filelist[selection].filename); else { - WaitPrompt((char*) "Maximum filepath length reached!"); + WaitPrompt("Maximum filepath length reached!"); return -1; } romfile = fopen(filepath, "rb"); if ( romfile == NULL ) { - WaitPrompt((char*) "Error opening file!"); + WaitPrompt("Error opening file!"); VMClose(); return 0; } @@ -340,9 +338,10 @@ int VMCPULoadROM(int method) return 0; } - fseek(romfile, 0, SEEK_END); - GBAROMSize = ftell(romfile); - fseek(romfile, 0, SEEK_SET); + struct stat fileinfo; + fstat(romfile->_file, &fileinfo); + GBAROMSize = fileinfo.st_size; + vmpageno = 0; vmpage[0].pageptr = rombase; vmpage[0].pageno = 0; @@ -454,7 +453,7 @@ u16 VMRead16( u32 address ) return READ16LE( vmpage[pageid].pageptr + ( address & VMSHIFTMASK ) ); default: - WaitPrompt((char*) "VM16 : Unknown page type!"); + WaitPrompt("VM16 : Unknown page type!"); VMClose(); return 0; } @@ -485,7 +484,7 @@ u8 VMRead8( u32 address ) return (u8)vmpage[pageid].pageptr[ (address & VMSHIFTMASK) ]; default: - WaitPrompt((char*) "VM8 : Unknown page type!"); + WaitPrompt("VM8 : Unknown page type!"); VMClose(); return 0; } diff --git a/source/sz/7zTypes.h b/source/sz/7zTypes.h index fa4c5c3..e6f2576 100644 --- a/source/sz/7zTypes.h +++ b/source/sz/7zTypes.h @@ -61,10 +61,11 @@ typedef UInt32 CFileSize; #define SZE_NOTIMPL (4) #define SZE_FAIL (5) +#define SZE_FAILREAD (6) -#define SZE_ARCHIVE_ERROR (6) +#define SZE_ARCHIVE_ERROR (7) -#define SZE_OUTOFMEMORYDIC (7) +#define SZE_OUTOFMEMORYDIC (8) #define RINOK(x) { int __result_ = (x); if(__result_ != 0) return __result_; }