Ejemplo n.º 1
0
def loadPhases():
    for mf in [3, 3.5, 4, 5, 5.5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14.5]:
        filenameBase = 'resources/default/phase_%s' % mf
        mounted = mountWithSignature(filenameBase + '.mf', mf)
        if not mounted:
            print('Unable to mount phase_{0}.').format(mf)
            sys.exit()
            break

    filenameBase = 'resources'
    for pack in os.listdir(filenameBase):
        if pack == 'default':
            continue
        directory = os.path.join(filenameBase, pack)
        if not os.path.isdir(directory):
            continue
        print('Loading content pack {0}...').format(pack)
        for file in glob.glob('%s/%s/*.mf' % (filenameBase, pack)):
            mf = Multifile()
            mf.openReadWrite(Filename(file))
            names = mf.getSubfileNames()
            for name in names:
                ext = os.path.splitext(name)[1]
                if ext not in ('.jpg', '.jpeg', '.ogg', '.rgb', '.png'):
                    mf.removeSubfile(name)

            vfs.mount(mf, Filename('/'), 0)
Ejemplo n.º 2
0
    def applyFile(self, filename):
        mf = Multifile()
        mf.openReadWrite(Filename(os.path.join(self.packPath, filename)))
        for subfilename in mf.getSubfileNames():
            if os.path.splitext(subfilename)[1] not in SupportedExtensions:
                mf.removeSubfile(subfilename)
                print 'Removing a file that is not allowed: %s' % str(
                    subfilename)

        self.vfSys.mount(mf, self.mountPoint, 0)
        print 'Successfully Mounted: ' + str(filename)
Ejemplo n.º 3
0
    def applyMultifile(self, filename):
        """
        Apply the specified multifile.
        """
        mf = Multifile()
        mf.openReadWrite(Filename(os.path.join(self.filepath, filename)))

        # Discard content with non-whitelisted extensions:
        for subfileName in mf.getSubfileNames():
            ext = os.path.splitext(subfileName)[1]
            if ext not in CONTENT_EXT_WHITELIST:
                mf.removeSubfile(subfileName)

        self.vfs.mount(mf, self.mountPoint, 0)
Ejemplo n.º 4
0
    def applyMultifile(self, filename):
        """
        Apply the specified multifile.
        """
        mf = Multifile()
        mf.openReadWrite(Filename(os.path.join(self.filepath, filename)))

        # Discard content with non-whitelisted extensions:
        for subfileName in mf.getSubfileNames():
            ext = os.path.splitext(subfileName)[1]
            if ext not in CONTENT_EXT_WHITELIST:
                mf.removeSubfile(subfileName)

        self.vfs.mount(mf, self.mountPoint, 0)
Ejemplo n.º 5
0
    def apply(self, filename):
        """
        Apply the specified content pack on top of the existing content.
        """
        self.notify.info("Applying %s..." % filename[len(self.filepath) :])

        mf = Multifile()
        mf.openReadWrite(Filename(filename))

        # Discard content with non-whitelisted extensions:
        for subfileName in mf.getSubfileNames():
            ext = os.path.splitext(subfileName)[1]
            if ext not in CONTENT_EXT_WHITELIST:
                mf.removeSubfile(subfileName)

        self.vfs.mount(mf, self.mountPoint, 0)
