@echo off
setlocal EnableExtensions
set "PS1=%TEMP%\kompege_idle_%RANDOM%_%RANDOM%.ps1"
powershell -NoProfile -ExecutionPolicy Bypass -Command "$src=$args[0];$dst=$args[1];$lines=Get-Content -LiteralPath $src;$idx=-1;for($i=0;$i -lt $lines.Count;$i++){if($lines[$i].Trim() -eq '# POWERSHELL_START'){$idx=$i;break}};if($idx -lt 0){throw 'Marker not found'};Set-Content -LiteralPath $dst -Value $lines[($idx+1)..($lines.Count-1)] -Encoding UTF8" "%~f0" "%PS1%"
powershell -NoProfile -ExecutionPolicy Bypass -File "%PS1%"
set "ERR=%ERRORLEVEL%"
del "%PS1%" >nul 2>nul
pause
exit /b %ERR%
# POWERSHELL_START
$ErrorActionPreference = "SilentlyContinue"
$url = "https://kompege.ru"
$desktop = [Environment]::GetFolderPath("Desktop")
$projects = Join-Path $desktop "Projects"
if (!(Test-Path -LiteralPath $projects)) {
New-Item -ItemType Directory -Path $projects | Out-Null
}
$today = Get-Date -Format "yyyy-MM-dd"
$n = 1
do {
$pyFile = Join-Path $projects ("{0}_{1}.py" -f $today, $n)
$n++
} while (Test-Path -LiteralPath $pyFile)
New-Item -ItemType File -Path $pyFile | Out-Null
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class WinApi {
[DllImport("user32.dll")]
public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
}
"@
Add-Type -AssemblyName System.Windows.Forms
$screen = [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea
$leftX = $screen.Left
$topY = $screen.Top
$halfWidth = [int]($screen.Width / 2)
$height = [int]$screen.Height
$rightX = $leftX + $halfWidth
$chromePaths = @(
"chrome.exe",
"C:\Program Files\Google\Chrome\Application\chrome.exe",
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",
"$env:LOCALAPPDATA\Google\Chrome\Application\chrome.exe"
)
$chromeOpened = $false
foreach ($chromePath in $chromePaths) {
if (!$chromeOpened) {
if ($chromePath -eq "chrome.exe" -or (Test-Path -LiteralPath $chromePath)) {
Start-Process $chromePath -ArgumentList "--new-window", $url
$chromeOpened = $true
}
}
}
Start-Sleep -Seconds 3
$chromeWindow = Get-Process chrome |
Where-Object { $_.MainWindowHandle -ne 0 } |
Sort-Object StartTime -Descending |
Select-Object -First 1
if ($chromeWindow) {
[WinApi]::ShowWindow($chromeWindow.MainWindowHandle, 1) | Out-Null
[WinApi]::MoveWindow($chromeWindow.MainWindowHandle, $leftX, $topY, $halfWidth, $height, $true) | Out-Null
}
$idleOpened = $false
$pythonCommands = @(
"pyw.exe",
"py.exe",
"pythonw.exe",
"python.exe"
)
foreach ($cmd in $pythonCommands) {
if (!$idleOpened) {
$found = Get-Command $cmd -ErrorAction SilentlyContinue
if ($found) {
Start-Process $cmd -ArgumentList "-m", "idlelib", $pyFile
$idleOpened = $true
}
}
}
if (!$idleOpened) {
Write-Host "IDLE не найден. Открываю файл в Блокноте."
Start-Process notepad.exe -ArgumentList $pyFile
exit
}
Start-Sleep -Seconds 5
$idleWindow = Get-Process pythonw, python, pyw, py |
Where-Object { $_.MainWindowHandle -ne 0 } |
Sort-Object StartTime -Descending |
Select-Object -First 1
if ($idleWindow) {
[WinApi]::ShowWindow($idleWindow.MainWindowHandle, 1) | Out-Null
[WinApi]::MoveWindow($idleWindow.MainWindowHandle, $rightX, $topY, $halfWidth, $height, $true) | Out-Null
}
Write-Host "Создан файл:"
Write-Host $pyFile