Rebranding.

This commit is contained in:
Jared Goodwin 2019-03-04 06:43:38 -08:00
parent 23d5f88b8c
commit 6b236e156c
5 changed files with 100 additions and 56 deletions

View File

@ -72,7 +72,7 @@ namespace Remotely_Library.Win32
uint dwCreationFlags;
if (hiddenWindow)
{
dwCreationFlags = NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW | DETACHED_PROCESS;
dwCreationFlags = NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW;
}
else
{

View File

@ -76,7 +76,6 @@ namespace Remotely_ScreenCast.Capture
PreviousFrame = new Bitmap(CurrentScreenBounds.Width, CurrentScreenBounds.Height, PixelFormat.Format32bppArgb);
graphic = Graphics.FromImage(CurrentFrame);
desktopName = Win32Interop.GetCurrentDesktop();
//hWnd = User32.GetDesktopWindow();
}
public void Capture()
@ -103,29 +102,34 @@ namespace Remotely_ScreenCast.Capture
{
lock (ScreenLock)
{
PreviousFrame = (Bitmap)CurrentFrame.Clone();
//hWnd = User32.GetDesktopWindow();
//hDC = User32.GetWindowDC(hWnd);
//graphic = Graphics.FromImage(CurrentFrame);
//graphDC = graphic.GetHdc();
//var copyResult = GDI32.BitBlt(graphDC, 0, 0, CurrentScreenBounds.Width, CurrentScreenBounds.Height, hDC, CurrentScreenBounds.Left, CurrentScreenBounds.Top, GDI32.TernaryRasterOperations.SRCCOPY);
PreviousFrame = (Bitmap)CurrentFrame.Clone();
//if (!copyResult)
//{
// Logger.Write($"BitBlt failed on {currentDesktop}.");
//}
graphic.CopyFromScreen(CurrentScreenBounds.Left, CurrentScreenBounds.Top, 0, 0, new Size(CurrentScreenBounds.Width, CurrentScreenBounds.Height));
}
}
catch (Exception ex)
{
Logger.Write(ex);
Init();
}
finally
{
//if (graphDC != IntPtr.Zero)
//{
// graphic.ReleaseHdc(graphDC);
//}
//if (hDC != IntPtr.Zero)
//{
// User32.ReleaseDC(hWnd, hDC);
//}
if (graphDC != IntPtr.Zero)
{
graphic.ReleaseHdc(graphDC);
}
if (hDC != IntPtr.Zero)
{
User32.ReleaseDC(hWnd, hDC);
}
}
}
}

View File

