Skip to content

Commit

Permalink
Code refactor
Browse files Browse the repository at this point in the history
69 files changed
e
  • Loading branch information
Lamparter committed Nov 16, 2024
1 parent b14f9a6 commit 66b2c32
Show file tree
Hide file tree
Showing 69 changed files with 2,594 additions and 2,990 deletions.
43 changes: 21 additions & 22 deletions About/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,31 @@
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace Rebound.About
namespace Rebound.About;

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public partial class App : Application
public App()
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
}

/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
m_window = new MainWindow();
m_window.Activate();
}
this.InitializeComponent();
}

private Window m_window;
/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
m_window = new MainWindow();
m_window.Activate();
}

private Window m_window;
}
208 changes: 99 additions & 109 deletions About/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,143 +6,134 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
using Microsoft.Win32;
using Windows.ApplicationModel.DataTransfer;
using WinUIEx;

namespace Rebound.About
namespace Rebound.About;

public sealed partial class MainWindow : WindowEx
{
public sealed partial class MainWindow : WindowEx
public MainWindow()
{
public MainWindow()
{
this.InitializeComponent();
this.AppWindow.DefaultTitleBarShouldMatchAppModeTheme = true;
this.IsMaximizable = false;
this.IsMinimizable = false;
this.MinWidth = 650;
this.MoveAndResize(25, 25, 650, 690);
this.Title = "About Windows";
this.IsResizable = false;
this.SystemBackdrop = new MicaBackdrop();
this.SetIcon($"{AppContext.BaseDirectory}\\Assets\\Rebound.ico");
User.Text = GetCurrentUserName();
Version.Text = GetDetailedWindowsVersion();
LegalStuff.Text = GetLegalInfo();
Load();
}
this.InitializeComponent();
AppWindow.DefaultTitleBarShouldMatchAppModeTheme = true;
IsMaximizable = false;
IsMinimizable = false;
MinWidth = 650;
this.MoveAndResize(25, 25, 650, 690);
Title = "About Windows";
IsResizable = false;
SystemBackdrop = new MicaBackdrop();
this.SetIcon($"{AppContext.BaseDirectory}\\Assets\\Rebound.ico");
User.Text = GetCurrentUserName();
Version.Text = GetDetailedWindowsVersion();
LegalStuff.Text = GetLegalInfo();
Load();
}

public async void Load()
{
await Task.Delay(100);
public async void Load()
{
await Task.Delay(100);

this.SetWindowSize(WinverPanel.ActualWidth + 60, 690);
}
this.SetWindowSize(WinverPanel.ActualWidth + 60, 690);
}

public static string GetDetailedWindowsVersion()
public static string GetDetailedWindowsVersion()
{
try
{
try
// Open the registry key
using var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
if (key != null)
{
// Open the registry key
using (var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion"))
{
if (key != null)
{
// Retrieve build number and revision
var versionName = key.GetValue("DisplayVersion", "Unknown") as string;
var buildNumber = key.GetValue("CurrentBuildNumber", "Unknown") as string;
var buildLab = key.GetValue("UBR", "Unknown");

return $"Version {versionName} (OS Build {buildNumber}.{buildLab})";
}
}
}
catch (Exception ex)
{
return $"Error retrieving OS version details: {ex.Message}";
}
// Retrieve build number and revision
var versionName = key.GetValue("DisplayVersion", "Unknown") as string;
var buildNumber = key.GetValue("CurrentBuildNumber", "Unknown") as string;
var buildLab = key.GetValue("UBR", "Unknown");

return "Registry key not found";
return $"Version {versionName} (OS Build {buildNumber}.{buildLab})";
}
}
catch (Exception ex)
{
return $"Error retrieving OS version details: {ex.Message}";
}

public string GetLegalInfo()
return "Registry key not found";
}

public string GetLegalInfo()
{
try
{
try
{
var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem");
var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem");

foreach (ManagementObject os in searcher.Get().Cast<ManagementObject>())
{
var caption = os["Caption"];
var version = os["Version"];
var buildNumber = os["BuildNumber"];
foreach (var os in searcher.Get().Cast<ManagementObject>())
{
var caption = os["Caption"];
var version = os["Version"];
var buildNumber = os["BuildNumber"];

if (caption.ToString().Contains("10")) windowsVer = "Windows 10";
else windowsVer = "Windows 11";
windowsVer = caption.ToString().Contains("10") ? "Windows 10" : "Windows 11";

WindowsVer.Text = caption.ToString().Replace("Microsoft ", "");
WindowsVer.Text = caption.ToString().Replace("Microsoft ", "");

return $"The {caption.ToString().Replace("Microsoft ", "")} operating system and its user interface are protected by trademark and other pending or existing intellectual property rights in the United States and other countries/regions.";
}
return $"The {caption.ToString().Replace("Microsoft ", "")} operating system and its user interface are protected by trademark and other pending or existing intellectual property rights in the United States and other countries/regions.";
}
catch (Exception ex)
{
return $"Error retrieving OS edition details: {ex.Message}";
}

return "WMI query returned no results";
}
catch (Exception ex)
{
return $"Error retrieving OS edition details: {ex.Message}";
}

return "WMI query returned no results";
}

public static string GetCurrentUserName()
public static string GetCurrentUserName()
{
try
{
try
// Open the registry key
using var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
if (key != null)
{
// Open the registry key
using (var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion"))
{
if (key != null)
{
// Retrieve current username
var owner = key.GetValue("RegisteredOwner", "Unknown") as string;

return owner;
}
}
}
catch (Exception ex)
{
return $"Error retrieving OS version details: {ex.Message}";
}
// Retrieve current username
var owner = key.GetValue("RegisteredOwner", "Unknown") as string;

return "Registry key not found";
return owner;
}
}
catch (Exception ex)
{
return $"Error retrieving OS version details: {ex.Message}";
}

private async void Button_Click(object sender, RoutedEventArgs e)
return "Registry key not found";
}

private async void Button_Click(object sender, RoutedEventArgs e)
{
var info = new ProcessStartInfo()
{
var info = new ProcessStartInfo()
{
FileName = "powershell",
Arguments = "winver",
UseShellExecute = false,
CreateNoWindow = true
};
FileName = "powershell",
Arguments = "winver",
UseShellExecute = false,
CreateNoWindow = true
};

var proc = Process.Start(info);
var proc = Process.Start(info);

await proc.WaitForExitAsync();
await proc.WaitForExitAsync();

Close();
}
Close();
}

private void Button_Click_1(object sender, RoutedEventArgs e)
{
Close();
}
private void Button_Click_1(object sender, RoutedEventArgs e) => Close();

string windowsVer = "Windows";
private string windowsVer = "Windows";

private void Button_Click_2(object sender, RoutedEventArgs e)
{
string content = $@"==========================
private void Button_Click_2(object sender, RoutedEventArgs e)
{
var content = $@"==========================
---Microsoft {windowsVer}---
==========================
Expand All @@ -160,9 +151,8 @@ This product is licensed under the [Microsoft Software License Terms] (https://s
{ReboundVer.Text}
Rebound 11 is a Windows mod that does not interfere with the system. The current Windows installation contains additional apps to run Rebound 11.";
var package = new DataPackage();
package.SetText(content);
Clipboard.SetContent(package);
}
var package = new DataPackage();
package.SetText(content);
Clipboard.SetContent(package);
}
}
53 changes: 26 additions & 27 deletions Cleanup/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,39 @@
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace Rebound.Cleanup
namespace Rebound.Cleanup;

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public partial class App : Application
public App()
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
}
this.InitializeComponent();
}

/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override async void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
string commandArgs = string.Join(" ", Environment.GetCommandLineArgs().Skip(1));
/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected async override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
var commandArgs = string.Join(" ", Environment.GetCommandLineArgs().Skip(1));

m_window = new MainWindow(commandArgs);
m_window.Activate();
m_window = new MainWindow(commandArgs);
m_window.Activate();

if (string.IsNullOrEmpty(commandArgs) != true)
{
await Task.Delay(100);
await (m_window as MainWindow).ArgumentsLaunch(commandArgs.Substring(0, 2));
}
if (string.IsNullOrEmpty(commandArgs) != true)
{
await Task.Delay(100);
await (m_window as MainWindow).ArgumentsLaunch(commandArgs[..2]);
}

private Window m_window;
}

private Window m_window;
}
Loading

0 comments on commit 66b2c32

Please sign in to comment.