Skip to content

Migrate note storage from Registry to file system#5

Merged
zzy-life merged 3 commits intomasterfrom
claude/fix-notes-persistence-9dOxu
Mar 21, 2026
Merged

Migrate note storage from Registry to file system#5
zzy-life merged 3 commits intomasterfrom
claude/fix-notes-persistence-9dOxu

Conversation

@zzy-life
Copy link
Copy Markdown
Owner

Summary

This PR migrates the Desktop Notes application from storing note data in the Windows Registry to a file-based storage system in the AppData directory, while maintaining backward compatibility with existing user data.

Key Changes

REGISTRY.cs

  • Storage Migration: Moved note data storage from HKEY_CURRENT_USER\Software\Sand Soft\Desktop Notes to %AppData%\Desktop_Notes\notes\
  • Data Directory Structure:
    • %AppData%\Desktop_Notes\ - Main data directory
    • %AppData%\Desktop_Notes\notes\ - Individual note files (JSON format)
    • %AppData%\Desktop_Notes\_DefaultSettings.json - Default note settings
  • Backward Compatibility: Added MigrateFromRegistry() method that automatically detects and migrates existing Registry data to the new file-based storage on first run
  • Registry Cleanup: After successful migration, old Registry entries are deleted and empty Registry keys are removed
  • Default Settings: Moved SaveDefaultSettings() and GetDefaultSettings() from Registry to file-based storage
  • System Settings: Kept Windows startup settings in Registry (unchanged)

MainForm.cs

  • Loading State Management: Added _isLoading flag to prevent saving during form initialization
  • Property Access: Changed direct property assignments to use backing fields (_theme, _style) with proper validation
  • Save Guard: Modified Save() method to skip saving while form is loading to prevent data corruption
  • Error Handling: Wrapped LoadData() in try-finally block to ensure _isLoading flag is properly reset

Product.wxs

  • Installer Upgrade Sequence: Changed MajorUpgrade schedule from afterInstallExecute to afterInstallInitialize for more reliable upgrades
  • Application Launch: Adjusted custom action timing for running the main executable

Implementation Details

  • All note data is now stored as individual JSON files with pretty-printing for readability
  • Migration is automatic and transparent to users - existing Registry data is detected and migrated on first run
  • File-based storage provides better scalability and easier backup/portability compared to Registry
  • The migration process includes error handling to ensure data integrity even if individual entries fail to migrate

https://claude.ai/code/session_01C8uHLbTTSPExtKZ7pNi56j

claude added 3 commits March 21, 2026 16:03
根本原因:_DefaultSettings 注册表项被当作便签数据处理
- OPENED_NOTES 过滤掉以下划线开头的特殊键,避免 _DefaultSettings 被加载为便签
- DeleteAll() 保留特殊键,防止默认设置在重启时被误删
- LoadData 添加 _isLoading 标志,防止加载过程中 Title setter 用未初始化的 theme=0/style=0 提前写入注册表
- LoadData 直接设置 _theme/_style 字段并调用 ReloadTheme/ReloadStyle,避免 setter 副作用
- 安装器 MajorUpgrade Schedule 改为 afterInstallInitialize 确保覆盖升级顺序正确
- CustomAction 添加条件 NOT REMOVE~="ALL",卸载时不启动程序

https://claude.ai/code/session_01C8uHLbTTSPExtKZ7pNi56j
- 便签数据存储到 %AppData%\Desktop_Notes\notes\{id}.json
- 默认设置存储到 %AppData%\Desktop_Notes\_DefaultSettings.json
- 启动时自动检测注册表中的存量数据并迁移到文件目录
- 迁移完成后清理注册表中的旧数据和空键
- StartWithWindows 和 FirstRun 仍使用注册表(属于系统级设置)
- 保持 REGISTRY 类的公共 API 不变,所有调用方无需修改

https://claude.ai/code/session_01C8uHLbTTSPExtKZ7pNi56j
- Custom 元素的条件从 inner text 改为 Condition 属性(WIX0400)
- DesktopFolder 从 DirectoryRef 改为 StandardDirectory(WIX5436)
- 移除顶部重复的 StandardDirectory DesktopFolder 声明
- RemoveFolder Id 改名避免与 StandardDirectory Id 冲突

https://claude.ai/code/session_01C8uHLbTTSPExtKZ7pNi56j
@zzy-life zzy-life merged commit cc82dce into master Mar 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants