Delete file after importing BeatmapSet w/error handling,

also changed batch-commit of multiple sets to database.
This commit is contained in:
Mikal Stodal 2017-02-28 14:35:42 +01:00
parent 6ce0b7c83a
commit d54a75a5c5
1 changed files with 41 additions and 7 deletions

View File

@ -118,11 +118,44 @@ public void Reset()
public void Import(IEnumerable<string> paths)
{
Stack<BeatmapSetInfo> sets = new Stack<BeatmapSetInfo>();
foreach (string p in paths)
Import(p);
try
{
BeatmapSetInfo set = importBeatmapSet(p);
sets.Push(set);
}
catch (Exception e)
{
Logger.Error(e, $@"Could not import beatmap set");
}
finally
{
// We may or may not want to delete the file depending on where it is stored.
// e.g. reconstructing/repairing database with beatmaps from default storage.
// TODO: Add a check to prevent files from storage to be deleted.
try
{
File.Delete(p);
}
catch (Exception e)
{
Logger.Error(e, $@"Could not delete file at {p}");
}
}
// Batch commit with multiple sets to database
Import(sets);
}
public void Import(string path)
{
Import(new [] { path });
}
private BeatmapSetInfo importBeatmapSet(string path)
{
string hash = null;
@ -156,7 +189,7 @@ public void Import(string path)
BeatmapSetAdded?.Invoke(existing);
}
return;
return null;
}
var beatmapSet = new BeatmapSetInfo
@ -188,7 +221,7 @@ public void Import(string path)
}
}
Import(new[] { beatmapSet });
return beatmapSet;
}
public void Import(IEnumerable<BeatmapSetInfo> beatmapSets)
@ -198,10 +231,11 @@ public void Import(IEnumerable<BeatmapSetInfo> beatmapSets)
connection.BeginTransaction();
foreach (var s in beatmapSets)
{
connection.InsertWithChildren(s, true);
BeatmapSetAdded?.Invoke(s);
}
if (s != null)
{
connection.InsertWithChildren(s, true);
BeatmapSetAdded?.Invoke(s);
}
connection.Commit();
}