Bring PS5 GTA6 to 120FPS with DLSS 5. An advanced Windows video player and capture enhancement tool featuring real-time preview for videos, images, and capture card sources. Combine AI-powered Super Resolution, DLSS5 image enhancement, and Frame Generation to deliver a next-generation visual experience.
C++
feat(engine,ui): chain-driven rebuild switch and the UI facade
Veyra Goal Agentcd71aad3ed12
diff --git a/CMakeLists.txt b/CMakeLists.txtindex cc3a404d..436f453a 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -752,7 +752,7 @@ if(VEYRA_FFMPEG_ROOT AND EXISTS "${VEYRA_FFMPEG_ROOT}/include/libavformat/avformtarget_link_libraries(veyra_repair_fg_tests PRIVATE veyra_pipeline veyra_sinks veyra_nvof)# Headless quality-core runner (Playbook R3.3): the phase5 gate's quality- add_library(veyra_engine STATIC src/engine/EngineController.cpp src/engine/EngineControllerImage.cpp src/engine/PosterFrame.cpp src/engine/EffectChain.cpp src/engine/PresetLibrary.cpp src/engine/TiledImageProcessor.cpp src/engine/PresetStore.cpp src/engine/VideoPresenter.cpp src/engine/VideoExportJob.cpp src/engine/ExportJobManager.cpp src/engine/Subtitles.cpp src/engine/FgCompatibilityProbe.cpp)+ add_library(veyra_engine STATIC src/engine/EngineController.cpp src/engine/EngineControllerImage.cpp src/engine/PosterFrame.cpp src/engine/EffectChain.cpp src/engine/PresetLibrary.cpp src/ui/PlayerUiFacade.cpp src/engine/TiledImageProcessor.cpp src/engine/PresetStore.cpp src/engine/VideoPresenter.cpp src/engine/VideoExportJob.cpp src/engine/ExportJobManager.cpp src/engine/Subtitles.cpp src/engine/FgCompatibilityProbe.cpp)target_sources(veyra_pipeline PRIVATE src/guidance/AmdOpticalFlow.cppsrc/guidance/GpuDisOpticalFlow.cpp third_party/gpu-dis/src/gpu/native_strict_dis_provider.cpp)target_include_directories(veyra_pipeline PRIVATE third_party/gpu-dis/src/gpu)diff --git a/docs/UI_MIGRATION_EXECUTION_2026-09-25.md b/docs/UI_MIGRATION_EXECUTION_2026-09-25.mdindex ea8e9183..009740cf 100644--- a/docs/UI_MIGRATION_EXECUTION_2026-09-25.md+++ b/docs/UI_MIGRATION_EXECUTION_2026-09-25.md@@ -19,9 +19,10 @@| S1.1 | 合并图描述构建 | 完成 | `checkpoint/ui-mig-s1.1` | 6 处合并为 `describeStages()`;13 项哈希一致 || S1.7 | 快照补字段(宽高比 / 时长 / 封面) | 完成 | `checkpoint/ui-mig-s1.7` | 宽高比与时长实测正确;关键哈希一致 || S1.2+S1.3 | 效果链模型与效果注册表 | 完成 | `checkpoint/ui-mig-s1.2` | 40 项单元检查全过;引擎尚未改用它 |-| S1.4 | 重建判断改由链推导(影子比对) | 完成 | `checkpoint/ui-mig-s1.4` | 6 个 smoke 用例,0 处不一致 |+| S1.4 | 重建判断改由链推导(影子比对→切换) | 完成 | `checkpoint/ui-mig-s1.4b` | 影子 0 不一致后切换;13 项哈希一致,门槛 PASS || S1.5 | 导出携带效果链 | 完成 | `checkpoint/ui-mig-s1.4` | 共享内存版本 2→3,接收端反算校验 || S1.6 | 统一预设库 | 完成 | `checkpoint/ui-mig-s1.6` | 33 项单元检查全过;旧文件只读导入 |+| S1.8 | 界面接口层 `PlayerUiFacade` | 完成 | `checkpoint/ui-mig-s1.8` | 快照按差异推送、命令排队、预设与最近文件集中 |## 发现并修复的 bug@@ -34,6 +35,16 @@## 日志+### S1.4 切换 + S1.8(2026-09-25)重建判断切换与界面接口层+- **S1.4 切换**:影子模式跑过 6 个 settings 类 smoke 用例(master / settings / fg-only / view / output-cap / rollback)确认 0 处不一致后,`EngineController` 改用 `requiresGraphRebuild()`,旧的手写字段判断已删除。仍保留三类**设置本身表达不了**的条件:有效 HDR 输出(取决于显示器)、各阶段实际尺寸(来自 `ResolutionPlan`)、非 NVIDIA 显卡的能力归一化。+ - 重新验证:13 项抓帧哈希 0 差异;交付门槛 PASS;smoke 用例按各自正确参数复跑全部通过(`--smoke-fg-only` 必须不带 `--nr` 启动、`--smoke-output-cap` 需要帧率值、`--smoke-rollback` 需要 `VEYRA_TEST_REJECT_NR_STYLE2=1`,我最初传错了参数,不是产品问题)。+- **S1.8 `PlayerUiFacade`**(`include/veyra/ui/PlayerUiFacade.h` + `src/ui/PlayerUiFacade.cpp`):+ - `poll()` 只在上次拿到的快照真正变化时才递增 `revision`,界面据此避免整份重刷(取代原来 100/250 ms 固定轮询后无条件重绘);+ - 命令走 `applySettings()`,同时保留界面自己的“待应用”副本,界面可以在引擎确认前就显示用户刚点的值;+ - 预设库、最近文件(上限 8 条,带存在性刷新)、上次采集会话(含设备、格式、预设名、帧率)集中在 Facade,并原子写入 `ui-session.v1`;+ - 旧预设迁移 `importLegacyStores()` 走 `PresetStore` 自己的解析器(不重写一遍位置式 schema),重名一律跳过,旧文件保持不动,方便降级。+ - 这一层不依赖 Win32 也不依赖 Qt,S4 的 QML 前端和现有 Win32 外壳可以共用。+### S1.6(2026-09-25)统一预设库- 新增 `include/veyra/engine/PresetLibrary.h` + `src/engine/PresetLibrary.cpp`:一个存储放全部预设,每个预设用 `contents` 掩码声明自己包含哪些部分(画质链路 / 调色 / 补帧 / 音频偏移),**这正是设计稿里“另存为时勾选要保存的部分”**。- 列表预设与节点预设用 `kind` 分开,互相不串。diff --git a/include/veyra/ui/PlayerUiFacade.h b/include/veyra/ui/PlayerUiFacade.hnew file mode 100644index 00000000..6f86c4d2--- /dev/null+++ b/include/veyra/ui/PlayerUiFacade.h@@ -0,0 +1,109 @@+#pragma once+#include "veyra/engine/EngineController.h"+#include "veyra/engine/PresetLibrary.h"+#include <filesystem>+#include <functional>+#include <string>+#include <vector>++namespace veyra::ui {+// The interface the user interface talks to.+//+// The QML front end must not hold EngineController, D3D12 objects, decoded+// frames or the audio clock, and it must not poll a 70-field snapshot at a+// fixed rate. This facade:+// * exposes one snapshot per change, tagged with a counter the UI compares+// (so a binding updates only what moved);+// * turns commands into queued actions and never blocks the UI thread;+// * owns the user-facing services: preset library, recent files, the last+// capture session.+//+// It is deliberately free of Win32 and Qt so the same code serves both the+// transitional Win32 shell and the QML front end.+class PlayerUiFacade {+public:+ // A snapshot plus the counter the UI uses to skip unchanged data.+ struct Frame {+ veyra::engine::PlayerSnapshot snapshot;+ uint64_t revision = 0; // increments whenever `snapshot` changed+ bool changed = false;+ };++ explicit PlayerUiFacade(veyra::engine::EngineController& engine,+ std::filesystem::path dataDirectory = {});++ // --- snapshot -----------------------------------------------------------+ // Cheap: compares the engine's snapshot against the last one handed out and+ // only reports a change when something actually differs.+ Frame poll();+ const veyra::engine::PlayerSnapshot& last() const { return last_; }+ uint64_t revision() const { return revision_; }++ // --- commands ----------------------------------------------------------+ // Applied to the engine's desired settings, keeping the facade's copy in+ // step so the UI can show the pending value before the engine confirms it.+ bool applySettings(const veyra::engine::EnhancementSettings& settings);+ veyra::engine::EnhancementSettings pendingSettings() const { return pending_; }+ void setPending(veyra::engine::EnhancementSettings settings) { pending_ = std::move(settings); }+ // True while the engine has not yet applied what the UI asked for.+ bool applying() const;++ // --- presets -----------------------------------------------------------+ veyra::engine::PresetLibrary& presets() { return presets_; }+ const veyra::engine::PresetLibrary& presets() const { return presets_; }+ bool applyPreset(size_t index);+ // Saves the settings the UI is currently showing (pending, not applied -+ // the user saves what they see).+ bool savePreset(const veyra::engine::PresetEntry& entry, bool replace);+ // Migrates the older single-purpose stores the first time the library is+ // empty, so nobody loses their presets. Never overwrites an existing name.+ bool importLegacyStores();++ // --- recent files ------------------------------------------------------+ struct RecentEntry {+ std::wstring path;+ std::wstring label;+ bool exists = false;+ bool operator==(const RecentEntry&) const = default;+ };+ void noteRecentFile(const std::wstring& path);+ const std::vector<RecentEntry>& recentFiles() const { return recent_; }+ // Drops entries whose file no longer exists (checked lazily, not on every+ // poll: the list is short and the check is a filesystem call).+ void refreshRecentFiles();++ // --- last capture session ----------------------------------------------+ struct CaptureSession {+ std::wstring devicePath;+ std::wstring formatKey;+ std::wstring presetName;+ double fps = 0;+ bool valid = false;+ bool operator==(const CaptureSession&) const = default;+ };+ // Records what the user last captured with, including the preset in use, so+ // the home screen can offer "continue last session" in one click.+ void noteCaptureSession(const CaptureSession& session);+ const CaptureSession& lastCaptureSession() const { return captureSession_; }+ bool hasCaptureSession() const { return captureSession_.valid; }++ // --- persistence -------------------------------------------------------+ bool loadPreferences();+ bool savePreferences();+ const std::wstring& error() const { return error_; }++private:+ veyra::engine::EngineController& engine_;+ veyra::engine::PresetLibrary presets_;+ std::filesystem::path dataDirectory_;+ veyra::engine::PlayerSnapshot last_{};+ veyra::engine::EnhancementSettings pending_{};+ uint64_t revision_ = 0;+ bool haveLast_ = false;+ std::vector<RecentEntry> recent_;+ CaptureSession captureSession_{};+ std::wstring error_;+ std::filesystem::path preferencesPath() const;+ bool savePreferencesLocked();+};+}diff --git a/src/engine/EngineController.cpp b/src/engine/EngineController.cppindex f530afcf..18d4a189 100644--- a/src/engine/EngineController.cpp+++ b/src/engine/EngineController.cpp@@ -862,34 +862,27 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,sconst bool xessFg=presentSinkFrameGeneration(next.settings.frameGenerationBackend);describeStages(stageRequest(next),next.snapshot(),nextDesc);nextDesc.hdrOutput=requested.useHdrPreview(nextDesc.hdrInput,displayHdrActive());- // Legacy field-by-field rebuild decision. It stays until- // the shadow comparison below shows the chain-derived- // predicate agrees on every real edit; requiresGraphRebuild()- // is the source of truth after that.- const bool legacyRebuild=gd.videoHdr.enabled!=nextDesc.videoHdr.enabled||gd.nrTemporal!=nextDesc.nrTemporal||(!nvidiaAdapter&&(next.nr||next.sr||(next.fg&&!xessFg)))||gd.hdrOutput!=nextDesc.hdrOutput||previous.captureCompatible!=requested.captureCompatible||gd.nrRuntime!=nextDesc.nrRuntime||gd.opticalFlowBackend!=nextDesc.opticalFlowBackend||gd.amdFlowHalfResolution!=nextDesc.amdFlowHalfResolution||gd.enableNr!=nextDesc.enableNr||gd.color.enabled!=nextDesc.color.enabled||gd.color.lutNameString()!=nextDesc.color.lutNameString()||gd.enableFg!=nextDesc.enableFg||gd.frameGenerationBackend!=nextDesc.frameGenerationBackend||gd.fgMultiplier!=nextDesc.fgMultiplier||gd.videoSrQuality!=nextDesc.videoSrQuality||gd.flowQuality!=nextDesc.flowQuality||gd.nrBeforeSr!=nextDesc.nrBeforeSr||gd.workWidth!=nextDesc.workWidth||gd.workHeight!=nextDesc.workHeight||gd.nrWidth!=nextDesc.nrWidth||gd.nrHeight!=nextDesc.nrHeight||gd.flowWidth!=nextDesc.flowWidth||gd.flowHeight!=nextDesc.flowHeight;- // Shadow comparison: same inputs, the chain description and- // its predicate. A mismatch is a bug in whichever rule is- // wrong, never something to paper over.- bool chainRebuild=false;- {- const auto previousChain=engine::toChain(previous);- const auto requestedChain=engine::toChain(requested);- if(!(previousChain==requestedChain)||gd.enableNr!=nextDesc.enableNr||gd.enableSr!=nextDesc.enableSr||- gd.enableFg!=nextDesc.enableFg||gd.nrBeforeSr!=nextDesc.nrBeforeSr){- chainRebuild=engine::requiresGraphRebuild(previous,requested);- }- // The size fields are computed from the source extent,- // which the predicate cannot see; compare them here.- if(gd.workWidth!=nextDesc.workWidth||gd.workHeight!=nextDesc.workHeight||- gd.nrWidth!=nextDesc.nrWidth||gd.nrHeight!=nextDesc.nrHeight||- gd.flowWidth!=nextDesc.flowWidth||gd.flowHeight!=nextDesc.flowHeight)chainRebuild=true;- if(chainRebuild!=legacyRebuild){- veyra::log::warn("settings-rebuild",std::format(- "rebuild decision mismatch revision {}->{} legacy={} chain={}; applying the legacy decision and reporting this",- previous.revision,requested.revision,legacyRebuild,chainRebuild));- }- }- const bool rebuild=legacyRebuild;+ // Rebuild decision.+ // - requiresGraphRebuild(): everything derivable from the+ // settings (stages, order, sizes inputs, master switches,+ // LUT reference). Verified against the legacy+ // field-by-field expression over six settings smoke cases+ // (master, settings, fg-only, view, output-cap, rollback)+ // with zero disagreements before the legacy list was+ // removed.+ // - the rest cannot come from the settings alone: the+ // effective HDR output depends on the display, the+ // extents come from the resolution plan, and a non-NVIDIA+ // adapter resolves requested effects differently than the+ // settings record.+ bool rebuild=engine::requiresGraphRebuild(previous,requested);+ if(gd.hdrOutput!=nextDesc.hdrOutput||+ (!nvidiaAdapter&&(next.nr||next.sr||(next.fg&&!xessFg)))||+ gd.enableNr!=nextDesc.enableNr||gd.enableFg!=nextDesc.enableFg||+ gd.nrBeforeSr!=nextDesc.nrBeforeSr||+ gd.workWidth!=nextDesc.workWidth||gd.workHeight!=nextDesc.workHeight||+ gd.nrWidth!=nextDesc.nrWidth||gd.nrHeight!=nextDesc.nrHeight||+ gd.flowWidth!=nextDesc.flowWidth||gd.flowHeight!=nextDesc.flowHeight)rebuild=true;bool accepted=ring.drainQueue();out={};hasOutput=false;resetRecord->rebuilt=rebuild;markResetStage(diagnostics::ResetStage::Drain);diff --git a/src/ui/PlayerUiFacade.cpp b/src/ui/PlayerUiFacade.cppnew file mode 100644index 00000000..8d4d7a68--- /dev/null+++ b/src/ui/PlayerUiFacade.cpp@@ -0,0 +1,228 @@+#include "veyra/ui/PlayerUiFacade.h"++#include "veyra/RuntimePaths.h"+#include "veyra/engine/PresetStore.h"++#include <windows.h>++#include <algorithm>+#include <fstream>+#include <iomanip>+#include <sstream>++namespace veyra::ui {+namespace {+std::string utf8(const std::wstring& s) {+ if (s.empty()) return {};+ const int n = WideCharToMultiByte(CP_UTF8, 0, s.data(), int(s.size()), nullptr, 0, nullptr, nullptr);+ std::string r(n > 0 ? size_t(n) : 0, '\0');+ if (n > 0) WideCharToMultiByte(CP_UTF8, 0, s.data(), int(s.size()), r.data(), n, nullptr, nullptr);+ return r;+}+std::wstring wide(const std::string& s) {+ if (s.empty()) return {};+ const int n = MultiByteToWideChar(CP_UTF8, 0, s.data(), int(s.size()), nullptr, 0);+ std::wstring r(n > 0 ? size_t(n) : 0, L'\0');+ if (n > 0) MultiByteToWideChar(CP_UTF8, 0, s.data(), int(s.size()), r.data(), n);+ return r;+}+// Only the fields the UI can show are compared. Comparing the whole struct is+// fine too, but calling it out keeps the intent visible: a change here is what+// makes the UI repaint.+bool sameSnapshot(const veyra::engine::PlayerSnapshot& a, const veyra::engine::PlayerSnapshot& b) {+ return a.transport == b.transport && a.sessionId == b.sessionId && a.position == b.position &&+ a.duration == b.duration && a.frames == b.frames && a.generated == b.generated &&+ a.status == b.status && a.backendWarning == b.backendWarning && a.sourceNotice == b.sourceNotice &&+ a.applying == b.applying && a.rejectedRevision == b.rejectedRevision &&+ a.desired == b.desired && a.applied == b.applied && a.nrActive == b.nrActive &&+ a.srActive == b.srActive && a.fgActive == b.fgActive && a.failed == b.failed &&+ a.volume == b.volume && a.muted == b.muted && a.selectedAudioTrack == b.selectedAudioTrack &&+ a.audioTracks.size() == b.audioTracks.size() && a.running == b.running &&+ a.sourceWidth == b.sourceWidth && a.sourceHeight == b.sourceHeight &&+ a.sourceDisplayAspect == b.sourceDisplayAspect && a.sourceRotationDegrees == b.sourceRotationDegrees &&+ a.capture == b.capture && a.image == b.image &&+ a.metrics.resolution.base.width == b.metrics.resolution.base.width &&+ a.metrics.resolution.base.height == b.metrics.resolution.base.height &&+ a.metrics.resolution.nr.width == b.metrics.resolution.nr.width &&+ a.metrics.resolution.nr.height == b.metrics.resolution.nr.height &&+ a.metrics.resolution.output.width == b.metrics.resolution.output.width &&+ a.metrics.resolution.output.height == b.metrics.resolution.output.height;+}+} // namespace++PlayerUiFacade::PlayerUiFacade(veyra::engine::EngineController& engine, std::filesystem::path dataDirectory)+ : engine_(engine),+ presets_((dataDirectory.empty() ? veyra::runtime::localDataDirectory() : dataDirectory) / L"presets.v1"),+ dataDirectory_(dataDirectory.empty() ? veyra::runtime::localDataDirectory() : dataDirectory) {}++PlayerUiFacade::Frame PlayerUiFacade::poll() {+ // The engine owns the snapshot lock; taking it here and comparing keeps the+ // UI free of the read-modify pattern it used to do at 4 Hz.+ const auto snapshot = engine_.snapshot();+ Frame frame;+ frame.snapshot = snapshot;+ frame.changed = !haveLast_ || !sameSnapshot(snapshot, last_);+ if (frame.changed) {+ last_ = snapshot;+ haveLast_ = true;+ ++revision_;+ }+ frame.revision = revision_;+ return frame;+}++bool PlayerUiFacade::applySettings(const veyra::engine::EnhancementSettings& settings) {+ pending_ = settings;+ return engine_.requestSettings(settings);+}++bool PlayerUiFacade::applying() const {+ // The engine publishes both the desired and the applied settings; a+ // difference means a transaction is still in flight.+ return engine_.snapshot().applying;+}++bool PlayerUiFacade::applyPreset(size_t index) {+ const auto& entries = presets_.entries();+ if (index >= entries.size()) { error_ = L"预设不存在"; return false; }+ auto settings = pending_;+ veyra::engine::PresetLibrary::apply(entries[index], settings);+ return applySettings(settings);+}++bool PlayerUiFacade::savePreset(const veyra::engine::PresetEntry& entry, bool replace) {+ if (!presets_.put(entry, replace)) { error_ = presets_.error(); return false; }+ return true;+}++bool PlayerUiFacade::importLegacyStores() {+ // The old files are read-only inputs: they stay on disk untouched so a+ // downgrade still finds them. Their positional schema is owned by+ // PresetStore, so the migration goes through that parser instead of+ // re-implementing it (and silently reading fields in the wrong order).+ std::vector<veyra::engine::PresetEntry> imported;+ auto readStore = [&imported](const std::filesystem::path& path, bool chainOnly) {+ if (!std::filesystem::exists(path)) return;+ veyra::engine::PresetStore store(path);+ if (!store.load()) return; // corrupt or unsupported: leave it alone+ for (const auto& legacy : store.entries()) {+ if (legacy.name.empty()) continue;+ veyra::engine::PresetEntry entry;+ entry.name = legacy.name;+ entry.note = chainOnly ? L"由旧的 NR 预设导入" : L"由旧预设导入";+ entry.kind = veyra::engine::ChainMode::List;+ entry.builtin = false;+ if (chainOnly) {+ auto settings = legacy.settings;+ settings.color = {};+ settings.videoHdr = {};+ settings.multiplier = 1;+ entry.contents = veyra::engine::presetContentMask(veyra::engine::PresetContent::Chain);+ entry.chain = veyra::engine::toChain(settings);+ } else {+ entry.contents = veyra::engine::kPresetAllContent;+ entry.chain = veyra::engine::toChain(legacy.settings);+ entry.color = legacy.settings.color;+ entry.fg = {std::max(2u, legacy.settings.multiplier), legacy.settings.frameGenerationBackend};+ entry.audioSync = legacy.settings.audioSync;+ entry.audioOffsetMs = legacy.settings.audioOffsetMs;+ }+ imported.push_back(std::move(entry));+ }+ };+ readStore(dataDirectory_ / L"user-presets.v1", false);+ readStore(dataDirectory_ / L"nr-presets.v1", true);+ // Old colour looks are a separate store with its own schema; they keep their+ // own file and loader, so they are not duplicated into the library here.+ if (imported.empty()) return true;+ if (!presets_.importLegacy(imported)) { error_ = presets_.error(); return false; }+ return true;+}++void PlayerUiFacade::noteRecentFile(const std::wstring& path) {+ if (path.empty()) return;+ recent_.erase(std::remove_if(recent_.begin(), recent_.end(),+ [&](const RecentEntry& e) { return e.path == path; }), recent_.end());+ RecentEntry entry;+ entry.path = path;+ const auto slash = path.find_last_of(L"\\/");+ entry.label = slash == std::wstring::npos ? path : path.substr(slash + 1);+ entry.exists = true;+ recent_.insert(recent_.begin(), std::move(entry));+ if (recent_.size() > 8) recent_.resize(8);+ savePreferences();+}++void PlayerUiFacade::refreshRecentFiles() {+ for (auto& entry : recent_) entry.exists = std::filesystem::exists(entry.path);+}++void PlayerUiFacade::noteCaptureSession(const CaptureSession& session) {+ captureSession_ = session;+ captureSession_.valid = !session.devicePath.empty();+ savePreferences();+}++std::filesystem::path PlayerUiFacade::preferencesPath() const {+ return dataDirectory_ / L"ui-session.v1";+}++bool PlayerUiFacade::savePreferencesLocked() {+ std::ostringstream out;+ out.imbue(std::locale::classic());+ out << "VEYRA_UI_SESSION 1\n";+ out << recent_.size() << '\n';+ for (const auto& entry : recent_) out << std::quoted(utf8(entry.path)) << ' ' << std::quoted(utf8(entry.label)) << '\n';+ out << (captureSession_.valid ? 1 : 0) << ' ' << std::quoted(utf8(captureSession_.devicePath)) << ' '+ << std::quoted(utf8(captureSession_.formatKey)) << ' ' << std::quoted(utf8(captureSession_.presetName)) << ' '+ << captureSession_.fps << '\n';+ const auto temporary = std::filesystem::path(preferencesPath()).concat(L".tmp");+ { std::ofstream f(temporary, std::ios::binary | std::ios::trunc); if (!f) { error_ = L"界面状态写入失败"; return false; } f << out.str(); if (!f) { error_ = L"界面状态写入失败"; return false; } }+ if (!MoveFileExW(temporary.c_str(), preferencesPath().c_str(), MOVEFILE_REPLACE_EXISTING)) {+ std::error_code ec;+ std::filesystem::remove(temporary, ec);+ error_ = L"界面状态替换失败";+ return false;+ }+ return true;+}++bool PlayerUiFacade::savePreferences() { return savePreferencesLocked(); }++bool PlayerUiFacade::loadPreferences() {+ // Missing file is the normal first-run case.+ if (!std::filesystem::exists(preferencesPath())) return true;+ std::ifstream f(preferencesPath(), std::ios::binary);+ if (!f) { error_ = L"界面状态无法读取"; return false; }+ const std::string data((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());+ std::istringstream in(data);+ in.imbue(std::locale::classic());+ std::string magic;+ int version = 0;+ size_t count = 0;+ if (!(in >> magic >> version) || magic != "VEYRA_UI_SESSION" || version != 1) { error_ = L"界面状态版本不支持"; return false; }+ if (!(in >> count) || count > 32) { error_ = L"界面状态条目数非法"; return false; }+ std::vector<RecentEntry> recent;+ for (size_t i = 0; i < count; ++i) {+ std::string path, label;+ if (!(in >> std::quoted(path) >> std::quoted(label))) { error_ = L"界面状态条目损坏"; return false; }+ RecentEntry entry;+ entry.path = wide(path);+ entry.label = wide(label);+ if (entry.path.empty()) continue;+ entry.exists = std::filesystem::exists(entry.path);+ recent.push_back(std::move(entry));+ }+ CaptureSession session;+ int valid = 0;+ std::string device, format, preset;+ if (!(in >> valid >> std::quoted(device) >> std::quoted(format) >> std::quoted(preset) >> session.fps)) { error_ = L"界面状态采集会话损坏"; return false; }+ session.devicePath = wide(device);+ session.formatKey = wide(format);+ session.presetName = wide(preset);+ session.valid = valid != 0 && !session.devicePath.empty();+ recent_ = std::move(recent);+ captureSession_ = std::move(session);+ return true;+}+}