From 3692d1499fb9787724a83b08e30b9840c088250e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Mon, 13 May 2024 17:26:22 +0800 Subject: [PATCH] refactor: boot script --- docs/changelogs/CHANGELOG.v1.3.5.md | 3 ++- script/napcat-utf8.ps1 | 24 +++++++++++++++++++----- script/napcat.ps1 | 24 +++++++++++++++++++----- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/docs/changelogs/CHANGELOG.v1.3.5.md b/docs/changelogs/CHANGELOG.v1.3.5.md index e5e1bd3e..9e22dedd 100644 --- a/docs/changelogs/CHANGELOG.v1.3.5.md +++ b/docs/changelogs/CHANGELOG.v1.3.5.md @@ -3,7 +3,8 @@ QQ Version: Windows 9.9.9-23424 / Linux 3.2.7-23361 ## 修复与优化 - +* 优化启动脚本 + ## 新增与调整 * 修复快速重启进程清理问题 diff --git a/script/napcat-utf8.ps1 b/script/napcat-utf8.ps1 index 72228b1c..ada7f56f 100644 --- a/script/napcat-utf8.ps1 +++ b/script/napcat-utf8.ps1 @@ -2,14 +2,28 @@ function Get-QQpath { try { $key = Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\QQ" $uninstallString = $key.UninstallString + throw "get QQ path error:" return [System.IO.Path]::GetDirectoryName($uninstallString) + "\QQ.exe" - } - catch { - return "D:\QQ.exe" + } catch { + throw "get QQ path error: $_" } } $params = $args -join " " -$QQpath = Get-QQpath +Try { + $QQpath = Get-QQpath +} Catch { + $QQpath = Read-Host -Prompt "select QQ path" + if (!$QQpath) { + Write-Host "not select QQ path, exit" + exit + } +} + +if (!(Test-Path $QQpath)) { + throw "provided QQ path is invalid: $QQpath" +} + $Bootfile = Join-Path $PSScriptRoot "napcat.cjs" $env:ELECTRON_RUN_AS_NODE = 1 -Start-Process powershell -ArgumentList "-noexit", "-noprofile", "-command &{& chcp 65001;& '$QQpath' $Bootfile $params}" +$commandInfo = Get-Command $QQpath -ErrorAction Stop +Start-Process powershell -ArgumentList "-noexit", "-noprofile", "-command &{& chcp 65001;& '$($commandInfo.Path)' $Bootfile $params}" diff --git a/script/napcat.ps1 b/script/napcat.ps1 index 55abd42e..f760eb52 100644 --- a/script/napcat.ps1 +++ b/script/napcat.ps1 @@ -2,14 +2,28 @@ function Get-QQpath { try { $key = Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\QQ" $uninstallString = $key.UninstallString + throw "get QQ path error:" return [System.IO.Path]::GetDirectoryName($uninstallString) + "\QQ.exe" - } - catch { - return "D:\QQ.exe" + } catch { + throw "get QQ path error: $_" } } $params = $args -join " " -$QQpath = Get-QQpath +Try { + $QQpath = Get-QQpath +} Catch { + $QQpath = Read-Host -Prompt "select QQ path" + if (!$QQpath) { + Write-Host "not select QQ path, exit" + exit + } +} + +if (!(Test-Path $QQpath)) { + throw "provided QQ path is invalid: $QQpath" +} + $Bootfile = Join-Path $PSScriptRoot "napcat.cjs" $env:ELECTRON_RUN_AS_NODE = 1 -Start-Process powershell -ArgumentList "-noexit", "-noprofile", "-command &{& '$QQpath' $Bootfile $params}" +$commandInfo = Get-Command $QQpath -ErrorAction Stop +Start-Process powershell -ArgumentList "-noexit", "-noprofile", "-command &{& '$($commandInfo.Path)' $Bootfile $params}" \ No newline at end of file