Skip to content

Commit

Permalink
Update file paths in install and uninstall scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
steve02081504 committed Dec 12, 2023
1 parent 0a5eaf0 commit 5f438f0
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 75 deletions.
34 changes: 5 additions & 29 deletions opt/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,16 @@
[switch]$Fix=$false,
[ValidateSet('yes', 'no', 'ask', 'auto')][string]$StartEsh='auto'
)

function illusionlimb($path) {
Invoke-Expression $(if (Test-Path $PSScriptRoot/../path/esh) { Get-Content "$PSScriptRoot/$path" -Raw }
else { (Invoke-WebRequest "https://github.com/steve02081504/esh/raw/master/opt/$path").Content })
Invoke-Expression $(if (Test-Path $PSScriptRoot/../path/esh) { Get-Content "$PSScriptRoot/../src/$path" -Raw }
else { (Invoke-WebRequest "https://github.com/steve02081504/esh/raw/master/src/$path").Content })
}

illusionlimb ../src/fixers/CodePageFixer.ps1
illusionlimb opt_init.ps1
illusionlimb fixers/CodePageFixer.ps1
illusionlimb opt/opt_init.ps1

if (-not $eshDir) {
Remove-Item $env:LOCALAPPDATA/esh -Confirm -ErrorAction Ignore -Recurse
if (Get-Command git -ErrorAction Ignore) {
try { git clone https://github.com/steve02081504/esh $env:LOCALAPPDATA/esh --depth 1 }
catch {
$Host.UI.WriteErrorLine("下载错误 终止脚本")
exit 1
}
}
else{
Remove-Item $env:TEMP/esh-master -Force -ErrorAction Ignore -Confirm:$false -Recurse
try { Invoke-WebRequest https://bit.ly/Esh-zip -OutFile $env:TEMP/Eshell.zip }
catch {
$Host.UI.WriteErrorLine("下载错误 终止脚本")
exit 1
}
Expand-Archive $env:TEMP/Eshell.zip $env:TEMP -Force
Remove-Item $env:TEMP/Eshell.zip -Force
Move-Item $env:TEMP/esh-master $env:LOCALAPPDATA/esh -Force
}
$eshDir = "$env:LOCALAPPDATA/esh"
try { Invoke-WebRequest 'https://bit.ly/SAO-lib' -OutFile "$eshDir/data/SAO-lib.txt" }
catch {
Write-Host "啊哦 SAO-lib下载失败了`n这不会影响什么,不过你可以在Esh安装好后使用``Update-SAO-lib``来让Esh有机会显示更多骚话"
}
illusionlimb opt/download.ps1
}
else {
Write-Host "检测到已安装 Esh 于 $eshDir"
Expand Down
8 changes: 4 additions & 4 deletions opt/uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
[ValidateSet('no', 'yes', 'ask', 'auto')][string]$RemoveDir='auto'
)
function illusionlimb($path) {
Invoke-Expression $(if (Test-Path $PSScriptRoot/../path/esh) { Get-Content "$PSScriptRoot/$path" -Raw }
else { (Invoke-WebRequest "https://github.com/steve02081504/esh/raw/master/opt/$path").Content })
Invoke-Expression $(if (Test-Path $PSScriptRoot/../path/esh) { Get-Content "$PSScriptRoot/../src/$path" -Raw }
else { (Invoke-WebRequest "https://github.com/steve02081504/esh/raw/master/src/$path").Content })
}

illusionlimb ../src/fixers/CodePageFixer.ps1
illusionlimb opt_init.ps1
illusionlimb fixers/CodePageFixer.ps1
illusionlimb opt/opt_init.ps1

if (-not $eshDir) {
Write-Host "未找到 Esh 安装目录,无法卸载。"
Expand Down
2 changes: 1 addition & 1 deletion runner/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ process {
GetToolFromGit psminnifyer
}
& $PSScriptRoot/tools/ps2exe/ps2exe.ps1 $PSScriptRoot/main.ps1 "$PSScriptRoot/build/esh.exe" -NoConsole `
-Minifyer { $_ | &$PSScriptRoot/tools/psminnifyer/psminnifyer.ps1 } `
-Minifyer { $_.Replace('$Script:','$').Replace('终止脚本','终止程序') | &$PSScriptRoot/tools/psminnifyer/psminnifyer.ps1 } `
-TempDir "$PSScriptRoot/build" -iconFile $PSScriptRoot/../img/esh.ico `
-title 'E-Shell' -description 'E-Shell' -version '1960.7.17.13' `
-company 'E-tek' -product 'E-Sh' -copyright '(c) E-tek Corporation. All rights reserved.' | Out-Default
Expand Down
51 changes: 12 additions & 39 deletions runner/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,28 @@ param(
[Parameter(ValueFromRemainingArguments = $true)]
$RemainingArguments
)
if((Get-ExecutionPolicy) -eq 'Restricted'){ Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force }
$env:Path.Split(";") | ForEach-Object {
if ($_ -and (-not (Test-Path $_ -PathType Container))) {
Write-Warning "检测到无效的环境变量于$_,请考虑删除"
}
elseif ($_ -like "*[\\/]esh[\\/]path*") {
$eshDir = $_ -replace "[\\/]path[\\/]*$", ''
$eshDirFromEnv = $true
}
}
if (-not $eshDir) {
$eshDir = if (Test-Path $env:LOCALAPPDATA/esh) { "$env:LOCALAPPDATA/esh" }
}

#_if PSEXE
#_include ../src/opt/opt_init.ps1
#_else
. $PSScriptRoot/../src/opt/opt_init.ps1
#_endif

if (-not $eshDir) {
Remove-Item $env:LOCALAPPDATA/esh -Confirm -ErrorAction Ignore -Recurse
if (Get-Command git -ErrorAction Ignore) {
try { git clone https://github.com/steve02081504/esh $env:LOCALAPPDATA/esh --depth 1 }
catch {
$Host.UI.WriteErrorLine("下载错误 终止程序")
exit 1
}
}
else{
Remove-Item $env:TEMP/esh-master -Force -ErrorAction Ignore -Confirm:$false -Recurse
try { Invoke-WebRequest https://bit.ly/Esh-zip -OutFile $env:TEMP/Eshell.zip }
catch {
$Host.UI.WriteErrorLine("下载错误 终止程序")
exit 1
}
Expand-Archive $env:TEMP/Eshell.zip $env:TEMP -Force
Remove-Item $env:TEMP/Eshell.zip -Force
Move-Item $env:TEMP/esh-master $env:LOCALAPPDATA/esh -Force
}
$eshDir = "$env:LOCALAPPDATA/esh"
try { Invoke-WebRequest 'https://bit.ly/SAO-lib' -OutFile "$eshDir/data/SAO-lib.txt" }
catch {
Write-Host "啊哦 SAO-lib下载失败了`n这不会影响什么,不过你可以在Esh启动后使用``Update-SAO-lib``来让Esh有机会显示更多骚话"
}
#_if PSEXE
#_include ../src/opt/download.ps1
#_else
. $PSScriptRoot/../src/opt/download.ps1
#_endif
}

if ($RunInstall){
Invoke-Expression "&'$eshDir/src/opt/install.ps1' $RemainingArguments"
exit
}
if (-not (Get-Command pwsh -ErrorAction Ignore)) {
$Host.UI.WriteErrorLine("esh的运行需要PowerShell 6或以上`n访问 https://aka.ms/pscore6 来获取PowerShell 6+ 并使得``pwsh``命令在环境中可用以使得esh能够正常工作")
do {
$response = $Host.UI.PromptForChoice("未找到可用的pwsh", "尝试自动安装PowerShell吗", @("自动安装","带我到下载页面","退出"), 0)
$response = $Host.UI.PromptForChoice("未在环境变量中找到可用的pwsh", "esh的运行需要PowerShell 6或以上`n尝试自动安装PowerShell吗", @("自动安装","带我到下载页面","退出"), 0)
} until ($response -ne -1)
switch ($response) {
0 {
Expand Down
24 changes: 24 additions & 0 deletions src/opt/download.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Remove-Item $env:LOCALAPPDATA/esh -Confirm -ErrorAction Ignore -Recurse
if (Get-Command git -ErrorAction Ignore) {
try { git clone https://github.com/steve02081504/esh $env:LOCALAPPDATA/esh --depth 1 }
catch {
$Host.UI.WriteErrorLine("下载错误 终止脚本")
exit 1
}
}
else{
Remove-Item $env:TEMP/esh-master -Force -ErrorAction Ignore -Confirm:$false -Recurse
try { Invoke-WebRequest https://bit.ly/Esh-zip -OutFile $env:TEMP/Eshell.zip }
catch {
$Host.UI.WriteErrorLine("下载错误 终止脚本")
exit 1
}
Expand-Archive $env:TEMP/Eshell.zip $env:TEMP -Force
Remove-Item $env:TEMP/Eshell.zip -Force
Move-Item $env:TEMP/esh-master $env:LOCALAPPDATA/esh -Force
}
$Script:eshDir = "$env:LOCALAPPDATA/esh"
try { Invoke-WebRequest 'https://bit.ly/SAO-lib' -OutFile "$eshDir/data/SAO-lib.txt" }
catch {
Write-Host "啊哦 SAO-lib下载失败了`n这不会影响什么,不过你可以在Esh安装好后使用``Update-SAO-lib``来让Esh有机会显示更多骚话"
}
9 changes: 7 additions & 2 deletions opt/opt_init.ps1 → src/opt/opt_init.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ $env:Path.Split(";") | ForEach-Object {
# 使用if判断+赋值:我们不能使用??=因为用户可能以winpwsh运行该脚本
if (-not $eshDir) {
$Script:eshDir =
if ($EshellUI.Sources.Path -and (Test-Path "${EshellUI.Sources.Path}/path/esh")) { $EshellUI.Sources.Path }
#_if PSScript #在PSEXE中不可能有$EshellUI,而$PSScriptRoot无效
if (Test-Path "$($EshellUI.Sources.Path)/path/esh") { $EshellUI.Sources.Path }
elseif (Test-Path $PSScriptRoot/../path/esh) { "$PSScriptRoot/.." }
elseif (Test-Path $env:LOCALAPPDATA/esh) { "$env:LOCALAPPDATA/esh" }
elseif
#_else
#_!!if
#_endif
(Test-Path $env:LOCALAPPDATA/esh) { "$env:LOCALAPPDATA/esh" }
}

0 comments on commit 5f438f0

Please sign in to comment.