Exemplo n.º 1
0
bool plFileUtils::FileCopy(const wchar_t* existingFile, const wchar_t* newFile)
{
#if HS_BUILD_FOR_WIN32
    return (::CopyFileW(existingFile, newFile, FALSE) != 0);
#elif HS_BUILD_FOR_UNIX
    char data[1500];
    const char* cexisting = hsWStringToString(existingFile);
    const char* cnew = hsWStringToString(newFile);
    FILE* fp = fopen(cexisting, "rb");
    FILE* fw = fopen(cnew, "w");
    delete[] cexisting;
    delete[] cnew;
    int num = 0;
    bool retVal =  true;
    if (fp && fw){
        while(!feof(fp)){
            num = fread(data, sizeof( char ), 1500, fp);
            if( ferror( fp ) ) {
                retVal = false;
                break;
            }
            fwrite(data, sizeof( char ), num, fw);
        }
        fclose(fp);
        fclose(fw);
    } else {
        retVal = false;
    }
    return retVal;
#else
    hsAssert(0, "Not implemented");
    return false;
#endif
}
Exemplo n.º 2
0
static void ManifestDownloaded(
    ENetError                     result, 
    void*                         param, 
    const wchar_t                 group[], 
    const NetCliFileManifestEntry manifest[], 
    uint32_t                        entryCount)
{
    plResPatcher* patcher = (plResPatcher*)param;
    char* name = hsWStringToString(group);
    if (IS_NET_SUCCESS(result))
        PatcherLog(kInfo, "    Downloaded manifest %s", name);
    else {
        PatcherLog(kError, "    Failed to download manifest %s", name);
        patcher->Finish(false);
        delete[] name;
        return;
    }

    for (uint32_t i = 0; i < entryCount; ++i)
    {
        const NetCliFileManifestEntry mfs = manifest[i];
        char* fileName = hsWStringToString(mfs.clientName);

        // See if the files are the same
        // 1. Check file size before we do time consuming md5 operations
        // 2. Do wasteful md5. We should consider implementing a CRC instead.
        if (plFileUtils::GetFileSize(fileName) == mfs.fileSize)
        {
            plMD5Checksum cliMD5(fileName);
            plMD5Checksum srvMD5;
            char* eapSucksString = hsWStringToString(mfs.md5);
            srvMD5.SetFromHexString(eapSucksString);
            delete[] eapSucksString;

            if (cliMD5 == srvMD5)
            {
                delete[] fileName;
                continue;
            } else
                PatcherLog(kInfo, "    Enqueueing %s: MD5 Checksums Differ", fileName);
        } else
            PatcherLog(kInfo, "    Enqueueing %s: File Sizes Differ", fileName);

        // If we're still here, then we need to update the file.
        float size = mfs.zipSize ? (float)mfs.zipSize : (float)mfs.fileSize;
        patcher->GetProgress()->SetLength(size + patcher->GetProgress()->GetMax());
        patcher->RequestFile(mfs.downloadName, mfs.clientName);
    }

    patcher->IssueRequest();
    delete[] name;
}
Exemplo n.º 3
0
//============================================================================
static void FileSrvIpAddressCallback (
    ENetError       result,
    void *          param,
    const wchar_t     addr[]
) {
    NetCliGateKeeperDisconnect();

    if (IS_NET_ERROR(result)) {
        plString msg = plString::Format("FileSrvIpAddressRequest failed: %S", NetErrorToString(result));
        plStatusLog::AddLineS("patcher.log", msg.c_str());

        s_patchResult = result;
        s_downloadComplete = true;
    }
    
    // Start connecting to the server
    const char* caddr = hsWStringToString(addr);
    NetCliFileStartConnect(&caddr, 1, true);
    delete[] caddr;

    PathGetProgramDirectory(s_newPatcherFile, arrsize(s_newPatcherFile));
    GetTempFileNameW(s_newPatcherFile, kPatcherExeFilename, 0, s_newPatcherFile);
    plFileUtils::RemoveFile(s_newPatcherFile);

    NetCliFileManifestRequest(ManifestCallback, nil, s_manifest);
}
std::string pyGUIControlTextBox::GetText()
{
    char *temp = hsWStringToString(GetTextW().c_str());
    std::string retVal = temp;
    delete [] temp;
    return retVal;
}
Exemplo n.º 5
0
void plResPatcher::IssueRequest()
{
    if (!fPatching) return;
    if (fRequests.empty())
        // Wheee!
        Finish();
    else {
        Request req = fRequests.front();
        fRequests.pop();

        std::wstring title;
        if (req.fType == kManifest)
        {
            char* eapSucksString = hsWStringToString(req.fFile.c_str());
            PatcherLog(kMajorStatus, "    Downloading manifest... %s", eapSucksString);
            xtl::format(title, L"Checking %s for updates...", req.fFile.c_str());
            NetCliFileManifestRequest(ManifestDownloaded, this, req.fFile.c_str());
            delete[] eapSucksString;
        } else if (req.fType == kFile) {
            char* eapSucksString = hsWStringToString(req.fFriendlyName.c_str());
            PatcherLog(kMajorStatus, "    Downloading file... %s", eapSucksString);
            xtl::format(title, L"Downloading... %s", plFileUtils::GetFileName(req.fFriendlyName.c_str()));

            // If this is a PRP, we need to unload it from the ResManager
            if (stricmp(plFileUtils::GetFileExt(eapSucksString), "prp") == 0)
                ((plResManager*)hsgResMgr::ResMgr())->RemoveSinglePage(eapSucksString);

            plFileUtils::EnsureFilePathExists(req.fFriendlyName.c_str());
            plResDownloadStream* stream = new plResDownloadStream(fProgress, req.fFile.c_str());
            if(stream->Open(eapSucksString, "wb"))
                NetCliFileDownloadRequest(req.fFile.c_str(), stream, FileDownloaded, this);
            else {
                PatcherLog(kError, "    Unable to create file %s", eapSucksString);
                Finish(false);
            }
            delete[] eapSucksString;
        }

        char* hack = hsWStringToString(title.c_str());
        fProgress->SetTitle(hack);
        delete[] hack;
    }
}
Exemplo n.º 6
0
static void FileDownloaded(
    ENetError       result,
    void*           param,
    const wchar_t   filename[],
    hsStream*       writer) 
{
    plResPatcher* patcher = (plResPatcher*)param;
    char* name = hsWStringToString(filename);
    if (((plResDownloadStream*)writer)->IsZipped())
        plFileUtils::StripExt(name); // Kill off .gz
    writer->Close();

    switch (result)
    {
        case kNetSuccess:
            PatcherLog(kStatus, "    Download Complete: %s", name);
            
            // If this is a PRP, then we need to add it to the ResManager
            if (stricmp(plFileUtils::GetFileExt(name), "prp") == 0)
                ((plResManager*)hsgResMgr::ResMgr())->AddSinglePage(name);

            // Continue down the warpath
            patcher->IssueRequest();
            delete[] name;
            delete writer;
            return;
        case kNetErrFileNotFound:
            PatcherLog(kError, "    Download Failed: %s not found", name);
            break;
        default:
            char* error = hsWStringToString(NetErrorToString(result));
            PatcherLog(kError, "    Download Failed: %s", error);
            delete[] error;
            break;
    }

    // Failure case
    ((plResDownloadStream*)writer)->Unlink();
    patcher->Finish(false);
    delete[] name;
    delete writer;
}
Exemplo n.º 7
0
bool    plFileUtils::CreateDir( const wchar_t *path )
{
    // Create our directory
#if HS_BUILD_FOR_WIN32
    return ( _wmkdir( path ) == 0 ) ? true : ( errno==EEXIST );
#elif HS_BUILD_FOR_UNIX
    const char* cpath = hsWStringToString(path);
    bool ret = CreateDir(cpath);
    delete[] cpath; /* Free the string */

    return ret;
#endif
}
Exemplo n.º 8
0
bool plFileUtils::RemoveFile(const wchar_t* filename, bool delReadOnly)
{
#ifdef HS_BUILD_FOR_WIN32
    if (delReadOnly)
        _wchmod(filename, S_IWRITE);
    return (_wunlink(filename) == 0);
#elif HS_BUILD_FOR_UNIX
    const char* cfilename = hsWStringToString(filename);
    bool ret = RemoveFile(cfilename, delReadOnly);
    delete[] cfilename; /* Free the string */

    return ret;
#endif
}
Exemplo n.º 9
0
std::string pyVaultImageNode::Image_GetTitle( void )
{
    if (!fNode)
        return "";

    VaultImageNode image(fNode);

    std::string retVal = "";
    if (image.GetImageTitle())
    {
        char* temp = hsWStringToString(image.GetImageTitle());
        retVal = temp;
        delete [] temp;
    }
    
    return retVal;
}
Exemplo n.º 10
0
static void FileDownloaded(
    ENetError           result,
    void*               param,
    const plFileName &  filename,
    hsStream*           writer)
{
    plResPatcher* patcher = (plResPatcher*)param;
    plFileName file = filename;
    if (((plResDownloadStream*)writer)->IsZipped())
        file = file.StripFileExt(); // Kill off .gz
    writer->Close();

    switch (result)
    {
        case kNetSuccess:
        {
            PatcherLog(kStatus, "    Download Complete: %s", file.AsString().c_str());
            
            // If this is a PRP, then we need to add it to the ResManager
            plFileName clientPath = static_cast<plResDownloadStream*>(writer)->GetFileName();
            if (clientPath.GetFileExt().CompareI("prp") == 0)
            {
                plResManager* clientResMgr = static_cast<plResManager*>(hsgResMgr::ResMgr());
                clientResMgr->AddSinglePage(clientPath);
            }

            // Continue down the warpath
            patcher->IssueRequest();
            delete writer;
            return;
        }
        case kNetErrFileNotFound:
            PatcherLog(kError, "    Download Failed: %s not found", file.AsString().c_str());
            break;
        default:
            char* error = hsWStringToString(NetErrorToString(result));
            PatcherLog(kError, "    Download Failed: %s", error);
            delete[] error;
            break;
    }

    // Failure case
    static_cast<plResDownloadStream*>(writer)->Unlink();
    patcher->Finish(false);
    delete writer;
}
Exemplo n.º 11
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;
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
0
bool plPythonPack::Open()
{
    if (fPackStreams.size() > 0)
        return true;
    
    // We already tried and it wasn't there
    if (fPackNotFound)
        return false;

    fPackNotFound = true;

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

    std::vector<time_t> modTimes; // the modification time for each of the streams (to resolve duplicate file issues)

    // grab all the .pak files in the folder
    for (int curName = 0; curName < files.size(); curName++)
    {
        // obtain the stream
        hsStream *fPackStream = plStreamSource::GetInstance()->GetFile(files[curName]);
        if (fPackStream)
        {
            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;
            modTimes.push_back(curModTime);
            delete [] tempFilename;

            // read the index data
            int numFiles = fPackStream->ReadLE32();
            uint32_t streamIndex = (uint32_t)(fPackStreams.size());
            for (int i = 0; i < numFiles; i++)
            {
                // and pack the index into our own data structure
                char* buf = fPackStream->ReadSafeString();
                std::string pythonName = buf; // reading a "string" from a hsStream directly into a stl string causes memory loss
                delete [] buf;
                uint32_t offset = fPackStream->ReadLE32();

                plPackOffsetInfo offsetInfo;
                offsetInfo.fOffset = offset;
                offsetInfo.fStreamIndex = streamIndex;

                if (fFileOffsets.find(pythonName) != fFileOffsets.end())
                {
                    uint32_t index = fFileOffsets[pythonName].fStreamIndex;
                    if (modTimes[index] < curModTime) // is the existing file older then the new one?
                        fFileOffsets[pythonName] = offsetInfo; // yup, so replace it with the new info
                }
                else
                    fFileOffsets[pythonName] = offsetInfo; // no conflicts, add the info
            }
            fPackStreams.push_back(fPackStream);
        }
    }

    return !fPackNotFound;
}
Exemplo n.º 14
0
void    plDynamicTextMap::SetFont( const wchar_t *face, uint16_t size, uint8_t fontFlags , bool antiAliasRGB )
{
    char *sFace = hsWStringToString(face);
    SetFont(sFace,size,fontFlags,antiAliasRGB);
    delete [] sFace;
}