HelperForm.cs 2.5 KB

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