StartupPreviewForm.cs 2.1 KB

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