mirror of
https://github.com/tcsenpai/UWINE.git
synced 2025-06-07 03:55:21 +00:00
added automatic launcher creator
This commit is contained in:
parent
94c6c979db
commit
4b6841a548
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ __pycache__
|
|||||||
test_launcher
|
test_launcher
|
||||||
var
|
var
|
||||||
_not_needed_
|
_not_needed_
|
||||||
|
launcher/launcher.uwine
|
||||||
|
41
libs/ulauncher_creator.py
Normal file
41
libs/ulauncher_creator.py
Normal file
@ -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)
|
62
uwine
62
uwine
@ -17,6 +17,7 @@ import libs.predirectives_loader as predirectives_loader
|
|||||||
import libs.postdirectives_loader as postdirectives_loader
|
import libs.postdirectives_loader as postdirectives_loader
|
||||||
import libs.ulwlg_runner as ulwlg_runner
|
import libs.ulwlg_runner as ulwlg_runner
|
||||||
import libs.wine_runner as wine_runner
|
import libs.wine_runner as wine_runner
|
||||||
|
import libs.ulauncher_creator as ulauncher_creator
|
||||||
|
|
||||||
# SECTION Constants
|
# SECTION Constants
|
||||||
LAUNCHDIR = os.getcwd()
|
LAUNCHDIR = os.getcwd()
|
||||||
@ -43,7 +44,11 @@ parser = argparse.ArgumentParser(
|
|||||||
epilog="https://github.com/thecookingsenpai/UWINE",
|
epilog="https://github.com/thecookingsenpai/UWINE",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
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(
|
parser.add_argument(
|
||||||
"-l", "--load", help="Load a specific env file", type=str, dest="envfile"
|
"-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"
|
"-u", "--ulwgl", dest="ulwlgdir", help="Path to the ULWGL installation"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
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")
|
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)
|
print("[*] Loading the env file: " + envfile)
|
||||||
# Which is mandatory
|
# Which is mandatory
|
||||||
if not os.path.isfile(envfile):
|
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)
|
exit(1)
|
||||||
dotenv.load_dotenv(dotenv_path=envfile)
|
dotenv.load_dotenv(dotenv_path=envfile)
|
||||||
|
|
||||||
@ -87,15 +101,15 @@ if os.environ["CUSTOMVARS"]:
|
|||||||
else:
|
else:
|
||||||
env_defined_customvars = {}
|
env_defined_customvars = {}
|
||||||
|
|
||||||
if os.environ["USE_WINE"]:
|
if "USE_WINE" not in os.environ:
|
||||||
if os.environ["USE_WINE"] == "True":
|
use_wine = False
|
||||||
use_wine = True
|
elif os.environ["USE_WINE"] == "True":
|
||||||
else:
|
use_wine = True
|
||||||
use_wine = False
|
else:
|
||||||
|
use_wine = False
|
||||||
print("[INFO] [USE_WINE] " + str(use_wine))
|
print("[INFO] [USE_WINE] " + str(use_wine))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# SECTION Loading methods
|
# SECTION Loading methods
|
||||||
ulwgl_dir = ulwgl_loader.set_ulwgldir(args.ulwlgdir, UWINEDIR)
|
ulwgl_dir = ulwgl_loader.set_ulwgldir(args.ulwlgdir, UWINEDIR)
|
||||||
@ -108,9 +122,12 @@ if __name__ == "__main__":
|
|||||||
os.environ["WINEPREFIX"] = wineprefix_loader.set_wineprefix(
|
os.environ["WINEPREFIX"] = wineprefix_loader.set_wineprefix(
|
||||||
args.wineprefix, wine_prefix
|
args.wineprefix, wine_prefix
|
||||||
)
|
)
|
||||||
|
original_filepath = args.filepath
|
||||||
filepath = filepath_loader.set_filepath(args.filepath, LAUNCHDIR)
|
filepath = filepath_loader.set_filepath(args.filepath, LAUNCHDIR)
|
||||||
# Directives support
|
# 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)
|
postdirectives = postdirectives_loader.set_postdirectives(args.additionalargs)
|
||||||
# SECTION Launching the game
|
# SECTION Launching the game
|
||||||
print("\n[*] Launching the game...")
|
print("\n[*] Launching the game...")
|
||||||
@ -130,17 +147,38 @@ if __name__ == "__main__":
|
|||||||
["PREDIRECTIVES", predirectives],
|
["PREDIRECTIVES", predirectives],
|
||||||
["FILEPATH", filepath],
|
["FILEPATH", filepath],
|
||||||
["POSTDIRECTIVES", postdirectives],
|
["POSTDIRECTIVES", postdirectives],
|
||||||
["CUSTOMVARS", loaded_customvars]
|
["CUSTOMVARS", loaded_customvars],
|
||||||
],
|
],
|
||||||
headers=["Variable", "Value"],
|
headers=["Variable", "Value"],
|
||||||
tablefmt="fancy_grid",
|
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
|
# Launching with ulwlg_runner or wine depending on the use_wine variable
|
||||||
if use_wine:
|
if use_wine:
|
||||||
print("[*] Using Wine to launch the game")
|
print("[*] Using Wine to launch the game")
|
||||||
wine_runner.wine_run(filepath, os.environ["PROTONPATH"])
|
wine_runner.wine_run(filepath, os.environ["PROTONPATH"])
|
||||||
else:
|
else:
|
||||||
print("[*] Using ULWGL to launch the game")
|
print("[*] Using ULWGL to launch the game")
|
||||||
ulwlg_runner.ulwlg_run(filepath, ulwgl_dir, os.environ["PROTONPATH"], os.environ["WINEPREFIX"], os.environ["GAMEID"])
|
ulwlg_runner.ulwlg_run(
|
||||||
|
filepath,
|
||||||
|
ulwgl_dir,
|
||||||
|
os.environ["PROTONPATH"],
|
||||||
|
os.environ["WINEPREFIX"],
|
||||||
|
os.environ["GAMEID"],
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user