Пример #1
0
    def test_select_game_gui_provider_env(self, gui_provider,
                                          steam_app_factory, monkeypatch,
                                          gui_cmd, steam_dir):
        """
        Test that the correct GUI provider is selected based on the
        `PROTONTRICKS_GUI` environment variable
        """
        monkeypatch.setenv("PROTONTRICKS_GUI", gui_cmd)

        steam_apps = [
            steam_app_factory(name="Fake game 1", appid=10),
            steam_app_factory(name="Fake game 2", appid=20)
        ]

        gui_provider.mock_stdout = "Fake game 2: 20"
        select_steam_app_with_gui(steam_apps=steam_apps, steam_path=steam_dir)

        # The flags should differ slightly depending on which provider is in
        # use
        if gui_cmd == "yad":
            assert gui_provider.args[0] == "yad"
            assert gui_provider.args[2] == "--no-headers"
        elif gui_cmd == "zenity":
            assert gui_provider.args[0] == "zenity"
            assert gui_provider.args[2] == "--hide-header"
Пример #2
0
    def test_select_game_no_choice(self, zenity, steam_app_factory):
        """
        Try choosing a game but make no choice
        """
        steam_apps = [steam_app_factory(name="Fake game 1", appid=10)]

        # Fake user doesn't select any game
        zenity.mock_stdout = ""

        with pytest.raises(SystemExit) as exc:
            select_steam_app_with_gui(steam_apps=steam_apps)

        assert exc.value.code == 0
Пример #3
0
    def test_select_game(self, zenity, steam_app_factory):
        """
        Select a game using the GUI
        """
        steam_apps = [
            steam_app_factory(name="Fake game 1", appid=10),
            steam_app_factory(name="Fake game 2", appid=20)
        ]

        # Fake user selecting 'Fake game 2'
        zenity.mock_stdout = "Fake game 2: 20"
        steam_app = select_steam_app_with_gui(steam_apps=steam_apps)

        assert steam_app == steam_apps[1]
Пример #4
0
    def test_select_game_broken_zenity(self, broken_zenity, steam_app_factory):
        """
        Try choosing a game with a broken Zenity executable that
        prints a specific error message that Protontricks knows how to ignore
        """
        steam_apps = [
            steam_app_factory(name="Fake game 1", appid=10),
            steam_app_factory(name="Fake game 2", appid=20)
        ]

        # Fake user selecting 'Fake game 2'
        broken_zenity.mock_stdout = "Fake game 2: 20"
        steam_app = select_steam_app_with_gui(steam_apps=steam_apps)

        assert steam_app == steam_apps[1]
Пример #5
0
    def test_select_game_icons(self, gui_provider, steam_app_factory,
                               steam_dir):
        """
        Select a game using the GUI. Ensure that icons are used in the dialog
        whenever available.
        """
        steam_apps = [
            steam_app_factory(name="Fake game 1", appid=10),
            steam_app_factory(name="Fake game 2", appid=20),
            steam_app_factory(name="Fake game 3", appid=30),
        ]

        # Create icons for game 1 and 3
        (steam_dir / "appcache" / "librarycache" / "10_icon.jpg").touch()
        (steam_dir / "appcache" / "librarycache" / "30_icon.jpg").touch()

        gui_provider.mock_stdout = "Fake game 2: 20"
        select_steam_app_with_gui(steam_apps=steam_apps, steam_path=steam_dir)

        input_ = gui_provider.kwargs["input"]

        assert b"librarycache/10_icon.jpg\nFake game 1" in input_
        assert b"icon_placeholder.png\nFake game 2" in input_
        assert b"librarycache/30_icon.jpg\nFake game 3" in input_
Пример #6
0
    def test_select_game_broken_zenity(self, broken_zenity, monkeypatch,
                                       steam_app_factory, steam_dir):
        """
        Try choosing a game with a broken Zenity executable that
        prints a specific error message that Protontricks knows how to ignore
        """
        monkeypatch.setenv("PROTONTRICKS_GUI", "zenity")

        steam_apps = [
            steam_app_factory(name="Fake game 1", appid=10),
            steam_app_factory(name="Fake game 2", appid=20)
        ]

        # Fake user selecting 'Fake game 2'
        broken_zenity.mock_stdout = "Fake game 2: 20"
        steam_app = select_steam_app_with_gui(steam_apps=steam_apps,
                                              steam_path=steam_dir)

        assert steam_app == steam_apps[1]
Пример #7
0
    def test_select_game_locale_error(self, locale_error_zenity,
                                      steam_app_factory, caplog):
        """
        Try choosing a game with an environment that can't handle non-ASCII
        characters
        """
        steam_apps = [
            steam_app_factory(name="Fäke game 1", appid=10),
            steam_app_factory(name="Fäke game 2", appid=20)
        ]

        # Fake user selecting 'Fäke game 2'. The non-ASCII character 'ä'
        # is stripped since Zenity wouldn't be able to display the character.
        locale_error_zenity.mock_stdout = "Fke game 2: 20"
        steam_app = select_steam_app_with_gui(steam_apps=steam_apps)

        assert steam_app == steam_apps[1]
        assert ("Your system locale is incapable of displaying all characters"
                in caplog.records[0].message)
Пример #8
0
    def test_select_game(self, gui_provider, steam_app_factory, steam_dir):
        """
        Select a game using the GUI
        """
        steam_apps = [
            steam_app_factory(name="Fake game 1", appid=10),
            steam_app_factory(name="Fake game 2", appid=20)
        ]

        # Fake user selecting 'Fake game 2'
        gui_provider.mock_stdout = "Fake game 2: 20"
        steam_app = select_steam_app_with_gui(steam_apps=steam_apps,
                                              steam_path=steam_dir)

        assert steam_app == steam_apps[1]

        input_ = gui_provider.kwargs["input"]

        # Check that choices were displayed
        assert b"Fake game 1: 10\n" in input_
        assert b"Fake game 2: 20" in input_
