Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/tatux.net #2

Merged
merged 5 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Modules/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Config.psd1
*git-ignore*
Binary file added Modules/.psd1
Binary file not shown.
33 changes: 33 additions & 0 deletions Modules/.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#region get public and private function definition files.
$Public = @(
Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -Exclude "*.Tests.ps1" -ErrorAction SilentlyContinue
)
$Private = @(
Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -Exclude "*.Tests.ps1" -ErrorAction SilentlyContinue
)
#endregion

#region source the files
foreach ($Function in @($Public + $Private)) {
$FunctionPath = $Function.fullname
try {
. $FunctionPath # dot source function
} catch {
Write-Error -Message "Failed to import function at $($FunctionPath): $_"
}
}
#endregion

#region read in or create an initial config file and variable
#. "$PSScriptRoot\Config.ps1" # uncomment to source config parsing logic
#endregion

#region set variables visible to the module and its functions only
$Date = Get-Date -UFormat "%Y.%m.%d"
$Time = Get-Date -UFormat "%H:%M:%S"
. "$PSScriptRoot\Colors.ps1"
#endregion

#region export Public functions ($Public.BaseName) for WIP modules
Export-ModuleMember -Function $Public.Basename
#endregion
21 changes: 21 additions & 0 deletions Modules/Colors.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Color variables for easy peasy splatting :-)
$Green = @{
Background = 'Black'
Foreground = 'Green'
}
$Cyan = @{
Background = 'Black'
Foreground = 'Cyan'
}
$Magenta = @{
Background = 'Black'
Foreground = 'Magenta'
}
$Red = @{
Background = 'Black'
Foreground = 'Red'
}
$Yellow = @{
Background = 'Black'
Foreground = 'Yellow'
}
32 changes: 32 additions & 0 deletions Modules/Config.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#region read in or create an initial config file and variable
$ConfigFile = "Config.psd1"

if (Test-Path "$PSScriptRoot\$ConfigFile") {
try {
$Params = @{
BaseDirectory = $PSScriptRoot
FileName = $ConfigFile
}
$Config = Import-LocalizedData @Params
foreach ($variable in $Config.keys) {
Write-Verbose "Setting $var variable."
New-Variable -Name "$variable" -Value $Config.$variable -Force
Export-ModuleMember -Variable $variable
}
} catch {
Write-Warning "Invalid configuration data in $ConfigFile."
Write-Warning "Please fill out or correct $PSScriptRoot\$ConfigFile."
Write-Verbose $_.Exception.Message
Write-Verbose $_.InvocationInfo.ScriptName
Write-Verbose $_.InvocationInfo.PositionMessage
}
} else {
@"
@{
Variable = ""
}
"@ | Out-File -Encoding UTF8 -FilePath "$PSScriptRoot\$ConfigFile"
Write-Warning "Generated $PSScriptRoot\$ConfigFile."
Write-Warning "Please edit $ConfigFile and re-import module."
}
#endregion
5 changes: 4 additions & 1 deletion Modules/README.MD
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
Function module packages go here
# Powershell Module

*Module Description*

18 changes: 18 additions & 0 deletions Modules/Tatux.Utils/Public/Invoke-NativeExpression.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function Invoke-NativeExpression {
param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)]
[string]$Expression
)

