2022-09-08 04:42:07 +12:00
|
|
|
import multiprocessing
|
2021-04-15 01:14:06 +12:00
|
|
|
import os
|
2022-09-06 06:18:40 +12:00
|
|
|
import pathlib
|
|
|
|
import sys
|
2021-04-09 21:36:27 +12:00
|
|
|
from argparse import ArgumentParser
|
2021-04-18 06:00:15 +12:00
|
|
|
|
2021-03-26 10:58:32 +13:00
|
|
|
|
2021-03-26 10:52:36 +13:00
|
|
|
def main():
|
2021-09-14 08:44:59 +12:00
|
|
|
# fix cx_freeze
|
|
|
|
multiprocessing.freeze_support()
|
|
|
|
|
2021-12-08 09:49:15 +13:00
|
|
|
# insert legendary for installed via pip/setup.py submodule to path
|
2022-04-19 02:51:51 +12:00
|
|
|
# if not __name__ == "__main__":
|
|
|
|
# sys.path.insert(0, os.path.join(os.path.dirname(__file__), "legendary"))
|
2021-09-06 08:00:14 +12:00
|
|
|
|
2021-09-14 08:44:59 +12:00
|
|
|
# CLI Options
|
2021-04-09 21:36:27 +12:00
|
|
|
parser = ArgumentParser()
|
2021-12-24 22:09:50 +13:00
|
|
|
parser.add_argument(
|
|
|
|
"-V", "--version", action="store_true", help="Shows version and exits"
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-S",
|
|
|
|
"--silent",
|
|
|
|
action="store_true",
|
|
|
|
help="Launch Rare in background. Open it from System Tray Icon",
|
|
|
|
)
|
2021-06-21 07:07:56 +12:00
|
|
|
parser.add_argument("--debug", action="store_true", help="Launch in debug mode")
|
2021-12-24 22:09:50 +13:00
|
|
|
parser.add_argument(
|
|
|
|
"--offline", action="store_true", help="Launch Rare in offline mode"
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--test-start", action="store_true", help="Quit immediately after launch"
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--desktop-shortcut",
|
|
|
|
action="store_true",
|
|
|
|
dest="desktop_shortcut",
|
|
|
|
help="Use this, if there is no link on desktop to start Rare",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--startmenu-shortcut",
|
|
|
|
action="store_true",
|
|
|
|
dest="startmenu_shortcut",
|
|
|
|
help="Use this, if there is no link in start menu to launch Rare",
|
|
|
|
)
|
2021-04-14 02:56:44 +12:00
|
|
|
subparsers = parser.add_subparsers(title="Commands", dest="subparser")
|
|
|
|
|
2022-09-02 22:17:05 +12:00
|
|
|
launch_minimal_parser = subparsers.add_parser("start", aliases=["launch"])
|
2022-05-15 11:25:13 +12:00
|
|
|
launch_minimal_parser.add_argument("app_name", help="AppName of the game to launch",
|
|
|
|
metavar="<App Name>", action="store")
|
2022-05-19 09:41:48 +12:00
|
|
|
launch_minimal_parser.add_argument("--offline", help="Launch game offline",
|
|
|
|
action="store_true")
|
|
|
|
launch_minimal_parser.add_argument('--wine-bin', dest='wine_bin', action='store', metavar='<wine binary>',
|
2022-09-02 22:17:05 +12:00
|
|
|
default=os.environ.get('LGDRY_WINE_BINARY', None),
|
|
|
|
help='Set WINE binary to use to launch the app')
|
2022-05-19 09:41:48 +12:00
|
|
|
launch_minimal_parser.add_argument('--wine-prefix', dest='wine_pfx', action='store', metavar='<wine pfx path>',
|
2022-09-02 22:17:05 +12:00
|
|
|
default=os.environ.get('LGDRY_WINE_PREFIX', None),
|
|
|
|
help='Set WINE prefix to use')
|
2023-01-13 04:32:03 +13:00
|
|
|
launch_minimal_parser.add_argument("--ask-sync-saves", help="Ask to sync cloud saves",
|
2022-05-15 11:25:13 +12:00
|
|
|
action="store_true")
|
2022-10-01 11:44:37 +13:00
|
|
|
launch_minimal_parser.add_argument("--skip-update-check", help="Do not check for updates",
|
|
|
|
action="store_true")
|
2022-05-15 11:25:13 +12:00
|
|
|
|
2021-04-09 21:36:27 +12:00
|
|
|
args = parser.parse_args()
|
2021-04-14 02:56:44 +12:00
|
|
|
|
2022-07-27 02:58:17 +12:00
|
|
|
if args.desktop_shortcut or args.startmenu_shortcut:
|
|
|
|
from rare.utils.misc import create_desktop_link
|
2021-12-24 22:09:50 +13:00
|
|
|
|
2022-07-27 02:58:17 +12:00
|
|
|
if args.desktop_shortcut:
|
|
|
|
create_desktop_link(type_of_link="desktop", for_rare=True)
|
2021-09-19 02:34:43 +12:00
|
|
|
|
2022-07-27 02:58:17 +12:00
|
|
|
if args.startmenu_shortcut:
|
|
|
|
create_desktop_link(type_of_link="start_menu", for_rare=True)
|
2021-12-24 22:09:50 +13:00
|
|
|
|
2022-07-27 02:58:17 +12:00
|
|
|
print("Link created")
|
2022-04-18 21:45:14 +12:00
|
|
|
return
|
2021-05-23 03:49:01 +12:00
|
|
|
|
2021-04-09 21:36:27 +12:00
|
|
|
if args.version:
|
2021-12-12 11:41:55 +13:00
|
|
|
from rare import __version__, code_name
|
|
|
|
print(f"Rare {__version__} Codename: {code_name}")
|
2021-08-31 06:34:53 +12:00
|
|
|
return
|
2022-09-02 22:17:05 +12:00
|
|
|
|
|
|
|
if args.subparser == "start" or args.subparser == "launch":
|
2022-05-15 11:25:13 +12:00
|
|
|
from rare import game_launch_helper as helper
|
2022-05-19 09:41:48 +12:00
|
|
|
helper.start_game(args)
|
2022-05-15 11:25:13 +12:00
|
|
|
return
|
|
|
|
|
2022-06-24 06:11:09 +12:00
|
|
|
from rare.utils import singleton
|
|
|
|
|
|
|
|
try:
|
|
|
|
# this object only allows one instance per machine
|
|
|
|
|
|
|
|
me = singleton.SingleInstance()
|
|
|
|
except singleton.SingleInstanceException:
|
2021-04-09 22:32:41 +12:00
|
|
|
print("Rare is already running")
|
2022-09-08 10:27:37 +12:00
|
|
|
from rare.utils.paths import lock_file
|
2022-06-24 06:11:09 +12:00
|
|
|
|
2022-09-08 10:27:37 +12:00
|
|
|
with open(lock_file(), "w") as file:
|
2022-09-02 22:17:05 +12:00
|
|
|
file.write("show")
|
2021-04-15 01:14:06 +12:00
|
|
|
file.close()
|
2021-08-31 06:34:53 +12:00
|
|
|
return
|
2021-02-10 23:48:25 +13:00
|
|
|
|
2021-04-09 21:36:27 +12:00
|
|
|
from rare.app import start
|
2021-12-24 22:09:50 +13:00
|
|
|
|
2021-04-09 21:36:27 +12:00
|
|
|
start(args)
|
2021-03-26 10:58:32 +13:00
|
|
|
|
2021-03-25 23:49:05 +13:00
|
|
|
|
2021-12-24 22:09:50 +13:00
|
|
|
if __name__ == "__main__":
|
2021-12-08 10:16:03 +13:00
|
|
|
# run from source
|
|
|
|
# insert raw legendary submodule
|
2022-04-19 01:55:23 +12:00
|
|
|
# sys.path.insert(
|
|
|
|
# 0, os.path.join(pathlib.Path(__file__).parent.absolute(), "legendary")
|
|
|
|
# )
|
2022-09-06 06:18:40 +12:00
|
|
|
|
2021-12-08 10:16:03 +13:00
|
|
|
# insert source directory
|
2022-09-10 05:49:30 +12:00
|
|
|
if "__compiled__" not in globals():
|
|
|
|
sys.path.insert(0, str(pathlib.Path(__file__).parents[1].absolute()))
|
2021-12-08 10:16:03 +13:00
|
|
|
|
2022-09-12 23:19:24 +12:00
|
|
|
# If we are on Windows, and we are in a "compiled" GUI application form
|
2022-09-11 07:05:00 +12:00
|
|
|
# stdout (and stderr?) will be None. So to avoid `'NoneType' object has no attribute 'write'`
|
|
|
|
# errors, redirect both of them to devnull
|
|
|
|
if os.name == "nt" and (getattr(sys, "frozen", False) or ("__compiled__" in globals())):
|
2022-09-12 23:19:24 +12:00
|
|
|
# Check if stdout and stderr are None before redirecting
|
|
|
|
# This is useful in the case of test builds that enable console
|
|
|
|
if sys.stdout is None:
|
|
|
|
sys.stdout = open(os.devnull, 'w')
|
|
|
|
if sys.stderr is None:
|
|
|
|
sys.stderr = open(os.devnull, 'w')
|
2022-09-11 07:05:00 +12:00
|
|
|
|
2021-02-10 23:48:25 +13:00
|
|
|
main()
|