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)
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)
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)
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)
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!')
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) print 'Mounted %s from resource pack.' % phase import Logger