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.

52 lines
1.8 KiB

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