Program.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 = 4;
  19. internal readonly static float Minor = 3;
  20. internal static string GetCurrentVersionTostring()
  21. {
  22. return Major.ToString() + "." + Minor.ToString();
  23. }
  24. internal static float GetCurrentVersion()
  25. {
  26. return float.Parse(GetCurrentVersionTostring());
  27. }
  28. /* END OF VERSION PROPERTIES */
  29. internal static MainForm MainForm;
  30. readonly static string _adminMissingMessage = "Optimizer needs to be run as administrator!\nApp will now close...";
  31. readonly static string _unsupportedMessage = "Optimizer works in Windows 7 or higher!\nApp will now close...";
  32. [STAThread]
  33. static void Main()
  34. {
  35. Application.EnableVisualStyles();
  36. Application.SetCompatibleTextRenderingDefault(false);
  37. if (!Utilities.IsAdmin())
  38. {
  39. HelperForm f = new HelperForm(null, MessageType.Error, _adminMissingMessage);
  40. f.ShowDialog();
  41. Application.Exit();
  42. }
  43. else
  44. {
  45. if (Utilities.IsCompatible())
  46. {
  47. string resource = "Optimizer.Newtonsoft.Json.dll";
  48. EmbeddedAssembly.Load(resource, "Newtonsoft.Json.dll");
  49. AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
  50. if (!Directory.Exists(Required.CoreFolder))
  51. {
  52. Required.Deploy();
  53. }
  54. // for backward compatibility
  55. if (File.Exists(Options.SettingsFile))
  56. {
  57. if (File.ReadAllText(Options.SettingsFile).Contains("FirstRun"))
  58. {
  59. File.Delete(Options.SettingsFile);
  60. }
  61. }
  62. // load settings, if there is no settings, load defaults
  63. Options.LoadSettings();
  64. Application.Run(new MainForm());
  65. }
  66. else
  67. {
  68. HelperForm f = new HelperForm(null, MessageType.Error, _unsupportedMessage);
  69. f.ShowDialog();
  70. Application.Exit();
  71. }
  72. }
  73. }
  74. static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
  75. {
  76. return EmbeddedAssembly.Get(args.Name);
  77. }
  78. }
  79. }