⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 6, 2026

Bug 背景

用户将 Downloads 目录从默认位置 C:\Users\xxx\Downloads 移动到自定义位置(如 D:\Downloads)后,安装脚本仍将 chsrc 下载到原默认路径,导致文件位置错误或下载失败。

相关 issue: #306


Bug 原因

installer.ps1 使用硬编码的 ${HOME}\Downloads 作为默认安装路径,未检测 Windows 系统中 Downloads 文件夹的实际位置。


方案

实现三层回退机制:

  1. 从 Windows 注册表读取 Downloads 文件夹实际位置
  2. 若读取失败,使用当前工作目录
  3. 用户可通过 -d 参数覆盖

实现

新增 Get_Downloads_Dir 函数:

  • 从注册表 HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders 读取 Downloads GUID {374DE290-123F-4565-9164-39C4925E467B}
  • 展开环境变量并验证路径存在性
  • 失败时返回 $null 触发回退

修改 Set_Install_Dir 函数:

  • $Directory$null 时自动检测
  • 依次尝试注册表检测和当前目录回退
  • 保留用户指定路径的优先级

其他调整:

  • 参数 $Directory 默认值从 "${HOME}\Downloads" 改为 $null
  • 删除未使用的 $default_install_dir 变量
  • 更新帮助文本反映新的默认行为
  • 使用 $PWD.Path 替代 Get-Location 管道以提升性能
Original prompt

This section details on the original issue you should resolve

<issue_title>chsrc的安装脚本未正确识别已被移动的downloads目录</issue_title>
<issue_description>### 你操作了什么?

我使用脚本下载安装了chsrc

发生了什么?

  1. 我的downloads目录被移动到了D:\downloads
  2. 脚本("& { $(iwr -useb https://chsrc.run/windows) } -Version pre" | iex)仍然将chsrc下载到了 User/xxx/downloads

本应该怎么样?

希望以current dir作为下载路径,或正确识别downloads目录的位置

chsrc 版本

chsrc v0.2.4 (2025/12/31)

你使用的是哪个操作系统?

Windows

OS 版本 / OS 发行版

win11

Log 输出

防止重复问题

  • 我已在项目中搜索过类似的 issue</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Jan 6, 2026
@github-actions
Copy link

github-actions bot commented Jan 6, 2026

Hi @Copilot,

❤️ 感谢你的贡献!你的 PR 当前基于 main 分支,请修改使用 dev 分支

@ccmywish ccmywish changed the base branch from main to dev January 6, 2026 04:33
@ccmywish ccmywish marked this pull request as ready for review January 6, 2026 04:33
Copilot AI and others added 2 commits January 6, 2026 04:34
- 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 <[email protected]>
Use $PWD.Path instead of Get-Location | Select-Object for better performance

Co-authored-by: ccmywish <[email protected]>
Copilot AI changed the title [WIP] Fix chsrc installation script to recognize moved downloads directory 修复 Windows 安装脚本无法识别已移动的 Downloads 目录 Jan 6, 2026
Copilot AI requested a review from ccmywish January 6, 2026 04:38
@YU-7
Copy link
Contributor

YU-7 commented Jan 6, 2026

安装脚本没有把chsrc命令加入系统环境变量,我在archLinux下测试是这样的

@ccmywish
Copy link
Contributor

ccmywish commented Jan 7, 2026

@YU-7

非root用户默认安装至 ~/.local/bin,root用户默认安装至 /usr/local/bin

shell 安装脚本很久没有收到反馈,可能是你的这两个路径之一没有加到 PATH

@ccmywish ccmywish added this to the v0.2.5 milestone Jan 7, 2026
@ccmywish ccmywish added the Windows Windows相关 label Jan 7, 2026
@ccmywish ccmywish merged commit d87fa49 into dev Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Windows Windows相关

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chsrc的安装脚本未正确识别已被移动的downloads目录

3 participants