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.

50 lines
1.6 KiB

1 year ago
  1. using System.Linq;
  2. using System.Runtime.InteropServices;
  3. using System.Threading.Tasks;
  4. using System.Windows.Forms;
  5. using TrustedUninstaller.Shared.Tasks;
  6. namespace TrustedUninstaller.Shared.Actions
  7. {
  8. class LanguageAction : ITaskAction
  9. {
  10. public int ProgressWeight { get; set; } = 1;
  11. public int GetProgressWeight() => ProgressWeight;
  12. private bool InProgress { get; set; }
  13. public void ResetProgress() => InProgress = false;
  14. public string Tag { get; set; } = "";
  15. public string Primary() => "for language " + Tag;
  16. public bool Display { get; set; } = false;
  17. public string ErrorString() => $"LanguageAction failed to install language {Tag}.";
  18. [DllImport("intl.cpl", CharSet = CharSet.Unicode, SetLastError = true)]
  19. public static extern int IntlUpdateSystemLocale(string LocaleName, int dwFlags);
  20. public UninstallTaskStatus GetStatus() =>
  21. InputLanguage.InstalledInputLanguages.Cast<InputLanguage>()
  22. .Any(c => c.Culture.IetfLanguageTag == this.Tag)
  23. ? UninstallTaskStatus.Completed
  24. : UninstallTaskStatus.ToDo;
  25. public async Task<bool> RunTask()
  26. {
  27. if (GetStatus() != UninstallTaskStatus.ToDo)
  28. {
  29. return false;
  30. }
  31. if (this.Display)
  32. {
  33. // Reversed from the Set-WinSystemLocale cmdlet...
  34. // TODO: Figure out the return value lol
  35. IntlUpdateSystemLocale(this.Tag, 2);
  36. }
  37. // TODO: Installing languages is AIDS
  38. return false;
  39. }
  40. }
  41. }