def load(filename): """ Loads persistence data from `filename`. Returns None if the data could not be loaded, or a Persistent object if it could be loaded. """ if not os.path.exists(filename): return None # Unserialize the persistent data. try: f = open(filename, "rb") s = f.read().decode("zlib") f.close() persistent = loads(s) except: import renpy.display try: renpy.display.log.write("Loading persistent.") renpy.display.log.exception() except: pass return None persistent._update() return persistent
def load(filename): """ Loads persistence data from `filename`. Returns None if the data could not be loaded, or a Persistent object if it could be loaded. """ if not os.path.exists(filename): return None # Unserialize the persistent data. try: f = file(filename, "rb") s = f.read().decode("zlib") f.close() persistent = loads(s) except: import renpy.display try: renpy.display.log.write("Loading persistent.") renpy.display.log.exception() except: pass return None persistent._update() return persistent
def MultiPersistent(name): name = renpy.exports.fsencode(name) if not renpy.game.context().init_phase: raise Exception( "MultiPersistent objects must be created during the init phase.") if renpy.android: files = [ os.path.join(os.environ['ANDROID_OLD_PUBLIC'], '../RenPy/Persistent') ] elif renpy.ios: raise Exception("MultiPersistent is not supported on iOS.") elif renpy.windows: files = [os.path.expanduser("~/RenPy/Persistent")] if 'APPDATA' in os.environ: files.append(os.environ['APPDATA'] + "/RenPy/persistent") elif renpy.macintosh: files = [ os.path.expanduser("~/.renpy/persistent"), os.path.expanduser("~/Library/RenPy/persistent") ] else: files = [os.path.expanduser("~/.renpy/persistent")] if "RENPY_MULTIPERSISTENT" in os.environ: files = [os.environ["RENPY_MULTIPERSISTENT"]] # Make the new persistent directory, why not? try: os.makedirs(files[-1]) except: pass fn = "" # prevent a warning from happening. # Find the first file that actually exists. Otherwise, use the last # file. for fn in files: fn = fn + "/" + name if os.path.exists(fn): break try: rv = loads(open(fn, "rb").read()) except: rv = _MultiPersistent() rv._filename = fn # W0201 return rv
def MultiPersistent(name): name = renpy.exports.fsencode(name) if not renpy.game.context().init_phase: raise Exception( "MultiPersistent objects must be created during the init phase.") if renpy.android or renpy.ios: # Due to the security policy of mobile devices, we store MultiPersistent # in the same place as common persistent. # This is better than not working at all. files = [renpy.config.savedir] elif renpy.windows: files = [os.path.expanduser("~/RenPy/Persistent")] if 'APPDATA' in os.environ: files.append(os.environ['APPDATA'] + "/RenPy/persistent") elif renpy.macintosh: files = [ os.path.expanduser("~/.renpy/persistent"), os.path.expanduser("~/Library/RenPy/persistent") ] else: files = [os.path.expanduser("~/.renpy/persistent")] if "RENPY_MULTIPERSISTENT" in os.environ: files = [os.environ["RENPY_MULTIPERSISTENT"]] # Make the new persistent directory, why not? try: os.makedirs(files[-1]) except: pass fn = "" # prevent a warning from happening. # Find the first file that actually exists. Otherwise, use the last # file. for fn in files: fn = fn + "/" + name if os.path.exists(fn): break try: rv = loads(open(fn, "rb").read()) except: rv = _MultiPersistent() rv._filename = fn # W0201 return rv
def MultiPersistent(name): name = renpy.exports.fsencode(name) if not renpy.game.context().init_phase: raise Exception("MultiPersistent objects must be created during the init phase.") if renpy.android: files = [ os.path.join(os.environ['ANDROID_OLD_PUBLIC'], '../RenPy/Persistent') ] elif renpy.ios: raise Exception("MultiPersistent is not supported on iOS.") elif renpy.windows: files = [ os.path.expanduser("~/RenPy/Persistent") ] if 'APPDATA' in os.environ: files.append(os.environ['APPDATA'] + "/RenPy/persistent") elif renpy.macintosh: files = [ os.path.expanduser("~/.renpy/persistent"), os.path.expanduser("~/Library/RenPy/persistent") ] else: files = [ os.path.expanduser("~/.renpy/persistent") ] if "RENPY_MULTIPERSISTENT" in os.environ: files = [ os.environ["RENPY_MULTIPERSISTENT"] ] # Make the new persistent directory, why not? try: os.makedirs(files[-1]) except: pass fn = "" # prevent a warning from happening. # Find the first file that actually exists. Otherwise, use the last # file. for fn in files: fn = fn + "/" + name if os.path.exists(fn): break try: rv = loads(file(fn, "rb").read()) except: rv = _MultiPersistent() rv._filename = fn # W0201 return rv
def load_persistent(): """ Loads the persistent data from disk. """ # Unserialize the persistent data. try: f = file(renpy.config.savedir + "/persistent", "rb") s = f.read().decode("zlib") f.close() persistent = loads(s) except: persistent = Persistent() update_persistent(persistent) return persistent
def load(filename): """ Loads persistence data from `filename`. Returns None if the data could not be loaded, or a Persistent object if it could be loaded. """ # Unserialize the persistent data. try: f = file(filename, "rb") s = f.read().decode("zlib") f.close() persistent = loads(s) except: return None persistent._update() return persistent
def MultiPersistent(name): if not renpy.game.context().init_phase: raise Exception( "MultiPersistent objects must be created during the init phase.") if renpy.windows: files = [os.path.expanduser("~/RenPy/Persistent")] if 'APPDATA' in os.environ: files.append(os.environ['APPDATA'] + "/RenPy/persistent") elif renpy.macintosh: files = [ os.path.expanduser("~/.renpy/persistent"), os.path.expanduser("~/Library/RenPy/persistent") ] else: files = [os.path.expanduser("~/.renpy/persistent")] # Make the new persistent directory, why not? try: os.makedirs(files[-1]) except: pass fn = "" # prevent a warning from happening. # Find the first file that actually exists. Otherwise, use the last # file. for fn in files: fn = fn + "/" + name if os.path.exists(fn): break try: rv = loads(file(fn).read()) except: rv = _MultiPersistent() rv._filename = fn # W0201 return rv
def MultiPersistent(name): if not renpy.game.context().init_phase: raise Exception("MultiPersistent objects must be created during the init phase.") if renpy.windows: files = [ os.path.expanduser("~/RenPy/Persistent") ] if 'APPDATA' in os.environ: files.append(os.environ['APPDATA'] + "/RenPy/persistent") elif renpy.macintosh: files = [ os.path.expanduser("~/.renpy/persistent"), os.path.expanduser("~/Library/RenPy/persistent") ] else: files = [ os.path.expanduser("~/.renpy/persistent") ] # Make the new persistent directory, why not? try: os.makedirs(files[-1]) except: pass fn = "" # prevent a warning from happening. # Find the first file that actually exists. Otherwise, use the last # file. for fn in files: fn = fn + "/" + name if os.path.exists(fn): break try: rv = loads(file(fn).read()) except: rv = _MultiPersistent() rv._filename = fn # W0201 return rv
def MultiPersistent(name, save_on_quit=False): name = renpy.exports.fsdecode(name) if not renpy.game.context().init_phase: raise Exception( "MultiPersistent objects must be created during the init phase.") if renpy.android or renpy.ios: # Due to the security policy of mobile devices, we store MultiPersistent # in the same place as common persistent. # This is better than not working at all. files = [renpy.config.savedir] elif renpy.windows: files = [os.path.expanduser("~/RenPy/Persistent")] if 'APPDATA' in os.environ: files.append( renpy.exports.fsdecode(os.environ['APPDATA']) + "/RenPy/persistent") elif renpy.macintosh: files = [ os.path.expanduser("~/.renpy/persistent"), os.path.expanduser("~/Library/RenPy/persistent") ] else: files = [os.path.expanduser("~/.renpy/persistent")] if "RENPY_MULTIPERSISTENT" in os.environ: files = [renpy.exports.fsdecode(os.environ["RENPY_MULTIPERSISTENT"])] # Make the new persistent directory, why not? try: os.makedirs(files[-1]) # type: ignore except: pass fn = "" # prevent a warning from happening. data = None # Find the first file that actually exists. Otherwise, use the last # file. for fn in files: fn = os.path.join(fn, name) # type: ignore if os.path.isfile(fn): try: data = open(fn, "rb").read() break except: pass rv = _MultiPersistent() if data is not None: try: rv = loads(data) except: renpy.display.log.write("Loading MultiPersistent at %r:" % fn) renpy.display.log.exception() rv._filename = fn if save_on_quit: save_MP_instances.add(rv) return rv