def load_from_remote_file(name): """ Defer loading a file if it has not been downloaded yet but exists on the remote server. """ if name in remote_files: raise DownloadNeeded(relpath=name, rtype=remote_files[name]['type'], size=remote_files[name]['size']) return None
def load_core(name): """ Returns an open python file object of the given type. """ name = lower_map.get(name.lower(), name) if renpy.config.file_open_callback: rv = renpy.config.file_open_callback(name) if rv is not None: return rv # Look for the file directly. if not renpy.config.force_archives: try: fn = transfn(name) return open_file(fn, "rb") except: pass # Look for the file in the apk. for apk in apks: prefixed_name = "/".join("x-" + i for i in name.split("/")) try: return apk.open(prefixed_name) except IOError: pass # Look for it in archive files. for prefix, index in archives: if not name in index: continue afn = transfn(prefix + ".rpa") data = [] # Direct path. if len(index[name]) == 1: t = index[name][0] if len(t) == 2: offset, dlen = t start = b'' else: offset, dlen, start = t rv = SubFile(afn, offset, dlen, start) # Compatibility path. else: f = open(afn, "rb") for offset, dlen in index[name]: f.seek(offset) data.append(f.read(dlen)) rv = io.BytesIO(b''.join(data)) f.close() return rv if remote_files.has_key(name): raise DownloadNeeded(relpath=name, rtype=remote_files[name]['type'], size=remote_files[name]['size']) return None