diff --git a/build.ps1 b/build.ps1 index 08a0d7dc..325f4960 100644 --- a/build.ps1 +++ b/build.ps1 @@ -43,11 +43,11 @@ if (Test-Path .\other\release) { } Write-Host -Write-Host "Building Netch" +Write-Host 'Building Netch' dotnet publish ` -c $Configuration ` - -r "win-x64" ` - -p:Platform="x64" ` + -r 'win-x64' ` + -p:Platform='x64' ` -p:PublishSingleFile=$PublishSingleFile ` -p:SelfContained=$SelfContained ` -p:PublishTrimmed=$SelfContained ` @@ -57,7 +57,7 @@ dotnet publish ` if ( -Not $? ) { exit $lastExitCode } Write-Host -Write-Host "Building Redirector" +Write-Host 'Building Redirector' msbuild ` -property:Configuration=Release ` -property:Platform=x64 ` @@ -66,7 +66,7 @@ if ( -Not $? ) { exit $lastExitCode } Copy-Item -Force Redirector\bin\Redirector.bin $OutputPath\bin -if ( "Release".Equals($Configuration) ) { +if ( $Configuration.Equals('Release') ) { Remove-Item -Force $OutputPath\*.pdb Remove-Item -Force $OutputPath\*.xml } diff --git a/clean.ps1 b/clean.ps1 index a769d15d..0515f827 100644 --- a/clean.ps1 +++ b/clean.ps1 @@ -1,22 +1,27 @@ -Set-Location (Split-Path $MyInvocation.MyCommand.Path -Parent) +Push-Location (Split-Path $MyInvocation.MyCommand.Path -Parent) function Delete { - param([string]$Path) + param ( + [string] + $Path + ) if (Test-Path $Path) { - Remove-Item -Recurse -Force $Path | Out-Null + rm -Recurse -Force $Path | Out-Null } } -Delete ".vs" -Delete "release" -Delete "Netch\bin" -Delete "Netch\obj" -Delete "Tests\bin" -Delete "Tests\obj" -Delete "TestResults" -Delete "Redirector\bin" -Delete "Redirector\obj" +Delete '.vs' +Delete 'release' +Delete 'Netch\bin' +Delete 'Netch\obj' +Delete 'Tests\bin' +Delete 'Tests\obj' +Delete 'TestResults' +Delete 'Redirector\bin' +Delete 'Redirector\obj' -.\Other\clean.ps1 -exit $lastExitCode +.\other\clean.ps1 + +Pop-Location +exit $lastExitCode \ No newline at end of file diff --git a/deps.ps1 b/deps.ps1 index 04eff82e..a31cc00e 100644 --- a/deps.ps1 +++ b/deps.ps1 @@ -3,29 +3,32 @@ param ( $OutputPath = 'release' ) -Push-Location $OutputPath +if ( Test-Path -Path "$OutputPath" -IsValid ) { + New-Item -ItemType Directory -Name "$OutputPath" | Out-Null +} -New-Item -ItemType Directory -Name bin | Out-Null -New-Item -ItemType Directory -Name mode | Out-Null -New-Item -ItemType Directory -Name i18n | Out-Null +Push-Location "$OutputPath" +New-Item -ItemType Directory -Name 'bin' | Out-Null +New-Item -ItemType Directory -Name 'mode' | Out-Null +New-Item -ItemType Directory -Name 'i18n' | Out-Null -# Get-ChildItem -Path ..\scripts\deps\base -File | ForEach-Object { +# Get-ChildItem -Path '..\scripts\deps\main' -File | ForEach-Object { # $name=$_.Name # Write-Host "Executing $name" # & "..\scripts\deps\base\$name" -# if (-Not $?) { +# if ( -Not $? ) { # Pop-Location # exit $lastExitCode # } # } -Get-ChildItem -Path ..\scripts\deps -File | ForEach-Object { +Get-ChildItem -Path '..\scripts\deps' -File | ForEach-Object { $name=$_.Name Write-Host "Executing $name" - & "..\scripts\deps\$name" -OutputPath bin - if (-Not $?) { + & "..\scripts\deps\$name" -OutputPath 'bin' + if ( -Not $? ) { Pop-Location exit $lastExitCode } diff --git a/scripts/deps/cloak.ps1 b/scripts/deps/cloak.ps1 index 5a56f7f4..f7459410 100644 --- a/scripts/deps/cloak.ps1 +++ b/scripts/deps/cloak.ps1 @@ -1,9 +1,16 @@ -param([string]$OutputPath) -$name="ck-client.exe" -$address="https://github.com/cbeuw/Cloak/releases/download/v2.5.4/ck-client-windows-amd64-v2.5.4.exe" +param ( + [string] + $OutputPath +) -..\scripts\download.ps1 $name $address -if (-Not $?) { exit $lastExitCode } +try { + Invoke-WebRequest ` + -Uri 'https://github.com/cbeuw/Cloak/releases/download/v2.5.4/ck-client-windows-amd64-v2.5.4.exe' ` + -OutFile 'ck-client.exe' +} +catch { + exit 1 +} -Move-Item -Force $name $OutputPath +mv -Force 'ck-client.exe' $OutputPath exit 0 \ No newline at end of file diff --git a/scripts/deps/geoip.ps1 b/scripts/deps/geoip.ps1 index 6730b4bc..78afc4a6 100644 --- a/scripts/deps/geoip.ps1 +++ b/scripts/deps/geoip.ps1 @@ -1,9 +1,16 @@ -param([string]$OutputPath) -$name="geoip.dat" -$address="https://github.com/v2fly/geoip/releases/download/202107150023/geoip.dat" +param ( + [string] + $OutputPath +) -..\scripts\download.ps1 $name $address -if (-Not $?) { exit $lastExitCode } +try { + Invoke-WebRequest ` + -Uri 'https://github.com/v2fly/geoip/releases/download/202107150023/geoip.dat' ` + -OutFile 'geoip.dat' +} +catch { + exit 1 +} -Move-Item -Force $name $OutputPath +mv -Force 'geoip.dat' $OutputPath exit 0 \ No newline at end of file diff --git a/scripts/deps/geosite.ps1 b/scripts/deps/geosite.ps1 index 320aebb4..8f62a026 100644 --- a/scripts/deps/geosite.ps1 +++ b/scripts/deps/geosite.ps1 @@ -1,9 +1,16 @@ -param([string]$OutputPath) -$name="geosite.dat" -$address="https://github.com/v2fly/domain-list-community/releases/download/20210718155822/dlc.dat" +param ( + [string] + $OutputPath +) -..\scripts\download.ps1 $name $address -if (-Not $?) { exit $lastExitCode } +try { + Invoke-WebRequest ` + -Uri 'https://github.com/v2fly/domain-list-community/releases/download/20210718155822/dlc.dat' ` + -OutFile 'geosite.dat' +} +catch { + exit 1 +} -Move-Item -Force $name $OutputPath +mv -Force 'geosite.dat' $OutputPath exit 0 \ No newline at end of file diff --git a/scripts/deps/base/netch-data.ps1 b/scripts/deps/main/netch-data.ps1 similarity index 100% rename from scripts/deps/base/netch-data.ps1 rename to scripts/deps/main/netch-data.ps1 diff --git a/scripts/deps/base/netch-i18n.ps1 b/scripts/deps/main/netch-i18n.ps1 similarity index 100% rename from scripts/deps/base/netch-i18n.ps1 rename to scripts/deps/main/netch-i18n.ps1 diff --git a/scripts/deps/base/netch-mode.ps1 b/scripts/deps/main/netch-mode.ps1 similarity index 100% rename from scripts/deps/base/netch-mode.ps1 rename to scripts/deps/main/netch-mode.ps1 diff --git a/scripts/deps/v2ray-core.ps1 b/scripts/deps/v2ray-core.ps1 index 5d483f1b..933aaeb5 100644 --- a/scripts/deps/v2ray-core.ps1 +++ b/scripts/deps/v2ray-core.ps1 @@ -1,17 +1,24 @@ -param([string]$OutputPath) -$name="v2ray-core.zip" -$address="https://github.com/v2fly/v2ray-core/releases/download/v4.40.1/v2ray-windows-64.zip" +param ( + [string] + $OutputPath +) -..\scripts\download.ps1 $name $address -if (-Not $?) { exit $lastExitCode } +try { + Invoke-WebRequest ` + -Uri 'https://github.com/v2fly/v2ray-core/releases/download/v4.40.1/v2ray-windows-64.zip' ` + -OutFile 'v2ray-core.zip' +} +catch { + exit 1 +} -..\scripts\extract.ps1 $name "v2ray-core" -if (-Not $?) { exit $lastExitCode } +7z x 'v2ray-core.zip' -o'v2ray-core' +if ( -Not $? ) { exit $lastExitCode } -Move-Item -Force v2ray-core\v2ctl.exe $OutputPath -Move-Item -Force v2ray-core\v2ray.exe $OutputPath -Move-Item -Force v2ray-core\wv2ray.exe $OutputPath +mv -Force 'v2ray-core\v2ctl.exe' $OutputPath +mv -Force 'v2ray-core\v2ray.exe' $OutputPath +mv -Force 'v2ray-core\wv2ray.exe' $OutputPath -Remove-Item -Recurse -Force v2ray-core -Remove-Item -Recurse -Force v2ray-core.zip +rm -Recurse -Force v2ray-core +rm -Recurse -Force v2ray-core.zip exit 0 \ No newline at end of file diff --git a/scripts/deps/v2ray-plugin.ps1 b/scripts/deps/v2ray-plugin.ps1 index 87b2d0ce..646fe84c 100644 --- a/scripts/deps/v2ray-plugin.ps1 +++ b/scripts/deps/v2ray-plugin.ps1 @@ -1,18 +1,25 @@ -param([string]$OutputPath) -$name="v2ray-plugin.tar.gz" -$address="https://github.com/teddysun/v2ray-plugin/releases/download/v4.40.1/v2ray-plugin-windows-amd64-v4.40.1.tar.gz" +param ( + [string] + $OutputPath +) -..\scripts\download.ps1 $name $address -if (-Not $?) { exit $lastExitCode } +try { + Invoke-WebRequest ` + -Uri 'https://github.com/teddysun/v2ray-plugin/releases/download/v4.40.1/v2ray-plugin-windows-amd64-v4.40.1.tar.gz' ` + -OutFile 'v2ray-plugin.tar.gz' +} +catch { + exit 1 +} -7z x $name -if (-Not $?) { exit $lastExitCode } +7z x 'v2ray-plugin.tar.gz' +if ( -Not $? ) { exit $lastExitCode } -7z x "v2ray-plugin.tar" -if (-Not $?) { exit $lastExitCode } +7z x 'v2ray-plugin.tar' +if ( -Not $? ) { exit $lastExitCode } -Move-Item -Force "v2ray-plugin_windows_amd64.exe" "$OutputPath\v2ray-plugin.exe" +mv -Force 'v2ray-plugin_windows_amd64.exe' "$OutputPath\v2ray-plugin.exe" -Remove-Item -Recurse -Force $name -Remove-Item -Recurse -Force v2ray-plugin.tar +rm -Force 'v2ray-plugin.tar' +rm -Force 'v2ray-plugin.tar.gz' exit 0 \ No newline at end of file diff --git a/scripts/deps/xray-core.ps1 b/scripts/deps/xray-core.ps1 index 36f0e2bc..6e2e96c2 100644 --- a/scripts/deps/xray-core.ps1 +++ b/scripts/deps/xray-core.ps1 @@ -1,15 +1,22 @@ -param([string]$OutputPath) -$name="xray-core.zip" -$address="https://github.com/XTLS/Xray-core/releases/download/v1.4.2/Xray-windows-64.zip" +param ( + [string] + $OutputPath +) -..\scripts\download.ps1 $name $address -if (-Not $?) { exit $lastExitCode } +try { + Invoke-WebRequest ` + -Uri 'https://github.com/XTLS/Xray-core/releases/download/v1.4.2/Xray-windows-64.zip' ` + -OutFile 'xray-core.zip' +} +catch { + exit 1 +} -..\scripts\extract.ps1 $name "xray-core" -if (-Not $?) { exit $lastExitCode } +7z x 'xray-core.zip' -o'xray-core' +if ( -Not $? ) { exit $lastExitCode } -Move-Item -Force "xray-core\xray.exe" $OutputPath +mv -Force 'xray-core\xray.exe' $OutputPath -Remove-Item -Recurse -Force xray-core -Remove-Item -Recurse -Force xray-core.zip +rm -Recurse -Force xray-core +rm -Recurse -Force xray-core.zip exit 0 \ No newline at end of file diff --git a/scripts/deps/xray-plugin.ps1 b/scripts/deps/xray-plugin.ps1 index f9cf5d12..870caf8c 100644 --- a/scripts/deps/xray-plugin.ps1 +++ b/scripts/deps/xray-plugin.ps1 @@ -1,18 +1,25 @@ -param([string]$OutputPath) -$name="xray-plugin.tar.gz" -$address="https://github.com/teddysun/xray-plugin/releases/download/v1.4.2/xray-plugin-windows-amd64-v1.4.2.tar.gz" +param ( + [string] + $OutputPath +) -..\scripts\download.ps1 $name $address -if (-Not $?) { exit $lastExitCode } +try { + Invoke-WebRequest ` + -Uri 'https://github.com/teddysun/xray-plugin/releases/download/v1.4.2/xray-plugin-windows-amd64-v1.4.2.tar.gz' ` + -OutFile 'xray-plugin.tar.gz' +} +catch { + exit 1 +} -7z x $name -if (-Not $?) { exit $lastExitCode } +7z x 'xray-plugin.tar.gz' +if ( -Not $? ) { exit $lastExitCode } -7z x "xray-plugin.tar" -if (-Not $?) { exit $lastExitCode } +7z x 'xray-plugin.tar' +if ( -Not $? ) { exit $lastExitCode } -Move-Item -Force "xray-plugin_windows_amd64.exe" "$OutputPath\xray-plugin.exe" +mv -Force 'xray-plugin_windows_amd64.exe' "$OutputPath\xray-plugin.exe" -Remove-Item -Recurse -Force $name -Remove-Item -Recurse -Force xray-plugin.tar +rm -Force 'xray-plugin.tar' +rm -Force 'xray-plugin.tar.gz' exit 0 \ No newline at end of file diff --git a/scripts/download.ps1 b/scripts/download.ps1 deleted file mode 100644 index 516423af..00000000 --- a/scripts/download.ps1 +++ /dev/null @@ -1,18 +0,0 @@ -param ( - [string] - $name, - - [string] - $address -) - -try -{ - Invoke-WebRequest -OutFile $name -Uri $address -} -catch -{ - exit 1 -} - -exit 0 \ No newline at end of file diff --git a/scripts/extract.ps1 b/scripts/extract.ps1 deleted file mode 100644 index d8a9c5d7..00000000 --- a/scripts/extract.ps1 +++ /dev/null @@ -1,19 +0,0 @@ -param ( - [string] - $name, - - [string] - $address -) - -try -{ - Expand-Archive -Force -Path $name -DestinationPath $address -} -catch -{ - Write-Host "Extract $name failed" - exit 1 -} - -exit 0 \ No newline at end of file