mirror of
https://github.com/Relintai/mono.git
synced 2024-11-08 10:12:16 +01:00
31 lines
758 B
C#
31 lines
758 B
C#
using System.IO;
|
|
|
|
namespace GodotTools.Core
|
|
{
|
|
public static class FileUtils
|
|
{
|
|
public static void SaveBackupCopy(string filePath)
|
|
{
|
|
string backupPathBase = filePath + ".old";
|
|
string backupPath = backupPathBase;
|
|
|
|
const int maxAttempts = 5;
|
|
int attempt = 1;
|
|
|
|
while (File.Exists(backupPath) && attempt <= maxAttempts)
|
|
{
|
|
backupPath = backupPathBase + "." + (attempt);
|
|
attempt++;
|
|
}
|
|
|
|
if (attempt > maxAttempts + 1)
|
|
{
|
|
// Overwrite the oldest one
|
|
backupPath = backupPathBase;
|
|
}
|
|
|
|
File.Copy(filePath, backupPath, overwrite: true);
|
|
}
|
|
}
|
|
}
|