def save_and_quit(): io.output("Bye.") # Return from the system world if we are in it if hasattr(game, "currentworld") and game.currentworld: game.world = game.currentworld if game.playing and app.config["main.save_on_exit"]: filename = game.save() io.output("--- Your game has been saved. ---") app.config["main.last_game_save"] = filename app.quit()
def main(): try: opts, args = getopt.getopt(sys.argv[1:], "hl:w:", ["help", "load=", "world="]) except getopt.GetoptError: # print help information and exit: usage() app.quit() worldsource = None worldobj = None for option, argument in opts: if option in ("-h", "--help"): usage() app.quit() elif option in ("-w", "--world"): try: worldobj = world.load(load_world(argument)) except error.VersionError, e: io.errormsg("This world file requires a newer version (%s) of this game." % e.required) app.quit() elif option in ("-l", "--load"): try: worldobj = game.load(argument) except error.VersionError, e: io.errormsg("This save file was made using a different version (%s) of this game." % e.required) app.quit()
usage() app.quit() elif option in ("-w", "--world"): try: worldobj = world.load(load_world(argument)) except error.VersionError, e: io.errormsg("This world file requires a newer version (%s) of this game." % e.required) app.quit() elif option in ("-l", "--load"): try: worldobj = game.load(argument) except error.VersionError, e: io.errormsg("This save file was made using a different version (%s) of this game." % e.required) app.quit() except error.FileFormatError, e: io.errormsg(e.message) app.quit() if not worldobj: if app.config["main.last_game_save"]: game.output("--- Resuming your previous game. ---") worldobj = game.load(app.config["main.last_game_save"]) else: # Temporarily default to ocean. In the future, there will be a chooser in the system world. worldobj = world.load(load_world("ocean")) init(worldobj) if __name__ == "__main__": main()
def wiz_execute(wiz): # Connect if wiz.fields["storagetype"].value == _("Local Folder"): store = FolderStore("store", 0, False, wiz.fields["folderpath"].value) elif wiz.fields["storagetype"].value == _("FTP Server"): server = wiz.fields["ftpserver"].value login = wiz.fields["ftplogin"].value password = wiz.fields["ftppassword"].value root = wiz.fields["ftproot"].value sftp = wiz.fields["sftp"].value store = FTPStore("store", 0, False, server, root, login, password, sftp) elif wiz.fields["storagetype"].value == _("DropBox"): login = wiz.fields["dblogin"].value password = wiz.fields["dbpassword"].value root = wiz.fields["dbroot"].value store = DropBoxStore("store", 0, False, root, login, password) elif wiz.fields["storagetype"].value == _("Server Share"): mountcmd = wiz.fields["mountcmd"].value umountcmd = wiz.fields["umountcmd"].value shareroot = wiz.fields["shareroot"].value store = ShareStore("store", 0, False, shareroot, mountcmd, umountcmd) else: raise Exception("Internal error: bad store type") log.debug("Store = ", store) # In case we need to revert our config later orig_config = Config.get_config() try: store.connect() folders = [] # List all backups backups = store.list(".") for backup in backups: # Make sure its not a system folder if backup[0] != "_": try: runs = store.list(backup + "/") for run in runs: folders.append((backup, run)) except: pass log.debug("Folders", folders) if len(folders) == 0: raise Exception(_("There are no backup runs in this store")) # Sort them based on the path name folders.sort(key=lambda item: item[1], reverse=True) # Now the first item is the one to use (as it is the most recent). backupname, backuprun = folders[0] config = os.path.join(backupname, backuprun, const.ConfigName) configenc = config + const.EncryptionSuffix # Check if the config exists. if store.exists(config): src = config encrypted = False elif store.exists(configenc): src = configenc encrypted = True else: raise Exception(_("The backup runs are missing or corrupt (no config files)")) if not encrypted: store.get(src, const.ConfigDir+os.sep) else: # Fetch the file. enc_file = const.ConfigFile + const.EncryptionSuffix clear_file = const.ConfigFile store.get(src, const.ConfigDir+os.sep) # ENCRYPTED bad = True # keep going until we get a good password while bad: password = GetPassword(wiz, backupname, backuprun) if password == None: # User is quitting return # Lets check the file is good. try: log.debug("Decrypting", enc_file, clear_file, password) ret = cryptor.decrypt_file(password, enc_file, clear_file) log.debug("Return from decrypt", ret) if ret != 0: raise Exception(_("Failed encryption")) bad = False if os.path.exists(enc_file): os.remove(enc_file) # Looks like this password is a good one. except: log.info("Invalid backup password") dlg.Warn(wiz, _("Invalid password. Please enter the correct backup password.")) os.remove(clear_file) # Revert the old config orig_config.save() dlg.Info(wiz, _("Your configuration has been restored.\nClick OK to restart the UI..."), _("Restore")) python = sys.executable log.debug("Starting:", const.UIProgram) subprocess.Popen(const.UIProgram) app.quit() except Exception as e: dlg.Warn(wiz, str(e), _("Configuration restore failed")) finally: store.disconnect()