2
3
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-14 02:27:40 -04:00

Replace hsStream::Open duplicated methods everywhere with a single plFileName interface

This commit is contained in:
2013-01-17 21:08:21 -08:00
parent 219061c095
commit 6f6ade2636
60 changed files with 509 additions and 982 deletions

View File

@ -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();
}

View File

@ -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);

View File

@ -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
};

View File

@ -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

View File

@ -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);

View File

@ -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();

View File

@ -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)