feat: 首次安装时让用户确认 BetterNCM 数据目录#90
Open
arisewind wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
BetterNCM 的数据目录(插件、配置等)由环境变量
BETTERNCM_PROFILE决定。当前 installer 在点"安装"时不会询问数据目录,直接开始下载并复制 DLL;数据目录完全交给 BetterNCM DLL 在运行时按内部默认值C:\betterncm处理。这带来两个问题:
C:\betterncm无脑创建文件夹,用户对此毫无感知也无法干预。button_set_path)来事后修改BETTERNCM_PROFILE,但用户必须主动去找这个按钮,且首次安装时已经默认在 C 盘创建了文件——事后修改也无法清理已创建的目录。目标
让用户在首次安装时就决定数据目录的位置,而不是被动接受 C 盘默认值。具体要求:
BETTERNCM_PROFILE未设置)→ 弹出文件夹选择框,让用户确认或修改C:\betterncm,完全向后兼容——用户不改、直接确认或取消,行为与现在一致BETTERNCM_PROFILE的用户(重装、升级)→ 不再打扰,沿用已有值改动
仅修改
src/main.rs,无新增依赖(rfd、winreg均已在Cargo.toml中)。1. 抽取两个 helper 函数
把原本内联在
button_set_path里的注册表读写 + 文件夹对话框逻辑抽取为可复用的函数,避免代码重复:prompt_and_set_data_dir(force: bool)— 核心逻辑。读取当前BETTERNCM_PROFILE,决定是否弹窗、用户选了/取消后写什么值。write_betterncm_profile(value: &str)— 把值同时写入HKLM\...\Environment和HKCU\Environment(沿用原"修改数据地址"的双写实现)。引入
const DEFAULT_BETTERNCM_PROFILE: &str = "C:\\betterncm"统一管理默认值,消除原本散落在代码里的多处硬编码字面量。2.
button_install在下载前插入询问在
on_click闭包开头、std::thread::spawn之前调用prompt_and_set_data_dir(false):force = false表示"仅当BETTERNCM_PROFILE未设过时才弹窗",已设过的用户(重装/升级)不受打扰。spawn之前,确保它运行在 GUI 线程(与button_set_path、button_set_ncm_path的现有模式一致——rfd的模态对话框本就设计为在 UI 线程调用),且用户做选择时下载/安装尚未开始,可以放心取消整个安装流程。3.
button_set_path重构为复用 helper原 28 行内联逻辑替换为单行调用
prompt_and_set_data_dir(true)(force = true表示"总是弹窗"),消除与首次安装路径的代码重复。行为对照
BETTERNCM_PROFILE未设)C:\betterncmC:\betterncm;用户可改可确认C:\betterncm(保证留下明确的注册表值,而非依赖 DLL 硬编码回落)BETTERNCM_PROFILE再点"安装"BETTERNCM_PROFILE备注
force = true("修改数据地址")和force = false(首次安装)在用户取消时的行为有意做了区分:首次安装取消会写默认值(确保留下明确记录);修改地址取消保持原状(零副作用,尊重已有配置)。详见prompt_and_set_data_dir中的None if !force分支注释。rfd::FileDialog,保持安装器界面布局不变。