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.

62 lines
1.9 KiB

1 year ago
10 months ago
1 year ago
6 months ago
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 : TaskAction, ITaskAction
  11. {
  12. public void RunTaskOnMainThread() { throw new NotImplementedException(); }
  13. [YamlMember(typeof(string), Alias = "name")]
  14. public string PackageName { get; set; }
  15. [YamlMember(typeof(string), Alias = "weight")]
  16. public int ProgressWeight { get; set; } = 1;
  17. public int GetProgressWeight() => ProgressWeight;
  18. private bool InProgress { get; set; }
  19. public void ResetProgress() => InProgress = false;
  20. public string ErrorString() => $"UpdateAction failed to remove update package {PackageName}.";
  21. public UninstallTaskStatus GetStatus()
  22. {
  23. if (InProgress)
  24. {
  25. return UninstallTaskStatus.InProgress;
  26. }
  27. return UninstallTaskStatus.Completed;
  28. }
  29. public async Task<bool> RunTask()
  30. {
  31. if (InProgress)
  32. {
  33. Console.WriteLine("An update action is already in progress...");
  34. return false;
  35. }
  36. InProgress = true;
  37. Console.WriteLine($"Removing update package '{PackageName}'...");
  38. CmdAction removeUpdate = new CmdAction()
  39. {
  40. Command = @$"DISM.exe /Online /Remove-Package /PackageName:{PackageName} /quiet /norestart"
  41. };
  42. while(removeUpdate.GetStatus() != UninstallTaskStatus.Completed)
  43. {
  44. await removeUpdate.RunTask();
  45. }
  46. InProgress = false;
  47. return true;
  48. }
  49. }
  50. }