bug fixes for smb - everything works now EXCEPT LoadSMBFile()

This commit is contained in:
dborth 2008-08-10 08:09:22 +00:00
parent 654c9b353b
commit 0ddf00e79e
4 changed files with 44 additions and 46 deletions

View File

@ -558,7 +558,7 @@ OpenSMB (int method)
if(ConnectShare ())
{
// change current dir to root dir
sprintf(currentdir, GCSettings.LoadFolder);
sprintf(currentdir, "/%s", GCSettings.LoadFolder);
if (maxfiles = parseSMBdirectory ())
{

View File

@ -18,6 +18,7 @@
#include <string.h>
#include <fat.h>
#include <zlib.h>
#include <smb.h>
#include "snes9x.h"
#include "memmap.h"
@ -39,6 +40,7 @@ extern void S9xSRTCPreSaveState ();
extern void NGCFreezeStruct ();
extern bool8 S9xUnfreezeGame (const char *filename);
extern unsigned char savebuffer[];
extern SMBCONN smbconn;
static int bufoffset;
static char membuffer[MEMBUFFER];
@ -133,9 +135,11 @@ NGCFreezeGame (int method, bool8 silent)
method = autoSaveMethod();
char filename[1024];
//SMBFILE smbfile;
SMBFILE smbfile;
FILE *handle;
int len = 0;
int wrote = 0;
int offset = 0;
char msg[100];
@ -150,7 +154,7 @@ NGCFreezeGame (int method, bool8 silent)
}
else if (method == METHOD_SMB) // SMB
{
sprintf (filename, "/%s/%s.frz", GCSettings.SaveFolder, Memory.ROMFilename);
sprintf (filename, "%s/%s.frz", GCSettings.SaveFolder, Memory.ROMFilename);
}
S9xSetSoundMute (TRUE);
@ -240,8 +244,7 @@ NGCFreezeGame (int method, bool8 silent)
}
else if (method == METHOD_SMB) // SMB
{
/*
smbfile = SMB_OpenFile (filename, SMB_OPEN_WRITING, SMB_OF_CREATE | SMB_OF_TRUNCATE);
smbfile = SMB_OpenFile (SMBPath(filename), SMB_OPEN_WRITING | SMB_DENY_NONE, SMB_OF_CREATE | SMB_OF_TRUNCATE, smbconn);
if (smbfile)
{
@ -254,11 +257,11 @@ NGCFreezeGame (int method, bool8 silent)
{
if (len > 1024)
wrote =
SMB_Write ((char *) membuffer + offset, 1024, offset,
SMB_WriteFile ((char *) membuffer + offset, 1024, offset,
smbfile);
else
wrote =
SMB_Write ((char *) membuffer + offset, len, offset,
SMB_WriteFile ((char *) membuffer + offset, len, offset,
smbfile);
offset += wrote;
@ -276,10 +279,9 @@ NGCFreezeGame (int method, bool8 silent)
else
{
char msg[100];
sprintf(msg, "Couldn't save to SMB:\\%s\\", GCSettings.SaveFolder);
sprintf(msg, "Couldn't save to SMB: %s", GCSettings.SaveFolder);
WaitPrompt (msg);
}
*/
}
return 0;
}
@ -328,7 +330,7 @@ int
NGCUnfreezeGame (int method, bool8 silent)
{
char filename[1024];
//SMBFILE smbfile;
SMBFILE smbfile;
FILE *handle;
int read = 0;
int offset = 0;
@ -436,8 +438,7 @@ NGCUnfreezeGame (int method, bool8 silent)
sprintf (filename, "%s/%s.frz", GCSettings.SaveFolder, Memory.ROMFilename);
// Read the file into memory
/*smbfile =
SMB_OpenFile (filename, SMB_OPEN_READING | SMB_DENY_NONE, SMB_OF_OPEN);
smbfile = SMB_OpenFile (SMBPath(filename), SMB_OPEN_READING, SMB_OF_OPEN, smbconn);
if (smbfile)
{
@ -448,7 +449,7 @@ NGCUnfreezeGame (int method, bool8 silent)
smbfile)) > 0)
offset += read;
SMB_Close (smbfile);
SMB_CloseFile (smbfile);
if ( !silent )
ShowAction ((char*) "Unpacking freeze file");
@ -463,7 +464,7 @@ NGCUnfreezeGame (int method, bool8 silent)
WaitPrompt((char*) "Freeze file not found");
return 0;
}
return 1;*/
return 1;
}
return 0; // if we reached here, nothing was done!
}

