| 1 |
using System.IO; |
| 2 |
|
| 3 |
namespace GodotTools.Core |
| 4 |
{ |
| 5 |
public static class FileUtils |
| 6 |
{ |
| 7 |
public static void SaveBackupCopy(string filePath) |
| 8 |
{ |
| 9 |
string backupPathBase = filePath + ".old"; |
| 10 |
string backupPath = backupPathBase; |
| 11 |
|
| 12 |
const int maxAttempts = 5; |
| 13 |
int attempt = 1; |
| 14 |
|
| 15 |
while (File.Exists(backupPath) && attempt <= maxAttempts) |
| 16 |
{ |
| 17 |
backupPath = backupPathBase + "." + (attempt); |
| 18 |
attempt++; |
| 19 |
} |
| 20 |
|
| 21 |
if (attempt > maxAttempts + 1) |
| 22 |
{ |
| 23 |
|
| 24 |
backupPath = backupPathBase; |
| 25 |
} |
| 26 |
|
| 27 |
File.Copy(filePath, backupPath, overwrite: true); |
| 28 |
} |
| 29 |
} |
| 30 |
} |