Compare commits
4
Commits
216b91f784
..
v0.1.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ef14b65fe | ||
|
|
1e1cafab2f | ||
|
|
dea4932d9c | ||
|
|
d66dc97de1 |
No files matched your search
@@ -26,6 +26,7 @@ x86/
|
||||
[Aa][Rr][Mm]64/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Bb]uild/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
[submodule "MeloongCore"]
|
||||
path = MeloongCore
|
||||
url = https://github.com/Meloong-Git/MeloongCore.git
|
||||
url = https://git.infstar.cn/InfStarMC/MeloongCore.git
|
||||
@@ -40,8 +40,13 @@ Public Class Application
|
||||
If e.Args.Length > 0 Then
|
||||
If e.Args(0) = "--update" Then
|
||||
'自动更新
|
||||
UpdateReplace(e.Args(1), e.Args(2).Trim(""""), e.Args(3).Trim(""""), e.Args(4))
|
||||
Environment.Exit(ProcessReturnValues.TaskDone)
|
||||
Dim PreviousProcessId As Integer
|
||||
Dim RestartAfterUpdate As Boolean
|
||||
If e.Args.Length <> 5 OrElse Not Integer.TryParse(e.Args(1), PreviousProcessId) OrElse Not Boolean.TryParse(e.Args(4), RestartAfterUpdate) Then
|
||||
Environment.Exit(ProcessReturnValues.Fail)
|
||||
Return
|
||||
End If
|
||||
Environment.Exit(If(UpdateReplace(PreviousProcessId, e.Args(2), e.Args(3), RestartAfterUpdate), ProcessReturnValues.TaskDone, ProcessReturnValues.Fail))
|
||||
ElseIf e.Args(0) = "--gpu" Then
|
||||
'调整显卡设置
|
||||
Try
|
||||
@@ -164,7 +169,7 @@ RetryCacheCheck:
|
||||
End Try
|
||||
End If
|
||||
'将已有的 PCL 窗口拖出来
|
||||
Dim WindowHwnd As IntPtr = FindWindow(Nothing, "Plain Craft Launcher ")
|
||||
Dim WindowHwnd As IntPtr = FindWindow(Nothing, "Plain Craft Launcher (PCL) InfstarMC Edition")
|
||||
If WindowHwnd = IntPtr.Zero Then WindowHwnd = FindWindow(Nothing, "Plain Craft Launcher 2 ")
|
||||
If WindowHwnd <> IntPtr.Zero Then ShowWindowToTop(WindowHwnd)
|
||||
'播放提示音并退出
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
xmlns:local="clr-namespace:PCL"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
|
||||
x:Name="WindMain" x:Class="FormMain" Style="{StaticResource MyWindow}"
|
||||
AllowDrop="True" Topmost="True" Title="Plain Craft Launcher " AllowsTransparency="True" MinHeight="470" MinWidth="810"
|
||||
AllowDrop="True" Topmost="True" Title="Plain Craft Launcher (PCL) InfstarMC Edition" AllowsTransparency="True" MinHeight="470" MinWidth="810"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Disabled" Icon="/Plain Craft Launcher 2;component/Images/icon.ico" WindowStyle="None"
|
||||
ResizeMode="CanMinimize" Background="{x:Null}" d:DesignWidth="870" d:DesignHeight="520" Width="850" Height="500"
|
||||
RenderTransformOrigin="0.5,0.5">
|
||||
|
||||
@@ -449,7 +449,7 @@ Public Class FormMain
|
||||
Telemetry("启动")
|
||||
'开源版本提示
|
||||
If VersionBranchMain = "OpenSource" Then
|
||||
MyMsgBox($"该版本中无法使用以下特性:{vbCrLf}- CurseForge API 调用:需要自行申请 API Key,然后添加到 ModSecret.vb 的开头{vbCrLf}- 正版登录:需要自行向微软申请 Client ID,然后添加到 ModSecret.vb 的开头{vbCrLf}- 更新与联网通知:避免滥用隐患{vbCrLf}- 主题切换:这是需要赞助解锁的纪念性质的功能,别让赞助者太伤心啦……{vbCrLf}- 百宝箱:开发早期往里面塞了些开发工具,整理起来太麻烦了……", "开源版本说明")
|
||||
MyMsgBox($"PCL-ISE 是 InfstarMC 基于 PCL 开发的第三方修改版。{vbCrLf}可在设置中检查 InfstarMC 仓库发布的启动器更新。{vbCrLf}{vbCrLf}当前仍需单独配置:{vbCrLf}- 正版登录:申请并设置环境变量 PCL_MS_CLIENT_ID。{vbCrLf}- CurseForge:申请并设置环境变量 PCL_CURSEFORGE_API_KEY。{vbCrLf}设置后请重新启动启动器。", "PCL-ISE 开发版说明")
|
||||
End If
|
||||
End Sub, "初始化", ThreadPriority.Lowest)
|
||||
|
||||
@@ -623,7 +623,7 @@ Public Class FormMain
|
||||
If ReturnCode = ProcessReturnValues.Exception Then
|
||||
If Not IsLogShown Then
|
||||
FeedbackInfo()
|
||||
Logger.Info("请在 https://github.com/Meloong-Git/PCL/issues 提交错误报告,以便于作者解决此问题!")
|
||||
Logger.Info("请在 https://git.infstar.cn/InfStarMC/PCL-ISE/issues 提交错误报告,以便于作者解决此问题!")
|
||||
IsLogShown = True
|
||||
StartProcess(Paths.Base & "PCL\Log1.txt")
|
||||
End If
|
||||
@@ -753,8 +753,8 @@ Public Class FormMain
|
||||
FrmSetupUI.PanLogoChange.Visibility = Visibility.Collapsed
|
||||
End If
|
||||
Case 1 '默认
|
||||
ShapeTitleLogo.Visibility = Visibility.Visible
|
||||
LabTitleLogo.Visibility = Visibility.Collapsed
|
||||
ShapeTitleLogo.Visibility = Visibility.Collapsed
|
||||
LabTitleLogo.Visibility = Visibility.Visible
|
||||
ImageTitleLogo.Visibility = Visibility.Collapsed
|
||||
If Not IsNothing(FrmSetupUI) Then
|
||||
FrmSetupUI.CheckLogoLeft.Visibility = Visibility.Collapsed
|
||||
@@ -788,7 +788,8 @@ Public Class FormMain
|
||||
End Select
|
||||
FrmSetupUI?.CardLogo.TriggerForceResize()
|
||||
'标题栏文本
|
||||
LabTitleLogo.Text = Settings.Get(Of String)("UiLogoText")
|
||||
Dim LogoText As String = Settings.Get(Of String)("UiLogoText")
|
||||
LabTitleLogo.Text = If(LogoText = "", ProductShortName, LogoText)
|
||||
'标题栏文本是否居左
|
||||
PanTitleMain.ColumnDefinitions(0).Width = New GridLength(If(Settings.Get(Of Boolean)("UiLogoLeft") AndAlso Settings.Get(Of Integer)("UiLogoType") = 0, 0, 1), GridUnitType.Star)
|
||||
End Sub
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Imports System.Runtime.CompilerServices
|
||||
Imports System.Runtime.CompilerServices
|
||||
Imports System.Xaml
|
||||
|
||||
Public Module ModBase
|
||||
@@ -8,7 +8,7 @@ Public Module ModBase
|
||||
'PCL-ISE 版本规则:主版本.次版本.修订版本;内部 VersionCode 继续用于更新兼容判断。
|
||||
Public Const ProductName As String = "Plain Craft Launcher (PCL) InfstarMC Edition"
|
||||
Public Const ProductShortName As String = "PCL-ISE"
|
||||
Public Const VersionBaseName As String = "0.1.0" '显示用版本名
|
||||
Public Const VersionBaseName As String = "0.1.1" '显示用版本名
|
||||
Public Const CommitHash As String = "" 'Commit Hash,由 GitHub Workflow 自动替换
|
||||
#If RELEASE Then
|
||||
Public Const VersionCode As Integer = 413 '正式版
|
||||
@@ -25,11 +25,12 @@ Public Module ModBase
|
||||
Public Const BuildTypeDisplay As String = "正式版"
|
||||
Public Const BuildType As BuildTypes = BuildTypes.Release
|
||||
#Else
|
||||
Public Const BuildTypeDisplay As String = "快照版"
|
||||
Public Const BuildType As BuildTypes = BuildTypes.Snapshot
|
||||
Public Const BuildTypeDisplay As String = "开发版"
|
||||
Public Const BuildType As BuildTypes = BuildTypes.Development
|
||||
#End If
|
||||
Public Enum BuildTypes
|
||||
Debug = 100
|
||||
Development = 75
|
||||
Release = 50
|
||||
Snapshot = 0
|
||||
End Enum
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
Imports System
|
||||
Imports System.Diagnostics
|
||||
Imports System.IO
|
||||
|
||||
'只依赖 .NET,供启动器与独立的更新功能测试共同使用。
|
||||
Public Module ModLauncherUpdate
|
||||
Public Function ParseLauncherVersion(Value As String) As Version
|
||||
If String.IsNullOrWhiteSpace(Value) Then Return Nothing
|
||||
Dim Clean = Value.Trim().TrimStart("v"c, "V"c)
|
||||
Dim Separator = Clean.IndexOfAny(New Char() {"-"c, "+"c})
|
||||
If Separator >= 0 Then Clean = Clean.Substring(0, Separator)
|
||||
Dim Parts = Clean.Split("."c)
|
||||
If Parts.Length <> 3 Then Return Nothing
|
||||
Dim Numbers(2) As Integer
|
||||
For Index = 0 To 2
|
||||
If Not Integer.TryParse(Parts(Index), Globalization.NumberStyles.None, Globalization.CultureInfo.InvariantCulture, Numbers(Index)) Then Return Nothing
|
||||
Next
|
||||
Return New Version(Numbers(0), Numbers(1), Numbers(2), 0)
|
||||
End Function
|
||||
|
||||
Public Sub ReplaceLauncherFile(ProcessId As Integer, OldFileName As String, NewFileName As String, Optional WaitTimeout As Integer = 30000)
|
||||
Dim Target = Path.GetFullPath(OldFileName)
|
||||
Dim Source = Path.GetFullPath(NewFileName)
|
||||
If String.Equals(Target, Source, StringComparison.OrdinalIgnoreCase) Then Throw New IOException("更新文件与目标文件不能相同")
|
||||
If Not File.Exists(Source) Then Throw New FileNotFoundException("找不到已下载的更新文件", Source)
|
||||
If ProcessId > 0 Then
|
||||
If ProcessId = Process.GetCurrentProcess().Id Then Throw New InvalidOperationException("更新进程不能替换自身")
|
||||
Dim Previous As Process = Nothing
|
||||
Try
|
||||
Previous = Process.GetProcessById(ProcessId)
|
||||
Catch ex As ArgumentException
|
||||
'旧进程已经退出。
|
||||
End Try
|
||||
If Previous IsNot Nothing Then
|
||||
Using Previous
|
||||
If Not Previous.WaitForExit(WaitTimeout) Then Throw New TimeoutException("启动器尚未退出,请关闭后重试更新")
|
||||
End Using
|
||||
End If
|
||||
End If
|
||||
'在目标目录暂存副本,再进行原子替换;失败时保留旧程序和下载文件。
|
||||
Dim Staged = Target & "." & Guid.NewGuid().ToString("N") & ".new"
|
||||
Try
|
||||
File.Copy(Source, Staged)
|
||||
If File.Exists(Target) Then
|
||||
File.Replace(Staged, Target, Target & ".bak", True)
|
||||
Else
|
||||
File.Move(Staged, Target)
|
||||
End If
|
||||
Finally
|
||||
If File.Exists(Staged) Then File.Delete(Staged)
|
||||
End Try
|
||||
End Sub
|
||||
End Module
|
||||
@@ -967,7 +967,7 @@ NextFile:
|
||||
If ForceOpenLog OrElse (ShowMsgbox AndAlso MyMsgBox("若你在汇报一个 Bug,请点击 打开文件夹 按钮,并上传 Log(1~5).txt 中包含错误信息的文件。" & vbCrLf & "游戏崩溃一般与启动器无关,请不要因为游戏崩溃而提交反馈。", "反馈提交提醒", "打开文件夹", "不需要") = 1) Then
|
||||
OpenExplorer(Paths.Base & "PCL\Log1.txt")
|
||||
End If
|
||||
OpenWebsite("https://github.com/Meloong-Git/PCL/issues/")
|
||||
OpenWebsite("https://git.infstar.cn/InfStarMC/PCL-ISE/issues/")
|
||||
End Sub
|
||||
''' <summary>
|
||||
''' 在日志中输出系统诊断信息。
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
'由于包含加解密等安全信息,本文件中的部分代码已被删除
|
||||
|
||||
Imports System.Diagnostics
|
||||
Imports System.IO
|
||||
|
||||
Friend Module ModSecret
|
||||
|
||||
'标注 PCL 的不同分支,仅用于替换标记
|
||||
@@ -15,7 +18,8 @@ Friend Module ModSecret
|
||||
|
||||
#Region "网络鉴权"
|
||||
|
||||
Public Const RestrictMcDownload As Boolean = True
|
||||
'PCL-ISE 提供 Mojang 官方版本清单以及现有的 Minecraft 下载链路。
|
||||
Public Const RestrictMcDownload As Boolean = False
|
||||
Friend Function SecretCdnSign(UrlWithMark As String) As String
|
||||
If Not UrlWithMark.EndsWithF("{CDN}") Then Return UrlWithMark
|
||||
Return UrlWithMark.Replace("{CDN}", "").Replace(" ", "%20")
|
||||
@@ -145,22 +149,179 @@ Friend Module ModSecret
|
||||
|
||||
#Region "更新"
|
||||
|
||||
'更新源使用 InfstarMC 自己的 Gitea Release API,不会从上游 PCL 下载启动器。
|
||||
Public Const UpdateApiUrl As String = "https://git.infstar.cn/api/v1/repos/InfStarMC/PCL-ISE/releases/latest"
|
||||
Public Const UpdateRepositoryUrl As String = "https://git.infstar.cn/InfStarMC/PCL-ISE/releases"
|
||||
Private Const UpdateCacheFile As String = "Cache\PclIseUpdate.json"
|
||||
Private Const UpdateAssetFileName As String = "PCL-ISE.exe"
|
||||
Private Const UpdateAssetMinSize As Long = 64 * 1024
|
||||
|
||||
Private Class LauncherUpdateInfo
|
||||
Public TagName As String
|
||||
Public ReleaseName As String
|
||||
Public ReleaseBody As String
|
||||
Public DownloadUrl As String
|
||||
Public AssetName As String
|
||||
Public AssetSize As Long
|
||||
Public AssetHash As String
|
||||
Public VersionNumber As Version
|
||||
End Class
|
||||
|
||||
Private UpdateFilePath As String = Nothing
|
||||
Private UpdateCheckRunning As Integer = 0
|
||||
Friend IsUpdateWaitingRestart As Boolean = False
|
||||
|
||||
Private Function GetLatestLauncherUpdate() As LauncherUpdateInfo
|
||||
Dim Json As JObject = NetRequestByClientRetry(UpdateApiUrl, RequireJson:=True).DeserializeJson()
|
||||
Dim TagName = If(Json("tag_name"), "").ToString
|
||||
Dim VersionNumber = ParseLauncherVersion(TagName)
|
||||
If VersionNumber Is Nothing Then Throw New FormatException("PCL-ISE 发布信息中的版本号无效")
|
||||
|
||||
Dim SelectedAsset As JObject = Nothing
|
||||
For Each Candidate As JObject In If(Json("assets"), New JArray)
|
||||
Dim CandidateName = If(Candidate("name"), "").ToString
|
||||
If CandidateName.Equals(UpdateAssetFileName, StringComparison.OrdinalIgnoreCase) Then
|
||||
SelectedAsset = Candidate
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
If SelectedAsset Is Nothing Then Throw New FileNotFoundException("发布中没有找到 PCL-ISE 的 exe 更新文件")
|
||||
|
||||
Dim DownloadUrl = If(SelectedAsset("browser_download_url"), If(SelectedAsset("download_url"), "")).ToString
|
||||
If String.IsNullOrWhiteSpace(DownloadUrl) Then Throw New FormatException("PCL-ISE 发布文件缺少下载地址")
|
||||
Dim AssetSize As Long = -1
|
||||
If SelectedAsset("size") IsNot Nothing Then AssetSize = SelectedAsset("size").ToObject(Of Long)()
|
||||
Dim AssetHash = If(SelectedAsset("digest"), If(SelectedAsset("sha256"), If(SelectedAsset("checksum"), ""))).ToString
|
||||
If AssetHash.StartsWith("sha256:", StringComparison.OrdinalIgnoreCase) Then AssetHash = AssetHash.Substring(7)
|
||||
If Not System.Text.RegularExpressions.Regex.IsMatch(AssetHash, "\A[0-9a-fA-F]{64}\z") Then
|
||||
Dim ChecksumAsset = DirectCast(Json("assets"), JArray).OfType(Of JObject)().FirstOrDefault(
|
||||
Function(a) String.Equals(If(a("name"), "").ToString, UpdateAssetFileName & ".sha256", StringComparison.OrdinalIgnoreCase))
|
||||
If ChecksumAsset Is Nothing Then Throw New FormatException("发布文件缺少 SHA256 校验信息")
|
||||
Dim ChecksumUrl = If(ChecksumAsset("browser_download_url"), If(ChecksumAsset("download_url"), "")).ToString
|
||||
Dim ChecksumText = NetRequestByClientRetry(ChecksumUrl).ToString.Trim()
|
||||
Dim Match = System.Text.RegularExpressions.Regex.Match(ChecksumText, "\A([0-9a-fA-F]{64})(?:\s+\*?PCL-ISE\.exe)?\s*\z")
|
||||
If Not Match.Success Then Throw New FormatException("发布文件的 SHA256 校验信息无效")
|
||||
AssetHash = Match.Groups(1).Value
|
||||
End If
|
||||
|
||||
Dim Info As New LauncherUpdateInfo With {
|
||||
.TagName = TagName,
|
||||
.ReleaseName = If(Json("name"), TagName).ToString,
|
||||
.ReleaseBody = If(Json("body"), "").ToString,
|
||||
.DownloadUrl = DownloadUrl,
|
||||
.AssetName = If(SelectedAsset("name"), UpdateAssetFileName).ToString,
|
||||
.AssetSize = AssetSize,
|
||||
.AssetHash = AssetHash,
|
||||
.VersionNumber = VersionNumber
|
||||
}
|
||||
DirectoryUtils.Create(PathTemp & "Cache\")
|
||||
FileUtils.Write(PathTemp & UpdateCacheFile, Json.ToString)
|
||||
Return Info
|
||||
End Function
|
||||
|
||||
Private Function IsUpdateNewer(Info As LauncherUpdateInfo) As Boolean
|
||||
Return Info IsNot Nothing AndAlso Info.VersionNumber IsNot Nothing AndAlso Info.VersionNumber > ParseLauncherVersion(VersionBaseName)
|
||||
End Function
|
||||
|
||||
Friend Function IsCachedLauncherNewest() As Boolean?
|
||||
Try
|
||||
Dim CacheContent = FileUtils.TryReadAsString(PathTemp & UpdateCacheFile)
|
||||
If String.IsNullOrWhiteSpace(CacheContent) Then Return Nothing
|
||||
Dim Json As JObject = CacheContent.DeserializeJson()
|
||||
Dim CachedVersion = ParseLauncherVersion(If(Json("tag_name"), "").ToString)
|
||||
If CachedVersion Is Nothing Then Return Nothing
|
||||
Return CachedVersion <= ParseLauncherVersion(VersionBaseName)
|
||||
Catch ex As Exception
|
||||
Logger.Warn(ex, "读取 PCL-ISE 更新缓存失败")
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Friend Sub UpdateCheckByButton()
|
||||
Hint("该版本中不包含更新功能……")
|
||||
If Interlocked.Exchange(UpdateCheckRunning, 1) <> 0 Then
|
||||
Hint("正在检查更新,请稍候……")
|
||||
Return
|
||||
End If
|
||||
RunInNewThread(
|
||||
Sub()
|
||||
Try
|
||||
RunInUi(Sub() Hint("正在检查 PCL-ISE 更新……", Log:=False))
|
||||
Dim Info = GetLatestLauncherUpdate()
|
||||
If Not IsUpdateNewer(Info) Then
|
||||
RunInUi(Sub() Hint("当前已经是最新版本!", HintType.Green))
|
||||
Return
|
||||
End If
|
||||
|
||||
Dim Summary = If(String.IsNullOrWhiteSpace(Info.ReleaseBody), "该版本没有提供更新说明。", Info.ReleaseBody)
|
||||
If Summary.Length > 1200 Then Summary = Summary.Substring(0, 1200) & "……"
|
||||
Dim Confirm = RunInUiWait(Function() MyMsgBox($"发现 PCL-ISE {Info.TagName}。" & vbCrLf & vbCrLf & Summary,
|
||||
"发现新版本", "下载并更新", "查看发布页", "取消",
|
||||
Button2Action:=Sub() OpenWebsite(UpdateRepositoryUrl)))
|
||||
If Confirm = 2 Then Return
|
||||
If Confirm <> 1 Then Return
|
||||
|
||||
Dim SafeVersion = Info.VersionNumber.ToString(3)
|
||||
UpdateFilePath = PathTemp & "Update\PCL-ISE-" & SafeVersion & ".exe"
|
||||
Dim Checker As New FileChecker With {.MinSize = UpdateAssetMinSize, .ActualSize = Info.AssetSize, .Hash = If(String.IsNullOrWhiteSpace(Info.AssetHash), Nothing, Info.AssetHash)}
|
||||
RunInUi(Sub() Hint("正在下载更新……", Log:=False))
|
||||
NetDownloadByLoader(Info.DownloadUrl, UpdateFilePath, Check:=Checker)
|
||||
Dim DownloadedAssembly = Reflection.AssemblyName.GetAssemblyName(UpdateFilePath)
|
||||
If DownloadedAssembly.Name <> "Plain Craft Launcher 2" OrElse DownloadedAssembly.Version <> Info.VersionNumber Then Throw New FormatException("更新文件的程序集版本与发布版本不符")
|
||||
IsUpdateWaitingRestart = True
|
||||
RunInUi(
|
||||
Sub()
|
||||
MyMsgBox("更新文件已下载并通过完整性校验。点击立即重启完成更新。", "准备更新", "立即重启", "稍后再说",
|
||||
Button1Action:=Sub()
|
||||
UpdateRestart(True)
|
||||
End Sub)
|
||||
End Sub)
|
||||
Catch ex As Exception
|
||||
Logger.Warn(ex, "检查 PCL-ISE 更新失败")
|
||||
RunInUi(Sub() Hint("检查更新失败:" & ex.GetDisplay(False), HintType.Red))
|
||||
Finally
|
||||
Interlocked.Exchange(UpdateCheckRunning, 0)
|
||||
End Try
|
||||
End Sub, "PCL-ISE Update Check", ThreadPriority.BelowNormal)
|
||||
End Sub
|
||||
|
||||
Friend IsUpdateWaitingRestart As Boolean = False
|
||||
Public Sub UpdateRestart(TriggerRestartAndByEnd As Boolean)
|
||||
Dim NewFile = UpdateFilePath
|
||||
If String.IsNullOrWhiteSpace(NewFile) OrElse Not FileUtils.Exists(NewFile) Then
|
||||
IsUpdateWaitingRestart = False
|
||||
Return
|
||||
End If
|
||||
Try
|
||||
Dim Arguments = $"--update {Process.GetCurrentProcess.Id} ""{PathExe}"" ""{NewFile}"" {TriggerRestartAndByEnd.ToString.ToLowerInvariant()}"
|
||||
StartProcess(New ProcessStartInfo With {.FileName = NewFile, .Arguments = Arguments, .WorkingDirectory = Paths.Base, .UseShellExecute = True})
|
||||
IsUpdateWaitingRestart = False
|
||||
If TriggerRestartAndByEnd Then FormMain.EndProgramForce()
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex, "启动更新替换进程失败", LogBehavior.Toast)
|
||||
End Try
|
||||
End Sub
|
||||
Public Sub UpdateReplace(ProcessId As Integer, OldFileName As String, NewFileName As String, TriggerRestart As Boolean)
|
||||
End Sub
|
||||
|
||||
Public Function UpdateReplace(ProcessId As Integer, OldFileName As String, NewFileName As String, TriggerRestart As Boolean) As Boolean
|
||||
Try
|
||||
ReplaceLauncherFile(ProcessId, OldFileName, NewFileName)
|
||||
Logger.Info("PCL-ISE 更新文件替换完成")
|
||||
If TriggerRestart Then StartProcess(OldFileName)
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex, "替换 PCL-ISE 更新文件失败")
|
||||
MsgBox("PCL-ISE 更新失败:" & ex.GetDisplay(False), MsgBoxStyle.Critical, "更新失败")
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 确保 PathTemp/Latest.exe 是最新正式版的 PCL,它会被用于整合包打包。
|
||||
''' 下载 InfstarMC 发布的启动器,用于整合包打包。
|
||||
''' 如果不是,则下载一个。
|
||||
''' </summary>
|
||||
Friend Sub DownloadLatestPCL(Optional LoaderToSyncProgress As LoaderBase = Nothing)
|
||||
'注意:如果要自行实现这个功能,请换用另一个文件路径,以免与官方版本冲突
|
||||
Dim Target = PathTemp & "PCL-ISE-Latest.exe"
|
||||
Dim Info = GetLatestLauncherUpdate()
|
||||
Dim Checker As New FileChecker With {.MinSize = UpdateAssetMinSize, .ActualSize = Info.AssetSize, .Hash = Info.AssetHash}
|
||||
NetDownloadByLoader(Info.DownloadUrl, Target, LoaderToSyncProgress, Checker)
|
||||
End Sub
|
||||
|
||||
#End Region
|
||||
@@ -173,7 +334,8 @@ Friend Module ModSecret
|
||||
''' </summary>
|
||||
Public ServerConfig As JObject
|
||||
|
||||
Public ServerLoader As New LoaderTask(Of Integer, Integer)("PCL 配置更新", Sub() Logger.Info("该版本中不包含更新通知功能……"), Priority:=ThreadPriority.BelowNormal) With
|
||||
'联机模块仍使用原有配置接口;启动器更新通过“检查更新”按钮单独请求 Release API。
|
||||
Public ServerLoader As New LoaderTask(Of Integer, Integer)("PCL 配置更新", Sub() Logger.Info("PCL-ISE 未启用远程联机配置"), Priority:=ThreadPriority.BelowNormal) With
|
||||
{.ReloadTimeout = 1000 * 60 * 60} '超时 1 小时
|
||||
|
||||
#End Region
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Imports System.Reflection
|
||||
Imports System.Reflection
|
||||
Imports System.Resources
|
||||
Imports System.Runtime.InteropServices
|
||||
|
||||
@@ -51,6 +51,6 @@ Imports System.Runtime.InteropServices
|
||||
' 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
|
||||
' 方法是按如下所示使用“*”
|
||||
|
||||
<Assembly: AssemblyVersion("0.1.0")>
|
||||
<Assembly: AssemblyFileVersion("0.1.0")>
|
||||
<Assembly: AssemblyVersion("0.1.1")>
|
||||
<Assembly: AssemblyFileVersion("0.1.1")>
|
||||
<Assembly: NeutralResourcesLanguage("")>
|
||||
@@ -476,10 +476,10 @@ Public Class PageInstanceExport
|
||||
#Region "准备 PCL 文件"
|
||||
|
||||
If BuildType <> BuildTypes.Release AndAlso IncludePCL Then
|
||||
Loaders.Add(New LoaderTask(Of Integer, Integer)("下载 PCL 正式版",
|
||||
Loaders.Add(New LoaderTask(Of Integer, Integer)("下载 PCL-ISE 发布版",
|
||||
Sub(Loader As LoaderTask(Of Integer, Integer))
|
||||
DownloadLatestPCL(Loader)
|
||||
FileUtils.Copy(PathTemp & "Latest.exe", CacheFolder & "Plain Craft Launcher.exe")
|
||||
FileUtils.Copy(PathTemp & "PCL-ISE-Latest.exe", CacheFolder & "PCL-ISE.exe")
|
||||
End Sub) With {.ProgressWeight = 0.5, .Block = False})
|
||||
End If
|
||||
|
||||
@@ -566,7 +566,7 @@ Public Class PageInstanceExport
|
||||
If DirectoryUtils.Exists(TargetInstance.PathVersion & "PCL\") Then DirectoryUtils.Copy(TargetInstance.PathVersion & "PCL\", OverridesFolder & "PCL\")
|
||||
WriteIni(OverridesFolder & "PCL\Setup.ini", "IsStar", False)
|
||||
'复制 PCL 本体(正式版)
|
||||
If BuildType = BuildTypes.Release AndAlso IncludePCL Then FileUtils.Copy(PathExe, CacheFolder & "Plain Craft Launcher.exe")
|
||||
If BuildType = BuildTypes.Release AndAlso IncludePCL Then FileUtils.Copy(PathExe, CacheFolder & "PCL-ISE.exe")
|
||||
'复制 PCL 个性化内容
|
||||
If IncludePCLCustom Then
|
||||
If DirectoryUtils.Exists(Paths.Base & "PCL\Pictures\") Then DirectoryUtils.Copy(Paths.Base & "PCL\Pictures\", CacheFolder & "PCL\Pictures\")
|
||||
|
||||
@@ -7,7 +7,7 @@ Public Class PageOtherLeft
|
||||
Dim IsHiddenPage As Boolean = False
|
||||
If ItemHelp.Checked AndAlso Settings.Get(Of Boolean)("UiHiddenOtherHelp") Then IsHiddenPage = True
|
||||
If ItemAbout.Checked AndAlso Settings.Get(Of Boolean)("UiHiddenOtherAbout") Then IsHiddenPage = True
|
||||
If ItemTest.Checked AndAlso Settings.Get(Of Boolean)("UiHiddenOtherTest") Then IsHiddenPage = True
|
||||
If ItemTest.Checked Then IsHiddenPage = True
|
||||
If PageSetupUI.HiddenForceShow Then IsHiddenPage = False
|
||||
'若页面错误,或尚未加载,则继续
|
||||
If IsLoad AndAlso Not IsHiddenPage Then Return
|
||||
@@ -21,7 +21,7 @@ Public Class PageOtherLeft
|
||||
ElseIf Not Settings.Get(Of Boolean)("UiHiddenOtherAbout") Then
|
||||
ItemAbout.SetChecked(True, False, False)
|
||||
Else
|
||||
ItemTest.SetChecked(True, False, False)
|
||||
ItemAbout.SetChecked(True, False, False)
|
||||
End If
|
||||
End Sub
|
||||
Private Sub PageOtherLeft_Unloaded(sender As Object, e As RoutedEventArgs) Handles Me.Unloaded
|
||||
@@ -42,7 +42,7 @@ Public Class PageOtherLeft
|
||||
ElseIf Not Settings.Get(Of Boolean)("UiHiddenOtherAbout") Then
|
||||
PageID = FormMain.PageSubType.OtherAbout
|
||||
Else
|
||||
PageID = FormMain.PageSubType.OtherTest
|
||||
PageID = FormMain.PageSubType.OtherAbout
|
||||
End If
|
||||
End Sub
|
||||
|
||||
@@ -142,7 +142,7 @@ Public Class PageOtherLeft
|
||||
Case 1
|
||||
Feedback(True, False)
|
||||
Case 2
|
||||
OpenWebsite("https://github.com/Meloong-Git/PCL/issues/")
|
||||
OpenWebsite("https://git.infstar.cn/InfStarMC/PCL-ISE/issues/")
|
||||
End Select
|
||||
End Sub
|
||||
Private Sub TryVote(sender As Object, e As RouteEventArgs) Handles ItemVote.Changed
|
||||
|
||||
@@ -108,11 +108,7 @@ Public Class PageSetupSystem
|
||||
''' </summary>
|
||||
Public Shared Function IsLauncherNewest() As Boolean?
|
||||
Try
|
||||
'确认服务器公告是否正常
|
||||
Dim ServerContent As String = If(FileUtils.TryReadAsString(PathTemp & "Cache\Notice.cfg"), "")
|
||||
If ServerContent.Split("|").Count < 3 Then Return Nothing
|
||||
'确认是否为最新
|
||||
Return ServerContent.Split("|")(If(BuildType = BuildTypes.Release, 2, 1)) <= VersionCode
|
||||
Return IsCachedLauncherNewest()
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex, "确认启动器更新失败")
|
||||
Return Nothing
|
||||
|
||||
@@ -329,9 +329,9 @@
|
||||
<TextBlock Grid.Row="3" VerticalAlignment="Center" HorizontalAlignment="Left" Text="更多 子页面" />
|
||||
<local:MyCheckBox Height="22" VerticalAlignment="Center" Grid.Row="3" Grid.Column="2" Text="帮助" x:Name="CheckHiddenOtherHelp" local:SettingService.Key="UiHiddenOtherHelp" />
|
||||
<local:MyCheckBox Height="22" VerticalAlignment="Center" Grid.Row="3" Grid.Column="3" Text="关于与鸣谢" x:Name="CheckHiddenOtherAbout" local:SettingService.Key="UiHiddenOtherAbout" />
|
||||
<local:MyCheckBox Height="22" VerticalAlignment="Center" Grid.Row="3" Grid.Column="4" Text="百宝箱" x:Name="CheckHiddenOtherTest" local:SettingService.Key="UiHiddenOtherTest" />
|
||||
<local:MyCheckBox Height="22" VerticalAlignment="Center" Grid.Row="3" Grid.Column="4" Text="百宝箱" x:Name="CheckHiddenOtherTest" local:SettingService.Key="UiHiddenOtherTest" Visibility="Collapsed" />
|
||||
<local:MyCheckBox Height="22" VerticalAlignment="Center" Grid.Row="3" Grid.Column="5" Text="反馈" x:Name="CheckHiddenOtherFeedback" local:SettingService.Key="UiHiddenOtherFeedback" />
|
||||
<local:MyCheckBox Height="22" VerticalAlignment="Center" Grid.Row="3" Grid.Column="6" Text="新功能投票" x:Name="CheckHiddenOtherVote" local:SettingService.Key="UiHiddenOtherVote" />
|
||||
<local:MyCheckBox Height="22" VerticalAlignment="Center" Grid.Row="3" Grid.Column="6" Text="新功能投票" x:Name="CheckHiddenOtherVote" local:SettingService.Key="UiHiddenOtherVote" Visibility="Collapsed" />
|
||||
<TextBlock Grid.Row="4" VerticalAlignment="Center" HorizontalAlignment="Left" Text="特定功能" />
|
||||
<local:MyCheckBox Height="22" VerticalAlignment="Center" Grid.Row="4" Grid.Column="2" Text="邮箱隐藏" x:Name="CheckLauncherEmail" local:SettingService.Key="UiLauncherEmail" ToolTip="隐藏第三方登录的账号邮箱显示,以避免隐私泄露。
此选项的更改将在重启启动器后生效。" />
|
||||
<local:MyCheckBox Height="22" VerticalAlignment="Center" Grid.Row="4" Grid.Column="3" Text="版本管理" x:Name="CheckHiddenFunctionSelect" local:SettingService.Key="UiHiddenFunctionSelect" ToolTip="隐藏启动按钮下方的版本选择与版本设置入口。" />
|
||||
|
||||
@@ -475,15 +475,13 @@ Refresh:
|
||||
Dim OtherAvaliableCount As Integer = 0
|
||||
If Not Settings.Get(Of Boolean)("UiHiddenOtherHelp") Then OtherAvaliableCount += 1
|
||||
If Not Settings.Get(Of Boolean)("UiHiddenOtherAbout") Then OtherAvaliableCount += 1
|
||||
If Not Settings.Get(Of Boolean)("UiHiddenOtherTest") Then OtherAvaliableCount += 1
|
||||
If Not Settings.Get(Of Boolean)("UiHiddenOtherFeedback") Then OtherAvaliableCount += 1
|
||||
If Not Settings.Get(Of Boolean)("UiHiddenOtherVote") Then OtherAvaliableCount += 1
|
||||
If FrmOtherLeft IsNot Nothing Then
|
||||
FrmOtherLeft.ItemHelp.Visibility = If(Not HiddenForceShow AndAlso Settings.Get(Of Boolean)("UiHiddenOtherHelp"), Visibility.Collapsed, Visibility.Visible)
|
||||
FrmOtherLeft.ItemFeedback.Visibility = If(Not HiddenForceShow AndAlso Settings.Get(Of Boolean)("UiHiddenOtherFeedback"), Visibility.Collapsed, Visibility.Visible)
|
||||
FrmOtherLeft.ItemVote.Visibility = If(Not HiddenForceShow AndAlso Settings.Get(Of Boolean)("UiHiddenOtherVote"), Visibility.Collapsed, Visibility.Visible)
|
||||
FrmOtherLeft.ItemVote.Visibility = Visibility.Collapsed
|
||||
FrmOtherLeft.ItemAbout.Visibility = If(Not HiddenForceShow AndAlso Settings.Get(Of Boolean)("UiHiddenOtherAbout"), Visibility.Collapsed, Visibility.Visible)
|
||||
FrmOtherLeft.ItemTest.Visibility = If(Not HiddenForceShow AndAlso Settings.Get(Of Boolean)("UiHiddenOtherTest"), Visibility.Collapsed, Visibility.Visible)
|
||||
FrmOtherLeft.ItemTest.Visibility = Visibility.Collapsed
|
||||
'隐藏左边选择卡
|
||||
FrmOtherLeft.PanItem.Visibility = If(OtherAvaliableCount < 2 AndAlso Not HiddenForceShow, Visibility.Collapsed, Visibility.Visible)
|
||||
End If
|
||||
@@ -493,7 +491,7 @@ Refresh:
|
||||
ElseIf Not Settings.Get(Of Boolean)("UiHiddenOtherAbout") Then
|
||||
FrmMain.BtnTitleSelect4.Text = "关于"
|
||||
Else
|
||||
FrmMain.BtnTitleSelect4.Text = "百宝箱"
|
||||
FrmMain.BtnTitleSelect4.Text = "反馈"
|
||||
End If
|
||||
Else
|
||||
FrmMain.BtnTitleSelect4.Text = "更多"
|
||||
|
||||
@@ -144,8 +144,8 @@ Public Class Settings
|
||||
New Setting("UiCustomType", 0, OnChanged:=AddressOf PageSetupUI.OnMainPageTypeChanged),
|
||||
New Setting("UiCustomPreset", 0),
|
||||
New Setting("UiCustomNet", ""),
|
||||
New Setting("UiLogoType", 1, OnChanged:=AddressOf FormMain.UpdateBackgroundAndTitleBar),
|
||||
New Setting("UiLogoText", "", OnChanged:=AddressOf FormMain.UpdateBackgroundAndTitleBar),
|
||||
New Setting("UiLogoType", 2, OnChanged:=AddressOf FormMain.UpdateBackgroundAndTitleBar),
|
||||
New Setting("UiLogoText", "PCL-ISE", OnChanged:=AddressOf FormMain.UpdateBackgroundAndTitleBar),
|
||||
New Setting("UiLogoLeft", False, OnChanged:=AddressOf FormMain.UpdateBackgroundAndTitleBar),
|
||||
New Setting("UiMusicVolume", 500),
|
||||
New Setting("UiMusicStop", False),
|
||||
@@ -166,9 +166,9 @@ Public Class Settings
|
||||
New Setting("UiHiddenSetupSystem", False, OnChanged:=AddressOf PageSetupUI.HiddenRefresh),
|
||||
New Setting("UiHiddenOtherHelp", False, OnChanged:=AddressOf PageSetupUI.HiddenRefresh),
|
||||
New Setting("UiHiddenOtherFeedback", False, OnChanged:=AddressOf PageSetupUI.HiddenRefresh),
|
||||
New Setting("UiHiddenOtherVote", False, OnChanged:=AddressOf PageSetupUI.HiddenRefresh),
|
||||
New Setting("UiHiddenOtherVote", True, OnChanged:=AddressOf PageSetupUI.HiddenRefresh),
|
||||
New Setting("UiHiddenOtherAbout", False, OnChanged:=AddressOf PageSetupUI.HiddenRefresh),
|
||||
New Setting("UiHiddenOtherTest", False, OnChanged:=AddressOf PageSetupUI.HiddenRefresh),
|
||||
New Setting("UiHiddenOtherTest", True, OnChanged:=AddressOf PageSetupUI.HiddenRefresh),
|
||||
New Setting("VersionAdvanceJvm", "", Source:=Sources.Instance),
|
||||
New Setting("VersionAdvanceGame", "", Source:=Sources.Instance),
|
||||
New Setting("VersionAdvanceAssets", 0, Source:=Sources.Instance),
|
||||
|
||||
@@ -330,6 +330,7 @@
|
||||
</Compile>
|
||||
<Compile Include="Controls\MyDropShadow.vb" />
|
||||
<Compile Include="Modules\Base\ModLoader.vb" />
|
||||
<Compile Include="Modules\Base\ModLauncherUpdate.vb" />
|
||||
<Compile Include="Modules\Base\ModNet.vb" />
|
||||
<Compile Include="Modules\Base\ModValidate.vb" />
|
||||
<Compile Include="Modules\Minecraft\ModDownload.vb" />
|
||||
@@ -951,4 +952,4 @@
|
||||
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -0,0 +1,32 @@
|
||||
# PCL-ISE 0.1.1 开发测试版
|
||||
|
||||
Plain Craft Launcher (PCL) InfstarMC Edition 是 InfstarMC 基于 PCL 独立修改的第三方版本。本次发布用于测试启动器更新,尚不建议用于生产环境。
|
||||
|
||||
## 本次变化
|
||||
|
||||
- 从 InfstarMC 仓库的 Release API 检查、下载启动器更新,按三位版本号比较版本。
|
||||
- 校验更新包大小、SHA256 和程序集版本;更新时等待旧进程退出,保留旧程序为 `.bak`。
|
||||
- 开发构建显示为“开发版”,更新启动说明,移除上游公告缓存对版本判断的影响。
|
||||
- 开放现有 Minecraft 原版下载入口;整合包导出使用 PCL-ISE 发布的启动器。
|
||||
|
||||
## 下载与测试
|
||||
|
||||
- `PCL-ISE.exe`:0.1.1 开发测试版,可直接下载运行。
|
||||
- `PCL-ISE.exe.sha256`:0.1.1 可执行文件的 SHA256 校验值。
|
||||
- `PCL-ISE-0.1.0-update-test.zip`:包含修复了更新流程的 0.1.0 测试基线及说明。解压至独立目录,运行后进入“设置 → 其他 → 检查更新”,可测试从 0.1.0 下载、重启并升级至 0.1.1。
|
||||
|
||||
此前构建的旧 0.1.0 存在更新文件占用问题,需先换用上述测试基线,或手动下载 0.1.1。仅发布新版不会修复旧程序中的更新代码。
|
||||
|
||||
为使现有 `/releases/latest` 更新入口能获取本版本,此开发测试版使用普通 Release 发布;这不代表功能已经稳定。
|
||||
|
||||
## 已知限制
|
||||
|
||||
- 正版登录仍需自行申请并通过环境变量 `PCL_MS_CLIENT_ID` 配置微软 Client ID,设置后重启启动器。本版本尚未内置该配置。
|
||||
- CurseForge 仍需配置 `PCL_CURSEFORGE_API_KEY`。
|
||||
- 当前更新通过“检查更新”按钮触发,未实现后台自动检查。
|
||||
|
||||
## 源码与署名
|
||||
|
||||
源码及子模块配置见本版本的 `v0.1.1` 标签。克隆时请使用 `git clone --recurse-submodules https://git.infstar.cn/InfStarMC/PCL-ISE`。
|
||||
|
||||
上游项目:[Meloong-Git/PCL](https://github.com/Meloong-Git/PCL)。原作者:龙腾猫跃;[赞助原作者](https://meloong.com/afd/a/LTCat)。使用与分发请遵守仓库中的 `LICENCE`。
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
// Run under .NET Framework after compiling with the framework's csc.exe.
|
||||
// Uses the launcher's real release API parser without starting its main window.
|
||||
internal static class CheckLauncherRelease {
|
||||
[STAThread]
|
||||
private static int Main(string[] args) {
|
||||
try {
|
||||
Assembly launcher = Assembly.LoadFrom(Path.GetFullPath(args[0]));
|
||||
Activator.CreateInstance(launcher.GetType("PCL.Application", true), true);
|
||||
Assembly core = Assembly.Load("MeloongCore");
|
||||
core.GetType("MeloongCore.Main", true).GetMethod("Init").Invoke(null, new object[] { "PCL" });
|
||||
Type module = launcher.GetType("PCL.ModSecret", true);
|
||||
object info = module.GetMethod("GetLatestLauncherUpdate", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, null);
|
||||
Type infoType = info.GetType();
|
||||
string tag = (string)infoType.GetField("TagName").GetValue(info);
|
||||
string hash = (string)infoType.GetField("AssetHash").GetValue(info);
|
||||
string url = (string)infoType.GetField("DownloadUrl").GetValue(info);
|
||||
string version = infoType.GetField("VersionNumber").GetValue(info).ToString();
|
||||
Console.WriteLine("Release: " + tag + ", version: " + version);
|
||||
Console.WriteLine("Asset: " + url);
|
||||
Console.WriteLine("SHA256: " + hash);
|
||||
if (args.Length > 1) {
|
||||
using (SHA256 sha = SHA256.Create())
|
||||
using (Stream file = File.OpenRead(args[1])) {
|
||||
string expected = BitConverter.ToString(sha.ComputeHash(file)).Replace("-", "");
|
||||
if (!expected.Equals(hash, StringComparison.OrdinalIgnoreCase))
|
||||
throw new InvalidDataException("Release SHA256 does not match local build");
|
||||
}
|
||||
}
|
||||
if (tag != "v0.1.1" || version != "0.1.1.0") throw new InvalidDataException("Unexpected test release version");
|
||||
Console.WriteLine("PASS: launcher resolves published test release and checksum");
|
||||
return 0;
|
||||
} catch (Exception ex) {
|
||||
Console.Error.WriteLine(ex.ToString());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
[CmdletBinding()]
|
||||
param([string]$LauncherPath, [string]$RepositoryRoot)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$repoRoot = if ($RepositoryRoot) { $RepositoryRoot } else { Split-Path $PSScriptRoot -Parent }
|
||||
$sourcePath = Join-Path $repoRoot 'Plain Craft Launcher 2\Modules\Base\ModLauncherUpdate.vb'
|
||||
$testRoot = Join-Path $repoRoot ('artifacts\update-tests\' + [Guid]::NewGuid().ToString('N'))
|
||||
[IO.Directory]::CreateDirectory($testRoot) | Out-Null
|
||||
|
||||
$framework = Join-Path $env:WINDIR 'Microsoft.NET\Framework\v4.0.30319'
|
||||
$testLibrary = Join-Path $testRoot 'LauncherUpdateTests.dll'
|
||||
& (Join-Path $framework 'vbc.exe') /nologo /target:library "/out:$testLibrary" $sourcePath
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Update module compilation failed' }
|
||||
$updateType = [Reflection.Assembly]::LoadFile($testLibrary).GetType('ModLauncherUpdate')
|
||||
$parse = $updateType.GetMethod('ParseLauncherVersion')
|
||||
$replace = $updateType.GetMethod('ReplaceLauncherFile')
|
||||
$testState = @{ Passed = 0 }
|
||||
function Assert-True([bool]$Condition, [string]$Description) {
|
||||
if (-not $Condition) { throw "FAIL: $Description" }
|
||||
$testState.Passed++
|
||||
Write-Host "PASS: $Description"
|
||||
}
|
||||
function Replace-File([int]$PreviousId, [string]$Target, [string]$Source, [int]$Timeout = 30000) {
|
||||
$replace.Invoke($null, @($PreviousId, $Target, $Source, $Timeout))
|
||||
}
|
||||
|
||||
foreach ($inputVersion in @('0.1.1', 'v0.1.1', '0.1.1-dev', '0.1.1+build')) {
|
||||
Assert-True ($parse.Invoke($null, @($inputVersion)) -eq [Version]'0.1.1.0') "parse $inputVersion"
|
||||
}
|
||||
foreach ($inputVersion in @('', '1', '1.2', '1.2.3.4', '-1.2.3', '1.two.3', '2147483648.0.0')) {
|
||||
Assert-True ($null -eq $parse.Invoke($null, @($inputVersion))) "reject invalid version [$inputVersion]"
|
||||
}
|
||||
Assert-True ($parse.Invoke($null, @('0.1.1')) -gt $parse.Invoke($null, @('0.1.0'))) '0.1.1 updates 0.1.0'
|
||||
|
||||
$target = Join-Path $testRoot 'PCL-ISE.exe'
|
||||
$download = Join-Path $testRoot 'download.exe'
|
||||
[IO.File]::WriteAllText($target, 'old version')
|
||||
[IO.File]::WriteAllText($download, 'new version')
|
||||
Replace-File 0 $target $download
|
||||
Assert-True ([IO.File]::ReadAllText($target) -eq 'new version') 'replace target'
|
||||
Assert-True ([IO.File]::ReadAllText($target + '.bak') -eq 'old version') 'retain backup'
|
||||
Assert-True ([IO.File]::ReadAllText($download) -eq 'new version') 'retain helper/download'
|
||||
|
||||
$missingRejected = $false
|
||||
try { Replace-File 0 $target (Join-Path $testRoot 'missing.exe') } catch { $missingRejected = $true }
|
||||
Assert-True ($missingRejected -and [IO.File]::ReadAllText($target) -eq 'new version') 'missing download leaves target intact'
|
||||
|
||||
# An isolated test process holds the old executable open during a normal update.
|
||||
$oldProgram = Join-Path $testRoot 'OldLauncher.cs'
|
||||
[IO.File]::WriteAllText($oldProgram, 'using System.Threading; class OldLauncher { static void Main() { Thread.Sleep(1500); } }')
|
||||
$oldExe = Join-Path $testRoot 'OldLauncher.exe'
|
||||
$csc = Join-Path $framework 'csc.exe'
|
||||
& $csc /nologo /target:winexe "/out:$oldExe" $oldProgram
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Test launcher compilation failed' }
|
||||
$oldProcess = Start-Process -FilePath $oldExe -WindowStyle Hidden -PassThru
|
||||
$timeoutRejected = $false
|
||||
try { Replace-File $oldProcess.Id $target $download 20 } catch { $timeoutRejected = $_.Exception.InnerException -is [TimeoutException] }
|
||||
Assert-True ($timeoutRejected -and [IO.File]::ReadAllText($target) -eq 'new version') 'wait timeout leaves target intact'
|
||||
$oldProcess.WaitForExit()
|
||||
|
||||
$newTarget = Join-Path $testRoot 'new-target.exe'
|
||||
Replace-File 0 $newTarget $download
|
||||
Assert-True ([IO.File]::ReadAllText($newTarget) -eq 'new version') 'install into absent target'
|
||||
Assert-True (@(Get-ChildItem $testRoot -Filter '*.new').Count -eq 0) 'no staged files left behind'
|
||||
|
||||
if ($LauncherPath) {
|
||||
$LauncherPath = (Resolve-Path $LauncherPath).Path
|
||||
$liveTarget = Join-Path $testRoot 'RunningLauncher.exe'
|
||||
Copy-Item -LiteralPath $oldExe -Destination $liveTarget
|
||||
$previous = Start-Process -FilePath $liveTarget -WindowStyle Hidden -PassThru
|
||||
$arguments = '--update {0} "{1}" "{2}" false' -f $previous.Id, $liveTarget, $LauncherPath
|
||||
$helper = Start-Process -FilePath $LauncherPath -ArgumentList $arguments -WorkingDirectory $testRoot -WindowStyle Hidden -PassThru
|
||||
if (-not $helper.WaitForExit(20000)) { throw 'Update helper did not finish within 20 seconds' }
|
||||
$helper.Refresh()
|
||||
# The launcher uses ProcessReturnValues.TaskDone (5) for command-line tasks.
|
||||
Assert-True ($helper.ExitCode -eq 5) 'real launcher update helper exits successfully'
|
||||
Assert-True ((Get-FileHash $liveTarget).Hash -eq (Get-FileHash $LauncherPath).Hash) 'real helper replaces running old launcher after it exits'
|
||||
Assert-True ((Get-FileHash ($liveTarget + '.bak')).Hash -eq (Get-FileHash $oldExe).Hash) 'real helper preserves previous launcher'
|
||||
}
|
||||
|
||||
Write-Host "$($testState.Passed) checks passed. Artifacts: $testRoot"
|
||||
Reference in new issue
Block a user