improved save method

This commit is contained in:
2022-08-20 17:44:19 +03:00
parent 3ba45790e7
commit 6da9828e5c
7 changed files with 101 additions and 33 deletions

View File

@@ -261,10 +261,9 @@ namespace PluginManager.Others
/// <returns></returns>
public static async Task SaveToJsonFile<T>(string file, T Data)
{
File.Delete(file);
var s = File.Open(file, FileMode.OpenOrCreate);
await JsonSerializer.SerializeAsync(s, Data, typeof(T), new JsonSerializerOptions { WriteIndented = true });
s.Close();
MemoryStream str = new MemoryStream();
await JsonSerializer.SerializeAsync(str, Data, typeof(T), new JsonSerializerOptions { WriteIndented = true });
await File.WriteAllBytesAsync(file, str.ToArray());
}
/// <summary>
@@ -277,8 +276,7 @@ namespace PluginManager.Others
{
Stream text;
if (File.Exists(input))
text = File.OpenRead(input);
text = new MemoryStream(await File.ReadAllBytesAsync(input));
else
text = new MemoryStream(Encoding.ASCII.GetBytes(input));
text.Position = 0;