Exemple #1
0
 def __init__(self, filename):
     if isinstance(self, CIndexedRowset):
         parent = CIndexedRowset
         self.cdata = True
     elif isinstance(self, CFilterRowset):
         parent = CFilterRowset
         self.cdata = False
     else:
         raise RuntimeError("CRowsetDiskBase: No support for '%s'" %
                            type(self))
     f = blue.ResFile()
     f.OpenAlways(filename + '.index.cr')
     indexData = blue.marshal.Load(f.Read())
     if indexData[0] != ROWSETVERSION:
         msg = 'DiskData: File %s is version %s, but I want %s' % (
             filename, indexData.version, ROWSETVERSION)
         raise RuntimeError(msg)
     parent.__init__(self, indexData[1], indexData[2])
     self.offsets = indexData[3]
     self.dataFile = blue.ResFile()
     self.dataFile.OpenAlways(filename + '.data.cr')
     self.maxUsage = 1
     self.minAge = 60
     self.loaded = {}
     self.__diskRowsets__ = weakref(self)
Exemple #2
0
def SaveRowset(rs, filename, segmented):
    print '>>about to SaveRowset', filename, segmented
    if isinstance(rs, CRowset):
        if segmented:
            raise RuntimeError('SaveRowset: No support for segmented CRowset')
    elif isinstance(rs, CIndexedRowset):
        cdata = True
    elif isinstance(rs, CFilterRowset):
        cdata = False
    else:
        raise RuntimeError("SaveRowset: No support for '%s'" % type(rs))
    dataFile = blue.ResFile()
    if not segmented:
        dataFile.Create(filename + '.cr')
        dataFile.Write(blue.marshal.Save((ROWSETVERSION, rs)))
    else:
        dataFile.Create(filename + '.data.cr')
        offsets = {}
        for k, v in rs.iteritems():
            pos = dataFile.pos
            if cdata:
                blob = blue.marshal.Save(v.__cdata__)
            else:
                blob = blue.marshal.Save(v)
            dataFile.Write(blob)
            offsets[k] = (pos, len(blob))

        indexData = (ROWSETVERSION, rs.header, rs.columnName, offsets)
        indexFile = blue.ResFile()
        indexFile.Create(filename + '.index.cr')
        indexFile.Write(blue.marshal.Save(indexData))
Exemple #3
0
    def __PopulateSystemLists(self):
        """
            Utility method to populate the system lists from the flagged-site list on the server/db.
        """
        flaggedSites = []
        try:
            f = blue.ResFile()
            if f.Open(self.flaggedSitesFile):
                flaggedSites = cPickle.loads(f.Read())
        except:
            log.LogException('Error reading file from disk')
        finally:
            f.Close()

        try:
            m = hashlib.md5()
            m.update(str(flaggedSites))
            if m.hexdigest() != sm.RemoteSvc('browserLockdownSvc').GetFlaggedSitesHash():
                self.LogInfo('FlaggedSites: Download full list from server')
                flaggedSites = sm.RemoteSvc('browserLockdownSvc').GetFlaggedSitesList()
                try:
                    f = blue.ResFile()
                    f.Create(self.flaggedSitesFile)
                    f.Write(cPickle.dumps(flaggedSites))
                except:
                    log.LogException('Error writing flaggedSites list to disk')
                finally:
                    f.Close()

        except:
            log.LogException('Error connecting to database')
            return

        self.systemLists = util.KeyVal(blacklist=[], bannedInChat=[], whitelist=['about:blank'], community=[], autotrusted=[])

        def GetDomainOnly(uStr):
            if uStr.find(u'//') != -1:
                uStr = uStr.split(u'//')[1]
            if uStr.startswith(u'*'):
                uStr = uStr[1:]
            if uStr.startswith(u'.'):
                uStr = uStr[1:]
            if uStr.endswith(u'/*'):
                uStr = uStr[:-2]
            return uStr

        for flaggedSiteRow in flaggedSites:
            if flaggedSiteRow['siteFlag'] & self.BLACKLIST_FLAG:
                self.systemLists.blacklist.append(flaggedSiteRow['siteUrl'])
                uStr = GetDomainOnly(unicode(flaggedSiteRow['siteUrl'])).strip()
                if uStr:
                    self.systemLists.bannedInChat.append(uStr)
            if flaggedSiteRow['siteFlag'] & self.WHITELIST_FLAG:
                self.systemLists.whitelist.append(flaggedSiteRow['siteUrl'])
            if flaggedSiteRow['siteFlag'] & self.COMMUNITY_FLAG:
                self.systemLists.community.append(flaggedSiteRow['siteUrl'])
            if flaggedSiteRow['siteFlag'] & self.AUTOTRUSTED_FLAG:
                self.systemLists.autotrusted.append(flaggedSiteRow['siteUrl'])
