-
Notifications
You must be signed in to change notification settings - Fork 53
refactor(update): 迁移并重构更新逻辑 #2282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ruattd
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
从 VB 把史山 Copy-Paste 到 C# 没什么意义
我衷心建议你去读读别的优秀开源项目源码,自己写写实际项目沉淀一下,再考虑动 CE 的核心设施
以及,你起名字的能力确实不太够,要不借助一下 AI?
| /// <summary> | ||
| /// 下载更新文件 | ||
| /// </summary> | ||
| /// <param name="outputPath">输出路径</param> | ||
| public Task<bool> DownloadAsync(string outputPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
更新源自己负责下载会导致很多重复的可复用内容
|
|
||
| public string SourceName => name; | ||
|
|
||
| private static readonly string _TempPath = Path.Combine(FileService.TempPath, "Cache", "Update"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
《TempPath》《Cache》《Update》
很难不让人怀疑你在把缓存目录当数据目录用
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个实现里我注意到了很多抛出的异常,你在上层有健全的异常处理来利用这个抛出异常的机制吗,还是仅仅把它直接丢给 Lifecycle 或 UI 层的保底处理?
这里抛出异常这种设计本身就不是很合理,况且一般使用这种设计传递信息都是会自定义异常的,然而你抛的都是stdlib 自带的异常
| _LogTrace("开始获取版本信息"); | ||
| var channelName = Config.System.Update.UpdateChannel switch | ||
| { | ||
| 0 => "sr", | ||
| 1 => "fr", | ||
| _ => "sr" | ||
| } + (RuntimeInformation.ProcessArchitecture == Architecture.Arm64 ? "arm64" : "x64"); | ||
|
|
||
| var assets = await _GetRemoteInfoByNameAsync<VersionAssetsDataModel>( | ||
| $"updates-{channelName}", "updates/").ConfigureAwait(false); | ||
| _LogTrace("版本信息获取完成"); | ||
|
|
||
| ret = assets?.Assets.FirstOrDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目前更新是打算改成逐层检查的逻辑的,这里仍然用了传统的逻辑,而且这段逻辑可以复用吧
| public Task<AnnouncementsListModel> GetAnnouncementAsync() | ||
| { | ||
| throw new NotSupportedException("MirrorChyan 更新源不支持公告功能"); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么不直接设计成返回 nullable 呢,这点 unsupported 的破事都要抛个异常,不就是把史山直接搬过来了
| _LogInfo("开始下载更新文件"); | ||
| var manager = new DownloadManager(new FastMirrorSelector(NetworkService.GetClient())); | ||
| await manager.DownloadAsync(task, CancellationToken.None).ConfigureAwait(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
虽然不知道这个下载器支不支持但是提个醒,这个下载源最好限制单线程
|
|
||
| /// <summary> | ||
| /// 已显示的启动器公告。 | ||
| /// </summary> | ||
| [ConfigItem<string>("SystemSystemAnnouncement", "", ConfigSource.Local)] public partial string ShowedAnnouncement { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
直接用 List
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你这个 RemoteInfo 干的事跟这个名字八竿子打不着
|
|
||
| [LifecycleService(LifecycleState.BeforeLoading)] | ||
| public sealed class UpdateService : GeneralService | ||
| [LifecycleScope("update", "处理更新参数")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
真的只是“处理更新参数”吗
|
唉...我应该再关PR再次重写 |
No description provided.