HelperForm.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows.Forms;
  5. namespace Optimizer {
  6. public sealed partial class HelperForm : System.Windows.Forms.Form {
  7. MainForm _main;
  8. MessageType _type;
  9. private void Confirm() {
  10. if (_type == MessageType.Error) {
  11. this.Close();
  12. }
  13. if (_type == MessageType.Startup) {
  14. _main.RemoveAllStartupItems();
  15. }
  16. if (_type == MessageType.Restart) {
  17. OptionsHelper.SaveSettings();
  18. Utilities.Reboot();
  19. }
  20. if (_type == MessageType.Hosts) {
  21. _main.RemoveAllHostsEntries();
  22. }
  23. if (_type == MessageType.Integrator) {
  24. _main.RemoveAllDesktopItems();
  25. }
  26. }
  27. internal HelperForm(MainForm main, MessageType m, string text) {
  28. InitializeComponent();
  29. OptionsHelper.ApplyTheme(this);
  30. _main = main;
  31. _type = m;
  32. lblMessage.Text = text;
  33. if (_type == MessageType.Error) {
  34. btnNo.Visible = false;
  35. btnYes.Text = OptionsHelper.TranslationList["btnOk"];
  36. this.AcceptButton = btnNo;
  37. this.AcceptButton = btnYes;
  38. this.CancelButton = btnNo;
  39. this.CancelButton = btnYes;
  40. }
  41. // translate UI elements
  42. if (OptionsHelper.CurrentOptions.LanguageCode != LanguageCode.EN) Translate();
  43. }
  44. private void btnNo_Click(object sender, EventArgs e) {
  45. this.Close();
  46. }
  47. private void btnYes_Click(object sender, EventArgs e) {
  48. Confirm();
  49. this.Close();
  50. }
  51. private void Messager_Load(object sender, EventArgs e) {
  52. CheckForIllegalCrossThreadCalls = false;
  53. this.BringToFront();
  54. }
  55. private void Translate() {
  56. Dictionary<string, string> translationList = OptionsHelper.TranslationList.ToObject<Dictionary<string, string>>();
  57. Control element;
  58. foreach (var x in translationList) {
  59. if (x.Key == null || x.Key == string.Empty) continue;
  60. element = this.Controls.Find(x.Key, true).FirstOrDefault();
  61. if (element == null) continue;
  62. element.Text = x.Value;
  63. }
  64. }
  65. }
  66. }