#!/usr/bin/env python3
import sys
import os
import argparse
import shutil
from os.path import realpath, dirname, normpath

APPLICATION_NAME = "Minigalaxy"

LAUNCH_PATH = dirname(realpath(__file__))
if os.path.isdir(os.path.join(LAUNCH_PATH, "../minigalaxy")):
    SOURCE_PATH = normpath(os.path.join(LAUNCH_PATH, '..'))
    sys.path.insert(0, SOURCE_PATH)
    os.chdir(SOURCE_PATH)

from minigalaxy.version import VERSION
from minigalaxy.paths import CONFIG_DIR, CACHE_DIR

def conf_reset():
    shutil.rmtree(CONFIG_DIR, ignore_errors=True)
    shutil.rmtree(CACHE_DIR, ignore_errors=True)

def cli_params():
    parser = argparse.ArgumentParser(description="A simple GOG Linux client")

    parser.add_argument("--reset",
        dest="reset", action="store_true", 
        help="reset the configuration of Minigalaxy")
    parser.add_argument("-v", "--version",
        action="version", version=VERSION)

    return parser.parse_args()

def main():
    cli_args = cli_params()

    if cli_args.reset: conf_reset()

    # Import the gi module after parsing arguments
    from minigalaxy.ui.gtk import Gtk
    from minigalaxy.ui import Window

    # Start the application
    window = Window(APPLICATION_NAME)
    window.connect("destroy", Gtk.main_quit)
    Gtk.main()


if __name__ == "__main__":
    main()
