mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2024-12-15 06:50:12 +08:00
Update java download window style
This commit is contained in:
parent
312152de78
commit
2136fddec5
@ -5,32 +5,30 @@
|
||||
$url = 'https://aka.ms/download-jdk/microsoft-jdk-17-windows-x64.zip'
|
||||
$chinese = (Get-WinSystemLocale).Name -eq 'zh-CN'
|
||||
|
||||
do {
|
||||
$tempFileName = "hmcl-java-$(Get-Random).zip"
|
||||
$script:tempFile = Join-Path ([System.IO.Path]::GetTempPath()) $tempFileName
|
||||
} while (Test-Path $script:tempFile)
|
||||
|
||||
echo $script:tempFile
|
||||
|
||||
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
|
||||
|
||||
$result = if ($chinese) {
|
||||
[System.Windows.Forms.MessageBox]::Show('HMCL 需要 Java 运行时环境才能正常运行,是否自动下载安装 Java?', '', [System.Windows.Forms.MessageBoxButtons]::YesNo)
|
||||
[System.Windows.Forms.MessageBox]::Show('HMCL 需要 Java 运行时环境才能正常运行,是否自动下载安装 Java?', 'HMCL', [System.Windows.Forms.MessageBoxButtons]::YesNo)
|
||||
} else {
|
||||
[System.Windows.Forms.MessageBox]::Show('Running HMCL requires a Java runtime environment. Do you want to download and install Java automatically?', '', [System.Windows.Forms.MessageBoxButtons]::YesNo)
|
||||
[System.Windows.Forms.MessageBox]::Show('Running HMCL requires a Java runtime environment. Do you want to download and install Java automatically?', 'HMCL', [System.Windows.Forms.MessageBoxButtons]::YesNo)
|
||||
}
|
||||
|
||||
if ($result -ne [System.Windows.Forms.DialogResult]::Yes) {
|
||||
exit 0
|
||||
}
|
||||
|
||||
do {
|
||||
$tempFileName = "hmcl-java-$(Get-Random).zip"
|
||||
$script:tempFile = Join-Path ([System.IO.Path]::GetTempPath()) $tempFileName
|
||||
} while (Test-Path $script:tempFile)
|
||||
|
||||
$form = New-Object System.Windows.Forms.Form
|
||||
$form.AutoSize = $true
|
||||
$form.AutoSizeMode = [System.Windows.Forms.AutoSizeMode]::GrowAndShrink
|
||||
if ($chinese) {
|
||||
$form.Text = '正在下载 Java'
|
||||
$form.Text = '正在下载 Java。这需要一段时间,请耐心等待。'
|
||||
} else {
|
||||
$form.Text = 'Downloading Java'
|
||||
$form.Text = 'Downloading Java. Please wait patiently for the download to complete.'
|
||||
}
|
||||
|
||||
$tip = New-Object System.Windows.Forms.Label
|
||||
@ -49,12 +47,12 @@ $progressBar = New-Object System.Windows.Forms.ProgressBar
|
||||
$progressBar.Maximum = 100
|
||||
|
||||
$label = New-Object System.Windows.Forms.Label
|
||||
$label.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom
|
||||
|
||||
$box = New-Object System.Windows.Forms.FlowLayoutPanel
|
||||
$box.AutoSize = $true
|
||||
$box.FlowDirection = [System.Windows.Forms.FlowDirection]::LeftToRight
|
||||
$box.AutoSizeMode = [System.Windows.Forms.AutoSizeMode]::GrowAndShrink
|
||||
$box.Anchor = [System.Windows.Forms.AnchorStyles]::Right
|
||||
$box.Controls.Add($progressBar)
|
||||
$box.Controls.Add($label)
|
||||
|
||||
@ -69,27 +67,26 @@ if ($chinese) {
|
||||
|
||||
$layout.Controls.Add($tip)
|
||||
$layout.Controls.Add($box)
|
||||
#$layout.Controls.Add($progressBar)
|
||||
$layout.Controls.Add($cancelButton)
|
||||
$box.Controls.Add($cancelButton)
|
||||
|
||||
$form.Controls.Add($layout)
|
||||
#$form.Controls.Add($progressBar)
|
||||
#$form.Controls.Add($cancelButton)
|
||||
|
||||
[System.Net.DownloadProgressChangedEventHandler]$progressChangedEventHandler = {
|
||||
param($sender, [System.Net.DownloadProgressChangedEventArgs]$EventArgs)
|
||||
$bytesReceived = $EventArgs.BytesReceived
|
||||
$totalBytes = $EventArgs.TotalBytesToReceive
|
||||
param($sender, [System.Net.DownloadProgressChangedEventArgs]$ChangedEventArgs)
|
||||
$bytesReceived = $ChangedEventArgs.BytesReceived
|
||||
$totalBytes = $ChangedEventArgs.TotalBytesToReceive
|
||||
|
||||
$percentage = ([double]$bytesReceived)/([double]$totalBytes) * 100
|
||||
|
||||
$progressBar.Value = [int][System.Math]::Truncate($percentage)
|
||||
#$tooltip.SetToolTip($progressBar, [string]::Format("{0:0.00}%", $percentage))
|
||||
$label.Text = [string]::Format("{0:0.00}%", $percentage)
|
||||
}
|
||||
|
||||
[System.ComponentModel.AsyncCompletedEventHandler]$downloadFileCompletedEventHandler = {
|
||||
$form.DialogResult = [System.Windows.Forms.DialogResult]::OK
|
||||
param($sender, [System.ComponentModel.AsyncCompletedEventArgs]$CompletedEventArgs)
|
||||
if (!$form.IsDisposed) {
|
||||
$form.DialogResult = [System.Windows.Forms.DialogResult]::OK
|
||||
}
|
||||
}
|
||||
|
||||
$client = New-Object System.Net.WebClient
|
||||
@ -108,10 +105,13 @@ if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
|
||||
foreach ($item in $items) {
|
||||
$app.NameSpace($JavaDir).copyHere($item)
|
||||
}
|
||||
} elseif ($result -eq [System.Windows.Forms.DialogResult]::Cancel) {
|
||||
$client.CancelAsync()
|
||||
}
|
||||
|
||||
$client.CancelAsync()
|
||||
if ([System.IO.File]::Exists($script:tempFile)) {
|
||||
[System.IO.File]::Delete($script:tempFile)
|
||||
try {
|
||||
[System.IO.File]::Delete($script:tempFile)
|
||||
} catch {
|
||||
Write-Error $_
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user