Added a corruption check of the database before backing it up.

This commit is contained in:
ruri
2019-10-01 16:03:52 +02:00
parent 6e9513ad4c
commit d8b5eb2133
+7
View File
@@ -123,6 +123,13 @@ namespace OpenBullet
(!File.Exists(Globals.dataBaseBackupFile) ||
(File.Exists(Globals.dataBaseBackupFile) && ((DateTime.Now - File.GetCreationTime(Globals.dataBaseBackupFile)).TotalDays > 1))))
{
// Check that the DB is not corrupted by accessing a random collection. If this fails, an exception will be thrown.
using (var db = new LiteDB.LiteDatabase(Globals.dataBaseFile))
{
var coll = db.GetCollection<RuriLib.Models.CProxy>("proxies");
}
// Delete the old file and copy over the new one
File.Delete(Globals.dataBaseBackupFile);
File.Copy(Globals.dataBaseFile, Globals.dataBaseBackupFile);
Globals.LogInfo(Components.Main, "Backed up the DB");