tested file natives and handle system

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40260
This commit is contained in:
David Anderson 2007-01-01 21:18:56 +00:00
parent f072110a44
commit 929957643f
4 changed files with 33 additions and 2 deletions

View File

@ -51,7 +51,10 @@ cell_t sm_OpenDirectory(IPluginContext *pContext, const cell_t *params)
return 0;
}
IDirectory *pDir = g_LibSys.OpenDirectory(path);
char realpath[PLATFORM_MAX_PATH+1];
g_LibSys.PathFormat(realpath, sizeof(realpath), "%s/%s", g_SourceMod.GetBaseDir(), path);
IDirectory *pDir = g_LibSys.OpenDirectory(realpath);
if (!pDir)
{
return 0;
@ -95,20 +98,36 @@ cell_t sm_ReadDirEntry(IPluginContext *pContext, const cell_t *params)
}
const char *path = pDir->GetEntryName();
if ((err=pContext->StringToLocalUTF8(params[2], params[3],path, NULL))
if ((err=pContext->StringToLocalUTF8(params[2], params[3], path, NULL))
!= SP_ERROR_NONE)
{
pContext->ThrowNativeErrorEx(err, NULL);
return 0;
}
pDir->NextEntry();
return true;
}
cell_t PrintStuff(IPluginContext *pContext, const cell_t *params)
{
char *stuff;
pContext->LocalToString(params[1], &stuff);
FILE *fp = fopen("c:\\debug.txt", "at");
fprintf(fp, "%s\n", stuff);
fclose(fp);
return 0;
}
static FileNatives s_FileNatives;
REGISTER_NATIVES(filesystem)
{
{"OpenDirectory", sm_OpenDirectory},
{"ReadDirEntry", sm_ReadDirEntry},
{"PrintStuff", PrintStuff},
{NULL, NULL},
};

View File

@ -165,5 +165,7 @@ REGISTER_NATIVES(basicstrings)
{"IntToString", sm_numtostr},
{"StringToFloat", sm_strtofloat},
{"FloatToString", sm_floattostr},
{"Format", sm_format},
{"FormatEx", sm_formatex},
{NULL, NULL},
};

View File

@ -200,6 +200,11 @@ const char *SourceModBase::GetSMBaseDir()
return m_SMBaseDir;
}
const char *SourceModBase::GetBaseDir()
{
return g_BaseDir.c_str();
}
SMGlobalClass *SMGlobalClass::head = NULL;
SMGlobalClass::SMGlobalClass()

View File

@ -37,6 +37,11 @@ public:
*/
const char *GetSMBaseDir();
/**
* @brief Returns the base folder for file natives.
*/
const char *GetBaseDir();
/**
* @brief Returns whether our load in this map is late.
*/