From a54cfef36ac3ad257234aaf14b624e34f7e5ed1d Mon Sep 17 00:00:00 2001 From: Pigeon0v0 Date: Thu, 27 Jun 2024 19:43:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Images/{Icons => Blocks}/NeoForge.png | Bin .../Modules/Minecraft/ModDownload.vb | 76 +++++------------- .../Modules/Minecraft/ModMinecraft.vb | 20 ++--- .../Pages/PageDownload/ModDownloadLib.vb | 29 +++---- .../PageDownload/PageDownloadInstall.xaml | 2 +- .../PageDownload/PageDownloadInstall.xaml.vb | 3 +- .../Pages/PageVersion/PageVersionOverall.xaml | 2 +- .../Plain Craft Launcher 2.vbproj | 2 +- Plain Craft Launcher 2/Resources/Custom.xaml | 2 +- 9 files changed, 42 insertions(+), 94 deletions(-) rename Plain Craft Launcher 2/Images/{Icons => Blocks}/NeoForge.png (100%) diff --git a/Plain Craft Launcher 2/Images/Icons/NeoForge.png b/Plain Craft Launcher 2/Images/Blocks/NeoForge.png similarity index 100% rename from Plain Craft Launcher 2/Images/Icons/NeoForge.png rename to Plain Craft Launcher 2/Images/Blocks/NeoForge.png diff --git a/Plain Craft Launcher 2/Modules/Minecraft/ModDownload.vb b/Plain Craft Launcher 2/Modules/Minecraft/ModDownload.vb index 1d5f353..43d683e 100644 --- a/Plain Craft Launcher 2/Modules/Minecraft/ModDownload.vb +++ b/Plain Craft Launcher 2/Modules/Minecraft/ModDownload.vb @@ -785,14 +785,16 @@ Try For Each Token As String In VersionsJArray Dim Version As String = Token.Replace("neoforge-", "") - Dim Inherit As String = $"1.{Version.ToString().Split(".")(0)}.{Token.ToString().Split(".")(1)}" + Dim Inherit As String = $"1.{Version.Split(".")(0)}.{Token.Split(".")(1)}" If Inherit.EndsWith(".0") Then Inherit = Inherit.Replace(".0", "") - Versions.Add(Inherit) + If Versions.Contains(Inherit) Then + Continue For + Else + Versions.Add(Inherit) + End If Next - Versions.Distinct() '去重 Catch ex As Exception Log(ex, LogLevel.Feedback) - 'Throw New Exception("版本列表解析失败(" & VersionsJArray.ToString & ")", ex) End Try If Not Versions.Any() Then Throw New Exception("没有可用版本") Loader.Output = New DlNeoForgeListResult With {.IsOfficial = True, .SourceName = "NeoForge 官方源", .Value = Versions} @@ -808,9 +810,8 @@ Dim ClientReleases As New List(Of String) For Each Client In ClientVersions '排除快照版或远古版等特殊版本 - Dim ClientVersionString = Client("id").ToString() - If Not (ClientVersionString.ContainsF("a") OrElse ClientVersionString.ContainsF("b") OrElse ClientVersionString.ContainsF("c") OrElse ClientVersionString.ContainsF("w") OrElse ClientVersionString.ContainsF("pre") OrElse ClientVersionString.ContainsF("Pre") OrElse ClientVersionString.ContainsF("rc") OrElse ClientVersionString.ContainsF("b") OrElse ClientVersionString.ContainsF("rd") OrElse ClientVersionString.ContainsF("inf")) Then - ClientReleases.Add(ClientVersionString) + If RegexCheck(Client("id").ToString(), "[0,9.]+") Then + ClientReleases.Add(Client("id").ToString()) End If Next @@ -846,10 +847,6 @@ ''' Public Hash As String = Nothing ''' - ''' 安装类型。有 installer、client、universal 三种。 - ''' - Public Category As String - ''' ''' 版本分支。若无分支则为 Nothing。 ''' Public Branch As String = Nothing @@ -876,19 +873,6 @@ Public Value As JObject End Structure ''' - ''' 构建数。 - ''' - Public ReadOnly Property Build As Integer - Get - Dim Version = Me.VersionName.Split(".") - If Version(0) < 15 Then - Return Version(Version.Count - 1) - Else - Return Version(Version.Count - 1) + 10000 - End If - End Get - End Property - ''' ''' 用于下载的文件版本名。可能在 Version 的基础上添加了分支。 ''' Public ReadOnly Property FileVersion As String @@ -908,10 +892,6 @@ End If End Get End Property - ''' - ''' 文件扩展名。 - ''' - Public FileSuffix As String = "jar" End Class ''' ''' NeoForge 版本列表,主加载器。 @@ -944,13 +924,9 @@ Public Sub DlNeoForgeVersionOfficialMain(Loader As LoaderTask(Of String, List(Of DlNeoForgeVersionEntry))) Dim ResultLatest As String Dim ResultLegacy As String - Dim ResultLatestJson As JObject - Dim ResultLegacyJson As JObject - Dim VersionsJArray As JArray - Dim IsLegacyNeo As Boolean = False Try - ResultLatest = NetGetCodeByDownload("https://maven.neoforged.net/api/maven/versions/releases/net/neoforged/neoforge", UseBrowserUserAgent:=True) - ResultLegacy = NetGetCodeByDownload("https://maven.neoforged.net/api/maven/versions/releases/net/neoforged/forge", UseBrowserUserAgent:=True) + ResultLatest = NetGetCodeByDownload("https://maven.neoforged.net/api/maven/versions/releases/net/neoforged/neoforge", UseBrowserUserAgent:=True, IsJson:=True) + ResultLegacy = NetGetCodeByDownload("https://maven.neoforged.net/api/maven/versions/releases/net/neoforged/forge", UseBrowserUserAgent:=True, IsJson:=True) Catch ex As Exception If GetExceptionSummary(ex).Contains("(404)") Then Throw New Exception("没有可用版本") @@ -959,15 +935,13 @@ End If End Try If ResultLatest.Length < 50 AndAlso ResultLegacy.Length < 50 Then Throw New Exception("获取到的版本列表长度不足(" & ResultLatest & ")") - ResultLatestJson = GetJson(ResultLatest) - ResultLegacyJson = GetJson(ResultLegacy) - If Loader.Input IsNot Nothing Then - If Loader.Input.ToString().Contains("1.20.1") Then - VersionsJArray = ResultLegacyJson("versions") - IsLegacyNeo = True - Else - VersionsJArray = ResultLatestJson("versions") - End If + Dim ResultLatestJson As JObject = GetJson(ResultLatest) + Dim ResultLegacyJson As JObject = GetJson(ResultLegacy) + Dim VersionsJArray As JArray + Dim IsLegacyNeo As Boolean = False + If Loader.Input IsNot Nothing AndAlso Loader.Input.ToString().Contains("1.20.1") Then + VersionsJArray = ResultLegacyJson("versions") + IsLegacyNeo = True Else VersionsJArray = ResultLatestJson("versions") End If @@ -984,19 +958,14 @@ StdVersion = Token.Replace("neoforge-", "").Replace("1.20.1-", "") IsBeta = False End If - Dim Inherit As String = "1." & StdVersion.Split(".")(0) & "." & StdVersion.Split(".")(1) - Inherit = Inherit.Replace(".0", "") - If IsLegacyNeo Then Inherit = "1.20.1" + Dim Inherit As String = $"1.{StdVersion.Split(".")(0)}.{StdVersion.Split(".")(1)}" + If Inherit.EndsWithF(".0") Then Inherit.Remove(Inherit.LastIndexOfF(".0"), 1) + Inherit = If(IsLegacyNeo, "1.20.1", Inherit) Dim Entry = New DlNeoForgeVersionEntry If Loader.Input IsNot Nothing Then - If IsLegacyNeo Then + If IsLegacyNeo OrElse Inherit.Contains(Loader.Input.ToString().Replace("1.", "")) Then Entry = New DlNeoForgeVersionEntry With {.VersionName = rawVersion, .Inherit = Inherit, .IsBeta = IsBeta, .VersionCode = StdVersion} Versions.Add(Entry) - Else - If Inherit.Contains(Loader.Input.ToString().Replace("1.", "")) Then - Entry = New DlNeoForgeVersionEntry With {.VersionName = rawVersion, .Inherit = Inherit, .IsBeta = IsBeta, .VersionCode = StdVersion} - Versions.Add(Entry) - End If End If Else Entry = New DlNeoForgeVersionEntry With {.VersionName = rawVersion, .Inherit = Inherit, .IsBeta = IsBeta, .VersionCode = StdVersion} @@ -1004,8 +973,7 @@ End If Next Catch ex As Exception - MyMsgBox(ex.ToString(), "错误") - Throw New Exception("版本列表解析失败(" & VersionsJArray.ToString & ")", ex) + Log(ex, LogLevel.Feedback) End Try If Not Versions.Any() Then Throw New Exception("没有可用版本") Dim VersionsArray = Versions.ToList() diff --git a/Plain Craft Launcher 2/Modules/Minecraft/ModMinecraft.vb b/Plain Craft Launcher 2/Modules/Minecraft/ModMinecraft.vb index 620134d..676d5b1 100644 --- a/Plain Craft Launcher 2/Modules/Minecraft/ModMinecraft.vb +++ b/Plain Craft Launcher 2/Modules/Minecraft/ModMinecraft.vb @@ -761,7 +761,7 @@ ExitDataLoad: Case McVersionState.Forge Logo = PathImage & "Blocks/Anvil.png" Case McVersionState.NeoForge - Logo = PathImage & "Icons/NeoForge.png" + Logo = PathImage & "Blocks/NeoForge.png" Case McVersionState.Fabric Logo = PathImage & "Blocks/Fabric.png" Case McVersionState.OptiFine @@ -979,25 +979,15 @@ ExitDataLoad: Else Throw New Exception("无效的 Fabric 版本:" & ForgeVersion) End If - ElseIf HasForge Then - If ForgeVersion = "未知版本" Then Return 0 - Dim SubVersions = ForgeVersion.Split(".") + ElseIf HasForge OrElse HasNeoForge Then + If ForgeVersion = "未知版本" AndAlso NeoForgeVersion = "未知版本" Then Return 0 + Dim SubVersions = If(HasForge, ForgeVersion.Split("."), NeoForgeVersion.Split(".")) If SubVersions.Length = 4 Then _SortCode = Val(SubVersions(0)) * 1000000 + Val(SubVersions(1)) * 10000 + Val(SubVersions(3)) ElseIf SubVersions.Length = 3 Then _SortCode = Val(SubVersions(0)) * 1000000 + Val(SubVersions(1)) * 10000 + Val(SubVersions(2)) Else - Throw New Exception("无效的 Forge 版本:" & ForgeVersion) - End If - ElseIf HasNeoForge Then - If NeoForgeVersion = "未知版本" Then Return 0 - Dim SubVersions = NeoForgeVersion.Split(".") - If SubVersions.Length = 4 Then - _SortCode = Val(SubVersions(0)) * 1000000 + Val(SubVersions(1)) * 10000 + Val(SubVersions(3)) - ElseIf SubVersions.Length = 3 Then - _SortCode = Val(SubVersions(0)) * 1000000 + Val(SubVersions(1)) * 10000 + Val(SubVersions(2)) - Else - Throw New Exception("无效的 NeoForge 版本:" & NeoForgeVersion) + Throw New Exception(If(HasForge, "无效的 Forge 版本:" & ForgeVersion, "无效的 NeoForge 版本:" & NeoForgeVersion)) End If ElseIf HasOptiFine Then If OptiFineVersion = "未知版本" Then Return 0 diff --git a/Plain Craft Launcher 2/Pages/PageDownload/ModDownloadLib.vb b/Plain Craft Launcher 2/Pages/PageDownload/ModDownloadLib.vb index bbe980a..b63f82a 100644 --- a/Plain Craft Launcher 2/Pages/PageDownload/ModDownloadLib.vb +++ b/Plain Craft Launcher 2/Pages/PageDownload/ModDownloadLib.vb @@ -1701,7 +1701,7 @@ Retry: Public Sub McDownloadNeoForge(DownloadInfo As DlNeoForgeVersionEntry) '初始化参数 Dim Id As String = DownloadInfo.Inherit & "-neoforge-" & DownloadInfo.VersionName - Dim Target As String = PathTemp & "Cache\Code\NeoForgeInstall-" & DownloadInfo.VersionName & "_" & GetUuid() & "." & DownloadInfo.FileSuffix + Dim Target As String = PathTemp & "Cache\Code\NeoForgeInstall-" & DownloadInfo.VersionName & "_" & GetUuid() & ".jar" Dim VersionFolder As String = PathMcFolder & "versions\" & Id & "\" Dim DisplayName As String = "NeoForge " & DownloadInfo.Inherit & " - " & DownloadInfo.VersionName Try @@ -1745,7 +1745,7 @@ Retry: End Sub Public Sub McDownloadNeoForgeSave(DownloadInfo As DlNeoForgeVersionEntry) Try - Dim Target As String = SelectAs("选择保存位置", DownloadInfo.FileName, "NeoForge 文件 (*." & DownloadInfo.FileSuffix & ")|*." & DownloadInfo.FileSuffix) + Dim Target As String = SelectAs("选择保存位置", DownloadInfo.FileName, "NeoForge 文件 (*.jar)") Dim DisplayName As String = "NeoForge " & DownloadInfo.Inherit & " - " & DownloadInfo.VersionName If Not Target.Contains("\") Then Exit Sub @@ -2011,20 +2011,11 @@ Retry: If IsCustomFolder Then Throw New Exception("如果没有指定原版下载器,则不能指定 MC 安装文件夹") ClientDownloadLoader = McDownloadClient(NetPreDownloadBehaviour.ExitWhileExistsOrDownloading, Inherit) End If - Dim Files - If DownloadInfo.VersionCode.StartsWith("47.") Then '1.20.1 NeoForge 下载地址不同 - Dim FilesLegacy As New List(Of NetFile) From {New NetFile({ - "https://bmclapi2.bangbang93.com/maven/net/neoforged/forge/" & "1.20.1-" & DownloadInfo.VersionCode & If(DownloadInfo.IsBeta, "-beta", "") & "/" & DownloadInfo.FileName, - "https://maven.neoforged.net/releases/net/neoforged/forge/" & "1.20.1-" & DownloadInfo.VersionCode & If(DownloadInfo.IsBeta, "-beta", "") & "/" & DownloadInfo.FileName + Dim IsLegacyNeo As Boolean = DownloadInfo.VersionCode.StartsWith("47.") + Dim Files As New List(Of NetFile) From {New NetFile({ + $"https://bmclapi2.bangbang93.com/maven/net/neoforged/{If(IsLegacyNeo, "", "neo")}forge/{If(IsLegacyNeo, "1.20.1-", "")}{DownloadInfo.VersionCode}{If(DownloadInfo.IsBeta, "-beta", "")}/{DownloadInfo.FileName}", + $"https://maven.neoforged.net/releases/net/neoforged/{If(IsLegacyNeo, "", "neo")}forge/{If(IsLegacyNeo, "1.20.1-", "")}{DownloadInfo.VersionCode}{If(DownloadInfo.IsBeta, "-beta", "")}/{DownloadInfo.FileName}" }, InstallerAddress, New FileChecker(MinSize:=64 * 1024, Hash:=DownloadInfo.Hash))} - Files = FilesLegacy - Else - Dim FilesLatest As New List(Of NetFile) From {New NetFile({ - "https://bmclapi2.bangbang93.com/maven/net/neoforged/neoforge/" & DownloadInfo.VersionCode & If(DownloadInfo.IsBeta, "-beta", "") & "/" & DownloadInfo.FileName, - "https://maven.neoforged.net/releases/net/neoforged/neoforge/" & DownloadInfo.VersionCode & If(DownloadInfo.IsBeta, "-beta", "") & "/" & DownloadInfo.FileName - }, InstallerAddress, New FileChecker(MinSize:=64 * 1024, Hash:=DownloadInfo.Hash))} - Files = FilesLatest - End If Task.Output = Files End Sub) With {.ProgressWeight = 0.5, .Show = False}) Loaders.Add(New LoaderDownload("下载 NeoForge 主文件", New List(Of NetFile)) With {.ProgressWeight = 9}) @@ -2224,9 +2215,9 @@ Retry: .Title = If(Entry.IsBeta, Entry.VersionCode & "-beta", Entry.VersionCode), .SnapsToDevicePixels = True, .Height = 42, .Type = MyListItem.CheckType.Clickable, .Tag = Entry, .Info = If(Entry.IsBeta, "测试版", "稳定版") & If(Entry.ReleaseTime = "", - If(ModeDebug, If(Entry.Category IsNot Nothing, "种类:" & Entry.Category, "") & If(Entry.Branch Is Nothing, "", ",开发分支:" & Entry.Branch), ""), - "发布于 " & Entry.ReleaseTime & If(ModeDebug, ",种类:" & Entry.Category & If(Entry.Branch Is Nothing, "", ",开发分支:" & Entry.Branch), "")), - .Logo = PathImage & "Icons/NeoForge.png" + If(ModeDebug, If(Entry.Branch Is Nothing, "", ",开发分支:" & Entry.Branch), ""), + "发布于 " & Entry.ReleaseTime & If(ModeDebug, If(Entry.Branch Is Nothing, "", ",开发分支:" & Entry.Branch), "")), + .Logo = PathImage & "Blocks/NeoForge.png" } AddHandler NewItem.Click, OnClick '建立菜单 @@ -2559,7 +2550,7 @@ Retry: Public Function McInstallLoader(Request As McInstallRequest, Optional DontFixLibraries As Boolean = False) As List(Of LoaderBase) '获取缓存目录 Dim PathInstallTemp As String - If PathTemp.Contains(" ") AndAlso (Request.ForgeEntry IsNot Nothing Or Request.NeoForgeEntry IsNot Nothing) Then + If PathTemp.Contains(" ") AndAlso (Request.ForgeEntry IsNot Nothing OrElse Request.NeoForgeEntry IsNot Nothing) Then PathInstallTemp = OsDrive & "ProgramData\PCL\Install\" Else PathInstallTemp = PathTemp & "Install\" diff --git a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadInstall.xaml b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadInstall.xaml index 9676cfa..1cf0a2d 100644 --- a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadInstall.xaml +++ b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadInstall.xaml @@ -89,7 +89,7 @@ - + diff --git a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadInstall.xaml.vb b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadInstall.xaml.vb index a2ff68d..1adeb06 100644 --- a/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadInstall.xaml.vb +++ b/Plain Craft Launcher 2/Pages/PageDownload/PageDownloadInstall.xaml.vb @@ -541,7 +541,7 @@ ElseIf SelectedForge IsNot Nothing Then Return "pack://application:,,,/images/Blocks/Anvil.png" ElseIf SelectedNeoForge IsNot Nothing Then - Return "pack://application:,,,/images/Icons/NeoForge.png" + Return "pack://application:,,,/images/Blocks/NeoForge.png" ElseIf SelectedLiteLoader IsNot Nothing Then Return "pack://application:,,,/images/Blocks/Egg.png" ElseIf SelectedOptiFine IsNot Nothing Then @@ -946,7 +946,6 @@ End If If Loader.State <> LoadState.Finished Then Return "获取版本列表失败:未知错误,状态为 " & GetStringFromEnum(Loader.State) For Each Version In Loader.Output - If Version.Category = "universal" OrElse Version.Category = "client" Then Continue For '跳过无法自动安装的版本 If SelectedForge IsNot Nothing Then Return "与 Forge 不兼容" If SelectedFabric IsNot Nothing Then Return "与 Fabric 不兼容" Return Nothing diff --git a/Plain Craft Launcher 2/Pages/PageVersion/PageVersionOverall.xaml b/Plain Craft Launcher 2/Pages/PageVersion/PageVersionOverall.xaml index 4f0ad73..d461c04 100644 --- a/Plain Craft Launcher 2/Pages/PageVersion/PageVersionOverall.xaml +++ b/Plain Craft Launcher 2/Pages/PageVersion/PageVersionOverall.xaml @@ -37,7 +37,7 @@ - + diff --git a/Plain Craft Launcher 2/Plain Craft Launcher 2.vbproj b/Plain Craft Launcher 2/Plain Craft Launcher 2.vbproj index 663d1ee..7331061 100644 --- a/Plain Craft Launcher 2/Plain Craft Launcher 2.vbproj +++ b/Plain Craft Launcher 2/Plain Craft Launcher 2.vbproj @@ -924,7 +924,7 @@ - + \ No newline at end of file diff --git a/Plain Craft Launcher 2/Resources/Custom.xaml b/Plain Craft Launcher 2/Resources/Custom.xaml index 1d5bb85..bf12a82 100644 --- a/Plain Craft Launcher 2/Resources/Custom.xaml +++ b/Plain Craft Launcher 2/Resources/Custom.xaml @@ -202,7 +202,7 @@ - +