diff --git a/GUI/GUI.ps1 b/GUI/GUI.ps1 index 3457665d..ef39bfb3 100644 --- a/GUI/GUI.ps1 +++ b/GUI/GUI.ps1 @@ -1,14 +1,21 @@ [CmdletBinding()] -param([string]$ConfingFile,[string]$Localize) +param( + [string]$ConfingFile, + [string]$Localize, + [ValidateSet('Light', 'Dark', 'Auto')] + [string]$UIMode = 'Auto' +) + +$Prarms = [hashtable]$PSBoundParameters if (!$Localize) { # 本机语言 - $Localize = (Get-Culture).Name + $Prarms.Localize = (Get-Culture).Name } if (($PSVersionTable.PSEdition -eq "Core") -and (Get-Command powershell -ErrorAction Ignore)) { - powershell -NoProfile -ExecutionPolicy Bypass -File $PSScriptRoot\src\Main.ps1 -ConfingFile $ConfingFile -Localize $Localize | Out-Null + powershell -NoProfile -ExecutionPolicy Bypass -File $PSScriptRoot\src\Main.ps1 @Prarms | Out-Null return } -.$PSScriptRoot\src\Main.ps1 -ConfingFile $ConfingFile -Localize $Localize | Out-Null +.$PSScriptRoot\src\Main.ps1 @Prarms | Out-Null diff --git a/GUI/src/DarkMode.ps1 b/GUI/src/DarkMode.ps1 new file mode 100644 index 00000000..0e793810 --- /dev/null +++ b/GUI/src/DarkMode.ps1 @@ -0,0 +1,35 @@ +if($UIMode -eq 'Auto') { + $DarkMode = Get-ItemPropertyValue -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize" -Name "AppsUseLightTheme" -ErrorAction SilentlyContinue + $DarkMode = $DarkMode -eq 0 +} +else { + $DarkMode = $UIMode -eq 'Dark' +} + +if ($DarkMode) { + $Script:refs['MainForm'].BackColor = [System.Drawing.ColorTranslator]::FromHtml('#333333') + $Script:refs['MainForm'].ForeColor = [System.Drawing.ColorTranslator]::FromHtml('#FFFFFF') + $Script:refs.Values | Where-Object { $_.GetType().Name -eq 'TextBox' } | ForEach-Object { + $_.BackColor = 'WindowFrame' + $_.ForeColor = 'Window' + $_.BorderStyle = 'FixedSingle' + } + $Script:refs.Values | Where-Object { $_.GetType().Name -eq 'Button' } | ForEach-Object { + $_.BackColor = 'WindowFrame' + $_.ForeColor = 'Window' + $_.FlatStyle = 'Flat' + } + $Script:refs.Values | Where-Object { $_.GetType().Name -eq 'CheckBox' } | ForEach-Object { + $_.ForeColor = 'Window' + $_.FlatStyle = 'Flat' + } + $Script:refs.Values | Where-Object { $_.GetType().Name -eq 'GroupBox' } | ForEach-Object { + $_.ForeColor = [System.Drawing.ColorTranslator]::FromHtml('#FFFFFF') + } + # DWMWA_USE_IMMERSIVE_DARK_MODE + [Dwm]::SetWindowAttribute($Script:refs['MainForm'].Handle, 20, 1) + # DWMWA_MICA_EFFECT + [Dwm]::SetWindowAttribute($Script:refs['MainForm'].Handle, 1029 , 1) + # DWMWA_BORDER_COLOR + [Dwm]::SetWindowBorderColor($Script:refs['MainForm'].Handle, [System.Drawing.ColorTranslator]::FromHtml('#FFFFFF')) +} diff --git a/GUI/src/Main.ps1 b/GUI/src/Main.ps1 index 740b370e..831aa559 100644 --- a/GUI/src/Main.ps1 +++ b/GUI/src/Main.ps1 @@ -2,7 +2,9 @@ param ( [string]$ConfingFile, #本地化信息 - [string]$Localize + [string]$Localize, + [ValidateSet('Light', 'Dark', 'Auto')] + [string]$UIMode = 'Auto' ) # ScriptBlock to Execute in STA Runspace @@ -17,6 +19,8 @@ $sbGUI = { . "$BaseDir\Events.ps1" + . "$BaseDir\DarkMode.ps1" + #region Other Actions Before ShowDialog try { diff --git a/GUI/src/UItools.ps1 b/GUI/src/UItools.ps1 index 1e9692a9..eca63b31 100644 --- a/GUI/src/UItools.ps1 +++ b/GUI/src/UItools.ps1 @@ -12,6 +12,19 @@ public class psd { [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern bool SetProcessDPIAware(); } +using System.Drawing; +public class Dwm { + [DllImport("dwmapi.dll")] + public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, int[] attrValue, int attrSize); + + public static int SetWindowAttribute(IntPtr hwnd, int attr, int attrValue) { + return DwmSetWindowAttribute(hwnd, attr, new int[] { attrValue }, 4); + } + + public static int SetWindowBorderColor(IntPtr hwnd, Color color){ + return SetWindowAttribute(hwnd, 34, int.Parse(`$"{color.B:X2}{color.G:X2}{color.R:X2}", System.Globalization.NumberStyles.HexNumber)); + } +} "@ -ReferencedAssemblies System.Windows.Forms, System.Drawing, System.Drawing.Primitives, System.Net.Primitives, System.ComponentModel.Primitives, Microsoft.Win32.Primitives $script:tscale = 1 diff --git a/README.md b/README.md index 11a5f23f..d3cfb977 100644 --- a/README.md +++ b/README.md @@ -34,23 +34,37 @@ ps12exe .\source.ps1 .\target.exe compiles `source.ps1` into the executable target.exe (if `.\target.exe` is omitted, output is written to `.\source.exe`). -## Comparison +## Project Comparison -Compared to [`MScholtes/PS2EXE@678a892`](https://github.com/MScholtes/PS2EXE/tree/678a89270f4ef4b636b69db46b31e1b4e0a9e1c5), this project: +When compared to [`MScholtes/PS2EXE@678a892`](https://github.com/MScholtes/PS2EXE/tree/678a89270f4ef4b636b69db46b31e1b4e0a9e1c5), this project introduces the following enhancements: -- Adds [powerful preprocessing features](#prepossessing) that allow you to preprocess the script before compiling (instead of copy-pasting everything and embedding it into the script) -- Special parameters are no longer enabled by default in the generated files, but can be enabled with the new `-SepcArgsHandling` parameter if needed. -- The `-CompilerOptions` parameter has been added to allow you to further customise the generated executable. -- Added [`-Minifyer` parameter](#minifyer) to allow you to pre-process scripts before compilation to get smaller generated executables -- Support for compiling scripts and including files from urls, support for downloading icons from urls -- Optimised option handling and window title display under the `-noConsole` parameter, you can now customise the title of popup windows by setting `$Host.UI.RawUI.WindowTitle`. -- Removed exe files from code repository -- Better multi-language support、pure script GUI -- Separated the cs file from the ps1 file, easier to read and maintain. -- and more... +- Incorporates [robust preprocessing capabilities](#prepossessing), enabling you to preprocess scripts prior to compilation, eliminating the need to embed everything into the script manually. +- Special parameters are not enabled by default in the generated files anymore, but can be activated with the new `-SepcArgsHandling` parameter if required. +- A new `-CompilerOptions` parameter has been introduced, providing additional customization options for the generated executable. +- The [`-Minifyer` parameter](#minifyer) has been added, allowing for script preprocessing before compilation, resulting in smaller executables. +- Supports compiling scripts and including files from URLs, as well as downloading icons from URLs. +- Under the `-noConsole` parameter, option handling and window title display have been optimized. You can now personalize the title of popup windows by setting `$Host.UI.RawUI.WindowTitle`. +- Executable files have been removed from the code repository. +- Enhanced multi-language support, pure script GUI, and dark mode support. +- The C# file has been separated from the PowerShell file, making it easier to read and maintain. +- And much more... ## Parameter +### GUI parameters + +```powershell +ps12exeGUI [[-ConfingFile] ''] [-Localize ''] [[-UIMode] 'Dark'|'Light'|'Auto'] +``` + +```text +ConfingFile = path to config file (default is none) + Localize = language code (default is current system language, try to load 'en-UK' if no corresponding language file is available, if still not available, iterate through all language files until available) + UIMode = UI mode (default is Auto) +``` + +### Console parameters + ```powershell [input |] ps12exe [[-inputFile] '' | -Content '