Пример #9
0
def main():
    """
    'protontricks' script entrypoint
    """
    parser = argparse.ArgumentParser(
        description=(
            "Wrapper for running Winetricks commands for "
            "Steam Play/Proton games.\n"
            "\n"
            "Usage:\n"
            "\n"
            "Run winetricks for game with APPID\n"
            "$ protontricks APPID COMMAND\n"
            "\n"
            "Search installed games to find the APPID\n"
            "$ protontricks -s GAME_NAME\n"
            "\n"
            "Launch the Protontricks GUI\n"
            "$ protontricks --gui\n"
            "\n"
            "Environment variables:\n"
            "\n"
            "PROTON_VERSION: name of the preferred Proton installation\n"
            "STEAM_DIR: path to custom Steam installation\n"
            "WINETRICKS: path to a custom 'winetricks' executable\n"
            "WINE: path to a custom 'wine' executable\n"
            "WINESERVER: path to a custom 'wineserver' executable"),
        formatter_class=argparse.RawTextHelpFormatter)
    parser.add_argument("--verbose",
                        "-v",
                        action="store_true",
                        help="Print debug information")
    parser.add_argument("-s",
                        "--search",
                        type=str,
                        dest="search",
                        nargs="+",
                        required=False,
                        help="Search for game(s) with the given name")
    parser.add_argument(
        "-c",
        "--command",
        type=str,
        dest="command",
        required=False,
        help="Run a command in the game's installation directory with "
        "Wine-related environment variables set. "
        "The command is passed to the shell as-is without being escaped.")
    parser.add_argument("--gui",
                        action="store_true",
                        help="Launch the Protontricks GUI.")
    parser.add_argument("appid", type=int, nargs="?", default=None)
    parser.add_argument("winetricks_command", nargs=argparse.REMAINDER)
    parser.add_argument("-V",
                        "--version",
                        action="version",
                        version="%(prog)s ({})".format(__version__))

    args = parser.parse_args()

    do_command = bool(args.command)
    do_search = bool(args.search)
    do_gui = bool(args.gui)
    do_winetricks = bool(args.appid and args.winetricks_command)

    if not do_command and not do_search and not do_gui and not do_winetricks:
        parser.print_help()
        return

    # Don't allow more than one action
    if sum([do_search, do_gui, do_winetricks, do_command]) != 1:
        print("Only one action can be performed at a time.")
        parser.print_help()
        return

    enable_logging(args.verbose)

    # 1. Find Steam path
    steam_path = find_steam_path()
    if not steam_path:
        print("Steam installation directory could not be found.")
        sys.exit(-1)

    # 2. Find Winetricks
    winetricks_path = get_winetricks_path()
    if not winetricks_path:
        print("Winetricks isn't installed, please install "
              "winetricks in order to use this script!")
        sys.exit(-1)

    # 3. Find any Steam library folders
    steam_lib_paths = get_steam_lib_paths(steam_path)

    # 4. Find any Steam apps
    steam_apps = get_steam_apps(steam_path, steam_lib_paths)

    # 5. Find active Proton version
    proton_app = find_proton_app(steam_path=steam_path,
                                 steam_apps=steam_apps,
                                 appid=args.appid)

    if not proton_app:
        print("Proton installation could not be found!")
        sys.exit(-1)

    # Run the GUI
    if args.gui:
        steam_app = select_steam_app_with_gui(steam_apps=steam_apps)
        run_command(steam_path=steam_path,
                    winetricks_path=winetricks_path,
                    proton_app=proton_app,
                    steam_app=steam_app,
                    command=[winetricks_path, "--gui"])
        return
    # Perform a search
    elif args.search:
        # Search for games
        search_query = " ".join(args.search)
        matching_apps = [
            app for app in steam_apps
            if app.prefix_path_exists and app.name_contains(search_query)
        ]

        if matching_apps:
            matching_games = "\n".join([
                "{} ({})".format(app.name, app.appid) for app in matching_apps
            ])
            print("Found the following games:" "\n{}\n".format(matching_games))
            print("To run protontricks for the chosen game, run:\n"
                  "$ protontricks APPID COMMAND")
        else:
            print("Found no games.")

        print(
            "\n"
            "NOTE: A game must be launched at least once before protontricks "
            "can find the game.")
        return

    # If neither search or GUI are set, do a normal Winetricks command
    # Find game by appid
    steam_appid = int(args.appid)
    try:
        steam_app = next(app for app in steam_apps
                         if not app.is_proton and app.appid == steam_appid
                         and app.prefix_path_exists)
    except StopIteration:
        print("Steam app with the given app ID could not be found. "
              "Is it installed, Proton compatible and have you launched it at "
              "least once? You can search for the app ID using the following "
              "command:\n"
              "$ protontricks -s <GAME NAME>")
        sys.exit(-1)

    if args.winetricks_command:
        run_command(steam_path=steam_path,
                    winetricks_path=winetricks_path,
                    proton_app=proton_app,
                    steam_app=steam_app,
                    command=[winetricks_path] + args.winetricks_command)
    elif args.command:
        run_command(
            steam_path=steam_path,
            winetricks_path=winetricks_path,
            proton_app=proton_app,
            steam_app=steam_app,
            command=args.command,
            # Pass the command directly into the shell *without*
            # escaping it
            cwd=steam_app.install_path,
            shell=True)