Add-Type -assembly System.Windows.Forms
# Add-Type -Assembly System.Windows.Forms.ShowNotification


#region RESOURCE URLS #################
# https://channel9.msdn.com/Series/GuruPowerShell/GUI-Form-Using-PowerShell-Add-Panel-Label-Edit-box-Combo-Box-List-Box-CheckBox-and-More
# https://social.technet.microsoft.com/Forums/windowsserver/en-US/bc47bfa7-a275-41db-b2bf-da9b1051f29f/powershell-gui-adding-and-removing-controls
# https://blog.danskingdom.com/powershell-functions-to-get-an-xml-node-and-get-and-set-an-xml-elements-value-even-when-the-element-does-not-already-exist/
# https://lazywinadmin.com/2016/07/powershellwinforms-row-header.html
#endregion

#region VARIABLES ##################
# $AppName                    = 'InfoDev Tools'
# $AppVersion                 = '2021.1.0527.1'
$ComputerName               = $env:COMPUTERNAME
# $UserDocuments              = [Environment]::GetFolderPath("MyDocuments")
# $InfoDevToolsFolder         = $UserDocuments + "\InfoDev Tools"
# $ScriptName                 = $MyInvocation.MyCommand.Name
# $LogsPath                   = $PSScriptRoot + "\Logs\"
# $LogPath                    = $LogsPath
# $LogFilename                = $ScriptName + "_Log.txt"
$TempPath                   = "C:\temp\DITAFilesTemp"
# $AZCopyExe                  = $PSScriptRoot + "\azcopy.exe"
$CurrentDateTime            = Get-Date -Format "MM/dd/yyyy HH:mm"
# $Path_GearImage             = $PSSCriptRoot + "\images\Gear-200px.gif"
$Path_DITAInstallationFiles = "\\zusscgrcprodwebhelp.file.core.windows.net\webhelp\dev\InfoDev\DITA_InstallationFiles"
$Path_DITAZipFile           = "\\zusscgrcprodwebhelp.file.core.windows.net\webhelp\dev\InfoDev\DITA_InstallationFiles\DITA.zip"
$Path_DITAZipArchives       = "\\zusscgrcprodwebhelp.file.core.windows.net\webhelp\dev\InfoDev\DITA_InstallationFiles\archives"
$Path_Scripts               = "C:\DITA\scripts"
$Path_Resources             = "C:\DITA\server\resources"
$Path_ServerIndex           = "C:\DITA\server\index.html"
$Path_VersionTextFile       = "C:\DITA\version.txt"
$Path_WKFSOxygenFiles       = "C:\DITA\WKFS_Oxygen_Files"
$CompletionSoundPath        = "C:\Windows\Media\notify.wav"
$AnalyzeCollectionLogText   = ""
#endregion

#region RESOURCES #################
# Main Form
#set icon for form using Base64
# This base64 string holds the bytes that make up the orange 'G' icon (just an example for a 32x32 pixel image)
# $iconBase64      = 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuMTnU1rJkAAAB50lEQVRIS7WWzytEURTHZ2FhaWFhYWFhYWFhaWFh6c+wsGCapJBJU0hRSrOgLBVSmkQoSpqyUJISapIFJU0i1KQp1PG9826vO9+Z97Pr22dz3pxzv/PO/fUSkvxfOLYOx9bh2DocBzPZKlPtku2VuS7JtMlwIydUw7EnGO50Rd4ehPRdlru87GWUMZVU4LgOqLza0cP56PdHNga4NthgsUc+i3qIQOH9qDzAYLZTyiVd7Ah/8/lGztclNyLbY5JfksKxeuiKRvAzwOy93OsyR+9Pam6HajLHm5UfXhTQT34GqDH1eCGjTZxjkmqQmQ5+6Gdgth5NQLsoIRwca7AoTZ1k1UM0p7Y/QXCsof4sdOvRrRlgeZgyu49eY/0cTDO76ShzcJnTQ0O0NvA2XioWqjIrcKy5PdQ1kLl90CKsVC9F2GiYVVPuiQaDiRb1TzGWw9eHzoEiGGwO6hpHWFRe04vuu4pggCPIFPwowSWmAXa/qdKr5zaOaQBwyps6W+UEh/gGtasFlrjCKC2+ATia15WucHpf76vna/2ylVLntnmeRzbApsUQ4RXZwAFnAC7eMMLNSrWhDEC6RfUac1D3+sRew87HhVzvC4PjYLBecRxhDsByn/qEoYRqOLYOx9bh2DocWyaZ+APgBBKhVfsHwAAAAABJRU5ErkJggg=='
# $iconBytes       = [Convert]::FromBase64String($iconBase64)
# $stream          = New-Object IO.MemoryStream($iconBytes, 0, $iconBytes.Length)
# $stream.Write($iconBytes, 0, $iconBytes.Length)
# $Form.Icon       = [System.Drawing.Icon]::FromHandle((New-Object System.Drawing.Bitmap -Argument $stream).GetHIcon())


