diff --git a/Plain Craft Launcher 2/Application.xaml.vb b/Plain Craft Launcher 2/Application.xaml.vb index 34fc417..2ee8be9 100644 --- a/Plain Craft Launcher 2/Application.xaml.vb +++ b/Plain Craft Launcher 2/Application.xaml.vb @@ -96,6 +96,12 @@ Public Class Application End If '动态 DLL 调用 AddHandler AppDomain.CurrentDomain.AssemblyResolve, AddressOf AssemblyResolve + SetDllDirectory(Path & "PCL\") + If Is32BitSystem Then + File.WriteAllBytes(Path & "PCL\libwebp.dll", GetResources("libwebp32")) + Else + File.WriteAllBytes(Path & "PCL\libwebp.dll", GetResources("libwebp64")) + End If '日志初始化 LogStart() '添加日志 @@ -171,9 +177,11 @@ Public Class Application Private Shared AssemblyNAudio As Assembly Private Shared AssemblyJson As Assembly Private Shared AssemblyDialog As Assembly + Private Shared AssemblyWebp As Assembly Private Shared ReadOnly AssemblyNAudioLock As New Object Private Shared ReadOnly AssemblyJsonLock As New Object Private Shared ReadOnly AssemblyDialogLock As New Object + Private Shared ReadOnly AssemblyWebpLock As New Object Public Shared Function AssemblyResolve(sender As Object, args As ResolveEventArgs) As Assembly If args.Name.StartsWithF("NAudio") Then SyncLock AssemblyNAudioLock @@ -199,6 +207,14 @@ Public Class Application End If Return AssemblyDialog End SyncLock + ElseIf args.Name.StartsWithF("Imazen.WebP") Then + SyncLock AssemblyWebpLock + If AssemblyWebp Is Nothing Then + Log("[Start] 加载 DLL:Imazen.WebP") + AssemblyWebp = Assembly.Load(GetResources("WebP")) + End If + Return AssemblyWebp + End SyncLock Else Return Nothing End If diff --git a/Plain Craft Launcher 2/Modules/Minecraft/MyCompItem.xaml.vb b/Plain Craft Launcher 2/Modules/Minecraft/MyCompItem.xaml.vb index 6bf0f72..ee52b36 100644 --- a/Plain Craft Launcher 2/Modules/Minecraft/MyCompItem.xaml.vb +++ b/Plain Craft Launcher 2/Modules/Minecraft/MyCompItem.xaml.vb @@ -18,9 +18,6 @@ '网络图片 If File.Exists(FileAddress) Then PathLogo.Source = New MyBitmap(FileAddress) - ElseIf _Logo.EndsWithF(".webp", True) Then 'Modrinth 林业 Mod 使用了不支持的 WebP 格式 Logo - Log($"[Comp] 发现不支持的 WebP 格式图标,已更改为默认图标:{_Logo}") - PathLogo.Source = New MyBitmap(PathImage & "Icons/NoIcon.png") Else PathLogo.Source = New MyBitmap(PathImage & "Icons/NoIcon.png") RunInNewThread(Sub() LogoLoader(FileAddress), "Comp Logo Loader " & Uuid & "#", ThreadPriority.BelowNormal) @@ -58,6 +55,12 @@ RetryStart: End If '下载图片 NetDownload(Url, LocalFileAddress & DownloadEnd, True) + If Url.EndsWithF("webp") Then + Log($"[Comp] Webp 格式转换:{LocalFileAddress}") + Dim dec = New Imazen.WebP.SimpleDecoder() + Dim picFile = File.ReadAllBytes(LocalFileAddress & DownloadEnd) + dec.DecodeFromBytes(picFile, picFile.Length).Save(LocalFileAddress & DownloadEnd) + End If Dim LoadError As Exception = Nothing RunInUiWait( Sub() diff --git a/Plain Craft Launcher 2/Modules/Minecraft/MyLocalModItem.xaml.vb b/Plain Craft Launcher 2/Modules/Minecraft/MyLocalModItem.xaml.vb index 016f81a..a623f04 100644 --- a/Plain Craft Launcher 2/Modules/Minecraft/MyLocalModItem.xaml.vb +++ b/Plain Craft Launcher 2/Modules/Minecraft/MyLocalModItem.xaml.vb @@ -20,9 +20,6 @@ Public Class MyLocalModItem '网络图片 If File.Exists(FileAddress) Then PathLogo.Source = New MyBitmap(FileAddress) - ElseIf _Logo.EndsWithF(".webp", True) Then 'Modrinth 林业 Mod 使用了不支持的 WebP 格式 Logo - Log($"[LocalModItem] 发现不支持的 WebP 格式图标,已更改为默认图标:{_Logo}") - PathLogo.Source = New MyBitmap(PathImage & "Icons/NoIcon.png") Else PathLogo.Source = New MyBitmap(PathImage & "Icons/NoIcon.png") RunInNewThread(Sub() LogoLoader(FileAddress), "Comp Logo Loader " & Uuid & "#", ThreadPriority.BelowNormal) @@ -60,6 +57,12 @@ RetryStart: End If '下载图片 NetDownload(Url, LocalFileAddress & DownloadEnd, True) + If Url.EndsWithF("webp") Then + Log($"[Comp] Webp 格式转换:{LocalFileAddress}") + Dim dec = New Imazen.WebP.SimpleDecoder() + Dim picFile = File.ReadAllBytes(LocalFileAddress & DownloadEnd) + dec.DecodeFromBytes(picFile, picFile.Length).Save(LocalFileAddress & DownloadEnd) + End If Dim LoadError As Exception = Nothing RunInUiWait( Sub() diff --git a/Plain Craft Launcher 2/Modules/ModMain.vb b/Plain Craft Launcher 2/Modules/ModMain.vb index a971886..2136213 100644 --- a/Plain Craft Launcher 2/Modules/ModMain.vb +++ b/Plain Craft Launcher 2/Modules/ModMain.vb @@ -798,6 +798,8 @@ NextFile: Public Declare Function SetForegroundWindow Lib "user32" (hWnd As IntPtr) As Integer Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (hWnd As IntPtr, msg As UInteger, wParam As Long, lParam As Long) As Boolean + Public Declare Function SetDllDirectory Lib "kernel32" Alias "SetDllDirectoryA" (lpPathName As String) As Boolean + #End Region Public DragControl = Nothing diff --git a/Plain Craft Launcher 2/My Project/Resources.Designer.vb b/Plain Craft Launcher 2/My Project/Resources.Designer.vb index 033f910..990f9b4 100644 --- a/Plain Craft Launcher 2/My Project/Resources.Designer.vb +++ b/Plain Craft Launcher 2/My Project/Resources.Designer.vb @@ -120,6 +120,26 @@ Namespace My.Resources End Get End Property + ''' + ''' 查找 System.Byte[] 类型的本地化资源。 + ''' + Friend ReadOnly Property libwebp32() As Byte() + Get + Dim obj As Object = ResourceManager.GetObject("libwebp32", resourceCulture) + Return CType(obj,Byte()) + End Get + End Property + + ''' + ''' 查找 System.Byte[] 类型的本地化资源。 + ''' + Friend ReadOnly Property libwebp64() As Byte() + Get + Dim obj As Object = ResourceManager.GetObject("libwebp64", resourceCulture) + Return CType(obj,Byte()) + End Get + End Property + ''' ''' 查找 System.Byte[] 类型的本地化资源。 ''' @@ -149,5 +169,15 @@ Namespace My.Resources Return CType(obj,Byte()) End Get End Property + + ''' + ''' 查找 System.Byte[] 类型的本地化资源。 + ''' + Friend ReadOnly Property WebP() As Byte() + Get + Dim obj As Object = ResourceManager.GetObject("WebP", resourceCulture) + Return CType(obj,Byte()) + End Get + End Property End Module End Namespace diff --git a/Plain Craft Launcher 2/My Project/Resources.resx b/Plain Craft Launcher 2/My Project/Resources.resx index 66663f3..d15494b 100644 --- a/Plain Craft Launcher 2/My Project/Resources.resx +++ b/Plain Craft Launcher 2/My Project/Resources.resx @@ -136,6 +136,12 @@ ..\Resources\Newtonsoft.Json.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Resources\libwebp32.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\libwebp64.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + ..\Resources\ModData.txt;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 @@ -145,4 +151,7 @@ ..\Resources\transformer.jar;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Resources\Imazen.WebP.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/Plain Craft Launcher 2/Plain Craft Launcher 2.vbproj b/Plain Craft Launcher 2/Plain Craft Launcher 2.vbproj index 8246a85..bc74b16 100644 --- a/Plain Craft Launcher 2/Plain Craft Launcher 2.vbproj +++ b/Plain Craft Launcher 2/Plain Craft Launcher 2.vbproj @@ -140,6 +140,10 @@ false + + False + Resources\Imazen.WebP.dll + False False @@ -185,9 +189,6 @@ MyIconTextButton.xaml - - - @@ -472,7 +473,6 @@ FormMain.xaml Code - MSBuild:Compile Designer @@ -927,7 +927,9 @@ - + + + diff --git a/Plain Craft Launcher 2/Resources/Imazen.WebP.dll b/Plain Craft Launcher 2/Resources/Imazen.WebP.dll new file mode 100644 index 0000000..ac7cf07 Binary files /dev/null and b/Plain Craft Launcher 2/Resources/Imazen.WebP.dll differ diff --git a/Plain Craft Launcher 2/Resources/libwebp32.dll b/Plain Craft Launcher 2/Resources/libwebp32.dll new file mode 100644 index 0000000..9ebce90 Binary files /dev/null and b/Plain Craft Launcher 2/Resources/libwebp32.dll differ diff --git a/Plain Craft Launcher 2/Resources/libwebp64.dll b/Plain Craft Launcher 2/Resources/libwebp64.dll new file mode 100644 index 0000000..d3e2d47 Binary files /dev/null and b/Plain Craft Launcher 2/Resources/libwebp64.dll differ