Skip to content

Commit

Permalink
Don't update hook.json (installer <0.2)
Browse files Browse the repository at this point in the history
  • Loading branch information
insolor committed Dec 15, 2024
1 parent 746f671 commit e203ed8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/update-hook-manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- 'store/encodings/*'
- 'store/fonts/*'
- 'store/offsets/*'
- 'metadata/hook.json'
- 'metadata/hook_v2.json'
- '.github/workflows/update-hook-manifest.yml'
pull_request:
branches:
Expand All @@ -17,7 +17,7 @@ on:
- 'store/encodings/*'
- 'store/fonts/*'
- 'store/offsets/*'
- 'metadata/hook.json'
- 'metadata/hook_v2.json'
- '.github/workflows/update-hook-manifest.yml'

jobs:
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

Data backend for [dfint installer](https://github.com/dfint/installer).

- [`metadata/hook.json`](metadata/hook.json) contains info about releases of [df-steam-hook-rs](https://github.com/dfint/df-steam-hook-rs), configs, offset files
- [`metadata/hook_v2.json`](metadata/hook_v2.json) metadata for installer 0.2.0 and higher, also contains info about [dfhooks](https://github.com/DFHack/dfhooks) library
- [`metadata/dict.json`](metadata/dict.json) contains info about localization languages: url of their csv files, font files, encoding specific configs
- [`store`](store) directory contains files referenced from metadata, like encoding specific configs, offsets for different DF versions, and other misc. stuff.

Legacy, not updated anymore:

- [`metadata/hook.json`](metadata/hook.json) contains info about releases of [df-steam-hook-rs](https://github.com/dfint/df-steam-hook-rs), configs, offset files for installer older then 0.2.0.
27 changes: 5 additions & 22 deletions automation/hook_manifest_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

base_dir = Path(__file__).parent.parent # base directory of the repository

hook_json_path = base_dir / "metadata/hook.json"
hook_v2_json_path = base_dir / "metadata/hook_v2.json"
hook_json_path = base_dir / "metadata/hook_v2.json"
offsets_toml_path = base_dir / "store/offsets"
config_path = base_dir / "store"

Expand All @@ -32,22 +31,18 @@ class ConfigItem(NamedTuple):
hook_lib_url: str
config_url: str
offsets_url: str
dfhooks_url: str | None
dfhooks_url: str

def dict(self) -> dict[str, Any]:
item = {
return {
"df": self.df_checksum,
"checksum": self.payload_checksum,
"lib": self.hook_lib_url,
"config": self.config_url,
"offsets": self.offsets_url,
"dfhooks": self.dfhooks_url,
}

if self.dfhooks_url:
item["dfhooks"] = self.dfhooks_url

return item


def update_or_append(manifest_path: str, config_item: ConfigItem):
hook_manifest = json.loads(manifest_path.read_text())
Expand All @@ -72,21 +67,9 @@ def main(hook_lib_url: str, config_file_name: str, offsets_file_name: str, dfhoo
df_checksum = offsets_data["metadata"]["checksum"]
payload_checksum = crc32(res_hook + res_config + res_offsets)
payload_checksum_v2 = crc32(res_hook + res_config + res_offsets + res_dfhooks)

update_or_append(
hook_json_path,
ConfigItem(
df_checksum,
payload_checksum,
hook_lib_url,
config_base_url + config_file_name,
offsets_base_url + offsets_file_name,
None,
)
)

update_or_append(
hook_v2_json_path,
hook_json_path,
ConfigItem(
df_checksum,
payload_checksum_v2,
Expand Down
38 changes: 17 additions & 21 deletions automation/hook_manifest_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,23 @@

def main():
base_dir = Path(__file__).parent.parent # base directory of the repository
hook_json_path = [
base_dir / "metadata/hook.json",
base_dir / "metadata/hook_v2.json",
]

for path in hook_json_path:
manifest = json.loads(path.read_text(encoding="utf-8"))

for item in manifest:
print(f"Recalculating checksum for {item["df"]=}...")
try:
data = get_from_url(item["lib"]) + get_from_url(item["config"]) + get_from_url(item["offsets"])
if item.get("dfhooks"):
data += get_from_url(item["dfhooks"])
checksum = binascii.crc32(data)
item["checksum"] = checksum
except Exception as ex:
print(f"Failed on recalculation {item["df"]=}")
raise

path.write_text(json.dumps(manifest, indent=2, ensure_ascii=False), encoding="utf-8")
path = base_dir / "metadata/hook_v2.json"

manifest = json.loads(path.read_text(encoding="utf-8"))

for item in manifest:
print(f"Recalculating checksum for {item["df"]=}...")
try:
data = get_from_url(item["lib"]) + get_from_url(item["config"]) + get_from_url(item["offsets"])
if item.get("dfhooks"):
data += get_from_url(item["dfhooks"])
checksum = binascii.crc32(data)
item["checksum"] = checksum
except Exception as ex:
print(f"Failed on recalculation {item["df"]=}")
raise

path.write_text(json.dumps(manifest, indent=2, ensure_ascii=False), encoding="utf-8")


if __name__ == "__main__":
Expand Down

0 comments on commit e203ed8

Please sign in to comment.