process {
$executable, $arguments = $expression -split ' '
$arguments = $arguments | foreach { "'$_'" }
$arguments = $arguments -join ' '
$command = $executable + ' ' + $arguments

if ($command) {
Write-Verbose "Invoking '$command'"
Invoke-Expression -command $command
}
}
}
80 changes: 57 additions & 23 deletions Modules/Tatux.Utils/Public/New-NTModuleTemplate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function New-NTModuleTemplate {
Param (
[Parameter(Mandatory, ValueFromPipeline)]
[string[]]$Names,
[System.IO.DirectoryInfo]$Path = $(Get-Item -Path .\).FullName,
[System.IO.DirectoryInfo]$Path = $PWD.Path,
[string]$Author = $env:USER,
[string]$CompanyName = "",
[string]$Description = "Module Description",
Expand All @@ -77,7 +77,6 @@ function New-NTModuleTemplate {
$Colors = "$Templates\Colors.ps1"
$GitIgnore = "$Templates\GitIgnore"
}

process {
foreach ($Name in $Names) {
$Directories = @(
Expand All @@ -87,30 +86,65 @@ function New-NTModuleTemplate {
'Public\Tests'
'Private\Tests'
)
foreach ($Directory in $Directories) {
New-Item -Name "$Path\$Name\$Directory" -ItemType 'Container'
Set-Content -Value "# $Name $Directory Functions" -Path "$Path\$Name\$Directory\README.md"
Write-Verbose "Generated $Path\$Name\$Directory."
$ParentPath = Join-Path -Path $Path -ChildPath $Name
try {
if (-not (Test-Path -Path $ParentPath)) {
Write-Verbose "Creating Module path: $ParentPath."
New-Item -Path $ParentPath -Type Directory -ErrorAction Stop
}
}

Set-Content -Value "# $Name Powershell Module" -Path "$Path\$Name\README.md"
Add-Content -Value "`n*$Description*`n" -Path "$Path\$Name\README.md"

Copy-Item $Config "$Path\$Name\Config.ps1"
Write-Verbose "Copied $Config to $Path\$Name\Config.ps1."

catch {
Write-Verbose "Failed to create Module path: $ParentPath."
$_
break
}
try {
foreach ($Directory in $Directories) {
$FullPath = Join-Path -Path $ParentPath -ChildPath $Directory
if (-not (Test-Path -Path $FullPath)) {
Write-Verbose "Creating path: $FullPath."
New-Item -Path $FullPath -Type Directory -ErrorAction Stop
Write-Verbose "Created path: $FullPath."
}
$ReadmePath = Join-Path -Path $FullPath -ChildPath "README.md"
Set-Content -Value "# $Name $Directory" -Path $ReadmePath -ErrorAction Stop
}
}
catch {
Write-Verbose "Failed to create path: $FullPath."
$_
break
}

$ReadmePath = Join-Path -Path $Path -ChildPath "$Name\README.md"
Set-Content -Value "# $Name Powershell Module" -Path $ReadmePath
Add-Content -Value "`n*$Description*`n" -Path $ReadmePath

$ConfigPath = Join-Path -Path $Path -ChildPath "$Name\Config.ps1"
if (Test-Path -Path $Config) {
Copy-Item $Config $ConfigPath
Write-Verbose "Copied $Config to $ConfigPath."
}

if ($UncommentConfig) {
(Get-Content $Module) -Replace ('\#\.\s', '. ') |
Set-Content "$Path\$Name\$Name.psm1"
$ModuleContent = Get-Content $Module
$ModulePath = Join-Path -Path $Path -ChildPath "$Name\$Name.psm1"
$ModuleContent -Replace ('\#\.\s', '. ') | Set-Content $ModulePath
}
else {
Copy-Item $Module "$Path\$Name\$Name.psm1"
$ModulePath = Join-Path -Path $Path -ChildPath "$Name\$Name.psm1"
if (Test-Path -Path $Module) {
Copy-Item $Module $ModulePath
}
}
Write-Verbose "Copied $Module to $Path\$Name\$Name.psm1."

Copy-Item $Colors "$Path\$Name\Colors.ps1"
Write-Verbose "Copied $Colors to $Path\$Name\Colors.ps1."

Write-Verbose "Copied $Module to $ModulePath."

$ColorsPath = Join-Path -Path $Path -ChildPath "$Name\Colors.ps1"
if (Test-Path -Path $Colors) {
Copy-Item $Colors $ColorsPath
Write-Verbose "Copied $Colors to $ColorsPath."
}

$Params = @{
Path = "$Path\$Name\$Name.psd1"
Author = $Author
Expand All @@ -126,9 +160,9 @@ function New-NTModuleTemplate {
}
New-ModuleManifest @Params
Write-Verbose "Generated $Module manifest at $Path\$Name\$Name.psd1."

Copy-Item $GitIgnore "$Path\$Name\.gitignore"
Write-Verbose "Copied $GitIgnore to $Path\$Name\.gitignore."
}
}
}
}
2 changes: 2 additions & 0 deletions Modules/Tatux.Win.Admin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Config.psd1
*git-ignore*
1 change: 1 addition & 0 deletions Modules/Tatux.Win.Admin/Classes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Tatux.Win.Admin Classes
33 changes: 33 additions & 0 deletions Modules/Tatux.Win.Admin/Classes/Taskbar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Runtime.InteropServices;

public class Taskbar
{
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern IntPtr FindWindow(
string lpClassName,
string lpWindowName);

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);

public static bool IsTaskbarLoaded()
{
var taskbarHandle = FindWindow("Shell_traywnd", "");
var startButtonHandle = FindWindowEx(taskbarHandle, IntPtr.Zero, "Start", null);
return taskbarHandle != IntPtr.Zero && startButtonHandle != IntPtr.Zero;
}

public static IntPtr GetTaskbarHandle()
{
var taskbarHandle = FindWindow("Shell_traywnd", "");
var startButtonHandle = FindWindowEx(taskbarHandle, IntPtr.Zero, "Start", null);
return taskbarHandle;
}
public static IntPtr GetTaskbarStartHandle()
{
var taskbarHandle = FindWindow("Shell_traywnd", "");
var startButtonHandle = FindWindowEx(taskbarHandle, IntPtr.Zero, "Start", null);
return startButtonHandle;
}
}
21 changes: 21 additions & 0 deletions Modules/Tatux.Win.Admin/Colors.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Color variables for easy peasy splatting :-)
$Green = @{
Background = 'Black'
Foreground = 'Green'
}
$Cyan = @{
Background = 'Black'
Foreground = 'Cyan'
}
$Magenta = @{
Background = 'Black'
Foreground = 'Magenta'
}
$Red = @{
Background = 'Black'
Foreground = 'Red'
}
$Yellow = @{
Background = 'Black'
Foreground = 'Yellow'
}
32 changes: 32 additions & 0 deletions Modules/Tatux.Win.Admin/Config.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#region read in or create an initial config file and variable
$ConfigFile = "Config.psd1"

if (Test-Path "$PSScriptRoot\$ConfigFile") {
try {
$Params = @{
BaseDirectory = $PSScriptRoot
FileName = $ConfigFile
}
$Config = Import-LocalizedData @Params
foreach ($variable in $Config.keys) {
Write-Verbose "Setting $var variable."
New-Variable -Name "$variable" -Value $Config.$variable -Force
Export-ModuleMember -Variable $variable
}
} catch {
Write-Warning "Invalid configuration data in $ConfigFile."
Write-Warning "Please fill out or correct $PSScriptRoot\$ConfigFile."
Write-Verbose $_.Exception.Message
Write-Verbose $_.InvocationInfo.ScriptName
Write-Verbose $_.InvocationInfo.PositionMessage
}
} else {
@"
@{
Variable = ""
}
"@ | Out-File -Encoding UTF8 -FilePath "$PSScriptRoot\$ConfigFile"
Write-Warning "Generated $PSScriptRoot\$ConfigFile."
Write-Warning "Please edit $ConfigFile and re-import module."
}
#endregion
1 change: 1 addition & 0 deletions Modules/Tatux.Win.Admin/Private/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Tatux.Win.Admin Private
1 change: 1 addition & 0 deletions Modules/Tatux.Win.Admin/Private/Tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Tatux.Win.Admin Private\Tests
1 change: 1 addition & 0 deletions Modules/Tatux.Win.Admin/Public/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Tatux.Win.Admin Public
27 changes: 27 additions & 0 deletions Modules/Tatux.Win.Admin/Public/Test-WindowsTaskbar.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This function determines if the Windows Taskbar is loaded using a c# class.
function Test-WindowsTaskbar {
begin {
try {
if (-not ([System.Management.Automation.PSTypeName]'Taskbar').Type) {
Add-Type -Path "$PSScriptRoot\..\Classes\Taskbar.cs" -ErrorAction Stop
}

}
catch {
Write-Error "Failed to load Taskbar class."
$_
break
}
}
process {
$taskbarStatus = [Taskbar]::IsTaskbarLoaded()
if ($taskbarStatus) {
Write-Verbose "Taskbar is visible."
$true
}
else {
Write-Verbose "Taskbar is not visible."
$false
}
}
}
1 change: 1 addition & 0 deletions Modules/Tatux.Win.Admin/Public/Tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Tatux.Win.Admin Public\Tests
4 changes: 4 additions & 0 deletions Modules/Tatux.Win.Admin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Tatux.Win.Admin Powershell Module

*Module Description*

Binary file added Modules/Tatux.Win.Admin/Tatux.Win.Admin.psd1
Binary file not shown.
Loading
Loading