From 24287ac575fb6535321344110e6279da2732b185 Mon Sep 17 00:00:00 2001 From: Xx Date: Fri, 13 Dec 2024 15:49:05 +0800 Subject: [PATCH] refactor: Remove obsolete analysis file and improve Windows admin privilege check in main.go - Deleted the outdated analysis file that contained error diagnostics and solutions. - Updated the checkAdminPrivileges function in main.go to use a more reliable method for checking Windows administrator privileges, enhancing security and accuracy. - Fixed a minor display issue in the success message output. - Added "apprun" to the cSpell dictionary in .vscode/settings.json for improved spell checking. These changes streamline the codebase and enhance the functionality of the application. --- .vscode/settings.json | 1 + analysis | 8 -------- main.go | 17 +++++++++-------- 3 files changed, 10 insertions(+), 16 deletions(-) delete mode 100644 analysis diff --git a/.vscode/settings.json b/.vscode/settings.json index 57e9773..51b045d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "cSpell.words": [ + "apprun", "buildmode", "dylib", "endlocal", diff --git a/analysis b/analysis deleted file mode 100644 index be6e4b7..0000000 --- a/analysis +++ /dev/null @@ -1,8 +0,0 @@ -1. 问题定位 -- 错误发生在第68行附近的 `}` 处 -- 这是一个 shell 脚本语法错误 -- 检查发现是 check_requirements 函数中的花括号闭合问题 - -2. 解决方案 -- 移除多余的花括号 -- 确保函数语法正确 \ No newline at end of file diff --git a/main.go b/main.go index 9d7ea17..be116fc 100644 --- a/main.go +++ b/main.go @@ -482,7 +482,7 @@ func showSuccess() { successColor.Printf("%s\n", text.SuccessMessage) fmt.Println() warningColor.Printf("%s\n", text.RestartMessage) - successColor.Println("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━���━━━") + successColor.Println("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━") } // Add spacing before config location @@ -527,13 +527,14 @@ func showPrivilegeError() { func checkAdminPrivileges() (bool, error) { switch runtime.GOOS { case "windows": - cmd := exec.Command("whoami", "/groups") - output, err := cmd.Output() - if err != nil { - return false, err + // 使用更可靠的方法检查Windows管理员权限 + cmd := exec.Command("net", "session") + err := cmd.Run() + if err == nil { + return true, nil } - return strings.Contains(string(output), "S-1-16-12288") || - strings.Contains(string(output), "S-1-5-32-544"), nil + // 如果命令执行失败,说明没有管理员权限 + return false, nil case "darwin", "linux": currentUser, err := user.Current() @@ -841,7 +842,7 @@ func main() { // Progress spinner functions / 进度条函数 func NewProgressSpinner(message string) *ProgressSpinner { return &ProgressSpinner{ - frames: []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}, + frames: []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "��", "⠏"}, message: message, } }