示例#1
0
def overwrite_rf_location(value):
    result = False
    if Path(value).exists() and Path(
            value).is_dir() and Path(value) != Path('.'):
        AppSettings.rf_overwrite_location = Path(value).as_posix()
        RfactorLocation.overwrite_location(AppSettings.rf_overwrite_location)
        logging.warning('Overwriting rf2 location: %s', Path(value).as_posix())
        result = True
    else:
        logging.warning('Overwriting rf2 location cleared!')
        AppSettings.rf_overwrite_location = ''
        RfactorLocation.overwrite_location(None)

    AppSettings.save()
    return result
示例#2
0
def run_rfactor(server_info: Optional[dict] = None, method: Optional[int] = 0):
    logging.info('UI requested rF2 run with method: %s', method)
    if server_info and server_info.get('password_remember'):
        # -- Store password if remember option checked
        logging.info('Storing password for Server %s', server_info.get('id'))
        AppSettings.server_passwords[server_info.get('id')] = server_info.get(
            'password')
        AppSettings.save()
    elif server_info and not server_info.get('password_remember'):
        # -- Delete password if remember option unchecked
        if server_info.get('id') in AppSettings.server_passwords:
            AppSettings.server_passwords.pop(server_info.get('id'))
            AppSettings.save()

    rf, result = RfactorPlayer(), False
    if rf.is_valid:
        result = rf.run_rfactor(method, server_info)

    return json.dumps({'result': result, 'msg': rf.error})
示例#3
0
def server_favourite(server_info, add: bool = True):
    if not server_info.get('id'):
        return json.dumps({'result': False})

    # -- Add favourite
    if add:
        logging.debug('Adding Server favourite = %s %s', server_info.get('id'),
                      add)
        if server_info.get('id') not in AppSettings.server_favourites:
            AppSettings.server_favourites.append(server_info.get('id'))
        AppSettings.save()
        return json.dumps({
            'result': True,
            'data': AppSettings.server_favourites
        })

    # -- Remove favourite
    if server_info.get('id') in AppSettings.server_favourites:
        logging.debug('Removing Server favourite = %s %s',
                      server_info.get('id'), add)
        AppSettings.server_favourites.remove(server_info.get('id'))
        AppSettings.save()

    return json.dumps({'result': True, 'data': AppSettings.server_favourites})
示例#4
0
def restore_backup():
    rf = RfactorPlayer()

    if not rf.is_valid:
        return json.dumps({'result': False, 'msg': rf.error})

    if AppSettings.restore_backup(rf):
        logging.info('Original settings restored!')
        return json.dumps({'result': True, 'msg': 'BackUp files restored!'})

    return json.dumps({
        'result':
        False,
        'msg':
        'Could not restore all back up files! Make sure you '
        'did not deleted any *.original files!'
    })
示例#5
0
def start_eel():
    logging.info('\n\n\n')
    logging.info('#######################################################')
    logging.info('################ Starting APP               ###########')
    logging.info('#######################################################\n\n\n')

    if FROZEN:
        # Set Exception hook
        sys.excepthook = AppExceptionHook.exception_hook

    AppSettings.load()
    AppSettings.copy_default_presets()
    AppSettings.delete_current_settings_presets()

    # This will ask for and re-run with admin rights
    # if setting needs_admin set.
    if AppSettings.needs_admin and not run_as_admin():
        return

    """
        THIS WILL DISABLE ctypes support! But it will make sure "Launch rFactor2" 
        or basically any executable that is loading DLLs will work.
    """
    if sys.platform == "win32":
        import ctypes
        ctypes.windll.kernel32.SetDllDirectoryA(None)
    """
        //
    """
    page = 'index.html'
    host = 'localhost'
    port = 8123
    eel.init('web')

    # TODO: fetch OSError port in use
    try:
        eel.start(page, host=host, port=port, block=False)
    except EnvironmentError:
        # If Chrome isn't found, fallback to Microsoft Edge on Win10 or greater
        if sys.platform in ['win32', 'win64'] and int(platform.release()) >= 10:
            eel.start(page, mode='edge', host=host, port=port, block=False)
        # Fallback to opening a regular browser window
        else:
            eel.start(page, mode=None, app_mode=False, host=host, port=port, block=False)
            # Open system default web browser
            webbrowser.open_new(f'http://{host}:{port}')

    # -- Game Controller Greenlet
    cg = eel.spawn(controller_greenlet)

    # -- Headlights Greenlet
    hg = eel.spawn(headlights_greenlet)

    # -- rFactor Greenlet
    rg = eel.spawn(rfactor_greenlet)

    # -- Run until window/tab closed
    while not CLOSE_EVENT.is_set():
        # Game controller event loop
        controller_event_loop()
        # rFactor 2 event loop
        rfactor_event_loop()
        # Capture exception events
        AppExceptionHook.exception_event_loop()
        test_exception()

    # -- Shutdown Greenlets
    logging.debug('Shutting down Greenlets.')
    gevent.joinall((cg, hg, rg), timeout=15.0)

    # -- Shutdown logging
    logging.info('\n\n\n')
    logging.info('#######################################################')
    logging.info('################ APP SHUTDOWN               ###########')
    logging.info('#######################################################\n\n\n')
    logging.shutdown()
示例#6
0
def save_server_browser_settings(server_browser: dict):
    AppSettings.server_browser.update(server_browser)
    if AppSettings.save():
        logging.debug('Updated Server Browser settings.')
        return json.dumps({'result': True})
    return json.dumps({'result': False})
示例#7
0
def reset_admin():
    AppSettings.needs_admin = False
    AppSettings.save()

    request_close()
示例#8
0
def re_run_admin():
    AppSettings.needs_admin = True
    AppSettings.save()

    if not run_as_admin():
        request_close()