From 8723fbfcbe1ee7adc3aa7169b748053e0cccd703 Mon Sep 17 00:00:00 2001 From: Controllerdestiny <523321293@qq.co> Date: Thu, 22 Aug 2024 22:50:49 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- InstallTShock.ps1 | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/InstallTShock.ps1 b/InstallTShock.ps1 index 242d0a331..b8a80d7f7 100644 --- a/InstallTShock.ps1 +++ b/InstallTShock.ps1 @@ -18,10 +18,8 @@ function Get-DownloadUrl { } $json = $response.Content | ConvertFrom-Json - # 验证JSON是否包含tag_name属性 - if (-not ($json -and $json.assets[3].browser_download_url)) { + # 验证JSON是否包含tag_name属�? if (-not ($json -and $json.assets[3].browser_download_url)) { throw "The JSON content at '$url' does not contain a valid 'tag_name' property." - } return $json.assets[3].browser_download_url } @@ -50,7 +48,7 @@ function Get-TShockZip{ #$ProgressPreference = 'SilentlyContinue' $zipFile = "./TShock.zip" - $response = Invoke-WebRequest -Uri $url -UseBasicParsing + $response = Invoke-WebRequest -Uri $url -UseBasicParsing [IO.File]::WriteAllBytes($zipFile, $response.Content) #$wc = New-Object System.Net.WebClient #$wc.DownloadFile($url, $zipFile) @@ -63,8 +61,8 @@ function Get-TShockZip{ Start-Process -FilePath ./TShock.Server.exe -ArgumentList "-lang 7" } } - catch{ - throw "$_" + catch [System.Net.WebException], [System.Management.Automation.PSInvocationException] { + throw "Error when attempting to get version from '$url': $_" } } } @@ -82,6 +80,4 @@ if ($proxys -ge 0 -and $index -lt $proxys.Length){ Get-TShockZip -proxy $proxys[$index - 1] }else{ Write-Host "Input Number Error!" -} - - \ No newline at end of file +} \ No newline at end of file From ae23c0f053fecc966b66bf35aa41345b98357956 Mon Sep 17 00:00:00 2001 From: Controllerdestiny <523321293@qq.co> Date: Thu, 22 Aug 2024 22:54:16 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- InstallTShock.ps1 | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/InstallTShock.ps1 b/InstallTShock.ps1 index b8a80d7f7..b62811efa 100644 --- a/InstallTShock.ps1 +++ b/InstallTShock.ps1 @@ -37,7 +37,7 @@ function Get-TShockZip{ ) process { - try { + $download_url = Get-DownloadUrl $url = $proxy + $download_url if($null -eq $download_url){ @@ -60,10 +60,7 @@ function Get-TShockZip{ Set-Location ./TShockServer Start-Process -FilePath ./TShock.Server.exe -ArgumentList "-lang 7" } - } - catch [System.Net.WebException], [System.Management.Automation.PSInvocationException] { - throw "Error when attempting to get version from '$url': $_" - } + } } From 3ed967ed81a0aa03056901225b83fb3fe7049e1a Mon Sep 17 00:00:00 2001 From: Controllerdestiny <523321293@qq.co> Date: Thu, 22 Aug 2024 23:17:32 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- InstallTShock.ps1 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/InstallTShock.ps1 b/InstallTShock.ps1 index b62811efa..22086f8ef 100644 --- a/InstallTShock.ps1 +++ b/InstallTShock.ps1 @@ -18,8 +18,10 @@ function Get-DownloadUrl { } $json = $response.Content | ConvertFrom-Json - # 验证JSON是否包含tag_name属�? if (-not ($json -and $json.assets[3].browser_download_url)) { + + if (-not ($json -and $json.assets[3].browser_download_url)) { throw "The JSON content at '$url' does not contain a valid 'tag_name' property." + } return $json.assets[3].browser_download_url } @@ -37,7 +39,7 @@ function Get-TShockZip{ ) process { - + try { $download_url = Get-DownloadUrl $url = $proxy + $download_url if($null -eq $download_url){ @@ -60,7 +62,10 @@ function Get-TShockZip{ Set-Location ./TShockServer Start-Process -FilePath ./TShock.Server.exe -ArgumentList "-lang 7" } - + }catch [System.Net.WebException], [System.Management.Automation.PSInvocationException] { + # 处理可能的网络异常和JSON解析异常 + throw "Error when attempting to get version from '$url': $_" + } } } From 8fe7e9a61d5bce0c622efe183c23ffb67dc4ccec Mon Sep 17 00:00:00 2001 From: Controllerdestiny <523321293@qq.co> Date: Thu, 22 Aug 2024 23:27:29 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=B8=BB=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- InstallTShock.ps1 | 6 ++++-- README.md | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/InstallTShock.ps1 b/InstallTShock.ps1 index 22086f8ef..4a0d6cf7e 100644 --- a/InstallTShock.ps1 +++ b/InstallTShock.ps1 @@ -51,9 +51,11 @@ function Get-TShockZip{ $zipFile = "./TShock.zip" $response = Invoke-WebRequest -Uri $url -UseBasicParsing + # 检查HTTP状态码 + if ($response.StatusCode -ne 200) { + throw "Failed to retrieve the resource at '$url'. Status code: $($response.StatusCode)" + } [IO.File]::WriteAllBytes($zipFile, $response.Content) - #$wc = New-Object System.Net.WebClient - #$wc.DownloadFile($url, $zipFile) Write-Host "Ready to start unzipping TShock.zip...." Expand-Archive -Path "./TShock.zip" -DestinationPath "./TShockServer/" Remove-Item -Path $zipFile -Force diff --git a/README.md b/README.md index cafa64973..5597c6c99 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,12 @@ - 国内镜像: [Plugins.zip](https://github.moeyy.xyz/https://github.com/Controllerdestiny/TShockPlugin/releases/download/V1.0.0.0/Plugins.zip) - 本仓库: [Plugins.zip](https://github.com/Controllerdestiny/TShockPlugin/releases/tag/V1.0.0.0) +## 如何安装TShock +- 如果你是Window用户可以选择使用以下命令一次性安装(在pwsh中运行此命令即可) +``` +curl -o install.ps1 https://github.moeyy.xyz/https://raw.githubusercontent.com/UnrealMultiple/TShockPlugin/main/InstallTShock.ps1 +powershell -ExecutionPolicy ByPass -File ./install.ps1 -verb runas +``` ## 开发者注意事项 From 0559bb257c954af9fd972ae12cfd65f3775b2444 Mon Sep 17 00:00:00 2001 From: Controllerdestiny <523321293@qq.co> Date: Thu, 22 Aug 2024 23:30:34 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5597c6c99..65f23a00a 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ ## 如何安装TShock - 如果你是Window用户可以选择使用以下命令一次性安装(在pwsh中运行此命令即可) ``` -curl -o install.ps1 https://github.moeyy.xyz/https://raw.githubusercontent.com/UnrealMultiple/TShockPlugin/main/InstallTShock.ps1 +curl -o install.ps1 https://github.moeyy.xyz/https://raw.githubusercontent.com/UnrealMultiple/TShockPlugin/master/InstallTShock.ps1 powershell -ExecutionPolicy ByPass -File ./install.ps1 -verb runas ```