56 lines
1.2 KiB
C#
56 lines
1.2 KiB
C#
using System.Reflection.Metadata;
|
|
using SzLib;
|
|
using SzLib.DataObjects;
|
|
|
|
namespace SzCli;
|
|
|
|
public class LocalFileManager : ISzFileManager
|
|
{
|
|
public string DataPath
|
|
{
|
|
get
|
|
{
|
|
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data");
|
|
if (!Directory.Exists(path))
|
|
{
|
|
Directory.CreateDirectory(path);
|
|
}
|
|
|
|
return path;
|
|
}
|
|
}
|
|
|
|
public string DatasetsPath => Path.Combine(DataPath, "datasets");
|
|
|
|
public bool SaveFile(string path, string fileContent)
|
|
{
|
|
try
|
|
{
|
|
var dir = Path.GetDirectoryName(path);
|
|
if (dir is null) return false;
|
|
Directory.CreateDirectory(dir);
|
|
|
|
File.WriteAllText(path, fileContent);
|
|
return true;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine($"Error saving file: {e.Message}");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public string? LoadFile(string path)
|
|
{
|
|
try
|
|
{
|
|
return File.ReadAllText(path);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine($"Error saving file: {e.Message}");
|
|
return null;
|
|
}
|
|
}
|
|
}
|