mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-18 11:19:10 +00: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; }
|
||||
};
|
||||
|
||||
|
@ -247,18 +247,10 @@ void DummyPrintFn( const char *line )
|
||||
|
||||
//// ExecuteFile /////////////////////////////////////////////////////////////
|
||||
|
||||
bool pfConsoleEngine::ExecuteFile( const char *fileName )
|
||||
bool pfConsoleEngine::ExecuteFile(const plFileName &fileName)
|
||||
{
|
||||
wchar_t* wFilename = hsStringToWString(fileName);
|
||||
bool ret = ExecuteFile(wFilename);
|
||||
delete [] wFilename;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool pfConsoleEngine::ExecuteFile( const wchar_t *fileName )
|
||||
{
|
||||
char string[ 512 ];
|
||||
int line;
|
||||
char string[ 512 ];
|
||||
int line;
|
||||
|
||||
hsStream* stream = plEncryptedStream::OpenEncryptedFile(fileName);
|
||||
|
||||
@ -273,13 +265,14 @@ bool pfConsoleEngine::ExecuteFile( const wchar_t *fileName )
|
||||
return true;
|
||||
}
|
||||
|
||||
for( line = 1; stream->ReadLn( string, sizeof( string ) ); line++ )
|
||||
for( line = 1; stream->ReadLn( string, arrsize( string ) ); line++ )
|
||||
{
|
||||
strncpy( fLastErrorLine, string, sizeof( fLastErrorLine ) );
|
||||
strncpy( fLastErrorLine, string, arrsize( fLastErrorLine ) );
|
||||
|
||||
if( !RunCommand( string, DummyPrintFn ) )
|
||||
{
|
||||
sprintf( string, "Error in console file %S, command line %d: %s", fileName, line, fErrorMsg );
|
||||
snprintf(string, arrsize(string), "Error in console file %s, command line %d: %s",
|
||||
fileName.AsString().c_str(), line, fErrorMsg);
|
||||
ISetErrorMsg( string );
|
||||
stream->Close();
|
||||
delete stream;
|
||||
|
@ -57,6 +57,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
|
||||
#include "HeadSpin.h"
|
||||
|
||||
class plFileName;
|
||||
|
||||
|
||||
//// pfConsoleEngine Class Definition ////////////////////////////////////////
|
||||
@ -94,8 +95,7 @@ class pfConsoleEngine
|
||||
bool RunCommand( char *line, void (*PrintFn)( const char * ) );
|
||||
|
||||
// Executes the given file as a sequence of console commands
|
||||
bool ExecuteFile( const char *fileName );
|
||||
bool ExecuteFile( const wchar_t *fileName );
|
||||
bool ExecuteFile( const plFileName &fileName );
|
||||
|
||||
// Get the last reported error
|
||||
const char *GetErrorMsg( void ) { return fErrorMsg; }
|
||||
|
@ -44,7 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
#include "plCrash_Private.h"
|
||||
#include "plFile/plFileUtils.h"
|
||||
#include "plProduct.h"
|
||||
#include "plString.h"
|
||||
#include "plFileSystem.h"
|
||||
|
||||
#ifdef HS_BUILD_FOR_WIN32
|
||||
|
||||
@ -78,14 +78,8 @@ plCrashSrv::~plCrashSrv()
|
||||
|
||||
void plCrashSrv::IHandleCrash()
|
||||
{
|
||||
// Begin Hackiness
|
||||
wchar_t dumpPath[1024];
|
||||
SHGetSpecialFolderPathW(NULL, dumpPath, CSIDL_LOCAL_APPDATA, TRUE);
|
||||
plFileUtils::ConcatFileName(dumpPath, plProduct::LongName().ToWchar());
|
||||
plFileUtils::ConcatFileName(dumpPath, L"Log");
|
||||
plFileUtils::EnsureFilePathExists(dumpPath);
|
||||
plFileUtils::ConcatFileName(dumpPath, L"crash.dmp");
|
||||
HANDLE file = CreateFileW(dumpPath,
|
||||
plFileName dumpPath = plFileName::Join(plFileSystem::GetLogPath(), "crash.dmp");
|
||||
HANDLE file = CreateFileW(dumpPath.AsString().ToWchar(),
|
||||
GENERIC_WRITE,
|
||||
0,
|
||||
NULL,
|
||||
@ -93,7 +87,6 @@ void plCrashSrv::IHandleCrash()
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
NULL
|
||||
);
|
||||
// End Hackiness
|
||||
|
||||
MINIDUMP_EXCEPTION_INFORMATION e;
|
||||
e.ClientPointers = TRUE;
|
||||
|
@ -43,8 +43,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
#include <Python.h>
|
||||
#include <marshal.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string>
|
||||
|
||||
#include "HeadSpin.h"
|
||||
@ -125,7 +123,7 @@ bool plPythonPack::Open()
|
||||
fPackNotFound = true;
|
||||
|
||||
// Get the names of all the pak files
|
||||
std::vector<std::wstring> files = plStreamSource::GetInstance()->GetListOfNames(L"python", L".pak");
|
||||
std::vector<plFileName> files = plStreamSource::GetInstance()->GetListOfNames("python", "pak");
|
||||
|
||||
std::vector<time_t> modTimes; // the modification time for each of the streams (to resolve duplicate file issues)
|
||||
|
||||
@ -139,13 +137,11 @@ bool plPythonPack::Open()
|
||||
fPackStream->Rewind(); // make sure we're at the beginning of the file
|
||||
fPackNotFound = false;
|
||||
|
||||
char* tempFilename = hsWStringToString(files[curName].c_str());
|
||||
struct stat buf;
|
||||
time_t curModTime = 0;
|
||||
if (stat(tempFilename,&buf)==0)
|
||||
curModTime = buf.st_mtime;
|
||||
plFileInfo info(files[curName]);
|
||||
if (info.Exists())
|
||||
curModTime = info.ModifyTime();
|
||||
modTimes.push_back(curModTime);
|
||||
delete [] tempFilename;
|
||||
|
||||
// read the index data
|
||||
int numFiles = fPackStream->ReadLE32();
|
||||
@ -191,9 +187,8 @@ void plPythonPack::Close()
|
||||
// do NOT close or delete the streams, the preloader will do that for us
|
||||
fPackStreams[i] = nil;
|
||||
}
|
||||
|
||||
fPackStreams.clear();
|
||||
|
||||
fPackStreams.clear();
|
||||
fFileOffsets.clear();
|
||||
}
|
||||
|
||||
|
@ -178,24 +178,24 @@ uint32_t pyImage::GetHeight()
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pyImage::SaveAsJPEG(const wchar_t* fileName, uint8_t quality)
|
||||
void pyImage::SaveAsJPEG(const plFileName& fileName, uint8_t quality)
|
||||
{
|
||||
if (quality <= 0 || quality > 100)
|
||||
{
|
||||
quality = 75;
|
||||
}
|
||||
|
||||
plJPEG::Instance().SetWriteQuality( quality );
|
||||
plJPEG::Instance().WriteToFile( fileName, this->GetImage() );
|
||||
plJPEG::Instance().SetWriteQuality(quality);
|
||||
plJPEG::Instance().WriteToFile(fileName, this->GetImage());
|
||||
}
|
||||
|
||||
void pyImage::SaveAsPNG(const wchar_t* fileName)
|
||||
void pyImage::SaveAsPNG(const plFileName& fileName)
|
||||
{
|
||||
|
||||
plPNG::Instance().WriteToFile( fileName, this->GetImage() );
|
||||
plPNG::Instance().WriteToFile(fileName, this->GetImage());
|
||||
}
|
||||
|
||||
PyObject* pyImage::LoadJPEGFromDisk(const wchar_t* filename, uint16_t width, uint16_t height)
|
||||
PyObject* pyImage::LoadJPEGFromDisk(const plFileName& filename, uint16_t width, uint16_t height)
|
||||
{
|
||||
plMipmap* theMipmap = plJPEG::Instance().ReadFromFile(filename);
|
||||
if (theMipmap)
|
||||
@ -210,7 +210,7 @@ PyObject* pyImage::LoadJPEGFromDisk(const wchar_t* filename, uint16_t width, uin
|
||||
}
|
||||
|
||||
// let's create a nice name for this thing based on the filename
|
||||
plString name = plString::Format("PtImageFromDisk_%S", filename);
|
||||
plString name = plString::Format("PtImageFromDisk_%s", filename.AsString().c_str());
|
||||
|
||||
hsgResMgr::ResMgr()->NewKey(name, theMipmap, plLocation::kGlobalFixedLoc);
|
||||
|
||||
@ -220,7 +220,7 @@ PyObject* pyImage::LoadJPEGFromDisk(const wchar_t* filename, uint16_t width, uin
|
||||
PYTHON_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyObject* pyImage::LoadPNGFromDisk(const wchar_t* filename, uint16_t width, uint16_t height)
|
||||
PyObject* pyImage::LoadPNGFromDisk(const plFileName& filename, uint16_t width, uint16_t height)
|
||||
{
|
||||
plMipmap* theMipmap = plPNG::Instance().ReadFromFile(filename);
|
||||
if (theMipmap)
|
||||
@ -235,7 +235,7 @@ PyObject* pyImage::LoadPNGFromDisk(const wchar_t* filename, uint16_t width, uint
|
||||
}
|
||||
|
||||
// let's create a nice name for this thing based on the filename
|
||||
plString name = plString::Format("PtImageFromDisk_%S", filename);
|
||||
plString name = plString::Format("PtImageFromDisk_%s", filename.AsString().c_str());
|
||||
|
||||
hsgResMgr::ResMgr()->NewKey(name, theMipmap, plLocation::kGlobalFixedLoc);
|
||||
|
||||
|
@ -143,10 +143,10 @@ public:
|
||||
PyObject *GetColorLoc(const pyColor &color); // returns the x,y position of a color (x and y from 0 to 1) - returns pyPoint3
|
||||
uint32_t GetWidth(); // returns the width of the image
|
||||
uint32_t GetHeight(); // returns the height of the image
|
||||
void SaveAsJPEG(const wchar_t* fileName, uint8_t quality = 75);
|
||||
void SaveAsPNG(const wchar_t* fileName);
|
||||
static PyObject* LoadJPEGFromDisk(const wchar_t* filename, uint16_t width, uint16_t height); // returns pyImage
|
||||
static PyObject* LoadPNGFromDisk(const wchar_t* filename, uint16_t width, uint16_t height); // returns pyImage
|
||||
void SaveAsJPEG(const plFileName& fileName, uint8_t quality = 75);
|
||||
void SaveAsPNG(const plFileName& fileName);
|
||||
static PyObject* LoadJPEGFromDisk(const plFileName& filename, uint16_t width, uint16_t height); // returns pyImage
|
||||
static PyObject* LoadPNGFromDisk(const plFileName& filename, uint16_t width, uint16_t height); // returns pyImage
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -152,24 +152,9 @@ PYTHON_METHOD_DEFINITION(ptImage, saveAsJPEG, args)
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
if (PyUnicode_Check(filenameObj))
|
||||
{
|
||||
int strLen = PyUnicode_GetSize(filenameObj);
|
||||
wchar_t* text = new wchar_t[strLen + 1];
|
||||
PyUnicode_AsWideChar((PyUnicodeObject*)filenameObj, text, strLen);
|
||||
text[strLen] = L'\0';
|
||||
self->fThis->SaveAsJPEG(text, quality);
|
||||
delete [] text;
|
||||
PYTHON_RETURN_NONE;
|
||||
}
|
||||
else if (PyString_Check(filenameObj))
|
||||
{
|
||||
// we'll allow this, just in case something goes weird
|
||||
char* text = PyString_AsString(filenameObj);
|
||||
wchar_t* wText = hsStringToWString(text);
|
||||
self->fThis->SaveAsJPEG(wText, quality);
|
||||
delete [] wText;
|
||||
PYTHON_RETURN_NONE;
|
||||
if (PyString_CheckEx(filenameObj)) {
|
||||
self->fThis->SaveAsJPEG(PyString_AsStringEx(filenameObj), quality);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -187,23 +172,9 @@ PYTHON_METHOD_DEFINITION(ptImage, saveAsPNG, args)
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
if (PyUnicode_Check(filenameObj))
|
||||
if (PyString_CheckEx(filenameObj))
|
||||
{
|
||||
int strLen = PyUnicode_GetSize(filenameObj);
|
||||
wchar_t* text = new wchar_t[strLen + 1];
|
||||
PyUnicode_AsWideChar((PyUnicodeObject*)filenameObj, text, strLen);
|
||||
text[strLen] = L'\0';
|
||||
self->fThis->SaveAsPNG(text);
|
||||
delete [] text;
|
||||
PYTHON_RETURN_NONE;
|
||||
}
|
||||
else if (PyString_Check(filenameObj))
|
||||
{
|
||||
// we'll allow this, just in case something goes weird
|
||||
char* text = PyString_AsString(filenameObj);
|
||||
wchar_t* wText = hsStringToWString(text);
|
||||
self->fThis->SaveAsPNG(wText);
|
||||
delete [] wText;
|
||||
self->fThis->SaveAsPNG(PyString_AsStringEx(filenameObj));
|
||||
PYTHON_RETURN_NONE;
|
||||
}
|
||||
else
|
||||
@ -290,8 +261,8 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtLoadJPEGFromDisk, args, "Params: filename,widt
|
||||
|
||||
if (PyString_CheckEx(filenameObj))
|
||||
{
|
||||
plString text = PyString_AsStringEx(filenameObj);
|
||||
PyObject* ret = pyImage::LoadJPEGFromDisk(text.ToWchar(), width, height);
|
||||
plFileName filename = PyString_AsStringEx(filenameObj);
|
||||
PyObject* ret = pyImage::LoadJPEGFromDisk(filename, width, height);
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
@ -312,8 +283,8 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtLoadPNGFromDisk, args, "Params: filename,width
|
||||
}
|
||||
if (PyString_CheckEx(filenameObj))
|
||||
{
|
||||
plString text = PyString_AsStringEx(filenameObj);
|
||||
PyObject* ret = pyImage::LoadPNGFromDisk(text.ToWchar(), width, height);
|
||||
plFileName filename = PyString_AsStringEx(filenameObj);
|
||||
PyObject* ret = pyImage::LoadPNGFromDisk(filename, width, height);
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
|
@ -61,12 +61,12 @@ pyStream::~pyStream()
|
||||
}
|
||||
|
||||
|
||||
bool pyStream::Open(const wchar_t* fileName, const wchar_t* flags)
|
||||
bool pyStream::Open(const plFileName& fileName, const char* flags)
|
||||
{
|
||||
// make sure its closed first
|
||||
Close();
|
||||
|
||||
if (fileName)
|
||||
if (fileName.IsValid())
|
||||
{
|
||||
if (flags)
|
||||
{
|
||||
@ -74,13 +74,13 @@ bool pyStream::Open(const wchar_t* fileName, const wchar_t* flags)
|
||||
bool writeflag = false;
|
||||
bool encryptflag = false;
|
||||
int i;
|
||||
for (i=0 ; i < wcslen(flags) ; i++ )
|
||||
for (i=0 ; i < strlen(flags) ; i++ )
|
||||
{
|
||||
if ( flags[i] == L'r' || flags[i] == L'R' )
|
||||
if ( flags[i] == 'r' || flags[i] == 'R' )
|
||||
readflag = true;
|
||||
if ( flags[i] == L'w' || flags[i] == L'W' )
|
||||
if ( flags[i] == 'w' || flags[i] == 'W' )
|
||||
writeflag = true;
|
||||
if ( flags[i] == L'e' || flags[i] == L'E' )
|
||||
if ( flags[i] == 'e' || flags[i] == 'E' )
|
||||
encryptflag = true;
|
||||
}
|
||||
// if there is a write flag, it takes priorty over read
|
||||
@ -90,7 +90,7 @@ bool pyStream::Open(const wchar_t* fileName, const wchar_t* flags)
|
||||
if (encryptflag)
|
||||
{
|
||||
fStream = new plEncryptedStream;
|
||||
fStream->Open(fileName, L"wb");
|
||||
fStream->Open(fileName, "wb");
|
||||
}
|
||||
else
|
||||
fStream = plEncryptedStream::OpenEncryptedFileWrite(fileName);
|
||||
|
@ -55,6 +55,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
#include <vector>
|
||||
|
||||
class hsStream;
|
||||
class plFileName;
|
||||
|
||||
class pyStream
|
||||
{
|
||||
@ -75,7 +76,7 @@ public:
|
||||
|
||||
static void AddPlasmaClasses(PyObject *m);
|
||||
|
||||
virtual bool Open(const wchar_t* fileName, const wchar_t* flags);
|
||||
virtual bool Open(const plFileName& fileName, const char* flags);
|
||||
virtual std::vector<std::string> ReadLines();
|
||||
virtual bool WriteLines(const std::vector<std::string> & lines);
|
||||
virtual void Close();
|
||||
|
@ -44,6 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
#pragma hdrstop
|
||||
|
||||
#include "pyStream.h"
|
||||
#include "plFileSystem.h"
|
||||
|
||||
|
||||
// glue functions
|
||||
@ -67,23 +68,10 @@ PYTHON_METHOD_DEFINITION(ptStream, open, args)
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
std::wstring filename;
|
||||
if (PyUnicode_Check(filenameObj))
|
||||
plFileName filename;
|
||||
if (PyString_CheckEx(filenameObj))
|
||||
{
|
||||
int strLen = PyUnicode_GetSize(filenameObj);
|
||||
wchar_t* text = new wchar_t[strLen + 1];
|
||||
PyUnicode_AsWideChar((PyUnicodeObject*)filenameObj, text, strLen);
|
||||
text[strLen] = L'\0';
|
||||
filename = text;
|
||||
delete [] text;
|
||||
}
|
||||
else if (PyString_Check(filenameObj))
|
||||
{
|
||||
// we'll allow this, just in case something goes weird
|
||||
char* text = PyString_AsString(filenameObj);
|
||||
wchar_t* wText = hsStringToWString(text);
|
||||
filename = wText;
|
||||
delete [] wText;
|
||||
filename = PyString_AsStringEx(filenameObj);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -91,23 +79,10 @@ PYTHON_METHOD_DEFINITION(ptStream, open, args)
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
std::wstring flags;
|
||||
if (PyUnicode_Check(flagsObj))
|
||||
plString flags;
|
||||
if (PyString_CheckEx(flagsObj))
|
||||
{
|
||||
int strLen = PyUnicode_GetSize(flagsObj);
|
||||
wchar_t* text = new wchar_t[strLen + 1];
|
||||
PyUnicode_AsWideChar((PyUnicodeObject*)flagsObj, text, strLen);
|
||||
text[strLen] = L'\0';
|
||||
flags = text;
|
||||
delete [] text;
|
||||
}
|
||||
else if (PyString_Check(flagsObj))
|
||||
{
|
||||
// we'll allow this, just in case something goes weird
|
||||
char* text = PyString_AsString(flagsObj);
|
||||
wchar_t* wText = hsStringToWString(text);
|
||||
flags = wText;
|
||||
delete [] wText;
|
||||
flags = PyString_AsStringEx(flagsObj);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -115,7 +90,7 @@ PYTHON_METHOD_DEFINITION(ptStream, open, args)
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
PYTHON_RETURN_BOOL(self->fThis->Open(filename.c_str(), flags.c_str()));
|
||||
PYTHON_RETURN_BOOL(self->fThis->Open(filename, flags.c_str()));
|
||||
}
|
||||
|
||||
PYTHON_METHOD_DEFINITION_NOARGS(ptStream, readlines)
|
||||
|
@ -189,28 +189,9 @@ public:
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
pfSecurePreloader::pfSecurePreloader()
|
||||
: fProgress(nil), fLegacyMode(false)
|
||||
{ }
|
||||
|
||||
pfSecurePreloader::~pfSecurePreloader()
|
||||
hsRAMStream* pfSecurePreloader::LoadToMemory(const plFileName& file) const
|
||||
{
|
||||
while (fDownloadEntries.size())
|
||||
{
|
||||
free((void*)fDownloadEntries.front());
|
||||
fDownloadEntries.pop();
|
||||
}
|
||||
|
||||
while (fManifestEntries.size())
|
||||
{
|
||||
free((void*)fManifestEntries.front());
|
||||
fManifestEntries.pop();
|
||||
}
|
||||
}
|
||||
|
||||
hsRAMStream* pfSecurePreloader::LoadToMemory(const wchar_t* file) const
|
||||
{
|
||||
if (!plFileUtils::FileExists(file))
|
||||
if (!plFileInfo(file).Exists())
|
||||
return nil;
|
||||
|
||||
hsUNIXStream s;
|
||||
@ -228,10 +209,10 @@ hsRAMStream* pfSecurePreloader::LoadToMemory(const wchar_t* file) const
|
||||
return ram;
|
||||
}
|
||||
|
||||
void pfSecurePreloader::SaveFile(hsStream* file, const wchar_t* name) const
|
||||
void pfSecurePreloader::SaveFile(hsStream* file, const plFileName& name) const
|
||||
{
|
||||
hsUNIXStream s;
|
||||
s.Open(name, L"wb");
|
||||
s.Open(name, "wb");
|
||||
uint32_t pos = file->GetPosition();
|
||||
file->Rewind();
|
||||
|
||||
@ -244,9 +225,9 @@ void pfSecurePreloader::SaveFile(hsStream* file, const wchar_t* name) const
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
bool pfSecurePreloader::IsZipped(const wchar_t* filename) const
|
||||
bool pfSecurePreloader::IsZipped(const plFileName& filename) const
|
||||
{
|
||||
return wcscmp(plFileUtils::GetFileExt(filename), L"gz") == 0;
|
||||
return filename.GetFileExt().CompareI("gz") == 0;
|
||||
}
|
||||
|
||||
void pfSecurePreloader::PreloadNextFile()
|
||||
@ -257,14 +238,14 @@ void pfSecurePreloader::PreloadNextFile()
|
||||
return;
|
||||
}
|
||||
|
||||
const wchar_t* filename = fDownloadEntries.front();
|
||||
plFileName filename = fDownloadEntries.front();
|
||||
hsStream* s = new pfSecurePreloaderStream(fProgress, IsZipped(filename));
|
||||
|
||||
// Thankfully, both callbacks have the same arguments
|
||||
if (fLegacyMode)
|
||||
NetCliAuthFileRequest(filename, s, FileDownloaded, this);
|
||||
NetCliAuthFileRequest(filename.AsString().ToWchar(), s, FileDownloaded, this);
|
||||
else
|
||||
NetCliFileDownloadRequest(filename, s, FileDownloaded, this);
|
||||
NetCliFileDownloadRequest(filename.AsString().ToWchar(), s, FileDownloaded, this);
|
||||
}
|
||||
|
||||
void pfSecurePreloader::Init()
|
||||
@ -340,15 +321,12 @@ void pfSecurePreloader::PreloadManifest(const NetCliAuthFileInfo manifestEntries
|
||||
for (uint32_t i = 0; i < entryCount; ++i)
|
||||
{
|
||||
const NetCliAuthFileInfo mfs = manifestEntries[i];
|
||||
fDownloadEntries.push(wcsdup(mfs.filename));
|
||||
if (IsZipped(mfs.filename))
|
||||
{
|
||||
wchar_t* name = wcsdup(mfs.filename);
|
||||
plFileUtils::StripExt(name);
|
||||
fManifestEntries.push(name);
|
||||
|
||||
} else
|
||||
fManifestEntries.push(wcsdup(mfs.filename));
|
||||
plFileName filename = plString::FromWchar(mfs.filename);
|
||||
fDownloadEntries.push(filename);
|
||||
if (IsZipped(filename))
|
||||
fManifestEntries.push(filename.StripFileExt());
|
||||
else
|
||||
fManifestEntries.push(filename);
|
||||
|
||||
totalBytes += mfs.filesize;
|
||||
}
|
||||
@ -368,10 +346,12 @@ void pfSecurePreloader::PreloadManifest(const NetCliFileManifestEntry manifestEn
|
||||
const NetCliFileManifestEntry mfs = manifestEntries[i];
|
||||
bool fetchMe = true;
|
||||
hsRAMStream* s = nil;
|
||||
plFileName clientName = plString::FromWchar(mfs.clientName);
|
||||
plFileName downloadName = plString::FromWchar(mfs.downloadName);
|
||||
|
||||
if (plFileUtils::FileExists(mfs.clientName))
|
||||
if (plFileInfo(clientName).Exists())
|
||||
{
|
||||
s = LoadToMemory(mfs.clientName);
|
||||
s = LoadToMemory(clientName);
|
||||
if (s)
|
||||
{
|
||||
// Damn this
|
||||
@ -389,15 +369,15 @@ void pfSecurePreloader::PreloadManifest(const NetCliFileManifestEntry manifestEn
|
||||
|
||||
if (fetchMe)
|
||||
{
|
||||
fManifestEntries.push(wcsdup(mfs.clientName));
|
||||
fDownloadEntries.push(wcsdup(mfs.downloadName));
|
||||
if (IsZipped(mfs.downloadName))
|
||||
fManifestEntries.push(clientName);
|
||||
fDownloadEntries.push(downloadName);
|
||||
if (IsZipped(downloadName))
|
||||
totalBytes += mfs.zipSize;
|
||||
else
|
||||
totalBytes += mfs.fileSize;
|
||||
} else {
|
||||
plSecureStream* ss = new plSecureStream(s, fEncryptionKey);
|
||||
plStreamSource::GetInstance()->InsertFile(mfs.clientName, ss);
|
||||
plStreamSource::GetInstance()->InsertFile(clientName, ss);
|
||||
}
|
||||
|
||||
if (s)
|
||||
@ -418,12 +398,12 @@ void pfSecurePreloader::FilePreloaded(const wchar_t* file, hsStream* stream)
|
||||
{
|
||||
// Clear out queue
|
||||
fDownloadEntries.pop();
|
||||
const wchar_t* clientName = fManifestEntries.front(); // Stolen by plStreamSource
|
||||
plFileName clientName = fManifestEntries.front();
|
||||
fManifestEntries.pop();
|
||||
|
||||
if (!fLegacyMode) // AuthSrv data caching is useless
|
||||
{
|
||||
plFileUtils::EnsureFilePathExists(clientName);
|
||||
plFileSystem::CreateDir(clientName.StripFileName(), true);
|
||||
SaveFile(stream, clientName);
|
||||
}
|
||||
|
||||
|
@ -60,19 +60,18 @@ class pfSecurePreloader : public hsKeyedObject
|
||||
private:
|
||||
|
||||
static pfSecurePreloader* fInstance;
|
||||
std::queue<const wchar_t*> fManifestEntries;
|
||||
std::queue<const wchar_t*> fDownloadEntries;
|
||||
std::queue<plFileName> fManifestEntries;
|
||||
std::queue<plFileName> fDownloadEntries;
|
||||
plOperationProgress* fProgress;
|
||||
uint32_t fEncryptionKey[4];
|
||||
uint32_t fEncryptionKey[4];
|
||||
bool fLegacyMode;
|
||||
|
||||
hsRAMStream* LoadToMemory(const wchar_t* file) const;
|
||||
void SaveFile(hsStream* file, const wchar_t* name) const;
|
||||
bool IsZipped(const wchar_t* filename) const;
|
||||
hsRAMStream* LoadToMemory(const plFileName& file) const;
|
||||
void SaveFile(hsStream* file, const plFileName& name) const;
|
||||
bool IsZipped(const plFileName& filename) const;
|
||||
|
||||
public:
|
||||
pfSecurePreloader();
|
||||
~pfSecurePreloader();
|
||||
pfSecurePreloader() : fProgress(nil), fLegacyMode(false) { }
|
||||
|
||||
CLASSNAME_REGISTER(pfSecurePreloader);
|
||||
GETINTERFACE_ANY(pfSecurePreloader, hsKeyedObject);
|
||||
|
Reference in New Issue
Block a user