Загрузка данных
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# Настройки
$alertFile = "\\server\AlertShare\alert.txt"
$checkInterval = 5
$AlertTitle = "ЭКСТРЕННОЕ ОПОВЕЩЕНИЕ"
$AlertMessage = @"
Срочно покиньте помещение
"@
$SoundRepeat = $true
$BlinkSpeed = 500
# Конец настроек
while ($true) {
# Ждём появления файла тревоги
while (-not (Test-Path $alertFile)) {
Start-Sleep -Seconds $checkInterval
}
# Создаём форму
$Form = New-Object System.Windows.Forms.Form
$Form.Text = $AlertTitle
$Form.StartPosition = "CenterScreen"
$Form.FormBorderStyle = "None"
$Form.ControlBox = $false
$Form.TopMost = $true
$Form.WindowState = "Maximized"
$Form.BackColor = [System.Drawing.Color]::FromArgb(192, 0, 0)
$Form.KeyPreview = $true
# Запрещаем закрытие пользователем
$Form.Add_FormClosing({
if ($_.CloseReason -eq "UserClosing") {
$_.Cancel = $true
}
})
# Заголовок
$LabelTitle = New-Object System.Windows.Forms.Label
$LabelTitle.Text = "БЕСПИЛОТНАЯ ОПАСНОСТЬ"
$LabelTitle.Font = New-Object System.Drawing.Font("Arial", 32, [System.Drawing.FontStyle]::Bold)
$LabelTitle.ForeColor = [System.Drawing.Color]::White
$LabelTitle.AutoSize = $true
$LabelTitle.TextAlign = "MiddleCenter"
$Form.Add_Shown({
$LabelTitle.Left = ($Form.ClientSize.Width - $LabelTitle.Width) / 2
$LabelTitle.Top = ($Form.ClientSize.Height * 0.15) - ($LabelTitle.Height / 2)
})
$Form.Controls.Add($LabelTitle)
# Основной текст
$LabelMessage = New-Object System.Windows.Forms.Label
$LabelMessage.Text = $AlertMessage
$LabelMessage.Font = New-Object System.Drawing.Font("Arial", 20)
$LabelMessage.ForeColor = [System.Drawing.Color]::White
$LabelMessage.AutoSize = $true
$LabelMessage.TextAlign = "MiddleCenter"
$Form.Add_Shown({
$LabelMessage.Left = ($Form.ClientSize.Width - $LabelMessage.Width) / 2
$LabelMessage.Top = ($Form.ClientSize.Height / 2) - ($LabelMessage.Height / 2)
})
$Form.Controls.Add($LabelMessage)
# Футер
$LabelFooter = New-Object System.Windows.Forms.Label
$LabelFooter.Text = "Ждите дальнейших указаний"
$LabelFooter.Font = New-Object System.Drawing.Font("Arial", 12, [System.Drawing.FontStyle]::Italic)
$LabelFooter.ForeColor = [System.Drawing.Color]::LightGray
$LabelFooter.AutoSize = $true
$LabelFooter.TextAlign = "MiddleCenter"
$Form.Add_Shown({
$LabelFooter.Left = ($Form.ClientSize.Width - $LabelFooter.Width) / 2
$LabelFooter.Top = ($Form.ClientSize.Height * 0.92) - ($LabelFooter.Height / 2)
})
$Form.Controls.Add($LabelFooter)
# Таймер возврата фокуса
$FocusTimer = New-Object System.Windows.Forms.Timer
$FocusTimer.Interval = 200
$FocusTimer.Add_Tick({
try {
$Form.Activate()
$Form.BringToFront()
$Form.TopMost = $true
} catch {}
})
# Таймер проверки отбоя
$CheckTimer = New-Object System.Windows.Forms.Timer
$CheckTimer.Interval = 1000
$CheckTimer.Add_Tick({
if (-not (Test-Path $alertFile)) {
$Form.Close()
}
})
# Таймер мерцания
$BlinkState = $false
$BlinkTimer = New-Object System.Windows.Forms.Timer
$BlinkTimer.Interval = $BlinkSpeed
$BlinkTimer.Add_Tick({
$BlinkState = -not $BlinkState
if ($BlinkState) {
$Form.BackColor = [System.Drawing.Color]::FromArgb(255, 0, 0)
$LabelTitle.ForeColor = [System.Drawing.Color]::White
$LabelMessage.ForeColor = [System.Drawing.Color]::White
$LabelFooter.ForeColor = [System.Drawing.Color]::White
} else {
$Form.BackColor = [System.Drawing.Color]::FromArgb(100, 0, 0)
$LabelTitle.ForeColor = [System.Drawing.Color]::Yellow
$LabelMessage.ForeColor = [System.Drawing.Color]::Yellow
$LabelFooter.ForeColor = [System.Drawing.Color]::LightGray
}
})
# Звук
$SoundTimer = $null
if ($SoundRepeat) {
$SoundTimer = New-Object System.Windows.Forms.Timer
$SoundTimer.Interval = 10000
$SoundTimer.Add_Tick({ [System.Console]::Beep(800, 500) })
}
# Запуск таймеров
$Form.Add_Shown({
$FocusTimer.Start()
$CheckTimer.Start()
$BlinkTimer.Start()
if ($SoundTimer) { $SoundTimer.Start() }
})
# Показываем форму
$Form.ShowDialog()
# Остановка таймеров
$FocusTimer.Stop()
$CheckTimer.Stop()
$BlinkTimer.Stop()
if ($SoundTimer) { $SoundTimer.Stop() }
# Очистка
$FocusTimer.Dispose()
$CheckTimer.Dispose()
$BlinkTimer.Dispose()
if ($SoundTimer) { $SoundTimer.Dispose() }
$Form.Dispose()
}