feat(git-provider): Initial DatabaseManager
This commit is contained in:
parent
93717b4e43
commit
caa65ca7c3
2 changed files with 36 additions and 0 deletions
33
src/ModuleCore/Database/DatabaseManager.cs
Normal file
33
src/ModuleCore/Database/DatabaseManager.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
namespace ModuleCore.Database;
|
||||
|
||||
public class DatabaseManager
|
||||
{
|
||||
private readonly FileInfo _databaseLocation;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new manager for the given database file by name
|
||||
/// </summary>
|
||||
/// <param name="databaseName">
|
||||
/// Filename for the database with no extension. Slashes are accepted and will create directories as needed.
|
||||
/// </param>
|
||||
public DatabaseManager(string databaseName)
|
||||
{
|
||||
// Even though the xmldoc says "with no extension", we strip off any extension regardless
|
||||
_databaseLocation = new FileInfo(Path.Combine(".", "data", $"{SanitiseFilename(databaseName)}.db"));
|
||||
|
||||
Directory.CreateDirectory(_databaseLocation.DirectoryName!);
|
||||
var file = File.Create(_databaseLocation.FullName);
|
||||
file.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes double dots from the filename and removes the file extension
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
/// <returns></returns>
|
||||
private string SanitiseFilename(string filename)
|
||||
{
|
||||
// Honestly not really needed seeing as its just me and this isn't coming from user supplied code, but eh.
|
||||
return Path.GetFileNameWithoutExtension(filename.Replace("..", string.Empty));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue