Esempio n. 1
0
void pyGUIControlListBox::Add2TextWColor( const char *str1, pyColor& textcolor1,const char *str2, pyColor& textcolor2, uint32_t inheritalpha)
{
    wchar_t *wStr1 = hsStringToWString(str1);
    wchar_t *wStr2 = hsStringToWString(str2);
    Add2TextWColorW(wStr1,textcolor1,wStr2,textcolor2,inheritalpha);
    delete [] wStr2;
    delete [] wStr1;
}
Esempio n. 2
0
bool plFileUtils::FileCopy(const char* existingFile, const char* newFile)
{
    wchar_t* wExisting = hsStringToWString(existingFile);
    wchar_t* wNew = hsStringToWString(newFile);
    bool ret = FileCopy(wExisting, wNew);
    delete [] wExisting;
    delete [] wNew;
    return ret;
}
hsBool  pfConsoleDirSrc::ParseDirectory(const std::string& path, const std::string& mask /* = "*.*" */)
{
    wchar_t* wPath = hsStringToWString(path.c_str());
    wchar_t* wMask = hsStringToWString(mask.c_str());
    hsBool ret = ParseDirectory(wPath, wMask);
    delete [] wPath;
    delete [] wMask;
    return ret;
}
hsBool  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);
    if (handle == INVALID_HANDLE_VALUE)
        return false;

    do
    {
        if (!( findInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) 
        {
            std::wstringstream fileAndPath;
            fileAndPath << path << L"\\" << findInfo.cFileName;
            if (AlreadyProcessedFile(path, findInfo.cFileName))
                continue;
            AddProcessedFile(path, findInfo.cFileName);
            if (!fEngine->ExecuteFile(fileAndPath.str().c_str()))
            {
                // Change the following line once we have a better way of reporting
                // errors in the parsing
                std::wstringstream error;
                std::wstringstream caption;
                wchar_t* errorMsg = hsStringToWString(fEngine->GetErrorMsg());
                wchar_t* errorLine = hsStringToWString(fEngine->GetLastErrorLine());

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

                delete [] errorMsg;
                delete [] errorLine;

                FindClose(handle);
                SetCheckProcessedFiles(true);
                return false;
            }
        }
    } while (FindNextFileW(handle, &findInfo) != 0);

    FindClose(handle);
    SetCheckProcessedFiles(true);
    return true;
}
Esempio n. 5
0
uint32_t  plFileUtils::GetFileSize( const char *path )
{
    wchar_t* wPath = hsStringToWString(path);
    uint32_t ret = GetFileSize(wPath);
    delete [] wPath;
    return ret;
}
Esempio n. 6
0
int16_t pyGUIControlListBox::AddTextWColorWSize( const char *str, pyColor& textcolor, uint32_t inheritalpha, int32_t fontsize)
{
    wchar_t *wStr = hsStringToWString(str);
    int16_t retVal = AddTextWColorWSizeW(wStr,textcolor,inheritalpha,fontsize);
    delete [] wStr;
    return retVal;
}
Esempio n. 7
0
bool    plFileUtils::EnsureFilePathExists( const char *filename )
{
    wchar_t* wFilename = hsStringToWString(filename);
    bool ret = EnsureFilePathExists(wFilename);
    delete [] wFilename;
    return ret;
}
Esempio n. 8
0
uint16_t      plTextGenerator::CalcStringWidth( const char *text, uint16_t *height )
{
    wchar_t *wText = hsStringToWString(text);
    uint16_t retVal = CalcStringWidth(wText,height);
    delete [] wText;
    return retVal;
}
Esempio n. 9
0
uint16_t      plDynamicTextMap::CalcStringWidth( const char *text, uint16_t *height )
{
    wchar_t *wText = hsStringToWString(text);
    uint16_t w = CalcStringWidth(wText,height);
    delete [] wText;
    return w;
}
Esempio n. 10
0
PYTHON_METHOD_DEFINITION(ptImage, saveAsPNG, args)
{
    PyObject* filenameObj;
    if (!PyArg_ParseTuple(args, "O", &filenameObj))
    {
        PyErr_SetString(PyExc_TypeError, "saveAsPNG expects a string");
        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->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;
        PYTHON_RETURN_NONE;
    }
    else
    {
        PyErr_SetString(PyExc_TypeError, "saveAsPNG expects a string");
        PYTHON_RETURN_ERROR;
    }
}
Esempio n. 11
0
void plProfileManagerFull::LogStats(const char* ageName, const char* spawnName)
{
    fLogStats = true;
    wchar_t* temp = hsStringToWString(ageName);
    fLogAgeName = temp;
    delete [] temp;
    fLogSpawnName = spawnName;
}
Esempio n. 12
0
void plClientResMgr::ILoadResources(const char* resfile)
{
    if (!resfile) {
        return;
    }

    wchar_t* wFilename = hsStringToWString(resfile);
    hsUNIXStream in;

    if (in.Open(wFilename, L"rb")) {
        uint32_t header = in.ReadLE32();
        uint32_t version = in.ReadLE32();
        uint32_t num_resources = 0;

        switch (version) {
            case 1:
                num_resources = in.ReadLE32();

                for (int i = 0; i < num_resources; i++) {
                    plMipmap* res_data = NULL;
                    uint32_t res_size = 0;
                    char* tmp_name = in.ReadSafeStringLong();
                    std::string res_name = std::string(tmp_name);
                    std::string res_type = res_name.substr(res_name.length() - 4, 4);
                    delete tmp_name;

                    // Version 1 doesn't encode format, so we'll try some simple
                    // extension sniffing
                    if (res_type == ".png") {
                        // Read resource stream size, but the PNG has that info in the header
                        // so it's not needed
                        res_size = in.ReadLE32();
                        res_data = plPNG::Instance().ReadFromStream(&in);
                    } else if (res_type == ".jpg") {
                        // Don't read resource stream size, as plJPEG's reader will need it
                        res_data = plJPEG::Instance().ReadFromStream(&in);
                    } else {
                        // Original Myst5 format only is known to support Targa,
                        // so default fallback is targa
                        // TODO - Add plTarga::ReadFromStream()
                        // for now, just skip the unknown resource and put NULL into the map
                        res_size = in.ReadLE32();
                        in.Skip(res_size);
                    }

                    (*this->ClientResources)[res_name] = res_data;
                }

                break;
            default:
                break;
        }

        in.Close();
    }

    delete wFilename;
}
Esempio n. 13
0
        virtual void SetText( const char *text )
        {
            if ( fString1 )
                delete [] fString1;

            if( text != nil )
                fString1 = hsStringToWString(text);
            else
                fString1 = nil;
        }
