Skip to content

Commit 5e490f0

Browse files
version 0.40
1 parent 93c021d commit 5e490f0

File tree

4 files changed

+79
-21
lines changed

4 files changed

+79
-21
lines changed

src/plugin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,10 @@ async def prepare_local_size_context(self, game_ids: List[GameId]) -> Dict[str,
309309
async def get_local_size(self, game_id: GameId, context: Dict[str, pathlib.PurePath]) -> Optional[int]:
310310
try:
311311
return parse_map_crc_for_total_size(context[game_id])
312-
except (KeyError, FileNotFoundError) as e:
313-
raise UnknownError(f"Manifest for game {game_id} is not found: {repr(e)} | context: {context}")
312+
except FileNotFoundError:
313+
return None
314+
except KeyError:
315+
raise UnknownError("Manifest not found")
314316

315317
@staticmethod
316318
def _get_multiplayer_id(offer) -> Optional[MultiplayerId]:

src/uri_scheme_handler.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
import platform
22

3+
34
if platform.system().lower() == "windows":
45

56
import winreg
6-
import shlex
77
import os
88

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

12+
def is_uri_handler_installed(protocol) -> bool:
1513
try:
16-
executable_template = winreg.QueryValue(key, None)
17-
splitted_exec = shlex.split(executable_template)
18-
if not splitted_exec:
19-
return False
20-
return os.path.exists(splitted_exec[0])
21-
except ValueError:
14+
with winreg.OpenKey(
15+
winreg.HKEY_CLASSES_ROOT, r"{}\shell\open\command".format(protocol)
16+
) as key:
17+
executable_template = winreg.QueryValue(key, None)
18+
path = _get_path_from_cmd_template(executable_template)
19+
return os.path.exists(path)
20+
except OSError:
2221
return False
23-
finally:
24-
winreg.CloseKey(key)
2522

26-
return True
2723

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

3026
from CoreServices.LaunchServices import LSCopyDefaultHandlerForURLScheme
3127
from AppKit import NSWorkspace
3228

33-
def is_uri_handler_installed(protocol):
29+
def is_uri_handler_installed(protocol) -> bool:
3430
bundle_id = LSCopyDefaultHandlerForURLScheme(protocol)
3531
if not bundle_id:
3632
return False
37-
return NSWorkspace.sharedWorkspace().absolutePathForAppBundleWithIdentifier_(bundle_id) is not None
33+
return (
34+
NSWorkspace.sharedWorkspace().absolutePathForAppBundleWithIdentifier_(bundle_id)
35+
is not None
36+
)
37+
3838

3939
else:
4040

41-
def is_uri_handler_installed(protocol):
41+
def is_uri_handler_installed(protocol) -> bool:
4242
return False

src/version.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
__version__ = "0.39"
1+
__version__ = "0.40"
22

33
__changelog__ = {
4+
"unreleased":"""""",
5+
"0.40":
6+
"""
7+
- `get_local_size`: return `None` if map.crc not found instead of raising error
8+
- fix detecting installed launcher & games when EA Desktop is installed
9+
""",
410
"0.39":
511
"""
612
- update Galaxy API version to 0.68

tests/test_uri_scheme_handler.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import platform
2+
3+
import pytest
4+
5+
from uri_scheme_handler import is_uri_handler_installed
6+
7+
8+
@pytest.mark.skipif(platform.system().lower() != "windows", reason="windows registry")
9+
@pytest.mark.parametrize(
10+
"reg_value_template",
11+
[
12+
pytest.param('{} "%1"', id="Origin case"),
13+
pytest.param('"{}" "%1"', id="EA Desktop case"),
14+
pytest.param('{} "%1" "%2"', id="more params (hypotetical)"),
15+
pytest.param("{} %1", id="no quotes around param (hypotetical)"),
16+
pytest.param("{}", id="just exe without params (hypotetical)"),
17+
],
18+
)
19+
def test_win_reg_uri_handler_installed(mocker, reg_value_template):
20+
launcher_path = r"C:\Program Files\EA Desktop Example Path\EALauncher.exe"
21+
reg_value = reg_value_template.format(launcher_path)
22+
23+
mocker.patch("winreg.OpenKey")
24+
mocker.patch("winreg.QueryValue", return_value=reg_value)
25+
mocker.patch("os.path.exists", side_effect=lambda x: x == launcher_path)
26+
27+
assert is_uri_handler_installed(mocker.Mock()) == True
28+
29+
30+
@pytest.mark.skipif(platform.system().lower() != "windows", reason="windows registry")
31+
@pytest.mark.parametrize(
32+
"problem_patch_config",
33+
[
34+
{"target": "winreg.OpenKey", "side_effect": OSError},
35+
{"target": "winreg.OpenKey", "side_effect": FileNotFoundError},
36+
{"target": "winreg.QueryValue", "side_effect": PermissionError},
37+
{"target": "os.path.exists", "return_value": False},
38+
],
39+
)
40+
def test_win_reg_uri_hanlder_not_installed(mocker, problem_patch_config):
41+
# "installed" case patches
42+
mocker.patch("winreg.OpenKey")
43+
mocker.patch("winreg.QueryValue", return_value="path"),
44+
mocker.patch("os.path.exists", return_value=True)
45+
assert is_uri_handler_installed(mocker.Mock()) == True, "test preconfiguration failed"
46+
47+
# problem patch
48+
mocker.patch(**problem_patch_config)
49+
50+
assert is_uri_handler_installed(mocker.Mock()) == False

0 commit comments

Comments
 (0)