From 06a95d983b2f4c1849366dde0cde6d27627f4151 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 6 Jan 2026 04:32:15 +0000 Subject: [PATCH 1/3] Initial plan From 92e9c3139d982ca80d9c31c23ecbf931e20fc730 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 6 Jan 2026 04:34:57 +0000 Subject: [PATCH 2/3] Fix Windows downloads directory recognition in installer.ps1 - Changed default directory parameter from hardcoded ${HOME}\Downloads to null - Added Get_Downloads_Dir function to read actual downloads folder from Windows registry - Modified Set_Install_Dir to auto-detect downloads directory or use current directory - Updated help text to reflect new default behavior (current directory) - Removed unused $default_install_dir variable Co-authored-by: ccmywish <63459097+ccmywish@users.noreply.github.com> --- tool/installer.ps1 | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/tool/installer.ps1 b/tool/installer.ps1 index 28bb14a8a..ae405a6ce 100644 --- a/tool/installer.ps1 +++ b/tool/installer.ps1 @@ -7,7 +7,7 @@ # Contributors : Aoran Zeng # | # Created On : <2024-10-26> -# Last Modified : <2025-03-07> +# Last Modified : <2026-01-06> # # chsrc installer for Windows # --------------------------------------------------------------- @@ -16,13 +16,12 @@ param( [switch] $Help, - $Directory = "${HOME}\Downloads", + $Directory = $null, $Version = "pre" ) $binary_name = "chsrc" -$default_install_dir = "${HOME}\Downloads" $platform = "Windows" $global:install_dir = "" @@ -58,7 +57,7 @@ chsrc-installer: Install chsrc on ${platform}. Usage: install.ps1 [options] Options: -h Print this help information --d Specify installation directory, default is $default_install_dir +-d Specify installation directory, default is current directory -v Specify chsrc version "@ @@ -80,7 +79,42 @@ function output_error () { } +function Get_Downloads_Dir { + # 尝试从注册表获取实际的 Downloads 文件夹位置 + try { + $shellFoldersKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" + $downloadsGuid = "{374DE290-123F-4565-9164-39C4925E467B}" + $downloadsPath = (Get-ItemProperty -Path $shellFoldersKey -Name $downloadsGuid -ErrorAction Stop).$downloadsGuid + + # 展开环境变量 (例如 %USERPROFILE% -> C:\Users\xxx) + $downloadsPath = [System.Environment]::ExpandEnvironmentVariables($downloadsPath) + + if (Test-Path -Path $downloadsPath -PathType Container) { + return $downloadsPath + } + } catch { + # 如果注册表读取失败,不输出错误信息,继续使用后备方案 + } + + # 后备方案:返回 null,稍后使用当前目录 + return $null +} + function Set_Install_Dir { + # 如果用户未指定目录,则自动检测 + if ($null -eq $Directory) { + # 尝试获取实际的 Downloads 目录 + $detectedDownloads = Get_Downloads_Dir + if ($null -ne $detectedDownloads) { + $Directory = $detectedDownloads + output_info "Detected Downloads directory: $Directory" + } else { + # 使用当前目录作为默认值 + $Directory = Get-Location | Select-Object -ExpandProperty Path + output_info "Using current directory: $Directory" + } + } + # 检查目录是否存在 if (-not (Test-Path -Path $Directory -PathType Container)) { # 如果目录不存在,执行下面的代码块 From bfe6b091129614dbed7500ce74d4c41bfa6328f4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 6 Jan 2026 04:36:51 +0000 Subject: [PATCH 3/3] Improve efficiency of current directory detection Use $PWD.Path instead of Get-Location | Select-Object for better performance Co-authored-by: ccmywish <63459097+ccmywish@users.noreply.github.com> --- tool/installer.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tool/installer.ps1 b/tool/installer.ps1 index ae405a6ce..3390e5fcb 100644 --- a/tool/installer.ps1 +++ b/tool/installer.ps1 @@ -110,7 +110,7 @@ function Set_Install_Dir { output_info "Detected Downloads directory: $Directory" } else { # 使用当前目录作为默认值 - $Directory = Get-Location | Select-Object -ExpandProperty Path + $Directory = $PWD.Path output_info "Using current directory: $Directory" } }