CLI tool for running Playbooks
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.8 KiB

1 year ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using TrustedUninstaller.Shared.Tasks;
  7. using YamlDotNet.Serialization;
  8. namespace TrustedUninstaller.Shared.Actions
  9. {
  10. internal class UpdateAction : ITaskAction
  11. {
  12. [YamlMember(typeof(string), Alias = "name")]
  13. public string PackageName { get; set; }
  14. [YamlMember(typeof(string), Alias = "weight")]
  15. public int ProgressWeight { get; set; } = 1;
  16. public int GetProgressWeight() => ProgressWeight;
  17. private bool InProgress { get; set; }
  18. public void ResetProgress() => InProgress = false;
  19. public string ErrorString() => $"UpdateAction failed to remove update package {PackageName}.";
  20. public UninstallTaskStatus GetStatus()
  21. {
  22. if (InProgress)
  23. {
  24. return UninstallTaskStatus.InProgress;
  25. }
  26. return UninstallTaskStatus.Completed;
  27. }
  28. public async Task<bool> RunTask()
  29. {
  30. if (InProgress)
  31. {
  32. Console.WriteLine("An update action is already in progress...");
  33. return false;
  34. }
  35. InProgress = true;
  36. Console.WriteLine($"Removing update package '{PackageName}'...");
  37. CmdAction removeUpdate = new CmdAction()
  38. {
  39. Command = @$"DISM.exe /Online /Remove-Package /PackageName:{PackageName} /quiet /norestart"
  40. };
  41. while(removeUpdate.GetStatus() != UninstallTaskStatus.Completed)
  42. {
  43. await removeUpdate.RunTask();
  44. }
  45. InProgress = false;
  46. return true;
  47. }
  48. }
  49. }