Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions .github/workflows/avatars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# 干员头像同步:从 PRTS Wiki 抓「头像_*.png」,压成 96px WebP 推到 pack-data
#
# 触发:每周一 14:00(北京时间,UTC 06:00)+ 手动。头像只在出新干员时变,
# 没必要跟 pack.yml 一样一天两次——那样每次都要多传 2MB 的对象。
#
# 做的事(tools/sync_avatars.py):
# 1. 先把 pack-data 上现有的头像取到 build/avatars,增量模式下只补缺的
# 2. 拉 PRTS Wiki 的 MediaWiki 列表(list=allimages&aiprefix=头像)
# 3. 按干员表匹配、转 96px WebP q80,写 avatar-index.json(sha256 + 字节数)
# 4. 推到 pack-data 的 resources/avatars/:继承整条分支,只替换这一块
#
# 为什么和 pack.yml 共用 concurrency:两个流程都强推同一条分支,
# 同时跑必然有一个被覆盖掉(后推的赢,前一个白干)。
name: Avatar Sync

on:
schedule:
- cron: '0 6 * * 1' # 周一 14:00(UTC+8)
workflow_dispatch:
inputs:
force:
description: '已有的头像也重新下载'
type: boolean
default: false

permissions:
contents: write

concurrency:
group: pack-data-write
cancel-in-progress: false

env:
MAA_PRTS_PACK_BRANCH: pack-data
PYTHONUTF8: '1'
PYTHONIOENCODING: utf-8

jobs:
sync:
name: 同步干员头像
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout main
uses: actions/checkout@v7
with:
ref: main
fetch-depth: 1
show-progress: false

- name: Setup Python
uses: actions/setup-python@v7
with:
python-version: '3.12'

- name: Install Pillow
run: python -m pip install --quiet --disable-pip-version-check pillow

# 增量基础:pack-data 上已有的图先落到 build/avatars,sync_avatars 默认
# 跳过已存在的文件,所以常态下一次只下几张新干员的图。
# 同时用数据分支的干员表覆盖 main 里那份——main 只在发版时更新,
# 新干员还没进表的话会被当成「没匹配到头像」直接跳过。
- name: Seed previous avatars
shell: bash
run: |
mkdir -p build/avatars
if ! git fetch --depth=1 origin "$MAA_PRTS_PACK_BRANCH" 2>/dev/null; then
echo "pack-data 还不存在,本次按全量处理"
exit 0
fi
if git show "FETCH_HEAD:resources/arknights.json" > resources/arknights.json.tmp 2>/dev/null; then
mv -f resources/arknights.json.tmp resources/arknights.json
fi
rm -f resources/arknights.json.tmp
if git cat-file -e "FETCH_HEAD:resources/avatars/avatar-index.json" 2>/dev/null; then
rm -rf "$RUNNER_TEMP/av"; mkdir -p "$RUNNER_TEMP/av"
git archive --format=tar FETCH_HEAD resources/avatars | tar -xf - -C "$RUNNER_TEMP/av"
cp -a "$RUNNER_TEMP/av/resources/avatars/." build/avatars/
echo "已有 $(find build/avatars -name '*.webp' | wc -l) 张,本次只补缺的"
fi

- name: Sync avatars from PRTS Wiki
run: |
if [ "${{ inputs.force }}" = "true" ]; then
python -u tools/sync_avatars.py --out build/avatars --force
else
python -u tools/sync_avatars.py --out build/avatars
fi

- name: Validate
run: |
python - <<'PY'
import json, os
d = json.load(open('build/avatars/avatar-index.json', encoding='utf-8'))
n = d.get('count') or 0
assert n > 300, '头像只有 %d 张,PRTS 接口多半挂了(别把残缺的索引推上去)' % n
files = set(f for f in os.listdir('build/avatars') if f.endswith('.webp'))
assert len(files) >= n * 0.98, '文件数 %d 与索引 %d 对不上' % (len(files), n)
print('索引 %d 条 | 文件 %d 个 | 合计 %.2f MB'
% (n, len(files), (d.get('bytes') or 0) / 1048576.0))
PY

- name: Publish to pack-data
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
# 只比 webp 文件集合(索引里的 generatedAt 每次都变,拿它比永远「有变化」)
hash_av() {
find "$1" -name '*.webp' -type f 2>/dev/null | sort | xargs -r sha256sum \
| sha256sum | cut -d' ' -f1
}

