WFControlsLIB.psm1

<#
    My Function
#>


Add-Type -AssemblyName System.Windows.Forms

###| winform |###
function form {
    param(
        [string]$sizex,
        [string]$sizey,
        [string]$startposition,
        [bool]$maximizebox,
        [bool]$controlbox,
        [string]$formborderstyle

    )
    $form = New-Object System.Windows.Forms.Form
    $form.Size = New-Object System.Drawing.Point($sizex, $sizey)
    $form.StartPosition = $startposition
    $form.MaximizeBox = $maximizebox
    $form.ControlBox = $controlbox
            if ($formborderstyle -and $formborderstyle -ne "") {
        $form.FormBorderStyle = $formborderstyle
    }

    return $form
}
function button {
    param(
        [string]$text,
        [string]$font,
        [string]$textalign = "MiddleCenter",
        [bool]$autosize,
        [int]$sizex,
        [int]$sizey,
        [int]$x,
        [int]$y,
        [string]$backcolor,
        [string]$flatstyle = "Flat",
        [int]$flatappearance_bordersize,
        [string]$imagepath,
        [string]$imagelayout = "Center",
        [scriptblock]$onclick,
        [bool]$visible = $true
    )
    
    $button = New-Object System.Windows.Forms.Button
    $button.Text = $text
    $button.Font = $font
    $button.TextAlign = $textalign
    $button.AutoSize = $autosize
    $button.Size = New-Object System.Drawing.Size($sizex, $sizey)
    $button.Location = New-Object System.Drawing.Point($x, $y)
    $button.BackColor = $backcolor
    $button.FlatStyle = $flatstyle
    $button.FlatAppearance.BorderSize = $flatappearance_bordersize
    $button.Visible = $visible
  
    if ($imagepath) {
        $image = [System.Drawing.Image]::FromFile($imagepath)
        $button.BackgroundImage = $image
        $button.BackgroundImageLayout = $imagelayout
    }
    
    if($onclick) {
        $button.Add_Click($OnClick)
    }

    return $button
}
function label{
    param(
        [string]$text,
        [string]$font,
        [bool]$autosize,
        [int]$sizex,
        [int]$sizey,
        [string]$borderstyle = "None",
        [int]$x,
        [int]$y,
        [bool]$visible = $true
    )

    $label = New-Object System.Windows.Forms.Label
    $label.Text = $text
    $label.font = $font
    $label.AutoSize = $autosize
    $label.Size = New-Object System.Drawing.Size($sizex, $sizey)
    $label.Location = New-Object System.Drawing.Point($x, $y)
    $label.BorderStyle = $borderstyle
    $label.Visible = $visible

    return $label
}
function textbox {
    param(
        [string]$text,
        [string]$font,
        [string]$textalign,
        [string]$borderstyle,
        [bool]$multiline,
        [int]$sizex,
        [int]$sizey,
        [int]$x,
        [int]$y,
        [bool]$visible = $true
    )

    $textbox = New-Object System.Windows.Forms.TextBox
    $textbox.Text = $text
    $textbox.Font = $font
    $textbox.TextAlign = "Left"
    $textbox.BorderStyle = $borderstyle
    $textbox.Multiline = $multiline
    $textbox.Size = New-Object System.Drawing.Size($sizex, $sizey)
    $textbox.Location = New-Object System.Drawing.Point($x, $y)
    $textbox.Visible = $visible
        if ($borderstyle -and $borderstyle -ne "") {
            $textbox.BorderStyle = [System.Windows.Forms.BorderStyle]::$borderstyle
    }

    return $textbox
}
function checkbox{
    param(
        [int]$x,
        [int]$y,
        [bool]$checked,
        [bool]$visible = $true,
        [scriptblock]$checkedchanged
    )

    $checkbox = New-Object System.Windows.Forms.CheckBox
    $checkbox.Location = New-Object System.Drawing.Point($x, $y)
    $checkbox.Checked = $checked
    $checkbox.Visible = $visible
        if($checkedchanged) {
            $checkbox.Add_CheckedChanged($checkedchanged)
        }

    return $checkbox
}
function combobox{
    param(
        [string]$dropdownstyle,
        [string]$font,
        [int]$sizex,
        [int]$sizey,
        [bool]$autosize,
        [int]$x,
        [int]$y,
        [string[]]$items,
        [string]$flatstyle,
        [string]$defaultselection,
        [bool]$visible = $true
    )
    
    $combobox = New-Object System.Windows.Forms.ComboBox
    $combobox.Font = $font
    $combobox.Size = New-Object System.Drawing.Size($sizex, $sizey)
    $combobox.AutoSize = $autosize
    $combobox.Location = New-Object System.Drawing.Point($x, $y)
    $combobox.Items.AddRange(@($items))
    $combobox.FlatStyle = $flatstyle
    $combobox.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::$dropdownstyle
    $combobox.Visible = $visible
    $defaultcbindex = $combobox.FindStringExact($defaultselection)
        if($defaultcbindex -ge 0){
            $combobox.SelectedIndex = $defaultcbindex
        }
    
    
    return $combobox
}
function tab{
    param(
        [int]$sizex,
        [int]$sizey,
        [int]$x,
        [int]$y,
        [bool]$visible = $true
    )
    
    $tab = New-Object System.Windows.Forms.TabControl
    $tab.Size = New-Object System.Drawing.Size($sizex, $sizey)
    $tab.Location = New-Object System.Drawing.Point($x, $y)
    $tab.Visible = $visible

    return $tab
}
function tabpage{
    param(
        [string]$text,
        [bool]$visible = $true
    )

    $tabpage = New-Object System.Windows.Forms.TabPage
    $tabpage.Text = $text
    $tabpage.Visible = $visible

    return $tabpage
}
function checkedlistbox{
    param (
        [int]$x,
        [int]$y,
        [int]$sizex,
        [int]$sizey,
        [bool]$autosize = $false,
        [string[]]$items
    )

    $checkedlistbox = New-Object System.Windows.Forms.CheckedListBox
    $checkedlistbox.Location = New-Object System.Drawing.Point($x, $y)
    $checkedlistbox.Size = New-Object System.Drawing.Size($sizex ,$sizey)
    $checkedlistbox.AutoSize = $autosize
        foreach($item in $items){
            $checkedlistbox.items.addrange(@("$item"))
        }

    return $checkedlistbox
}
function tooltip{
    param(
        [System.Windows.Forms.Control]$control,
        [string]$text
    )

    $tooltip = New-Object System.Windows.Forms.Tooltip
    $tooltip.SetToolTip($control, $text)
}
function listbox {
    param(
        [int]$sizex,
        [int]$sizey,
        [int]$x,
        [int]$y,
        [string]$font,
        [int]$itemheight,
        [string[]]$items,
        [string]$selecteditem = 0,
        [bool]$visible = $true
    )

    $listbox = New-Object System.Windows.Forms.ListBox
    $listbox.Size = New-Object System.Drawing.Size($sizex, $sizey)
    $listbox.Location = New-Object System.Drawing.Point($x, $y)
    $listbox.Font = $font
    $listbox.ItemHeight = $itemheight
    $listbox.Items.AddRange(@($items))
    $listbox.SelectedItem = $selecteditem
    $listbox.Visible = $visible

    return $listbox
}