@ -14,34 +14,41 @@ namespace Remotely_ScreenCast.Capture
{
public class ScreenCaster
{
private static object CaptureLock { get; } = new object();
public static async void BeginScreenCasting(HubConnection hubConnection,
string viewerID,
string requesterName,
OutgoingMessages outgoingMessages)
{
var inputDesktop = Win32Interop.OpenInputDesktop();
var result = User32.SetThreadDesktop(inputDesktop);
User32.CloseDesktop(inputDesktop);
Logger.Write($"Set thread desktop begin screencasting to {Win32Interop.GetCurrentDesktop()}: {result}");
ICapturer capturer;
CaptureMode captureMode;
try
{
if (Program.Viewers.Count == 0)
{
capturer = new DXCapture();
captureMode = CaptureMode.DirectX;
}
else
{
capturer = new BitBltCapture();
captureMode = CaptureMode.BitBtl;
}
}
catch (Exception ex)
{
Logger.Write(ex);
capturer = new BitBltCapture();
captureMode = CaptureMode.BitBtl;
}
capturer = new BitBltCapture();
captureMode = CaptureMode.BitBtl;
//try
//{
// if (Program.Viewers.Count == 0)
// {
// capturer = new DXCapture();
// captureMode = CaptureMode.DirectX;
// }
// else
// {
// capturer = new BitBltCapture();
// captureMode = CaptureMode.BitBtl;
// }
//}
//catch (Exception ex)
//{
// Logger.Write(ex);
// capturer = new BitBltCapture();
// captureMode = CaptureMode.BitBtl;
//}
Logger.Write($"Starting screen cast. Requester: {requesterName}. Viewer ID: {viewerID}. Capture Mode: {captureMode.ToString()}. Desktop: {Win32Interop.GetCurrentDesktop()}");

View File

@ -31,34 +31,58 @@ namespace Remotely_ScreenCast
public static HubConnection Connection { get; private set; }
public static OutgoingMessages OutgoingMessages { get; private set; }
public static ConcurrentDictionary<string, Viewer> Viewers { get; } = new ConcurrentDictionary<string, Viewer>();
private static string CurrentDesktopName { get; set; }
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
var argDict = ProcessArgs(args);
Mode = argDict["mode"];
RequesterID = argDict["requester"];
Host = argDict["host"];
Connection = new HubConnectionBuilder()
.WithUrl($"{Host}/RCDeviceHub")
.Build();
Connection.StartAsync().Wait();
OutgoingMessages = new OutgoingMessages(Connection);
MessageHandlers.ApplyConnectionHandlers(Connection, OutgoingMessages);
CursorIconWatcher.Current.OnChange += CursorIconWatcher_OnChange;
OutgoingMessages.NotifyRequesterUnattendedReady(RequesterID).Wait();
StartWaitForViewerTimer();
while (true)
try
{
Console.Read();
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
var inputDesktop = Win32Interop.OpenInputDesktop();
var success = User32.SetThreadDesktop(inputDesktop);
User32.CloseDesktop(inputDesktop);
CurrentDesktopName = Win32Interop.GetCurrentDesktop();
Logger.Write($"Set thread desktop on launch to {CurrentDesktopName}: {success}");
var argDict = ProcessArgs(args);
Mode = argDict["mode"];
RequesterID = argDict["requester"];
Host = argDict["host"];
Connection = new HubConnectionBuilder()
.WithUrl($"{Host}/RCDeviceHub")
.Build();
Connection.StartAsync().Wait();
OutgoingMessages = new OutgoingMessages(Connection);
MessageHandlers.ApplyConnectionHandlers(Connection, OutgoingMessages);
CursorIconWatcher.Current.OnChange += CursorIconWatcher_OnChange;
OutgoingMessages.NotifyRequesterUnattendedReady(RequesterID).Wait();
StartWaitForViewerTimer();
while (true)
{
var desktopName = Win32Interop.GetCurrentDesktop();
if (desktopName != CurrentDesktopName)
{
CurrentDesktopName = desktopName;
inputDesktop = Win32Interop.OpenInputDesktop();
success = User32.SetThreadDesktop(inputDesktop);
User32.CloseDesktop(inputDesktop);
Logger.Write($"Set thread desktop on main thread to {CurrentDesktopName}: {success}");
}
System.Threading.Thread.Sleep(100);
}
}
catch (Exception ex)
{
Logger.Write(ex);
}
}

View File

@ -28,7 +28,14 @@ namespace Remotely_ScreenCast.Sockets
hubConnection.On("GetScreenCast", (string viewerID, string requesterName) =>
{
ScreenCaster.BeginScreenCasting(hubConnection, viewerID, requesterName, outgoingMessages);
try
{
ScreenCaster.BeginScreenCasting(hubConnection, viewerID, requesterName, outgoingMessages);
}
catch (Exception ex)
{
Logger.Write(ex);
}
});
hubConnection.On("KeyDown", (int keyCode, string viewerID) =>
@ -36,6 +43,7 @@ namespace Remotely_ScreenCast.Sockets
if (Program.Viewers.TryGetValue(viewerID, out var viewer) && viewer.HasControl)
{
Win32Interop.SendKeyDown((User32.VirtualKeyShort)keyCode);
//User32.SendKeyDown((User32.VirtualKeyShort)KeyInterop.VirtualKeyFromKey((Key)Enum.Parse(typeof(Key), key)));
}
});
@ -44,6 +52,7 @@ namespace Remotely_ScreenCast.Sockets
if (Program.Viewers.TryGetValue(viewerID, out var viewer) && viewer.HasControl)
{
Win32Interop.SendKeyUp((User32.VirtualKeyShort)keyCode);
//User32.SendKeyDown((User32.VirtualKeyShort)KeyInterop.VirtualKeyFromKey((Key)Enum.Parse(typeof(Key), key)));
}
});