D="$RUNNER_TEMP/pack-data"
rm -rf "$D"; mkdir -p "$D"
cd "$D"
git init -q -b "$MAA_PRTS_PACK_BRANCH"
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git remote add origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"

# 继承上一版(含 themes/ 与三个资源 JSON),只替换 resources/avatars/
if git fetch -q --depth=1 origin "$MAA_PRTS_PACK_BRANCH" 2>/dev/null; then
git archive --format=tar FETCH_HEAD | tar -xf - -C .
fi

OLD=$(hash_av resources/avatars)
rm -rf resources/avatars
mkdir -p resources
cp -a "$GITHUB_WORKSPACE/build/avatars" resources/avatars
NEW=$(hash_av resources/avatars)

if [ -n "$OLD" ] && [ "$OLD" = "$NEW" ]; then
echo "头像没有变化,本次不推送"
echo "### 头像无变化" >> "$GITHUB_STEP_SUMMARY"
exit 0
fi

COUNT=$(python -c "import json;print(json.load(open('resources/avatars/avatar-index.json',encoding='utf-8'))['count'])")
MB=$(python -c "import json;d=json.load(open('resources/avatars/avatar-index.json',encoding='utf-8'));print(round((d.get('bytes') or 0)/1048576.0,2))")
git add -A
git commit -q -m "chore(avatar): 同步干员头像 ${COUNT} 张"
git push -q -f origin "HEAD:refs/heads/${MAA_PRTS_PACK_BRANCH}"

echo "### 头像已更新:${COUNT} 张 / ${MB} MB" >> "$GITHUB_STEP_SUMMARY"
65 changes: 47 additions & 18 deletions .github/workflows/pack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
# 4. 条数只增不减才放行(arknights 各字段 + 悖论条数)
# 5. 产物推到独立的 pack-data 分支(不碰 main)
#
# 这个流程只负责 resources/ 下那三个 JSON;pack-data 上还有 themes/(主题包)
# 和 resources/avatars/(头像),发布前会把上一版整条分支继承过来,不会冲掉。
#
# 为什么不推 main:main 挂着规则集(强制走 PR、需审批、只允许 squash),
# GitHub Actions 的 bot 不在绕过名单里,直推必被拒。数据也不该和代码抢同一条分支。
# pack-data 是纯数据分支,没有保护,客户端按固定分支名拼 raw / jsDelivr 地址。
Expand All @@ -33,7 +36,8 @@ permissions:
contents: write

concurrency:
group: pack-sync
# 与 avatars.yml 共用一把锁:两个流程都写 pack-data,同时跑必然互相覆盖
group: pack-data-write
cancel-in-progress: false

env:
Expand Down Expand Up @@ -133,6 +137,11 @@ jobs:

# 推数据分支。每次都是独立的单提交(orphan)+ 强推:
# 数据不保留历史,仓库体积不会越滚越大;manifest 里的 ?v=指纹 保证客户端不吃旧缓存。
#
# 但「强推」只允许冲掉本工作流自己生成的东西。pack-data 上还住着
# themes/(主题包,人工发布)和 resources/avatars/(头像,avatars.yml 生成),
# 所以先把上一版整条分支继承下来,再盖这三个 JSON——否则每天两次同步
# 都会把用户已经下载过的主题包和头像冲成 404。
- name: Publish to pack-data
shell: bash
env:
Expand All @@ -155,33 +164,53 @@ jobs:
fi

D="$RUNNER_TEMP/pack-data"
rm -rf "$D"; mkdir -p "$D/resources"
cp resources/arknights.json resources/paradox.json resources/pack-manifest.json "$D/resources/"
rm -rf "$D"; mkdir -p "$D"
cd "$D"

git init -q -b "$MAA_PRTS_PACK_BRANCH"
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git remote add origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"

# 继承上一版(含 themes/ 与 resources/avatars/)。首次生成时 fetch 会失败,
# 此时就是一份干净的孤儿提交。
if git fetch -q --depth=1 origin "$MAA_PRTS_PACK_BRANCH" 2>/dev/null; then
git archive --format=tar FETCH_HEAD | tar -xf - -C .
echo "继承上一版:$(ls -d themes resources/avatars 2>/dev/null | tr '\n' ' ')"
fi

