diff --git a/config/themes.json b/config/themes.json index 2c11a09d6c..5947ced7c2 100644 --- a/config/themes.json +++ b/config/themes.json @@ -1,220 +1,168 @@ { - "Classic": { - "CustomDialogFontSize": "12", - "CustomDialogFontSizeHeader": "14", - "CustomDialogIconSize": "25", - "CustomDialogWidth": "400", - "CustomDialogHeight": "200", - - "FontSize": "12", - "FontFamily": "Arial", - "FontSizeHeading": "14", - "HeaderFontFamily": "Consolas, Monaco", - - "CheckBoxBulletDecoratorFontSize": "14", - "CheckBoxMargin": "15,0,0,2", - - "TabButtonFontSize": "14", - "TabButtonWidth": "100", - "TabButtonHeight": "25", - "TabRowHeightInPixels": "50", - "IconFontSize": "14", - "IconButtonSize": "35", - "WinUtilIconSize": "Auto", - "SettingsIconFontSize": "18", - - "MicroWinLogoSize": "10", - - "ProgressBarForegroundColor": "#FFAC1C", - "ProgressBarBackgroundColor": "Transparent", - "ProgressBarTextColor": "#000000", - - "ComboBoxBackgroundColor": "#FFFFFF", - "LabelboxForegroundColor": "#000000", - "MainForegroundColor": "#000000", - "MainBackgroundColor": "#FFFFFF", - "LabelBackgroundColor": "#FAFAFA", - "LinkForegroundColor": "#000000", - "LinkHoverForegroundColor": "#000000", - "GroupBorderBackgroundColor": "#000000", - "ComboBoxForegroundColor": "#000000", - - "ButtonFontSize": "12", - "ButtonFontFamily": "Arial", - "ButtonWidth": "200", - "ButtonHeight": "25", - "ConfigTabButtonFontSize": "16", - - "SearchBarWidth": "200", - "SearchBarHeight": "25", - "SearchBarTextBoxFontSize": "16", - "SearchBarClearButtonFontSize": "14", - - "ButtonInstallBackgroundColor": "#FFFFFF", - "ButtonTweaksBackgroundColor": "#FFFFFF", - "ButtonConfigBackgroundColor": "#FFFFFF", - "ButtonUpdatesBackgroundColor": "#FFFFFF", - "ButtonInstallForegroundColor": "#000000", - "ButtonTweaksForegroundColor": "#000000", - "ButtonConfigForegroundColor": "#000000", - "ButtonUpdatesForegroundColor": "#000000", - "ButtonBackgroundColor": "#F5F5F5", - "ButtonBackgroundPressedColor": "#1A1A1A", - "CheckboxMouseOverColor": "#999999", - "ButtonBackgroundMouseoverColor": "#C2C2C2", - "ButtonBackgroundSelectedColor": "#F0F0F0", - "ButtonForegroundColor": "#000000", - "ToggleButtonOnColor": "#2e77ff", - - "ButtonBorderThickness": "1", - "ButtonMargin": "1", - "ButtonCornerRadius": "2", - "BorderColor": "#000000", - "BorderOpacity": "0.2", - "ShadowPulse": "Forever" - }, - "Matrix": { - "CustomDialogFontSize": "12", - "CustomDialogFontSizeHeader": "14", - "CustomDialogIconSize": "25", - "CustomDialogWidth": "400", - "CustomDialogHeight": "200", - - "FontSize": "12", - "FontFamily": "Arial", - "FontSizeHeading": "14", - "HeaderFontFamily": "Consolas, Monaco", - - "CheckBoxBulletDecoratorFontSize": "14", - "CheckBoxMargin": "15,0,0,2", - - "TabButtonFontSize": "14", - "TabButtonWidth": "100", - "TabButtonHeight": "25", - "TabRowHeightInPixels": "50", - "IconFontSize": "14", - "IconButtonSize": "35", - "WinUtilIconSize": "Auto", - "SettingsIconFontSize": "18", - - "MicroWinLogoSize": "10", - - "ProgressBarForegroundColor": "#222222", - "ProgressBarBackgroundColor": "Transparent", - "ProgressBarTextColor": "#cccccc", - - "ComboBoxBackgroundColor": "#000000", - "LabelboxForegroundColor": "#FFEE58", - "MainForegroundColor": "#9CCC65", - "MainBackgroundColor": "#000000", - "LabelBackgroundColor": "#000000", - "LinkForegroundColor": "#add8e6", - "LinkHoverForegroundColor": "#FFFFFF", - "ComboBoxForegroundColor": "#FFEE58", - - "ButtonFontSize": "12", - "ButtonFontFamily": "Arial", - "ButtonWidth": "200", - "ButtonHeight": "25", - "ConfigTabButtonFontSize": "16", - - "SearchBarWidth": "200", - "SearchBarHeight": "25", - "SearchBarTextBoxFontSize": "16", - "SearchBarClearButtonFontSize": "14", - - "ButtonInstallBackgroundColor": "#222222", - "ButtonTweaksBackgroundColor": "#333333", - "ButtonConfigBackgroundColor": "#444444", - "ButtonUpdatesBackgroundColor": "#555555", - "ButtonInstallForegroundColor": "#FFFFFF", - "ButtonTweaksForegroundColor": "#FFFFFF", - "ButtonConfigForegroundColor": "#FFFFFF", - "ButtonUpdatesForegroundColor": "#FFFFFF", - "ButtonBackgroundColor": "#000019", - "ButtonBackgroundPressedColor": "#FFFFFF", - "ButtonBackgroundMouseoverColor": "#A55A64", - "ButtonBackgroundSelectedColor": "#FF5733", - "ButtonForegroundColor": "#9CCC65", - "ToggleButtonOnColor": "#2e77ff", - - "ButtonBorderThickness": "1", - "ButtonMargin": "1", - "ButtonCornerRadius": "2", - "BorderColor": "#FFAC1C", - "BorderOpacity": "0.8", - "ShadowPulse": "0:0:3" - }, - "Dark": { - "CustomDialogFontSize": "12", - "CustomDialogFontSizeHeader": "14", - "CustomDialogIconSize": "25", - "CustomDialogWidth": "400", - "CustomDialogHeight": "200", - - "FontSize": "12", - "FontFamily": "Arial", - "FontSizeHeading": "14", - "HeaderFontFamily": "Consolas, Monaco", - - "CheckBoxBulletDecoratorFontSize": "14", - "CheckBoxMargin": "15,0,0,2", - - "TabButtonFontSize": "14", - "TabButtonWidth": "100", - "TabButtonHeight": "25", - "TabRowHeightInPixels": "50", - "IconFontSize": "14", - "IconButtonSize": "35", - "WinUtilIconSize": "Auto", - "SettingsIconFontSize": "18", - - "MicroWinLogoSize": "10", - - "ProgressBarForegroundColor": "#222222", - "ProgressBarBackgroundColor": "Transparent", - "ProgressBarTextColor": "#FFFFFF", - - "ComboBoxBackgroundColor": "#000000", - "LabelboxForegroundColor": "#FFEE58", - "MainForegroundColor": "#9CCC65", - "MainBackgroundColor": "#000000", - "LabelBackgroundColor": "#000000", - "LinkForegroundColor": "#add8e6", - "LinkHoverForegroundColor": "#FFFFFF", - "ComboBoxForegroundColor": "#FFEE58", - - "ButtonFontSize": "12", - "ButtonFontFamily": "Arial", - "ButtonWidth": "200", - "ButtonHeight": "25", - "ConfigTabButtonFontSize": "16", - - "SearchBarWidth": "200", - "SearchBarHeight": "25", - "SearchBarTextBoxFontSize": "16", - "SearchBarClearButtonFontSize": "14", - - "ButtonInstallBackgroundColor": "#222222", - "ButtonTweaksBackgroundColor": "#333333", - "ButtonConfigBackgroundColor": "#444444", - "ButtonUpdatesBackgroundColor": "#555555", - "ButtonInstallForegroundColor": "#FFFFFF", - "ButtonTweaksForegroundColor": "#FFFFFF", - "ButtonConfigForegroundColor": "#FFFFFF", - "ButtonUpdatesForegroundColor": "#FFFFFF", - "ButtonBackgroundColor": "#000019", - "ButtonBackgroundPressedColor": "#9CCC65", - "ButtonBackgroundMouseoverColor": "#FF5733", - "ButtonBackgroundSelectedColor": "#FF5733", - "ButtonForegroundColor": "#9CCC65", - "ToggleButtonOnColor": "#2e77ff", - - "ButtonBorderThickness": "1", - "ButtonMargin": "1", - "ButtonCornerRadius": "2", - "BorderColor": "#FFAC1C", - "BorderOpacity": "0.2", - "ShadowPulse": "Forever" - } + "_default": { + "CustomDialogFontSize": "12", + "CustomDialogFontSizeHeader": "14", + "CustomDialogIconSize": "25", + "CustomDialogWidth": "400", + "CustomDialogHeight": "200", + + "FontSize": "14", + "FontFamily": "Arial", + "FontSizeHeading": "16", + "HeaderFontFamily": "Consolas, Monaco", + + "CheckBoxBulletDecoratorSize": "14", + "CheckBoxMargin": "15,0,0,2", + + "TabButtonFontSize": "14", + "TabButtonWidth": "100", + "TabButtonHeight": "25", + "TabRowHeightInPixels": "50", + "IconFontSize": "14", + "IconButtonSize": "35", + "WinUtilIconSize": "Auto", + "SettingsIconFontSize": "18", + "CloseIconFontSize": "18", + + "MicroWinLogoSize": "10", + + "ProgressBarForegroundColor": "#FFAC1C", + "ProgressBarBackgroundColor": "Transparent", + "ProgressBarTextColor": "#000000", + + "ComboBoxBackgroundColor": "#FFFFFF", + "LabelboxForegroundColor": "#000000", + "MainForegroundColor": "#000000", + "MainBackgroundColor": "#FFFFFF", + "LabelBackgroundColor": "#FAFAFA", + "LinkForegroundColor": "#000000", + "LinkHoverForegroundColor": "#000000", + "GroupBorderBackgroundColor": "#000000", + "ComboBoxForegroundColor": "#000000", + + "ButtonFontSize": "12", + "ButtonFontFamily": "Arial", + "ButtonWidth": "200", + "ButtonHeight": "25", + "ConfigTabButtonFontSize": "16", + + "SearchBarWidth": "200", + "SearchBarHeight": "25", + "SearchBarTextBoxFontSize": "16", + "SearchBarClearButtonFontSize": "14", + + "ButtonInstallBackgroundColor": "#FFFFFF", + "ButtonTweaksBackgroundColor": "#FFFFFF", + "ButtonConfigBackgroundColor": "#FFFFFF", + "ButtonUpdatesBackgroundColor": "#FFFFFF", + "ButtonInstallForegroundColor": "#000000", + "ButtonTweaksForegroundColor": "#000000", + "ButtonConfigForegroundColor": "#000000", + "ButtonUpdatesForegroundColor": "#000000", + "ButtonBackgroundColor": "#F5F5F5", + "ButtonBackgroundPressedColor": "#1A1A1A", + "CheckboxMouseOverColor": "#999999", + "ButtonBackgroundMouseoverColor": "#C2C2C2", + "ButtonBackgroundSelectedColor": "#F0F0F0", + "ButtonForegroundColor": "#000000", + "ToggleButtonOnColor": "#2e77ff", + + "ButtonBorderThickness": "1", + "ButtonMargin": "1", + "ButtonCornerRadius": "2", + "BorderColor": "#000000", + "BorderOpacity": "0.2", + "ShadowPulse": "Forever" + }, + "Classic": { + "ComboBoxBackgroundColor": "#FFFFFF", + "LabelboxForegroundColor": "#000000", + "MainForegroundColor": "#000000", + "MainBackgroundColor": "#FFFFFF", + "LabelBackgroundColor": "#FAFAFA", + "LinkForegroundColor": "#000000", + "LinkHoverForegroundColor": "#000000", + "GroupBorderBackgroundColor": "#000000", + "ComboBoxForegroundColor": "#000000", + + "ButtonInstallBackgroundColor": "#FFFFFF", + "ButtonTweaksBackgroundColor": "#FFFFFF", + "ButtonConfigBackgroundColor": "#FFFFFF", + "ButtonUpdatesBackgroundColor": "#FFFFFF", + "ButtonInstallForegroundColor": "#000000", + "ButtonTweaksForegroundColor": "#000000", + "ButtonConfigForegroundColor": "#000000", + "ButtonUpdatesForegroundColor": "#000000", + "ButtonBackgroundColor": "#F5F5F5", + "ButtonBackgroundPressedColor": "#1A1A1A", + "CheckboxMouseOverColor": "#999999", + "ButtonBackgroundMouseoverColor": "#C2C2C2", + "ButtonBackgroundSelectedColor": "#F0F0F0", + "ButtonForegroundColor": "#000000", + "ToggleButtonOnColor": "#2e77ff" + }, + "Matrix": { + "ComboBoxBackgroundColor": "#000000", + "LabelboxForegroundColor": "#FFEE58", + "MainForegroundColor": "#9CCC65", + "MainBackgroundColor": "#000000", + "LabelBackgroundColor": "#000000", + "LinkForegroundColor": "#add8e6", + "LinkHoverForegroundColor": "#FFFFFF", + "ComboBoxForegroundColor": "#FFEE58", + + "ProgressBarForegroundColor": "#222222", + "ProgressBarBackgroundColor": "Transparent", + "ProgressBarTextColor": "#cccccc", + + "ButtonInstallBackgroundColor": "#222222", + "ButtonTweaksBackgroundColor": "#333333", + "ButtonConfigBackgroundColor": "#444444", + "ButtonUpdatesBackgroundColor": "#555555", + "ButtonInstallForegroundColor": "#FFFFFF", + "ButtonTweaksForegroundColor": "#FFFFFF", + "ButtonConfigForegroundColor": "#FFFFFF", + "ButtonUpdatesForegroundColor": "#FFFFFF", + "ButtonBackgroundColor": "#000019", + "ButtonBackgroundPressedColor": "#FFFFFF", + "ButtonBackgroundMouseoverColor": "#A55A64", + "ButtonBackgroundSelectedColor": "#FF5733", + "ButtonForegroundColor": "#9CCC65", + "ToggleButtonOnColor": "#2e77ff", + + "BorderColor": "#FFAC1C", + "BorderOpacity": "0.8", + "ShadowPulse": "0:0:3" + }, + "Dark": { + "ComboBoxBackgroundColor": "#000000", + "LabelboxForegroundColor": "#FFEE58", + "MainForegroundColor": "#9CCC65", + "MainBackgroundColor": "#000000", + "LabelBackgroundColor": "#000000", + "LinkForegroundColor": "#add8e6", + "LinkHoverForegroundColor": "#FFFFFF", + "ComboBoxForegroundColor": "#FFEE58", + + "ProgressBarForegroundColor": "#222222", + "ProgressBarBackgroundColor": "Transparent", + "ProgressBarTextColor": "#cccccc", + + "ButtonInstallBackgroundColor": "#222222", + "ButtonTweaksBackgroundColor": "#333333", + "ButtonConfigBackgroundColor": "#444444", + "ButtonUpdatesBackgroundColor": "#555555", + "ButtonInstallForegroundColor": "#FFFFFF", + "ButtonTweaksForegroundColor": "#FFFFFF", + "ButtonConfigForegroundColor": "#FFFFFF", + "ButtonUpdatesForegroundColor": "#FFFFFF", + "ButtonBackgroundColor": "#000019", + "ButtonBackgroundPressedColor": "#9CCC65", + "ButtonBackgroundMouseoverColor": "#FF5733", + "ButtonBackgroundSelectedColor": "#FF5733", + "ButtonForegroundColor": "#9CCC65", + "ToggleButtonOnColor": "#2e77ff", + + "BorderColor": "#FFAC1C" + } } diff --git a/functions/private/Get-TabXaml.ps1 b/functions/private/Get-TabXaml.ps1 index 5eef64176f..3dc674fd8e 100644 --- a/functions/private/Get-TabXaml.ps1 +++ b/functions/private/Get-TabXaml.ps1 @@ -132,7 +132,6 @@ function Get-TabXaml { if ($columncount -gt 0) { $panelcount2 = [Int](($count)/$maxcount-0.5) - # Verify the indentation actually works... if ($panelcount -eq $panelcount2 ) { $blockXml += $precal_indent_m1 + "" + "`r`n" @@ -190,7 +189,7 @@ function Get-TabXaml { "HorizontalAlignment=""Left"" Margin=""5"" Padding=""20,5"" $($ButtonWidthStr)/>" + "`r`n" } - # else it is a checkbox + # else it's a checkbox default { $checkedStatus = If ($appInfo.Checked -eq $null) {""} else {" IsChecked=""$($appInfo.Checked)"""} if ($appInfo.Link -eq $null) { diff --git a/functions/private/Set-WinUtilUITheme.ps1 b/functions/private/Set-WinUtilUITheme.ps1 new file mode 100644 index 0000000000..bd89aa5c89 --- /dev/null +++ b/functions/private/Set-WinUtilUITheme.ps1 @@ -0,0 +1,74 @@ +function Set-WinUtilUITheme { + <# + .SYNOPSIS + Sets the theme of the XAML file + + .PARAMETER inputXML + A string representing the XAML object to modify + + .PARAMETER customThemeName + The name of the custom theme to set the XAML to. Defaults to 'matrix' + + .PARAMETER defaultThemeName + The name of the default theme to use when setting the XAML. Defaults to '_default' + + .EXAMPLE + Set-WinUtilUITheme -inputXAML $inputXAML + #> + + param ( + [Parameter(Mandatory, position=0)] + [string]$inputXML, + + [Parameter(position=1)] + [string]$customThemeName = 'matrix', + + [Parameter(position=2)] + [string]$defaultThemeName = '_default' + ) + + try { + # Note: + # Reason behind not caching the '$sync.configs.themes` object into a variable, + # because this code can modify the themes object.. meaning it's better to access it + # using the more verbose way, rather than introduce possible bugs into the code, just for the sake of readability. + # + if (-NOT $sync.configs.themes) { + throw [GenericException]::new("[Set-WinUtilTheme] Did not find 'config.themes' inside `$sync variable.") + } + + if (-NOT $sync.configs.themes.$defaultThemeName) { + throw [GenericException]::new("[Set-WinUtilTheme] Did not find '$defaultThemeName' theme in the themes config file.") + } + + if ($sync.configs.themes.$customThemeName) { + # Loop through every default theme option, and modify the custom theme in $sync variable, + # so that it has full options available for other functions to use. + foreach ($option in $sync.configs.themes.$defaultThemeName.PSObject.Properties) { + $optionName = $option.Name + $optionValue = $option.Value + if (-NOT $sync.configs.themes.$customThemeName.$optionName) { + $sync.configs.themes.$customThemeName | Add-Member -MemberType NoteProperty -Name $optionName -Value $optionValue + } + } + } else { + Write-Debug "[Set-WinUtilTheme] Theme '$customThemeName' was not found." + } + + foreach ($property in $sync.configs.themes.$customThemeName.PSObject.Properties) { + $key = $property.Name + $value = $property.Value + # Add curly braces around the key + $formattedKey = "{$key}" + # Replace the key with the value in the input XML + $inputXML = $inputXML.Replace($formattedKey, $value) + } + } + catch { + Write-Host "[Set-WinUtilTheme] Unable to apply theme" -ForegroundColor Red + Write-Host "$($psitem.Exception.Message)" -ForegroundColor Red + $inputXML = "" # Make inputXML equal an empty string, indicating something went wrong to the function caller. + } + + return $inputXML; +} diff --git a/functions/private/Set-WinUtilUiTheme.ps1 b/functions/private/Set-WinUtilUiTheme.ps1 deleted file mode 100644 index 45db1ab42a..0000000000 --- a/functions/private/Set-WinUtilUiTheme.ps1 +++ /dev/null @@ -1,50 +0,0 @@ -function Set-WinUtilUITheme { - <# - .SYNOPSIS - Sets the theme of the XAML file - - .PARAMETER inputXML - A string representing the XAML object to modify - - .PARAMETER themeName - The name of the theme to set the XAML to. Defaults to 'matrix' - - .EXAMPLE - Set-WinUtilUITheme -inputXAML $inputXAML - #> - - param - ( - [Parameter(Mandatory, position=0)] - [string]$inputXML, - [Parameter(position=1)] - [string]$themeName = 'matrix' - ) - - try { - # Convert the JSON to a PowerShell object - $themes = $sync.configs.themes - # Select the specified theme - $selectedTheme = $themes.$themeName - - if ($selectedTheme) { - # Loop through all key-value pairs in the selected theme - foreach ($property in $selectedTheme.PSObject.Properties) { - $key = $property.Name - $value = $property.Value - # Add curly braces around the key - $formattedKey = "{$key}" - # Replace the key with the value in the input XML - $inputXML = $inputXML.Replace($formattedKey, $value) - } - } else { - Write-Host "Theme '$themeName' not found." - } - - } catch { - Write-Warning "Unable to apply theme" - Write-Warning $psitem.Exception.StackTrace - } - - return $inputXML; -} diff --git a/scripts/main.ps1 b/scripts/main.ps1 index c1d476f43a..b1e436aa6e 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -61,15 +61,26 @@ if ((Get-WinUtilToggleStatus WPFToggleDarkMode) -eq $True) { } else { $ctttheme = 'Classic' } -$inputXML = Set-WinUtilUITheme -inputXML $inputXML -themeName $ctttheme + +$inputXML = Set-WinUtilUITheme -inputXML $inputXML -customThemeName $ctttheme +if ($inputXML -eq "") { + Write-Host "Failed to statically apply theming to xaml content using Set-WinUtilTheme, please check previous Error/Warning messages." -ForegroundColor Red + Write-Host "Quitting winutil..." -ForegroundColor Red + $sync.runspace.Dispose() + $sync.runspace.Close() + [System.GC]::Collect() + exit 1 +} [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework') [xml]$XAML = $inputXML # Read the XAML file +$readerOperationSuccessful = $false # There's more cases of failure then success. $reader = (New-Object System.Xml.XmlNodeReader $xaml) try { $sync["Form"] = [Windows.Markup.XamlReader]::Load( $reader ) + $readerOperationSuccessful = $true } catch [System.Management.Automation.MethodInvocationException] { Write-Warning "We ran into a problem with the XAML code. Check the syntax for this control..." Write-Host $error[0].Exception.Message -ForegroundColor Red @@ -81,6 +92,15 @@ try { Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed." } +if (-NOT ($readerOperationSuccessful)) { + Write-Host "Failed to parse xaml content using Windows.Markup.XamlReader's Load Method." -ForegroundColor Red + Write-Host "Quitting winutil..." -ForegroundColor Red + $sync.runspace.Dispose() + $sync.runspace.Close() + [System.GC]::Collect() + exit 1 +} + #=========================================================================== # Store Form Objects In PowerShell #=========================================================================== diff --git a/xaml/inputXML.xaml b/xaml/inputXML.xaml index 332122b04a..acedd9cb7b 100644 --- a/xaml/inputXML.xaml +++ b/xaml/inputXML.xaml @@ -305,13 +305,13 @@ - + + Foreground="{MainForegroundColor}" FontSize="{CloseIconFontSize}" Name="WPFCloseButton" />