Exemple #4
0
    def ImportCharacter(factory, scene, resPath, **kwargs):
        blocking = kwargs.get('blocking')
        callBack = kwargs.get('callBack')
        rotation = kwargs.get('rotation')
        position = kwargs.get('point')
        pdc = PaperDollCharacter(factory)
        pdc.scene = scene
        pdc.avatar = trinity.Load(resPath + '/unique.red')
        if pdc.avatar is None:
            log.LogInfo('Import failed on ' + resPath + '/unique.red')
            return
        pdc.visualModel = pdc.avatar.visualModel
        slash = resPath.rfind('/')
        pdc.avatar.name = str(resPath[slash + 1:] + ' (import)')
        if position:
            pdc.avatar.translation = position
        if rotation:
            pdc.avatar.rotation = rotation
        rf = blue.ResFile()
        bsPath = resPath + '/blendshapes.yaml'
        meshes = None
        morphTargets = None
        if rf.FileExists(bsPath):
            f = rf.open(bsPath)
            morphTargets = yaml.load(f, Loader=yaml.CLoader)
            f.close()
            if morphTargets:
                meshes = pdc.visualModel.meshes

        def fun():
            if meshes:
                factory.ApplyMorphTargetsToMeshes(meshes, morphTargets)
                if trinity.GetShaderModel() == 'SM_2_0_LO':
                    PD.PortraitTools.RebindDXT5ShadersForSM2(meshes)
            if callBack:
                callBack()

        if blocking:
            fun()
        else:
            uthread.worker('paperDoll::PaperDollCharacter::ImportCharacter', fun)
        scene.AddDynamic(pdc.avatar)
        rf = blue.ResFile()
        aoPath = resPath + '/animationOffsets.yaml'
        if rf.FileExists(aoPath):
            f = rf.open(aoPath)
            animationOffsets = yaml.load(f, Loader=yaml.CLoader)
            f.close()
            if animationOffsets:
                pdc.ApplyAnimationOffsets(animationOffsets)
        pdc.avatar.explicitMinBounds = (-5, -5, -5)
        pdc.avatar.explicitMaxBounds = (5, 5, 5)
        pdc.avatar.useExplicitBounds = True
        if PD.SkinSpotLightShadows.instance is not None:
            for mesh in pdc.visualModel.meshes:
                PD.SkinSpotLightShadows.instance.CreateEffectParamsForMesh(mesh)

        return pdc
Exemple #5
0
 def _LoadAnimationData(self):
     ANIMATION_METADATA_PATH = 'res:/Animation/animInfo.yaml'
     resourceFile = blue.ResFile()
     openResults = resourceFile.Open(ANIMATION_METADATA_PATH)
     self._animTypeData = yaml.load(resourceFile)
     resourceFile.close()
     self.ProcessAnimationDictionary(self.GetAnimationData())
