所有配置文件统一放到 exe 同目录
- control-monitors.json 从 %LocalAppData%\pacs_win_uia\ 改到 exe 同目录 (settings.json / out.json / 截图与 OCR 目录本来就是 exe 同目录,现在一致) - 首次读取时把旧位置的监控配置复制过来(只复制不删除),并记日志; exe 目录不可写时退化为直接读旧文件,保存会明确报错,不会丢配置 - ControlMonitorStore.GetDefaultFilePath()/GetLegacyFilePath() 公开, Program 的 --read-saved 与设置页「关于」都改用同一套路径 - 回归新增用例:默认配置与设置文件都必须在 exe 同目录、旧路径与当前路径必须不同 - 实测(隔离宿主):默认路径=exe 同目录;旧位置有 1 条配置被复制过来并能正常读出 测试 24/24 通过,
This commit is contained in:
@@ -29,6 +29,8 @@ namespace PacsWinUia.RegressionTests
|
||||
tests.Add(new KeyValuePair<string, Action>("Store reads legacy UiaPath definitions", StoreLegacy));
|
||||
// 防:设置缺省刷新间隔不再是 300ms,或缺失的区段未被补全。
|
||||
tests.Add(new KeyValuePair<string, Action>("Settings missing refresh interval defaults to 300", SettingsDefault));
|
||||
// 防:默认配置文件又跑回 %LocalAppData%(需求:所有配置都在 exe 同级别)。
|
||||
tests.Add(new KeyValuePair<string, Action>("Default monitor config lives next to the exe", DefaultConfigLocation));
|
||||
// 防:悬浮条缺省启用被误判为显式停用(或反之)。
|
||||
tests.Add(new KeyValuePair<string, Action>("Floating JSON missing defaults differs from explicit disabled", FloatingDefaults));
|
||||
}
|
||||
@@ -126,6 +128,30 @@ namespace PacsWinUia.RegressionTests
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 默认配置必须在 exe 同目录;旧位置只作为一次性迁移来源保留。
|
||||
// 这里只断言路径本身,不读写磁盘——绝不能在测试里碰用户真实的配置文件。
|
||||
private static void DefaultConfigLocation()
|
||||
{
|
||||
string expectedDirectory = Path.GetDirectoryName(typeof(ControlMonitorStore).Assembly.Location);
|
||||
string defaultPath = ControlMonitorStore.GetDefaultFilePath();
|
||||
Check.Equal(expectedDirectory, Path.GetDirectoryName(defaultPath), "Default config is not next to the exe");
|
||||
Check.Equal("control-monitors.json", Path.GetFileName(defaultPath), "Default config file name");
|
||||
Check.True(Path.IsPathRooted(defaultPath), "Default config path must be absolute");
|
||||
|
||||
string preferred = new AppSettingsStore().PreferredPath;
|
||||
Check.Equal(expectedDirectory, Path.GetDirectoryName(preferred), "Settings file is not next to the exe");
|
||||
|
||||
string legacy = ControlMonitorStore.GetLegacyFilePath();
|
||||
if (legacy != null)
|
||||
{
|
||||
Check.True(!string.Equals(legacy, defaultPath, StringComparison.OrdinalIgnoreCase),
|
||||
"Legacy and current config paths must differ");
|
||||
Check.True(legacy.IndexOf("pacs_win_uia", StringComparison.OrdinalIgnoreCase) >= 0,
|
||||
"Legacy path should stay inside pacs_win_uia");
|
||||
}
|
||||
}
|
||||
|
||||
private static void SettingsDefault()
|
||||
{
|
||||
using (var directory = new TemporaryDirectory())
|
||||
|
||||
Reference in New Issue
Block a user