mirror of
https://git.recroomarchive.org/RecRoomArchive/RRAC.git
synced 2026-09-08 14:41:25 -07:00
70 lines
1.8 KiB
C#
70 lines
1.8 KiB
C#
using RecRoomArchive.Models.RRA;
|
|
using System.Text.Json;
|
|
|
|
namespace RecRoomArchive.Services
|
|
{
|
|
public class FileService
|
|
{
|
|
private static void PopulateServerData()
|
|
{
|
|
string basePath = "data";
|
|
|
|
string[] directories = ["rooms", "images", "blobs"];
|
|
string[] files = ["rooms.json", "avatar.json", "settings.json", "profile.json", "avatarItems.json", "serverPreferences.json"];
|
|
|
|
Directory.CreateDirectory(basePath);
|
|
|
|
foreach (var directory in directories)
|
|
{
|
|
Directory.CreateDirectory(Path.Combine(basePath, directory));
|
|
}
|
|
|
|
foreach (var file in files)
|
|
{
|
|
string fullPath = Path.Combine(basePath, file);
|
|
|
|
if (!File.Exists(fullPath))
|
|
{
|
|
File.WriteAllText(fullPath, string.Empty);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void WriteServerPrefs(bool isComplete)
|
|
{
|
|
var preferences = new ServerPreferences
|
|
{
|
|
CompletedSetup = isComplete
|
|
};
|
|
|
|
SetData("serverPreferences.json", JsonSerializer.Serialize(preferences));
|
|
}
|
|
|
|
public string? GetData(string name)
|
|
{
|
|
var path = $"data/{name}";
|
|
|
|
if (!File.Exists(path))
|
|
return null;
|
|
|
|
return File.ReadAllText(path);
|
|
}
|
|
|
|
public void SetData(string name, string data)
|
|
{
|
|
var path = $"data/{name}";
|
|
|
|
File.WriteAllText(path, data);
|
|
}
|
|
|
|
public bool FileExists(string name)
|
|
{
|
|
var path = $"data/{name}";
|
|
|
|
if (!File.Exists(path))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
}
|
|
} |