2008-12-24 09:02:04 +01:00
|
|
|
/****************************************************************************
|
2010-01-27 23:20:37 +01:00
|
|
|
* Snes9x Nintendo Wii/Gamecube Port
|
2008-12-24 09:02:04 +01:00
|
|
|
*
|
2010-01-27 23:20:37 +01:00
|
|
|
* Tantric 2008-2010
|
2008-12-24 09:02:04 +01:00
|
|
|
*
|
|
|
|
* networkop.cpp
|
|
|
|
*
|
|
|
|
* Network and SMB support routines
|
|
|
|
****************************************************************************/
|
|
|
|
|
2009-10-02 05:09:36 +02:00
|
|
|
#ifdef HW_DOL
|
|
|
|
|
|
|
|
bool
|
|
|
|
ConnectShare (bool silent)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
2009-03-11 18:28:37 +01:00
|
|
|
|
2008-12-24 09:02:04 +01:00
|
|
|
#include <network.h>
|
|
|
|
#include <smb.h>
|
|
|
|
#include <mxml.h>
|
2009-10-06 08:37:53 +02:00
|
|
|
#include <malloc.h>
|
2008-12-24 09:02:04 +01:00
|
|
|
|
2010-03-22 00:43:54 +01:00
|
|
|
#include "snes9xgx.h"
|
2009-03-11 18:28:37 +01:00
|
|
|
#include "menu.h"
|
2008-12-24 09:02:04 +01:00
|
|
|
#include "fileop.h"
|
2009-06-12 09:47:42 +02:00
|
|
|
#include "filebrowser.h"
|
2010-03-22 00:43:54 +01:00
|
|
|
#include "utils/http.h"
|
|
|
|
#include "utils/unzip/unzip.h"
|
|
|
|
#include "utils/unzip/miniunz.h"
|
2008-12-24 09:02:04 +01:00
|
|
|
|
2009-06-22 22:04:43 +02:00
|
|
|
bool inNetworkInit = false;
|
2008-12-30 01:08:17 +01:00
|
|
|
static bool networkInit = false;
|
|
|
|
static bool autoNetworkInit = true;
|
|
|
|
static bool networkShareInit = false;
|
|
|
|
static bool updateChecked = false; // true if checked for app update
|
2008-12-24 09:02:04 +01:00
|
|
|
static char updateURL[128]; // URL of app update
|
|
|
|
bool updateFound = false; // true if an app update was found
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* UpdateCheck
|
|
|
|
* Checks for an update for the application
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
void UpdateCheck()
|
|
|
|
{
|
|
|
|
// we can only check for the update if we have internet + SD
|
2009-12-23 01:38:11 +01:00
|
|
|
if(!updateChecked && networkInit && (isMounted[DEVICE_SD] || isMounted[DEVICE_USB]))
|
2008-12-24 09:02:04 +01:00
|
|
|
{
|
|
|
|
static char url[128];
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
updateChecked = true;
|
|
|
|
|
|
|
|
snprintf(url, 128, "http://snes9x-gx.googlecode.com/svn/trunk/update.xml");
|
|
|
|
|
2009-03-31 09:16:28 +02:00
|
|
|
u8 * tmpbuffer = (u8 *)memalign(32,32768);
|
2009-01-05 23:23:41 +01:00
|
|
|
memset(tmpbuffer, 0, 32768);
|
|
|
|
retval = http_request(url, NULL, tmpbuffer, 32768);
|
2008-12-24 09:02:04 +01:00
|
|
|
memset(url, 0, 128);
|
|
|
|
|
|
|
|
if (retval)
|
|
|
|
{
|
|
|
|
mxml_node_t *xml;
|
|
|
|
mxml_node_t *item;
|
|
|
|
|
2009-01-05 23:23:41 +01:00
|
|
|
xml = mxmlLoadString(NULL, (char *)tmpbuffer, MXML_TEXT_CALLBACK);
|
2008-12-24 09:02:04 +01:00
|
|
|
|
2009-01-05 23:23:41 +01:00
|
|
|
if(xml)
|
2008-12-24 09:02:04 +01:00
|
|
|
{
|
2009-01-05 23:23:41 +01:00
|
|
|
// check settings version
|
|
|
|
item = mxmlFindElement(xml, xml, "app", "version", NULL, MXML_DESCEND);
|
|
|
|
if(item) // a version entry exists
|
2008-12-24 09:02:04 +01:00
|
|
|
{
|
2009-03-28 20:03:35 +01:00
|
|
|
const char * version = mxmlElementGetAttr(item, "version");
|
2009-01-05 23:23:41 +01:00
|
|
|
|
2009-03-28 20:03:35 +01:00
|
|
|
if(version && strlen(version) == 5)
|
2008-12-24 09:02:04 +01:00
|
|
|
{
|
2009-03-28 20:03:35 +01:00
|
|
|
int verMajor = version[0] - '0';
|
|
|
|
int verMinor = version[2] - '0';
|
|
|
|
int verPoint = version[4] - '0';
|
|
|
|
int curMajor = APPVERSION[0] - '0';
|
|
|
|
int curMinor = APPVERSION[2] - '0';
|
|
|
|
int curPoint = APPVERSION[4] - '0';
|
|
|
|
|
|
|
|
// check that the versioning is valid and is a newer version
|
|
|
|
if((verMajor >= 0 && verMajor <= 9 &&
|
|
|
|
verMinor >= 0 && verMinor <= 9 &&
|
|
|
|
verPoint >= 0 && verPoint <= 9) &&
|
|
|
|
(verMajor > curMajor ||
|
2009-04-01 07:47:01 +02:00
|
|
|
(verMajor == curMajor && verMinor > curMinor) ||
|
|
|
|
(verMajor == curMajor && verMinor == curMinor && verPoint > curPoint)))
|
2009-03-28 20:03:35 +01:00
|
|
|
{
|
|
|
|
item = mxmlFindElement(xml, xml, "file", NULL, NULL, MXML_DESCEND);
|
|
|
|
if(item)
|
|
|
|
{
|
|
|
|
const char * tmp = mxmlElementGetAttr(item, "url");
|
|
|
|
if(tmp)
|
|
|
|
{
|
|
|
|
snprintf(updateURL, 128, "%s", tmp);
|
|
|
|
updateFound = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-24 09:02:04 +01:00
|
|
|
}
|
2009-01-05 23:23:41 +01:00
|
|
|
mxmlDelete(xml);
|
2008-12-24 09:02:04 +01:00
|
|
|
}
|
|
|
|
}
|
2009-01-05 23:23:41 +01:00
|
|
|
free(tmpbuffer);
|
2008-12-24 09:02:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-30 01:08:17 +01:00
|
|
|
static bool unzipArchive(char * zipfilepath, char * unzipfolderpath)
|
2008-12-24 09:02:04 +01:00
|
|
|
{
|
|
|
|
unzFile uf = unzOpen(zipfilepath);
|
|
|
|
if (uf==NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(chdir(unzipfolderpath)) // can't access dir
|
|
|
|
{
|
|
|
|
makedir(unzipfolderpath); // attempt to make dir
|
|
|
|
if(chdir(unzipfolderpath)) // still can't access dir
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
extractZip(uf,0,1,0);
|
|
|
|
|
|
|
|
unzCloseCurrentFile(uf);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DownloadUpdate()
|
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
|
2009-12-23 01:38:11 +01:00
|
|
|
if(strlen(updateURL) == 0 || strlen(appPath) == 0)
|
|
|
|
goto done;
|
2008-12-24 09:02:04 +01:00
|
|
|
|
2009-12-23 01:38:11 +01:00
|
|
|
if(!ChangeInterface(appPath, NOTSILENT))
|
|
|
|
goto done;
|
2009-01-25 08:09:37 +01:00
|
|
|
|
2009-12-23 01:38:11 +01:00
|
|
|
// stop checking if devices were removed/inserted
|
|
|
|
// since we're saving a file
|
|
|
|
HaltDeviceThread();
|
2008-12-24 09:02:04 +01:00
|
|
|
|
2009-12-23 01:38:11 +01:00
|
|
|
int device;
|
|
|
|
FindDevice(appPath, &device);
|
2008-12-24 09:02:04 +01:00
|
|
|
|
2009-12-23 01:38:11 +01:00
|
|
|
FILE * hfile;
|
|
|
|
char updateFile[50];
|
|
|
|
sprintf(updateFile, "%s%s Update.zip", pathPrefix[device], APPNAME);
|
|
|
|
hfile = fopen (updateFile, "wb");
|
2008-12-24 09:02:04 +01:00
|
|
|
|
2009-12-23 01:38:11 +01:00
|
|
|
if (hfile > 0)
|
|
|
|
{
|
|
|
|
int retval;
|
2010-03-31 04:50:05 +02:00
|
|
|
retval = http_request(updateURL, hfile, NULL, (1024*1024*10));
|
2009-12-23 01:38:11 +01:00
|
|
|
fclose (hfile);
|
2008-12-24 09:02:04 +01:00
|
|
|
}
|
2009-12-23 01:38:11 +01:00
|
|
|
|
|
|
|
result = unzipArchive(updateFile, (char *)pathPrefix[device]);
|
|
|
|
remove(updateFile); // delete update file
|
|
|
|
|
|
|
|
// go back to checking if devices were inserted/removed
|
|
|
|
ResumeDeviceThread();
|
|
|
|
|
|
|
|
done:
|
|
|
|
if(result)
|
|
|
|
InfoPrompt("Update successful!");
|
|
|
|
else
|
|
|
|
ErrorPrompt("Update failed!");
|
|
|
|
|
|
|
|
updateFound = false; // updating is finished (successful or not!)
|
2008-12-24 09:02:04 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* InitializeNetwork
|
|
|
|
* Initializes the Wii/GameCube network interface
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
void InitializeNetwork(bool silent)
|
|
|
|
{
|
|
|
|
// stop if we're already initialized, or if auto-init has failed before
|
|
|
|
// in which case, manual initialization is required
|
2009-10-06 08:37:53 +02:00
|
|
|
if(networkInit || (silent && !autoNetworkInit))
|
2008-12-24 09:02:04 +01:00
|
|
|
return;
|
|
|
|
|
2009-10-06 08:37:53 +02:00
|
|
|
int retry = 1;
|
|
|
|
char ip[16];
|
|
|
|
s32 initResult;
|
|
|
|
|
2008-12-24 09:02:04 +01:00
|
|
|
if(!silent)
|
|
|
|
ShowAction ("Initializing network...");
|
|
|
|
|
2009-03-11 18:28:37 +01:00
|
|
|
while(inNetworkInit) // a network init is already in progress!
|
|
|
|
usleep(50);
|
|
|
|
|
2009-05-30 20:26:45 +02:00
|
|
|
if(!networkInit) // check again if the network was inited
|
2008-12-24 09:02:04 +01:00
|
|
|
{
|
2009-05-30 20:26:45 +02:00
|
|
|
inNetworkInit = true;
|
2008-12-24 09:02:04 +01:00
|
|
|
|
2009-10-06 08:37:53 +02:00
|
|
|
while(retry)
|
2009-05-30 20:26:45 +02:00
|
|
|
{
|
|
|
|
if(!silent)
|
2009-10-06 08:37:53 +02:00
|
|
|
ShowAction ("Initializing network...");
|
|
|
|
|
|
|
|
initResult = if_config(ip, NULL, NULL, true);
|
|
|
|
|
|
|
|
if(initResult == 0)
|
|
|
|
networkInit = true;
|
|
|
|
|
|
|
|
if(networkInit || silent)
|
|
|
|
break;
|
|
|
|
|
2010-03-18 00:20:08 +01:00
|
|
|
retry = ErrorPromptRetry("Unable to initialize network!");
|
2008-12-24 09:02:04 +01:00
|
|
|
}
|
2009-10-06 08:37:53 +02:00
|
|
|
|
|
|
|
// do not automatically attempt a reconnection
|
|
|
|
autoNetworkInit = false;
|
2009-05-30 20:26:45 +02:00
|
|
|
inNetworkInit = false;
|
2008-12-24 09:02:04 +01:00
|
|
|
}
|
2009-05-30 20:26:45 +02:00
|
|
|
if(!silent)
|
|
|
|
CancelAction();
|
2008-12-24 09:02:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CloseShare()
|
|
|
|
{
|
|
|
|
if(networkShareInit)
|
2009-03-12 08:07:52 +01:00
|
|
|
smbClose("smb");
|
2008-12-24 09:02:04 +01:00
|
|
|
networkShareInit = false;
|
2010-03-15 08:41:40 +01:00
|
|
|
isMounted[DEVICE_SMB] = false;
|
2008-12-24 09:02:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Mount SMB Share
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
bool
|
|
|
|
ConnectShare (bool silent)
|
|
|
|
{
|
|
|
|
// Crashes or stalls system in GameCube mode - so disable
|
|
|
|
#ifndef HW_RVL
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
|
2010-06-19 19:21:01 +02:00
|
|
|
if(networkShareInit)
|
|
|
|
return true;
|
|
|
|
|
2009-10-06 08:37:53 +02:00
|
|
|
int retry = 1;
|
2008-12-24 09:02:04 +01:00
|
|
|
int chkS = (strlen(GCSettings.smbshare) > 0) ? 0:1;
|
|
|
|
int chkI = (strlen(GCSettings.smbip) > 0) ? 0:1;
|
|
|
|
|
|
|
|
// check that all parameters have been set
|
2009-10-04 21:30:55 +02:00
|
|
|
if(chkS + chkI > 0)
|
2008-12-24 09:02:04 +01:00
|
|
|
{
|
|
|
|
if(!silent)
|
|
|
|
{
|
|
|
|
char msg[50];
|
|
|
|
char msg2[100];
|
2009-10-04 21:30:55 +02:00
|
|
|
if(chkS + chkI > 1) // more than one thing is wrong
|
2008-12-24 09:02:04 +01:00
|
|
|
sprintf(msg, "Check settings.xml.");
|
|
|
|
else if(chkS)
|
|
|
|
sprintf(msg, "Share name is blank.");
|
|
|
|
else if(chkI)
|
|
|
|
sprintf(msg, "Share IP is blank.");
|
|
|
|
|
|
|
|
sprintf(msg2, "Invalid network settings - %s", msg);
|
2009-03-11 18:28:37 +01:00
|
|
|
ErrorPrompt(msg2);
|
2008-12-24 09:02:04 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!networkInit)
|
|
|
|
InitializeNetwork(silent);
|
|
|
|
|
2009-10-06 08:37:53 +02:00
|
|
|
if(!networkInit)
|
|
|
|
return false;
|
2008-12-24 09:02:04 +01:00
|
|
|
|
2009-10-06 08:37:53 +02:00
|
|
|
while(retry)
|
|
|
|
{
|
|
|
|
if(!silent)
|
|
|
|
ShowAction ("Connecting to network share...");
|
|
|
|
|
|
|
|
if(smbInit(GCSettings.smbuser, GCSettings.smbpwd, GCSettings.smbshare, GCSettings.smbip))
|
|
|
|
networkShareInit = true;
|
2009-05-30 20:26:45 +02:00
|
|
|
|
2009-10-06 08:37:53 +02:00
|
|
|
if(networkShareInit || silent)
|
|
|
|
break;
|
2008-12-24 09:02:04 +01:00
|
|
|
|
2009-10-06 08:37:53 +02:00
|
|
|
retry = ErrorPromptRetry("Failed to connect to network share.");
|
2008-12-24 09:02:04 +01:00
|
|
|
}
|
|
|
|
|
2009-10-06 08:37:53 +02:00
|
|
|
if(!silent)
|
|
|
|
CancelAction();
|
|
|
|
|
2008-12-24 09:02:04 +01:00
|
|
|
return networkShareInit;
|
|
|
|
}
|
2009-02-08 22:59:53 +01:00
|
|
|
|
|
|
|
#endif
|