Program.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using System.Windows.Forms;
  6. using System.Security.Principal;
  7. using Microsoft.Win32;
  8. using System.IO;
  9. using System.Security.Cryptography;
  10. using System.Reflection;
  11. namespace Optimizer
  12. {
  13. static class Program
  14. {
  15. /* VERSION PROPERTIES */
  16. /* DO NOT LEAVE THEM EMPTY */
  17. // Enter current version here
  18. internal readonly static float Major = 3;
  19. internal readonly static float Minor = 7;
  20. internal static string GetCurrentVersion()
  21. {
  22. return Major.ToString() + "." + Minor.ToString();
  23. }
  24. /* END OF VERSION PROPERTIES */
  25. internal static MainForm MainForm;
  26. readonly static string _adminMissingMessage = "Optimizer needs to be run as administrator!\nApp will now close...";
  27. readonly static string _unsupportedMessage = "Optimizer works in Windows 7 or higher!\nApp will now close...";
  28. [STAThread]
  29. static void Main()
  30. {
  31. Application.EnableVisualStyles();
  32. Application.SetCompatibleTextRenderingDefault(false);
  33. if (!Utilities.IsAdmin())
  34. {
  35. HelperForm f = new HelperForm(null, MessageType.Error, _adminMissingMessage);
  36. f.ShowDialog();
  37. Application.Exit();
  38. }
  39. else
  40. {
  41. if (Utilities.IsCompatible())
  42. {
  43. string resource = "Optimizer.Newtonsoft.Json.dll";
  44. EmbeddedAssembly.Load(resource, "Newtonsoft.Json.dll");
  45. AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
  46. if (!Directory.Exists(Required.CoreFolder))
  47. {
  48. Required.Deploy();
  49. }
  50. // for backward compatibility
  51. if (File.Exists(Options.SettingsFile))
  52. {
  53. if (File.ReadAllText(Options.SettingsFile).Contains("FirstRun"))
  54. {
  55. File.Delete(Options.SettingsFile);
  56. }
  57. }
  58. // load settings, if there is no settings, load defaults
  59. Options.LoadSettings();
  60. Application.Run(new MainForm());
  61. }
  62. else
  63. {
  64. HelperForm f = new HelperForm(null, MessageType.Error, _unsupportedMessage);
  65. f.ShowDialog();
  66. Application.Exit();
  67. }
  68. }
  69. }
  70. static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
  71. {
  72. return EmbeddedAssembly.Get(args.Name);
  73. }
  74. }
  75. }