Esempio n. 14
0
//==================================================================
// class RelVaultNode : public plVaultNode
//
void pyVaultImageNode::Image_SetTitle( const char * text )
{
    if (!fNode)
        return;
        
    wchar_t * wStr = hsStringToWString(text);

    VaultImageNode image(fNode);
    image.SetImageTitle(wStr);
    delete [] wStr;
}
Esempio n. 15
0
 pfColorListElement( const char *string1, hsColorRGBA color1, const char *string2, hsColorRGBA color2, uint32_t inheritalpha, int32_t fontsize=-1 )
 {
     if ( string1 )
     {
         fString1 = hsStringToWString(string1);
         fText = plString::Null;
     }
     else
     {
         fString1 = nil;
         fText = "";
     }
     fTextColor1 = color1;
     if (string2)
         fString2 = hsStringToWString(string2);
     else
         fString2 = nil;
     fTextColor2 = color2;
     fInheritAlpha = inheritalpha;
     fJustify = kLeftJustify;
     fOverrideFontSize = fontsize;
 }
Esempio n. 16
0
//============================================================================
void plAgeLoader::UpdateAge(const char ageName[])
{
    if (gDataServerLocal)
        // We have to send this msg ourselves since we're not actually updating
        plgDispatch::Dispatch()->MsgSend(new plResPatcherMsg);
    else
    {
        wchar_t* wideAgeName = hsStringToWString(ageName);
        plResPatcher::GetInstance()->RequestManifest(wideAgeName);
        plResPatcher::GetInstance()->Start();
        delete[] wideAgeName;
    }
}
Esempio n. 17
0
std::vector<std::wstring> plLocalization::StringToLocal(const std::wstring & localizedText)
{
    std::vector<std::wstring> tags;
    std::vector<int> tagLocs;
    std::vector<int> sortedTagLocs;
    std::vector<std::wstring> retVal;
    int i;
    for (i=0; i<kNumLanguages; i++)
    {
        std::wstring tag = L"$";
        std::string temp = GetLanguageName((Language)i);
        wchar_t *wTemp = hsStringToWString(temp.c_str());
        std::wstring langName = wTemp;
        delete [] wTemp;
        
        tag += langName.substr(0,2) + L"$";
        tags.push_back(tag);
        tagLocs.push_back(localizedText.find(tag));
        sortedTagLocs.push_back(i);
        retVal.push_back(L"");
    }
    for (i=0; i<kNumLanguages-1; i++)
    {
        for (int j=i; j<kNumLanguages; j++)
        {
            if (tagLocs[sortedTagLocs[i]] > tagLocs[sortedTagLocs[j]])
                sortedTagLocs[i]^=sortedTagLocs[j]^=sortedTagLocs[i]^=sortedTagLocs[j]; // swap the contents (yes, it works)
        }
    }
    // now sortedTagLocs has the indexes of tagLocs sorted from smallest loc to highest loc
    bool noTags = true;
    for (i=0; i<kNumLanguages; i++)
    {
        int lang = sortedTagLocs[i]; // the language we are extracting
        if (tagLocs[lang] != -1)
        {
            noTags = false; // at least one tag was found in the text
            int startLoc = tagLocs[lang] + tags[lang].length();
            int endLoc;
            if (i+1 == kNumLanguages)
                endLoc = localizedText.length();
            else
                endLoc = tagLocs[sortedTagLocs[i+1]];
            retVal[lang] = localizedText.substr(startLoc,endLoc-startLoc);
        }
    }
    if (noTags)
        retVal[0] = localizedText; // if no tags were in the text, we assume it to be English
    return retVal;
}
Esempio n. 18
0
std::vector<std::string> plLocalization::StringToLocal(const std::string & localizedText)
{
    std::vector<std::string> retVal;
    wchar_t *temp = hsStringToWString(localizedText.c_str());
    std::wstring wLocalizedText = temp;
    delete [] temp;

    std::vector<std::wstring> wStringVector = StringToLocal(wLocalizedText);
    int i;
    for (i=0; i<wStringVector.size(); i++)
    {
        char *local = hsWStringToString(wStringVector[i].c_str());
        std::string val = local;
        delete [] local;
        retVal.push_back(val);
    }

    return retVal;
}
Esempio n. 19
0
//
// load all .sdl files in sdl directory, and create descriptors for each.
// return false on error
//
bool plSDLParser::IReadDescriptors() const
{
    std::string sdlDir = plSDLMgr::GetInstance()->GetSDLDir();
    DebugMsg("SDL: Reading latest descriptors from directory %s", sdlDir.c_str());

    wchar_t* temp = hsStringToWString(sdlDir.c_str());
    std::wstring wSDLDir = temp;
    delete [] temp;

    // Get the names of all the sdl files
    std::vector<std::wstring> files = plStreamSource::GetInstance()->GetListOfNames(wSDLDir, L".sdl");

    bool ret=true;
    int cnt=0;
    for (int i = 0; i < files.size(); i++)
    {
        char* str = hsWStringToString(files[i].c_str());
        if (!ILoadSDLFile(str))
        {
            plNetApp* netApp = plSDLMgr::GetInstance()->GetNetApp();
            if (netApp)
                netApp->ErrorMsg("Error loading SDL file %s", str);
            else
                hsStatusMessageF("Error loading SDL file %s", str);
            ret=false;
        }
        else
            cnt++;
        delete [] str;
    }
    DebugMsg("Done reading SDL files"); 

    if (!cnt)
        ret=false;

    return ret;
}
Esempio n. 20
0
//
// create state descriptor from sdl file.
// return false on err.
//
bool plSDLParser::ILoadSDLFile(const char* fileName) const
{
    DebugMsg("Parsing SDL file %s", fileName);
    
    wchar_t* temp = hsStringToWString(fileName);
    hsStream* stream = plStreamSource::GetInstance()->GetFile(temp);
    delete [] temp;
    if (!stream)
        return false;

    stream->Rewind();

    plVarDescriptor* curVar=nil;
    plStateDescriptor* curDesc=nil;
    char token[kTokenLen];
    bool parsingStateDesc=false;
    bool skip=false;
    while (1)
    {       
        if (!skip)
        {
            if (!stream->GetToken(token, kTokenLen))
                break;
        }
        skip=false;

        if (!strcmp(token, "VAR"))
        {
            parsingStateDesc=false;
            curVar=nil;     // start fresh
            continue;
        }
        
        if (!strcmp(token, "STATEDESC"))
        {
            parsingStateDesc=true;
            curDesc=nil;    // start fresh
            continue;
        }

        if (!strcmp(token, "}"))
        {
            if ( curDesc )
                curDesc->SetFilename( fileName );
            parsingStateDesc=false;
            continue;
        }

        if (parsingStateDesc)
        {
            skip=IParseStateDesc(fileName, stream, token, curDesc);
            if ( !curDesc )
                break;  // failed to parse state desc
        }
        else
        {
            skip=IParseVarDesc(fileName, stream, token, curDesc, curVar);
        }
    }

    // If the very last char is a } without a \n, then it won't be handled above for some reason, so we have to catch it here.
    if ( curDesc )
        curDesc->SetFilename( fileName );

    // do not close or delete the stream, we do not own it
    return true;
}
Esempio n. 21
0
void    plDynamicTextMsg::DrawClippedString( int16_t x, int16_t y, uint16_t clipLeft, uint16_t clipTop, uint16_t clipRight, uint16_t clipBottom, const char *text )
{
    wchar_t *wString = hsStringToWString(text);
    DrawClippedString(x,y,clipLeft,clipTop,clipRight,clipBottom,wString);
    delete [] wString;
}
void pyGUIControlTextBox::SetText( const char *text )
{
    wchar_t *wText = hsStringToWString(text);
    SetTextW(wText);
    delete [] wText;
}
Esempio n. 23
0
void    plDynamicTextMap::DrawWrappedString( uint16_t x, uint16_t y, const char *text, uint16_t width, uint16_t height, uint16_t *lastX, uint16_t *lastY )
{
    wchar_t *wText = hsStringToWString(text);
    DrawWrappedString(x,y,wText,width,height,lastX,lastY);
    delete [] wText;
}
Esempio n. 24
0
void    plDynamicTextMap::CalcWrappedStringSize( const char *text, uint16_t *width, uint16_t *height, uint32_t *firstClippedChar, uint16_t *maxAscent, uint16_t *lastX, uint16_t *lastY )
{
    wchar_t *wText = hsStringToWString(text);
    CalcWrappedStringSize(wText,width,height,firstClippedChar,maxAscent,lastX,lastY);
    delete [] wText;
}
Esempio n. 25
0
void    plTextGenerator::CalcWrappedStringSize( const char *text, uint16_t *width, uint16_t *height )
{
    wchar_t *wText = hsStringToWString(text);
    CalcWrappedStringSize(wText,width,height);
    delete [] wText;
}
Esempio n. 26
0
void    plTextGenerator::DrawWrappedString( uint16_t x, uint16_t y, const char *text, uint16_t width, uint16_t height )
{
    wchar_t *wText = hsStringToWString(text);
    DrawWrappedString(x,y,wText,width,height);
    delete [] wText;
}
Esempio n. 27
0
void    plTextGenerator::DrawClippedString( int16_t x, int16_t y, const char *text, uint16_t clipX, uint16_t clipY, uint16_t width, uint16_t height )
{
    wchar_t *wText = hsStringToWString(text);
    DrawClippedString(x,y,wText,clipX,clipY,width,height);
    delete [] wText;
}
Esempio n. 28
0
void    plTextGenerator::DrawString( uint16_t x, uint16_t y, const char *text )
{
    wchar_t *wText = hsStringToWString(text);
    DrawString(x,y,wText);
    delete [] wText;
}
Esempio n. 29
0
void    plDynamicTextMsg::DrawString( int16_t x, int16_t y, const char *text )
{
    wchar_t *wString = hsStringToWString(text);
    DrawString(x,y,wString);
    delete [] wString;
}
Esempio n. 30
0
void    plDynamicTextMsg::DrawWrappedString( int16_t x, int16_t y, uint16_t wrapWidth, uint16_t wrapHeight, const char *text )
{
    wchar_t *wString = hsStringToWString(text);
    DrawWrappedString(x,y,wrapWidth,wrapHeight,wString);
    delete [] wString;
}