Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit39ff83c

Browse files
committed
added comments
1 parentfcefec4 commit39ff83c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

‎App/Services/SettingsManager.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,23 @@ private void Save(string name, bool value)
9898
{
9999
try
100100
{
101-
//Ensure cache is loaded before saving
101+
//We lock the file for the entire operation to prevent concurrent writes
102102
usingvarfs=newFileStream(_settingsFilePath,
103103
FileMode.OpenOrCreate,
104104
FileAccess.ReadWrite,
105105
FileShare.None);
106-
107-
varcurrentCache=JsonSerializer.Deserialize<Dictionary<string,JsonElement>>(fs)??new();
106+
107+
// Ensure cache is loaded before saving
108+
varcurrentCache=JsonSerializer.Deserialize<Dictionary<string,JsonElement>>(fs)??[];
108109
_cache=currentCache;
109110
_cache[name]=JsonSerializer.SerializeToElement(value);
110-
fs.Position=0;// Reset stream position to the beginning before writing to override the file
111-
varoptions=newJsonSerializerOptions{WriteIndented=true};
112-
JsonSerializer.Serialize(fs,_cache,options);
111+
fs.Position=0;// Reset stream position to the beginning before writing
112+
113+
JsonSerializer.Serialize(fs,_cache,newJsonSerializerOptions{WriteIndented=true});
114+
115+
// This ensures the file is truncated to the new length
116+
// if the new content is shorter than the old content
117+
fs.SetLength(fs.Position);
113118
}
114119
catch
115120
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp