From dc38724f1d9904658e2a194e6473b2f0fd352bdf Mon Sep 17 00:00:00 2001 From: jkpete <1031139173@qq.com> Date: Sat, 7 Jun 2025 11:32:13 +0800 Subject: [PATCH] EGSave add contains and list method --- addons/EGFramework/Module/EGSave.cs | 81 +++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 5 deletions(-) diff --git a/addons/EGFramework/Module/EGSave.cs b/addons/EGFramework/Module/EGSave.cs index 2e53dc8..b2ec8ca 100644 --- a/addons/EGFramework/Module/EGSave.cs +++ b/addons/EGFramework/Module/EGSave.cs @@ -167,14 +167,85 @@ namespace EGFramework } #endregion - + #region Get or Search data and object - public TObject GetObject(string path,string key) where TObject : new(){ - if(ObjectFiles.ContainsKey(path)){ + + public bool ContainsObject(string path, string key) + { + if (ObjectFiles.ContainsKey(path)) + { + return ObjectFiles[path].ContainsKey(key); + } + else if (ObjectReadOnly.ContainsKey(path)) + { + return ObjectReadOnly[path].ContainsKey(key); + } + else + { + throw new Exception("File not loaded, you should use LoadObjectFile(key) or ReadObject(key) first."); + } + } + + public bool ContainsData(string path, string key) + { + if (DataBaseFiles.ContainsKey(path)) + { + return DataBaseFiles[path].ContainsKey(key); + } + else if (DataBaseReadOnly.ContainsKey(path)) + { + return DataBaseReadOnly[path].ContainsKey(key); + } + else + { + throw new Exception("File not loaded, you should use LoadDataFile(key) or ReadData(key) first."); + } + } + + public IEnumerable ListObject(string path) + { + if (ObjectFiles.ContainsKey(path)) + { + return ObjectFiles[path].GetKeys(); + } + else if (ObjectReadOnly.ContainsKey(path)) + { + return ObjectReadOnly[path].GetKeys(); + } + else + { + throw new Exception("File not loaded, you should use LoadObjectFile(key) or ReadObject(key) first."); + } + } + + public IEnumerable ListData(string path, string key) + { + if (DataBaseFiles.ContainsKey(path)) + { + return DataBaseFiles[path].GetKeys(); + } + else if (DataBaseReadOnly.ContainsKey(path)) + { + return DataBaseReadOnly[path].GetKeys(); + } + else + { + throw new Exception("File not loaded, you should use LoadDataFile(key) or ReadData(key) first."); + } + } + + public TObject GetObject(string path, string key) where TObject : new() + { + if (ObjectFiles.ContainsKey(path)) + { return ObjectFiles[path].GetObject(key); - }else if(ObjectReadOnly.ContainsKey(path)){ + } + else if (ObjectReadOnly.ContainsKey(path)) + { return ObjectReadOnly[path].GetObject(key); - }else{ + } + else + { throw new Exception("File not loaded, you should use LoadObjectFile(key) or ReadObject(key) first."); } }