# $FormIcon           = New-Object system.drawing.icon ($PSScriptRoot + "\resources\images\Tools_16.png")
# $imgBtnOpen    = New-Object System.Drawing.Bitmap ($PSScriptRoot + "\resources\images\folder16.png")
$imgBtnCloseBase64      = "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABmJLR0QA/wD/AP+gvaeTAAABaklEQVRIDe2VPUsDQRCG90IKsTiMIPlDNtb+AT9AxMoPVFCRgFgYMCiIjShW9jb+F/0LCkZjq+fzxiUse1lvN2iX432Ymd2dmcwm5IwZPyk3UBRFDjfwDKlSzjVJuduz7gb4FzAPl/ACKZrh8BrUYBHKovsbnJV34lbIPYdX97S6ubHG67oLib6KT7k5fgN370/8ygaM/AQnfjfW2vDor/txZQMSHmCHYqfYvqy/TaA9TFj+r6h0MsuydQp+sLGP1XeU4S/DMXsH2F9V2UDZKkRxFd5TDFHFOWdirshQXOeaSrA07ZoNw6ZyAlvoihJLcASaRFeTsbfCdF+sBVXZgMwOqHiHYof4mmgSuwk92ICgYhrMkt2m+C62L/wtPv0nwRzEiySpZUZ8SG5B4abX3OA/fL/BO00aMKqmSezCQPWB9+PcY1YZcwKrPy5MtBqcXDDG3MFwUVgvnFtsD1KlHL2s8uHVx6uBG/gGgRf4SH/3ykUAAAAASUVORK5CYII="
$imgBtnClose            = [Convert]::FromBase64String($imgBtnCloseBase64)
# $imgBtnFolderBrowse = New-Object System.Drawing.Bitmap ($PSScriptRoot + "\resources\images\folder_16px.png")
$imgBtnMinimizeBase64   = "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABmJLR0QA/wD/AP+gvaeTAAAA6UlEQVRIDe2VQQrCMBBFU+nCVbGCBxD0RF5AV4prD6IgLgTFlXsv47IXULDqAeobhDK2tTZVcJPyH5kkM5l0aBNj3GNTgSRJAtjCCWwlMRuCAp3T1x3sJQxgBWewUQfnKTRgBHmR/Qrz/Ey1EWIXcNHekk335fViPWBpy+ItHZNNoOd+YrsEH8voSvT/EmWPipcd8VeOGehCmSLP89bvHEoTEDSDHpTpyGS9BOysT/BXyn6mN1YLoa7aBMaQyk+tp3GgmVD7Jq0cXDSVFeI5NMbsoVgsLBfOjvYOtpIYuazkRC5O4EaLKvAAlretqANQcGwAAAAASUVORK5CYII="
$imgBtnMinimize         = [Convert]::FromBase64String($imgBtnMinimizeBase64)
$imgBtnWelcomeBase64    = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAACL0lEQVRYCe2Vz0sVURTHBw0XvQK1hWDtXEXrWpqViYvcBOJS3egqs0U/3EggEoh7F0H+AyoE7d5CEgRBKaQghJCW2cLwmYih7/r5vnePDDlyn3lTAofv55x775z5njvzxjFJzo//7Qk456rhAbyFAqxC96ncB4164Rtk6eE/3QQdH4NJd/2CSQM8AekLYQAWIBd9M5iqKcl1O+eqrAHjm7AFafUksQ/cf4B0jZCDPvgAaS0zaYWDDUbbB6ZTIC0SNsC0xmAMbkVrljbC+AJ0wicwFRnkQes16froY5p8BtMeA71sd6I3yjKkWSNIvwiDUGd1jO/DHKx73pPj/ili2AbSnDVWZmEE9DOQDumVaqKAte6a5CbMkMk9UPMd8nO4CDkYgN+gc3F+Isxeg/QotQE9dq09szXLLA6BNGtrJ8o4zYN014yYbIJUa2uWWawHacPWQrkqUHDdn1/xOZ1ceuLHWWv+VHYKbeCSv6zdZ6UlBeiFP9XvFxZ9PlniWX4FqUC4ITdyB0g7hPRLqH9Oegn1rWhJYhw0GAKTNjHM5CpMQJaKLI7F6F3ywKwe7KVjWJFU31UyiBFoOQ5SnjAD6/Ad3sBt51ydp5k8DVKREOeriFEDbMMuNIVuipqnIP0kXAnVV3Qeo0lXPkYruYDSdyC9TGIcOLWA9LESPwqPVR/0xPAySIVgMQUUHqueS8LCtKRwZbmiVEwoz46OoS/h0VdGOnPmG4h0H+c2f/8E9gGPzxVB9m7XqAAAAABJRU5ErkJggg=="
$imgBtnWelcome          = [Convert]::FromBase64String($imgbtnWelcomeBase64)
$imgbtnCollectBase64    = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAABm0lEQVRYCe2Tz0rDQBDGm+KlICL4QILgqQf/gFWsoGhBKghevHjx4NP04NmjHn0PH8GLf7v+ZtmJmzSbJqHRy4bv6+zOzM58mU07nfjECeQmYH6fSS7UyrbbStUaRaOAP5kAn9UmXCm6mdYF0PiYxg/wifUathwkKeb+C0jcgOuhisQO4RcUTPk5COWmfpIUpQJI2obvjjtpAbfAfwGlKcZ883PmQuWGREVQAAl9+AYVst7SyjhPoDTFGBEx1thcKyccJ0XJxPTNWWbwwW4fjqDf/LyoTtDHYcWMAAIDKI0wFrfGmDuokPuWN5a9iBgFG4UCctIxIwDfEEoDjMWN1mB3DbUxS3vnpxqvZeW0YyqA/SXUBmJnxkpcBH5ihXu1mvrJFFBYAWzkzmWcLO0HdeXn+2sShvDI99VeU0ChAno4Ho2xY632V6rd1TtAI4UVICEcq7D5WKVIVdJIkQqoerZJXrfJoUWeiQL+fQJJ/j75Al/xLcMX+AwXiiRJBn7BIgH3JOzCVoCATM+lgi5jfFPYhz0YESfQ6gR+ABkA5F/r07W+AAAAAElFTkSuQmCC"
$imgbtnCollect          = [Convert]::FromBase64String($imgbtnCollectBase64)
$imgBtnCollectBase64    = "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABmJLR0QA/wD/AP+gvaeTAAABZ0lEQVRIDeWUv0oDQRCH90wQPEJe4rCIvZ1gYQLa+Qd9C8UmPoGVryR4KFb2dvoMphDERDN+P8jKErMX9zRV5L6dudnfzOztbnRuqf7MrAfdhX00xW9ESoNmihhtBknPyjw1K86hD22vlQ+K5T4Ws3NXRKF1kh/hAcagp8GwCRtZlj1h//bQ5AhG8AIDGMJh7aoka1s6YQFiJ/Ax4XhqrkN8LYxV+ojP4McqiXVFmMy7/7rTMF7pk9SCO1CT/ZiY+QOQ5hbbmqX7PmQEWwiuYBX06IYVOPr0HoepIiXvY/wd9Nv41/AGz+AvwBD/As091jU1TFCzV3xZjGswjEANfEx6X8jHPtEMQBbj3jVUwur+bYtmNqJB7JD3mNsNk3ivdci6psVUoaprWtBIWxmm/N4n2a8y+YfmDyrajeKL/VdBA23XObYNpZmVZiZfsTy6sjoTFC6NBim5utcpeksRS5va4FJJy8UXbY4/IbJxfVsAAAAASUVORK5CYII="
$imgBtnCollect          = [Convert]::FromBase64String($imgBtnCollectBase64)
#
#endregion

