StartupPreviewForm.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Windows.Forms;
  6. namespace Optimizer
  7. {
  8. public sealed partial class StartupPreviewForm : Form
  9. {
  10. string _token = string.Empty;
  11. public StartupPreviewForm(List<BackupStartupItem> items)
  12. {
  13. InitializeComponent();
  14. CheckForIllegalCrossThreadCalls = false;
  15. OptionsHelper.ApplyTheme(this);
  16. // translate UI elements
  17. if (OptionsHelper.CurrentOptions.LanguageCode != LanguageCode.EN) Translate();
  18. foreach (BackupStartupItem x in items)
  19. {
  20. if (File.Exists(SanitizePath(x.FileLocation)))
  21. {
  22. _token = "[✓] ";
  23. }
  24. else
  25. {
  26. _token = "[⚠] ";
  27. }
  28. listPreview.Items.Add(_token + x.Name + " - " + x.FileLocation);
  29. }
  30. }
  31. private void Translate()
  32. {
  33. this.Text = OptionsHelper.TranslationList["StartupPreviewForm"];
  34. Dictionary<string, string> translationList = OptionsHelper.TranslationList.ToObject<Dictionary<string, string>>();
  35. Control element;
  36. foreach (var x in translationList)
  37. {
  38. if (x.Key == null || x.Key == string.Empty) continue;
  39. element = this.Controls.Find(x.Key, true).FirstOrDefault();
  40. if (element == null) continue;
  41. element.Text = x.Value;
  42. }
  43. }
  44. private void StartupPreviewForm_Load(object sender, EventArgs e)
  45. {
  46. this.Focus();
  47. }
  48. private string SanitizePath(string s)
  49. {
  50. s = s.Replace("\"", string.Empty);
  51. int i;
  52. while (s.Contains("/"))
  53. {
  54. i = s.LastIndexOf("/");
  55. s = s.Substring(0, i);
  56. }
  57. i = s.IndexOf(".exe");
  58. s = s.Substring(0, i + 4);
  59. return s.Trim();
  60. }
  61. }
  62. }