import os
import json
import appdirs

app_name = 'FinnWarsLauncher'
author_name = 'NikkeDoy, NuffMan'
default_server_address = "23.88.63.235:14572"
default_username = "FinnWarsLauncher"

def save_preferences(data):
    config_dir = appdirs.user_config_dir(app_name, author_name)
    os.makedirs(config_dir, exist_ok=True)
    file_path = os.path.join(config_dir, 'config.json')
    with open(file_path, 'w') as f:
        json.dump(data, f)

def get_preferences():
    config_dir = appdirs.user_config_dir(app_name, author_name)
    file_path = os.path.join(config_dir, 'config.json')
    if(os.path.isfile(file_path)):
        with open(file_path, 'r') as f:
            return json.load(f)
    else:
        return {"server": default_server_address, "username": default_username}
