Exemplo n.º 1
0
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))
Exemplo n.º 2
0
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()
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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')
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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()
Exemplo n.º 7
0
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')
Exemplo n.º 8
0
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()
Exemplo n.º 9
0
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()
Exemplo n.º 10
0
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
Exemplo n.º 11
0
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
Exemplo n.º 12
0
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))
Exemplo n.º 13
0
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
Exemplo n.º 14
0
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))
Exemplo n.º 15
0
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
Exemplo n.º 16
0
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)
Exemplo n.º 17
0
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)
Exemplo n.º 18
0
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)
Exemplo n.º 19
0
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))
Exemplo n.º 20
0
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),
    )
Exemplo n.º 21
0
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()
Exemplo n.º 22
0
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()
Exemplo n.º 23
0
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()
Exemplo n.º 24
0
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()
Exemplo n.º 25
0
 def logged(result):
     print 'Login successful'
     with open(save.get_save_dir() + '/civsync.sessid.txt', 'w') as f:
         f.write(session.sessid)
     callback()
Exemplo n.º 26
0
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()
Exemplo n.º 27
0
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()
Exemplo n.º 28
0
def get_download_path():
    return _save.get_save_dir() + '/from-dropbox.sav'
Exemplo n.º 29
0
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()
Exemplo n.º 30
0
def get_download_path():
    return _save.get_save_dir() + '/from-dropbox.sav'
Exemplo n.º 31
0
 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()
Exemplo n.º 32
0
 def logged(result):
     print 'Login successful'
     with open(save.get_save_dir() + '/civsync.sessid.txt', 'w') as f:
         f.write(session.sessid)
     callback()