Skip to content

Commit

Permalink
Version 0.2.4
Browse files Browse the repository at this point in the history
abcache : Cached game version and its hash is now stored in the cache file.
abcache : `--app-version` and `--app-appHash` is now only required when `--no-update` is not used.
  • Loading branch information
mos9527 committed Jun 12, 2024
1 parent 2adc316 commit 36b3e00
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
8 changes: 5 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
"args": [
"--log-level",
"DEBUG",
"abcache",
"abcache",
"--app-version",
"3.6.5",
"--app-appHash",
"c5e69328-dcfd-fa80-8ec2-b478ed0719d0"
],
"justMyCode": true
},
Expand All @@ -36,8 +40,6 @@
"abcache",
"--no-update",
"--download-ensure-deps",
"--download-dir",
"~/.sssekai/abcache",
"--download-filter",
".*characterv2/face/21/.*"
],
Expand Down
2 changes: 1 addition & 1 deletion sssekai/__init__.py
Original file line number Diff line number Diff line change
@@ -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__)
6 changes: 3 additions & 3 deletions sssekai/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='')
Expand Down
12 changes: 8 additions & 4 deletions sssekai/abcache/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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({
Expand All @@ -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')
Expand Down Expand Up @@ -267,7 +271,7 @@ def load(self, f : BinaryIO):
self.database = load(f)

def __repr__(self) -> str:
return f'<AbCache config={self.config} appVersion={self.SEKAI_APP_VERSION} bundles={len(self.abcache_index.bundles)}>'
return f'<AbCache config={self.config} bundles={len(self.abcache_index.bundles)}>'

def update_download_headers(self):
'''Update headers with the latest user auth data. Try to call this before downloading anything.'''
Expand Down
4 changes: 3 additions & 1 deletion sssekai/entrypoint/abcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 36b3e00

Please sign in to comment.