45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace Lucidiot.Raima {
|
|
public class FilesystemStorage : IDatabaseStorage {
|
|
public readonly string BaseDirectory;
|
|
|
|
public FilesystemStorage(string baseDir) {
|
|
if (!Directory.Exists(baseDir))
|
|
throw new DirectoryNotFoundException(String.Format("The directory '{0}' was not found.", baseDir));
|
|
this.BaseDirectory = Path.GetFullPath(baseDir);
|
|
}
|
|
|
|
#region IDatabaseStorage Members
|
|
|
|
public bool CanRead {
|
|
// TODO: Check the filesystem permissions!
|
|
get { return true; }
|
|
}
|
|
|
|
public bool CanWrite {
|
|
// TODO: Check the filesystem permissions!
|
|
get { return true; }
|
|
}
|
|
|
|
public bool Exists(string fileName) {
|
|
return File.Exists(Path.Combine(BaseDirectory, fileName));
|
|
}
|
|
|
|
public BinaryReader GetReader(string fileName) {
|
|
return new BinaryReader(File.OpenRead(Path.Combine(BaseDirectory, fileName)));
|
|
}
|
|
|
|
public BinaryWriter GetWriter(string fileName) {
|
|
return new BinaryWriter(File.OpenWrite(Path.Combine(BaseDirectory, fileName)));
|
|
}
|
|
|
|
public void Delete(string fileName) {
|
|
File.Delete(Path.Combine(BaseDirectory, fileName));
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|