Skip to content

Commit

Permalink
Humble Choice months as separate Subscriptions (#108)
Browse files Browse the repository at this point in the history
Beta. No support for installation/activation yet. Games may be duplicated (subscription games vs those coming as owned). tbd
  • Loading branch information
UncleGoogle authored May 22, 2020
1 parent dd8354f commit bf1b4a9
Show file tree
Hide file tree
Showing 19 changed files with 711 additions and 185 deletions.
48 changes: 2 additions & 46 deletions src/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@ class PlatformNotSupported(Exception):
pass


class SUBSCRIPTIONS(enum.Enum):
TROVE = 'Humble Trove'


class KEY_TYPE(enum.Enum):
STEAM = 'steam'
ORIGIN = 'origin'
UPLAY = 'uplay'
EPIC = 'epic' # not sure about it
BATTLENET = 'battlenet' # not sure about it
GOG = 'gog' # not sure about it


class SOURCE(enum.Enum):
DRM_FREE = 'drm-free'
KEYS = 'keys'
Expand All @@ -29,41 +16,10 @@ class BITNESS(enum.Enum):
B64 = 64
B32 = 32


class HP(enum.Enum):
"""HumbleBundle platform code name shown in subproducts>download section"""
WINDOWS = 'windows'
MAC = 'mac'
LINUX = 'linux'
ANDROID = 'android'
AUDIO = 'audio'
EBOOK = 'ebook'
ASMJS = 'asmjs'
UNITYWASM = 'unitywasm'
VIDEO = 'video'
COMEDY = 'comedy'

def __eq__(self, other):
if type(other) == str:
return self.value == other
return super().__eq__(other)

def __hash__(self):
return hash(self.value)


GAME_PLATFORMS = set([HP.WINDOWS, HP.MAC, HP.LINUX])
NON_GAME_BUNDLE_TYPES = {'mobilebundle', 'softwarebundle', 'bookbundle', 'audiobookbundle', 'comicsbundle', 'rpgbookbundle', 'mangabundle'}

if sys.platform == 'win32':
CURRENT_SYSTEM = HP.WINDOWS
elif sys.platform == 'darwin':
CURRENT_SYSTEM = HP.MAC
else:
raise PlatformNotSupported('GOG Galaxy 2.0 supports only Windows and macos for now')

IS_WINDOWS = HP.WINDOWS == CURRENT_SYSTEM
IS_MAC = HP.MAC == CURRENT_SYSTEM
IS_WINDOWS = sys.platform == 'win32'
IS_MAC = sys.platform == 'darwin'

if platform.machine().endswith('64'):
CURRENT_BITNESS = BITNESS.B64
Expand Down
2 changes: 1 addition & 1 deletion src/humbledownloader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from model.game import HumbleGame, TroveGame, Subproduct
from model.download import DownloadStructItem, SubproductDownload, TroveDownload
from consts import CURRENT_BITNESS, HP, BITNESS
from consts import CURRENT_BITNESS, BITNESS


class HumbleDownloadResolver:
Expand Down
3 changes: 2 additions & 1 deletion src/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import asyncio
from typing import Callable, Dict, List, Set, Iterable, Any, Coroutine

from consts import SOURCE, NON_GAME_BUNDLE_TYPES, GAME_PLATFORMS
from consts import SOURCE, NON_GAME_BUNDLE_TYPES
from model.product import Product
from model.game import HumbleGame, Subproduct, Key, KeyGame
from model.types import GAME_PLATFORMS
from settings import LibrarySettings


Expand Down
8 changes: 4 additions & 4 deletions src/local/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from consts import HP, CURRENT_SYSTEM
from consts import IS_MAC, IS_WINDOWS


if CURRENT_SYSTEM == HP.WINDOWS:
if IS_WINDOWS:
from local.winappfinder import WindowsAppFinder as AppFinder # noqa
elif CURRENT_SYSTEM == HP.MAC:
elif IS_MAC:
from local.macappfinder import MacAppFinder as AppFinder # type: ignore[misc] # noqa
else:
raise RuntimeError(f'Unsupported system: {CURRENT_SYSTEM}')
raise RuntimeError(f'Unsupported system')
4 changes: 2 additions & 2 deletions src/local/baseappfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
from typing import Dict, Set, Iterable, Union, List, AsyncGenerator, Tuple
from typing import cast

from consts import CURRENT_SYSTEM
from consts import IS_WINDOWS
from local.pathfinder import PathFinder
from local.localgame import LocalHumbleGame


class BaseAppFinder(abc.ABC):
def __init__(self, get_close_matches=None, find_best_exe=None):
self._pathfinder = PathFinder(CURRENT_SYSTEM)
self._pathfinder = PathFinder(IS_WINDOWS)
self.get_close_matches = get_close_matches or self._get_close_matches
self.find_best_exe = find_best_exe or self._find_best_exe

Expand Down
10 changes: 5 additions & 5 deletions src/local/localgame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from galaxy.api.types import LocalGameState, LocalGame

from consts import HP, CURRENT_SYSTEM
from consts import IS_WINDOWS, IS_MAC

DETACHED_PROCESS = 0b0001000

Expand Down Expand Up @@ -49,20 +49,20 @@ def state(self):

def in_galaxy_format(self):
return LocalGame(self.machine_name, self.state)

@property
def bundle_name(self) -> Optional[pathlib.Path]:
assert CURRENT_SYSTEM == HP.MAC, "macos only property"
assert IS_MAC, "macos only property"
for p in self.executable.parents:
if p.suffix == '.app':
return p
return None

def run(self):
if CURRENT_SYSTEM == HP.WINDOWS:
if IS_WINDOWS:
flags = DETACHED_PROCESS
proc = subprocess.Popen(str(self.executable), cwd=self.executable.parent, creationflags=flags)
elif CURRENT_SYSTEM == HP.MAC:
elif IS_MAC:
'''
-a Opens with the specified application.
-W Blocks until the used applications are closed (even if they were already running).
Expand Down
8 changes: 3 additions & 5 deletions src/local/pathfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
from typing import List, Union, Sequence, Optional
from typing import cast

from consts import HP


class PathFinder:
def __init__(self, system: HP):
self.system = system
def __init__(self, is_windows: bool):
self.is_windows = is_windows

def find_executables(self, path: Union[str, PurePath]) -> List[str]:
folder = Path(path)
Expand All @@ -26,7 +24,7 @@ def find_executables(self, path: Union[str, PurePath]) -> List[str]:
return execs

def is_exe(self, path: str) -> bool:
if self.system == HP.WINDOWS:
if self.is_windows:
return path.endswith('.exe')
else:
return os.access(path, os.X_OK)
Expand Down
2 changes: 1 addition & 1 deletion src/model/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from galaxy.api.types import Game, LicenseType, LicenseInfo, SubscriptionGame

from consts import KEY_TYPE, HP
from model.types import KEY_TYPE, HP
from model.download import TroveDownload, SubproductDownload


Expand Down
Loading

0 comments on commit bf1b4a9

Please sign in to comment.