diff --git a/Universal x86 Tuning Utility/App.xaml.cs b/Universal x86 Tuning Utility/App.xaml.cs index 57460f6..63d8c58 100644 --- a/Universal x86 Tuning Utility/App.xaml.cs +++ b/Universal x86 Tuning Utility/App.xaml.cs @@ -55,13 +55,6 @@ public static T GetService() return _host.Services.GetService(typeof(T)) as T; } - public static bool IsAdministrator() - { - WindowsIdentity identity = WindowsIdentity.GetCurrent(); - WindowsPrincipal principal = new WindowsPrincipal(identity); - return principal.IsInRole(WindowsBuiltInRole.Administrator); - } - public static string version = "2.2.10"; private Mutex mutex; private const string MutexName = "UniversalX86TuningUtility"; @@ -86,178 +79,164 @@ private async void OnStartup(object sender, StartupEventArgs e) try { - if (!App.IsAdministrator()) + try { - // Restart and run as admin - var exeName = Process.GetCurrentProcess().MainModule.FileName; - ProcessStartInfo startInfo = new ProcessStartInfo(exeName); - startInfo.Verb = "runas"; - startInfo.UseShellExecute = true; - startInfo.Arguments = "restart"; - Process.Start(startInfo); - Environment.Exit(0); + await Task.Run(() => product = GetSystemInfo.Product); + Display.setUpLists(); } - else + catch (Exception ex) { - try + Log.Logger.Error(ex, "Failed to setup product and display refresh rates"); + } + + _host = Host + .CreateDefaultBuilder() + .ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)); }) + .ConfigureLogging(logging => { - await Task.Run(() => product = GetSystemInfo.Product); - Display.setUpLists(); - } - catch (Exception ex) + logging.ClearProviders(); + logging.AddSerilog(); + }) + .ConfigureServices((context, services) => { - Log.Logger.Error(ex, "Failed to setup product and display refresh rates"); - } - - _host = Host - .CreateDefaultBuilder() - .ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)); }) - .ConfigureLogging(logging => - { - logging.ClearProviders(); - logging.AddSerilog(); - }) - .ConfigureServices((context, services) => - { - // App Host - services.AddHostedService(); + // App Host + services.AddHostedService(); - // Page resolver service - services.AddSingleton(); + // Page resolver service + services.AddSingleton(); - try - { - Settings.Default.isASUS = false; - Settings.Default.Save(); - - if (product.Contains("ROG") || product.Contains("TUF") || product.Contains("Ally") || product.Contains("Flow") || product.ToLower().Contains("vivobook") || product.ToLower().Contains("zenbook")) + try { - wmi = new ASUSWmi(); - - services.AddSingleton(wmi); - services.AddSingleton(); - - Settings.Default.isASUS = true; + Settings.Default.isASUS = false; Settings.Default.Save(); - } - } - catch (Exception ex) - { - Log.Logger.Error(ex, "Failed to setup ASUS WMI services"); - } - // Theme manipulation - services.AddSingleton(); - - // TaskBar manipulation - services.AddSingleton(); - - // Service containing navigation, same as INavigationWindow... but without window - services.AddSingleton(); - - // Main window with navigation - services.AddScoped(); - services.AddScoped(); - - // Views and ViewModels - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - - // Configuration - services.Configure(context.Configuration.GetSection(nameof(AppConfig))); - }).Build(); - - _logger = _host.Services.GetRequiredService>(); - - _ = Tablet.TabletDevices; - bool firstBoot = false; - try - { - if (Settings.Default.SettingsUpgradeRequired) - { - try + if (product.Contains("ROG") || product.Contains("TUF") || product.Contains("Ally") || product.Contains("Flow") || product.ToLower().Contains("vivobook") || product.ToLower().Contains("zenbook")) { - Settings.Default.Upgrade(); - Settings.Default.SettingsUpgradeRequired = false; + wmi = new ASUSWmi(); + + services.AddSingleton(wmi); + services.AddSingleton(); + + Settings.Default.isASUS = true; Settings.Default.Save(); } - catch (Exception ex) - { - _logger.LogError(ex, "Failed to update settings on startup"); - } + } + catch (Exception ex) + { + Log.Logger.Error(ex, "Failed to setup ASUS WMI services"); } - firstBoot = Settings.Default.FirstBoot; - } - catch (ConfigurationErrorsException ex) - { - string filename = ((ConfigurationErrorsException)ex.InnerException).Filename; - File.Delete(filename); - Settings.Default.Reload(); - } - - bool createdNew; - mutex = new Mutex(true, MutexName, out createdNew); - - if (!createdNew) - { - _logger.LogWarning("Failed to start app, as there is already running uxtu instance. Shutting down"); - MessageBox.Show("An instance of Universal x86 Tuning Utility is already open!", "Error starting Universal x86 Tuning Utility"); - // Close the new instance - Shutdown(); - return; - } - - if (File.Exists("C:\\Universal.x86.Tuning.Utility.V2.msi")) File.Delete("C:\\Universal.x86.Tuning.Utility.V2.msi"); - - Family.setCpuFamily(); - Family.setCpuFamily(); - string path = System.Reflection.Assembly.GetEntryAssembly().Location; - path = path.Replace("Universal x86 Tuning Utility.dll", null); - - if (firstBoot || Settings.Default.Path != path) + // Theme manipulation + services.AddSingleton(); + + // TaskBar manipulation + services.AddSingleton(); + + // Service containing navigation, same as INavigationWindow... but without window + services.AddSingleton(); + + // Main window with navigation + services.AddScoped(); + services.AddScoped(); + + // Views and ViewModels + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + + // Configuration + services.Configure(context.Configuration.GetSection(nameof(AppConfig))); + }).Build(); + + _logger = _host.Services.GetRequiredService>(); + + _ = Tablet.TabletDevices; + bool firstBoot = false; + try + { + if (Settings.Default.SettingsUpgradeRequired) { - Settings.Default.Path = path; - Settings.Default.FirstBoot = false; - if (Family.FAM > Family.RyzenFamily.Rembrandt || Family.FAM == Family.RyzenFamily.Mendocino) Settings.Default.polling = 3; - Settings.Default.Save(); - - //PowerPlans.SetPowerValue("scheme_current", "sub_processor", "PERFAUTONOMOUS", 1, true); - //PowerPlans.SetPowerValue("scheme_current", "sub_processor", "PERFAUTONOMOUS", 1, false); - //PowerPlans.SetPowerValue("scheme_current", "sub_processor", "PERFEPP", 50, true); - //PowerPlans.SetPowerValue("scheme_current", "sub_processor", "PERFEPP", 50, false); - //PowerPlans.SetPowerValue("scheme_current", "sub_processor", "PERFEPP1", 50, true); - //PowerPlans.SetPowerValue("scheme_current", "sub_processor", "PERFEPP1", 50, false); - try { - await Task.Run(() => UnblockFilesInDirectory(path)); + Settings.Default.Upgrade(); + Settings.Default.SettingsUpgradeRequired = false; + Settings.Default.Save(); } catch (Exception ex) { - _logger.LogError(ex, "Failed to unblock files in {dir} directory", path); + _logger.LogError(ex, "Failed to update settings on startup"); } } - if (IsInternetAvailable()) if (Settings.Default.UpdateCheck) CheckForUpdate(); + firstBoot = Settings.Default.FirstBoot; + } + catch (ConfigurationErrorsException ex) + { + string filename = ((ConfigurationErrorsException)ex.InnerException).Filename; + File.Delete(filename); + Settings.Default.Reload(); + } - await _host.StartAsync(); + bool createdNew; + mutex = new Mutex(true, MutexName, out createdNew); - await Task.Run(() => Game_Manager.installedGames = Game_Manager.syncGame_Library()); + if (!createdNew) + { + _logger.LogWarning("Failed to start app, as there is already running uxtu instance. Shutting down"); + MessageBox.Show("An instance of Universal x86 Tuning Utility is already open!", "Error starting Universal x86 Tuning Utility"); + // Close the new instance + Shutdown(); + return; + } + + if (File.Exists("C:\\Universal.x86.Tuning.Utility.V2.msi")) File.Delete("C:\\Universal.x86.Tuning.Utility.V2.msi"); + + Family.setCpuFamily(); + Family.setCpuFamily(); + string path = System.Reflection.Assembly.GetEntryAssembly().Location; + path = path.Replace("Universal x86 Tuning Utility.dll", null); + + if (firstBoot || Settings.Default.Path != path) + { + Settings.Default.Path = path; + Settings.Default.FirstBoot = false; + if (Family.FAM > Family.RyzenFamily.Rembrandt || Family.FAM == Family.RyzenFamily.Mendocino) Settings.Default.polling = 3; + Settings.Default.Save(); + + //PowerPlans.SetPowerValue("scheme_current", "sub_processor", "PERFAUTONOMOUS", 1, true); + //PowerPlans.SetPowerValue("scheme_current", "sub_processor", "PERFAUTONOMOUS", 1, false); + //PowerPlans.SetPowerValue("scheme_current", "sub_processor", "PERFEPP", 50, true); + //PowerPlans.SetPowerValue("scheme_current", "sub_processor", "PERFEPP", 50, false); + //PowerPlans.SetPowerValue("scheme_current", "sub_processor", "PERFEPP1", 50, true); + //PowerPlans.SetPowerValue("scheme_current", "sub_processor", "PERFEPP1", 50, false); + + try + { + await Task.Run(() => UnblockFilesInDirectory(path)); + } + catch (Exception ex) + { + _logger.LogError(ex, "Failed to unblock files in {dir} directory", path); + } } + + if (IsInternetAvailable()) if (Settings.Default.UpdateCheck) CheckForUpdate(); + + await _host.StartAsync(); + + await Task.Run(() => Game_Manager.installedGames = Game_Manager.syncGame_Library()); } catch (Exception ex) { diff --git a/Universal x86 Tuning Utility/app.manifest b/Universal x86 Tuning Utility/app.manifest index a98c943..78e7008 100644 --- a/Universal x86 Tuning Utility/app.manifest +++ b/Universal x86 Tuning Utility/app.manifest @@ -16,7 +16,7 @@ Remove this element if your application requires this virtualization for backwards compatibility. --> - +