Exemple #6
0
    def _GetSystem(self, cell, systemName):
        systemNames = self.systemNames.get(cell.name, None)
        if systemNames is None:
            systemNames = []
            self.systemNames[cell.name] = systemNames
        if systemName not in systemNames:
            systemNames.append(systemName)
        systemNum = systemNames.index(systemName)
        while len(cell.systems) < systemNum + 1:
            newSystem = trinity.Tr2InteriorEnlightenSystem()
            newSystem.bounceScale = 1.0
            newSystem.systemID = hash(cell.name)
            newSystem.radSystemPath = INTERIOR_RES_PATH + str(
                self.id) + '_' + cell.name + '.rad'
            try:
                path = INTERIOR_RES_PATH + str(
                    self.id) + '_' + cell.name + '.yaml'
                rf = blue.ResFile()
                if rf.FileExists(path):
                    rf.Open(path)
                    yamlStr = rf.read()
                    rf.close()
                    data = yaml.load(yamlStr)
                    newSystem.irradianceScale = data['irradianceScale']
                    newSystem.bounceScale = data['bounceScale']
            except:
                pass

            cell.systems.append(newSystem)
            newSystem.SetSystemInCellIdx(cell.systems.index(newSystem))
            self._SortSystems(cell)
            self.systemParentName[newSystem] = cell.name

        return cell.systems[systemNum]
Exemple #7
0
 def SaveTrusted(self):
     trustedList = self.GetTrustedSiteList()
     trusted = [ key for key, value in trustedList.iteritems() if value.auto == 0 and value.temporary == 0 and value.trusted == 1 ]
     ignored = [ key for key, value in trustedList.iteritems() if value.auto == 0 and value.temporary == 0 and value.trusted == 0 ]
     f = blue.ResFile()
     self.SaveSiteList(self.trustedFile, trusted)
     self.SaveSiteList(self.ignoredFile, ignored)
Exemple #8
0
 def _GetAudioCueFile(self, audioCueFilePath):
     if audioCueFilePath not in self.audioCueFiles:
         animEventFile = blue.ResFile()
         animEventFile.Open(audioCueFilePath)
         self.audioCueFiles[audioCueFilePath] = yaml.load(animEventFile)
         animEventFile.close()
     return self.audioCueFiles[audioCueFilePath]
def LoadMetaMaterialFile(resourceFile=METASHADER_PATH, forceload=False):
    """
    Loads the global meta-material library and initializes global shader library
    and global packing. Returns tuple of both.
    """
    global _gMetaShaderLibrary
    global _gMetaShaderPacking
    if _gMetaShaderLibrary is not None and _gMetaShaderPacking is not None and forceload is False:
        return (_gMetaShaderLibrary, _gMetaShaderPacking)
    _gMetaShaderLibrary = {}
    _gMetaShaderPacking = {}
    if blue.paths.exists(resourceFile):
        rf = blue.ResFile()
        rf.Open(resourceFile)
        yamlStr = rf.read()
        rf.close()
        data = yaml.load(yamlStr)
        for metashader in data['metashaders']:
            _gMetaShaderLibrary[metashader['name']] = metashader['areas']
            try:
                _gMetaShaderPacking[
                    metashader['name']] = metashader['texpacks']
            except:
                pass

    return (_gMetaShaderLibrary, _gMetaShaderPacking)
 def CheckForIndexFile(self):
     file = blue.ResFile()
     if not file.Open(
             blue.paths.ResolvePathForWriting(
                 u'cache:/Browser/Img/index.dat')):
         self.Load()
     else:
         file.Close()
Exemple #11
0
def GetCommonResource(path):
    resourceFile = blue.ResFile()
    path = GetCommonResourcePath(path)
    result = resourceFile.Open(path)
    if result:
        return resourceFile
    else:
        return None
Exemple #12
0
def LoadRowset(filename):
    f = blue.ResFile()
    f.OpenAlways(filename + '.rs.data.cr')
    version, rs = blue.marshal.Load(f.Read())
    if version != ROWSETVERSION:
        msg = 'DiskData: File %s is version %s, but I want %s' % (filename, version, ROWSETVERSION)
        raise RuntimeError(msg)
    return rs
