if((fp = fopen(strsave, "r")) != NULL)
{
send_to_char( "Invalid file name (already in use).\n\r", ch );
return FALSE;
}
bool file_exists(const char *path)
{ FILE *fp;
if( !(fp = fopen(path, "r") ) )
return false;
fclose(fp);
return true;
}
bool fileExists( const char *fname )
{
struct stat fst;
return stat( fname, &fst ) != -1;
}
bool playerExists( const char *name )
{
char fname[256];
snprintf( fname, 256, "%s%c/%s.plr", PLAYER_DIR, tolower(name[0]), capitalize( name ) );
return check_parse_name( capitalize(name) ) && fileExists(fname);
}
class OpenFile
{
public:
string filename;
string mode;
OpenFile( string f, string m ) : filename(f), mode(m) {};
~OpenFile();
};
class Files
{
public:
static list<FILE *> fileList;
static FILE *openFile( string *filename, string *mode )
{
FILE *fp = fopen( filename, mode );
if ( fp )
fileList[fp] = new OpenFile( filename, mode );
}
static void closeFile( FILE *fp )
{
if ( !fp ) return;
OpenFile *file = fileList[fp];
fileList.remove( fp );
delete file;
fclose( fp );
}
};
I noticed a commented out check in my aedit_file function which may have been leftover from stock or another coder having tried the same thing sometime after the codebase began being modified, but either way, uncommented and in use, it would crash.
So after looking over some stuff a bit, this is what I came up with and it seems to work:
added to merc.h:
added to olc_act.c under the aedit_file function:
Like I said, it seems to work, but when it comes to messing around or checking in directories, I thought I would run a quick post by others to see if they notice anything that might be bad.
I know this isn't much, but if there isn't anything that has the chance of messing something up, I'm thinking of putting up here as a small snippet.
Thanks :)