mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-13 18:17:49 -04:00
Replace hsStream::Open duplicated methods everywhere with a single plFileName interface
This commit is contained in:
@ -283,7 +283,7 @@ bool pfConsole::MsgReceive( plMessage *msg )
|
||||
{
|
||||
if( cmd->GetCmd() == plConsoleMsg::kExecuteFile )
|
||||
{
|
||||
if( !fEngine->ExecuteFile( (char *)cmd->GetString() ) )
|
||||
if( !fEngine->ExecuteFile( cmd->GetString() ) )
|
||||
{
|
||||
// Change the following line once we have a better way of reporting
|
||||
// errors in the parsing
|
||||
|
@ -6064,7 +6064,7 @@ PF_CONSOLE_CMD(Age, ShowSDL, "", "Prints the age SDL values")
|
||||
PF_CONSOLE_CMD( Age, GetElapsedDays, "string agedefnfile", "Gets the elapsed days and fractions" )
|
||||
{
|
||||
hsUNIXStream s;
|
||||
if (!s.Open(params[0]))
|
||||
if (!s.Open(static_cast<const char *>(params[0])))
|
||||
{
|
||||
PrintString("Couldn't open age defn file!");
|
||||
return;
|
||||
@ -6085,7 +6085,7 @@ PF_CONSOLE_CMD( Age, GetElapsedDays, "string agedefnfile", "Gets the elapsed day
|
||||
PF_CONSOLE_CMD( Age, GetTimeOfDay, "string agedefnfile", "Gets the elapsed days and fractions" )
|
||||
{
|
||||
hsUNIXStream s;
|
||||
if (!s.Open(params[0]))
|
||||
if (!s.Open(static_cast<const char *>(params[0])))
|
||||
{
|
||||
PrintString("Couldn't open age defn file!");
|
||||
return;
|
||||
|
@ -57,40 +57,27 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
|
||||
//// ParseDirectory //////////////////////////////////////////////////////////
|
||||
|
||||
bool pfConsoleDirSrc::ParseDirectory(const std::string& path, const std::string& mask /* = "*.*" */)
|
||||
bool pfConsoleDirSrc::ParseDirectory(const plFileName& path, const plString& mask /* = L"*.*" */)
|
||||
{
|
||||
wchar_t* wPath = hsStringToWString(path.c_str());
|
||||
wchar_t* wMask = hsStringToWString(mask.c_str());
|
||||
bool ret = ParseDirectory(wPath, wMask);
|
||||
delete [] wPath;
|
||||
delete [] wMask;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool pfConsoleDirSrc::ParseDirectory(const std::wstring& path, const std::wstring& mask /* = L"*.*" */)
|
||||
{
|
||||
std::wstringstream search;
|
||||
std::wstring file;
|
||||
WIN32_FIND_DATAW findInfo;
|
||||
HANDLE handle;
|
||||
|
||||
hsAssert( fEngine != nil, "Cannot do a dir execute without an engine!" );
|
||||
|
||||
search << path << L"\\" << mask;
|
||||
handle = FindFirstFileW(search.str().c_str(), &findInfo);
|
||||
handle = FindFirstFileW(plFileName::Join(path, mask).AsString().ToWchar(), &findInfo);
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
|
||||
do
|
||||
{
|
||||
if (!( findInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
||||
if (!( findInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
||||
{
|
||||
std::wstringstream fileAndPath;
|
||||
fileAndPath << path << L"\\" << findInfo.cFileName;
|
||||
if (AlreadyProcessedFile(path, findInfo.cFileName))
|
||||
plFileName name = plString::FromWchar(findInfo.cFileName);
|
||||
plFileName fileAndPath = plFileName::Join(path, name);
|
||||
if (AlreadyProcessedFile(path, name))
|
||||
continue;
|
||||
AddProcessedFile(path, findInfo.cFileName);
|
||||
if (!fEngine->ExecuteFile(fileAndPath.str().c_str()))
|
||||
AddProcessedFile(path, name);
|
||||
if (!fEngine->ExecuteFile(fileAndPath))
|
||||
{
|
||||
// Change the following line once we have a better way of reporting
|
||||
// errors in the parsing
|
||||
@ -102,7 +89,7 @@ bool pfConsoleDirSrc::ParseDirectory(const std::wstring& path, const std::wst
|
||||
caption << L"Error parsing " << findInfo.cFileName;
|
||||
error << errorMsg << L":\n\nCommand: '" << errorLine << L"'\n\nPress OK to continue parsing files.";
|
||||
|
||||
hsMessageBox(error.str().c_str(), caption.str().c_str(), hsMessageBoxNormal);
|
||||
hsMessageBox(error.str().c_str(), caption.str().c_str(), hsMessageBoxNormal);
|
||||
|
||||
delete [] errorMsg;
|
||||
delete [] errorLine;
|
||||
@ -137,12 +124,12 @@ void pfConsoleDirSrc::ResetProcessedFiles()
|
||||
// note: this n^2 linear search should be replaced with something
|
||||
// faster if we have lots of init files and turn on the checkProcessing option.
|
||||
//
|
||||
bool pfConsoleDirSrc::AlreadyProcessedFile(const std::wstring& path, const std::wstring& file)
|
||||
bool pfConsoleDirSrc::AlreadyProcessedFile(const plFileName& path, const plFileName& file)
|
||||
{
|
||||
if (fCheckProcessedFiles)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<fProcessedFiles.size(); i++)
|
||||
for (i=0; i<fProcessedFiles.size(); i++)
|
||||
{
|
||||
if (file == fProcessedFiles[i]->fFile && path == fProcessedFiles[i]->fPath)
|
||||
return true;
|
||||
@ -151,7 +138,7 @@ bool pfConsoleDirSrc::AlreadyProcessedFile(const std::wstring& path, const std::
|
||||
return false;
|
||||
}
|
||||
|
||||
void pfConsoleDirSrc::AddProcessedFile(const std::wstring& path, const std::wstring& file)
|
||||
void pfConsoleDirSrc::AddProcessedFile(const plFileName& path, const plFileName& file)
|
||||
{
|
||||
fProcessedFiles.push_back(new FileName(path, file));
|
||||
fProcessedFiles.push_back(new FileName(path, file));
|
||||
}
|
||||
|
@ -57,9 +57,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
|
||||
#include "HeadSpin.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "pfConsoleCore/pfConsoleEngine.h"
|
||||
#include "plFileSystem.h"
|
||||
|
||||
//// pfConsoleDirSrc Class Definition ////////////////////////////////////////
|
||||
|
||||
@ -69,23 +69,17 @@ class pfConsoleDirSrc
|
||||
pfConsoleEngine *fEngine;
|
||||
struct FileName
|
||||
{
|
||||
std::wstring fPath;
|
||||
std::wstring fFile;
|
||||
FileName() : fPath(L""), fFile(L"") {}
|
||||
FileName(const std::wstring& p, const std::wstring& f) : fPath(p), fFile(f) {}
|
||||
plFileName fPath;
|
||||
plFileName fFile;
|
||||
FileName() : fPath(""), fFile("") {}
|
||||
FileName(const plFileName& p, const plFileName& f) : fPath(p), fFile(f) {}
|
||||
};
|
||||
std::vector<FileName*> fProcessedFiles; // list of init files we've already executed
|
||||
bool fCheckProcessedFiles; // set to check and skip files init files we've already executed
|
||||
public:
|
||||
pfConsoleDirSrc(pfConsoleEngine *engine) : fCheckProcessedFiles(false) { fEngine = engine; }
|
||||
pfConsoleDirSrc(pfConsoleEngine *engine, const std::string& path, const std::string& mask = "*.ini") :
|
||||
fCheckProcessedFiles(false)
|
||||
{
|
||||
fEngine = engine;
|
||||
ParseDirectory(path, mask);
|
||||
}
|
||||
pfConsoleDirSrc(pfConsoleEngine *engine, const std::wstring& path, const std::wstring& mask = L"*.ini") :
|
||||
fCheckProcessedFiles(false)
|
||||
pfConsoleDirSrc(pfConsoleEngine *engine, const plFileName& path, const plString& mask = "*.ini")
|
||||
: fCheckProcessedFiles(false)
|
||||
{
|
||||
fEngine = engine;
|
||||
ParseDirectory(path, mask);
|
||||
@ -94,12 +88,11 @@ class pfConsoleDirSrc
|
||||
~pfConsoleDirSrc() { ResetProcessedFiles(); }
|
||||
|
||||
// Steps through the given directory and executes all files with the console engine
|
||||
bool ParseDirectory(const std::string& path, const std::string& mask = "*.*");
|
||||
bool ParseDirectory(const std::wstring& path, const std::wstring& mask = L"*.*");
|
||||
bool ParseDirectory(const plFileName& path, const plString& mask = "*.*");
|
||||
|
||||
void ResetProcessedFiles();
|
||||
bool AlreadyProcessedFile(const std::wstring& path, const std::wstring& file);
|
||||
void AddProcessedFile(const std::wstring& path, const std::wstring& file);
|
||||
bool AlreadyProcessedFile(const plFileName& path, const plFileName& file);
|
||||
void AddProcessedFile(const plFileName& path, const plFileName& file);
|
||||
void SetCheckProcessedFiles(bool c) { fCheckProcessedFiles=c; }
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user