Exemple #13
0
 def LoadDebugData(self, path=DEBUG_RES_PATH):
     import debugShapes
     sys.modules[debugShapes.__name__] = debugShapes
     resourceFile = blue.ResFile()
     resFile = resourceFile.open(path)
     self.shapes = yaml.load(resFile)
     resourceFile.close()
     del sys.modules[debugShapes.__name__]
Exemple #14
0
def GetAnimInfo():
    global animInfoDict
    if animInfoDict is None:
        dataFile = blue.ResFile()
        dataFile.Open('res:/Animation/animInfo.yaml')
        animInfoDict = yaml.load(dataFile)
        dataFile.close()
    return animInfoDict
Exemple #15
0
 def SaveSiteList(self, fileName, siteList):
     f = blue.ResFile()
     try:
         f.Create(fileName)
         f.Write(cPickle.dumps(siteList))
         f.Close()
     except:
         self.LogError('SitesSvc.SaveSiteList: Error saving to ', fileName)
Exemple #16
0
 def LoadBookmarks(self):
     self.bookmarkedSites = None
     f = blue.ResFile()
     if f.Open(self.bookmarksFile):
         self.bookmarkedSites = cPickle.loads(f.Read())
         f.Close()
     if not self.bookmarkedSites:
         self.bookmarkedSites = []
 def _LoadUVData(self, cellName):
     filePath = INTERIOR_RES_PATH + str(self.id) + '_' + str(cellName) + '.uv'
     if blue.paths.exists(filePath):
         file = blue.ResFile()
         file.open(filePath)
         marshalData = file.read()
         file.close()
         self.cellData[cellName] = blue.marshal.Load(marshalData)
     else:
         self.cellData[cellName] = {}
Exemple #18
0
def ReadYamlFile(path):
    telemetry.APPEND_TO_ZONE(path)
    data = None
    rf = blue.ResFile()
    if rf.FileExists(path):
        rf.Open(path)
        yamlStr = rf.read()
        rf.close()
        data = yaml.load(yamlStr, Loader=yaml.CLoader)
    return data
Exemple #19
0
 def LoadPickle(self, filename, default):
     f = blue.ResFile()
     localFilename = 'res:/%s.pickle' % filename
     sharedFilename = 'root:/common/res/%s.pickle' % filename
     if not f.Open(localFilename) and not f.Open(sharedFilename):
         LogTr('', "File '%s' does not exist." % filename)
         return default
     data = f.Read()
     f.Close()
     return cPickle.loads(data)
def GetCommonResource(path):
    """ return value:  blue.ResFile() or None
    Returns a resfile matching the path from either the current respath, or the common respath """
    resourceFile = blue.ResFile()
    path = GetCommonResourcePath(path)
    result = resourceFile.Open(path)
    if result:
        return resourceFile
    else:
        return None
 def LoadDebugData(self, path = DEBUG_RES_PATH):
     """
     Load written out debug data and put it in the list.
     """
     import debugShapes
     sys.modules[debugShapes.__name__] = debugShapes
     resourceFile = blue.ResFile()
     resFile = resourceFile.open(path)
     self.shapes = yaml.load(resFile)
     resourceFile.close()
     del sys.modules[debugShapes.__name__]
