Introduce migrations for drawings

This commit is contained in:
Shivam 2020-06-11 17:51:07 +02:00
parent 1d4d749b53
commit c9dc17f3d8
1 changed files with 21 additions and 2 deletions

View File

@ -54,8 +54,21 @@ internal void Migrate()
{
Logger.Log("Migrating bracket to default tournament storage.");
var bracketFile = new System.IO.FileInfo(host.Storage.GetFullPath("bracket.json"));
attemptOperation(() => bracketFile.CopyTo(Path.Combine(destination.FullName, bracketFile.Name), true));
bracketFile.Delete();
moveFile(bracketFile, destination);
}
if (host.Storage.Exists("drawings.txt"))
{
Logger.Log("Migrating drawings to default tournament storage.");
var drawingsFile = new System.IO.FileInfo(host.Storage.GetFullPath("drawings.txt"));
moveFile(drawingsFile, destination);
}
if (host.Storage.Exists("drawings_results.txt"))
{
Logger.Log("Migrating drawings results to default tournament storage.");
var drawingsResultsFile = new System.IO.FileInfo(host.Storage.GetFullPath("drawings_results.txt"));
moveFile(drawingsResultsFile, destination);
}
if (source.Exists)
@ -97,6 +110,12 @@ private void deleteRecursive(DirectoryInfo target)
attemptOperation(target.Delete);
}
private void moveFile(System.IO.FileInfo file, DirectoryInfo destination)
{
attemptOperation(() => file.CopyTo(Path.Combine(destination.FullName, file.Name), true));
file.Delete();
}
private void attemptOperation(Action action, int attempts = 10)
{
while (true)