fix(config): stop reads from creating empty registry subkeys

iniFile/binFile::GetCachedKey used RegCreateKeyExA for every access, so a plain
GetStr/GetInt on a missing section materialised an empty subkey. CScreenManager's
constructor calls LoadQualityProfiles() unconditionally, which reads profile0..
profile5 x4 keys, so every client start left six zero-valued subkeys behind:
126 of them on the dev box, all with zero values. The server's HKCU\SoftwareYAMA\quality key is the same artefact.

Split the helper by intent: writes go through RegCreateKeyExA, reads through
RegOpenKeyExA. Both still ask for KEY_READ|KEY_WRITE, because the handle cache is
shared and a read-only cached handle would make a later SetStr on the same
section fail.

Also fixes a second bug in SaveQualityProfiles: when a level matched the default
it simply continued, so a level the operator reset to default kept the old
custom values in the registry and the reset never took effect. Add
SectionExists() (open-only, never creates) and write the defaults back when the
section already exists.
This commit is contained in:
yuanyuanxiang committed 2026-11-02 14:12:21 +01:00
1 parent 454d25d37f
commit 8b92f32c47
2 files changed
+55 -17

No files matched your search

+13 -5
View File
@@ -2380,6 +2380,8 @@ void CScreenManager::SwitchToNextWindow()
void CScreenManager::LoadQualityProfiles()
{
// 读路径不会创建子键(iniFile 的读取走 RegOpenKeyEx),所以没有下发过质量等级
// 的机器不会凭空出现空的 profile0~profile5。别为了“性能”改成先写后读。
iniFile cfg(CLIENT_PATH);
for (int i = 0; i < QUALITY_COUNT; i++) {
char section[32];
@@ -2399,13 +2401,19 @@ void CScreenManager::SaveQualityProfiles()
for (int i = 0; i < QUALITY_COUNT; i++) {
const QualityProfile& def = GetQualityProfile(i);
const QualityProfile& cur = m_QualityProfiles[i];
// 只有与默认值不同时才保存
if (cur.maxFPS == def.maxFPS && cur.maxWidth == def.maxWidth &&
cur.algorithm == def.algorithm && cur.bitRate == def.bitRate) {
continue;
}
char section[32];
sprintf(section, "profile%d", i);
// 与默认值一致的档位不必落盘——主控每次开远程桌面都会整表下发,
// 全量写会把 6 个节全部建出来,用户没改过任何档位也留一堆默认值。
if (cur.maxFPS == def.maxFPS && cur.maxWidth == def.maxWidth &&
cur.algorithm == def.algorithm && cur.bitRate == def.bitRate) {
// 但**已存在**的节必须把默认值写回去:否则主控把某档改回默认后,
// 客户端还留着上次存的自定义值,重置永远不生效。SectionExists
// 只查不建,不会因为这条分支又凭空造出空键。
if (!cfg.SectionExists(section))
continue;
}
cfg.SetInt(section, "maxFPS", cur.maxFPS);
cfg.SetInt(section, "maxWidth", cur.maxWidth);
cfg.SetInt(section, "algorithm", cur.algorithm);