def save_and_sync_next_step(old_set): name_set = None start_time = time.time() stop = False while not stop: print 'finding save...' dir = save.get_save_dir() listing = list_saves(dir) new_set = set(listing) name_set = new_set - old_set if not name_set: for name in listing: mtime = os.path.getmtime(os.path.join(dir, name)) if mtime > start_time: stop = True break time.sleep(0.5) else: stop = True name = iter(name_set).next() break print 'found save', name time.sleep(0.5) ui.execute_later( lambda: upload_save(save.get_save_dir() + '/' + name, name))
def main(size=None, init=True): features.FEATURE_FILE_PATH = os.path.join(save.get_save_dir(), 'features') features.parse_options() setup_game_version() setup_android_version() setup_errors() size = size or check_force_size() maybe_start_remote_debug() monitor.start() client.window.init_screen(size) osutil.init() ui.init() ui.set_fill_image(None) unpack_data() ui.set_fill_image(pygame.image.load('data/user/background.jpg')) setup_freeciv_config() client.window.init() gamescreen.init() start_autoupdate() if init: client.freeciv.run() else: client_main()
def setup_freeciv_config(): path = os.environ['FREECIV_OPT'] = save.get_save_dir() + '/civrc-2.3-1' try: if not os.path.exists(path): shutil.copy('data/civrc-2.3-default', path) except (IOError, OSError): pass
def get_resume_data(): try: content = open(pause_file).read() except IOError: return None else: return os.path.join(save.get_save_dir(), 'pause_save.sav.gz')
def main(): features.FEATURE_FILE_PATH = os.path.join(save.get_save_dir(), 'features') features.parse_options() setup_game_version() setup_android_version() setup_errors() maybe_start_remote_debug() monitor.start() save.start_zygote() client.window.init_screen() osutil.init() ui.init() ui.set_fill_image(graphics.load_image('data/user/background.jpg')) setup_freeciv_config() client.window.init() gamescreen.init() start_autoupdate() start_marketnotice() client.freeciv.run()
def get_install_time(): path = os.path.join(save.get_save_dir(), 'install_time') try: return int(open(path).read()) except (IOError, ValueError): install_time = int(time.time() * 1000) with open(path, 'w') as f: f.write('%d' % install_time) return install_time
def comment_upload(install_time): ui.execute_later(lambda: ui.message('Compressing log...')) content = lzma.compress(open(save.get_save_dir() + '/more.log').read()) ui.execute_later(lambda: ui.back()) request(lambda result: comment_next(install_time), 'upload_log', content, install_time, banner="Uploading log (%dkB)" % (len(content)/1024))
def client(): global session if not session: try: sessid = open(save.get_save_dir() + '/civsync.sessid.txt').read().strip() except IOError: sessid = None session = civsync.Session(sessid) return session
def comment_upload(install_time): ui.execute_later(lambda: ui.message('Compressing log...')) content = lzma.compress(open(save.get_save_dir() + '/more.log').read()) ui.execute_later(lambda: ui.back()) request(lambda result: comment_next(install_time), 'upload_log', content, install_time, banner="Uploading log (%dkB)" % (len(content) / 1024))
def downloaded(data): ui.set_dialog(ui.Label('Loading save...')) uncompressed = lzma.decompress(data) print 'Uncompressed size', len(uncompressed) dl_path = save.get_save_dir() + '/downloaded_save' try: os.remove(dl_path) except OSError: print 'not removed...' with open(dl_path, 'wb') as f: f.write(uncompressed) ui.back(anim=False) save.load_game(dl_path)
def downloaded(data): ui.set_dialog(ui.Label("Loading save...")) uncompressed = lzma.decompress(data) print "Uncompressed size", len(uncompressed) dl_path = save.get_save_dir() + "/downloaded_save" try: os.remove(dl_path) except OSError: print "not removed..." with open(dl_path, "wb") as f: f.write(uncompressed) ui.back(anim=False) save.load_game(dl_path)
def save_and_sync_next_step(old_set): name_set = None start_time = time.time() stop = False while not stop: print 'finding save...' dir = save.get_save_dir() listing = list_saves(dir) new_set = set(listing) name_set = new_set - old_set if not name_set: for name in listing: mtime = os.path.getmtime(os.path.join(dir, name)) if mtime > start_time: stop = True break time.sleep(0.5) else: stop = True name = iter(name_set).next() break print 'found save', name time.sleep(0.5) ui.execute_later.append(lambda: upload_save(save.get_save_dir() + '/' + name, name))
def comment_upload(install_time): with ui.execute_later_lock: ui.execute_later.append(lambda: ui.message("Compressing log...")) content = lzma.compress(open(save.get_save_dir() + "/more.log").read()) with ui.execute_later_lock: ui.execute_later.append(lambda: ui.back()) request( lambda result: comment_next(install_time), "upload_log", content, install_time, banner="Uploading log (%dkB)" % (len(content) / 1024), )
def pause(): if client.client: print 'pause occured' print 'saving game' client.client.chat('/save %s/pause_save.sav.gz' % save.get_save_dir()) with open(pause_file, 'w') as f: f.write('version=1\n') time.sleep(featues.get('app.shutdown')) if not osutil.is_paused(): remove_pause_file() return print 'turning off server' client.client.disconnect() ui.back(allow_override=False) osutil.wait_for_resume() resume() else: osutil.wait_for_resume()
def pause(): if client.client: print "pause occured" print "saving game" client.client.chat("/save %s/pause_save.sav.gz" % save.get_save_dir()) with open(pause_file, "w") as f: f.write("version=1\n") time.sleep(features.get("app.shutdown")) if not osutil.is_paused(): remove_pause_file() return print "turning off server" client.client.disconnect() ui.back(allow_override=False) osutil.wait_for_resume() resume() else: osutil.wait_for_resume()
def pause(): if client.client: print 'pause occured' print 'saving game' client.client.chat('/save %s/pause_save.sav.gz' % save.get_save_dir()) with open(pause_file, 'w') as f: f.write('version=1\n') time.sleep(features.get('app.shutdown')) if not osutil.is_paused(): remove_pause_file() return print 'turning off server' client.client.disconnect() ui.back(allow_override=False) osutil.wait_for_resume() resume() else: osutil.wait_for_resume()
features.add_feature('app.autoupdate', default=True, type=bool) features.add_feature('app.forcesize') features.add_feature('app.resume', default=True, type=bool) features.add_feature('app.profile', default=False, type=bool) features.add_feature('app.shutdown', default=10, type=int) features.add_feature('app.multiplayer', default=False, type=bool) def apply_hardexit(t): client.freeciv.hard_exit = t features.set_applier('app.hardexit', apply_hardexit, type=bool, default=True) main_menu = None main_menu_update_shown = False pause_file = os.path.join(save.get_save_dir(), 'pause_options') def client_main(): action = sys.argv[1] if sys.argv[1:] else None if try_resume(): ui.main() return if action == 'load': savename = sys.argv[2] save.load_game(savename) elif action == 'connect': host, port = sys.argv[2:] save.connect(host, int(port)) else: show_main_menu()
def logged(result): print 'Login successful' with open(save.get_save_dir() + '/civsync.sessid.txt', 'w') as f: f.write(session.sessid) callback()
def save_and_sync(client): old_set = set(list_saves(save.get_save_dir())) client.chat('/save') ui.back() threading.Thread(target=save_and_sync_next_step, args=(old_set, )).start()
features.add_feature('debug.dsn', default=DESK_DSN if osutil.is_desktop else ANDR_DSN, type=bool) def apply_hardexit(t): client.freeciv.hard_exit = t features.set_applier('app.hardexit', apply_hardexit, type=bool, default=True) main_menu = None main_menu_update_shown = False pause_file = os.path.join(save.get_save_dir(), 'pause_options') def client_main(): if try_resume(): ui.main() return ui.set(ui.Label('loading...')) ui.execute_later(app_main) if features.get('app.profile'): profile_main() else: ui.main()
def get_download_path(): return _save.get_save_dir() + '/from-dropbox.sav'
def logged(result): print "Login successful" with open(save.get_save_dir() + "/civsync.sessid.txt", "w") as f: f.write(session.sessid) ui.back(anim=False) callback()