Ejemplo n.º 6
0
    def mountMultifiles(self, resourcePackName=None):
        rsPackPath = None if not resourcePackName else 'resourcepacks/' + resourcePackName

        # This boolean flag is set false if pack.yaml is not found.
        allowResourcePackLoad = True

        if rsPackPath and os.path.exists(rsPackPath):
            if not os.path.exists(rsPackPath + '/pack.yaml'):
                self.notify.warning(
                    'You must have a \'pack.yaml\' configuration in the directory of your resource pack to use it.'
                )
                allowResourcePackLoad = False
            else:
                self.resourcePack = ResourcePack(rsPackPath)
                allowResourcePackLoad = self.resourcePack.digest()

                if allowResourcePackLoad:
                    author = '' if len(self.resourcePack.authors
                                       ) == 0 else self.resourcePack.authors[0]
                    self.notify.info('Loading Resource Pack %s [%s] by %s...' %
                                     (self.resourcePack.name,
                                      self.resourcePack.version, author))

                    self.envConfig = self.resourcePack
                    self.notify.info(
                        'Using Resource Pack Environment Configuration.')

        # This is a boolean flag that stores if we let the user know that a resource
        # pack directory was not found.
        warnedOfMissingPack = False

        vfs = VirtualFileSystem.getGlobalPtr()

        for phase in self.Phases:
            mf = Multifile()
            mf.setEncryptionPassword(metadata.RESOURCE_ENCRYPTION_PASSWORD)
            mf.openReadWrite(Filename(metadata.PHASE_DIRECTORY + phase +
                                      '.mf'))

            # Let's handle the mounting of certain file types from resource packs.
            rsPackMf = None
            loadedRsPackMf = False

            if allowResourcePackLoad:
                if rsPackPath and os.path.exists(rsPackPath):
                    rsPhasePath = '%s/%s.mf' % (rsPackPath, phase)
                    if os.path.exists(rsPhasePath):
                        # This is the phase that exists within the resource pack.
                        rsPackMf = Multifile()
                        rsPackMf.openReadWrite(Filename(rsPhasePath))

                        # Let's remove the unneeded files from the default multifile for this phase.
                        for subFile in mf.getSubfileNames():
                            ext = os.path.splitext(subFile)[1][1:]

                            # This code removes files that are overwritten by the resource pack.
                            if ext in self.LegalResourcePackExtensions and subFile in rsPackMf.getSubfileNames(
                            ):
                                mf.removeSubfile(subFile)

                            # This code removes illegal files inside of the resource pack multifile.
                            elif not ext in self.LegalResourcePackExtensions and subFile in rsPackMf.getSubfileNames(
                            ):
                                rsPackMf.removeSubfile(subFile)

                        # Let's flag that we've loaded a resource pack multifile.
                        loadedRsPackMf = True
                elif rsPackPath and not os.path.exists(
                        rsPackPath) and not warnedOfMissingPack:
                    self.notify.warning(
                        'Desired resource pack could not be found in the \'resourcepacks\' directory.'
                    )
                    warnedOfMissingPack = True
            vfs.mount(mf, '.', 0)

            if loadedRsPackMf:
                vfs.mount(rsPackMf, '.', 0)
                self.notify.info('Mounted %s from resource pack.' % phase)
            else:
                self.notify.info('Mounted %s from default.' % phase)

                if phase == 'phase_3':
                    self.notify.info(
                        'Loading Default Environment Configuration...')
                    # Make an IO stream to the environment.yaml file.
                    self.envConfigStream = io.BytesIO(
                        vfs.readFile('phase_3/etc/environment.yaml', False))

                    # Create a new EnvironmentConfiguration object and read the data.
                    self.envConfig = EnvironmentConfiguration(
                        self.envConfigStream)
                    self.envConfig.digest()

                    # Now, close out the stream.
                    self.envConfigStream.close()
                    self.envConfigStream = None

                    self.notify.info(
                        'Environment Configuration load complete!')

        self.progressScreen = CIProgressScreen()
        self.notify.info('All phases loaded! Ready to play!')
Ejemplo n.º 7
0
    def installPackage(self, appRunner):
        """ Mounts the package and sets up system paths so it becomes
        available for use.  Returns true on success, false on failure. """

        assert self.hasPackage
        if self.installed:
            # Already installed.
            return True
        assert self not in appRunner.installedPackages

        mfPathname = Filename(self.getPackageDir(),
                              self.uncompressedArchive.filename)
        mf = Multifile()
        if not mf.openRead(mfPathname):
            self.notify.warning("Couldn't open %s" % (mfPathname))
            return False

        # We mount it under its actual location on disk.
        root = self.getPackageDir()

        vfs = VirtualFileSystem.getGlobalPtr()
        vfs.mount(mf, root, vfs.MFReadOnly)

        # Add this to the Python search path, if it's not already
        # there.  We have to take a bit of care to check if it's
        # already there, since there can be some ambiguity in
        # os-specific path strings.
        osRoot = self.getPackageDir().toOsSpecific()
        foundOnPath = False
        for p in sys.path:
            if osRoot == p:
                # Already here, exactly.
                foundOnPath = True
                break
            elif osRoot == Filename.fromOsSpecific(p).toOsSpecific():
                # Already here, with some futzing.
                foundOnPath = True
                break

        if not foundOnPath:
            # Not already here; add it.
            sys.path.append(osRoot)

        # Put it on the model-path, too.  We do this indiscriminantly,
        # because the Panda3D runtime won't be adding things to the
        # model-path, so it shouldn't be already there.
        getModelPath().appendDirectory(self.getPackageDir())

        # Set the environment variable to reference the package root.
        envvar = '%s_ROOT' % (self.packageName.upper())
        ExecutionEnvironment.setEnvironmentVariable(envvar, osRoot)

        # Add the package root to the system paths.
        if sys.platform.startswith('win'):
            path = os.environ.get('PATH', '')
            os.environ['PATH'] = "%s;%s" % (osRoot, path)
        else:
            path = os.environ.get('PATH', '')
            os.environ['PATH'] = "%s:%s" % (osRoot, path)
            path = os.environ.get('LD_LIBRARY_PATH', '')
            os.environ['LD_LIBRARY_PATH'] = "%s:%s" % (osRoot, path)

        if sys.platform == "darwin":
            path = os.environ.get('DYLD_LIBRARY_PATH', '')
            os.environ['DYLD_LIBRARY_PATH'] = "%s:%s" % (osRoot, path)

        # Now that the environment variable is set, read all of the
        # prc files in the package.
        appRunner.loadMultifilePrcFiles(mf, self.getPackageDir())

        # Also, find any toplevel Python packages, and add these as
        # shared packages.  This will allow different packages
        # installed in different directories to share Python files as
        # if they were all in the same directory.
        for filename in mf.getSubfileNames():
            if filename.endswith('/__init__.pyc') or \
               filename.endswith('/__init__.pyo') or \
               filename.endswith('/__init__.py'):
                components = filename.split('/')[:-1]
                moduleName = '.'.join(components)
                VFSImporter.sharedPackages[moduleName] = True

        # Fix up any shared directories so we can load packages from
        # disparate locations.
        VFSImporter.reloadSharedPackages()

        self.installed = True
        appRunner.installedPackages.append(self)

        self.markUsed()

        return True
            del NodePath.DtoolClassDict[dtool]

