60 lines
1.5 KiB
C#
60 lines
1.5 KiB
C#
namespace SzCore.Defaults;
|
|
|
|
public class DefaultLocalFileManager : ISzFileManager
|
|
{
|
|
public string DataPath => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data");
|
|
public string DatasetsPath => Path.Combine(DataPath, "datasets");
|
|
public string TemplatesPath => Path.Combine(DataPath, "templates");
|
|
|
|
public DefaultLocalFileManager()
|
|
{
|
|
Directory.CreateDirectory(DataPath);
|
|
Directory.CreateDirectory(DatasetsPath);
|
|
Directory.CreateDirectory(TemplatesPath);
|
|
}
|
|
|
|
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 loading file: {e.Message}");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public bool DeleteFile(string path)
|
|
{
|
|
try
|
|
{
|
|
File.Delete(path);
|
|
return true;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
SZ.Logger.LogError("LocalFileManager: Could not delete file. " + e.Message);
|
|
return false;
|
|
}
|
|
}
|
|
} |