mirror of
https://github.com/dborth/snes9xgx.git
synced 2024-12-24 18:21:50 +01:00
improved network init and file code
This commit is contained in:
parent
25e659297e
commit
dbcde69fd5
@ -88,11 +88,6 @@ HaltDeviceThread()
|
|||||||
#ifdef HW_RVL
|
#ifdef HW_RVL
|
||||||
deviceHalt = true;
|
deviceHalt = true;
|
||||||
|
|
||||||
#ifdef HW_RVL
|
|
||||||
if(inNetworkInit) // don't wait for network to initialize
|
|
||||||
return;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// wait for thread to finish
|
// wait for thread to finish
|
||||||
while(!LWP_ThreadIsSuspended(devicethread))
|
while(!LWP_ThreadIsSuspended(devicethread))
|
||||||
usleep(THREAD_SLEEP);
|
usleep(THREAD_SLEEP);
|
||||||
@ -121,19 +116,11 @@ HaltParseThread()
|
|||||||
* initializes the network in the background
|
* initializes the network in the background
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
#ifdef HW_RVL
|
#ifdef HW_RVL
|
||||||
static int devsleep = 1*1000*1000;
|
static int devsleep;
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
devicecallback (void *arg)
|
devicecallback (void *arg)
|
||||||
{
|
{
|
||||||
while(devsleep > 0)
|
|
||||||
{
|
|
||||||
if(deviceHalt)
|
|
||||||
LWP_SuspendThread(devicethread);
|
|
||||||
usleep(THREAD_SLEEP);
|
|
||||||
devsleep -= THREAD_SLEEP;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if(isMounted[DEVICE_SD])
|
if(isMounted[DEVICE_SD])
|
||||||
@ -154,9 +141,6 @@ devicecallback (void *arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateCheck();
|
|
||||||
InitializeNetwork(SILENT);
|
|
||||||
|
|
||||||
if(isMounted[DEVICE_DVD])
|
if(isMounted[DEVICE_DVD])
|
||||||
{
|
{
|
||||||
if(!dvd->isInserted()) // check if the device was removed
|
if(!dvd->isInserted()) // check if the device was removed
|
||||||
@ -175,6 +159,7 @@ devicecallback (void *arg)
|
|||||||
usleep(THREAD_SLEEP);
|
usleep(THREAD_SLEEP);
|
||||||
devsleep -= THREAD_SLEEP;
|
devsleep -= THREAD_SLEEP;
|
||||||
}
|
}
|
||||||
|
UpdateCheck();
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -767,7 +752,7 @@ LoadFile (char * rbuffer, char *filepath, size_t length, bool silent)
|
|||||||
HaltParseThread();
|
HaltParseThread();
|
||||||
|
|
||||||
// open the file
|
// open the file
|
||||||
while(!size && retry)
|
while(retry)
|
||||||
{
|
{
|
||||||
if(!ChangeInterface(device, silent))
|
if(!ChangeInterface(device, silent))
|
||||||
break;
|
break;
|
||||||
@ -795,6 +780,7 @@ LoadFile (char * rbuffer, char *filepath, size_t length, bool silent)
|
|||||||
{
|
{
|
||||||
unmountRequired[device] = true;
|
unmountRequired[device] = true;
|
||||||
retry = ErrorPromptRetry("Error reading file!");
|
retry = ErrorPromptRetry("Error reading file!");
|
||||||
|
fclose (file);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -822,6 +808,7 @@ LoadFile (char * rbuffer, char *filepath, size_t length, bool silent)
|
|||||||
CancelAction();
|
CancelAction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
retry = 0;
|
||||||
fclose (file);
|
fclose (file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,9 +19,10 @@ ConnectShare (bool silent)
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
#include <network.h>
|
#include <network.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <ogc/lwp_watchdog.h>
|
||||||
#include <smb.h>
|
#include <smb.h>
|
||||||
#include <mxml.h>
|
#include <mxml.h>
|
||||||
#include <malloc.h>
|
|
||||||
|
|
||||||
#include "snes9xgx.h"
|
#include "snes9xgx.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
@ -31,10 +32,10 @@ ConnectShare (bool silent)
|
|||||||
#include "utils/unzip/unzip.h"
|
#include "utils/unzip/unzip.h"
|
||||||
#include "utils/unzip/miniunz.h"
|
#include "utils/unzip/miniunz.h"
|
||||||
|
|
||||||
bool inNetworkInit = false;
|
static int netHalt = 0;
|
||||||
static bool networkInit = false;
|
static bool networkInit = false;
|
||||||
static bool autoNetworkInit = true;
|
|
||||||
static bool networkShareInit = false;
|
static bool networkShareInit = false;
|
||||||
|
char wiiIP[16] = { 0 };
|
||||||
static bool updateChecked = false; // true if checked for app update
|
static bool updateChecked = false; // true if checked for app update
|
||||||
static char updateURL[128]; // URL of app update
|
static char updateURL[128]; // URL of app update
|
||||||
bool updateFound = false; // true if an app update was found
|
bool updateFound = false; // true if an app update was found
|
||||||
@ -179,49 +180,124 @@ bool DownloadUpdate()
|
|||||||
* Initializes the Wii/GameCube network interface
|
* Initializes the Wii/GameCube network interface
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
void InitializeNetwork(bool silent)
|
static lwp_t networkthread = LWP_THREAD_NULL;
|
||||||
|
static u8 netstack[8192] ATTRIBUTE_ALIGN (32);
|
||||||
|
|
||||||
|
static void * netcb (void *arg)
|
||||||
{
|
{
|
||||||
// stop if we're already initialized, or if auto-init has failed before
|
s32 res = 0;
|
||||||
// in which case, manual initialization is required
|
int retry;
|
||||||
if(networkInit || (silent && !autoNetworkInit))
|
|
||||||
return;
|
|
||||||
|
|
||||||
int retry = 1;
|
while(netHalt != 2)
|
||||||
char ip[16];
|
|
||||||
s32 initResult;
|
|
||||||
|
|
||||||
if(!silent)
|
|
||||||
ShowAction ("Initializing network...");
|
|
||||||
|
|
||||||
while(inNetworkInit) // a network init is already in progress!
|
|
||||||
usleep(50);
|
|
||||||
|
|
||||||
if(!networkInit) // check again if the network was inited
|
|
||||||
{
|
{
|
||||||
inNetworkInit = true;
|
retry = 30;
|
||||||
|
|
||||||
while(retry)
|
while (retry)
|
||||||
{
|
{
|
||||||
if(!silent)
|
if (net_init_async(NULL, NULL) != 0)
|
||||||
ShowAction ("Initializing network...");
|
break; // failed
|
||||||
|
|
||||||
initResult = if_config(ip, NULL, NULL, true);
|
res = net_get_status();
|
||||||
|
while (res == -EBUSY)
|
||||||
|
{
|
||||||
|
usleep(20000);
|
||||||
|
res = net_get_status();
|
||||||
|
}
|
||||||
|
|
||||||
if(initResult == 0)
|
if (res != -EAGAIN && res != -ETIMEDOUT)
|
||||||
networkInit = true;
|
|
||||||
|
|
||||||
if(networkInit || silent)
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
retry = ErrorPromptRetry("Unable to initialize network!");
|
retry--;
|
||||||
|
usleep(2000);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// do not automatically attempt a reconnection
|
if (res >= 0)
|
||||||
autoNetworkInit = false;
|
{
|
||||||
inNetworkInit = false;
|
networkInit = true;
|
||||||
|
|
||||||
|
struct in_addr hostip;
|
||||||
|
hostip.s_addr = net_gethostip();
|
||||||
|
if (hostip.s_addr)
|
||||||
|
strcpy(wiiIP, inet_ntoa(hostip));
|
||||||
|
}
|
||||||
|
|
||||||
|
LWP_SuspendThread(networkthread);
|
||||||
}
|
}
|
||||||
if(!silent)
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* StartNetworkThread
|
||||||
|
*
|
||||||
|
* Signals the network thread to resume, or creates a new thread
|
||||||
|
***************************************************************************/
|
||||||
|
void StartNetworkThread()
|
||||||
|
{
|
||||||
|
netHalt = 0;
|
||||||
|
|
||||||
|
if(networkthread == LWP_THREAD_NULL)
|
||||||
|
LWP_CreateThread(&networkthread, netcb, NULL, netstack, 8192, 40);
|
||||||
|
else
|
||||||
|
LWP_ResumeThread(networkthread);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* StopNetworkThread
|
||||||
|
*
|
||||||
|
* Signals the network thread to stop
|
||||||
|
***************************************************************************/
|
||||||
|
void StopNetworkThread()
|
||||||
|
{
|
||||||
|
if(networkthread == LWP_THREAD_NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
netHalt = 2;
|
||||||
|
|
||||||
|
if(LWP_ThreadIsSuspended(networkthread))
|
||||||
|
LWP_ResumeThread(networkthread);
|
||||||
|
|
||||||
|
// wait for thread to finish
|
||||||
|
LWP_JoinThread(networkthread, NULL);
|
||||||
|
networkthread = LWP_THREAD_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool InitializeNetwork(bool silent)
|
||||||
|
{
|
||||||
|
if(networkInit)
|
||||||
|
{
|
||||||
|
StopNetworkThread();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(silent)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int retry = 1;
|
||||||
|
|
||||||
|
while(retry)
|
||||||
|
{
|
||||||
|
u64 start = gettime();
|
||||||
|
|
||||||
|
ShowAction("Initializing network...");
|
||||||
|
StartNetworkThread();
|
||||||
|
|
||||||
|
while (!LWP_ThreadIsSuspended(networkthread))
|
||||||
|
{
|
||||||
|
usleep(50 * 1000);
|
||||||
|
|
||||||
|
if(diff_sec(start, gettime()) > 10) // wait for 10 seconds max for net init
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
CancelAction();
|
CancelAction();
|
||||||
|
|
||||||
|
if(networkInit)
|
||||||
|
break;
|
||||||
|
|
||||||
|
retry = ErrorPromptRetry("Unable to initialize network!");
|
||||||
|
}
|
||||||
|
return networkInit;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CloseShare()
|
void CloseShare()
|
||||||
@ -244,6 +320,9 @@ ConnectShare (bool silent)
|
|||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if(!InitializeNetwork(silent))
|
||||||
|
return false;
|
||||||
|
|
||||||
if(networkShareInit)
|
if(networkShareInit)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -271,12 +350,6 @@ ConnectShare (bool silent)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!networkInit)
|
|
||||||
InitializeNetwork(silent);
|
|
||||||
|
|
||||||
if(!networkInit)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
while(retry)
|
while(retry)
|
||||||
{
|
{
|
||||||
if(!silent)
|
if(!silent)
|
||||||
|
@ -13,11 +13,11 @@
|
|||||||
|
|
||||||
void UpdateCheck();
|
void UpdateCheck();
|
||||||
bool DownloadUpdate();
|
bool DownloadUpdate();
|
||||||
void InitializeNetwork(bool silent);
|
void StartNetworkThread();
|
||||||
|
bool InitializeNetwork(bool silent);
|
||||||
bool ConnectShare (bool silent);
|
bool ConnectShare (bool silent);
|
||||||
void CloseShare();
|
void CloseShare();
|
||||||
|
|
||||||
extern bool updateFound;
|
extern bool updateFound;
|
||||||
extern bool inNetworkInit;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -149,13 +149,11 @@ void ExitApp()
|
|||||||
#ifdef HW_RVL
|
#ifdef HW_RVL
|
||||||
void ShutdownCB()
|
void ShutdownCB()
|
||||||
{
|
{
|
||||||
if(!inNetworkInit)
|
ShutdownRequested = 1;
|
||||||
ShutdownRequested = 1;
|
|
||||||
}
|
}
|
||||||
void ResetCB()
|
void ResetCB()
|
||||||
{
|
{
|
||||||
if(!inNetworkInit)
|
ResetRequested = 1;
|
||||||
ResetRequested = 1;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -346,6 +344,7 @@ main(int argc, char *argv[])
|
|||||||
if(version != 58 && preferred > 0 && version != (u32)preferred && __di_check_ahbprot() != 1)
|
if(version != 58 && preferred > 0 && version != (u32)preferred && __di_check_ahbprot() != 1)
|
||||||
IOS_ReloadIOS(preferred);
|
IOS_ReloadIOS(preferred);
|
||||||
|
|
||||||
|
StartNetworkThread();
|
||||||
DI_Init();
|
DI_Init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user