vbagx/source/ngc/smbop.cpp

128 lines
2.5 KiB
C++
Raw Normal View History

/****************************************************************************
2008-09-17 04:27:55 +02:00
* Visual Boy Advance GX
*
2008-09-17 04:27:55 +02:00
* Tantric September 2008
*
* smbload.cpp
*
* SMB support routines
****************************************************************************/
#include <gccore.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ogcsys.h>
#include <network.h>
#include <smb.h>
#include <zlib.h>
#include <errno.h>
#include "vba.h"
2008-12-18 19:58:30 +01:00
#include "fileop.h"
#include "gcunzip.h"
#include "video.h"
#include "menudraw.h"
#include "filesel.h"
bool networkInit = false;
bool networkShareInit = false;
2008-12-18 19:58:30 +01:00
bool networkInitHalt = false;
/****************************************************************************
* InitializeNetwork
* Initializes the Wii/GameCube network interface
****************************************************************************/
2008-12-18 19:58:30 +01:00
void InitializeNetwork(bool silent)
{
2008-12-18 19:58: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:58:30 +01:00
networkInitHalt = true; // do not attempt a reconnection again
if(!silent)
2008-12-18 19:58:30 +01:00
WaitPrompt("Error reading IP address.");
}
else
{
2008-12-18 19:58:30 +01:00
networkInit = true;
}
}
2008-12-18 19:58:30 +01:00
else
{
if(!silent)
WaitPrompt("Unable to initialize network.");
}
}
2008-12-18 19:58:30 +01:00
void CloseShare()
{
if(networkShareInit)
smbClose();
networkShareInit = false;
}
/****************************************************************************
* Mount SMB Share
****************************************************************************/
bool
ConnectShare (bool silent)
{
// Crashes or stalls system in GameCube mode - so disable
#ifndef HW_RVL
return false;
#endif
// check that all parameter have been set
if(strlen(GCSettings.smbuser) == 0 ||
strlen(GCSettings.smbpwd) == 0 ||
strlen(GCSettings.smbshare) == 0 ||
strlen(GCSettings.smbip) == 0)
{
if(!silent)
2008-12-18 19:58:30 +01:00
WaitPrompt("Invalid network settings. Check settings.xml.");
return false;
}
if(!networkInit)
2008-12-18 19:58:30 +01:00
InitializeNetwork(silent);
if(networkInit)
{
2008-12-18 19:58:30 +01:00
if(unmountRequired[METHOD_SMB])
CloseShare();
if(!networkShareInit)
{
if(!silent)
2008-12-18 19:58:30 +01:00
ShowAction ("Connecting to network share...");
2008-12-18 19:58:30 +01:00
if(smbInit(GCSettings.smbuser, GCSettings.smbpwd,
GCSettings.smbshare, GCSettings.smbip))
{
networkShareInit = true;
2008-12-18 19:58:30 +01:00
}
}
if(!networkShareInit && !silent)
2008-12-18 19:58:30 +01:00
WaitPrompt ("Failed to connect to network share.");
}
return networkShareInit;
}