diff --git a/.gitattributes b/.gitattributes index 7bda456..bd5dd49 100644 --- a/.gitattributes +++ b/.gitattributes @@ -57,6 +57,6 @@ #*.PDF diff=astextplain #*.rtf diff=astextplain #*.RTF diff=astextplain -/Rebound11Files/AppPackages/ReboundDefrag.msix filter=lfs diff=lfs merge=lfs -text -D:/Ivirius[[:space:]]Community/Source[[:space:]]Code/Current[[:space:]]Apps/Rebound[[:space:]]Hub/ReboundHub/Rebound11Files/Executables/QuickFullComputerCleanup.exe filter=lfs diff=lfs merge=lfs -text +/Rebound11Files/AppPackages/Rebound.Defrag.msix filter=lfs diff=lfs merge=lfs -text +D:/Ivirius[[:space:]]Community/Source[[:space:]]Code/Current[[:space:]]Apps/Rebound[[:space:]]Hub/Rebound/Rebound11Files/Executables/QuickFullComputerCleanup.exe filter=lfs diff=lfs merge=lfs -text *.msix filter=lfs diff=lfs merge=lfs -text diff --git a/README.md b/.github/README.md similarity index 100% rename from README.md rename to .github/README.md diff --git a/.gitignore b/.gitignore index 5d33332..dbc17f3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,11 @@ ## ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore +# Custom files + +/Rebound/Rebound11Files/Executables/Quick Full Computer Cleanup.exe +/Rebound/Rebound11Files/Executables/QuickFullComputerCleanup.exe + # User-specific files *.rsuser *.suo @@ -361,5 +366,3 @@ MigrationBackup/ # Fody - auto-generated XML schema FodyWeavers.xsd -/ReboundHub/Rebound11Files/Executables/Quick Full Computer Cleanup.exe -/ReboundHub/Rebound11Files/Executables/QuickFullComputerCleanup.exe diff --git a/About/App.xaml b/About/App.xaml new file mode 100644 index 0000000..f9b8d88 --- /dev/null +++ b/About/App.xaml @@ -0,0 +1,16 @@ + + + + + + + + + + + + diff --git a/About/App.xaml.cs b/About/App.xaml.cs new file mode 100644 index 0000000..c5b41a9 --- /dev/null +++ b/About/App.xaml.cs @@ -0,0 +1,50 @@ +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Navigation; +using Microsoft.UI.Xaml.Shapes; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.ApplicationModel; +using Windows.ApplicationModel.Activation; +using Windows.Foundation; +using Windows.Foundation.Collections; + +// 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 +{ + /// + /// Provides application-specific behavior to supplement the default Application class. + /// + public partial class App : Application + { + /// + /// 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(). + /// + public App() + { + this.InitializeComponent(); + } + + /// + /// Invoked when the application is launched. + /// + /// Details about the launch request and process. + protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args) + { + m_window = new MainWindow(); + m_window.Activate(); + } + + private Window m_window; + } +} diff --git a/ReboundHub/Assets/LargeTile.scale-100.png b/About/Assets/LargeTile.scale-100.png similarity index 100% rename from ReboundHub/Assets/LargeTile.scale-100.png rename to About/Assets/LargeTile.scale-100.png diff --git a/ReboundHub/Assets/LargeTile.scale-125.png b/About/Assets/LargeTile.scale-125.png similarity index 100% rename from ReboundHub/Assets/LargeTile.scale-125.png rename to About/Assets/LargeTile.scale-125.png diff --git a/ReboundHub/Assets/LargeTile.scale-150.png b/About/Assets/LargeTile.scale-150.png similarity index 100% rename from ReboundHub/Assets/LargeTile.scale-150.png rename to About/Assets/LargeTile.scale-150.png diff --git a/ReboundHub/Assets/LargeTile.scale-200.png b/About/Assets/LargeTile.scale-200.png similarity index 100% rename from ReboundHub/Assets/LargeTile.scale-200.png rename to About/Assets/LargeTile.scale-200.png diff --git a/ReboundHub/Assets/LargeTile.scale-400.png b/About/Assets/LargeTile.scale-400.png similarity index 100% rename from ReboundHub/Assets/LargeTile.scale-400.png rename to About/Assets/LargeTile.scale-400.png diff --git a/ReboundHub/Assets/LockScreenLogo.scale-200.png b/About/Assets/LockScreenLogo.scale-200.png similarity index 100% rename from ReboundHub/Assets/LockScreenLogo.scale-200.png rename to About/Assets/LockScreenLogo.scale-200.png diff --git a/ReboundHub/Assets/AppIcons/ReboundHub.ico b/About/Assets/Rebound.ico similarity index 100% rename from ReboundHub/Assets/AppIcons/ReboundHub.ico rename to About/Assets/Rebound.ico diff --git a/ReboundHub/Assets/SmallTile.scale-100.png b/About/Assets/SmallTile.scale-100.png similarity index 100% rename from ReboundHub/Assets/SmallTile.scale-100.png rename to About/Assets/SmallTile.scale-100.png diff --git a/ReboundHub/Assets/SmallTile.scale-125.png b/About/Assets/SmallTile.scale-125.png similarity index 100% rename from ReboundHub/Assets/SmallTile.scale-125.png rename to About/Assets/SmallTile.scale-125.png diff --git a/ReboundHub/Assets/SmallTile.scale-150.png b/About/Assets/SmallTile.scale-150.png similarity index 100% rename from ReboundHub/Assets/SmallTile.scale-150.png rename to About/Assets/SmallTile.scale-150.png diff --git a/ReboundHub/Assets/SmallTile.scale-200.png b/About/Assets/SmallTile.scale-200.png similarity index 100% rename from ReboundHub/Assets/SmallTile.scale-200.png rename to About/Assets/SmallTile.scale-200.png diff --git a/ReboundHub/Assets/SmallTile.scale-400.png b/About/Assets/SmallTile.scale-400.png similarity index 100% rename from ReboundHub/Assets/SmallTile.scale-400.png rename to About/Assets/SmallTile.scale-400.png diff --git a/ReboundHub/Assets/SplashScreen.scale-100.png b/About/Assets/SplashScreen.scale-100.png similarity index 100% rename from ReboundHub/Assets/SplashScreen.scale-100.png rename to About/Assets/SplashScreen.scale-100.png diff --git a/ReboundHub/Assets/SplashScreen.scale-125.png b/About/Assets/SplashScreen.scale-125.png similarity index 100% rename from ReboundHub/Assets/SplashScreen.scale-125.png rename to About/Assets/SplashScreen.scale-125.png diff --git a/ReboundHub/Assets/SplashScreen.scale-150.png b/About/Assets/SplashScreen.scale-150.png similarity index 100% rename from ReboundHub/Assets/SplashScreen.scale-150.png rename to About/Assets/SplashScreen.scale-150.png diff --git a/ReboundHub/Assets/SplashScreen.scale-200.png b/About/Assets/SplashScreen.scale-200.png similarity index 100% rename from ReboundHub/Assets/SplashScreen.scale-200.png rename to About/Assets/SplashScreen.scale-200.png diff --git a/ReboundHub/Assets/SplashScreen.scale-400.png b/About/Assets/SplashScreen.scale-400.png similarity index 100% rename from ReboundHub/Assets/SplashScreen.scale-400.png rename to About/Assets/SplashScreen.scale-400.png diff --git a/ReboundHub/Assets/Square150x150Logo.scale-100.png b/About/Assets/Square150x150Logo.scale-100.png similarity index 100% rename from ReboundHub/Assets/Square150x150Logo.scale-100.png rename to About/Assets/Square150x150Logo.scale-100.png diff --git a/ReboundHub/Assets/Square150x150Logo.scale-125.png b/About/Assets/Square150x150Logo.scale-125.png similarity index 100% rename from ReboundHub/Assets/Square150x150Logo.scale-125.png rename to About/Assets/Square150x150Logo.scale-125.png diff --git a/ReboundHub/Assets/Square150x150Logo.scale-150.png b/About/Assets/Square150x150Logo.scale-150.png similarity index 100% rename from ReboundHub/Assets/Square150x150Logo.scale-150.png rename to About/Assets/Square150x150Logo.scale-150.png diff --git a/ReboundHub/Assets/Square150x150Logo.scale-200.png b/About/Assets/Square150x150Logo.scale-200.png similarity index 100% rename from ReboundHub/Assets/Square150x150Logo.scale-200.png rename to About/Assets/Square150x150Logo.scale-200.png diff --git a/ReboundHub/Assets/Square150x150Logo.scale-400.png b/About/Assets/Square150x150Logo.scale-400.png similarity index 100% rename from ReboundHub/Assets/Square150x150Logo.scale-400.png rename to About/Assets/Square150x150Logo.scale-400.png diff --git a/ReboundHub/Assets/Square44x44Logo.altform-lightunplated_targetsize-16.png b/About/Assets/Square44x44Logo.altform-lightunplated_targetsize-16.png similarity index 100% rename from ReboundHub/Assets/Square44x44Logo.altform-lightunplated_targetsize-16.png rename to About/Assets/Square44x44Logo.altform-lightunplated_targetsize-16.png diff --git a/ReboundHub/Assets/Square44x44Logo.altform-lightunplated_targetsize-24.png b/About/Assets/Square44x44Logo.altform-lightunplated_targetsize-24.png similarity index 100% rename from ReboundHub/Assets/Square44x44Logo.altform-lightunplated_targetsize-24.png rename to About/Assets/Square44x44Logo.altform-lightunplated_targetsize-24.png diff --git a/ReboundHub/Assets/Square44x44Logo.altform-lightunplated_targetsize-256.png b/About/Assets/Square44x44Logo.altform-lightunplated_targetsize-256.png similarity index 100% rename from ReboundHub/Assets/Square44x44Logo.altform-lightunplated_targetsize-256.png rename to About/Assets/Square44x44Logo.altform-lightunplated_targetsize-256.png diff --git a/ReboundHub/Assets/Square44x44Logo.altform-lightunplated_targetsize-32.png b/About/Assets/Square44x44Logo.altform-lightunplated_targetsize-32.png similarity index 100% rename from ReboundHub/Assets/Square44x44Logo.altform-lightunplated_targetsize-32.png rename to About/Assets/Square44x44Logo.altform-lightunplated_targetsize-32.png diff --git a/ReboundHub/Assets/Square44x44Logo.altform-lightunplated_targetsize-48.png b/About/Assets/Square44x44Logo.altform-lightunplated_targetsize-48.png similarity index 100% rename from ReboundHub/Assets/Square44x44Logo.altform-lightunplated_targetsize-48.png rename to About/Assets/Square44x44Logo.altform-lightunplated_targetsize-48.png diff --git a/ReboundHub/Assets/Square44x44Logo.altform-unplated_targetsize-16.png b/About/Assets/Square44x44Logo.altform-unplated_targetsize-16.png similarity index 100% rename from ReboundHub/Assets/Square44x44Logo.altform-unplated_targetsize-16.png rename to About/Assets/Square44x44Logo.altform-unplated_targetsize-16.png diff --git a/ReboundHub/Assets/Square44x44Logo.altform-unplated_targetsize-256.png b/About/Assets/Square44x44Logo.altform-unplated_targetsize-256.png similarity index 100% rename from ReboundHub/Assets/Square44x44Logo.altform-unplated_targetsize-256.png rename to About/Assets/Square44x44Logo.altform-unplated_targetsize-256.png diff --git a/ReboundHub/Assets/Square44x44Logo.altform-unplated_targetsize-32.png b/About/Assets/Square44x44Logo.altform-unplated_targetsize-32.png similarity index 100% rename from ReboundHub/Assets/Square44x44Logo.altform-unplated_targetsize-32.png rename to About/Assets/Square44x44Logo.altform-unplated_targetsize-32.png diff --git a/ReboundHub/Assets/Square44x44Logo.altform-unplated_targetsize-48.png b/About/Assets/Square44x44Logo.altform-unplated_targetsize-48.png similarity index 100% rename from ReboundHub/Assets/Square44x44Logo.altform-unplated_targetsize-48.png rename to About/Assets/Square44x44Logo.altform-unplated_targetsize-48.png diff --git a/ReboundHub/Assets/Square44x44Logo.scale-100.png b/About/Assets/Square44x44Logo.scale-100.png similarity index 100% rename from ReboundHub/Assets/Square44x44Logo.scale-100.png rename to About/Assets/Square44x44Logo.scale-100.png diff --git a/ReboundHub/Assets/Square44x44Logo.scale-125.png b/About/Assets/Square44x44Logo.scale-125.png similarity index 100% rename from ReboundHub/Assets/Square44x44Logo.scale-125.png rename to About/Assets/Square44x44Logo.scale-125.png diff --git a/ReboundHub/Assets/Square44x44Logo.scale-150.png b/About/Assets/Square44x44Logo.scale-150.png similarity index 100% rename from ReboundHub/Assets/Square44x44Logo.scale-150.png rename to About/Assets/Square44x44Logo.scale-150.png diff --git a/ReboundHub/Assets/Square44x44Logo.scale-200.png b/About/Assets/Square44x44Logo.scale-200.png similarity index 100% rename from ReboundHub/Assets/Square44x44Logo.scale-200.png rename to About/Assets/Square44x44Logo.scale-200.png diff --git a/ReboundHub/Assets/Square44x44Logo.scale-400.png b/About/Assets/Square44x44Logo.scale-400.png similarity index 100% rename from ReboundHub/Assets/Square44x44Logo.scale-400.png rename to About/Assets/Square44x44Logo.scale-400.png diff --git a/ReboundHub/Assets/Square44x44Logo.targetsize-16.png b/About/Assets/Square44x44Logo.targetsize-16.png similarity index 100% rename from ReboundHub/Assets/Square44x44Logo.targetsize-16.png rename to About/Assets/Square44x44Logo.targetsize-16.png diff --git a/ReboundHub/Assets/Square44x44Logo.targetsize-24.png b/About/Assets/Square44x44Logo.targetsize-24.png similarity index 100% rename from ReboundHub/Assets/Square44x44Logo.targetsize-24.png rename to About/Assets/Square44x44Logo.targetsize-24.png diff --git a/ReboundHub/Assets/Square44x44Logo.targetsize-24_altform-unplated.png b/About/Assets/Square44x44Logo.targetsize-24_altform-unplated.png similarity index 100% rename from ReboundHub/Assets/Square44x44Logo.targetsize-24_altform-unplated.png rename to About/Assets/Square44x44Logo.targetsize-24_altform-unplated.png diff --git a/ReboundHub/Assets/Square44x44Logo.targetsize-256.png b/About/Assets/Square44x44Logo.targetsize-256.png similarity index 100% rename from ReboundHub/Assets/Square44x44Logo.targetsize-256.png rename to About/Assets/Square44x44Logo.targetsize-256.png diff --git a/ReboundHub/Assets/Square44x44Logo.targetsize-32.png b/About/Assets/Square44x44Logo.targetsize-32.png similarity index 100% rename from ReboundHub/Assets/Square44x44Logo.targetsize-32.png rename to About/Assets/Square44x44Logo.targetsize-32.png diff --git a/ReboundHub/Assets/Square44x44Logo.targetsize-48.png b/About/Assets/Square44x44Logo.targetsize-48.png similarity index 100% rename from ReboundHub/Assets/Square44x44Logo.targetsize-48.png rename to About/Assets/Square44x44Logo.targetsize-48.png diff --git a/ReboundHub/Assets/StoreLogo.backup.png b/About/Assets/StoreLogo.backup.png similarity index 100% rename from ReboundHub/Assets/StoreLogo.backup.png rename to About/Assets/StoreLogo.backup.png diff --git a/ReboundHub/Assets/StoreLogo.scale-100.png b/About/Assets/StoreLogo.scale-100.png similarity index 100% rename from ReboundHub/Assets/StoreLogo.scale-100.png rename to About/Assets/StoreLogo.scale-100.png diff --git a/ReboundHub/Assets/StoreLogo.scale-125.png b/About/Assets/StoreLogo.scale-125.png similarity index 100% rename from ReboundHub/Assets/StoreLogo.scale-125.png rename to About/Assets/StoreLogo.scale-125.png diff --git a/ReboundHub/Assets/StoreLogo.scale-150.png b/About/Assets/StoreLogo.scale-150.png similarity index 100% rename from ReboundHub/Assets/StoreLogo.scale-150.png rename to About/Assets/StoreLogo.scale-150.png diff --git a/ReboundHub/Assets/StoreLogo.scale-200.png b/About/Assets/StoreLogo.scale-200.png similarity index 100% rename from ReboundHub/Assets/StoreLogo.scale-200.png rename to About/Assets/StoreLogo.scale-200.png diff --git a/ReboundHub/Assets/StoreLogo.scale-400.png b/About/Assets/StoreLogo.scale-400.png similarity index 100% rename from ReboundHub/Assets/StoreLogo.scale-400.png rename to About/Assets/StoreLogo.scale-400.png diff --git a/ReboundHub/Assets/Wide310x150Logo.scale-100.png b/About/Assets/Wide310x150Logo.scale-100.png similarity index 100% rename from ReboundHub/Assets/Wide310x150Logo.scale-100.png rename to About/Assets/Wide310x150Logo.scale-100.png diff --git a/ReboundHub/Assets/Wide310x150Logo.scale-125.png b/About/Assets/Wide310x150Logo.scale-125.png similarity index 100% rename from ReboundHub/Assets/Wide310x150Logo.scale-125.png rename to About/Assets/Wide310x150Logo.scale-125.png diff --git a/ReboundHub/Assets/Wide310x150Logo.scale-150.png b/About/Assets/Wide310x150Logo.scale-150.png similarity index 100% rename from ReboundHub/Assets/Wide310x150Logo.scale-150.png rename to About/Assets/Wide310x150Logo.scale-150.png diff --git a/ReboundHub/Assets/Wide310x150Logo.scale-200.png b/About/Assets/Wide310x150Logo.scale-200.png similarity index 100% rename from ReboundHub/Assets/Wide310x150Logo.scale-200.png rename to About/Assets/Wide310x150Logo.scale-200.png diff --git a/ReboundHub/Assets/Wide310x150Logo.scale-400.png b/About/Assets/Wide310x150Logo.scale-400.png similarity index 100% rename from ReboundHub/Assets/Wide310x150Logo.scale-400.png rename to About/Assets/Wide310x150Logo.scale-400.png diff --git a/About/MainWindow.xaml b/About/MainWindow.xaml new file mode 100644 index 0000000..942c9c9 --- /dev/null +++ b/About/MainWindow.xaml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/About/MainWindow.xaml.cs b/About/MainWindow.xaml.cs new file mode 100644 index 0000000..96c4cbf --- /dev/null +++ b/About/MainWindow.xaml.cs @@ -0,0 +1,168 @@ +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Media; +using Microsoft.Win32; +using System; +using System.Diagnostics; +using System.Linq; +using System.Management; +using System.Threading.Tasks; +using Windows.ApplicationModel.DataTransfer; +using WinUIEx; + +namespace Rebound.About +{ + public sealed partial class MainWindow : WindowEx + { + 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(); + } + + public async void Load() + { + await Task.Delay(100); + + this.SetWindowSize(WinverPanel.ActualWidth + 60, 690); + } + + public static string GetDetailedWindowsVersion() + { + try + { + // 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}"; + } + + return "Registry key not found"; + } + + public string GetLegalInfo() + { + try + { + var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem"); + + foreach (ManagementObject os in searcher.Get().Cast()) + { + 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.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."; + } + } + catch (Exception ex) + { + return $"Error retrieving OS edition details: {ex.Message}"; + } + + return "WMI query returned no results"; + } + + public static string GetCurrentUserName() + { + try + { + // Open the registry key + using (var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion")) + { + if (key != null) + { + // Retrieve build number and revision + var owner = key.GetValue("RegisteredOwner", "Unknown") as string; + + return owner; + } + } + } + catch (Exception ex) + { + return $"Error retrieving OS version details: {ex.Message}"; + } + + return "Registry key not found"; + } + + private async void Button_Click(object sender, RoutedEventArgs e) + { + var info = new ProcessStartInfo() + { + FileName = "powershell", + Arguments = "winver", + UseShellExecute = false, + CreateNoWindow = true + }; + + var proc = Process.Start(info); + + await proc.WaitForExitAsync(); + + Close(); + } + + private void Button_Click_1(object sender, RoutedEventArgs e) + { + Close(); + } + + string windowsVer = "Windows"; + + private void Button_Click_2(object sender, RoutedEventArgs e) + { + string content = $@"========================== +---Microsoft {windowsVer}--- +========================== + +{GetDetailedWindowsVersion()} +� Microsoft Corporation. All rights reserved. + +{GetLegalInfo()} + +This product is licensed under the [Microsoft Software License Terms] (https://support.microsoft.com/en-us/windows/microsoft-software-license-terms-e26eedad-97a2-5250-2670-aad156b654bd) to: {GetCurrentUserName()} + +========================== +--------Rebound 11-------- +========================== + +{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); + } + } +} diff --git a/About/Package.appxmanifest b/About/Package.appxmanifest new file mode 100644 index 0000000..5108d15 --- /dev/null +++ b/About/Package.appxmanifest @@ -0,0 +1,52 @@ + + + + + + + + + + Rebound.About + Lenovo + Assets\StoreLogo.png + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/About/Properties/launchSettings.json b/About/Properties/launchSettings.json new file mode 100644 index 0000000..8e92a6d --- /dev/null +++ b/About/Properties/launchSettings.json @@ -0,0 +1,10 @@ +{ + "profiles": { + "Rebound.About (Package)": { + "commandName": "MsixPackage" + }, + "Rebound.About (Unpackaged)": { + "commandName": "Project" + } + } +} \ No newline at end of file diff --git a/About/Rebound.About.csproj b/About/Rebound.About.csproj new file mode 100644 index 0000000..2482aea --- /dev/null +++ b/About/Rebound.About.csproj @@ -0,0 +1,65 @@ + + + WinExe + net8.0-windows10.0.19041.0 + 10.0.17763.0 + Rebound.About + app.manifest + x86;x64;ARM64 + win-x86;win-x64;win-arm64 + win10-x86;win10-x64;win10-arm64 + win-$(Platform).pubxml + true + true + 10.0.22621.35-preview + True + True + 3A171B4CC25BF8365620669A928F4BF543826E6F + SHA256 + False + False + True + Never + C:/Users/Lenovo/Desktop + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + \ No newline at end of file diff --git a/About/app.manifest b/About/app.manifest new file mode 100644 index 0000000..6e338aa --- /dev/null +++ b/About/app.manifest @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + PerMonitorV2 + + + \ No newline at end of file diff --git a/Cleanup/App.xaml b/Cleanup/App.xaml new file mode 100644 index 0000000..bcef8ed --- /dev/null +++ b/Cleanup/App.xaml @@ -0,0 +1,16 @@ + + + + + + + + + + + + diff --git a/Cleanup/App.xaml.cs b/Cleanup/App.xaml.cs new file mode 100644 index 0000000..69b9f78 --- /dev/null +++ b/Cleanup/App.xaml.cs @@ -0,0 +1,59 @@ +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Navigation; +using Microsoft.UI.Xaml.Shapes; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using System.Threading.Tasks; +using Windows.ApplicationModel; +using Windows.ApplicationModel.Activation; +using Windows.Foundation; +using Windows.Foundation.Collections; + +// 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 +{ + /// + /// Provides application-specific behavior to supplement the default Application class. + /// + public partial class App : Application + { + /// + /// 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(). + /// + public App() + { + this.InitializeComponent(); + } + + /// + /// Invoked when the application is launched. + /// + /// Details about the launch request and process. + protected override async void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args) + { + string commandArgs = string.Join(" ", Environment.GetCommandLineArgs().Skip(1)); + + 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)); + } + } + + private Window m_window; + } +} diff --git a/Cleanup/Assets/DDORes_2001.ico b/Cleanup/Assets/DDORes_2001.ico new file mode 100644 index 0000000..c421be5 Binary files /dev/null and b/Cleanup/Assets/DDORes_2001.ico differ diff --git a/ReboundHub/Assets/AppIcons/EventViewer.png b/Cleanup/Assets/EventViewer.png similarity index 100% rename from ReboundHub/Assets/AppIcons/EventViewer.png rename to Cleanup/Assets/EventViewer.png diff --git a/Cleanup/Assets/LargeTile.scale-100.png b/Cleanup/Assets/LargeTile.scale-100.png new file mode 100644 index 0000000..aec1939 Binary files /dev/null and b/Cleanup/Assets/LargeTile.scale-100.png differ diff --git a/Cleanup/Assets/LargeTile.scale-125.png b/Cleanup/Assets/LargeTile.scale-125.png new file mode 100644 index 0000000..1e8ad5d Binary files /dev/null and b/Cleanup/Assets/LargeTile.scale-125.png differ diff --git a/Cleanup/Assets/LargeTile.scale-150.png b/Cleanup/Assets/LargeTile.scale-150.png new file mode 100644 index 0000000..3016372 Binary files /dev/null and b/Cleanup/Assets/LargeTile.scale-150.png differ diff --git a/Cleanup/Assets/LargeTile.scale-200.png b/Cleanup/Assets/LargeTile.scale-200.png new file mode 100644 index 0000000..016c25d Binary files /dev/null and b/Cleanup/Assets/LargeTile.scale-200.png differ diff --git a/Cleanup/Assets/LargeTile.scale-400.png b/Cleanup/Assets/LargeTile.scale-400.png new file mode 100644 index 0000000..c559409 Binary files /dev/null and b/Cleanup/Assets/LargeTile.scale-400.png differ diff --git a/Cleanup/Assets/LockScreenLogo.scale-200.png b/Cleanup/Assets/LockScreenLogo.scale-200.png new file mode 100644 index 0000000..7440f0d Binary files /dev/null and b/Cleanup/Assets/LockScreenLogo.scale-200.png differ diff --git a/Cleanup/Assets/SmallTile.scale-100.png b/Cleanup/Assets/SmallTile.scale-100.png new file mode 100644 index 0000000..6e9b062 Binary files /dev/null and b/Cleanup/Assets/SmallTile.scale-100.png differ diff --git a/Cleanup/Assets/SmallTile.scale-125.png b/Cleanup/Assets/SmallTile.scale-125.png new file mode 100644 index 0000000..6963c03 Binary files /dev/null and b/Cleanup/Assets/SmallTile.scale-125.png differ diff --git a/Cleanup/Assets/SmallTile.scale-150.png b/Cleanup/Assets/SmallTile.scale-150.png new file mode 100644 index 0000000..5300196 Binary files /dev/null and b/Cleanup/Assets/SmallTile.scale-150.png differ diff --git a/Cleanup/Assets/SmallTile.scale-200.png b/Cleanup/Assets/SmallTile.scale-200.png new file mode 100644 index 0000000..4804b3a Binary files /dev/null and b/Cleanup/Assets/SmallTile.scale-200.png differ diff --git a/Cleanup/Assets/SmallTile.scale-400.png b/Cleanup/Assets/SmallTile.scale-400.png new file mode 100644 index 0000000..d0ca1a8 Binary files /dev/null and b/Cleanup/Assets/SmallTile.scale-400.png differ diff --git a/Cleanup/Assets/SplashScreen.scale-100.png b/Cleanup/Assets/SplashScreen.scale-100.png new file mode 100644 index 0000000..82b5d40 Binary files /dev/null and b/Cleanup/Assets/SplashScreen.scale-100.png differ diff --git a/Cleanup/Assets/SplashScreen.scale-125.png b/Cleanup/Assets/SplashScreen.scale-125.png new file mode 100644 index 0000000..203dfa8 Binary files /dev/null and b/Cleanup/Assets/SplashScreen.scale-125.png differ diff --git a/Cleanup/Assets/SplashScreen.scale-150.png b/Cleanup/Assets/SplashScreen.scale-150.png new file mode 100644 index 0000000..9a255f4 Binary files /dev/null and b/Cleanup/Assets/SplashScreen.scale-150.png differ diff --git a/Cleanup/Assets/SplashScreen.scale-200.png b/Cleanup/Assets/SplashScreen.scale-200.png new file mode 100644 index 0000000..6d07ee9 Binary files /dev/null and b/Cleanup/Assets/SplashScreen.scale-200.png differ diff --git a/Cleanup/Assets/SplashScreen.scale-400.png b/Cleanup/Assets/SplashScreen.scale-400.png new file mode 100644 index 0000000..83df478 Binary files /dev/null and b/Cleanup/Assets/SplashScreen.scale-400.png differ diff --git a/Cleanup/Assets/Square150x150Logo.scale-100.png b/Cleanup/Assets/Square150x150Logo.scale-100.png new file mode 100644 index 0000000..156b041 Binary files /dev/null and b/Cleanup/Assets/Square150x150Logo.scale-100.png differ diff --git a/Cleanup/Assets/Square150x150Logo.scale-125.png b/Cleanup/Assets/Square150x150Logo.scale-125.png new file mode 100644 index 0000000..7afd577 Binary files /dev/null and b/Cleanup/Assets/Square150x150Logo.scale-125.png differ diff --git a/Cleanup/Assets/Square150x150Logo.scale-150.png b/Cleanup/Assets/Square150x150Logo.scale-150.png new file mode 100644 index 0000000..c7e4750 Binary files /dev/null and b/Cleanup/Assets/Square150x150Logo.scale-150.png differ diff --git a/Cleanup/Assets/Square150x150Logo.scale-200.png b/Cleanup/Assets/Square150x150Logo.scale-200.png new file mode 100644 index 0000000..d78f22d Binary files /dev/null and b/Cleanup/Assets/Square150x150Logo.scale-200.png differ diff --git a/Cleanup/Assets/Square150x150Logo.scale-400.png b/Cleanup/Assets/Square150x150Logo.scale-400.png new file mode 100644 index 0000000..8ff9329 Binary files /dev/null and b/Cleanup/Assets/Square150x150Logo.scale-400.png differ diff --git a/Cleanup/Assets/Square44x44Logo.altform-lightunplated_targetsize-16.png b/Cleanup/Assets/Square44x44Logo.altform-lightunplated_targetsize-16.png new file mode 100644 index 0000000..b6bcb7f Binary files /dev/null and b/Cleanup/Assets/Square44x44Logo.altform-lightunplated_targetsize-16.png differ diff --git a/Cleanup/Assets/Square44x44Logo.altform-lightunplated_targetsize-24.png b/Cleanup/Assets/Square44x44Logo.altform-lightunplated_targetsize-24.png new file mode 100644 index 0000000..61a7d8a Binary files /dev/null and b/Cleanup/Assets/Square44x44Logo.altform-lightunplated_targetsize-24.png differ diff --git a/Cleanup/Assets/Square44x44Logo.altform-lightunplated_targetsize-256.png b/Cleanup/Assets/Square44x44Logo.altform-lightunplated_targetsize-256.png new file mode 100644 index 0000000..6d983cb Binary files /dev/null and b/Cleanup/Assets/Square44x44Logo.altform-lightunplated_targetsize-256.png differ diff --git a/Cleanup/Assets/Square44x44Logo.altform-lightunplated_targetsize-32.png b/Cleanup/Assets/Square44x44Logo.altform-lightunplated_targetsize-32.png new file mode 100644 index 0000000..1c989a4 Binary files /dev/null and b/Cleanup/Assets/Square44x44Logo.altform-lightunplated_targetsize-32.png differ diff --git a/Cleanup/Assets/Square44x44Logo.altform-lightunplated_targetsize-48.png b/Cleanup/Assets/Square44x44Logo.altform-lightunplated_targetsize-48.png new file mode 100644 index 0000000..e62ec2f Binary files /dev/null and b/Cleanup/Assets/Square44x44Logo.altform-lightunplated_targetsize-48.png differ diff --git a/Cleanup/Assets/Square44x44Logo.altform-unplated_targetsize-16.png b/Cleanup/Assets/Square44x44Logo.altform-unplated_targetsize-16.png new file mode 100644 index 0000000..b6bcb7f Binary files /dev/null and b/Cleanup/Assets/Square44x44Logo.altform-unplated_targetsize-16.png differ diff --git a/Cleanup/Assets/Square44x44Logo.altform-unplated_targetsize-256.png b/Cleanup/Assets/Square44x44Logo.altform-unplated_targetsize-256.png new file mode 100644 index 0000000..6d983cb Binary files /dev/null and b/Cleanup/Assets/Square44x44Logo.altform-unplated_targetsize-256.png differ diff --git a/Cleanup/Assets/Square44x44Logo.altform-unplated_targetsize-32.png b/Cleanup/Assets/Square44x44Logo.altform-unplated_targetsize-32.png new file mode 100644 index 0000000..1c989a4 Binary files /dev/null and b/Cleanup/Assets/Square44x44Logo.altform-unplated_targetsize-32.png differ diff --git a/Cleanup/Assets/Square44x44Logo.altform-unplated_targetsize-48.png b/Cleanup/Assets/Square44x44Logo.altform-unplated_targetsize-48.png new file mode 100644 index 0000000..e62ec2f Binary files /dev/null and b/Cleanup/Assets/Square44x44Logo.altform-unplated_targetsize-48.png differ diff --git a/Cleanup/Assets/Square44x44Logo.scale-100.png b/Cleanup/Assets/Square44x44Logo.scale-100.png new file mode 100644 index 0000000..85594ab Binary files /dev/null and b/Cleanup/Assets/Square44x44Logo.scale-100.png differ diff --git a/Cleanup/Assets/Square44x44Logo.scale-125.png b/Cleanup/Assets/Square44x44Logo.scale-125.png new file mode 100644 index 0000000..3920f01 Binary files /dev/null and b/Cleanup/Assets/Square44x44Logo.scale-125.png differ diff --git a/Cleanup/Assets/Square44x44Logo.scale-150.png b/Cleanup/Assets/Square44x44Logo.scale-150.png new file mode 100644 index 0000000..0e14d6d Binary files /dev/null and b/Cleanup/Assets/Square44x44Logo.scale-150.png differ diff --git a/Cleanup/Assets/Square44x44Logo.scale-200.png b/Cleanup/Assets/Square44x44Logo.scale-200.png new file mode 100644 index 0000000..081ff6d Binary files /dev/null and b/Cleanup/Assets/Square44x44Logo.scale-200.png differ diff --git a/Cleanup/Assets/Square44x44Logo.scale-400.png b/Cleanup/Assets/Square44x44Logo.scale-400.png new file mode 100644 index 0000000..267d6d3 Binary files /dev/null and b/Cleanup/Assets/Square44x44Logo.scale-400.png differ diff --git a/Cleanup/Assets/Square44x44Logo.targetsize-16.png b/Cleanup/Assets/Square44x44Logo.targetsize-16.png new file mode 100644 index 0000000..d5e23d9 Binary files /dev/null and b/Cleanup/Assets/Square44x44Logo.targetsize-16.png differ diff --git a/Cleanup/Assets/Square44x44Logo.targetsize-24.png b/Cleanup/Assets/Square44x44Logo.targetsize-24.png new file mode 100644 index 0000000..de5bd14 Binary files /dev/null and b/Cleanup/Assets/Square44x44Logo.targetsize-24.png differ diff --git a/Cleanup/Assets/Square44x44Logo.targetsize-24_altform-unplated.png b/Cleanup/Assets/Square44x44Logo.targetsize-24_altform-unplated.png new file mode 100644 index 0000000..61a7d8a Binary files /dev/null and b/Cleanup/Assets/Square44x44Logo.targetsize-24_altform-unplated.png differ diff --git a/Cleanup/Assets/Square44x44Logo.targetsize-256.png b/Cleanup/Assets/Square44x44Logo.targetsize-256.png new file mode 100644 index 0000000..5e29b6e Binary files /dev/null and b/Cleanup/Assets/Square44x44Logo.targetsize-256.png differ diff --git a/Cleanup/Assets/Square44x44Logo.targetsize-32.png b/Cleanup/Assets/Square44x44Logo.targetsize-32.png new file mode 100644 index 0000000..932386c Binary files /dev/null and b/Cleanup/Assets/Square44x44Logo.targetsize-32.png differ diff --git a/Cleanup/Assets/Square44x44Logo.targetsize-48.png b/Cleanup/Assets/Square44x44Logo.targetsize-48.png new file mode 100644 index 0000000..36f4b66 Binary files /dev/null and b/Cleanup/Assets/Square44x44Logo.targetsize-48.png differ diff --git a/Cleanup/Assets/StoreLogo.backup.png b/Cleanup/Assets/StoreLogo.backup.png new file mode 100644 index 0000000..a4586f2 Binary files /dev/null and b/Cleanup/Assets/StoreLogo.backup.png differ diff --git a/Cleanup/Assets/StoreLogo.scale-100.png b/Cleanup/Assets/StoreLogo.scale-100.png new file mode 100644 index 0000000..4c829d4 Binary files /dev/null and b/Cleanup/Assets/StoreLogo.scale-100.png differ diff --git a/Cleanup/Assets/StoreLogo.scale-125.png b/Cleanup/Assets/StoreLogo.scale-125.png new file mode 100644 index 0000000..ed7b937 Binary files /dev/null and b/Cleanup/Assets/StoreLogo.scale-125.png differ diff --git a/Cleanup/Assets/StoreLogo.scale-150.png b/Cleanup/Assets/StoreLogo.scale-150.png new file mode 100644 index 0000000..f25f3ae Binary files /dev/null and b/Cleanup/Assets/StoreLogo.scale-150.png differ diff --git a/Cleanup/Assets/StoreLogo.scale-200.png b/Cleanup/Assets/StoreLogo.scale-200.png new file mode 100644 index 0000000..2d81107 Binary files /dev/null and b/Cleanup/Assets/StoreLogo.scale-200.png differ diff --git a/Cleanup/Assets/StoreLogo.scale-400.png b/Cleanup/Assets/StoreLogo.scale-400.png new file mode 100644 index 0000000..d032954 Binary files /dev/null and b/Cleanup/Assets/StoreLogo.scale-400.png differ diff --git a/Cleanup/Assets/Wide310x150Logo.scale-100.png b/Cleanup/Assets/Wide310x150Logo.scale-100.png new file mode 100644 index 0000000..1d189db Binary files /dev/null and b/Cleanup/Assets/Wide310x150Logo.scale-100.png differ diff --git a/Cleanup/Assets/Wide310x150Logo.scale-125.png b/Cleanup/Assets/Wide310x150Logo.scale-125.png new file mode 100644 index 0000000..4e488d5 Binary files /dev/null and b/Cleanup/Assets/Wide310x150Logo.scale-125.png differ diff --git a/Cleanup/Assets/Wide310x150Logo.scale-150.png b/Cleanup/Assets/Wide310x150Logo.scale-150.png new file mode 100644 index 0000000..a196a6f Binary files /dev/null and b/Cleanup/Assets/Wide310x150Logo.scale-150.png differ diff --git a/Cleanup/Assets/Wide310x150Logo.scale-200.png b/Cleanup/Assets/Wide310x150Logo.scale-200.png new file mode 100644 index 0000000..82b5d40 Binary files /dev/null and b/Cleanup/Assets/Wide310x150Logo.scale-200.png differ diff --git a/Cleanup/Assets/Wide310x150Logo.scale-400.png b/Cleanup/Assets/Wide310x150Logo.scale-400.png new file mode 100644 index 0000000..6d07ee9 Binary files /dev/null and b/Cleanup/Assets/Wide310x150Logo.scale-400.png differ diff --git a/ReboundHub/Assets/AppIcons/cleanmgr.ico b/Cleanup/Assets/cleanmgr.ico similarity index 100% rename from ReboundHub/Assets/AppIcons/cleanmgr.ico rename to Cleanup/Assets/cleanmgr.ico diff --git a/Cleanup/Assets/cleanmgr.png b/Cleanup/Assets/cleanmgr.png new file mode 100644 index 0000000..6ee5316 Binary files /dev/null and b/Cleanup/Assets/cleanmgr.png differ diff --git a/Cleanup/Assets/imageres_184.ico b/Cleanup/Assets/imageres_184.ico new file mode 100644 index 0000000..09495fe Binary files /dev/null and b/Cleanup/Assets/imageres_184.ico differ diff --git a/Cleanup/Assets/imageres_2.ico b/Cleanup/Assets/imageres_2.ico new file mode 100644 index 0000000..1f9c65c Binary files /dev/null and b/Cleanup/Assets/imageres_2.ico differ diff --git a/Cleanup/Assets/imageres_3.ico b/Cleanup/Assets/imageres_3.ico new file mode 100644 index 0000000..f969029 Binary files /dev/null and b/Cleanup/Assets/imageres_3.ico differ diff --git a/Cleanup/Assets/imageres_5364.ico b/Cleanup/Assets/imageres_5364.ico new file mode 100644 index 0000000..e7b8e3a Binary files /dev/null and b/Cleanup/Assets/imageres_5364.ico differ diff --git a/Cleanup/Assets/imageres_54.ico b/Cleanup/Assets/imageres_54.ico new file mode 100644 index 0000000..7bfd3dd Binary files /dev/null and b/Cleanup/Assets/imageres_54.ico differ diff --git a/Cleanup/Assets/imageres_59.ico b/Cleanup/Assets/imageres_59.ico new file mode 100644 index 0000000..6b8d9f1 Binary files /dev/null and b/Cleanup/Assets/imageres_59.ico differ diff --git a/ReboundHub/Rebound11Files/Rebound11/r11foldericon.ico b/Cleanup/Assets/r11imageres_101.ico similarity index 100% rename from ReboundHub/Rebound11Files/Rebound11/r11foldericon.ico rename to Cleanup/Assets/r11imageres_101.ico diff --git a/Cleanup/DiskWindow.xaml b/Cleanup/DiskWindow.xaml new file mode 100644 index 0000000..6352780 --- /dev/null +++ b/Cleanup/DiskWindow.xaml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Defrag/MainWindow.xaml.cs b/Defrag/MainWindow.xaml.cs new file mode 100644 index 0000000..a6a1407 --- /dev/null +++ b/Defrag/MainWindow.xaml.cs @@ -0,0 +1,1160 @@ +using Microsoft.UI.Windowing; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media; +using Microsoft.Win32.TaskScheduler; +using Microsoft.WindowsAPICodePack.Taskbar; +using Rebound.Defrag.Helpers; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.Eventing.Reader; +using System.IO; +using System.Linq; +using System.Management; +using System.Security.Principal; +using System.Text; +using System.Threading.Tasks; +using Windows.ApplicationModel; +using Windows.ApplicationModel.Core; +using Windows.Storage; +using Windows.System; +using WinUIEx; +using WinUIEx.Messaging; +using Task = System.Threading.Tasks.Task; + +#nullable enable +#pragma warning disable CA1854 // Prefer the 'IDictionary.TryGetValue(TKey, out TValue)' method + +namespace Rebound.Defrag +{ + public sealed partial class MainWindow : WindowEx + { + public MainWindow() + { + this?.InitializeComponent(); + // Set window backdrop to Mica for a modern translucent effect + SystemBackdrop = new MicaBackdrop(); + + // Set the window title + Title = "Optimize Drives - Beta v0.1.0"; + + // Window customization + IsMaximizable = false; + this.SetWindowSize(800, 670); + IsResizable = false; + AppWindow.DefaultTitleBarShouldMatchAppModeTheme = true; + this.CenterOnScreen(); + this.SetIcon(@$"{AppContext.BaseDirectory}/Assets/Rebound.Defrag.ico"); + } + + public async Task LoadAppAsync() + { + AdvancedView.IsOn = GetBoolFromLocalSettings("Advanced"); + + // Load data based on the current state of 'AdvancedView' + await LoadData(AdvancedView.IsOn); + + // Begin monitoring window messages (such as device changes) + var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this); + WindowMessageMonitor mon = new(hWnd); + + // Subscribe to the WindowMessageReceived event + mon.WindowMessageReceived += MessageReceived; + + // Set up a timer to periodically refresh the message listener every 5 seconds + var timer = new DispatcherTimer + { + Interval = TimeSpan.FromSeconds(5) // Timer interval set to 5 seconds + }; + + // Timer event handler + timer.Tick += (sender, e) => + { + mon.WindowMessageReceived += MessageReceived; // Re-subscribe to the event to keep monitoring + }; + + // Start the timer + timer.Start(); + + // Check if the application is running with administrator privileges + IsAdministrator(); + CheckTask(); + } + + public static void SetProgressState(TaskbarProgressBarState state) + { + TaskbarManager.Instance.SetProgressState(state); + } + + public static void SetProgressValue(int completed, int total) + { + TaskbarManager.Instance.SetProgressValue(completed, total); + } + + private async void MessageReceived(object? sender, WindowMessageEventArgs e) + { + // Handle incoming messages + switch (e.Message.MessageId) + { + default: + { + // No relevant message, break + break; + } + case Win32Helper.WM_DEVICECHANGE: + { + // Handle specific device changes + switch ((int)e.Message.WParam) + { + case Win32Helper.DBT_DEVICEARRIVAL: + { + // Device or partition inserted + MyListView.ItemsSource = null; // Clear existing list + await LoadData(AdvancedView.IsOn); // Reload data based on AdvancedView state + break; + } + case Win32Helper.DBT_DEVICEREMOVECOMPLETE: + { + // Device or partition removed + MyListView.ItemsSource = null; // Clear existing list + await LoadData(AdvancedView.IsOn); // Reload data based on AdvancedView state + break; + } + default: + { + // Handle any other device action + break; + } + } + break; + } + } + } + + public class DiskItem : Item + { + public string? DriveLetter { get; set; } + public string? MediaType { get; set; } + public int ProgressValue { get; set; } + public bool IsChecked { get; set; } + } + + public bool IsAdministrator() + { + var identity = WindowsIdentity.GetCurrent(); + var principal = new WindowsPrincipal(identity); + if (principal.IsInRole(WindowsBuiltInRole.Administrator)) + { + Admin1.Visibility = Visibility.Collapsed; + Admin2.Visibility = Visibility.Collapsed; + Admin3.Visibility = Visibility.Collapsed; + Admin4.Visibility = Visibility.Collapsed; + } + return principal.IsInRole(WindowsBuiltInRole.Administrator); + } + + private void ListviewSelectionChange(object sender, SelectionChangedEventArgs args) + { + LoadSelectedItemInfo(GetStatus()); + } + + public string GetLastOptimizeDate() + { + if (MyListView.SelectedItem != null) + { + DiskItem? selectedItem = MyListView.SelectedItem as DiskItem; + // Handle the selection change event + + try + { + List i = DefragInfo.GetEventLogEntriesForID(258); + return i.Last(s => s.Contains($"({selectedItem?.DriveLetter?.ToString().Remove(2, 1)})")); + } + catch + { + return "Never...."; + } + } + else return "Unknown...."; + } + + public void LoadSelectedItemInfo(string status, string info = "....") + { + if (info == "....") + { + info = GetLastOptimizeDate(); + } + else + { + info = "Unknown...."; + } + if (MyListView.SelectedItem != null) + { + DiskItem? selectedItem = MyListView.SelectedItem as DiskItem; + DetailsBar.Title = selectedItem?.Name; + DetailsBar.Message = $"Media type: {selectedItem?.MediaType}\nLast analyzed or optimized: {info[..^4]}\nCurrent status: {status}"; + DetailsBar.Severity = InfoBarSeverity.Informational; + OptimizeButton.IsEnabled = AdvancedView.IsEnabled; + if (status.Contains("Needs optimization")) + { + DetailsBar.Severity = InfoBarSeverity.Warning; + } + if (selectedItem?.MediaType == "CD-ROM") + { + DetailsBar.Message = "Media type: CD-ROM\nLast analyzed or optimized: Never\nCurrent status: cannot be optimized"; + DetailsBar.Severity = InfoBarSeverity.Error; + VisualStateManager.GoToState(OptimizeButton, "Disabled", true); + OptimizeButton.IsEnabled = false; + } + if (selectedItem?.Name == "EFI System Partition") + { + DetailsBar.Message = $"Media type: {selectedItem.MediaType}\nLast analyzed or optimized: Never\nCurrent status: cannot be optimized (EFI System Partition)"; + DetailsBar.Severity = InfoBarSeverity.Informational; + } + if (selectedItem?.Name == "Recovery Partition") + { + DetailsBar.Message = $"Media type: {selectedItem.MediaType}\nLast analyzed or optimized: Never\nCurrent status: cannot be optimized (Recovery Partition)"; + DetailsBar.Severity = InfoBarSeverity.Error; + VisualStateManager.GoToState(OptimizeButton, "Disabled", true); + OptimizeButton.IsEnabled = false; + } + } + } + + public string GetStatus() + { + string status = string.Empty; + + try + { + if (MyListView.SelectedItem != null) + { + List i = DefragInfo.GetEventLogEntriesForID(258); + var selectedItem = MyListView.SelectedItem as DiskItem; + + var selI = i.Last(s => s.Contains($"({selectedItem?.DriveLetter?.ToString().Remove(2, 1)})")); + + var localDate = DateTime.Parse(selI[..^4]); + + // Get the current local date and time + DateTime currentDate = DateTime.Now; + + // Calculate the days passed + TimeSpan timeSpan = currentDate - localDate; + int daysPassed = timeSpan.Days; + + if (daysPassed == 0) + { + //return $"OK (Last optimized: today)"; + return $"OK"; + } + + if (daysPassed == 1) + { + //return $"OK (Last optimized: yesterday)"; + return $"OK"; + } + + if (daysPassed < 50) + { + //return $"OK (Last optimized: {daysPassed} days ago)"; + return $"OK"; + } + + if (daysPassed >= 50) + { + //return $"Needs optimization (Last optimized: {daysPassed} days ago)"; + return $"Needs optimization"; + } + + else return "Unknown"; + } + else + { + return "Please select an item to proceed."; + } + } + catch + { + return "Needs optimization"; + } + } + + public void Lock(bool areItemsEnabled, string message = "", bool indeterminate = true) + { + AnalyzeButton.IsEnabled = areItemsEnabled; + OptimizeButton.IsEnabled = areItemsEnabled; + MyListView.IsEnabled = areItemsEnabled; + AdvancedView.IsEnabled = areItemsEnabled; + CurrentDisk.Visibility = areItemsEnabled == true ? Visibility.Collapsed : Visibility.Visible; + if (!string.IsNullOrWhiteSpace(message)) CurrentDisk.Text = message; + if (indeterminate == true) CurrentProgress.IsIndeterminate = !areItemsEnabled; + else CurrentProgress.IsIndeterminate = false; + VisualStateManager.GoToState(OptimizeButton, areItemsEnabled == true ? "Normal" : "Disabled", true); + } + + public async Task LoadData(bool loadSystemPartitions) + { + Lock(false, "Loading drive information..."); + + // Initial delay + // Essential for ensuring the UI loads before starting tasks + await Task.Delay(100); + + List items = []; + + // Get the logical drives bitmask + uint drivesBitMask = Win32Helper.GetLogicalDrives(); + if (drivesBitMask == 0) + { + return; + } + + for (char driveLetter = 'A'; driveLetter <= 'Z'; driveLetter++) + { + uint mask = 1u << (driveLetter - 'A'); + if ((drivesBitMask & mask) != 0) + { + string drive = $"{driveLetter}:\\"; + + StringBuilder volumeName = new(261); + StringBuilder fileSystemName = new(261); + if (Win32Helper.GetVolumeInformation(drive, volumeName, volumeName.Capacity, out _, out _, out _, fileSystemName, fileSystemName.Capacity)) + { + var newDriveLetter = drive.ToString().Remove(2, 1); + string mediaType = GetDriveTypeDescriptionAsync(drive); + + if (volumeName.ToString() != string.Empty) + { + var item = new DiskItem + { + Name = $"{volumeName} ({newDriveLetter})", + ImagePath = "ms-appx:///Assets/Drive.png", + MediaType = mediaType, + DriveLetter = drive, + }; + if (item.MediaType == "Removable") + { + item.ImagePath = "ms-appx:///Assets/DriveRemovable.png"; + } + if (item.MediaType == "Unknown") + { + item.ImagePath = "ms-appx:///Assets/DriveUnknown.png"; + } + if (item.MediaType == "CD-ROM") + { + item.ImagePath = "ms-appx:///Assets/DriveOptical.png"; + } + if (item.DriveLetter.Contains('C')) + { + item.ImagePath = "ms-appx:///Assets/DriveWindows.png"; + } + item.IsChecked = GetBoolFromLocalSettings(ConvertStringToNumericRepresentation(drive)); + items.Add(item); + } + else + { + var item = new DiskItem + { + Name = $"({newDriveLetter})", + ImagePath = "ms-appx:///Assets/Drive.png", + MediaType = mediaType, + DriveLetter = drive, + }; + if (item.MediaType == "Removable") + { + item.ImagePath = "ms-appx:///Assets/DriveRemovable.png"; + } + if (item.MediaType == "Unknown") + { + item.ImagePath = "ms-appx:///Assets/DriveUnknown.png"; + } + if (item.MediaType == "CD-ROM") + { + item.ImagePath = "ms-appx:///Assets/DriveOptical.png"; + } + if (item.DriveLetter.Contains('C')) + { + item.ImagePath = "ms-appx:///Assets/DriveWindows.png"; + } + item.IsChecked = GetBoolFromLocalSettings(ConvertStringToNumericRepresentation(drive)); + items.Add(item); + } + } + else + { + Debug.WriteLine($" Failed to get volume information for {drive}"); + } + } + } + + if (loadSystemPartitions) + { + var syspart = SystemVolumes.GetSystemVolumes(); + + // Add system partitions to the items list + foreach (var result in syspart) + { + string? driveType = string.Empty; + foreach (var diskitem in items) + { + if (diskitem.DriveLetter != null && diskitem.DriveLetter.Contains('C')) + { + driveType = diskitem.MediaType; + } + } + var item = new DiskItem + { + Name = result.FriendlyName, + ImagePath = "ms-appx:///Assets/DriveSystem.png", + MediaType = driveType, + DriveLetter = result.GUID, + }; + if (result.GUID != null) item.IsChecked = GetBoolFromLocalSettings(ConvertStringToNumericRepresentation(result.GUID)); + items.Add(item); + } + } + + int selIndex = MyListView.SelectedIndex is not -1 ? MyListView.SelectedIndex : 0; + + // Set the list view's item source + MyListView.ItemsSource = items; + + MyListView.SelectedIndex = selIndex >= items.Count ? items.Count - 1 : selIndex; + + Lock(true); + } + + public static string ConvertStringToNumericRepresentation(string input) + { + // Create a StringBuilder to store the numeric representation + StringBuilder numericRepresentation = new(); + + // Iterate over each character in the string + foreach (char c in input) + { + // Convert the character to its ASCII value and append it + numericRepresentation.Append((int)c); + } + + // Return the numeric representation as a string + return numericRepresentation.ToString(); + } + + // Method to read a bool value from LocalSettings + public static bool GetBoolFromLocalSettings(string name) + { + // Access the local settings + var localSettings = ApplicationData.Current.LocalSettings; + + // Check if the key exists and return the bool value if it does + if (localSettings.Values.ContainsKey(name)) + { + // Try to get the value and cast it to bool + if (localSettings.Values[name] is bool value) + { + return value; + } + } + + // Return false if the key does not exist or is not a bool + return false; + } + + // Method to write a bool value to LocalSettings + public static bool WriteBoolToLocalSettings(string name, bool value) + { + try + { + // Access the local settings + var localSettings = ApplicationData.Current.LocalSettings; + + // Write the bool value to the settings with the given key + localSettings.Values[name] = value; + + return true; // Return true if write is successful + } + catch + { + return false; // Return false if an error occurs + } + } + + public static string GetDiskDriveFromLetter(string driveLetter) + { + try + { + var FULLSEARCHER = new ManagementObjectSearcher("root\\Microsoft\\Windows\\Storage", "SELECT * FROM MSFT_PhysicalDisk"); + foreach (ManagementObject queryObj in FULLSEARCHER.Get().Cast()) + { + string? MEDIATYPE = queryObj["MediaType"].ToString(); + string? DEVICEID = queryObj["DeviceID"].ToString(); + + // Create a ManagementObjectSearcher to query the Win32_DiskDrive class + ManagementObjectSearcher searcher2 = new("SELECT * FROM Win32_DiskDrive"); + + foreach (ManagementObject disk in searcher2.Get().Cast()) + { + // Get the device ID of the disk + string? deviceID2 = disk["DeviceID"].ToString(); + + // Create a ManagementObjectSearcher to query the Win32_LogicalDiskToPartition class + ManagementObjectSearcher partitionSearcher = new( + $"ASSOCIATORS OF {{Win32_DiskDrive.DeviceID='{deviceID2}'}} WHERE AssocClass=Win32_DiskDriveToDiskPartition"); + + foreach (ManagementObject partition in partitionSearcher.Get().Cast()) + { + // Create a ManagementObjectSearcher to query the Win32_LogicalDisk class + ManagementObjectSearcher logicalDiskSearcher = new( + $"ASSOCIATORS OF {{Win32_DiskPartition.DeviceID='{partition["DeviceID"]}'}} WHERE AssocClass=Win32_LogicalDiskToPartition"); + + foreach (ManagementObject logicalDisk in logicalDiskSearcher.Get().Cast()) + { + // Check if the logical disk is drive C + if (logicalDisk["DeviceID"].ToString() == driveLetter.Replace(@"\", "")) + { + if (deviceID2 != null && DEVICEID != null && deviceID2.Contains(DEVICEID)) + { + string driveType = MEDIATYPE switch + { + "3" => "HDD (Hard Disk Drive)", + "4" => "SSD (Solid State Drive)", + _ => "Unknown" + }; + + return driveType; + } + } + } + } + } + } + } + catch + { + + } + return "Error"; + } + + private static async Task GetDeviceIdFromDriveAsync(string driveRoot) + { + string driveLetter = driveRoot.TrimEnd('\\'); // Clean the input + + return await Task.Run(async () => + { + string query = $"SELECT * FROM Win32_DiskDrive"; + using (var searcher = new ManagementObjectSearcher(query)) + { + foreach (ManagementObject logicalDisk in searcher.Get().Cast()) + { + if ((string)logicalDisk["DeviceID"] == await GetDeviceIdFromDriveAsync(driveRoot)) + return logicalDisk["DeviceID"]?.ToString(); // Return the DeviceID of the disk drive + } + } + return "Unknown"; // Fallback if not found + }); + } + + public static string GetDriveTypeDescriptionAsync(string driveRoot) + { + Win32Helper.DriveType driveType = Win32Helper.GetDriveType(driveRoot); + + return driveType switch + { + Win32Helper.DriveType.DRIVE_REMOVABLE => "Removable", + Win32Helper.DriveType.DRIVE_FIXED => GetDiskDriveFromLetter(driveRoot), + Win32Helper.DriveType.DRIVE_REMOTE => "Network", + Win32Helper.DriveType.DRIVE_CDROM => "CD-ROM", + Win32Helper.DriveType.DRIVE_RAMDISK => "RAM Disk", + Win32Helper.DriveType.DRIVE_NO_ROOT_DIR => "No Root Directory", + _ => "Unknown", + }; + } + + private void Button_Click(object sender, SplitButtonClickEventArgs e) + { + OptimizeSelected(AdvancedView.IsOn); + } + + public static void RestartAsAdmin(string args) + { + var packageName = Package.Current.Id.FamilyName; + var appId = CoreApplication.Id; + + // Request elevation + var startInfo = new ProcessStartInfo + { + FileName = "powershell.exe", + Arguments = $"-Command \"Start-Process 'shell:AppsFolder\\{packageName}!{appId}' -ArgumentList @('{args}') -Verb RunAs\"", + UseShellExecute = false, + CreateNoWindow = true, + Verb = "runas" + }; + + try + { + Process.Start(startInfo); + App.Current.Exit(); + } + catch + { + + } + } + + public async void OptimizeSelected(bool systemPartitions) + { + AdvancedView.IsOn = systemPartitions; + + if (!IsAdministrator()) + { + RestartAsAdmin($"SELECTED{(systemPartitions ? "-SYSTEM" : "")} {MyListView.SelectedIndex}"); + return; + } + + foreach (var item in (List)MyListView.ItemsSource) + { + if (item?.IsChecked == true) + { + Lock(false, "Loading...", true); + + MyListView.SelectedIndex = ((List)MyListView.ItemsSource).IndexOf(item); + + string scriptPath = "C:\\Rebound11\\rdfrgui.ps1"; + string? volume = item?.DriveLetter?.ToString().Remove(1, 2); + string arguments = $@" +$job = Start-Job -ScriptBlock {{ + $global:OutputLines = @() + + # Capture all output including verbose messages + Optimize-Volume -DriveLetter {volume} -Defrag -Verbose | ForEach-Object {{ + # Check if it's a progress update + if ($_ -like ""*Progress*"") {{ + Write-Output ""Progress: $_"" # Modify to capture progress as needed + }} else {{ + $global:OutputLines += $_ + Write-Output $_ # Output normal messages + }} + }} +}} + +while ($job.State -eq 'Running') {{ + Clear-Host + Start-Sleep -Seconds 0.01 + $output = Receive-Job -Id $job.Id -Keep + if ($output) {{ + Write-Output $output[-1] # Output the last line + }} +}} + +# Final output after the job completes +Receive-Job -Id $job.Id | ForEach-Object {{ Write-Output $_ }} + +"; + + // Ensure the script is written before proceeding + await File.WriteAllTextAsync(scriptPath, arguments); + + try + { + if (DetailsBar.Severity == InfoBarSeverity.Error) + { + LoadSelectedItemInfo("Cannot be optimized. Skipping..."); + await Task.Delay(1000); + continue; + } + var processInfo = new ProcessStartInfo + { + FileName = "powershell.exe", + Arguments = $"-ExecutionPolicy Bypass -File \"{scriptPath}\"", // Use -File to execute the script + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = true, + Verb = "runas" // Run as administrator + }; + + using var process = new Process { StartInfo = processInfo }; + + string outputData = "0"; + bool updateData = true; + + var alreadyUsed = new List(); + + process.OutputDataReceived += UpdateOutput; + + void UpdateOutput(object sender, DataReceivedEventArgs args) + { + // Only process if there's data + if (!string.IsNullOrEmpty(args.Data)) + { + // Use the dispatcher to update the UI + DispatcherQueue.TryEnqueue(() => { UpdateIO(args.Data); }); + + // Store the output data + outputData = "\n" + args.Data; + } + } + + process.Start(); + process.BeginOutputReadLine(); + + Lock(false, "", true); + LoadSelectedItemInfo("Optimizing..."); + + void UpdateIO(string data) + { + if (!updateData) return; + + if (data.Contains("VERBOSE: ") && data.Contains(" complete.")) + { + string a = data[data.LastIndexOf("VERBOSE: ")..].Replace("VERBOSE: ", string.Empty); + + string dataToReplace = " complete."; + + DispatcherQueue.TryEnqueue(() => { RunUpdate(a, dataToReplace); }); + } + } + + void RunUpdate(string a, string dataToReplace) + { + if (alreadyUsed.Contains(a) != true) + { + alreadyUsed.Add(a); + CurrentProgress.Value = GetMaxPercentage(a); + CurrentProgress.IsIndeterminate = false; + SetProgressState(TaskbarProgressBarState.Normal); + SetProgressValue((int)CurrentProgress.Value, (int)CurrentProgress.Maximum); + if (a.Contains(" complete...")) + { + dataToReplace = " complete..."; + if (item?.DriveLetter?.ToString().Contains('}') != true) CurrentDisk.Text = $"Drive {volume}: - {a.Remove(a.IndexOf(" complete..."))}"; + else CurrentDisk.Text = $"{((DiskItem)MyListView.SelectedItem).Name} - {a.Remove(a.IndexOf(" complete..."))}"; + } + else if (a.Contains(" complete.")) + { + dataToReplace = " complete."; + if (item?.DriveLetter?.ToString().Contains('}') != true) CurrentDisk.Text = $"Drive {volume}: - {a.Remove(a.IndexOf(" complete."))}"; + else CurrentDisk.Text = $"{((DiskItem)MyListView.SelectedItem).Name} - {a.Remove(a.IndexOf(" complete."))}"; + + } + } + } + + await process.WaitForExitAsync(); + + updateData = false; + Lock(true); + LoadSelectedItemInfo(GetStatus()); + File.Delete(scriptPath); + alreadyUsed.Clear(); + CurrentProgress.Value = 0; + SetProgressState(TaskbarProgressBarState.NoProgress); + } + catch (System.ComponentModel.Win32Exception ex) when (ex.NativeErrorCode == 1223) + { + ShowMessage("Defragmentation was canceled by the user."); + } + catch (Exception ex) + { + ShowMessage($"Error: {ex.Message}"); + } + } + } + } + + private static int GetMaxPercentage(string data) + { + static string KeepOnlyNumbers(string input) + { + StringBuilder sb = new(); + + foreach (char c in input) + { + if (char.IsDigit(c)) + { + sb.Append(c); + } + } + + return sb.ToString(); + } + var match = KeepOnlyNumbers(data); + return int.Parse(match); + } + + public async void OptimizeAll(bool close, bool systemPartitions) + { + AdvancedView.IsOn = systemPartitions; + + await LoadData(systemPartitions); + + MyListView.IsEnabled = false; + + if (!IsAdministrator()) + { + if (close == true) RestartAsAdmin($"OPTIMIZEALLANDCLOSE{(systemPartitions ? "-SYSTEM" : "")}"); + else RestartAsAdmin($"OPTIMIZEALL{(systemPartitions ? "-SYSTEM" : "")}"); + return; + } + + int i = 0; + int j = ((List)MyListView.ItemsSource).Count; + + MyListView.SelectedIndex = 0; + + foreach (var item in (List)MyListView.ItemsSource) + { + Lock(false, "Optimizing...", true); + + string scriptPath = "C:\\Rebound11\\rdfrgui.ps1"; + string? volume = item.DriveLetter?.ToString().Remove(1, 2); + string arguments = $@" +$job = Start-Job -ScriptBlock {{ + $global:OutputLines = @() + + # Capture all output including verbose messages + Optimize-Volume -DriveLetter {volume} -Defrag -Verbose | ForEach-Object {{ + # Check if it's a progress update + if ($_ -like ""*Progress*"") {{ + Write-Output ""Progress: $_"" # Modify to capture progress as needed + }} else {{ + $global:OutputLines += $_ + Write-Output $_ # Output normal messages + }} + }} +}} + +while ($job.State -eq 'Running') {{ + Clear-Host + Start-Sleep -Seconds 0.01 + $output = Receive-Job -Id $job.Id -Keep + if ($output) {{ + Write-Output $output[-1] # Output the last line + }} +}} + +# Final output after the job completes +Receive-Job -Id $job.Id | ForEach-Object {{ Write-Output $_ }} + +"; + + // Ensure the script is written before proceeding + await File.WriteAllTextAsync(scriptPath, arguments); + + try + { + i++; + + if (DetailsBar.Severity == InfoBarSeverity.Error) + { + LoadSelectedItemInfo("Cannot be optimized. Skipping..."); + await Task.Delay(1000); + if (MyListView.SelectedIndex + 1 != j) MyListView.SelectedIndex++; + continue; + } + var processInfo = new ProcessStartInfo + { + FileName = "powershell.exe", + Arguments = $"-ExecutionPolicy Bypass -File \"{scriptPath}\"", // Use -File to execute the script + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = true, + Verb = "runas" // Run as administrator + }; + + using var process = new Process { StartInfo = processInfo }; + + string outputData = "0"; + bool updateData = true; + + var alreadyUsed = new List(); + + process.OutputDataReceived += UpdateOutput; + + void UpdateOutput(object sender, DataReceivedEventArgs args) + { + // Only process if there's data + if (!string.IsNullOrEmpty(args.Data)) + { + // Use the dispatcher to update the UI + DispatcherQueue.TryEnqueue(() => { UpdateIO(args.Data); }); + + // Store the output data + outputData = "\n" + args.Data; + } + } + + process.Start(); + process.BeginOutputReadLine(); + + Lock(false, "", true); + LoadSelectedItemInfo("Optimizing..."); + + void UpdateIO(string data) + { + if (!updateData) return; + + if (data.Contains("VERBOSE: ") && data.Contains(" complete.")) + { + string a = data[data.LastIndexOf("VERBOSE: ")..].Replace("VERBOSE: ", string.Empty); + + string dataToReplace = " complete."; + + DispatcherQueue.TryEnqueue(() => { RunUpdate(a, dataToReplace); }); + } + } + + void RunUpdate(string a, string dataToReplace) + { + if (alreadyUsed.Contains(a) != true) + { + alreadyUsed.Add(a); + CurrentProgress.IsIndeterminate = false; + CurrentProgress.Value = GetMaxPercentage(a); + SetProgressState(TaskbarProgressBarState.Normal); + SetProgressValue((int)CurrentProgress.Value, (int)CurrentProgress.Maximum); + if (a.Contains(" complete...")) + { + dataToReplace = " complete..."; + if (item.DriveLetter?.ToString().Contains('}') != true) CurrentDisk.Text = $"Drive {i}/{j} ({volume}:) - {a.Remove(a.IndexOf(" complete..."))}"; + else CurrentDisk.Text = $"{((DiskItem)MyListView.SelectedItem).Name} ({i}/{j}) - {a.Remove(a.IndexOf(" complete..."))}"; + } + else if (a.Contains(" complete.")) + { + dataToReplace = " complete."; + if (item.DriveLetter?.ToString().Contains('}') != true) CurrentDisk.Text = $"Drive {i}/{j} ({volume}:) - {a.Remove(a.IndexOf(" complete."))}"; + else CurrentDisk.Text = $"{((DiskItem)MyListView.SelectedItem).Name} ({i}/{j}) - {a.Remove(a.IndexOf(" complete."))}"; + + } + } + } + + await process.WaitForExitAsync(); + + updateData = false; + Lock(true, "", false); + LoadSelectedItemInfo(GetStatus()); + File.Delete(scriptPath); + alreadyUsed.Clear(); + CurrentProgress.Value = 0; + SetProgressState(TaskbarProgressBarState.NoProgress); + if (MyListView.SelectedIndex + 1 != j) MyListView.SelectedIndex++; + } + catch (System.ComponentModel.Win32Exception ex) when (ex.NativeErrorCode == 1223) + { + ShowMessage("Defragmentation was canceled by the user."); + } + catch (Exception ex) + { + ShowMessage($"Error: {ex.Message}"); + } + } + + i = 0; + + MyListView.IsEnabled = true; + + if (close == true) Close(); + } + + private async void ShowMessage(string message) + { + try + { + var dialog = new ContentDialog + { + Title = "Defragmentation", + Content = message, + CloseButtonText = "OK", + XamlRoot = Content.XamlRoot + }; + _ = await dialog.ShowAsync(); + } + catch + { + + } + } + + private void MenuFlyoutItem_Click(object sender, RoutedEventArgs e) + { + OptimizeSelected(AdvancedView.IsOn); + } + + private void MenuFlyoutItem_Click_1(object sender, RoutedEventArgs e) + { + OptimizeAll(false, AdvancedView.IsOn); + } + + private void Button_Click_1(object sender, RoutedEventArgs e) + { + if (IsAdministrator() != true) + { + RestartAsAdmin($"TASK"); + return; + } + + OpenTaskWindow(); + } + + public async void CheckTask() + { + await Task.Delay(100); + try + { + ScheduledOptimizationDetails.Text = GetTaskFrequency(); + if (GetTaskFrequency() is not "Off") + { + ScheduledTaskText.Text = "Configure"; + } + else + { + ScheduledTaskText.Text = "Turn on"; + } + + CheckTask(); + } + catch + { + + } + } + + public void OpenTaskWindow() + { + var win = new ScheduledOptimization(this.AppWindow.Position.X, this.AppWindow.Position.Y); + Win32Helper.CreateModalWindow(this, win, true, true); + } + + private void Button_Click_2(object sender, RoutedEventArgs e) + { + LoadSelectedItemInfo(GetStatus()); + } + + private async void AdvancedView_Toggled(object sender, RoutedEventArgs e) + { + WriteBoolToLocalSettings("Advanced", AdvancedView.IsOn); + await LoadData(AdvancedView.IsOn); + } + + private async void MenuFlyoutItem_Click_2(object sender, RoutedEventArgs e) + { + await Launcher.LaunchUriAsync(new Uri("https://ivirius.vercel.app/docs/rebound11/defragment-and-optimize-drives/")); + } + + private void CheckBox_Click(object? sender, RoutedEventArgs e) + { + var name = ((DiskItem?)((CheckBox?)sender)?.DataContext)?.DriveLetter; + var isChecked = ((CheckBox?)sender)?.IsChecked; + if (name != null && isChecked != null) WriteBoolToLocalSettings(ConvertStringToNumericRepresentation(name), (bool)isChecked); + } + + public static string GetTaskFrequency() + { + using (TaskService ts = new()) + { + // Specify the path to the task in Task Scheduler + TaskFolder defragFolder = ts.GetFolder(@"Microsoft\Windows\Defrag"); + + // Retrieve the scheduled task + Microsoft.Win32.TaskScheduler.Task task = defragFolder.GetTasks()["ScheduledDefrag"]; + + if (task.Enabled != true) + { + return $"Off"; + } + + if (task != null) + { + // Check the triggers for their type + foreach (var trigger in task.Definition.Triggers) + { + switch (trigger) + { + case DailyTrigger _: + return "On (Frequency: daily)"; + case WeeklyTrigger _: + return "On (Frequency: weekly)"; + case MonthlyTrigger _: + return "On (Frequency: monthly)"; + } + } + + return "On (Frequency: unknown)"; + } + else + { + return $"Off"; + } + } + } + + public static string GetTaskCommand() + { + using (TaskService ts = new()) + { + // Specify the path to the task in Task Scheduler + TaskFolder defragFolder = ts.GetFolder(@"Microsoft\Windows\Defrag"); + + // Retrieve the scheduled task + Microsoft.Win32.TaskScheduler.Task task = defragFolder.GetTasks()["ScheduledDefrag"]; + + if (task != null) + { + // Check the triggers for their type + foreach (var action in task.Definition.Actions) + { + if (action is ExecAction ex) + { + return ex.Arguments; + } + } + + return "None"; + } + else + { + return $"None"; + } + } + } + + private void MenuFlyoutItem_Click_3(object sender, RoutedEventArgs e) + { + Process.Start("dfrgui.exe"); + Close(); + } + } + + public class DefragInfo + { + public static List GetEventLogEntriesForID(int eventID) + { + List eventMessages = []; + + // Define the query + string logName = "Application"; // Windows Logs > Application + string queryStr = "*[System/EventID=" + eventID + "]"; + + EventLogQuery query = new(logName, PathType.LogName, queryStr); + + // Create the reader + using (EventLogReader reader = new(query)) + { + for (EventRecord eventInstance = reader.ReadEvent(); eventInstance != null; eventInstance = reader.ReadEvent()) + { + // Extract the message from the event + string sb = string.Concat(eventInstance.TimeCreated.ToString(), eventInstance.FormatDescription().ToString().AsSpan(eventInstance.FormatDescription().ToString().Length - 4)); + + eventMessages.Add(sb.ToString()); + } + } + + return eventMessages; + } + } +} diff --git a/Defrag/Package.appxmanifest b/Defrag/Package.appxmanifest new file mode 100644 index 0000000..8f362b3 --- /dev/null +++ b/Defrag/Package.appxmanifest @@ -0,0 +1,58 @@ + + + + + + + + + + Rebound.Defrag + Lenovo + Assets\StoreLogo.png + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Defrag/Properties/launchSettings.json b/Defrag/Properties/launchSettings.json new file mode 100644 index 0000000..aae6a54 --- /dev/null +++ b/Defrag/Properties/launchSettings.json @@ -0,0 +1,10 @@ +{ + "profiles": { + "Rebound.Defrag (Package)": { + "commandName": "MsixPackage" + }, + "Rebound.Defrag (Unpackaged)": { + "commandName": "Project" + } + } +} \ No newline at end of file diff --git a/Defrag/Rebound.Defrag.csproj b/Defrag/Rebound.Defrag.csproj new file mode 100644 index 0000000..e4355ce --- /dev/null +++ b/Defrag/Rebound.Defrag.csproj @@ -0,0 +1,98 @@ + + + WinExe + net8.0-windows10.0.19041.0 + 10.0.17763.0 + Rebound.Defrag + app.manifest + x86;x64;ARM64 + win-x86;win-x64;win-arm64 + win10-x86;win10-x64;win10-arm64 + win-$(Platform).pubxml + true + true + 10.0.22621.35-preview + True + True + SHA256 + False + False + True + Never + C:\Users\Lenovo\Desktop\rdfrgui + 0 + Rebound.Defrag.ico + 805D9FAF3E251362A569D694C3D7834BE80FE5B8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Always + + + + + MSBuild:Compile + + + MSBuild:Compile + + + + + + true + + \ No newline at end of file diff --git a/Defrag/Rebound.Defrag.ico b/Defrag/Rebound.Defrag.ico new file mode 100644 index 0000000..a58321e Binary files /dev/null and b/Defrag/Rebound.Defrag.ico differ diff --git a/Defrag/ScheduledOptimization.xaml b/Defrag/ScheduledOptimization.xaml new file mode 100644 index 0000000..356ba9b --- /dev/null +++ b/Defrag/ScheduledOptimization.xaml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ReboundHub/ReboundHub/Pages/Rebound11Page.xaml.cs b/Rebound/Rebound/Pages/Rebound11Page.xaml.cs similarity index 98% rename from ReboundHub/ReboundHub/Pages/Rebound11Page.xaml.cs rename to Rebound/Rebound/Pages/Rebound11Page.xaml.cs index 89b10b4..dda2e12 100644 --- a/ReboundHub/ReboundHub/Pages/Rebound11Page.xaml.cs +++ b/Rebound/Rebound/Pages/Rebound11Page.xaml.cs @@ -24,7 +24,7 @@ // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. -namespace ReboundHub.ReboundHub.Pages; +namespace Rebound.Rebound.Pages; /// /// An empty page that can be used on its own or navigated to within a Frame. /// @@ -106,7 +106,7 @@ private void Button_Click(object sender, RoutedEventArgs e) private async Task CheckForUpdatesAsync() { // URL of the text file containing the latest version number - string versionUrl = "https://ivirius.vercel.app/reboundhubversion.txt"; + string versionUrl = "https://ivirius.vercel.app/Reboundversion.txt"; // Use HttpClient to fetch the content using HttpClient client = new HttpClient(); diff --git a/ReboundHub/ReboundHub/Pages/ShellPage.xaml b/Rebound/Rebound/Pages/ShellPage.xaml similarity index 97% rename from ReboundHub/ReboundHub/Pages/ShellPage.xaml rename to Rebound/Rebound/Pages/ShellPage.xaml index 339d944..bd44297 100644 --- a/ReboundHub/ReboundHub/Pages/ShellPage.xaml +++ b/Rebound/Rebound/Pages/ShellPage.xaml @@ -1,9 +1,9 @@ diff --git a/ReboundHub/ReboundHub/Pages/ShellPage.xaml.cs b/Rebound/Rebound/Pages/ShellPage.xaml.cs similarity index 98% rename from ReboundHub/ReboundHub/Pages/ShellPage.xaml.cs rename to Rebound/Rebound/Pages/ShellPage.xaml.cs index ef45a62..0ae9bd1 100644 --- a/ReboundHub/ReboundHub/Pages/ShellPage.xaml.cs +++ b/Rebound/Rebound/Pages/ShellPage.xaml.cs @@ -19,7 +19,7 @@ // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. -namespace ReboundHub.ReboundHub.Pages; +namespace Rebound.Rebound.Pages; /// /// An empty page that can be used on its own or navigated to within a Frame. /// diff --git a/ReboundHub/ReboundHub/UserControls/HomePageHeaderImage.xaml b/Rebound/Rebound/UserControls/HomePageHeaderImage.xaml similarity index 100% rename from ReboundHub/ReboundHub/UserControls/HomePageHeaderImage.xaml rename to Rebound/Rebound/UserControls/HomePageHeaderImage.xaml diff --git a/ReboundHub/ReboundHub/UserControls/HomePageHeaderImage.xaml.cs b/Rebound/Rebound/UserControls/HomePageHeaderImage.xaml.cs similarity index 100% rename from ReboundHub/ReboundHub/UserControls/HomePageHeaderImage.xaml.cs rename to Rebound/Rebound/UserControls/HomePageHeaderImage.xaml.cs diff --git a/ReboundHub/Rebound11Files/Executables/rcleanmgr.exe b/Rebound/Rebound11Files/Executables/rcleanmgr.exe similarity index 100% rename from ReboundHub/Rebound11Files/Executables/rcleanmgr.exe rename to Rebound/Rebound11Files/Executables/rcleanmgr.exe diff --git a/ReboundHub/Rebound11Files/Executables/rcontrol.exe b/Rebound/Rebound11Files/Executables/rcontrol.exe similarity index 100% rename from ReboundHub/Rebound11Files/Executables/rcontrol.exe rename to Rebound/Rebound11Files/Executables/rcontrol.exe diff --git a/ReboundHub/Rebound11Files/Executables/rdfrgui.exe b/Rebound/Rebound11Files/Executables/rdfrgui.exe similarity index 100% rename from ReboundHub/Rebound11Files/Executables/rdfrgui.exe rename to Rebound/Rebound11Files/Executables/rdfrgui.exe diff --git a/ReboundHub/Rebound11Files/Executables/rosk.exe b/Rebound/Rebound11Files/Executables/rosk.exe similarity index 100% rename from ReboundHub/Rebound11Files/Executables/rosk.exe rename to Rebound/Rebound11Files/Executables/rosk.exe diff --git a/ReboundHub/Rebound11Files/Executables/rrun.exe b/Rebound/Rebound11Files/Executables/rrun.exe similarity index 100% rename from ReboundHub/Rebound11Files/Executables/rrun.exe rename to Rebound/Rebound11Files/Executables/rrun.exe diff --git a/ReboundHub/Rebound11Files/Executables/rrunSTARTUP.exe b/Rebound/Rebound11Files/Executables/rrunSTARTUP.exe similarity index 100% rename from ReboundHub/Rebound11Files/Executables/rrunSTARTUP.exe rename to Rebound/Rebound11Files/Executables/rrunSTARTUP.exe diff --git a/ReboundHub/Rebound11Files/Executables/rtpm.exe b/Rebound/Rebound11Files/Executables/rtpm.exe similarity index 100% rename from ReboundHub/Rebound11Files/Executables/rtpm.exe rename to Rebound/Rebound11Files/Executables/rtpm.exe diff --git a/ReboundHub/Rebound11Files/Executables/ruacsettings.exe b/Rebound/Rebound11Files/Executables/ruacsettings.exe similarity index 100% rename from ReboundHub/Rebound11Files/Executables/ruacsettings.exe rename to Rebound/Rebound11Files/Executables/ruacsettings.exe diff --git a/ReboundHub/Rebound11Files/Executables/rwinver.exe b/Rebound/Rebound11Files/Executables/rwinver.exe similarity index 100% rename from ReboundHub/Rebound11Files/Executables/rwinver.exe rename to Rebound/Rebound11Files/Executables/rwinver.exe diff --git a/ReboundHub/Rebound11Files/Rebound11/desktop2.ini b/Rebound/Rebound11Files/Rebound11/desktop2.ini similarity index 100% rename from ReboundHub/Rebound11Files/Rebound11/desktop2.ini rename to Rebound/Rebound11Files/Rebound11/desktop2.ini diff --git a/Rebound/Rebound11Files/Rebound11/r11foldericon.ico b/Rebound/Rebound11Files/Rebound11/r11foldericon.ico new file mode 100644 index 0000000..ec71303 Binary files /dev/null and b/Rebound/Rebound11Files/Rebound11/r11foldericon.ico differ diff --git a/ReboundHub/Rebound11Files/Rebound11/r11imageres.dll b/Rebound/Rebound11Files/Rebound11/r11imageres.dll similarity index 100% rename from ReboundHub/Rebound11Files/Rebound11/r11imageres.dll rename to Rebound/Rebound11Files/Rebound11/r11imageres.dll diff --git a/ReboundHub/Rebound11Files/Scripts/CREATERE11TOOLSFOLDER.ps1 b/Rebound/Rebound11Files/Scripts/CREATERE11TOOLSFOLDER.ps1 similarity index 100% rename from ReboundHub/Rebound11Files/Scripts/CREATERE11TOOLSFOLDER.ps1 rename to Rebound/Rebound11Files/Scripts/CREATERE11TOOLSFOLDER.ps1 diff --git a/ReboundHub/Rebound11Files/shcre11/Change User Account Control settings.lnk b/Rebound/Rebound11Files/shcre11/Change User Account Control settings.lnk similarity index 100% rename from ReboundHub/Rebound11Files/shcre11/Change User Account Control settings.lnk rename to Rebound/Rebound11Files/shcre11/Change User Account Control settings.lnk diff --git a/ReboundHub/Rebound11Files/shcre11/Control Panel.lnk b/Rebound/Rebound11Files/shcre11/Control Panel.lnk similarity index 100% rename from ReboundHub/Rebound11Files/shcre11/Control Panel.lnk rename to Rebound/Rebound11Files/shcre11/Control Panel.lnk diff --git a/ReboundHub/Rebound11Files/shcre11/Disk Cleanup.lnk b/Rebound/Rebound11Files/shcre11/Disk Cleanup.lnk similarity index 100% rename from ReboundHub/Rebound11Files/shcre11/Disk Cleanup.lnk rename to Rebound/Rebound11Files/shcre11/Disk Cleanup.lnk diff --git a/ReboundHub/Rebound11Files/shcre11/On-Screen Keyboard.lnk b/Rebound/Rebound11Files/shcre11/On-Screen Keyboard.lnk similarity index 100% rename from ReboundHub/Rebound11Files/shcre11/On-Screen Keyboard.lnk rename to Rebound/Rebound11Files/shcre11/On-Screen Keyboard.lnk diff --git a/ReboundHub/Rebound11Files/shcre11/Rebound 11 Quick Full Computer Cleanup.lnk b/Rebound/Rebound11Files/shcre11/Rebound 11 Quick Full Computer Cleanup.lnk similarity index 100% rename from ReboundHub/Rebound11Files/shcre11/Rebound 11 Quick Full Computer Cleanup.lnk rename to Rebound/Rebound11Files/shcre11/Rebound 11 Quick Full Computer Cleanup.lnk diff --git a/ReboundHub/Rebound11Files/shcre11/ReboundRunStartup.lnk b/Rebound/Rebound11Files/shcre11/Rebound.RunStartup.lnk similarity index 100% rename from ReboundHub/Rebound11Files/shcre11/ReboundRunStartup.lnk rename to Rebound/Rebound11Files/shcre11/Rebound.RunStartup.lnk diff --git a/ReboundHub/Rebound11Files/shcre11/Run.lnk b/Rebound/Rebound11Files/shcre11/Run.lnk similarity index 100% rename from ReboundHub/Rebound11Files/shcre11/Run.lnk rename to Rebound/Rebound11Files/shcre11/Run.lnk diff --git a/ReboundHub/Rebound11Files/shcre11/dfrgui.lnk b/Rebound/Rebound11Files/shcre11/dfrgui.lnk similarity index 100% rename from ReboundHub/Rebound11Files/shcre11/dfrgui.lnk rename to Rebound/Rebound11Files/shcre11/dfrgui.lnk diff --git a/ReboundHub/Rebound11Files/shcre11/tpm.msc.lnk b/Rebound/Rebound11Files/shcre11/tpm.msc.lnk similarity index 100% rename from ReboundHub/Rebound11Files/shcre11/tpm.msc.lnk rename to Rebound/Rebound11Files/shcre11/tpm.msc.lnk diff --git a/ReboundHub/Rebound11Files/shcre11/winver.lnk b/Rebound/Rebound11Files/shcre11/winver.lnk similarity index 100% rename from ReboundHub/Rebound11Files/shcre11/winver.lnk rename to Rebound/Rebound11Files/shcre11/winver.lnk diff --git a/ReboundHub/Rebound11Files/shcwin11/Administrative Tools.lnk b/Rebound/Rebound11Files/shcwin11/Administrative Tools.lnk similarity index 100% rename from ReboundHub/Rebound11Files/shcwin11/Administrative Tools.lnk rename to Rebound/Rebound11Files/shcwin11/Administrative Tools.lnk diff --git a/ReboundHub/Rebound11Files/shcwin11/Command Prompt.lnk b/Rebound/Rebound11Files/shcwin11/Command Prompt.lnk similarity index 100% rename from ReboundHub/Rebound11Files/shcwin11/Command Prompt.lnk rename to Rebound/Rebound11Files/shcwin11/Command Prompt.lnk diff --git a/ReboundHub/Rebound11Files/shcwin11/Control Panel.lnk b/Rebound/Rebound11Files/shcwin11/Control Panel.lnk similarity index 100% rename from ReboundHub/Rebound11Files/shcwin11/Control Panel.lnk rename to Rebound/Rebound11Files/shcwin11/Control Panel.lnk diff --git a/ReboundHub/Rebound11Files/shcwin11/Disk Cleanup.lnk b/Rebound/Rebound11Files/shcwin11/Disk Cleanup.lnk similarity index 100% rename from ReboundHub/Rebound11Files/shcwin11/Disk Cleanup.lnk rename to Rebound/Rebound11Files/shcwin11/Disk Cleanup.lnk diff --git a/ReboundHub/Rebound11Files/shcwin11/On-Screen Keyboard.lnk b/Rebound/Rebound11Files/shcwin11/On-Screen Keyboard.lnk similarity index 100% rename from ReboundHub/Rebound11Files/shcwin11/On-Screen Keyboard.lnk rename to Rebound/Rebound11Files/shcwin11/On-Screen Keyboard.lnk diff --git a/ReboundHub/Rebound11Files/shcwin11/Run.lnk b/Rebound/Rebound11Files/shcwin11/Run.lnk similarity index 100% rename from ReboundHub/Rebound11Files/shcwin11/Run.lnk rename to Rebound/Rebound11Files/shcwin11/Run.lnk diff --git a/ReboundHub/Rebound11Files/shcwin11/desktop.ini b/Rebound/Rebound11Files/shcwin11/desktop.ini similarity index 100% rename from ReboundHub/Rebound11Files/shcwin11/desktop.ini rename to Rebound/Rebound11Files/shcwin11/desktop.ini diff --git a/ReboundHub/Rebound11Files/shcwin11/dfrgui.lnk b/Rebound/Rebound11Files/shcwin11/dfrgui.lnk similarity index 100% rename from ReboundHub/Rebound11Files/shcwin11/dfrgui.lnk rename to Rebound/Rebound11Files/shcwin11/dfrgui.lnk diff --git a/ReboundHub/RegionBlock.xaml b/Rebound/RegionBlock.xaml similarity index 89% rename from ReboundHub/RegionBlock.xaml rename to Rebound/RegionBlock.xaml index 0a97e41..06786dc 100644 --- a/ReboundHub/RegionBlock.xaml +++ b/Rebound/RegionBlock.xaml @@ -1,9 +1,9 @@ diff --git a/ReboundHub/RegionBlock.xaml.cs b/Rebound/RegionBlock.xaml.cs similarity index 99% rename from ReboundHub/RegionBlock.xaml.cs rename to Rebound/RegionBlock.xaml.cs index a37dcb6..fe3e544 100644 --- a/ReboundHub/RegionBlock.xaml.cs +++ b/Rebound/RegionBlock.xaml.cs @@ -22,7 +22,7 @@ // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. -namespace ReboundHub; +namespace Rebound; /// /// An empty window that can be used on its own or navigated to within a Frame. /// diff --git a/ReboundHub/UACWindow.xaml b/Rebound/UACWindow.xaml similarity index 98% rename from ReboundHub/UACWindow.xaml rename to Rebound/UACWindow.xaml index becac5a..7d6e1f7 100644 --- a/ReboundHub/UACWindow.xaml +++ b/Rebound/UACWindow.xaml @@ -1,9 +1,9 @@ /// An empty window that can be used on its own or navigated to within a Frame. /// diff --git a/ReboundHub/UninstallationWindow.xaml b/Rebound/UninstallationWindow.xaml similarity index 96% rename from ReboundHub/UninstallationWindow.xaml rename to Rebound/UninstallationWindow.xaml index 9861f6e..1202a3d 100644 --- a/ReboundHub/UninstallationWindow.xaml +++ b/Rebound/UninstallationWindow.xaml @@ -1,9 +1,9 @@ /// An empty window that can be used on its own or navigated to within a Frame. /// @@ -134,7 +134,7 @@ await UninstallAppPackage( await DeleteShortcut( "Rebound Run", - $@"{Environment.GetFolderPath(Environment.SpecialFolder.StartMenu)}\Programs\Startup\ReboundRunStartup.lnk", + $@"{Environment.GetFolderPath(Environment.SpecialFolder.StartMenu)}\Programs\Startup\Rebound.RunStartup.lnk", "Rebound Run"); await UninstallAppPackage( diff --git a/ReboundHub/app.manifest b/Rebound/app.manifest similarity index 95% rename from ReboundHub/app.manifest rename to Rebound/app.manifest index fa24770..57be6f7 100644 --- a/ReboundHub/app.manifest +++ b/Rebound/app.manifest @@ -1,6 +1,6 @@ - + diff --git a/ReboundHub.sln b/ReboundHub.sln deleted file mode 100644 index 4b57f58..0000000 --- a/ReboundHub.sln +++ /dev/null @@ -1,43 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.9.34616.47 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReboundHub", "ReboundHub\ReboundHub.csproj", "{4C58BAB7-F9D6-48AB-B20D-C8F6413D6E34}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|ARM64 = Debug|ARM64 - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|ARM64 = Release|ARM64 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {4C58BAB7-F9D6-48AB-B20D-C8F6413D6E34}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {4C58BAB7-F9D6-48AB-B20D-C8F6413D6E34}.Debug|ARM64.Build.0 = Debug|ARM64 - {4C58BAB7-F9D6-48AB-B20D-C8F6413D6E34}.Debug|ARM64.Deploy.0 = Debug|ARM64 - {4C58BAB7-F9D6-48AB-B20D-C8F6413D6E34}.Debug|x64.ActiveCfg = Debug|x64 - {4C58BAB7-F9D6-48AB-B20D-C8F6413D6E34}.Debug|x64.Build.0 = Debug|x64 - {4C58BAB7-F9D6-48AB-B20D-C8F6413D6E34}.Debug|x64.Deploy.0 = Debug|x64 - {4C58BAB7-F9D6-48AB-B20D-C8F6413D6E34}.Debug|x86.ActiveCfg = Debug|x86 - {4C58BAB7-F9D6-48AB-B20D-C8F6413D6E34}.Debug|x86.Build.0 = Debug|x86 - {4C58BAB7-F9D6-48AB-B20D-C8F6413D6E34}.Debug|x86.Deploy.0 = Debug|x86 - {4C58BAB7-F9D6-48AB-B20D-C8F6413D6E34}.Release|ARM64.ActiveCfg = Release|ARM64 - {4C58BAB7-F9D6-48AB-B20D-C8F6413D6E34}.Release|ARM64.Build.0 = Release|ARM64 - {4C58BAB7-F9D6-48AB-B20D-C8F6413D6E34}.Release|ARM64.Deploy.0 = Release|ARM64 - {4C58BAB7-F9D6-48AB-B20D-C8F6413D6E34}.Release|x64.ActiveCfg = Release|x64 - {4C58BAB7-F9D6-48AB-B20D-C8F6413D6E34}.Release|x64.Build.0 = Release|x64 - {4C58BAB7-F9D6-48AB-B20D-C8F6413D6E34}.Release|x64.Deploy.0 = Release|x64 - {4C58BAB7-F9D6-48AB-B20D-C8F6413D6E34}.Release|x86.ActiveCfg = Release|x86 - {4C58BAB7-F9D6-48AB-B20D-C8F6413D6E34}.Release|x86.Build.0 = Release|x86 - {4C58BAB7-F9D6-48AB-B20D-C8F6413D6E34}.Release|x86.Deploy.0 = Release|x86 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {F46D9F10-D75A-4C1E-99F0-14EE79D20EDE} - EndGlobalSection -EndGlobal diff --git a/ReboundHub/Rebound11Files/AppPackages/ReboundDefrag.cer b/ReboundHub/Rebound11Files/AppPackages/ReboundDefrag.cer deleted file mode 100644 index 1aee9dc..0000000 Binary files a/ReboundHub/Rebound11Files/AppPackages/ReboundDefrag.cer and /dev/null differ diff --git a/ReboundHub/Rebound11Files/AppPackages/ReboundDefrag.msix b/ReboundHub/Rebound11Files/AppPackages/ReboundDefrag.msix deleted file mode 100644 index a9b063b..0000000 --- a/ReboundHub/Rebound11Files/AppPackages/ReboundDefrag.msix +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:4b2d586afd6764cdb3898ef652c16c094482a23cb0836f9c651717650916e829 -size 96172578 diff --git a/ReboundHub/Rebound11Files/AppPackages/ReboundDiskCleanup.cer b/ReboundHub/Rebound11Files/AppPackages/ReboundDiskCleanup.cer deleted file mode 100644 index 79f7014..0000000 Binary files a/ReboundHub/Rebound11Files/AppPackages/ReboundDiskCleanup.cer and /dev/null differ diff --git a/ReboundHub/Rebound11Files/AppPackages/ReboundDiskCleanup.msix b/ReboundHub/Rebound11Files/AppPackages/ReboundDiskCleanup.msix deleted file mode 100644 index 3593a44..0000000 --- a/ReboundHub/Rebound11Files/AppPackages/ReboundDiskCleanup.msix +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:bf81c78938d20e7b88c332d80265c1a89e41f5332bd6c3255168fadff8f036ed -size 44798335 diff --git a/ReboundHub/Rebound11Files/AppPackages/ReboundRun.cer b/ReboundHub/Rebound11Files/AppPackages/ReboundRun.cer deleted file mode 100644 index 9dfc006..0000000 Binary files a/ReboundHub/Rebound11Files/AppPackages/ReboundRun.cer and /dev/null differ diff --git a/ReboundHub/Rebound11Files/AppPackages/ReboundRun.msix b/ReboundHub/Rebound11Files/AppPackages/ReboundRun.msix deleted file mode 100644 index 7820d69..0000000 --- a/ReboundHub/Rebound11Files/AppPackages/ReboundRun.msix +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:14425a097d83010cd46929310a59d7818cccdfac3c63dc76fb57748e65af4294 -size 45056401 diff --git a/ReboundHub/Rebound11Files/AppPackages/ReboundTpm.cer b/ReboundHub/Rebound11Files/AppPackages/ReboundTpm.cer deleted file mode 100644 index e1d1f44..0000000 Binary files a/ReboundHub/Rebound11Files/AppPackages/ReboundTpm.cer and /dev/null differ diff --git a/ReboundHub/Rebound11Files/AppPackages/ReboundTpm.msix b/ReboundHub/Rebound11Files/AppPackages/ReboundTpm.msix deleted file mode 100644 index 162418a..0000000 --- a/ReboundHub/Rebound11Files/AppPackages/ReboundTpm.msix +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:68e88191d66712bda3eb7b49769f3f96840871a4a9d8e92039b838888765d839 -size 68175764 diff --git a/ReboundHub/Rebound11Files/AppPackages/ReboundWinver.cer b/ReboundHub/Rebound11Files/AppPackages/ReboundWinver.cer deleted file mode 100644 index 26e18c6..0000000 Binary files a/ReboundHub/Rebound11Files/AppPackages/ReboundWinver.cer and /dev/null differ diff --git a/ReboundHub/Rebound11Files/AppPackages/ReboundWinver.msix b/ReboundHub/Rebound11Files/AppPackages/ReboundWinver.msix deleted file mode 100644 index af6478d..0000000 --- a/ReboundHub/Rebound11Files/AppPackages/ReboundWinver.msix +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:35a1ee585e28dfed0dcc25099be5086457f50ab4b7e6c8da1a84719a30b3847d -size 44999039 diff --git a/ReboundHub/Rebound11Files/Executables/QuickFullComputerCleanup.exe b/ReboundHub/Rebound11Files/Executables/QuickFullComputerCleanup.exe deleted file mode 100644 index 97b1d30..0000000 Binary files a/ReboundHub/Rebound11Files/Executables/QuickFullComputerCleanup.exe and /dev/null differ diff --git a/Run/App.xaml b/Run/App.xaml new file mode 100644 index 0000000..2a70101 --- /dev/null +++ b/Run/App.xaml @@ -0,0 +1,16 @@ + + + + + + + + + + + + diff --git a/Run/App.xaml.cs b/Run/App.xaml.cs new file mode 100644 index 0000000..01e88df --- /dev/null +++ b/Run/App.xaml.cs @@ -0,0 +1,288 @@ +using IWshRuntimeLibrary; +using Microsoft.UI.Xaml; +using Rebound.Run.Helpers; +using System; +using System.Diagnostics; +using System.Linq; +using System.Runtime.InteropServices; +using System.Threading.Tasks; +using Windows.System; +using Windows.UI.Input.Preview.Injection; +using WinUIEx; +using File = System.IO.File; +using Task = System.Threading.Tasks.Task; + +#nullable enable +#pragma warning disable CA2211 // Non-constant fields should not be visible + +namespace Rebound.Run +{ + public partial class App : Application + { + private readonly SingleInstanceDesktopApp _singleInstanceApp; + + public App() + { + this?.InitializeComponent(); + + _singleInstanceApp = new SingleInstanceDesktopApp("Rebound.Run"); + _singleInstanceApp.Launched += OnSingleInstanceLaunched; + } + + public static WindowEx? BackgroundWindow { get; set; } + + protected override void OnLaunched(LaunchActivatedEventArgs args) + { + _singleInstanceApp?.Launch(args.Arguments); + } + + private async void OnSingleInstanceLaunched(object? sender, SingleInstanceLaunchEventArgs e) + { + if (e.IsFirstLaunch) + { + await LaunchWork(); + } + else + { + // Get the current process + Process currentProcess = Process.GetCurrentProcess(); + + // Start a new instance of the application + if (currentProcess.MainModule != null) Process.Start(currentProcess.MainModule.FileName); + + // Terminate the current process + currentProcess?.Kill(); + return; + } + } + + public async Task LaunchWork() + { + CreateShortcut(); + + // Initialize the background window + InitializeBackgroundWindow(); + + MainWindow = new MainWindow(); + + // Register any background tasks or hooks + StartHook(); + + // Delay for task execution + await Task.Delay(5); + + // Check if Windows hotkey shortcuts are disabled by group policy + if (GroupPolicyHelper.IsGroupPolicyEnabled(GroupPolicyHelper.EXPLORER_GROUP_POLICY_PATH, "NoWinKeys", 1) == true) + { + StopHook(); + } + + // If started with the "STARTUP" argument, exit early + if (IsStartupArgumentPresent()) + { + return 0; + } + + // Try to activate the main window + await ActivateMainWindowAsync(); + + return 0; + } + + private static void InitializeBackgroundWindow() + { + try + { + BackgroundWindow = new() + { + SystemBackdrop = new TransparentTintBackdrop(), + IsMaximizable = false + }; + BackgroundWindow?.SetExtendedWindowStyle(ExtendedWindowStyle.ToolWindow); + BackgroundWindow?.SetWindowStyle(WindowStyle.Visible); + BackgroundWindow?.Activate(); + BackgroundWindow?.MoveAndResize(0, 0, 0, 0); + BackgroundWindow?.Minimize(); + BackgroundWindow?.SetWindowOpacity(0); + } + catch + { + + } + } + + private static bool IsStartupArgumentPresent() + { + return string.Join(" ", Environment.GetCommandLineArgs().Skip(1)).Contains("STARTUP"); + } + + private static async Task ActivateMainWindowAsync() + { + try + { + MainWindow?.Activate(); + } + catch + { + // Handle activation error + } + + await Task.Delay(100); // Ensure main window focus + + try + { + MainWindow?.Activate(); // Reactivate to ensure focus + } + catch + { + // Handle activation error + } + + MainWindow?.Show(); // Ensure window is visible + + // Bring to front explicitly + ((WindowEx?)MainWindow)?.BringToFront(); + } + + private void CreateShortcut() + { + string startupFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); + string oldShortcutPath = System.IO.Path.Combine(startupFolderPath, "Rebound.Run.lnk"); + try + { + File.Delete(oldShortcutPath); + } + catch + { + + } + string shortcutPath = System.IO.Path.Combine(startupFolderPath, "Rebound.RunStartup.lnk"); + if (!File.Exists(shortcutPath)) + { + WshShell shell = new(); + IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutPath); + shortcut.Description = "Rebound Run"; + shortcut.TargetPath = "C:\\Rebound11\\rrunSTARTUP.exe"; + shortcut?.Save(); + } + } + + public static void StartHook() + { + Win32Helper.keyboardProc = HookCallback; + Win32Helper.hookId = SetHook(Win32Helper.keyboardProc); + } + + public static void StopHook() + { + Win32Helper.UnhookWindowsHookEx(Win32Helper.hookId); + } + + public static bool AllowClosingRunBox { get; set; } = true; + + private static IntPtr SetHook(Win32Helper.LowLevelKeyboardProc proc) + { + using (Process curProcess = Process.GetCurrentProcess()) + { + if (curProcess.MainModule != null) + { + using (ProcessModule curModule = curProcess.MainModule) + { + return Win32Helper.SetWindowsHookEx(Win32Helper.WH_KEYBOARD_LL, proc, Win32Helper.GetModuleHandle(curModule.ModuleName), 0); + } + } + } + return IntPtr.Zero; + } + + private static bool winKeyPressed = false; + private static bool rKeyPressed = false; + + private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) + { + if (nCode >= 0) + { + int vkCode = Marshal.ReadInt32(lParam); + + // Check for keydown events + if (wParam == Win32Helper.WM_KEYDOWN) + { + // Check if Windows key is pressed + if (vkCode is Win32Helper.VK_LWIN or Win32Helper.VK_RWIN) + { + winKeyPressed = true; + } + + // Check if 'R' key is pressed + if (vkCode is Win32Helper.VK_R) + { + rKeyPressed = true; + + // If both Win and R are pressed, show the window + if (winKeyPressed) + { + ((WindowEx?)MainWindow)?.Show(); + ((WindowEx?)MainWindow)?.BringToFront(); + try + { + ((WindowEx?)MainWindow)?.Activate(); + } + catch + { + MainWindow = new MainWindow(); + MainWindow.Show(); + ((WindowEx?)MainWindow)?.Activate(); + ((WindowEx?)MainWindow)?.BringToFront(); + } + + // Prevent default behavior of Win + R + return 1; + } + } + } + + // Check for keyup events + if (wParam == Win32Helper.WM_KEYUP) + { + // Check if Windows key is released + if (vkCode is Win32Helper.VK_LWIN or Win32Helper.VK_RWIN) + { + winKeyPressed = false; + + // Suppress the Windows Start menu if 'R' is still pressed + if (rKeyPressed == true) + { + ForceReleaseWin(); + return 1; // Prevent Windows menu from appearing + } + } + + // Check if 'R' key is released + if (vkCode is Win32Helper.VK_R) + { + rKeyPressed = false; + } + } + } + + return Win32Helper.CallNextHookEx(Win32Helper.hookId, nCode, wParam, lParam); + } + + public static async void ForceReleaseWin() + { + await Task.Delay(10); + + var inj = InputInjector.TryCreate(); + var info = new InjectedInputKeyboardInfo + { + VirtualKey = (ushort)VirtualKey.LeftWindows, + KeyOptions = InjectedInputKeyOptions.KeyUp + }; + var infoList = new[] { info }; + + inj.InjectKeyboardInput(infoList); + } + + public static Window? MainWindow; + } +} diff --git a/Run/Assets/Administrator.ico b/Run/Assets/Administrator.ico new file mode 100644 index 0000000..3ac3b0e Binary files /dev/null and b/Run/Assets/Administrator.ico differ diff --git a/Run/Assets/ClassicEXE.ico b/Run/Assets/ClassicEXE.ico new file mode 100644 index 0000000..e2fd246 Binary files /dev/null and b/Run/Assets/ClassicEXE.ico differ diff --git a/Run/Assets/EXE.ico b/Run/Assets/EXE.ico new file mode 100644 index 0000000..978234c Binary files /dev/null and b/Run/Assets/EXE.ico differ diff --git a/Run/Assets/LargeTile.scale-100.png b/Run/Assets/LargeTile.scale-100.png new file mode 100644 index 0000000..7f2088d Binary files /dev/null and b/Run/Assets/LargeTile.scale-100.png differ diff --git a/Run/Assets/LargeTile.scale-125.png b/Run/Assets/LargeTile.scale-125.png new file mode 100644 index 0000000..552dbc4 Binary files /dev/null and b/Run/Assets/LargeTile.scale-125.png differ diff --git a/Run/Assets/LargeTile.scale-150.png b/Run/Assets/LargeTile.scale-150.png new file mode 100644 index 0000000..3922ad8 Binary files /dev/null and b/Run/Assets/LargeTile.scale-150.png differ diff --git a/Run/Assets/LargeTile.scale-200.png b/Run/Assets/LargeTile.scale-200.png new file mode 100644 index 0000000..7b267b3 Binary files /dev/null and b/Run/Assets/LargeTile.scale-200.png differ diff --git a/Run/Assets/LargeTile.scale-400.png b/Run/Assets/LargeTile.scale-400.png new file mode 100644 index 0000000..92846c0 Binary files /dev/null and b/Run/Assets/LargeTile.scale-400.png differ diff --git a/Run/Assets/LockScreenLogo.scale-200.png b/Run/Assets/LockScreenLogo.scale-200.png new file mode 100644 index 0000000..7440f0d Binary files /dev/null and b/Run/Assets/LockScreenLogo.scale-200.png differ diff --git a/Run/Assets/RunBox.ico b/Run/Assets/RunBox.ico new file mode 100644 index 0000000..5d1935f Binary files /dev/null and b/Run/Assets/RunBox.ico differ diff --git a/Run/Assets/RunBox.png b/Run/Assets/RunBox.png new file mode 100644 index 0000000..968dc8a Binary files /dev/null and b/Run/Assets/RunBox.png differ diff --git a/Run/Assets/SmallTile.scale-100.png b/Run/Assets/SmallTile.scale-100.png new file mode 100644 index 0000000..5800dd3 Binary files /dev/null and b/Run/Assets/SmallTile.scale-100.png differ diff --git a/Run/Assets/SmallTile.scale-125.png b/Run/Assets/SmallTile.scale-125.png new file mode 100644 index 0000000..a32dc96 Binary files /dev/null and b/Run/Assets/SmallTile.scale-125.png differ diff --git a/Run/Assets/SmallTile.scale-150.png b/Run/Assets/SmallTile.scale-150.png new file mode 100644 index 0000000..6168ddd Binary files /dev/null and b/Run/Assets/SmallTile.scale-150.png differ diff --git a/Run/Assets/SmallTile.scale-200.png b/Run/Assets/SmallTile.scale-200.png new file mode 100644 index 0000000..740ac50 Binary files /dev/null and b/Run/Assets/SmallTile.scale-200.png differ diff --git a/Run/Assets/SmallTile.scale-400.png b/Run/Assets/SmallTile.scale-400.png new file mode 100644 index 0000000..2cb1868 Binary files /dev/null and b/Run/Assets/SmallTile.scale-400.png differ diff --git a/Run/Assets/SplashScreen.scale-100.png b/Run/Assets/SplashScreen.scale-100.png new file mode 100644 index 0000000..3ebdc58 Binary files /dev/null and b/Run/Assets/SplashScreen.scale-100.png differ diff --git a/Run/Assets/SplashScreen.scale-125.png b/Run/Assets/SplashScreen.scale-125.png new file mode 100644 index 0000000..cf9eaef Binary files /dev/null and b/Run/Assets/SplashScreen.scale-125.png differ diff --git a/Run/Assets/SplashScreen.scale-150.png b/Run/Assets/SplashScreen.scale-150.png new file mode 100644 index 0000000..d1c8709 Binary files /dev/null and b/Run/Assets/SplashScreen.scale-150.png differ diff --git a/Run/Assets/SplashScreen.scale-200.png b/Run/Assets/SplashScreen.scale-200.png new file mode 100644 index 0000000..cf871d0 Binary files /dev/null and b/Run/Assets/SplashScreen.scale-200.png differ diff --git a/Run/Assets/SplashScreen.scale-400.png b/Run/Assets/SplashScreen.scale-400.png new file mode 100644 index 0000000..e721af6 Binary files /dev/null and b/Run/Assets/SplashScreen.scale-400.png differ diff --git a/Run/Assets/Square150x150Logo.scale-100.png b/Run/Assets/Square150x150Logo.scale-100.png new file mode 100644 index 0000000..34379a7 Binary files /dev/null and b/Run/Assets/Square150x150Logo.scale-100.png differ diff --git a/Run/Assets/Square150x150Logo.scale-125.png b/Run/Assets/Square150x150Logo.scale-125.png new file mode 100644 index 0000000..d33ab0f Binary files /dev/null and b/Run/Assets/Square150x150Logo.scale-125.png differ diff --git a/Run/Assets/Square150x150Logo.scale-150.png b/Run/Assets/Square150x150Logo.scale-150.png new file mode 100644 index 0000000..83b04a9 Binary files /dev/null and b/Run/Assets/Square150x150Logo.scale-150.png differ diff --git a/Run/Assets/Square150x150Logo.scale-200.png b/Run/Assets/Square150x150Logo.scale-200.png new file mode 100644 index 0000000..c33a96f Binary files /dev/null and b/Run/Assets/Square150x150Logo.scale-200.png differ diff --git a/Run/Assets/Square150x150Logo.scale-400.png b/Run/Assets/Square150x150Logo.scale-400.png new file mode 100644 index 0000000..4cb91e7 Binary files /dev/null and b/Run/Assets/Square150x150Logo.scale-400.png differ diff --git a/Run/Assets/Square44x44Logo.altform-lightunplated_targetsize-16.png b/Run/Assets/Square44x44Logo.altform-lightunplated_targetsize-16.png new file mode 100644 index 0000000..7545ceb Binary files /dev/null and b/Run/Assets/Square44x44Logo.altform-lightunplated_targetsize-16.png differ diff --git a/Run/Assets/Square44x44Logo.altform-lightunplated_targetsize-24.png b/Run/Assets/Square44x44Logo.altform-lightunplated_targetsize-24.png new file mode 100644 index 0000000..da2baca Binary files /dev/null and b/Run/Assets/Square44x44Logo.altform-lightunplated_targetsize-24.png differ diff --git a/Run/Assets/Square44x44Logo.altform-lightunplated_targetsize-256.png b/Run/Assets/Square44x44Logo.altform-lightunplated_targetsize-256.png new file mode 100644 index 0000000..8094c96 Binary files /dev/null and b/Run/Assets/Square44x44Logo.altform-lightunplated_targetsize-256.png differ diff --git a/Run/Assets/Square44x44Logo.altform-lightunplated_targetsize-32.png b/Run/Assets/Square44x44Logo.altform-lightunplated_targetsize-32.png new file mode 100644 index 0000000..a43f82c Binary files /dev/null and b/Run/Assets/Square44x44Logo.altform-lightunplated_targetsize-32.png differ diff --git a/Run/Assets/Square44x44Logo.altform-lightunplated_targetsize-48.png b/Run/Assets/Square44x44Logo.altform-lightunplated_targetsize-48.png new file mode 100644 index 0000000..78951ce Binary files /dev/null and b/Run/Assets/Square44x44Logo.altform-lightunplated_targetsize-48.png differ diff --git a/Run/Assets/Square44x44Logo.altform-unplated_targetsize-16.png b/Run/Assets/Square44x44Logo.altform-unplated_targetsize-16.png new file mode 100644 index 0000000..7545ceb Binary files /dev/null and b/Run/Assets/Square44x44Logo.altform-unplated_targetsize-16.png differ diff --git a/Run/Assets/Square44x44Logo.altform-unplated_targetsize-256.png b/Run/Assets/Square44x44Logo.altform-unplated_targetsize-256.png new file mode 100644 index 0000000..8094c96 Binary files /dev/null and b/Run/Assets/Square44x44Logo.altform-unplated_targetsize-256.png differ diff --git a/Run/Assets/Square44x44Logo.altform-unplated_targetsize-32.png b/Run/Assets/Square44x44Logo.altform-unplated_targetsize-32.png new file mode 100644 index 0000000..a43f82c Binary files /dev/null and b/Run/Assets/Square44x44Logo.altform-unplated_targetsize-32.png differ diff --git a/Run/Assets/Square44x44Logo.altform-unplated_targetsize-48.png b/Run/Assets/Square44x44Logo.altform-unplated_targetsize-48.png new file mode 100644 index 0000000..78951ce Binary files /dev/null and b/Run/Assets/Square44x44Logo.altform-unplated_targetsize-48.png differ diff --git a/Run/Assets/Square44x44Logo.scale-100.png b/Run/Assets/Square44x44Logo.scale-100.png new file mode 100644 index 0000000..9996dd7 Binary files /dev/null and b/Run/Assets/Square44x44Logo.scale-100.png differ diff --git a/Run/Assets/Square44x44Logo.scale-125.png b/Run/Assets/Square44x44Logo.scale-125.png new file mode 100644 index 0000000..af90ba1 Binary files /dev/null and b/Run/Assets/Square44x44Logo.scale-125.png differ diff --git a/Run/Assets/Square44x44Logo.scale-150.png b/Run/Assets/Square44x44Logo.scale-150.png new file mode 100644 index 0000000..504ca73 Binary files /dev/null and b/Run/Assets/Square44x44Logo.scale-150.png differ diff --git a/Run/Assets/Square44x44Logo.scale-200.png b/Run/Assets/Square44x44Logo.scale-200.png new file mode 100644 index 0000000..76310c9 Binary files /dev/null and b/Run/Assets/Square44x44Logo.scale-200.png differ diff --git a/Run/Assets/Square44x44Logo.scale-400.png b/Run/Assets/Square44x44Logo.scale-400.png new file mode 100644 index 0000000..67c19d0 Binary files /dev/null and b/Run/Assets/Square44x44Logo.scale-400.png differ diff --git a/Run/Assets/Square44x44Logo.targetsize-16.png b/Run/Assets/Square44x44Logo.targetsize-16.png new file mode 100644 index 0000000..fc635fc Binary files /dev/null and b/Run/Assets/Square44x44Logo.targetsize-16.png differ diff --git a/Run/Assets/Square44x44Logo.targetsize-24.png b/Run/Assets/Square44x44Logo.targetsize-24.png new file mode 100644 index 0000000..801807e Binary files /dev/null and b/Run/Assets/Square44x44Logo.targetsize-24.png differ diff --git a/Run/Assets/Square44x44Logo.targetsize-24_altform-unplated.png b/Run/Assets/Square44x44Logo.targetsize-24_altform-unplated.png new file mode 100644 index 0000000..da2baca Binary files /dev/null and b/Run/Assets/Square44x44Logo.targetsize-24_altform-unplated.png differ diff --git a/Run/Assets/Square44x44Logo.targetsize-256.png b/Run/Assets/Square44x44Logo.targetsize-256.png new file mode 100644 index 0000000..b3492fc Binary files /dev/null and b/Run/Assets/Square44x44Logo.targetsize-256.png differ diff --git a/Run/Assets/Square44x44Logo.targetsize-32.png b/Run/Assets/Square44x44Logo.targetsize-32.png new file mode 100644 index 0000000..a7700e6 Binary files /dev/null and b/Run/Assets/Square44x44Logo.targetsize-32.png differ diff --git a/Run/Assets/Square44x44Logo.targetsize-48.png b/Run/Assets/Square44x44Logo.targetsize-48.png new file mode 100644 index 0000000..6222cab Binary files /dev/null and b/Run/Assets/Square44x44Logo.targetsize-48.png differ diff --git a/Run/Assets/StoreLogo.backup.png b/Run/Assets/StoreLogo.backup.png new file mode 100644 index 0000000..a4586f2 Binary files /dev/null and b/Run/Assets/StoreLogo.backup.png differ diff --git a/Run/Assets/StoreLogo.scale-100.png b/Run/Assets/StoreLogo.scale-100.png new file mode 100644 index 0000000..ba63df3 Binary files /dev/null and b/Run/Assets/StoreLogo.scale-100.png differ diff --git a/Run/Assets/StoreLogo.scale-125.png b/Run/Assets/StoreLogo.scale-125.png new file mode 100644 index 0000000..ed3945b Binary files /dev/null and b/Run/Assets/StoreLogo.scale-125.png differ diff --git a/Run/Assets/StoreLogo.scale-150.png b/Run/Assets/StoreLogo.scale-150.png new file mode 100644 index 0000000..05baf29 Binary files /dev/null and b/Run/Assets/StoreLogo.scale-150.png differ diff --git a/Run/Assets/StoreLogo.scale-200.png b/Run/Assets/StoreLogo.scale-200.png new file mode 100644 index 0000000..7720923 Binary files /dev/null and b/Run/Assets/StoreLogo.scale-200.png differ diff --git a/Run/Assets/StoreLogo.scale-400.png b/Run/Assets/StoreLogo.scale-400.png new file mode 100644 index 0000000..32d81d3 Binary files /dev/null and b/Run/Assets/StoreLogo.scale-400.png differ diff --git a/Run/Assets/Wide310x150Logo.scale-100.png b/Run/Assets/Wide310x150Logo.scale-100.png new file mode 100644 index 0000000..d8222f5 Binary files /dev/null and b/Run/Assets/Wide310x150Logo.scale-100.png differ diff --git a/Run/Assets/Wide310x150Logo.scale-125.png b/Run/Assets/Wide310x150Logo.scale-125.png new file mode 100644 index 0000000..0e1f906 Binary files /dev/null and b/Run/Assets/Wide310x150Logo.scale-125.png differ diff --git a/Run/Assets/Wide310x150Logo.scale-150.png b/Run/Assets/Wide310x150Logo.scale-150.png new file mode 100644 index 0000000..9076ef6 Binary files /dev/null and b/Run/Assets/Wide310x150Logo.scale-150.png differ diff --git a/Run/Assets/Wide310x150Logo.scale-200.png b/Run/Assets/Wide310x150Logo.scale-200.png new file mode 100644 index 0000000..3ebdc58 Binary files /dev/null and b/Run/Assets/Wide310x150Logo.scale-200.png differ diff --git a/Run/Assets/Wide310x150Logo.scale-400.png b/Run/Assets/Wide310x150Logo.scale-400.png new file mode 100644 index 0000000..cf871d0 Binary files /dev/null and b/Run/Assets/Wide310x150Logo.scale-400.png differ diff --git a/Run/Helpers/GroupPolicyHelper.cs b/Run/Helpers/GroupPolicyHelper.cs new file mode 100644 index 0000000..67a4a59 --- /dev/null +++ b/Run/Helpers/GroupPolicyHelper.cs @@ -0,0 +1,51 @@ +using Microsoft.Win32; +using System; + +namespace Rebound.Run.Helpers +{ + public static class GroupPolicyHelper + { + public const string EXPLORER_GROUP_POLICY_PATH = @"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"; + + public static bool? IsGroupPolicyEnabled(string path, string value, int trueValue) + { + try + { + // Path to the registry key + string registryKeyPath = path; + // Name of the value we are looking for + string valueName = value; + + // Open the registry key + using (RegistryKey key = Registry.CurrentUser.OpenSubKey(registryKeyPath)) + { + if (key != null) + { + object val = key.GetValue(valueName); + + if (val != null && (int)val == trueValue) + { + // Run box is disabled + return true; + } + else + { + // Run box is enabled + return false; + } + } + else + { + // Key not found, assume Run box is enabled + return null; + } + } + } + catch (Exception) + { + // Handle any exceptions + return null; + } + } + } +} diff --git a/Run/Helpers/SingleInstanceHelper.cs b/Run/Helpers/SingleInstanceHelper.cs new file mode 100644 index 0000000..c29049a --- /dev/null +++ b/Run/Helpers/SingleInstanceHelper.cs @@ -0,0 +1,150 @@ +using System; +using System.Diagnostics; +using System.IO.Pipes; +using System.IO; +using System.Linq; +using System.Threading; + +#nullable enable + +namespace Rebound.Run.Helpers +{ + public class SingleInstanceLaunchEventArgs(string arguments, bool isFirstLaunch) : EventArgs + { + public string Arguments { get; private set; } = arguments; + public bool IsFirstLaunch { get; private set; } = isFirstLaunch; + } + + public sealed partial class SingleInstanceDesktopApp(string appId) : IDisposable + { + private readonly string _mutexName = "MUTEX_" + appId; + private readonly string _pipeName = "PIPE_" + appId; + private readonly object _namedPiperServerThreadLock = new(); + + private bool _isDisposed = false; + private bool _isFirstInstance; + + private Mutex? _mutexApplication; + private NamedPipeServerStream? _namedPipeServerStream; + + public event EventHandler? Launched; + + public void Launch(string arguments) + { + if (string.IsNullOrEmpty(arguments)) + { + // The arguments from LaunchActivatedEventArgs can be empty, when + // the user specified arguments (e.g. when using an execution alias). For this reason we + // alternatively check for arguments using a different API. + var argList = Environment.GetCommandLineArgs(); + if (argList.Length > 1) + { + arguments = string.Join(' ', argList.Skip(1)); + } + } + + if (IsFirstApplicationInstance()) + { + CreateNamedPipeServer(); + Launched?.Invoke(this, new SingleInstanceLaunchEventArgs(arguments, isFirstLaunch: true)); + } + else + { + SendArgumentsToRunningInstance(arguments); + + Process.GetCurrentProcess().Kill(); + // Note: needed to kill the process in WinAppSDK 1.0, since Application.Current.Exit() does not work there. + // OR: Application.Current.Exit(); + } + } + + public void Dispose() + { + if (_isDisposed) + return; + + _isDisposed = true; + + _namedPipeServerStream?.Dispose(); + _mutexApplication?.Dispose(); + } + + private bool IsFirstApplicationInstance() + { + // Allow for multiple runs but only try and get the mutex once + _mutexApplication ??= new Mutex(true, _mutexName, out _isFirstInstance); + + return _isFirstInstance; + } + + /// + /// Starts a new pipe server if one isn't already active. + /// + private void CreateNamedPipeServer() + { + _namedPipeServerStream = new NamedPipeServerStream( + _pipeName, PipeDirection.In, + maxNumberOfServerInstances: 1, + PipeTransmissionMode.Byte, + PipeOptions.Asynchronous, + inBufferSize: 0, + outBufferSize: 0); + + _namedPipeServerStream.BeginWaitForConnection(OnNamedPipeServerConnected, _namedPipeServerStream); + } + + private void SendArgumentsToRunningInstance(string arguments) + { + try + { + using var namedPipeClientStream = new NamedPipeClientStream(".", _pipeName, PipeDirection.Out); + namedPipeClientStream.Connect(3000); // Maximum wait 3 seconds + using var sw = new StreamWriter(namedPipeClientStream); + sw.Write(arguments); + sw.Flush(); + } + catch (Exception) + { + // Error connecting or sending + } + } + + private void OnNamedPipeServerConnected(IAsyncResult asyncResult) + { + try + { + if (_namedPipeServerStream == null) + return; + + _namedPipeServerStream.EndWaitForConnection(asyncResult); + + // Read the arguments from the pipe + lock (_namedPiperServerThreadLock) + { + using var sr = new StreamReader(_namedPipeServerStream); + var args = sr.ReadToEnd(); + Launched?.Invoke(this, new SingleInstanceLaunchEventArgs(args, isFirstLaunch: false)); + } + } + catch (ObjectDisposedException) + { + // EndWaitForConnection will throw when the pipe closes before there is a connection. + // In that case, we don't create more pipes and just return. + // This will happen when the app is closed and therefor the pipe is closed as well. + return; + } + catch (Exception) + { + // ignored + } + finally + { + // Close the original pipe (we will create a new one each time) + _namedPipeServerStream?.Dispose(); + } + + // Create a new pipe for next connection + CreateNamedPipeServer(); + } + } +} diff --git a/Run/Helpers/Win32Helper.cs b/Run/Helpers/Win32Helper.cs new file mode 100644 index 0000000..5fffa71 --- /dev/null +++ b/Run/Helpers/Win32Helper.cs @@ -0,0 +1,50 @@ +using System; +using System.Runtime.InteropServices; + +#pragma warning disable CA2211 // Non-constant fields should not be visible +#pragma warning disable CA1401 // P/Invokes should not be visible +#pragma warning disable SYSLIB1054 // Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time +#nullable enable + +namespace Rebound.Run.Helpers +{ + public static partial class Win32Helper + { + public const uint WM_CLOSE = 0x0010; + public const int WH_KEYBOARD_LL = 13; + public const int WM_KEYDOWN = 0x0100; + public const int WM_KEYUP = 0x0101; + public const int VK_R = 0x52; + public const int VK_LWIN = 0x5B; + public const int VK_RWIN = 0x5C; + public const int INPUT_KEYBOARD = 1; + public const int KEYEVENTF_KEYUP = 0x0002; + + public static IntPtr hookId = IntPtr.Zero; + public static LowLevelKeyboardProc? keyboardProc; + public delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam); + + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] + public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); + + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] + public static extern IntPtr FindWindow(string? lpClassName, string? lpWindowName); + + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); + + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] + public static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId); + + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool UnhookWindowsHookEx(IntPtr hhk); + + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] + public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam); + + [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] + public static extern IntPtr GetModuleHandle(string lpModuleName); + } +} diff --git a/Run/Languages/StringTable.cs b/Run/Languages/StringTable.cs new file mode 100644 index 0000000..80359ae --- /dev/null +++ b/Run/Languages/StringTable.cs @@ -0,0 +1,54 @@ +using System.Globalization; + +namespace Rebound.Run.Languages +{ + public class StringTable + { + public static string AppTitle; + public static string Run; + public static string RunAsAdmin; + public static string Description; + public static string Open; + public static string Arguments; + public static string Cancel; + public static string Browse; + + public StringTable() + { + ReadLanguage(); + } + + public static void ReadLanguage() + { + // Get the current culture (language) of the system + CultureInfo currentCulture = CultureInfo.CurrentUICulture; + if (currentCulture.Name.ToLower() == "en-us") + { + AppTitle = "Rebound Run"; + Run = "Run"; + RunAsAdmin = "Run as Administrator"; + Description = "Type the name of a program, folder, document, or Internet resource, and Windows will open it for you."; + Open = "Open"; + Arguments = "Arguments"; + Cancel = "Cancel"; + Browse = "Browse"; + } + if (currentCulture.Name.ToLower() == "ro-ro") + { + AppTitle = "Executare Rebound"; + Run = "Execută"; + } + if (currentCulture.Name.ToLower() == "de-de") + { + AppTitle = "Rebound Ausführen"; + Run = "Ausführen"; + RunAsAdmin = "Als Administrator ausführen"; + Description = "Geben Sie den Namen eines Programms, Ordners, Dokuments oder einer Internetressource an."; + Open = "Öffnen"; + Arguments = "Argumente"; + Cancel = "Abbrechen"; + Browse = "Druchsuchen"; + } + } + } +} diff --git a/Run/MainWindow.xaml b/Run/MainWindow.xaml new file mode 100644 index 0000000..c016204 --- /dev/null +++ b/Run/MainWindow.xaml @@ -0,0 +1,364 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TrustedPlatform/MainWindow.xaml.cs b/TrustedPlatform/MainWindow.xaml.cs new file mode 100644 index 0000000..912c353 --- /dev/null +++ b/TrustedPlatform/MainWindow.xaml.cs @@ -0,0 +1,673 @@ +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Microsoft.Graphics.Display; +using WinUIEx; +using Microsoft.UI.Windowing; +using CommunityToolkit.WinUI.Helpers; +using Microsoft.UI.Xaml.Media.Imaging; +using System.Runtime.InteropServices; +using Microsoft.Win32; +using Windows.Graphics; +using WindowMessageMonitor = WinUIEx.Messaging.WindowMessageMonitor; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace Rebound.TrustedPlatform; +/// +/// An empty window that can be used on its own or navigated to within a Frame. +/// +public sealed partial class MainWindow : WindowEx +{ + public double Scale() + { + // Get the DisplayInformation object for the current view + DisplayInformation displayInformation = DisplayInformation.CreateForWindowId(this.AppWindow.Id); + // Get the RawPixelsPerViewPixel which gives the scale factor + var scaleFactor = displayInformation.RawPixelsPerViewPixel; + return scaleFactor; + } + + public MainWindow() + { + this.InitializeComponent(); + this.SystemBackdrop = new MicaBackdrop(); + this.AppWindow.DefaultTitleBarShouldMatchAppModeTheme = true; + WindowTitle.Text = Title; + RootFrame.Navigate(typeof(MainPage)); + this.SetWindowIcon($"Assets\\icon.ico"); + + _msgMonitor ??= new WindowMessageMonitor(this); + _msgMonitor.WindowMessageReceived -= Event; + _msgMonitor.WindowMessageReceived += Event; + + this.AppWindow.TitleBar.ExtendsContentIntoTitleBar = true; + this.AppWindow.TitleBar.PreferredHeightOption = TitleBarHeightOption.Collapsed; + + mon = new RegistryMonitor(@"Software\Microsoft\Windows\DWM"); + mon.Start(); + var x = new ThemeListener(); + x.ThemeChanged += X_ThemeChanged; + + Rehook(); + CheckWindow(); + } + + public async void Rehook() + { + _msgMonitor ??= new WindowMessageMonitor(this); + _msgMonitor.WindowMessageReceived -= Event; + _msgMonitor.WindowMessageReceived += Event; + + await Task.Delay(1000); + + Rehook(); + } + + public void SetWindowIcon(string path) + { + TitleBarIcon.Source = new BitmapImage(new Uri($"ms-appx:///{path}")); + this.SetIcon($"{AppContext.BaseDirectory}\\{path}"); + } + + public async void CheckWindow() + { + try + { + if (WindowTitle != null && this != null) WindowTitle.Text = Title; + + await Task.Delay(50); + + CheckWindow(); + } + catch (AccessViolationException) + { + + } + catch (COMException) + { + + } + } + + RegistryMonitor mon; + + private async void X_ThemeChanged(ThemeListener sender) + { + await Task.Delay(200); + CheckFocus(); + } + + private void WindowEx_Closed(object sender, WindowEventArgs args) + { + App.m_window = null; + mon.Stop(); + _msgMonitor.Dispose(); + } + + #region MaximizeButton + + WindowMessageMonitor _msgMonitor; + + double additionalHeight = 0; + + public bool isInMaxButton = false; + + private void CrimsonMaxRes_PointerEntered(object sender, PointerRoutedEventArgs e) + { + ev = e; + isInMaxButton = true; + } + private void CrimsonMaxRes_PointerExited(object sender, PointerRoutedEventArgs e) + { + ev = e; + isInMaxButton = false; + } + + private void CrimsonMaxRes_PointerPressed(object sender, PointerRoutedEventArgs e) + { + ev = e; + isInMaxButton = false; + } + + PointerRoutedEventArgs ev; + + private void CrimsonMaxRes_PointerMoved(object sender, PointerRoutedEventArgs e) + { + ev = e; + _msgMonitor ??= new WindowMessageMonitor(this); + var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this); + _msgMonitor.WindowMessageReceived -= Event; + _msgMonitor.WindowMessageReceived += Event; + } + + private int GET_X_LPARAM(IntPtr lParam) + { + return unchecked((short)(long)lParam); + } + + private int GET_Y_LPARAM(IntPtr lParam) + { + return unchecked((short)((long)lParam >> 16)); + } + + bool windowFocused = false; + + SolidColorBrush buttonBrush; + + private const string RegistryKeyPath = @"Software\Microsoft\Windows\DWM"; + private const string RegistryValueName = "ColorPrevalence"; + + private static readonly IntPtr HKEY_CURRENT_USER = unchecked((IntPtr)0x80000001); + + [DllImport("advapi32.dll", SetLastError = true)] + private static extern IntPtr RegOpenKeyEx(IntPtr hKey, string lpSubKey, uint ulOptions, uint samDesired, out IntPtr phkResult); + + [DllImport("advapi32.dll", SetLastError = true)] + private static extern int RegCloseKey(IntPtr hKey); + + [DllImport("advapi32.dll", SetLastError = true)] + private static extern int RegNotifyChangeKeyValue(IntPtr hKey, bool bWatchSubtree, uint dwNotifyFilter, IntPtr hEvent, bool fAsynchronous); + + private const uint REG_NOTIFY_CHANGE_NAME = 0x00000001; + private const uint REG_NOTIFY_CHANGE_ATTRIBUTES = 0x00000002; + private const uint REG_NOTIFY_CHANGE_LAST_SET = 0x00000004; + private const uint REG_NOTIFY_CHANGE_SECURITY = 0x00000008; + + private static ManualResetEvent _changeEvent = new(false); + private static bool _running = true; + + private class RegistryMonitor : IDisposable + { + private readonly string _registryKeyPath; + private IntPtr _hKey; + private readonly Thread _monitorThread; + + public RegistryMonitor(string registryKeyPath) + { + _registryKeyPath = registryKeyPath; + _monitorThread = new Thread(MonitorRegistry) { IsBackground = true }; + } + + public void Start() + { + _monitorThread.Start(); + } + + public void Stop() + { + _running = false; + _changeEvent.Set(); + _monitorThread.Join(); + } + + private void MonitorRegistry() + { + if (RegOpenKeyEx(HKEY_CURRENT_USER, _registryKeyPath, 0, 0x20019, out _hKey) != 0) + { + throw new InvalidOperationException("Failed to open registry key."); + } + + while (_running) + { + // Wait for registry change notification + if (RegNotifyChangeKeyValue(_hKey, true, REG_NOTIFY_CHANGE_NAME | REG_NOTIFY_CHANGE_ATTRIBUTES | REG_NOTIFY_CHANGE_LAST_SET | REG_NOTIFY_CHANGE_SECURITY, _changeEvent.SafeWaitHandle.DangerousGetHandle(), true) == 0) + { + // Handle registry change + if (App.m_window != null) (App.m_window as MainWindow).CheckFocus(); + _changeEvent.WaitOne(); + } + } + + RegCloseKey(_hKey); + } + + public void Dispose() + { + Stop(); + _changeEvent.Dispose(); + } + } + + public static bool IsAccentColorEnabledForTitleBars() + { + try + { + using var key = Registry.CurrentUser.OpenSubKey(RegistryKeyPath); + if (key != null) + { + var value = key.GetValue(RegistryValueName); + if (value is int intValue) + { + // ColorPrevalence value of 1 means the accent color is used for title bars and window borders. + return intValue == 1; + } + } + } + catch (Exception ex) + { + // Handle exceptions (e.g., security exceptions or key not found) + Console.WriteLine($"Error checking accent color: {ex.Message}"); + } + + return false; // Default to false if any issues occur + } + + private void CheckFocus() + { + if (IsAccentColorEnabledForTitleBars() == true) + { + try + { + if (AccentStrip != null) AccentStrip.Visibility = Visibility.Visible; + if (!windowFocused) + { + buttonBrush = new SolidColorBrush(Colors.White); + AccentStrip.Visibility = Visibility.Visible; + } + else + { + buttonBrush = Application.Current.Resources["TextFillColorDisabledBrush"] as SolidColorBrush; + AccentStrip.Visibility = Visibility.Collapsed; + } + } + catch { } + } + else + { + try + { + if (AccentStrip != null) AccentStrip.Visibility = Visibility.Collapsed; + if (!windowFocused) + { + buttonBrush = Application.Current.Resources["TextFillColorPrimaryBrush"] as SolidColorBrush; + } + else + { + buttonBrush = Application.Current.Resources["TextFillColorDisabledBrush"] as SolidColorBrush; + } + } + catch { } + } + UpdateBrush(); + } + + private void UpdateBrush() + { + try + { + Close.Foreground = buttonBrush; + CrimsonMaxRes.Foreground = buttonBrush; + Minimize.Foreground = buttonBrush; + WindowTitle.Foreground = buttonBrush; + } + catch + { + + } + } + + public enum SelectedCaptionButton + { + None = 0, + Minimize = 1, + Maximize = 2, + Close = 3 + } + + public SelectedCaptionButton currentCaption = SelectedCaptionButton.None; + + async void Event(object sender, WinUIEx.Messaging.WindowMessageEventArgs e) + { + const int WM_NCLBUTTONDOWN = 0x00A1; + const int WM_NCHITTEST = 0x0084; + const int WM_NCLBUTTONUP = 0x00A2; + const int WM_NCMOUSELEAVE = 0x02A2; + const int WM_ACTIVATE = 0x0006; + const int WA_INACTIVE = 0; + var x = GET_X_LPARAM(e.Message.LParam); + var y = GET_Y_LPARAM(e.Message.LParam); + + var minButtonLeftPos = (Minimize.Width + CrimsonMaxRes.Width + closeWidth) * Scale(); + var maxButtonLeftPos = (CrimsonMaxRes.Width + closeWidth) * Scale(); + var closeButtonLeftPos = closeWidth * Scale(); + + switch (e.Message.MessageId) + { + case WM_ACTIVATE: + { + var wParam = e.Message.WParam.ToUInt32(); + if (wParam == WA_INACTIVE) + { + // The window has lost focus + windowFocused = true; + CheckFocus(); + } + else + { + // The window has gained focus + windowFocused = false; + CheckFocus(); + } + break; + } + case WM_NCHITTEST: + { + // Minimize Button + if ((x - 7 * Scale() - this.AppWindow.Position.X) >= (this.Bounds.Width * Scale() - minButtonLeftPos) && + (x - 7 * Scale() - this.AppWindow.Position.X) < (this.Bounds.Width * Scale() - maxButtonLeftPos) && + y < this.AppWindow.Position.Y + 31 * Scale() + additionalHeight * Scale() && + y >= this.AppWindow.Position.Y + 1 * Scale()) + { + e.Handled = true; + e.Result = new IntPtr(8); + if (currentCaption == SelectedCaptionButton.Minimize) VisualStateManager.GoToState(Minimize, "Pressed", true); + else if (currentCaption == SelectedCaptionButton.None) VisualStateManager.GoToState(Minimize, "PointerOver", true); + else VisualStateManager.GoToState(Minimize, "Normal", true); + VisualStateManager.GoToState(CrimsonMaxRes, "Normal", true); + VisualStateManager.GoToState(Close, "Normal", true); + await Task.Delay(1000); + e.Handled = false; + } + + // Maximize Button + else if ((x - 7 * Scale() - this.AppWindow.Position.X) >= (this.Bounds.Width * Scale() - maxButtonLeftPos) && + ((x - 7 * Scale() - this.AppWindow.Position.X) < (this.Bounds.Width * Scale() - closeButtonLeftPos)) && + y < this.AppWindow.Position.Y + 31 * Scale() + additionalHeight * Scale() && + y >= this.AppWindow.Position.Y + 1 * Scale()) + { + e.Handled = true; + e.Result = new IntPtr(9); + VisualStateManager.GoToState(Minimize, "Normal", true); + if (currentCaption == SelectedCaptionButton.Maximize) VisualStateManager.GoToState(CrimsonMaxRes, "Pressed", true); + else if (currentCaption == SelectedCaptionButton.None) VisualStateManager.GoToState(CrimsonMaxRes, "PointerOver", true); + else VisualStateManager.GoToState(CrimsonMaxRes, "Normal", true); + VisualStateManager.GoToState(Close, "Normal", true); + await Task.Delay(1000); + e.Handled = false; + } + + // Close Button + else if ((x - 7 * Scale() - this.AppWindow.Position.X) >= (this.Bounds.Width * Scale() - closeButtonLeftPos) && + (x - 7 * Scale() - this.AppWindow.Position.X) < (this.Bounds.Width * Scale()) + 2 && + y < this.AppWindow.Position.Y + 31 * Scale() + additionalHeight * Scale() && + y >= this.AppWindow.Position.Y + 1 * Scale()) + { + e.Handled = true; + e.Result = new IntPtr(20); + VisualStateManager.GoToState(Minimize, "Normal", true); + VisualStateManager.GoToState(CrimsonMaxRes, "Normal", true); + if (currentCaption == SelectedCaptionButton.Close) VisualStateManager.GoToState(Close, "Pressed", true); + else if (currentCaption == SelectedCaptionButton.None) VisualStateManager.GoToState(Close, "PointerOver", true); + else VisualStateManager.GoToState(Close, "Normal", true); + await Task.Delay(1000); + e.Handled = false; + } + + // Title bar drag area + else + { + e.Handled = true; + e.Result = new IntPtr(1); + VisualStateManager.GoToState(Minimize, "Normal", true); + VisualStateManager.GoToState(CrimsonMaxRes, "Normal", true); + VisualStateManager.GoToState(Close, "Normal", true); + e.Handled = false; + } + + break; + } + case WM_NCLBUTTONDOWN: + { + e.Handled = true; + e.Result = new IntPtr(1); + e.Handled = false; + + // Minimize Button + if ((x - 7 * Scale() - this.AppWindow.Position.X) >= (this.Bounds.Width * Scale() - minButtonLeftPos) && + (x - 7 * Scale() - this.AppWindow.Position.X) < (this.Bounds.Width * Scale() - maxButtonLeftPos) && + y < this.AppWindow.Position.Y + 31 * Scale() + additionalHeight * Scale() && + y >= this.AppWindow.Position.Y + 1 * Scale()) + { + currentCaption = SelectedCaptionButton.Minimize; + VisualStateManager.GoToState(Minimize, "Pressed", true); + VisualStateManager.GoToState(CrimsonMaxRes, "Normal", true); + VisualStateManager.GoToState(Close, "Normal", true); + } + + // Maximize Button + else if ((x - 7 * Scale() - this.AppWindow.Position.X) >= (this.Bounds.Width * Scale() - maxButtonLeftPos) && + ((x - 7 * Scale() - this.AppWindow.Position.X) < (this.Bounds.Width * Scale() - closeButtonLeftPos)) && + y < this.AppWindow.Position.Y + 31 * Scale() + additionalHeight * Scale() && + y >= this.AppWindow.Position.Y + 1 * Scale()) + { + currentCaption = SelectedCaptionButton.Maximize; + VisualStateManager.GoToState(Minimize, "Normal", true); + VisualStateManager.GoToState(CrimsonMaxRes, "Pressed", true); + VisualStateManager.GoToState(Close, "Normal", true); + } + + // Close Button + else if ((x - 7 * Scale() - this.AppWindow.Position.X) >= (this.Bounds.Width * Scale() - closeButtonLeftPos) && + (x - 7 * Scale() - this.AppWindow.Position.X) < (this.Bounds.Width * Scale()) + 2 && + y < this.AppWindow.Position.Y + 31 * Scale() + additionalHeight * Scale() && + y >= this.AppWindow.Position.Y + 1 * Scale()) + { + currentCaption = SelectedCaptionButton.Close; + VisualStateManager.GoToState(Minimize, "Normal", true); + VisualStateManager.GoToState(CrimsonMaxRes, "Normal", true); + VisualStateManager.GoToState(Close, "Pressed", true); + } + + // Title bar drag area + else + { + currentCaption = SelectedCaptionButton.None; + VisualStateManager.GoToState(Minimize, "Normal", true); + VisualStateManager.GoToState(CrimsonMaxRes, "Normal", true); + VisualStateManager.GoToState(Close, "Normal", true); + } + + break; + } + case WM_NCLBUTTONUP: + { + e.Handled = true; + e.Result = new IntPtr(1); + e.Handled = false; + + // Minimize Button + if ((x - 7 * Scale() - this.AppWindow.Position.X) >= (this.Bounds.Width * Scale() - minButtonLeftPos) && + (x - 7 * Scale() - this.AppWindow.Position.X) < (this.Bounds.Width * Scale() - maxButtonLeftPos) && + y < this.AppWindow.Position.Y + 31 * Scale() + additionalHeight * Scale() && + y >= this.AppWindow.Position.Y + 1 * Scale()) + { + if (currentCaption == SelectedCaptionButton.Minimize) + { + this.Minimize(); + VisualStateManager.GoToState(Minimize, "Normal", true); + VisualStateManager.GoToState(CrimsonMaxRes, "Normal", true); + VisualStateManager.GoToState(Close, "Normal", true); + } + } + + // Maximize Button + else if ((x - 7 * Scale() - this.AppWindow.Position.X) >= (this.Bounds.Width * Scale() - maxButtonLeftPos) && + ((x - 7 * Scale() - this.AppWindow.Position.X) < (this.Bounds.Width * Scale() - closeButtonLeftPos)) && + y < this.AppWindow.Position.Y + 31 * Scale() + additionalHeight * Scale() && + y >= this.AppWindow.Position.Y + 1 * Scale()) + { + if (currentCaption == SelectedCaptionButton.Maximize) RunMaximization(); + } + + // Close Button + else if ((x - 7 * Scale() - this.AppWindow.Position.X) >= (this.Bounds.Width * Scale() - closeButtonLeftPos) && + (x - 7 * Scale() - this.AppWindow.Position.X) < (this.Bounds.Width * Scale()) + 2 && + y < this.AppWindow.Position.Y + 31 * Scale() + additionalHeight * Scale() && + y >= this.AppWindow.Position.Y + 1 * Scale()) + { + if (currentCaption == SelectedCaptionButton.Close) + { + this.Close(); + } + } + + // Title bar drag area + else + { + + } + + currentCaption = SelectedCaptionButton.None; + + _msgMonitor.WindowMessageReceived -= Event; + _msgMonitor.Dispose(); + break; + } + case WM_NCMOUSELEAVE: + { + e.Handled = true; + e.Result = new IntPtr(1); + e.Handled = false; + VisualStateManager.GoToState(Minimize, "Normal", true); + VisualStateManager.GoToState(CrimsonMaxRes, "Normal", true); + VisualStateManager.GoToState(Close, "Normal", true); + break; + } + default: + { + e.Handled = false; + break; + } + } + } + + #endregion MaximizeButton + + double closeWidth = 46; + + public void RunMaximization() + { + var state = (this.Presenter as OverlappedPresenter).State; + if (state == OverlappedPresenterState.Restored) + { + this.Maximize(); + RootFrame.Focus(FocusState.Programmatic); + CheckMaximization(); + CaptionButtons.Margin = new Thickness(0, 0, 2, 0); + return; + } + else if (state == OverlappedPresenterState.Maximized) + { + this.Restore(); + RootFrame.Focus(FocusState.Programmatic); + CheckMaximization(); + CaptionButtons.Margin = new Thickness(0); + return; + } + } + + public async void CheckMaximization() + { + if (Presenter is OverlappedPresenter) + { + var state = (Presenter as OverlappedPresenter).State; + if (state == OverlappedPresenterState.Restored) + { + MaxResGlyph.Glyph = ""; + await Task.Delay(10); + VisualStateManager.GoToState(CrimsonMaxRes, "Normal", true); + closeWidth = 46; + additionalHeight = 0; + return; + } + else if (state == OverlappedPresenterState.Maximized) + { + MaxResGlyph.Glyph = ""; + await Task.Delay(10); + VisualStateManager.GoToState(CrimsonMaxRes, "Normal", true); + closeWidth = 46; + additionalHeight = 6; + return; + } + } + else + { + MaxResGlyph.Glyph = ""; + await Task.Delay(10); + VisualStateManager.GoToState(CrimsonMaxRes, "Normal", true); + return; + } + } + + public void LoadBounds() + { + var appWindow = this.AppWindow; + var titleBar = appWindow.TitleBar; + + RectInt32 rect = new RectInt32(0, 0, (int)(this.Bounds.Width * Scale()), (int)(31 * Scale())); + + RectInt32[] rects = + [ + rect, + ]; + + titleBar.SetDragRectangles(rects); + } + + private void WindowEx_SizeChanged(object sender, Microsoft.UI.Xaml.WindowSizeChangedEventArgs args) + { + LoadBounds(); + CheckMaximization(); + } + + private void WindowEx_PositionChanged(object sender, PointInt32 e) + { + LoadBounds(); + CheckMaximization(); + } + + private void CrimsonMaxRes_Click(object sender, RoutedEventArgs e) + { + RunMaximization(); + } + + private void Button_Click_1(object sender, RoutedEventArgs e) + { + this.Close(); + } + + private void Grid_PointerMoved(object sender, PointerRoutedEventArgs e) + { + if (e.GetCurrentPoint(this.Content).Properties.IsLeftButtonPressed != true) + { + currentCaption = SelectedCaptionButton.None; + } + } + + private void Grid_PointerReleased(object sender, PointerRoutedEventArgs e) + { + if (e.GetCurrentPoint(this.Content).Properties.IsLeftButtonPressed != true) + { + currentCaption = SelectedCaptionButton.None; + } + } + + private void Grid_PointerExited(object sender, PointerRoutedEventArgs e) + { + try + { + if (this.Content != null) + { + if (e.GetCurrentPoint(this.Content).Properties.IsLeftButtonPressed != true) + { + currentCaption = SelectedCaptionButton.None; + } + } + } + catch + { + + } + } +} diff --git a/TrustedPlatform/Models/TpmManager.cs b/TrustedPlatform/Models/TpmManager.cs new file mode 100644 index 0000000..7df0d9d --- /dev/null +++ b/TrustedPlatform/Models/TpmManager.cs @@ -0,0 +1,172 @@ +using System; +using System.ComponentModel; +using System.Management; + +public class TpmManager : INotifyPropertyChanged +{ + private string _manufacturerName; + private string _manufacturerVersion; + private string _specificationVersion; + private string _status; + private string _tpmSubVersion; + private string _pcClientSpecVersion; + private string _pcrValues; + + public string ManufacturerName + { + get => _manufacturerName; + private set + { + _manufacturerName = value; + OnPropertyChanged(nameof(ManufacturerName)); + } + } + + public string ManufacturerVersion + { + get => _manufacturerVersion; + private set + { + _manufacturerVersion = value; + OnPropertyChanged(nameof(ManufacturerVersion)); + } + } + + public string SpecificationVersion + { + get => _specificationVersion; + private set + { + _specificationVersion = value; + OnPropertyChanged(nameof(SpecificationVersion)); + } + } + + public string TpmSubVersion + { + get => _tpmSubVersion; + private set + { + _tpmSubVersion = value; + OnPropertyChanged(nameof(TpmSubVersion)); + } + } + + public string PcClientSpecVersion + { + get => _pcClientSpecVersion; + private set + { + _pcClientSpecVersion = value; + OnPropertyChanged(nameof(PcClientSpecVersion)); + } + } + + public string PcrValues + { + get => _pcrValues; + private set + { + _pcrValues = value; + OnPropertyChanged(nameof(PcrValues)); + } + } + + public string Status + { + get => _status; + private set + { + _status = value; + OnPropertyChanged(nameof(Status)); + } + } + + public event PropertyChangedEventHandler PropertyChanged; + + public TpmManager() + { + GetTpmInfo(); + } + + public void RefreshTpmInfo() + { + GetTpmInfo(); + } + + public List GetTpmInfo() + { + try + { + using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\CIMV2\Security\MicrosoftTpm", "SELECT * FROM Win32_Tpm")) + { + foreach (ManagementObject queryObj in searcher.Get()) + { + return new List + { + queryObj["ManufacturerID"] != null ? ConvertManufacturerIdToName((uint)queryObj["ManufacturerID"]) : "Unknown", + queryObj["ManufacturerVersion"]?.ToString() ?? "Unknown", + queryObj["SpecVersion"]?.ToString() ?? "Unknown", + queryObj["ManufacturerVersion"]?.ToString() ?? "Unknown", + queryObj["SpecVersion"]?.ToString() ?? "Unknown", + GetPcrValues(), + queryObj["IsActivated_InitialValue"] != null && (bool)queryObj["IsActivated_InitialValue"] ? "Ready" : "Not Ready" + }; + /*ManufacturerName = queryObj["ManufacturerID"] != null ? ConvertManufacturerIdToName((uint)queryObj["ManufacturerID"]) : "Unknown"; + ManufacturerVersion = queryObj["ManufacturerVersion"]?.ToString() ?? "Unknown"; + SpecificationVersion = queryObj["SpecVersion"]?.ToString() ?? "Unknown"; + TpmSubVersion = queryObj["ManufacturerVersion"]?.ToString() ?? "Unknown"; + PcClientSpecVersion = queryObj["SpecVersion"]?.ToString() ?? "Unknown"; + PcrValues = GetPcrValues(); + + Status = queryObj["IsActivated_InitialValue"] != null && (bool)queryObj["IsActivated_InitialValue"] ? "Ready" : "Not Ready";*/ + } + } + } + catch (Exception ex) + { + ManufacturerName = "N/A"; + ManufacturerVersion = "N/A"; + SpecificationVersion = "N/A"; + TpmSubVersion = "N/A"; + PcClientSpecVersion = "N/A"; + PcrValues = "N/A"; + Status = "Error communicating with TPM"; + Console.WriteLine($"An error occurred while getting TPM information: {ex.Message}"); + } + + return new List() + { + ManufacturerName, + ManufacturerVersion, + SpecificationVersion, + TpmSubVersion, + PcClientSpecVersion, + PcrValues, + + Status, + }; + } + + private string ConvertManufacturerIdToName(uint manufacturerId) + { + var manufacturerStr = string.Empty; + manufacturerStr += (char)((manufacturerId >> 24) & 0xFF); + manufacturerStr += (char)((manufacturerId >> 16) & 0xFF); + manufacturerStr += (char)((manufacturerId >> 8) & 0xFF); + manufacturerStr += (char)(manufacturerId & 0xFF); + return manufacturerStr; + } + + private string GetPcrValues() + { + // Placeholder for PCR retrieval logic. This should query TPM for PCR values. + // Requires advanced access via TBS API or TPM library. + return "PCR values are not directly accessible via WMI. Requires advanced TPM API."; + } + + protected virtual void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } +} diff --git a/TrustedPlatform/Models/TpmReset.cs b/TrustedPlatform/Models/TpmReset.cs new file mode 100644 index 0000000..4abf8b1 --- /dev/null +++ b/TrustedPlatform/Models/TpmReset.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Rebound.TrustedPlatform.Models; +public class TpmReset +{ + public static async Task ResetTpmAsync(ContentDialog dial) + { + dial.Content = "Processing..."; + try + { + // Path to the PowerShell script + string scriptPath = Path.Combine(Path.GetTempPath(), "Reset-TPM.ps1"); + + // Write the PowerShell script to a temporary file + File.WriteAllText(scriptPath, @" + Write-Host 'Starting TPM reset process...' + Clear-Tpm -ErrorAction Stop + Write-Host 'TPM reset successfully completed.' + "); + + // Set up the process to run PowerShell with elevated privileges + ProcessStartInfo psi = new ProcessStartInfo + { + FileName = "powershell.exe", + Arguments = $"-NoProfile -ExecutionPolicy Bypass -File \"{scriptPath}\"", + Verb = "runas", // Run as administrator + UseShellExecute = true, + CreateNoWindow = true + }; + + // Start the process and wait for it to exit + var process = Process.Start(psi); + await process.WaitForExitAsync(); + + // Check the exit code + if (process.ExitCode == 0) + { + // Update InfoBar for success + dial.Content = "TPM reset successfully completed."; + dial.SecondaryButtonText = "Close"; + } + else + { + // Update InfoBar for failure + dial.Content = "TPM reset failed. Please try again."; + dial.IsPrimaryButtonEnabled = true; + } + dial.IsSecondaryButtonEnabled = true; + } + catch (Exception ex) + { + // Handle exceptions and update InfoBar for failure + dial.Content = $"Operation cancelled from User Account Control."; + dial.IsPrimaryButtonEnabled = true; + dial.IsSecondaryButtonEnabled = true; + } + } +} diff --git a/TrustedPlatform/Models/TpmViewModel.cs b/TrustedPlatform/Models/TpmViewModel.cs new file mode 100644 index 0000000..dd0f9d2 --- /dev/null +++ b/TrustedPlatform/Models/TpmViewModel.cs @@ -0,0 +1,46 @@ +using System; +using System.ComponentModel; +using System.Threading.Tasks; + +public class TpmViewModel : INotifyPropertyChanged +{ + private readonly TpmManager _tpmManager; + + public string ManufacturerName => _tpmManager.ManufacturerName; + public string ManufacturerVersion => _tpmManager.ManufacturerVersion; + public string SpecificationVersion => _tpmManager.SpecificationVersion; + public string Status => _tpmManager.Status; + + // New properties + public string TpmSubVersion => _tpmManager.TpmSubVersion; + public string PcClientSpecVersion => _tpmManager.PcClientSpecVersion; + public string PcrValues => _tpmManager.PcrValues; + + public event PropertyChangedEventHandler PropertyChanged; + + public TpmViewModel() + { + _tpmManager = new TpmManager(); + _tpmManager.PropertyChanged += (s, e) => OnPropertyChanged(e.PropertyName); + } + + public async Task LoadTpmInfoAsync() + { + // Call the method to refresh TPM info + await Task.Run(() => _tpmManager.RefreshTpmInfo()); + // Notify properties + OnPropertyChanged(nameof(ManufacturerName)); + OnPropertyChanged(nameof(ManufacturerVersion)); + OnPropertyChanged(nameof(SpecificationVersion)); + OnPropertyChanged(nameof(Status)); + // Notify new properties + OnPropertyChanged(nameof(TpmSubVersion)); + OnPropertyChanged(nameof(PcClientSpecVersion)); + OnPropertyChanged(nameof(PcrValues)); + } + + protected virtual void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } +} diff --git a/TrustedPlatform/Package.appxmanifest b/TrustedPlatform/Package.appxmanifest new file mode 100644 index 0000000..d86a6af --- /dev/null +++ b/TrustedPlatform/Package.appxmanifest @@ -0,0 +1,55 @@ + + + + + + + + + Rebound.TrustedPlatform + JPJM- + Assets\Store\StoreLogo.png + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TrustedPlatform/Properties/launchSettings.json b/TrustedPlatform/Properties/launchSettings.json new file mode 100644 index 0000000..b21eb7c --- /dev/null +++ b/TrustedPlatform/Properties/launchSettings.json @@ -0,0 +1,10 @@ +{ + "profiles": { + "Rebound.TrustedPlatform (Package)": { + "commandName": "MsixPackage" + }, + "Rebound.TrustedPlatform (Unpackaged)": { + "commandName": "Project" + } + } +} \ No newline at end of file diff --git a/TrustedPlatform/Rebound.TrustedPlatform.csproj b/TrustedPlatform/Rebound.TrustedPlatform.csproj new file mode 100644 index 0000000..4370514 --- /dev/null +++ b/TrustedPlatform/Rebound.TrustedPlatform.csproj @@ -0,0 +1,87 @@ + + + WinExe + net8.0-windows10.0.22621.0 + 10.0.17763.0 + 10.0.22621.35-preview + Rebound.TrustedPlatform + app.manifest + x64;x86 + win-x86;win-x64 + win10-x86;win10-x64 + win-$(Platform).pubxml + true + true + 1.0.1 + true + Latest + Assets\icon.ico + false + true + MSIX + False + True + SHA256 + False + False + True + Never + 0 + Rebound.TrustedPlatform_TemporaryKey.pfx + + + + + Always + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MSBuild:Compile + + + + + + true + + diff --git a/TrustedPlatform/Views/MainPage.xaml b/TrustedPlatform/Views/MainPage.xaml new file mode 100644 index 0000000..0c6e0a9 --- /dev/null +++ b/TrustedPlatform/Views/MainPage.xaml @@ -0,0 +1,184 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Reset TPM + + + Refresh + + + + + + + + + diff --git a/TrustedPlatform/Views/MainPage.xaml.cs b/TrustedPlatform/Views/MainPage.xaml.cs new file mode 100644 index 0000000..b41c90a --- /dev/null +++ b/TrustedPlatform/Views/MainPage.xaml.cs @@ -0,0 +1,105 @@ +using Rebound.TrustedPlatform.Models; + +namespace Rebound.TrustedPlatform.Views; + +public sealed partial class MainPage : Page +{ + public TpmViewModel ViewModelTpm { get; } + public TpmManager TpmManager { get; } // Old method for original properties + + public MainPage() + { + this.InitializeComponent(); + + // Initialize TpmManager for the original properties + TpmManager = new TpmManager(); + // Initialize ViewModelTpm for new properties + ViewModelTpm = new TpmViewModel(); + + // Set DataContext to TpmManager for original properties + this.DataContext = this; + + // Load new TPM information asynchronously + _ = ViewModelTpm.LoadTpmInfoAsync(); + + var list = TpmManager.GetTpmInfo(); + + ManufacturerName.Text = list[0]; + ManufacturerVersion.Text = list[1]; + SpecificationVersion.Text = list[2]; + TpmSubVersion.Text = list[3]; + PcClientSpecVersion.Text = list[4]; + PcrValues.Text = list[5]; + Status.Text = list[6]; + + StatusBar.Severity = list[6] == "Ready" ? InfoBarSeverity.Success : InfoBarSeverity.Error; + StatusBar.Title = $"Status: {list[6]}"; + } + + ContentDialog dial; + + private async void Button_Click(object sender, RoutedEventArgs e) + { + var dialog = new ContentDialog() + { + XamlRoot = this.XamlRoot, + PrimaryButtonText = "Reset", + SecondaryButtonText = "Cancel", + DefaultButton = ContentDialogButton.Primary, + Title = "TPM Management", + Content = "This action cannot be undone. Are you sure you want to proceed?", + }; + dial = dialog; + dialog.PrimaryButtonClick += Dialog_PrimaryButtonClick; + dialog.SecondaryButtonClick += Dialog_SecondaryButtonClick; + await dialog.ShowAsync(); // Show the dialog + } + + private void Dialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) + { + sender.Hide(); + dial = null; + sender = null; + } + + private async void Dialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) + { + args.Cancel = true; + dial.Content = "Starting TPM reset... Please wait."; + dial.IsPrimaryButtonEnabled = false; + dial.IsSecondaryButtonEnabled = false; + + // Call the TPM reset function + await TpmReset.ResetTpmAsync(sender); + + var list = TpmManager.GetTpmInfo(); + + ManufacturerName.Text = list[0]; + ManufacturerVersion.Text = list[1]; + SpecificationVersion.Text = list[2]; + TpmSubVersion.Text = list[3]; + PcClientSpecVersion.Text = list[4]; + PcrValues.Text = list[5]; + Status.Text = list[6]; + + StatusBar.Severity = list[6] == "Ready" ? InfoBarSeverity.Success : InfoBarSeverity.Error; + StatusBar.Title = $"Status: {list[6]}"; + } + + private void HyperlinkButton_Click(object sender, RoutedEventArgs e) + { + var list = TpmManager.GetTpmInfo(); + + ManufacturerName.Text = list[0]; + ManufacturerVersion.Text = list[1]; + SpecificationVersion.Text = list[2]; + TpmSubVersion.Text = list[3]; + PcClientSpecVersion.Text = list[4]; + PcrValues.Text = list[5]; + Status.Text = list[6]; + + StatusBar.Severity = list[6] == "Ready" ? InfoBarSeverity.Success : InfoBarSeverity.Error; + StatusBar.Title = $"Status: {list[6]}"; + } +} + diff --git a/TrustedPlatform/app.manifest b/TrustedPlatform/app.manifest new file mode 100644 index 0000000..581f5f9 --- /dev/null +++ b/TrustedPlatform/app.manifest @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + PerMonitorV2 + + + + + + + + + + + +