-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDatabaseManager.cs
More file actions
35 lines (26 loc) · 928 Bytes
/
DatabaseManager.cs
File metadata and controls
35 lines (26 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
namespace OpenRec_2.Database;
using System.IO;
using System.Threading.Tasks;
public static class DatabaseManager
{
private static readonly string BaseDirectory = "Storage";
public static async Task SaveAsync(string identifier, string key, string data)
{
string userDirectory = Path.Combine(BaseDirectory, identifier);
if (!Directory.Exists(userDirectory))
{
Directory.CreateDirectory(userDirectory);
}
string filePath = Path.Combine(userDirectory, $"{key}.json");
await File.WriteAllTextAsync(filePath, data);
}
public static async Task<string> LoadAsync(string identifier, string key)
{
string filePath = Path.Combine(BaseDirectory, identifier, $"{key}.json");
if (File.Exists(filePath))
{
return await File.ReadAllTextAsync(filePath);
}
return string.Empty;
}
}