Пример #1
0
 private async Task DeleteOrphanedBackupFilesAsync(HashSet <string> backupPaths)
 {
     foreach (StorageFile backupFile in await SessionUtility.GetAllBackupFilesAsync())
     {
         if (!backupPaths.Contains(backupFile.Path))
         {
             try
             {
                 await backupFile.DeleteAsync();
             }
             catch
             {
                 // Best effort
             }
         }
     }
 }
Пример #2
0
        private async Task DeleteOrphanedBackupFilesAsync(NotepadsSessionDataV1 sessionData)
        {
            HashSet <string> backupPaths = sessionData.TextEditors
                                           .SelectMany(te => new[] { te.LastSaved?.BackupFilePath, te.Pending?.BackupFilePath })
                                           .ToHashSet(StringComparer.OrdinalIgnoreCase);

            foreach (StorageFile backupFile in await SessionUtility.GetAllBackupFilesAsync())
            {
                if (!backupPaths.Contains(backupFile.Path))
                {
                    try
                    {
                        await backupFile.DeleteAsync();
                    }
                    catch (Exception ex)
                    {
                        LoggingService.LogError($"Failed to delete backup file: {ex.Message}");
                    }
                }
            }
        }
Пример #3
0
        private async Task DeleteOrphanedBackupFilesAsync(NotepadsSessionDataV1 sessionData)
        {
            HashSet <string> backupPaths = sessionData.TextEditors
                                           .SelectMany(te => new[] { te.LastSaved?.BackupFilePath, te.Pending?.BackupFilePath })
                                           .ToHashSet(StringComparer.OrdinalIgnoreCase);

            foreach (StorageFile backupFile in await SessionUtility.GetAllBackupFilesAsync())
            {
                if (!backupPaths.Contains(backupFile.Path))
                {
                    try
                    {
                        await backupFile.DeleteAsync();
                    }
                    catch
                    {
                        // Best effort
                    }
                }
            }
        }
Пример #4
0
        // Cleanup orphaned/dangling backup files
        private async Task DeleteOrphanedBackupFilesAsync(NotepadsSessionDataV1 sessionData)
        {
            HashSet <string> backupPaths = sessionData.TextEditors
                                           .SelectMany(editor => new[] { editor.LastSavedBackupFilePath, editor.PendingBackupFilePath })
                                           .Where(path => path != null)
                                           .ToHashSet(StringComparer.OrdinalIgnoreCase);

            foreach (StorageFile backupFile in await SessionUtility.GetAllBackupFilesAsync(_backupFolderName))
            {
                if (!backupPaths.Contains(backupFile.Path))
                {
                    try
                    {
                        await backupFile.DeleteAsync();
                    }
                    catch (Exception ex)
                    {
                        LoggingService.LogError($"[{nameof(SessionManager)}] Failed to delete orphaned backup file: {ex.Message}");
                    }
                }
            }
        }