Better debug messages & some error handling

This commit is contained in:
j4ck 2022-06-02 22:59:09 +03:00
parent b45aaeedc7
commit 25ec0452a4
1 changed files with 13 additions and 4 deletions

View File

@ -20,7 +20,7 @@ public class Database
{
if (File.Exists($"{Name}.json"))
{
Console.WriteLine($"{Name} flag123");
Console.WriteLine($"[{Name}] The file exists.");
var json = File.ReadAllText($"{Name}.json");
var db = JsonConvert.DeserializeObject<List<Table>>(json);
if (db != null)
@ -28,15 +28,24 @@ public class Database
}
else
{
Console.WriteLine($"{Name} flag");
Console.WriteLine($"[{Name}] The file is getting created.");
File.Create($"{Name}.json");
}
}
public void Save()
{
try
{
var json = JsonConvert.SerializeObject(_tables);
File.WriteAllText($"{Name}.json", json);
}
catch
{
// slim chance there might be file structure issues.
// let's attempt to fix that.
SetupFiles();
}
}
public void CreateTable(Table query)
{