Skip to content

优化备份功能#78

Open
LanYun2022 wants to merge 6 commits intoJack251970:masterfrom
LanYun2022:fix1
Open

优化备份功能#78
LanYun2022 wants to merge 6 commits intoJack251970:masterfrom
LanYun2022:fix1

Conversation

@LanYun2022
Copy link

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes the backup and restore functionality for the context menu manager by introducing a dictionary-based lookup system to improve performance when searching for backup items.

Changes:

  • Replaced O(n) linear searches with O(1) dictionary lookups using a new backupLookup dictionary
  • Added GetRegistryKeySafe method to handle registry key access differently during backup vs restore operations
  • Optimized registry ownership operations to only execute during restore operations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

LanYun2022 and others added 4 commits January 26, 2026 15:24
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Jack251970
Copy link
Owner

@LanYun2022 这只包含代码质量的更新吗?能否将与原先逻辑改变的地方做出标注?

@LanYun2022
Copy link
Author

LanYun2022 commented Feb 27, 2026

@Jack251970 只是把代码拆分和优化了

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +123 to +137
// 获取MetaData对象
metaData = myData.MetaData;

// 清理backupRestoreList变量
backupRestoreList.Clear();
backupRestoreList = null;

// 获取BackupList对象
backupRestoreList = myData.BackupList;
backupLookup.Clear();
foreach (var item in backupRestoreList)
{
var key = GetLookupKey(item.BackupScene, item.KeyName, item.ItemType);
if (!backupLookup.ContainsKey(key)) backupLookup.Add(key, item);
}
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoadBackupList clears backupRestoreList and then sets it to null before reassigning from myData.BackupList. If the XML is missing <BackupList> (or it deserializes as null), the subsequent foreach will throw, and later calls like ClearBackupList() will also crash. Consider keeping the field non-null and defaulting to an empty list (e.g., assign myData.BackupList ?? new List<BackupItem>()) and remove the = null step.

Copilot uses AI. Check for mistakes.
Comment on lines +153 to +167
public static void LoadBackupDataMetaData(string filePath)
{
// 反序列化root对象并保存到XML文档
using var stream = new FileStream(filePath, FileMode.Open);
// 读取 <MetaData> 节点
using var reader = XmlReader.Create(stream);
// 寻找第一个<MetaData>节点
reader.ReadToFollowing("MetaData");

// 清理metaData变量
metaData = null;

// 反序列化<MetaData>节点为MetaData对象
metaData = (MetaData)metaDataSerializer.Deserialize(reader);
}
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoadBackupDataMetaData ignores the return value of reader.ReadToFollowing("MetaData"). If the node is missing/corrupt, Deserialize(reader) will throw (and metaData is set to null just before that). Consider checking the boolean result and handling the error (e.g., keep existing metaData, or initialize a new MetaData, or early-return) to avoid exceptions during backup cleanup.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants