### Esegue setup di EgtCAM5 da repo Artifacts ###

#inizializzo variabili vuote
$BitSelect = ""
$BitChoice = ""
$ChosenBit = ""
$ChosenDll = ""

#Definisco path truenas di origine
$Artifacts = '\\truenas\Artifacts'
$SrvEgtTech = '\\truenas\Artifacts\EGT_SRV\EgtTech'

#Definisco path test cartelle Egt
$TestProgFolder = 'c:\EgtTestProg'
$TestDataFolder = 'c:\EgtTestData'

#Definisco path test sottocartelle EgtCAM5
$TestProgCam5Folder = 'c:\EgtTestProg\EgtCAM5'
$TestDataCam5Folder = 'c:\EgtTestData\EgtCAM5'

#Chiedo all'utente se vuole 32 bit o 64 bit
function Show-MenuA
{
    param (
        [string]$Title = 'Seleziona architettura EgtCAM5'
    )
    Clear-Host
    Write-Host ""
    Write-Host "============= $Title ============="
    Write-Host ""
    Write-Host "1: Premi '1' per x86"
    Write-Host "2: Premi '2' per x64"
    Write-Host "q: Premi 'q' tornare al menù principale"
    Write-Host ""
}

Show-MenuA

#Salvo la selezione dell'utente 32 bit o 64 bit
$BitSelect = Read-Host "Seleziona architettura EgTCAM5"
switch ($BitSelect)
{
    '1' {
         $BitChoice = 'x86'
    }
    '2' {
        $BitChoice = 'x64'
    }
    'q' {
        Powershell.exe -executionpolicy remotesigned -File  .\CLI\EgtScriptsManager.ps1
    }
}

if($BitChoice -eq 'x86'){
    $ChosenBit = '32'
    $ChosenDll = 'Dll32'
}
else {
    $ChosenBit = '64'
    $ChosenDll = 'Dll64'
} 

Write-Output ""
Write-Output "Installing Test EgtCAM5 Architecture: $ChosenBit bit"
Write-Output ""
Start-Sleep -seconds 5

#Pulisco cartella c:\EgtTestProg\EgtCAM5 se già esistente, poi la creo
if (Test-Path -Path $TestProgCam5Folder) {
    "EgtTestProg\EgtCAM5 esiste!"
    Remove-Item -Recurse $TestProgCam5Folder\*.*
} else {
    new-item $TestProgCam5Folder -itemtype directory
}

#Pulisco cartella c:\EgtTestData\EgtCAM5 se già esistente, poi la creo
if (Test-Path -Path $TestDataCam5Folder) {
    "EgtTestData\EgtCAM5 esiste!"
    Remove-Item -Recurse $TestDataCam5Folder\*.*
} else {
    new-item $TestDataCam5Folder -itemtype directory
}

#Copio la cartella EgtCAM5
ROBOCOPY /E $SrvEgtTech\EgtProg\EgtCAM5\ $TestProgCam5Folder

#Copio la cartella Dll desiderata
ROBOCOPY /E $SrvEgtTech\EgtProg\$ChosenDll\ $TestProgCam5Folder

#Copio EgtCAM5.ini custom in C:\EgtTestProg\EgtCAM5\Config
ROBOCOPY /E $Artifacts\EgtProg\EgtCAM5\Config\ $TestDataCam5Folder\Config EgtCAM5.ini

#Copio DataRoot.ini custom in C:\EgtTestProg\EgtCAM5
ROBOCOPY /E $Artifacts\EgtProg\EgtCAM5\Config\ $TestProgCam5Folder DataRoot.ini

#Copio la cartella Lualibs
ROBOCOPY /E $SrvEgtTech\EgtProg\LuaLibs\ $TestProgFolder\LuaLibs

#Copio la cartella Fonts
ROBOCOPY /E $SrvEgtTech\EgtProg\Fonts\ $TestProgFolder\Fonts

#Copio la cartella Messages
ROBOCOPY /E $SrvEgtTech\EgtData\Messages\ $TestDataFolder\Messages

#Copio cartella 3dPrinting
ROBOCOPY /E $Artifacts\EgtData\3dPrinting\$ChosenBit\ $TestDataCam5Folder\3dPrinting

#Copio cartella Beam
ROBOCOPY /E $Artifacts\EgtData\Beam\$ChosenBit\ $TestDataCam5Folder\Beam

#Copio cartella Wall
ROBOCOPY /E $Artifacts\EgtData\Wall\$ChosenBit\ $TestDataCam5Folder\Wall

#Copio cartella BeamWall
ROBOCOPY /E $Artifacts\EgtData\BeamWall\$ChosenBit\ $TestDataCam5Folder\BeamWall

#Chiudo lanciando lo Script Manager per altre operazioni
Powershell.exe -executionpolicy remotesigned -File  .\CLI\EgtScriptsManager.ps1