From 4b6841a548e88a4de0a00519eeb9a99b083bb4c0 Mon Sep 17 00:00:00 2001 From: tcsenpai Date: Thu, 28 Mar 2024 13:48:51 +0100 Subject: [PATCH] added automatic launcher creator --- .gitignore | 3 +- libs/ulauncher_creator.py | 41 ++++++++++++++++++++++++++ uwine | 62 +++++++++++++++++++++++++++++++-------- 3 files changed, 93 insertions(+), 13 deletions(-) create mode 100644 libs/ulauncher_creator.py diff --git a/.gitignore b/.gitignore index 60820d7..cf44ba9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ __pycache__ test_launcher var -_not_needed_ \ No newline at end of file +_not_needed_ +launcher/launcher.uwine diff --git a/libs/ulauncher_creator.py b/libs/ulauncher_creator.py new file mode 100644 index 0000000..39eb57c --- /dev/null +++ b/libs/ulauncher_creator.py @@ -0,0 +1,41 @@ +def create_launcher( + game_id, + proton_path, + wine_prefix, + ulwgl_dir, + predirectives, + filepath, + postdirectives, + loaded_customvars, + use_wine +): + """ + Creates a launcher for the game + :param game_id: The game id + :param proton_path: The proton path + :param wine_prefix: The wine prefix + :param ulwgl_dir: The ulwgl dir + :param predirectives: The predirectives + :param filepath: The filepath + :param postdirectives: The postdirectives + :param loaded_customvars: The loaded custom vars + :param use_wine: If we are using wine or not + :return: None + """ + # Creating the launcher + launcher = f""" +# This file was created by ULWGL +PROTONPATH="{proton_path}" +USE_WINE="{use_wine}" +WINEPREFIX="{wine_prefix}" +GAMEID="{game_id}" +ULWGLDIR="{ulwgl_dir}" +PREDIRECTIVES="{predirectives}" +FILEPATH="{filepath}" +POSTDIRECTIVES="{postdirectives}" +CUSTOMVARS='{loaded_customvars}' +""" + + # Writing the launcher + with open(f"{ulwgl_dir}/launcher.uwine", "w") as file: + file.write(launcher) \ No newline at end of file diff --git a/uwine b/uwine index 1366fe9..6e9291e 100755 --- a/uwine +++ b/uwine @@ -17,6 +17,7 @@ import libs.predirectives_loader as predirectives_loader import libs.postdirectives_loader as postdirectives_loader import libs.ulwlg_runner as ulwlg_runner import libs.wine_runner as wine_runner +import libs.ulauncher_creator as ulauncher_creator # SECTION Constants LAUNCHDIR = os.getcwd() @@ -43,7 +44,11 @@ parser = argparse.ArgumentParser( epilog="https://github.com/thecookingsenpai/UWINE", ) parser.add_argument( - "filepath", help="Path to the file to be launched", type=str, nargs="?", default=None + "filepath", + help="Path to the file to be launched", + type=str, + nargs="?", + default=None, ) parser.add_argument( "-l", "--load", help="Load a specific env file", type=str, dest="envfile" @@ -62,7 +67,12 @@ parser.add_argument( "-u", "--ulwgl", dest="ulwlgdir", help="Path to the ULWGL installation" ) parser.add_argument( - "-a", "--additionalargs", dest="additionalargs", help="Additional arguments to be passed to the software (at the end, as a string)", type=str, default="" + "-a", + "--additionalargs", + dest="additionalargs", + help="Additional arguments to be passed to the software (at the end, as a string)", + type=str, + default="", ) parser.add_argument("-v", "--version", action="version", version="%(prog)s 0.1") @@ -76,7 +86,11 @@ if args.envfile: print("[*] Loading the env file: " + envfile) # Which is mandatory if not os.path.isfile(envfile): - print("[FATAL] env file not found: " + envfile + "\nTry to copy env.example to .env in your UWINE installation directory.") + print( + "[FATAL] env file not found: " + + envfile + + "\nTry to copy env.example to .env in your UWINE installation directory." + ) exit(1) dotenv.load_dotenv(dotenv_path=envfile) @@ -87,15 +101,15 @@ if os.environ["CUSTOMVARS"]: else: env_defined_customvars = {} -if os.environ["USE_WINE"]: - if os.environ["USE_WINE"] == "True": - use_wine = True - else: - use_wine = False +if "USE_WINE" not in os.environ: + use_wine = False +elif os.environ["USE_WINE"] == "True": + use_wine = True +else: + use_wine = False print("[INFO] [USE_WINE] " + str(use_wine)) - if __name__ == "__main__": # SECTION Loading methods ulwgl_dir = ulwgl_loader.set_ulwgldir(args.ulwlgdir, UWINEDIR) @@ -108,9 +122,12 @@ if __name__ == "__main__": os.environ["WINEPREFIX"] = wineprefix_loader.set_wineprefix( args.wineprefix, wine_prefix ) + original_filepath = args.filepath filepath = filepath_loader.set_filepath(args.filepath, LAUNCHDIR) # Directives support - predirectives = predirectives_loader.set_predirectives("") # Future support for postdirectives in cli + predirectives = predirectives_loader.set_predirectives( + "" + ) # Future support for postdirectives in cli postdirectives = postdirectives_loader.set_postdirectives(args.additionalargs) # SECTION Launching the game print("\n[*] Launching the game...") @@ -130,17 +147,38 @@ if __name__ == "__main__": ["PREDIRECTIVES", predirectives], ["FILEPATH", filepath], ["POSTDIRECTIVES", postdirectives], - ["CUSTOMVARS", loaded_customvars] + ["CUSTOMVARS", loaded_customvars], ], headers=["Variable", "Value"], tablefmt="fancy_grid", ) ) + print("[+] Creating the launcher...") + # Creating a launcher with all the variables in the table above + ulauncher_creator.create_launcher( + os.environ["GAMEID"], + os.environ["PROTONPATH"], + os.environ["WINEPREFIX"], + ulwgl_dir, + predirectives, + original_filepath, + postdirectives, + loaded_customvars, + use_wine, + ) + print("[+] Launcher created successfully at " + ulwgl_dir + "/launcher.uwine") + # Launching with ulwlg_runner or wine depending on the use_wine variable if use_wine: print("[*] Using Wine to launch the game") wine_runner.wine_run(filepath, os.environ["PROTONPATH"]) else: print("[*] Using ULWGL to launch the game") - ulwlg_runner.ulwlg_run(filepath, ulwgl_dir, os.environ["PROTONPATH"], os.environ["WINEPREFIX"], os.environ["GAMEID"]) \ No newline at end of file + ulwlg_runner.ulwlg_run( + filepath, + ulwgl_dir, + os.environ["PROTONPATH"], + os.environ["WINEPREFIX"], + os.environ["GAMEID"], + )