Bug fixes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using GazpromApp.Models;
|
||||
|
||||
@@ -8,12 +9,26 @@ public static class DataSerialization
|
||||
{
|
||||
private static void SaveData(string path, string data)
|
||||
{
|
||||
System.IO.File.WriteAllText(path, data);
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
File.WriteAllText(path, data);
|
||||
return;
|
||||
}
|
||||
|
||||
var dir = Path.GetDirectoryName(path) ?? "";
|
||||
var fileName = Path.GetFileNameWithoutExtension(path);
|
||||
var ext = Path.GetExtension(path);
|
||||
var index = 1;
|
||||
|
||||
while (File.Exists(Path.Combine(dir, $"{fileName} ({index}){ext}")))
|
||||
index++;
|
||||
|
||||
File.WriteAllText(Path.Combine(dir, $"{fileName} ({index}){ext}"), data);
|
||||
}
|
||||
|
||||
private static string LoadData(string path)
|
||||
{
|
||||
var text = System.IO.File.ReadAllText(path);
|
||||
var text = File.ReadAllText(path);
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user