-
Notifications
You must be signed in to change notification settings - Fork 67
feat(update): 添加新的更新通道 Nightly
#1850
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
Open
Big-Cake-jpg
wants to merge
10
commits into
dev
Choose a base branch
from
feat/nightly
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
06e4e85
feat(update): 新的更新通道 `Nightly`
Big-Cake-jpg cb2f4ce
Merge branch 'dev' into feat/nightly
Big-Cake-jpg 64d9adc
ref(update): 移除无用逻辑,换用语义明确的 Exception
Big-Cake-jpg 9556bce
fix(update): 欸我草眼瞎忘修一个
Big-Cake-jpg bf18aa5
ref(update): 优化更新通道下拉框的禁用逻辑
Big-Cake-jpg 53bd78d
fix(update): 会错意了 把更新的弹窗补回来
Big-Cake-jpg 151f1db
ref(update): 扔掉 if 简化代码
Big-Cake-jpg 747aaa1
Merge branch 'dev' into feat/nightly
Big-Cake-jpg ef99eee
ref(update): 重构开发版的现有逻辑,适配新仓库结构
Big-Cake-jpg 3aed5f9
Merge branch 'dev' into feat/nightly
Big-Cake-jpg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| Public Enum UpdateChannel | ||
| stable | ||
| beta | ||
| nightly | ||
| End Enum | ||
|
|
||
| Public Enum UpdateArch | ||
|
|
||
100 changes: 100 additions & 0 deletions
100
Plain Craft Launcher 2/Modules/Updates/UpdatesGitHubModel.vb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| Imports System.IO.Compression | ||
| Imports Newtonsoft.Json | ||
| Imports PCL.Core.Utils | ||
|
|
||
| Public Class UpdatesGitHubModel | ||
| Implements IUpdateSource | ||
|
|
||
| Private Const NightlyJsonUrl As String = "https://github.com/PCL-Community/PCL2-CE/releases/download/nightly/nightly.json" | ||
| ' Private Const NightlyJsonUrl As String = "https://r2.230225.xyz/nightly.json" | ||
| Private _nightlyInfo As NightlyJsonModel | ||
|
|
||
| Public Property SourceName As String Implements IUpdateSource.SourceName | ||
|
|
||
| Public Function IsAvailable() As Boolean Implements IUpdateSource.IsAvailable | ||
| Return True ' Assume network is available | ||
| End Function | ||
|
|
||
| Public Function RefreshCache() As Boolean Implements IUpdateSource.RefreshCache | ||
| Try | ||
| Dim jsonContent = NetGetCodeByRequestRetry(NightlyJsonUrl) | ||
| _nightlyInfo = JsonConvert.DeserializeObject(Of NightlyJsonModel)(jsonContent) | ||
| Return _nightlyInfo IsNot Nothing | ||
| Catch ex As Exception | ||
| Log(ex, "[Update] Failed to fetch nightly.json from GitHub") | ||
| Return False | ||
| End Try | ||
| End Function | ||
|
|
||
| Public Function GetLatestVersion(channel As UpdateChannel, arch As UpdateArch) As VersionDataModel Implements IUpdateSource.GetLatestVersion | ||
| If channel <> UpdateChannel.nightly Then Throw New NotSupportedException("UpdatesGitHubModel only supports the Nightly channel.") | ||
| If _nightlyInfo Is Nothing AndAlso Not RefreshCache() Then Throw New InvalidOperationException("Failed to get nightly update info.") | ||
|
|
||
| Dim asset = GetAssetForArch(arch) | ||
|
|
||
| Return New VersionDataModel With { | ||
| .VersionName = _nightlyInfo.version, | ||
| .VersionCode = _nightlyInfo.version_code, | ||
| .SHA256 = asset.sha256, | ||
| .Source = SourceName, | ||
| .Changelog = _nightlyInfo.changelog | ||
| } | ||
| End Function | ||
|
|
||
| Public Function IsLatest(channel As UpdateChannel, arch As UpdateArch, currentVersion As SemVer, currentVersionCode As Integer) As Boolean Implements IUpdateSource.IsLatest | ||
| If channel <> UpdateChannel.nightly Then Throw New NotSupportedException("UpdatesGitHubModel only supports the Nightly channel.") | ||
| If _nightlyInfo Is Nothing AndAlso Not RefreshCache() Then Return True ' If we can't get info, assume we're latest to avoid errors | ||
|
|
||
| Return currentVersionCode >= _nightlyInfo.version_code | ||
| End Function | ||
|
|
||
| Public Function GetAnnouncementList() As VersionAnnouncementDataModel Implements IUpdateSource.GetAnnouncementList | ||
| Throw New Exception("GitHub Nightly 无公告系统") | ||
| End Function | ||
|
|
||
| Public Function GetDownloadLoader(channel As UpdateChannel, arch As UpdateArch, output As String) As List(Of LoaderBase) Implements IUpdateSource.GetDownloadLoader | ||
| If channel <> UpdateChannel.nightly Then Throw New NotSupportedException("UpdatesGitHubModel only supports the Nightly channel.") | ||
| If _nightlyInfo Is Nothing AndAlso Not RefreshCache() Then Throw New InvalidOperationException("Failed to get nightly update info for download.") | ||
|
|
||
| Dim asset = GetAssetForArch(arch) | ||
| Dim downloadUrl = asset.download_url | ||
| Dim tempPath = IO.Path.Combine(PathTemp, "Cache", "Update", "Download", $"{asset.sha256}.zip") | ||
|
|
||
| Dim loaders As New List(Of LoaderBase) | ||
| ' 1. 下载更新包 | ||
| loaders.Add(New LoaderDownload("下载更新", New List(Of NetFile) From {New NetFile({downloadUrl}, tempPath)})) | ||
|
|
||
| ' 2. 解压更新包,将 .exe 文件提取到 ModSecret 指定的 output 路径 | ||
| loaders.Add(New LoaderTask(Of String, Integer)("提取文件", Sub() | ||
| Using fs As New IO.FileStream(tempPath, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read) | ||
| Using zip As New ZipArchive(fs) | ||
| Dim entry = zip.Entries.FirstOrDefault(Function(x) x.Name.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) | ||
| If entry Is Nothing Then Throw New InvalidOperationException("在下载的更新包中找不到可执行文件。") | ||
| entry.ExtractToFile(output, True) | ||
| End Using | ||
| End Using | ||
| End Sub)) | ||
| Return loaders | ||
| End Function | ||
|
|
||
| Private Function GetAssetForArch(arch As UpdateArch) As NightlyAsset | ||
| Dim archName = If(arch = UpdateArch.arm64, "arm64", "x64") | ||
| Dim asset = _nightlyInfo.assets.FirstOrDefault(Function(a) a.arch.Equals(archName, StringComparison.OrdinalIgnoreCase)) | ||
| If asset Is Nothing Then Throw New InvalidOperationException($"Nightly build for architecture {archName} not found.") | ||
| Return asset | ||
| End Function | ||
|
|
||
| End Class | ||
|
|
||
| Public Class NightlyJsonModel | ||
| Public Property version As String | ||
| Public Property version_code As Integer | ||
| Public Property changelog As String | ||
| Public Property assets As List(Of NightlyAsset) | ||
| End Class | ||
|
|
||
| Public Class NightlyAsset | ||
| Public Property arch As String | ||
| Public Property download_url As String | ||
| Public Property sha256 As String | ||
| End Class | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.