Skip to content

[Feature] 通过Mirror酱API实现自动更新 #208

@ZengXiaoPi

Description

@ZengXiaoPi

应该被确定的 | Confirm

  • 我填写的标题意义明确,而不是“一个建议”、“卡住了”等 | The title is clear rather than "A advice".
  • 我已确认在Issue目前没有类似 issue | I have confirmed that there is no similar issue in Issue at this time.
  • 我确定这是一个建议,而不是遇到了问题 | I'm sure it was a suggestion, not a problem encountered
  • 我理解并愿意跟进此 issue,协助测试和提供反馈 | I understand and am willing to follow up on this issue, assist with testing and provide feedback.
  • 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 issue 可能会被无视或直接关闭 | I understand and agree with the above, and understand that project maintainers have limited energy, and that issues that don't follow the rules may be ignored or simply shut down

建议 | Suggestion

目前,LALC已接入Mirror酱,Mirror酱提供了详尽的API,然而目前LALC还没有自动更新相关代码
目前也仅有一个检测自动更新的函数checkForUpdates,用的还是Github API,这会大幅下降国内可用性
我以个人开发者的角度简单拆解一下自动更新逻辑,希望能有些帮助
https://mirrorchyan.com/api/resources/LALC/latest结构(传有CDK情况下)类似于

此处使用LLC项目的json示例,且传入cdk
{
    "code": 0,
    "msg": "success",
    "data": {
        "version_name": "2025082101",
        "version_number": 1,
        "url": "https://mirrorchyan.com/api/resources/download/XXXXXXXXXX",
        "sha256": "XXXXXXXX",
        "channel": "stable",
        "os": "",
        "arch": "",
        "update_type": "full",
        "release_note": "XXXXX",
        "filesize": 3739710,
        "cdk_expired_time": 1769875200
    }
}

其中,version_number能用于高效检测当前版本是否过时,当然,也可以用version_name判断
而使用url即可下载包(此处需要注意,传入current_version字段可生成增量包节省流量,尤其是在LALC体积巨大的情况下)
另外,若不传入cdk字段,则不会有urlsha256,但仍然可以获取version以校验是否过时

那么问题来了,如何对程序进行更新?
既然LALC使用zip,那么就可以直接调用Windows有关Zip的API,可供参考的思路:在Temp目录下创建bat或ps1,调用Windows自带的zip接口解压下载下来的zip到根目录,同时,根据changes.json中的内容删除deletes下的文件

可供参考的changes.json示例
{
  "added": [
    "foo/a.png",
    "foo/b.png"
  ],
  "deleted": [
    "foo/c.png"
  ],
  "modified": [
    "resource/config.json"
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions