snes9xgx/source/ngc/smbop.cpp

130 lines
2.6 KiB
C++
Raw Normal View History

/****************************************************************************
* Snes9x 1.51 Nintendo Wii/Gamecube Port
2008-08-14 00:44:59 +02:00
*
* softdev July 2006
* crunchy2 May 2007
* Tantric August 2008
*
* smbload.cpp
*
* SMB support routines
****************************************************************************/
#include <gccore.h>
#include <stdio.h>
2008-12-18 19:36:30 +01:00
#include <stdlib.h>
#include <string.h>
#include <ogcsys.h>
#include <network.h>
#include <smb.h>
#include <zlib.h>
#include <errno.h>
2008-09-09 19:36:48 +02:00
2008-12-18 19:36:30 +01:00
#include "snes9xGX.h"
#include "fileop.h"
#include "unzip.h"
#include "video.h"
#include "menudraw.h"
#include "filesel.h"
2008-08-12 05:25:16 +02:00
bool networkInit = false;
bool networkShareInit = false;
2008-12-18 19:36:30 +01:00
bool networkInitHalt = false;
/****************************************************************************
* InitializeNetwork
* Initializes the Wii/GameCube network interface
****************************************************************************/
2008-12-18 19:36:30 +01:00
void InitializeNetwork(bool silent)
{
2008-12-18 19:36:30 +01:00
if(networkInit || networkInitHalt)
return;
if(!silent)
ShowAction ("Initializing network...");
s32 result;
while ((result = net_init()) == -EAGAIN);
if (result >= 0)
{
char myIP[16];
if (if_config(myIP, NULL, NULL, true) < 0)
{
2008-12-18 19:36:30 +01:00
networkInitHalt = true; // do not attempt a reconnection again
2008-08-12 05:25:16 +02:00
if(!silent)
2008-12-18 19:36:30 +01:00
WaitPrompt("Error reading IP address.");
}
else
{
2008-12-18 19:36:30 +01:00
networkInit = true;
}
}
2008-12-18 19:36:30 +01:00
else
{
if(!silent)
WaitPrompt("Unable to initialize network.");
}
}
2008-12-18 19:36:30 +01:00
void CloseShare()
{
if(networkShareInit)
smbClose();
networkShareInit = false;
}
/****************************************************************************
* Mount SMB Share
****************************************************************************/
2008-08-12 05:25:16 +02:00
bool
2008-08-12 05:25:16 +02:00
ConnectShare (bool silent)
{
2008-08-16 02:02:08 +02:00
// Crashes or stalls system in GameCube mode - so disable
#ifndef HW_RVL
return false;
#endif
2008-09-08 01:50:57 +02:00
// check that all parameter have been set
if(strlen(GCSettings.smbuser) == 0 ||
strlen(GCSettings.smbpwd) == 0 ||
strlen(GCSettings.smbshare) == 0 ||
strlen(GCSettings.smbip) == 0)
2008-09-10 07:57:37 +02:00
{
if(!silent)
2008-12-18 19:36:30 +01:00
WaitPrompt("Invalid network settings. Check settings.xml.");
2008-09-08 01:50:57 +02:00
return false;
2008-09-10 07:57:37 +02:00
}
2008-09-08 01:50:57 +02:00
2008-08-12 05:25:16 +02:00
if(!networkInit)
2008-12-18 19:36:30 +01:00
InitializeNetwork(silent);
if(networkInit)
{
2008-12-18 19:36:30 +01:00
if(unmountRequired[METHOD_SMB])
CloseShare();
if(!networkShareInit)
2008-08-12 05:25:16 +02:00
{
if(!silent)
2008-12-18 19:36:30 +01:00
ShowAction ("Connecting to network share...");
2008-08-12 05:25:16 +02:00
2008-12-18 19:36:30 +01:00
if(smbInit(GCSettings.smbuser, GCSettings.smbpwd,
GCSettings.smbshare, GCSettings.smbip))
{
2008-08-12 05:25:16 +02:00
networkShareInit = true;
2008-12-18 19:36:30 +01:00
}
2008-08-12 05:25:16 +02:00
}
if(!networkShareInit && !silent)
2008-12-18 19:36:30 +01:00
WaitPrompt ("Failed to connect to network share.");
}
return networkShareInit;
}