View File

@ -100,6 +100,22 @@ ConnectShare ()
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
*
@ -113,28 +129,24 @@ parseSMBdirectory ()
SMBDIRENTRY smbdir;
sprintf(searchpath, "%s/*", currentdir);
// fix path - replace all '/' with '\'
for(uint i=0; i < strlen(searchpath); i++)
if(searchpath[i] == '/')
searchpath[i] = '\\';
ShowAction((char*) "Loading...");
if(strlen(searchpath) <= 1) // root
sprintf(searchpath, "*");
else
sprintf(searchpath, "%s/*", currentdir);
if (SMB_FindFirst
(searchpath, SMB_SRCH_READONLY | SMB_SRCH_DIRECTORY, &smbdir, smbconn) != SMB_SUCCESS)
(SMBPath(searchpath), SMB_SRCH_READONLY | SMB_SRCH_DIRECTORY, &smbdir, smbconn) != SMB_SUCCESS)
{
char msg[200];
sprintf(msg, "Could not open %s", currentdir);
WaitPrompt (msg);
// if we can't open the dir, open root dir
currentdir[0] = '\0';
sprintf(searchpath, "/");
sprintf(searchpath,"*");
if (SMB_FindFirst
(searchpath, SMB_SRCH_READONLY | SMB_SRCH_DIRECTORY, &smbdir, smbconn) != SMB_SUCCESS)
(SMBPath(searchpath), SMB_SRCH_READONLY | SMB_SRCH_DIRECTORY, &smbdir, smbconn) != SMB_SUCCESS)
return 0;
}
@ -196,16 +208,11 @@ LoadSMBFile (char *filename, int length)
else
sprintf(filepath, "%s/%s", currentdir, filename);
// fix path - replace all '/' with '\'
for(uint i=0; i < strlen(filepath); i++)
if(filepath[i] == '/')
filepath[i] = '\\';
ShowAction((char *)"Loading...");
// Open the file for reading
smbfile =
SMB_OpenFile (filepath, SMB_OPEN_READING, SMB_OF_OPEN, smbconn);
SMB_OpenFile (SMBPath(filepath), SMB_OPEN_READING, SMB_OF_OPEN, smbconn);
if (smbfile)
{
while (offset < length)
@ -301,7 +308,6 @@ LoadSMBFile (char *filename, int length)
}
}
/****************************************************************************
* Write savebuffer to SMB file
****************************************************************************/
@ -313,13 +319,8 @@ SaveBufferToSMB (char *filepath, int datasize, bool8 silent)
int wrote = 0;
int offset = 0;
// fix path - replace all '/' with '\'
for(uint i=0; i < strlen(filepath); i++)
if(filepath[i] == '/')
filepath[i] = '\\';
smbfile =
SMB_OpenFile (filepath, SMB_OPEN_WRITING | SMB_DENY_NONE,
SMB_OpenFile (SMBPath(filepath), SMB_OPEN_WRITING | SMB_DENY_NONE,
SMB_OF_CREATE | SMB_OF_TRUNCATE, smbconn);
if (smbfile)
@ -344,7 +345,7 @@ SaveBufferToSMB (char *filepath, int datasize, bool8 silent)
else
{
char msg[100];
sprintf(msg, "Couldn't save SMB: %s", filepath);
sprintf(msg, "Couldn't save SMB: %s", SMBPath(filepath));
WaitPrompt (msg);
}
@ -361,20 +362,15 @@ LoadBufferFromSMB (char *filepath, bool8 silent)
int ret;
int offset = 0;
// fix path - replace all '/' with '\'
for(uint i=0; i < strlen(filepath); i++)
if(filepath[i] == '/')
filepath[i] = '\\';
smbfile =
SMB_OpenFile (filepath, SMB_OPEN_READING, SMB_OF_OPEN, smbconn);
SMB_OpenFile (SMBPath(filepath), SMB_OPEN_READING, SMB_OF_OPEN, smbconn);
if (!smbfile)
{
if (!silent)
{
char msg[100];
sprintf(msg, "Couldn't open SMB: %s", filepath);
sprintf(msg, "Couldn't open SMB: %s", SMBPath(filepath));
WaitPrompt (msg);
}
return 0;

View File

@ -17,6 +17,7 @@
bool InitializeNetwork(bool silent);
bool ConnectShare ();
char * SMBPath(char * path);
int updateSMBdirname();
int parseSMBdirectory ();
int LoadSMBFile (char *filename, int length);