@@ -18,13 +18,16 @@ Write-Output "Latest version: $tag"
1818
1919# download
2020Write-Output " Downloading..."
21+ $tempPath = Get-Random - Maximum 500
22+ $tempPath = " $env: TEMP \cg-$tempPath "
23+ if ( Test-Path $tempPath ) {
24+ rm $tempPath \*
25+ } else {
26+ mkdir - p $tempPath
27+ }
2128function download_file ($name , $path ) {
2229 Write-Output " Download file $path "
23- if ( Test-Path " $env: TEMP \$name " ) {
24- del " $env: TEMP \$name "
25- }
26-
27- Invoke-WebRequest $path - Out " $env: TEMP \$name "
30+ Invoke-WebRequest $path - Out " $tempPath \$name "
2831}
2932download_file cg " $rawPath /$tag /cg"
3033download_file cg.bat " $rawPath /$tag /cg.bat"
@@ -33,14 +36,14 @@ Write-Output "Download success."
3336
3437# move file
3538$cgPath = " $env: APPDATA \cg\bin"
36- $existDir = Test-Path $cgPath
37- if ($existDir -eq $False ) {
39+ if (Test-Path $cgPath ) {
40+ rm $cgPath \*
41+ } else {
3842 mkdir - p $cgPath
3943}
4044
41- mv " $env: TEMP \cg" $cgPath
42- mv " $env: TEMP \cg.bat" $cgPath
43- mv " $env: TEMP \cg.jar" $cgPath
45+ mv " $tempPath \*" $cgPath
46+ rm $tempPath
4447
4548# set environment
4649Write-Output " setting environment."
@@ -54,4 +57,3 @@ if (! $alreadyAdded) {
5457}
5558
5659Write-Output " Install success!"
57- cg - v
0 commit comments