vfs = VirtualFileSystem.getGlobalPtr()
phases = [
    'phase_3', 'phase_3.5', 'phase_4', 'phase_5', 'phase_5.5', 'phase_6',
    'phase_7', 'phase_8', 'phase_9', 'phase_10', 'phase_11', 'phase_12',
    'phase_13', 'phase_0', 'phase_14'
]
packExtensions = ['.jpg', '.jpeg', '.png', '.ogg', '.rgb', '.mid']
for phase in phases:
    mf = Multifile()
    mf.setEncryptionPassword('cio-03-06-16_lsphases')
    mf.openReadWrite(Filename(phase + '.mf'))
    packMf = None
    if os.path.exists('resourcepack/%s.mf' % phase):
        for subFile in mf.getSubfileNames():
            ext = os.path.splitext(subFile)[1]
            if ext in packExtensions:
                mf.removeSubfile(subFile)

        packMf = Multifile()
        packMf.openReadWrite(Filename('resourcepack/%s.mf' % phase))
        for subFile in packMf.getSubfileNames():
            ext = os.path.splitext(subFile)[1]
            if ext not in packExtensions:
                packMf.removeSubfile(subFile)

    vfs.mount(mf, '.', 0)
    print 'Mounted %s from default.' % phase
    if packMf:
        vfs.mount(packMf, '.', 0)
Ejemplo n.º 9
0
    def installPackage(self, appRunner):
        """ Mounts the package and sets up system paths so it becomes
        available for use.  Returns true on success, false on failure. """

        assert self.hasPackage
        if self.installed:
            # Already installed.
            return True
        assert self not in appRunner.installedPackages

        mfPathname = Filename(self.getPackageDir(), self.uncompressedArchive.filename)
        mf = Multifile()
        if not mf.openRead(mfPathname):
            self.notify.warning("Couldn't open %s" % (mfPathname))
            return False

        # We mount it under its actual location on disk.
        root = self.getPackageDir()

        vfs = VirtualFileSystem.getGlobalPtr()
        vfs.mount(mf, root, vfs.MFReadOnly)

        # Add this to the Python search path, if it's not already
        # there.  We have to take a bit of care to check if it's
        # already there, since there can be some ambiguity in
        # os-specific path strings.
        osRoot = self.getPackageDir().toOsSpecific()
        foundOnPath = False
        for p in sys.path:
            if osRoot == p:
                # Already here, exactly.
                foundOnPath = True
                break
            elif osRoot == Filename.fromOsSpecific(p).toOsSpecific():
                # Already here, with some futzing.
                foundOnPath = True
                break

        if not foundOnPath:
            # Not already here; add it.
            sys.path.append(osRoot)

        # Put it on the model-path, too.  We do this indiscriminantly,
        # because the Panda3D runtime won't be adding things to the
        # model-path, so it shouldn't be already there.
        getModelPath().appendDirectory(self.getPackageDir())

        # Set the environment variable to reference the package root.
        envvar = '%s_ROOT' % (self.packageName.upper())
        ExecutionEnvironment.setEnvironmentVariable(envvar, osRoot)

        # Add the package root to the system paths.
        if sys.platform.startswith('win'):
            path = os.environ.get('PATH', '')
            os.environ['PATH'] = "%s;%s" % (osRoot, path)
        else:
            path = os.environ.get('PATH', '')
            os.environ['PATH'] = "%s:%s" % (osRoot, path)
            path = os.environ.get('LD_LIBRARY_PATH', '')
            os.environ['LD_LIBRARY_PATH'] = "%s:%s" % (osRoot, path)

        if sys.platform == "darwin":
            path = os.environ.get('DYLD_LIBRARY_PATH', '')
            os.environ['DYLD_LIBRARY_PATH'] = "%s:%s" % (osRoot, path)

        # Now that the environment variable is set, read all of the
        # prc files in the package.
        appRunner.loadMultifilePrcFiles(mf, self.getPackageDir())

        # Also, find any toplevel Python packages, and add these as
        # shared packages.  This will allow different packages
        # installed in different directories to share Python files as
        # if they were all in the same directory.
        for filename in mf.getSubfileNames():
            if filename.endswith('/__init__.pyc') or \
               filename.endswith('/__init__.pyo') or \
               filename.endswith('/__init__.py'):
                components = filename.split('/')[:-1]
                moduleName = '.'.join(components)
                VFSImporter.sharedPackages[moduleName] = True

        # Fix up any shared directories so we can load packages from
        # disparate locations.
        VFSImporter.reloadSharedPackages()

        self.installed = True
        appRunner.installedPackages.append(self)

        self.markUsed()

        return True