*
This commit is contained in:
1 parent
204fc52ba2
commit
00b49bc3e3
1 file changed
+7
-3
@@ -8,8 +8,6 @@ public interface IConfigProvider {
|
|||||||
T? Read<T>(string key, T? defaultValue, bool encrypted);
|
T? Read<T>(string key, T? defaultValue, bool encrypted);
|
||||||
bool HasValue(string key);
|
bool HasValue(string key);
|
||||||
void DiscardCache();
|
void DiscardCache();
|
||||||
void MakeDirty();
|
|
||||||
void Save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class JsonConfigProvider : IConfigProvider {
|
public class JsonConfigProvider : IConfigProvider {
|
||||||
@@ -99,8 +97,14 @@ public class JsonConfigProvider : IConfigProvider {
|
|||||||
// ===================================== 保存 =====================================
|
// ===================================== 保存 =====================================
|
||||||
|
|
||||||
private readonly RateLimitedAction saveAction;
|
private readonly RateLimitedAction saveAction;
|
||||||
public void MakeDirty() => saveAction.Invoke();
|
private bool isDirty = false;
|
||||||
|
public void MakeDirty() {
|
||||||
|
isDirty = true;
|
||||||
|
saveAction.Invoke();
|
||||||
|
}
|
||||||
public void Save() {
|
public void Save() {
|
||||||
|
if (!isDirty) return;
|
||||||
|
isDirty = false;
|
||||||
lock (json) FileUtils.Write(filePath, json.Value.ToString(Formatting.Indented));
|
lock (json) FileUtils.Write(filePath, json.Value.ToString(Formatting.Indented));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user