cat > "$D/README.md" <<'EOF'
# 只覆盖本工作流负责的三个文件
mkdir -p resources
cp "$GITHUB_WORKSPACE/resources/arknights.json" \
"$GITHUB_WORKSPACE/resources/paradox.json" \
"$GITHUB_WORKSPACE/resources/pack-manifest.json" resources/

cat > README.md <<'EOF'
# pack-data

MAA-PRTS 的游戏资源数据分支,由 `.github/workflows/pack.yml` 自动生成,
**请勿手工编辑**。
MAA-PRTS 的公共资源数据分支,**请勿手工编辑**。

| 文件 | 说明 |
| --- | --- |
| `resources/arknights.json` | 干员 / 技能 / 模组 / 关卡 / 区域 / 活动 |
| `resources/paradox.json` | 悖论模拟清单与解锁条件 |
| `resources/pack-manifest.json` | 版本、指纹、sha256、下载地址(客户端读它) |
| 目录 / 文件 | 说明 | 谁在维护 |
| --- | --- | --- |
| `resources/arknights.json` | 干员 / 技能 / 模组 / 关卡 / 区域 / 活动 | `pack.yml`(每天 12:00 / 16:00) |
| `resources/paradox.json` | 悖论模拟清单与解锁条件 | `pack.yml` |
| `resources/pack-manifest.json` | 版本、指纹、sha256、下载地址(客户端读它) | `pack.yml` |
| `resources/avatars/` | 干员头像 96px WebP + `avatar-index.json` | `avatars.yml`(每周一) |
| `themes/` | 第三方主题包 + `manifest.json` | 人工发布 |

只保留最新一份快照,每次同步都是单提交强制覆盖,不累积历史。
原始出处:`yuanyan3060/ArknightsGameResource`,源提交记在 manifest 的 `source.commit`。
每次同步都是单提交强制覆盖,不累积历史;但只会覆盖自己那一块,
其余目录原样继承。原始出处:`yuanyan3060/ArknightsGameResource`,
源提交记在 manifest 的 `source.commit`。
EOF

cd "$D"
git init -q -b "$MAA_PRTS_PACK_BRANCH"
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git add -A
if git diff --cached --quiet; then
echo "内容没有变化,本次不推送"
exit 0
fi

git commit -q -m "chore(pack): 同步游戏资源 ${VERSION}" \
-m "上游提交 ${SHA:0:12}" -m "指纹 ${FP}"
git remote add origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git push -q -f origin "HEAD:refs/heads/${MAA_PRTS_PACK_BRANCH}"

echo "### 资源已更新到 ${VERSION}" >> "$GITHUB_STEP_SUMMARY"
Expand Down
1 change: 1 addition & 0 deletions backend/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
'.js': 'application/javascript; charset=utf-8',
'.svg': 'image/svg+xml',
'.png': 'image/png',
'.webp': 'image/webp',
'.ico': 'image/x-icon',
'.woff2': 'font/woff2',
'.webm': 'video/webm',
Expand Down
22 changes: 22 additions & 0 deletions backend/core/appupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,25 @@ def run():
threading.Thread(target=run, daemon=True, name='install-quit').start()


# ---------------------------------------------------------------- 图标缓存
def refresh_icon_cache() -> bool:
"""通知资源管理器重建图标缓存(SHCNE_ASSOCCHANGED)

换了 exe 以后 shell 不会自己失效:2026-11-28 实测 iconcache_*.db 的
时间戳停在 11-25 02:49,中间 11-26 12:23 重启过电脑也没重建,桌面快捷
方式一直显示旧图标,只能手动清缓存。安装脚本收尾时顾不上(无窗口、
Add-Type 还可能被拦),所以新版本第一次启动、确认替换成功时补一次。
"""
if os.name != 'nt':
return False
try:
import ctypes
ctypes.windll.shell32.SHChangeNotify(0x08000000, 0, None, None)
return True
except Exception:
return False


# ---------------------------------------------------------------- 启动自检
def on_start() -> dict:
"""启动时结算上一次安装:替换成功就把 pending 清掉,失败则留痕
Expand Down Expand Up @@ -1147,6 +1166,9 @@ def on_start() -> dict:
os.remove(os.path.join(update_dir(), 'install-ok.txt'))
except Exception:
pass
# exe 换了新图,但 shell 手里还是旧缓存:重启电脑也不重建,
# 不主动发一次通知,用户的桌面图标会一直停在上一版的图案上
refresh_icon_cache()
return info


Expand Down
Loading