public Task Execute() { string targetPath = _directoryPatcher.GetTargetPath(_subPath); string backupPath = _directoryPatcher.GetBackupPath(_subPath); Logger.Instance.Write($"RemoveAction - {targetPath} - {backupPath}"); // Deletes or moves the file to backupPath, if it exists if (File.Exists(targetPath)) { if (_needsBackup) { // Backup file Directory.CreateDirectory(Path.GetDirectoryName(backupPath)); File.Move(targetPath, backupPath); } else { // Delete file File.Delete(targetPath); } } // We're done; return CompletedTask return(TaskExtensions.CompletedTask); }
public async Task Execute() { string tempPath = DirectoryPatcher.GetTempPath(SubPath); string newPath = DirectoryPatcher.PatchSource.GetSystemPath(PatchSubPath); string targetPath = DirectoryPatcher.GetTargetPath(SubPath); string backupPath = DirectoryPatcher.GetBackupPath(SubPath); // Ensure the temp directory exists, and decompress the file Directory.CreateDirectory(Path.GetDirectoryName(tempPath)); await DirectoryPatcher.FilePatcher.DecompressAsync(tempPath, newPath); // Extract to a temp location, so that after copying, swapping the old and new file is a quick operation (i.e. not likely to cause inconsistency when interrupted). Copying is also necessary because the file may be shared (moving is not allowed). // Get the old file out of the way, if it exists if (File.Exists(targetPath)) { if (NeedsBackup) { Directory.CreateDirectory(Path.GetDirectoryName(backupPath)); File.Move(targetPath, backupPath); } else { File.Delete(targetPath); } } // Move the new file into place Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); File.Move(tempPath, targetPath); }
public Task ExecuteAsync() { string targetPath = _directoryPatcher.GetTargetPath(_subPath); string backupPath = _directoryPatcher.GetBackupPath(_subPath); if (File.Exists(targetPath)) { if (_needsBackup) { Directory.CreateDirectory(Path.GetDirectoryName(backupPath)); File.Move(targetPath, backupPath); } else { File.Delete(targetPath); } } return(TaskExtensions.CompletedTask); }
public Task Execute() { string targetPath = DirectoryPatcher.GetTargetPath(SubPath); string backupPath = DirectoryPatcher.GetBackupPath(SubPath); // Deletes or moves the file to backupPath, if it exists if (File.Exists(targetPath)) { if (NeedsBackup) { // Backup file Directory.CreateDirectory(Path.GetDirectoryName(backupPath)); File.Move(targetPath, backupPath); } else { // Delete file File.Delete(targetPath); } } // We're done; return CompletedTask return(TaskExtensions.CompletedTask); }