StartupPreviewForm.cs 1.9 KB

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