Moved Screens folder and always clean/restore before git pull
This commit is contained in:
parent
e4cae73dd7
commit
2276448d87
@ -5,20 +5,20 @@ using System.Runtime.InteropServices;
|
|||||||
public class ScreenCapture {
|
public class ScreenCapture {
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
public static extern IntPtr GetDC(IntPtr hwnd);
|
public static extern IntPtr GetDC(IntPtr hwnd);
|
||||||
|
|
||||||
[DllImport("gdi32.dll")]
|
[DllImport("gdi32.dll")]
|
||||||
public static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
|
public static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
public static extern int ReleaseDC(IntPtr hwnd, IntPtr hdc);
|
public static extern int ReleaseDC(IntPtr hwnd, IntPtr hdc);
|
||||||
|
|
||||||
public static int GetScreenWidth() {
|
public static int GetScreenWidth() {
|
||||||
IntPtr desktop = GetDC(IntPtr.Zero);
|
IntPtr desktop = GetDC(IntPtr.Zero);
|
||||||
int width = GetDeviceCaps(desktop, 118);
|
int width = GetDeviceCaps(desktop, 118);
|
||||||
ReleaseDC(IntPtr.Zero, desktop);
|
ReleaseDC(IntPtr.Zero, desktop);
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GetScreenHeight() {
|
public static int GetScreenHeight() {
|
||||||
IntPtr desktop = GetDC(IntPtr.Zero);
|
IntPtr desktop = GetDC(IntPtr.Zero);
|
||||||
int height = GetDeviceCaps(desktop, 117);
|
int height = GetDeviceCaps(desktop, 117);
|
||||||
@ -33,36 +33,37 @@ Add-Type -AssemblyName System.Drawing
|
|||||||
|
|
||||||
function Take-FullScreenshot {
|
function Take-FullScreenshot {
|
||||||
# Create directory if it doesn't exist
|
# Create directory if it doesn't exist
|
||||||
$dirPath = "C:\Scripts\Screens"
|
$dirPath = "C:\Screens"
|
||||||
if (-not (Test-Path $dirPath)) {
|
if (-not (Test-Path $dirPath)) {
|
||||||
New-Item -ItemType Directory -Path $dirPath -Force | Out-Null
|
New-Item -ItemType Directory -Path $dirPath -Force | Out-Null
|
||||||
|
Set-ItemProperty -Path $dirPath -Name Attributes -Value "Hidden"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Clean up any existing screenshots in the directory
|
# Clean up any existing screenshots in the directory
|
||||||
Get-ChildItem -Path $dirPath -Filter "*.png" | Remove-Item -Force
|
Get-ChildItem -Path $dirPath -Filter "*.png" | Remove-Item -Force
|
||||||
|
|
||||||
# Get timestamp and set output path
|
# Get timestamp and set output path
|
||||||
$timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
|
$timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
|
||||||
$outputPath = Join-Path $dirPath "screen_$timestamp.png"
|
$outputPath = Join-Path $dirPath "screen_$timestamp.png"
|
||||||
|
|
||||||
# Get actual screen resolution
|
# Get actual screen resolution
|
||||||
$width = [ScreenCapture]::GetScreenWidth()
|
$width = [ScreenCapture]::GetScreenWidth()
|
||||||
$height = [ScreenCapture]::GetScreenHeight()
|
$height = [ScreenCapture]::GetScreenHeight()
|
||||||
|
|
||||||
$bitmap = New-Object System.Drawing.Bitmap($width, $height)
|
$bitmap = New-Object System.Drawing.Bitmap($width, $height)
|
||||||
$graphics = [System.Drawing.Graphics]::FromImage($bitmap)
|
$graphics = [System.Drawing.Graphics]::FromImage($bitmap)
|
||||||
|
|
||||||
# Set high quality
|
# Set high quality
|
||||||
$graphics.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
|
$graphics.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
|
||||||
$graphics.PixelOffsetMode = [System.Drawing.Drawing2D.PixelOffsetMode]::HighQuality
|
$graphics.PixelOffsetMode = [System.Drawing.Drawing2D.PixelOffsetMode]::HighQuality
|
||||||
$graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::HighQuality
|
$graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::HighQuality
|
||||||
|
|
||||||
# Capture screen
|
# Capture screen
|
||||||
$graphics.CopyFromScreen(0, 0, 0, 0, $bitmap.Size)
|
$graphics.CopyFromScreen(0, 0, 0, 0, $bitmap.Size)
|
||||||
|
|
||||||
# Save screenshot
|
# Save screenshot
|
||||||
$bitmap.Save($outputPath, [System.Drawing.Imaging.ImageFormat]::Png)
|
$bitmap.Save($outputPath, [System.Drawing.Imaging.ImageFormat]::Png)
|
||||||
|
|
||||||
$graphics.Dispose()
|
$graphics.Dispose()
|
||||||
$bitmap.Dispose()
|
$bitmap.Dispose()
|
||||||
}
|
}
|
||||||
@ -72,4 +73,4 @@ while ($true) {
|
|||||||
Take-FullScreenshot
|
Take-FullScreenshot
|
||||||
# Wait 5 minutes
|
# Wait 5 minutes
|
||||||
Start-Sleep -Seconds 300
|
Start-Sleep -Seconds 300
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,15 +4,16 @@ cd "C:\Scripts"
|
|||||||
# Add exception handling for the git pull command
|
# Add exception handling for the git pull command
|
||||||
git config --global --add safe.directory C:/Scripts
|
git config --global --add safe.directory C:/Scripts
|
||||||
|
|
||||||
|
# Clean and restore repository state
|
||||||
|
git clean -fd
|
||||||
|
git restore .
|
||||||
|
|
||||||
# Execute the git pull command
|
# Execute the git pull command
|
||||||
git pull
|
git pull
|
||||||
|
|
||||||
# Optional: Check the exit code of the git pull command
|
# Check and report the result
|
||||||
$LASTEXITCODE
|
|
||||||
|
|
||||||
# Optional: Display a message based on the exit code
|
|
||||||
if ($LASTEXITCODE -eq 0) {
|
if ($LASTEXITCODE -eq 0) {
|
||||||
Write-Host "git pull successful."
|
Write-Host "Repository successfully updated."
|
||||||
} else {
|
} else {
|
||||||
Write-Host "git pull failed."
|
Write-Host "Repository update failed."
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user