luicl's picture
Upload folder using huggingface_hub
72b02e4 verified
Raw History Blame Contribute Delete
2.1 kB
Add-Type -AssemblyName System.Windows.Forms
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class WinAPI {
[DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hWnd);
}
"@
# 1. Locate project
$CurrentDir = $PWD.Path
$UProjectFile = $null
while ($CurrentDir) {
$UProjectFile = Get-ChildItem -Path $CurrentDir -Filter "*.uproject" | Select-Object -First 1
if ($UProjectFile) { break }
$ParentDir = Split-Path -Path $CurrentDir -Parent
if ($ParentDir -eq $CurrentDir) { break }
$CurrentDir = $ParentDir
}
if (!$UProjectFile) {
Write-Host "Please run within <Project>/source/<ProjectName>/."
exit
}
$ProjectFullName = $UProjectFile.FullName
$ProjectName = $UProjectFile.BaseName
$EnginePath = "D:\UE_5.7"
# 2. Fast-cycle close logic
while ($true) {
$ue = Get-Process "UnrealEditor" -ErrorAction SilentlyContinue
if (!$ue) { break }
$hasVisibleWindow = $false
foreach ($p in $ue) {
if ($p.MainWindowHandle -ne 0) {
[void][WinAPI]::SetForegroundWindow($p.MainWindowHandle)
[void]$p.CloseMainWindow()
$hasVisibleWindow = $true
}
}
if ($hasVisibleWindow) {
Start-Sleep -Milliseconds 200
} else {
if ($ue | Wait-Process -Timeout 1 -ErrorAction SilentlyContinue) { break }
$ue | Stop-Process -Force -ErrorAction SilentlyContinue
break
}
}
# 3. Ensure process is terminated
$FinalCheck = Get-Process "UnrealEditor" -ErrorAction SilentlyContinue
if ($FinalCheck) {
Start-Sleep -Seconds 1
Get-Process "UnrealEditor" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
}
# 4. Build Project
$BuildBatch = "$EnginePath\Engine\Build\BatchFiles\Build.bat"
& $BuildBatch "${ProjectName}Editor" Win64 Development -Project="$ProjectFullName" -WaitMutex | Tee-Object -Variable output
# 5. Handle Result
if ($LASTEXITCODE -eq 0) {
Start-Process "$ProjectFullName"
} else {
$output | Set-Clipboard
}