Skip to content

Commit

Permalink
Fix DX9 capture typo. Modified retry counts. No terminal window for A…
Browse files Browse the repository at this point in the history
…PI server. Stop capture on windows shutdown.
  • Loading branch information
sabaatworld committed Jan 8, 2022
1 parent 596c8ee commit c417db1
Show file tree
Hide file tree
Showing 6 changed files with 5,312 additions and 7 deletions.
2 changes: 2 additions & 0 deletions HyperionScreenCap/ApiServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ private bool IsAclUrlReserved(string hostname, string port)
ProcessStartInfo processStartInfo = new ProcessStartInfo
{
FileName = "netsh.exe",
CreateNoWindow = true,
UseShellExecute = false,
Arguments = $"http show urlacl url={aclUrl}",
WindowStyle = ProcessWindowStyle.Hidden,
Expand Down Expand Up @@ -172,6 +173,7 @@ private void ReserveAclUrl(string hostname, string port)
ProcessStartInfo processStartInfo = new ProcessStartInfo
{
FileName = "netsh.exe",
CreateNoWindow = true,
UseShellExecute = true,
Arguments = $"http add urlacl url={aclUrl} user={user}",
WindowStyle = ProcessWindowStyle.Hidden,
Expand Down
2 changes: 1 addition & 1 deletion HyperionScreenCap/Capture/Dx9ScreenCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class DX9ScreenCapture : IScreenCapture
public DX9ScreenCapture(int monitorIndex, int captureWidth, int captureHeight, int captureInterval)
{
_monitorIndex = monitorIndex;
CaptureWidth = captureHeight;
CaptureWidth = captureWidth;
CaptureHeight = captureHeight;
_captureInterval = captureInterval;
_disposed = true;
Expand Down
4 changes: 2 additions & 2 deletions HyperionScreenCap/Config/AppConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class AppConstants
/// <summary>
/// Maximum number of consecutive screen capture attempts before giving up and disabling screen capture.
/// </summary>
public const int MAX_CAPTURE_ATTEMPTS = 30;
public const int MAX_CAPTURE_ATTEMPTS = 45;

/// <summary>
/// Number of screen capture failure attemps after which screen capture should be re-initialized.
/// </summary>
public const int REINIT_CAPTURE_AFTER_ATTEMPTS = 24;
public const int REINIT_CAPTURE_AFTER_ATTEMPTS = 15;

/// <summary>
/// Amount of time to wait before attempting screen capture after a failure.
Expand Down
9 changes: 5 additions & 4 deletions HyperionScreenCap/Form/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions HyperionScreenCap/Form/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;

Expand All @@ -14,8 +15,14 @@ public partial class MainForm : Form
{
#region Variables

private static readonly int WM_QUERYENDSESSION = 0x11;
private static readonly ILog LOG = LogManager.GetLogger(typeof(MainForm));

[DllImport("user32.dll", SetLastError = true)]
private static extern bool ShutdownBlockReasonCreate(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)] string reason);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool ShutdownBlockReasonDestroy(IntPtr hWnd);

private ApiServer _apiServer;
private NotifyIcon _trayIcon;
private NotificationUtils _notificationUtils;
Expand Down Expand Up @@ -382,6 +389,18 @@ private void SessionSwitched(object sender, SessionSwitchEventArgs switchEvent)
}
}

protected override void WndProc(ref Message m)
{
if (m.Msg == WM_QUERYENDSESSION && CaptureEnabled)
{
LOG.Info("System logoff, shutdown, or reboot (WM_QUERYENDSESSION) detected. Stopping capture.");
ShutdownBlockReasonCreate(this.Handle, "Stopping capture");
ToggleCapture(CaptureCommand.OFF, false, false);
ShutdownBlockReasonDestroy(this.Handle);
}
base.WndProc(ref m);
}

private void ResumeCapture()
{
if ( _captureSuspended )
Expand Down
Loading

0 comments on commit c417db1

Please sign in to comment.