Skip to content

Commit

Permalink
version 0.40
Browse files Browse the repository at this point in the history
  • Loading branch information
FriendsOfGalaxy committed Jul 29, 2021
1 parent 93c021d commit 5e490f0
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 21 deletions.
6 changes: 4 additions & 2 deletions src/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,10 @@ async def prepare_local_size_context(self, game_ids: List[GameId]) -> Dict[str,
async def get_local_size(self, game_id: GameId, context: Dict[str, pathlib.PurePath]) -> Optional[int]:
try:
return parse_map_crc_for_total_size(context[game_id])
except (KeyError, FileNotFoundError) as e:
raise UnknownError(f"Manifest for game {game_id} is not found: {repr(e)} | context: {context}")
except FileNotFoundError:
return None
except KeyError:
raise UnknownError("Manifest not found")

@staticmethod
def _get_multiplayer_id(offer) -> Optional[MultiplayerId]:
Expand Down
36 changes: 18 additions & 18 deletions src/uri_scheme_handler.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
import platform


if platform.system().lower() == "windows":

import winreg
import shlex
import os

def is_uri_handler_installed(protocol):
try:
key = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, r"{}\shell\open\command".format(protocol))
except OSError:
return False
def _get_path_from_cmd_template(cmd_template) -> str:
return cmd_template.replace("\"", "").partition("%")[0].strip()

def is_uri_handler_installed(protocol) -> bool:
try:
executable_template = winreg.QueryValue(key, None)
splitted_exec = shlex.split(executable_template)
if not splitted_exec:
return False
return os.path.exists(splitted_exec[0])
except ValueError:
with winreg.OpenKey(
winreg.HKEY_CLASSES_ROOT, r"{}\shell\open\command".format(protocol)
) as key:
executable_template = winreg.QueryValue(key, None)
path = _get_path_from_cmd_template(executable_template)
return os.path.exists(path)
except OSError:
return False
finally:
winreg.CloseKey(key)

return True

elif platform.system().lower() == "darwin":

from CoreServices.LaunchServices import LSCopyDefaultHandlerForURLScheme
from AppKit import NSWorkspace

def is_uri_handler_installed(protocol):
def is_uri_handler_installed(protocol) -> bool:
bundle_id = LSCopyDefaultHandlerForURLScheme(protocol)
if not bundle_id:
return False
return NSWorkspace.sharedWorkspace().absolutePathForAppBundleWithIdentifier_(bundle_id) is not None
return (
NSWorkspace.sharedWorkspace().absolutePathForAppBundleWithIdentifier_(bundle_id)
is not None
)


else:

def is_uri_handler_installed(protocol):
def is_uri_handler_installed(protocol) -> bool:
return False
8 changes: 7 additions & 1 deletion src/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
__version__ = "0.39"
__version__ = "0.40"

__changelog__ = {
"unreleased":"""""",
"0.40":
"""
- `get_local_size`: return `None` if map.crc not found instead of raising error
- fix detecting installed launcher & games when EA Desktop is installed
""",
"0.39":
"""
- update Galaxy API version to 0.68
Expand Down
50 changes: 50 additions & 0 deletions tests/test_uri_scheme_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import platform

import pytest

from uri_scheme_handler import is_uri_handler_installed


@pytest.mark.skipif(platform.system().lower() != "windows", reason="windows registry")
@pytest.mark.parametrize(
"reg_value_template",
[
pytest.param('{} "%1"', id="Origin case"),
pytest.param('"{}" "%1"', id="EA Desktop case"),
pytest.param('{} "%1" "%2"', id="more params (hypotetical)"),
pytest.param("{} %1", id="no quotes around param (hypotetical)"),
pytest.param("{}", id="just exe without params (hypotetical)"),
],
)
def test_win_reg_uri_handler_installed(mocker, reg_value_template):
launcher_path = r"C:\Program Files\EA Desktop Example Path\EALauncher.exe"
reg_value = reg_value_template.format(launcher_path)

mocker.patch("winreg.OpenKey")
mocker.patch("winreg.QueryValue", return_value=reg_value)
mocker.patch("os.path.exists", side_effect=lambda x: x == launcher_path)

assert is_uri_handler_installed(mocker.Mock()) == True


@pytest.mark.skipif(platform.system().lower() != "windows", reason="windows registry")
@pytest.mark.parametrize(
"problem_patch_config",
[
{"target": "winreg.OpenKey", "side_effect": OSError},
{"target": "winreg.OpenKey", "side_effect": FileNotFoundError},
{"target": "winreg.QueryValue", "side_effect": PermissionError},
{"target": "os.path.exists", "return_value": False},
],
)
def test_win_reg_uri_hanlder_not_installed(mocker, problem_patch_config):
# "installed" case patches
mocker.patch("winreg.OpenKey")
mocker.patch("winreg.QueryValue", return_value="path"),
mocker.patch("os.path.exists", return_value=True)
assert is_uri_handler_installed(mocker.Mock()) == True, "test preconfiguration failed"

# problem patch
mocker.patch(**problem_patch_config)

assert is_uri_handler_installed(mocker.Mock()) == False

0 comments on commit 5e490f0

Please sign in to comment.