Şu c# kodlarımda Spectre.Console kullanarak daha güzel görünmesini sağla using System;…
- User
Şu c# kodlarımda Spectre.Console kullanarak daha güzel görünmesini sağla using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.Win32; using SophiApp.Helpers;
namespace QuickOptimizer { internal class Program { static void Main(string[] args) { Console.WriteLine(" ┌────────────────────────────────────────────────────────────────────────────────────┐"); Console.WriteLine(" │ QuickOptimizer │ Version : v1.0 │ Developer ShadesOfDeath │"); Console.WriteLine(" └──────────────────────────────────────────────────────────────────────────────────────┘"); Console.WriteLine(""); Console.WriteLine("► Activating the Old Context Menu.."); Thread.Sleep(1000); RegHelper.SetValue(RegistryHive.CurrentUser, @"Software\Classes\CLSID{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32", "", "", RegistryValueKind.String); Console.WriteLine("► Disabling Superfetch.."); Thread.Sleep(1000); RegHelper.SetValue(RegistryHive.LocalMachine, @"SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters", "EnableSuperfetch", 1, RegistryValueKind.DWord); Console.WriteLine("► Disabling System Restore.."); Thread.Sleep(1000); RegHelper.SetValue(RegistryHive.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows NT\SystemRestore", "DisableSR", 1, RegistryValueKind.DWord); Console.WriteLine("► Disabling Fast Startup.."); Thread.Sleep(1000); RegHelper.SetValue(RegistryHive.LocalMachine, @"SYSTEM\CurrentControlSet\Control\Session Manager\Power", "HiberbootEnabled", 0, RegistryValueKind.DWord); Console.WriteLine("► Disabling Modern Standby.."); Thread.Sleep(1000); RegHelper.TryDeleteKey(RegistryHive.LocalMachine, @"SYSTEM\CurrentControlSet\Control\Power", "PlatformAoAcOverride"); Console.WriteLine("► Setting Explorer This PC.."); Thread.Sleep(1000); RegHelper.SetValue(RegistryHive.CurrentUser, @"Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "LaunchTo", 1, RegistryValueKind.DWord); Console.WriteLine("► Disabling AutoPlay.."); Thread.Sleep(1000); RegHelper.SetValue(RegistryHive.CurrentUser, @"Software\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers", "DisableAutoplay", 0, RegistryValueKind.DWord); Console.WriteLine("► Disabling Thumbnail Previews in File Explorer"); Thread.Sleep(1000); RegHelper.SetValue(RegistryHive.CurrentUser, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "IconsOnly", 1, RegistryValueKind.DWord); Console.WriteLine("► Disabing Memory Compression.."); Thread.Sleep(1000); Process.Start(new ProcessStartInfo { FileName = "powershell", Arguments = "Disable-MMAgent -mc", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true }); Console.WriteLine("► Disabling Storage Sense.."); Thread.Sleep(1000); RegHelper.SetValue(RegistryHive.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\StorageSense", "AllowStorageSenseGlobal", 0, RegistryValueKind.DWord); Console.WriteLine("► Disabling Program Compatibility Assistant.."); Thread.Sleep(1000); RegHelper.SetValue(RegistryHive.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\AppCompat", "DisablePCA", 1, RegistryValueKind.DWord); Console.WriteLine("► Disabling Hibernation.."); Thread.Sleep(1000); RegHelper.SetValue(RegistryHive.LocalMachine, @"SYSTEM\CurrentControlSet\Control\Power", "HibernateEnabled", 0, RegistryValueKind.DWord); Console.WriteLine("► Disabling NTFS Last Access Time Stamp.."); Thread.Sleep(1000); RegHelper.SetValue(RegistryHive.LocalMachine, @"SYSTEM\CurrentControlSet\Control\FileSystem", "NtfsDisableLastAccessUpdate", 80000003, RegistryValueKind.DWord); Console.WriteLine("► Disabling Telemetry.."); Thread.Sleep(1000); RegHelper.SetValue(RegistryHive.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\DataCollection", "AllowTelemetry", 0, RegistryValueKind.DWord); Console.WriteLine("► Disabling Advertising ID.."); Thread.Sleep(1000); RegHelper.SetValue(RegistryHive.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\AdvertisingInfo", "DisabledByGroupPolicy", 1, RegistryValueKind.DWord);
} }}
- Assistant
To use
Spectre.Consoleto enhance the appearance of your console application, you need to first add theSpectre.ConsoleNuGet package to your project. You can do this through Visual Studio's NuGet package manager or by running the following command in your package manager console:Install-Package Spectre.ConsoleOnce you have the package installed, you can update your
Programclass to use Spectre.Console's functionality for rendering tables, text with colors, and other more advanced console UI elements. Here's an example of how you might enhance your existing code to useSpectre.Console:using System; using System.Diagnostics; using System.Threading; using Microsoft.Win32; using SophiApp.Helpers; using Spectre.Console; namespace QuickOptimizer { internal class Program { static void Main(string[] args) { AnsiConsole.Write(new Panel("[cyan]QuickOptimizer[/] [grey]Version: v1.0[/] [grey]Developer ShadesOfDeath[/]") .Expand() .SquareBorder()); AnsiConsole.WriteLine(); // Perform optimization tasks with descriptive messages PerformOptimizationTask("Activating the Old Context Menu", () => { RegHelper.SetValue(RegistryHive.CurrentUser, @"Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32", "", "", RegistryValueKind.String); }); PerformOptimizationTask("Disabling Superfetch", () => { RegHelper.SetValue(RegistryHive.LocalMachine, @"SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters", "EnableSuperfetch", 1, RegistryValueKind.DWord); }); // ... Add the rest of your optimization tasks here using the `PerformOptimizationTask` method ... AnsiConsole.WriteLine("Optimization tasks have been completed."); } static void PerformOptimizationTask(string description, Action taskAction) { AnsiConsole.Status() .Start(description, ctx => { ctx.Spinner(Spinner.Known.Dots); ctx.SpinnerStyle(Style.Parse("green")); Thread.Sleep(1000); // Simulate work taskAction.Invoke(); // Perform the actual work ctx.Status($"[green]✓[/] {description}"); }); } } }In this updated code, I've made use of
AnsiConsolefrom Spectre.Console to render a bordered panel title and to handle the status messages for each optimization task in a more visually appealing way with spinners and styles.For each optimization task, I've abstracted the work into a method called
PerformOptimizationTask, which takes a description of the task and anActionthat performs the work. This method uses theStatusclass from Spectre.Console to provide a dynamic spinner and a message to the user while the task is running.Please make sure your
RegHelperclass methods and theProcess.Startlogic runs synchronously or modify thePerformOptimizationTaskappropriately to handle asynchronous code if needed.Remember that to actually see the advanced rendering, you should run your console application in an environment that supports ANSI escape codes, which most modern terminals do.