Exemple #22
0
 def DoRewardChart(self, rewardID, size, icon):
     path = 'cache://Pictures/Rewards/rewardchart2_%s_%d_%d.png' % (session.languageID, size, rewardID)
     res = blue.ResFile()
     try:
         if res.Open(path):
             icon.LoadTexture(path)
             icon.SetRect(0, 0, size, size)
         else:
             uthread.new(self.DoRewardChart_Thread, rewardID, size, icon).context = 'DoRewardChart'
     finally:
         res.Close()
 def _LoadAnimationData(self):
     """
     Loads the AnimInfo.yaml file.  This should eventually move to an animation server 
     or something like staticActionDataServer.py
     """
     ANIMATION_METADATA_PATH = 'res:/Animation/animInfo.yaml'
     resourceFile = blue.ResFile()
     openResults = resourceFile.Open(ANIMATION_METADATA_PATH)
     self._animTypeData = yaml.load(resourceFile)
     resourceFile.close()
     self.ProcessAnimationDictionary(self.GetAnimationData())
 def _GetAudioCueFile(self, audioCueFilePath):
     """
     Load up the file containing associations between event track names and the audio cues they trigger.
     Maintains a cache of previously loaded files as well.
     """
     if audioCueFilePath not in self.audioCueFiles:
         animEventFile = blue.ResFile()
         animEventFile.Open(audioCueFilePath)
         self.audioCueFiles[audioCueFilePath] = yaml.load(animEventFile)
         animEventFile.close()
     return self.audioCueFiles[audioCueFilePath]
 def LoadImage(self, imagePath):
     if not blue.ResFile().Open(imagePath):
         log.LogError('Image not found in res:', imagePath)
         return
     texture, tWidth, tHeight, bw, bh = sm.GetService('photo').GetTextureFromURL(imagePath, sizeonly=1, dontcache=1)
     self.img.state = uiconst.UI_NORMAL
     self.img.SetTexturePath(imagePath)
     self.img.width = tWidth
     self.img.height = tHeight
     self.imgpar.width = min(128, tWidth) + self.img.left + 5
     if self.imgpar.state != uiconst.UI_DISABLED:
         self.imgpar.state = uiconst.UI_DISABLED
Exemple #26
0
 def SaveSiteList(self, fileName, siteList):
     """
         Utility method to save the various data structures in this service with proper
         error handling
     """
     f = blue.ResFile()
     try:
         f.Create(fileName)
         f.Write(cPickle.dumps(siteList))
         f.Close()
     except:
         self.LogError('SitesSvc.SaveSiteList: Error saving to ', fileName)
Exemple #27
0
def LoadFromYaml(path):
    blue.pyos.BeNice()
    resFile = blue.ResFile()
    yamlStr = ''
    if resFile.FileExists(path):
        try:
            resFile.Open(path)
            yamlStr = resFile.Read()
        finally:
            resFile.Close()

    return yaml.load(yamlStr)
 def SaveHistory(self):
     if not self.historyIsDirty:
         return
     self.historyIsDirty = False
     f = blue.ResFile()
     try:
         f.Create(self.historyPath)
         f.Write(cPickle.dumps(list(self.history)))
         f.Close()
         self.LogInfo('successfully saved', len(self.history),
                      'browser history entries to disk')
     except Exception as e:
         self.LogError('Error saving in-game browser history to disk', e)
Exemple #29
0
    def GetClientAffiliateID(self):
        if self.affiliateID is None:
            self.affiliateID = ''
            try:
                if os.path.exists(AFFILIATE_FILE_PATH):
                    affiliateFile = blue.ResFile()
                    if affiliateFile.Open(AFFILIATE_FILE_PATH):
                        self.affiliateID = filter(lambda x: x in '0123456789', affiliateFile.Read())
            except Exception as e:
                self.LogError('Error reading affiliate ID: %s' % e)
                sys.exc_clear()

        return self.affiliateID
 def AddAtlas(self, atlasPath):
     data = {}
     if blue.paths.exists(atlasPath):
         resFile = blue.ResFile()
         resFile.Open(atlasPath)
         yamlStr = resFile.Read()
         resFile.Close()
         data = yaml.load(yamlStr, Loader=yaml.CLoader)
     for entry in data:
         self.atlasData[entry] = (atlasPath.split('.')[0], data[entry])
         resPath = '%s_%s.dds' % (self.atlasData[entry][0], str(self.atlasData[entry][1][0]))
         if resPath not in self.preloadedTextures:
             resource = blue.resMan.GetResource(resPath)
             self.preloadedTextures[resPath] = resource