Exemple #1
0
        public static FileInfo[] GetBackupsFor(CharacterFile file)
        {
            var characterName = Path.GetFileNameWithoutExtension(file.FilePath);

            return(CharacterBackupDir.EnumerateFiles("*.fch")
                   .Select(f => (file: f, regex: Regex.Match(f.Name, @"^(.*)-backup-\d+\.fch")))
                   .Where(pair => pair.regex.Success && pair.regex.Groups[1].Value == characterName)
                   .Select(pair => pair.file)
                   .ToArray());
        }
Exemple #2
0
        public static void BackupCharacter(CharacterFile source)
        {
            CharacterBackupDir.Create();
            int latestBackupNumber =
                CharacterBackupDir.EnumerateFiles()
                .Select(f => f.Name)
                .Select(fileName => Regex.Match(fileName, @"^.*-backup-(\d+)\.fch$"))
                .Where(match => match.Success)
                .Select(match =>
                        int.Parse(match.Groups[1].Value))
                .DefaultIfEmpty().Max();

            string charFilename   = Path.GetFileNameWithoutExtension(source.FilePath);
            string backupFilename = $"{charFilename}-backup-{latestBackupNumber + 1}.fch";

            string backupFilePath = Path.Join(CharacterBackupDir.FullName, backupFilename);

            File.Copy(source.FilePath, backupFilePath);
        }
Exemple #3
0
 public Backups([NotNull] CharacterFile currentFile)
 {
     _currentFile = currentFile ?? throw new ArgumentNullException(nameof(currentFile));
     InitializeComponent();
 }