Refactor moving (2/2)

This commit is contained in:
Shivam 2020-06-16 17:15:43 +02:00
parent b75fd7bfa8
commit 02d66c4856

View File

@ -57,7 +57,7 @@ namespace osu.Game.Tournament.IO
if (!cfgDestination.Exists) if (!cfgDestination.Exists)
destination.CreateSubdirectory(config_directory); destination.CreateSubdirectory(config_directory);
moveFileIfExists("bracket.json", destination); moveFileIfExists("bracket.json", destination);
moveFileIfExists("drawings.txt", destination); moveFileIfExists("drawings.txt", destination);
moveFileIfExists("drawings_results.txt", destination); moveFileIfExists("drawings_results.txt", destination);
@ -77,7 +77,8 @@ namespace osu.Game.Tournament.IO
{ {
Logger.Log($"Migrating {file} to default tournament storage."); Logger.Log($"Migrating {file} to default tournament storage.");
var fileInfo = new System.IO.FileInfo(storage.GetFullPath(file)); var fileInfo = new System.IO.FileInfo(storage.GetFullPath(file));
moveFile(fileInfo, destination); attemptOperation(() => fileInfo.CopyTo(Path.Combine(destination.FullName, fileInfo.Name), true));
fileInfo.Delete();
} }
} }
@ -112,12 +113,6 @@ namespace osu.Game.Tournament.IO
attemptOperation(target.Delete); 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) private void attemptOperation(Action action, int attempts = 10)
{ {
while (true) while (true)