###| criptografia |###

function encryptcontent{
    param(
        [string]$content,
        [byte]$key = [byte[]] (0..31)
    )

        $contentbytes = [System.Text.Encoding]::UTF8.GetBytes($content)

        $aes = New-Object System.Security.Cryptography.AesCryptoServiceProvider
        $aes.KeySize = 256
        $aes.Mode = [System.Security.Cryptography.CipherMode]::CBC
        $aes.Padding = [System.Security.Cryptography.PaddingMode]::PKCS7
        $aes.GenerateIV()

        $iv = $aes.IV
        $encryptor = $aes.CreateEncryptor($key, $iv)

        $encryptedbytes = $encryptor.TransformFinalBlock($contentbytes, 0, $contentbytes.Length)

        $result = $iv + $encryptedBytes

        $encryptedbase64 = [Convert]::ToBase64String($result)
        
        return $encryptedbase64
}

function decryptcontent{
    param(
        [string]$content,
        [byte[]]$key = [byte[]] (0..31)
    )

    $encryptedbytes = [Convert]::FromBase64String($encryptedbase64)

    $iv = $encryptedbytes[0..15]
    $data = $encryptedbytes[16..($encryptedbytes.Length - 1)]

    $aes = New-Object System.Security.Cryptography.AesCryptoServiceProvider
    $aes.KeySize = 256
    $aes.Mode = [System.Security.Cryptography.CipherMode]::CBC
    $aes.Padding = [System.Security.Cryptography.PaddingMode]::PKCS7

    $decryptor = $aes.CreateDecryptor($key, $iv)

    $decryptedbytes = $decryptor.TransformFinalBlock($data, 0, $data.Length)

    $decryptedcontent = [System.Text.Encoding]::UTF8.GetString($decryptedbytes)

    return $decryptedcontent
}

function keygen{
$global:randombytes = New-Object byte[] 32
$randomgenerator = [System.Security.Cryptography.RandomNumberGenerator]::Create()
$randomgenerator.GetBytes($randombytes)

$hexkey = [System.BitConverter]::ToString($randombytes) -replace '-'

return $randombytes
}