diff --git a/.vscode/launch.json b/.vscode/launch.json index 4d5a31a..6cd5187 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -21,7 +21,11 @@ "args": [ "--log-level", "DEBUG", - "abcache", + "abcache", + "--app-version", + "3.6.5", + "--app-appHash", + "c5e69328-dcfd-fa80-8ec2-b478ed0719d0" ], "justMyCode": true }, @@ -36,8 +40,6 @@ "abcache", "--no-update", "--download-ensure-deps", - "--download-dir", - "~/.sssekai/abcache", "--download-filter", ".*characterv2/face/21/.*" ], diff --git a/sssekai/__init__.py b/sssekai/__init__.py index 0454e91..ce1057c 100644 --- a/sssekai/__init__.py +++ b/sssekai/__init__.py @@ -1,5 +1,5 @@ __VERSION_MAJOR__ = 0 __VERSION_MINOR__ = 2 -__VERSION_PATCH__ = 3 +__VERSION_PATCH__ = 4 __version__ = '%s.%s.%s' % (__VERSION_MAJOR__,__VERSION_MINOR__,__VERSION_PATCH__) diff --git a/sssekai/__main__.py b/sssekai/__main__.py index 14a9eab..bc47aee 100644 --- a/sssekai/__main__.py +++ b/sssekai/__main__.py @@ -55,9 +55,9 @@ def write(__s): group.add_argument('--db', type=str, help='''cache database file path (default: %(default)s)''',default=DEFAULT_CACHE_DB_FILE) group.add_argument('--no-update',action='store_true',help='skip all metadata updates and use cached ones as is.') group = abcache_parser.add_argument_group('game version options', 'NOTE: these options are used to *update* the cache database. Use --no-update to skip updating. Also, you may want to read the Wiki to know how to get these values.') - group.add_argument('--app-version', type=str, help='PJSK app version',required=True) - group.add_argument('--app-platform', type=str, help='PJSK app platform',choices=['ios','android'],required=True) # Let's hope this doesn't age well... - group.add_argument('--app-appHash', type=str, help='PJSK app hash',required=True) + group.add_argument('--app-platform', type=str, help='PJSK app platform (default: %(default)s',choices=['ios','android'],default='android') # Let's hope this doesn't age well... + group.add_argument('--app-version', type=str, help='PJSK app version. This is required unless --no-update is specified',default='') + group.add_argument('--app-appHash', type=str, help='PJSK app hash. This is required unless --no-update is specified',default='') group = abcache_parser.add_argument_group('download options') group.add_argument('--download-filter', type=str, help='filter AssetBundles (by bundle names) with this regex pattern',default=None) group.add_argument('--download-dir', type=str, help='asset bundle download directory. leave empty if you don\'t want to download anything',default='') diff --git a/sssekai/abcache/__init__.py b/sssekai/abcache/__init__.py index 7d4e7de..101d835 100644 --- a/sssekai/abcache/__init__.py +++ b/sssekai/abcache/__init__.py @@ -107,6 +107,7 @@ class SekaiUserAuthData: @dataclass class SSSekaiDatabase: + config : AbCacheConfig = None sekai_user_data : SekaiUserData = None sekai_user_auth_data : SekaiUserAuthData = None sekai_abcache_index : AbCacheIndex = None @@ -118,9 +119,12 @@ def __init__(self, bundleName: str): self.bundleName = bundleName super().__init__('Bundle not found: %s' % bundleName) class AbCache(Session): - config : AbCacheConfig database : SSSekaiDatabase - + + @property + def config(self): return self.database.config + @config.setter + def config(self, v): self.database.config = v @property def SEKAI_APP_VERSION(self): return self.config.app_version @property @@ -225,6 +229,7 @@ def _update_abcache_index(self) -> AbCacheIndex: def __init__(self, config : AbCacheConfig) -> None: super().__init__() + self.database = SSSekaiDatabase() self.config = config self.config.app_platform = self.config.app_platform.lower() self.headers.update({ @@ -239,7 +244,6 @@ def __init__(self, config : AbCacheConfig) -> None: 'X-App-Version': self.SEKAI_APP_VERSION, 'X-App-Hash': self.SEKAI_APP_HASH }) - self.database = SSSekaiDatabase() def update(self): logger.info('Updating metadata') @@ -267,7 +271,7 @@ def load(self, f : BinaryIO): self.database = load(f) def __repr__(self) -> str: - return f'' + return f'' def update_download_headers(self): '''Update headers with the latest user auth data. Try to call this before downloading anything.''' diff --git a/sssekai/entrypoint/abcache.py b/sssekai/entrypoint/abcache.py index fd875e3..66e3e15 100644 --- a/sssekai/entrypoint/abcache.py +++ b/sssekai/entrypoint/abcache.py @@ -58,16 +58,18 @@ def add_link(self, url, fname, length): self.progress.total += length return self.submit(self._download, url, fname, length) -def main_abcache(args): +def main_abcache(args): cache = AbCache(AbCacheConfig(args.app_version, args.app_platform, args.app_appHash)) db_path = os.path.expanduser(args.db) if not args.no_update: + assert args.app_version and args.app_appHash, "You need --app-version and --app-appHash to perform a cache index update!" with open(db_path, 'wb') as f: cache.update() cache.save(f) else: with open(db_path, 'rb') as f: cache.load(f) + logger.info("AbCache: %s" % cache) if args.download_dir: download_dir = os.path.expanduser(args.download_dir)