#region MODULES ###################
$StylesFile         = "$PSScriptRoot\modules\styles.ps1"
. $StylesFile
#endregion

#region ASSEMBLIES ###############
Add-Type -AssemblyName System.Data
Add-Type -AssemblyName System.Drawing
Add-Type -AssemblyName System.IO.Compression
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.XML

[System.Windows.Forms.Application]::EnableVisualStyles()
#endregion


function ArchiveDITAFile{
    $msg = "Archiving DITA file..."
    UpdateCollectionLog($msg)
    
    # Rename existing file
    $DateSuffix = Get-Date -Format "yyyyMMdd_HHmm"
    $NewZipName = "DITA_" + $DateSuffix + ".zip"
    Rename-Item -Path $Path_DITAZipFile $NewZipName
    # Move file to archives folder
    Move-Item -Path ($Path_DITAInstallationFiles + "\" + $NewZipName) $Path_DITAZipArchives
    Remove-Item -Path ($Path_DITAInstallationFiles + "\version.txt") -Force

    $msg = "DITA file archived"
    UpdateCollectionLog($msg)
}
function CreateForm(){
    #region Main Form
    $form               = New-Object System.Windows.Forms.Form
    $form.text          = "Deploy DITA Files"
    $form.Icon          = $FormIcon
    $form.Size          = New-Object System.Drawing.Size(800,480)
    $form.MinimumSize   = '800, 480'
    $form.BackColor     = $Backcolor
    $form.StartPosition = 'CenterScreen'
    $form.FormBorderStyle = "None" #None, FixedSingle, Fixed3D, FixedDialog, Sizable, FixedToolWindow, SizableToolWindow
    # $form.TopMost       = $true
    $form.Font  = $Font
    $form.ForeColor = 'White'


    #region Top Panel
    $pnlTop = New-Object System.Windows.Forms.Panel
    $pnlTop.Dock = "Top"
    $pnlTop.Height = 40
    $pnlTop.BackColor = $GroupBackColor
    $pnlTop
    $lblTopTitle             = New-Object System.Windows.Forms.Label
    $lblTopTitle.Text        = $form.Text
    $lblTopTitle.AutoSize    = $true
    $lblTopTitle.Location    = New-Object System.Drawing.Point(10,05)
    $lblTopTitle.Font        = $Font_NavBtn
    $btnMinimize = New-Object System.Windows.Forms.Button
    $btnMinimize.Image = $imgBtnMinimize
    $btnMinimize.Width = 32
    $btnMinimize.FlatAppearance.BorderSize = '0'
    $btnMinimize.Dock = "Right"
    $btnMinimize.FlatStyle = "Flat"
    $btnMinimize.Cursor = "Hand"
    $btnMinimize.Add_Click({
        $form.WindowState = "Minimized"
    })
    $btnClose = New-Object System.Windows.Forms.Button
    $btnClose.Image = $imgBtnClose
    $btnClose.Width = 32
    $btnClose.FlatAppearance.BorderSize = '0'
    $btnClose.Dock = "Right"
    $btnClose.FlatStyle = "Flat"
    $btnClose.Cursor = "Hand"
    $btnClose.Add_Click({
        $form.Close()
    })
    #endregion

    #region Left Panel
    $pnlLeft = New-Object System.Windows.Forms.Panel
    $pnlLeft.Location = "0,0"
    $pnlLeft.Width = 160
    $pnlLeft.Height = ($form.Height - $StatusStrip.Height)
    $pnlLeft.BackColor = $GroupBackColor #"#416C7B"
    $pnlLeft.BackColor = "#416C7B"
    $pnlLeft.Anchor = 'Top, Left, Bottom'

    # Left Panel Buttons
    $btnWelcome = New-Object System.Windows.Forms.Button
    $btnWelcome.Text = "        Welcome"
    $btnWelcome.TextAlign = "MiddleLeft"
    $btnWelcome.Width = $pnlLeft.Width
    $btnWelcome.Height = "50"
    $btnWelcome.Top = "40"
    $btnWelcome.FlatStyle = "Flat"
    $btnWelcome.Image = $imgbtnWelcome
    $btnWelcome.ImageAlign = "MiddleLeft"
    $btnWelcome.Cursor = "hand"
    $btnWelcome.Font = $Font_NavBtn
    $btnWelcome.FlatAppearance.BorderSize = 0
    $btnWelcome.BackColor = $BackColor
    $btnWelcome.Add_Click({
        ShowWelcome
    })

    $btnCollect = New-Object System.Windows.Forms.Button
    $btnCollect.Text = "        Collect"
    $btnCollect.TextAlign = "MiddleLeft"
    $btnCollect.Width = $pnlLeft.Width
    $btnCollect.Height = "50"
    $btnCollect.Top = ($btnWelcome.Top + $btnWelcome.Height)
    $btnCollect.FlatStyle = "Flat"
    $btnCollect.Image = $imgBtnCollect
    $btnCollect.ImageAlign = "MiddleLeft"
    $btnCollect.Cursor = "hand"
    $btnCollect.Font = $Font_NavBtn
    $btnCollect.FlatAppearance.BorderSize = 0
    $btnCollect.BackColor = $GroupBackColor
    $btnCollect.Add_Click({
        ShowCollect
    })
    #endregion

    #region Welcome
    $pnlWelcome = New-Object System.Windows.Forms.Panel
    $pnlWelcome.Location = New-Object System.Drawing.Point(
        ($pnlLeft.Width, $pnlTop.Height)
    )
    $pnlWelcome.Size = New-Object System.Drawing.Size(
        ($form.Width - $pnlLeft.Width), ($form.Height - $pnlTop.Height)
    )
    $pnlWelcome.BorderStyle = "None"
    $pnlWelcome.AutoScroll = $true
    $pnlWelcome.Visible = $true

    $lblWelcomeTitle             = New-Object System.Windows.Forms.Label
    $lblWelcomeTitle.Text        = "This utility deploys all DITA files to the Azure file system."
    $lblWelcomeTitle.AutoSize    = $true
    $lblWelcomeTitle.Location    = New-Object System.Drawing.Point(20,20)
    $lblWelcomeTitle.Font        = $Font_GroupTitle
    $lblWelcomeDesc             = New-Object System.Windows.Forms.Label
    $lblWelcomeDesc.Text        = "All applicable files are collected from your C:\DITA folder and deployed to the " +
                                    "`nAzure file system."
    $lblWelcomeDesc.AutoSize    = $true
    $lblWelcomeDesc.location    = New-Object System.Drawing.Point(20,50)
    $lblWelcomeDesc.Font        = 'Segoe UI,10'
    $lblWelcomeDesc.BackColor   = "Transparent"
    $lblWTDTitle                = New-Object System.Windows.Forms.Label
    $lblWTDTitle.Text           = "What happens during this process?"
    $lblWTDTitle.AutoSize       = $true
    $lblWTDTitle.Location       = New-Object System.Drawing.Point(20,120)
    $lblWTDTitle.Font           = $Font_GroupTitle
    $lblWTDDesc                 = New-Object System.Windows.Forms.Label
    $lblWTDDesc.Text            = "During this procedure, the following tasks are performed:`n" +
                                    "  1. Existing DITA files on the Dev server are archived.`n" +
                                    "  2. All folders and files are collected for the updated version, including: `n" +
                                    "     - respository folder `n" +
                                    "     - scripts folder and files `n" +
                                    "     - server and resources folders and files `n" +
                                    "     - transforms folders `n" +
                                    "     - WKFS_oXygen_Files folder and all contents `n`n" +
                                    "  3. Collected files are zipped and placed in the deployment location. `n" +
                                    "      \\zusscgrcprodwebhelp.file.core.windows.net\webhelp\dev\InfoDev\DITA_InstallationFiles`n`n" +
                                    "NOTE: This process takes several minutes to complete.  SELECT COLLECT TO CONTINUE"
    $lblWTDDesc.AutoSize        = $true
    $lblWTDDesc.location        = New-Object System.Drawing.Point(20,150)
    $lblWTDDesc.Font            = 'Segoe UI,10'
    $lblWTDDesc.BackColor       = "Transparent"

    #endregion


    #region Analyze
    $pnlCollect = New-Object System.Windows.Forms.Panel
    $pnlCollect.Location = New-Object System.Drawing.Point(
        ($pnlLeft.Width, $pnlTop.Height)
    )
    $pnlCollect.Size = New-Object System.Drawing.Size(
        ($form.Width - $pnlLeft.Width), ($form.Height - $pnlTop.Height)
    )
    $pnlCollect.BorderStyle = "None"
    $pnlCollect.AutoScroll = $true
    $pnlCollect.Visible = $true

    $lblCollectTitle             = New-Object System.Windows.Forms.Label
    $lblCollectTitle.Text        = "Collect all files to deploy."
    $lblCollectTitle.AutoSize    = $true
    $lblCollectTitle.Location    = New-Object System.Drawing.Point(20,20)
    $lblCollectTitle.Font        = $Font_GroupTitle
    $lblCollectDesc             = New-Object System.Windows.Forms.Label
    $lblCollectDesc.Text        = "Select the Collect Files button to begin collecting all files that are included `n" +
                                    "in the DITA files deployment. `n" +
                                    "This will take a few minutes. Please be patient."
    $lblCollectDesc.AutoSize    = $true
    $lblCollectDesc.location    = New-Object System.Drawing.Point(20,50)
    $lblCollectDesc.Font        = 'Segoe UI,10'
    $lblCollectDesc.BackColor   = "Transparent"
    $btnCollectFiles          = New-Object System.Windows.Forms.Button
    $btnCollectFiles.Text     = "Collect Files"
    $btnCollectFiles.FlatStyle = "Flat"
    $btnCollectFiles.Cursor    = "Hand"
    $btnCollectFiles.Size      = New-Object System.Drawing.Size(90,40)
    $btnCollectFiles.Location  = New-Object System.Drawing.Point(
        ($pnlCollect.Width - $btnCollect.Width + 40), $lblCollectDesc.Top)
    $btnCollectFiles.Add_Click({
        $txtAnalyzeLog.Text = ""
        $txtAnalyzeLog.Visible  = $true
        # $picGear.Visible  = $true
        CollectFiles
    })
    $txtAnalyzeLog              = New-Object System.Windows.Forms.TextBox
    $txtAnalyzeLog.Location     = New-Object System.Drawing.Point(20, ($lblCollectDesc.Top + $lblCollectDesc.Height + 50))
    $txtAnalyzeLog.Size         = New-Object System.Drawing.Size(($pnlCollect.Width - 40), 200)
    $txtAnalyzeLog.Multiline    = $true
    $txtAnalyzeLog.BackColor    = $BackColor
    $txtAnalyzeLog.ForeColor    = "White"
    $txtAnalyzeLog.Text         = $AnalyzeCollectionLogText
    # $txtAnalyzeLog.Text         = "Test"
    $txtAnalyzeLog.Visible      = $false
    # $picGear                    = New-Object System.Windows.Forms.PictureBox
    # $picGear.BorderStyle        = "FixedSingle"
    # $picGear.Image              = $Path_GearImage
    # $picGear.Size               = New-Object System.Drawing.Size(50,50)
    # $picGear.Location           = New-Object System.Drawing.Point(20, ($txtAnalyzeLog.Top + $txtAnalyzeLog.Height + 20))
    # $picGear.Visible            = $false

    #endregion

    # ADD OTHER ELEMENTS ABOVE THIS LINE
    $Form.controls.AddRange(@(
        $pnlTop,
        $StatusStrip,
        $pnlLeft,
        $pnlWelcome,
        $pnlCollect
        ))
    $pnlTop.Controls.AddRange(@(
        $lblTopTitle,
        $btnMinimize,
        $btnClose
        ))
    $pnlLeft.Controls.AddRange(@(
        $btnWelcome,
        $btnCollect,
        $btnPubAssist,
        $btnEditor,
        $btnTools,
        $btnSettings,
        $pnlLeftBottom,
        $labelTitle,
        $labelVersion
        ))
    $pnlWelcome.Controls.AddRange(@(
        $lblWelcomeTitle,
        $lblWelcomeDesc,
        $lblWTDTitle,
        $lblWTDDesc
        ))
    $pnlCollect.Controls.AddRange(@(
        $lblCollectTitle,
        $lblCollectDesc,
        $btnCollectFiles,
        $txtAnalyzeLog,
        $picGear
    ))

    # Display the form
    [void]$form.ShowDialog()
    [void]$form.BringToFront
    [void]$form.Focus
}
function ChangeBtnBGColor{
    $btnWelcome.BackColor = $GroupBackColor
    $btnCollect.BackColor = $GroupBackColor
}

function CollectFiles{
    $form.Cursor = [System.Windows.Forms.Cursors]::WaitCursor
    $btnCollectFiles.Enabled = $false

    ArchiveDITAFile

    $msg = "Gathering files... please wait"
    UpdateCollectionLog($msg)
    
    # Make temp folder
    CreateTempFolder

    CreateRepositoryFolder

    CollectScripts

    Collect_ServerResources

    CreateTransformsFolders

    CollectWKFSOxygenFiles

    CollectVersionTextFile

    $msg = "All files collected to: " + $TempPath
    UpdateCollectionLog($msg)

    ZipUpAndMoveNewFile

    DeleteTempFolder

    $msg = "DITA files deployment complete!"
    UpdateCollectionLog($msg)

    $btnCollectFiles.Enabled = $true
    $form.Cursor = [System.Windows.Forms.Cursors]::Default

    PlaySound($CompletionSoundPath)
    ShowNotification
}

function Collect_ServerResources{
    $msg = "Gathering server resources files..."
    UpdateCollectionLog($msg)
    New-Item -Path ($TempPath + "\server\resources") -ItemType Directory -Force
    Copy-Item $Path_Resources ($TempPath + "\server") -Recurse -Force
    Copy-Item $Path_ServerIndex ($TempPath + "\server") -Force
    $msg = "Server resources files collected"
    UpdateCollectionLog($msg)
}

function CollectVersionTextFile{
    $msg = "Gathering Version text file..."
    UpdateCollectionLog($msg)
    $Today = Get-Date -Format "yyyyMMdd"

    # replace content of version.txt
    Set-Content -Path $Path_VersionTextFile -Value $Today

    Copy-Item $Path_VersionTextFile ($TempPath) -Force
    $msg = "Version text file collected"
    UpdateCollectionLog($msg)
}

function CollectWKFSOxygenFiles{
    $msg = "Gathering WKFS Oxygen Files files..."
    UpdateCollectionLog($msg)
    Copy-Item $Path_WKFSOxygenFiles ($TempPath) -Recurse -Force
    $msg = "WKFS Oxygen Files files collected"
    UpdateCollectionLog($msg)
}

function CreateRepositoryFolder{
    New-Item -Path ($TempPath + "\repository") -ItemType Directory -Force
    $msg = "Repository folder created"
    UpdateCollectionLog($msg)
}

function CreateTransformsFolders{
    $msg = "Creating Transforms folders..."
    UpdateCollectionLog($msg)

    New-Item -path ($TempPath + "\transforms") -ItemType Directory -Force
    New-Item -path ($TempPath + "\transforms\extracts") -ItemType Directory -Force
    New-Item -path ($TempPath + "\transforms\out") -ItemType Directory -Force
    New-Item -path ($TempPath + "\transforms\out\pdf-css") -ItemType Directory -Force
    New-Item -path ($TempPath + "\transforms\temp") -ItemType Directory -Force

    $msg = "Transform folders created"
    UpdateCollectionLog($msg)
}

function CollectScripts{
    $msg = "Gathering scripts..."
    UpdateCollectionLog($msg)
    Copy-Item $Path_Scripts $TempPath -Recurse -Force
    $msg = "Scripts collected"
    UpdateCollectionLog($msg)
}

function CreateTempFolder{
    New-Item -Path $TempPath -ItemType Directory -Force
    $msg = "Temp folder created"
    UpdateCollectionLog($msg)
}

function DeleteTempFolder{
    Remove-Item $TempPath -Recurse -force
    $msg = "Temp folder removed"
    UpdateCollectionLog($msg)
}

function HidePanels{
    $pnlCollect.Hide()
    $pnlWelcome.Hide()
}

function PlaySound($SoundPath){
    $PlayWav = New-Object System.Media.SoundPlayer
    $PlayWav.SoundLocation = ""
    $PlayWav.playsync()
}

function UpdateCollectionLog($msg){
    $CurrentDateTime            = Get-Date -Format "MM/dd/yyyy HH:mm"
    $UpdateMsg = $CurrentDateTime + ": " + $msg

    if($txtAnalyzeLog.Text.Length -gt 0){
        $txtAnalyzeLog.AppendText("`r`n" + $UpdateMsg)
    }
    else{
        $txtAnalyzeLog.Text = $CurrentDateTime + ": " + $msg
    }
    
}

function ShowCollect{
    ChangeBtnBGColor
    $btnCollect.BackColor = $Backcolor
    HidePanels
    $pnlCollect.Show()
}

function ShowNotification{
    $global:balmsg = New-Object System.Windows.Forms.NotifyIcon
    $path = (Get-Process -id $pid).Path
    $balmsg.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
    $balmsg.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning
    $balmsg.BalloonTipText = "The DITA files have been successfully deployed to: `n" +
        $Path_DITAInstallationFiles
    $balmsg.BalloonTipTitle = "DITA Files Deployment"
    $balmsg.Visible = $true
    $balmsg.ShowBalloonTip(20000)
}

function ShowWelcome{
    ChangeBtnBGColor
    $btnWelcome.BackColor = $Backcolor
    HidePanels
    $pnlWelcome.Show()
}

function Main(){
    CreateForm
}

function ZipUpAndMoveNewFile{
    $msg = "Zipping collected files..."
    UpdateCollectionLog($msg)
    Compress-Archive -LiteralPath $TempPath -Destination ($TempPath + "\DITA.zip")
    $msg = "Files zipped"
    UpdateCollectionLog($msg)

    $msg = "Deploying new zip file..."
    UpdateCollectionLog($msg)
    Move-Item -Path ($TempPath + "\DITA.zip") -Destination $Path_DITAInstallationFiles
    Move-Item -Path ($TempPath + "\version.txt") -Destination $Path_DITAInstallationFiles -Force
    $msg = "New zip file deployed"
    UpdateCollectionLog($msg)
}

Main