From 64a9156d414c335dc878c15bb9c5fb0377923efb Mon Sep 17 00:00:00 2001 From: MaxXor Date: Tue, 21 Apr 2015 21:46:48 +0200 Subject: [PATCH] Added option to enable/disable Client Tooltips --- Client/Core/Information/GeoIP.cs | 5 +--- Server/Core/Commands/CommandHandler.cs | 36 ++++++++++++++------------ Server/Forms/FrmMain.cs | 4 ++- Server/Forms/FrmSettings.Designer.cs | 29 +++++++++++++++------ Server/Forms/FrmSettings.cs | 4 +++ Server/Settings/Settings.cs | 22 ++++++++-------- 6 files changed, 59 insertions(+), 41 deletions(-) diff --git a/Client/Core/Information/GeoIP.cs b/Client/Core/Information/GeoIP.cs index 5fb9f106..69ef1141 100644 --- a/Client/Core/Information/GeoIP.cs +++ b/Client/Core/Information/GeoIP.cs @@ -17,10 +17,10 @@ public GeoIP() try { HttpWebRequest request = (HttpWebRequest) WebRequest.Create("https://freegeoip.net/xml/"); + request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"; request.Proxy = null; request.Timeout = 5000; - // Be sure that response, dataStream, and reader will be disposed of, even if an error is thrown. using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) { using (Stream dataStream = response.GetResponseStream()) @@ -28,9 +28,6 @@ public GeoIP() using (StreamReader reader = new StreamReader(dataStream)) { string responseString = reader.ReadToEnd(); - reader.Close(); - dataStream.Close(); - response.Close(); XmlDocument doc = new XmlDocument(); doc.LoadXml(responseString); diff --git a/Server/Core/Commands/CommandHandler.cs b/Server/Core/Commands/CommandHandler.cs index caa95e5e..a000e6a6 100644 --- a/Server/Core/Commands/CommandHandler.cs +++ b/Server/Core/Commands/CommandHandler.cs @@ -58,7 +58,7 @@ public static void HandleInitialize(Client client, Initialize packet) ShowPopup(client); client.Value.IsAuthenticated = true; - new Core.Packets.ServerPackets.GetSystemInfo().Execute(client); + new Packets.ServerPackets.GetSystemInfo().Execute(client); } catch { @@ -413,41 +413,43 @@ public static void HandleDownloadFileResponse(Client client, DownloadFileRespons public static void HandleGetSystemInfoResponse(Client client, GetSystemInfoResponse packet) { - try + if (XMLSettings.ShowToolTip) { - FrmMain.Instance.lstClients.Invoke((MethodInvoker)delegate + try { - foreach (ListViewItem item in FrmMain.Instance.lstClients.Items) + FrmMain.Instance.lstClients.Invoke((MethodInvoker)delegate { - if (item.Tag == client) + foreach (ListViewItem item in FrmMain.Instance.lstClients.Items) { - var builder = new StringBuilder(); - for (int i = 0; i < packet.SystemInfos.Length; i += 2) + if (item.Tag == client) { - if (packet.SystemInfos[i] != null && packet.SystemInfos[i + 1] != null) + var builder = new StringBuilder(); + for (int i = 0; i < packet.SystemInfos.Length; i += 2) { - builder.AppendFormat("{0}: {1}\r\n", packet.SystemInfos[i], packet.SystemInfos[i + 1]); + if (packet.SystemInfos[i] != null && packet.SystemInfos[i + 1] != null) + { + builder.AppendFormat("{0}: {1}\r\n", packet.SystemInfos[i], packet.SystemInfos[i + 1]); + } } + item.ToolTipText = builder.ToString(); } - item.ToolTipText = builder.ToString(); } - } - }); + }); + } + catch + { + } } - catch (Exception) - { } if (client.Value.FrmSi == null) return; ListViewItem[] lviCollection = new ListViewItem[packet.SystemInfos.Length/2]; - int j = 0; - for (int i = 0; i < packet.SystemInfos.Length; i += 2) + for (int i = 0, j = 0; i < packet.SystemInfos.Length; i += 2, j++) { if (packet.SystemInfos[i] != null && packet.SystemInfos[i + 1] != null) { lviCollection[j] = new ListViewItem(new string[] {packet.SystemInfos[i], packet.SystemInfos[i + 1]}); - j++; } } diff --git a/Server/Forms/FrmMain.cs b/Server/Forms/FrmMain.cs index 8fe577d4..f90360b0 100644 --- a/Server/Forms/FrmMain.cs +++ b/Server/Forms/FrmMain.cs @@ -28,6 +28,7 @@ private void ReadSettings(bool writeIfNotExist = true) XMLSettings.AutoListen = bool.Parse(XMLSettings.ReadValue("AutoListen")); XMLSettings.ShowPopup = bool.Parse(XMLSettings.ReadValue("ShowPopup")); XMLSettings.UseUPnP = bool.Parse(XMLSettings.ReadValue("UseUPnP")); + XMLSettings.ShowToolTip = bool.Parse(!string.IsNullOrEmpty(XMLSettings.ReadValue("ShowToolTip")) ? XMLSettings.ReadValue("ShowToolTip") : "False"); //fallback XMLSettings.Password = XMLSettings.ReadValue("Password"); } @@ -48,7 +49,8 @@ public FrmMain() Instance = this; ReadSettings(); -#if(!DEBUG) + +#if !DEBUG ShowTermsOfService(XMLSettings.ShowToU); #endif diff --git a/Server/Forms/FrmSettings.Designer.cs b/Server/Forms/FrmSettings.Designer.cs index 8dd65a49..dbab5093 100644 --- a/Server/Forms/FrmSettings.Designer.cs +++ b/Server/Forms/FrmSettings.Designer.cs @@ -39,6 +39,7 @@ private void InitializeComponent() this.lblPassword = new System.Windows.Forms.Label(); this.txtPassword = new System.Windows.Forms.TextBox(); this.chkUseUpnp = new System.Windows.Forms.CheckBox(); + this.chkShowTooltip = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.ncPort)).BeginInit(); this.SuspendLayout(); // @@ -47,7 +48,7 @@ private void InitializeComponent() this.btnSave.Location = new System.Drawing.Point(227, 210); this.btnSave.Name = "btnSave"; this.btnSave.Size = new System.Drawing.Size(75, 23); - this.btnSave.TabIndex = 9; + this.btnSave.TabIndex = 10; this.btnSave.Text = "&Save"; this.btnSave.UseVisualStyleBackColor = true; this.btnSave.Click += new System.EventHandler(this.btnSave_Click); @@ -88,9 +89,9 @@ private void InitializeComponent() this.chkAutoListen.AutoSize = true; this.chkAutoListen.Location = new System.Drawing.Point(15, 63); this.chkAutoListen.Name = "chkAutoListen"; - this.chkAutoListen.Size = new System.Drawing.Size(136, 17); + this.chkAutoListen.Size = new System.Drawing.Size(249, 17); this.chkAutoListen.TabIndex = 5; - this.chkAutoListen.Text = "Enable auto listening"; + this.chkAutoListen.Text = "Listen for new connections on xRAT startup"; this.chkAutoListen.UseVisualStyleBackColor = true; // // chkPopup @@ -98,9 +99,9 @@ private void InitializeComponent() this.chkPopup.AutoSize = true; this.chkPopup.Location = new System.Drawing.Point(15, 86); this.chkPopup.Name = "chkPopup"; - this.chkPopup.Size = new System.Drawing.Size(267, 17); + this.chkPopup.Size = new System.Drawing.Size(259, 17); this.chkPopup.TabIndex = 6; - this.chkPopup.Text = "Show popup notification on server connection"; + this.chkPopup.Text = "Show popup notification on new connection"; this.chkPopup.UseVisualStyleBackColor = true; // // btnListen @@ -118,7 +119,7 @@ private void InitializeComponent() this.btnCancel.Location = new System.Drawing.Point(146, 210); this.btnCancel.Name = "btnCancel"; this.btnCancel.Size = new System.Drawing.Size(75, 23); - this.btnCancel.TabIndex = 8; + this.btnCancel.TabIndex = 9; this.btnCancel.Text = "&Cancel"; this.btnCancel.UseVisualStyleBackColor = true; this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); @@ -149,11 +150,22 @@ private void InitializeComponent() this.chkUseUpnp.Text = "Try to automatically port forward (UPnP)"; this.chkUseUpnp.UseVisualStyleBackColor = true; // - // frmSettings + // chkShowTooltip + // + this.chkShowTooltip.AutoSize = true; + this.chkShowTooltip.Location = new System.Drawing.Point(15, 132); + this.chkShowTooltip.Name = "chkShowTooltip"; + this.chkShowTooltip.Size = new System.Drawing.Size(268, 17); + this.chkShowTooltip.TabIndex = 8; + this.chkShowTooltip.Text = "Show tooltip on client with system information"; + this.chkShowTooltip.UseVisualStyleBackColor = true; + // + // FrmSettings // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(314, 245); + this.Controls.Add(this.chkShowTooltip); this.Controls.Add(this.chkUseUpnp); this.Controls.Add(this.txtPassword); this.Controls.Add(this.lblPassword); @@ -169,7 +181,7 @@ private void InitializeComponent() this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.MinimizeBox = false; - this.Name = "frmSettings"; + this.Name = "FrmSettings"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "xRAT 2.0 - Settings"; this.Load += new System.EventHandler(this.FrmSettings_Load); @@ -191,5 +203,6 @@ private void InitializeComponent() private System.Windows.Forms.Label lblPassword; private System.Windows.Forms.TextBox txtPassword; private System.Windows.Forms.CheckBox chkUseUpnp; + private System.Windows.Forms.CheckBox chkShowTooltip; } } \ No newline at end of file diff --git a/Server/Forms/FrmSettings.cs b/Server/Forms/FrmSettings.cs index 5986166e..b6144331 100644 --- a/Server/Forms/FrmSettings.cs +++ b/Server/Forms/FrmSettings.cs @@ -31,6 +31,7 @@ private void FrmSettings_Load(object sender, EventArgs e) chkPopup.Checked = XMLSettings.ShowPopup; txtPassword.Text = XMLSettings.Password; chkUseUpnp.Checked = XMLSettings.UseUPnP; + chkShowTooltip.Checked = XMLSettings.ShowToolTip; } private void btnListen_Click(object sender, EventArgs e) @@ -82,6 +83,9 @@ private void btnSave_Click(object sender, EventArgs e) XMLSettings.WriteValue("UseUPnP", chkUseUpnp.Checked.ToString()); XMLSettings.UseUPnP = chkUseUpnp.Checked; + XMLSettings.WriteValue("ShowToolTip", chkShowTooltip.Checked.ToString()); + XMLSettings.ShowToolTip = chkShowTooltip.Checked; + this.Close(); } diff --git a/Server/Settings/Settings.cs b/Server/Settings/Settings.cs index 0eafca05..7193576a 100644 --- a/Server/Settings/Settings.cs +++ b/Server/Settings/Settings.cs @@ -13,15 +13,16 @@ public static class XMLSettings public static bool AutoListen { get; set; } public static bool ShowPopup { get; set; } public static bool UseUPnP { get; set; } + public static bool ShowToolTip { get; set; } public static string Password { get; set; } - private static string settingsFilePath = Path.Combine(Application.StartupPath, "settings.xml"); + private static string _settingsFilePath = Path.Combine(Application.StartupPath, "settings.xml"); public static bool WriteDefaultSettings() { try { - if (!File.Exists(settingsFilePath)) + if (!File.Exists(_settingsFilePath)) { XmlDocument doc = new XmlDocument(); XmlNode root = doc.CreateElement("settings"); @@ -33,8 +34,9 @@ public static bool WriteDefaultSettings() root.AppendChild(doc.CreateElement("Password")).InnerText = "1234"; root.AppendChild(doc.CreateElement("ShowToU")).InnerText = "True"; root.AppendChild(doc.CreateElement("UseUPnP")).InnerText = "False"; + root.AppendChild(doc.CreateElement("ShowToolTip")).InnerText = "False"; - doc.Save(settingsFilePath); + doc.Save(_settingsFilePath); } return true; } @@ -48,10 +50,9 @@ public static string ReadValue(string pstrValueToRead) { try { - XPathDocument doc = new XPathDocument(settingsFilePath); + XPathDocument doc = new XPathDocument(_settingsFilePath); XPathNavigator nav = doc.CreateNavigator(); - XPathExpression expr; - expr = nav.Compile(@"/settings/" + pstrValueToRead); + var expr = nav.Compile(@"/settings/" + pstrValueToRead); XPathNodeIterator iterator = nav.Select(expr); while (iterator.MoveNext()) { @@ -70,24 +71,23 @@ public static bool WriteValue(string pstrValueToRead, string pstrValueToWrite) { try { - XmlNode oldNode; XmlDocument doc = new XmlDocument(); - using (var reader = new XmlTextReader(settingsFilePath)) + using (var reader = new XmlTextReader(_settingsFilePath)) { doc.Load(reader); } XmlElement root = doc.DocumentElement; - oldNode = root.SelectSingleNode(@"/settings/" + pstrValueToRead); + var oldNode = root.SelectSingleNode(@"/settings/" + pstrValueToRead); if (oldNode == null) // create if not exist { oldNode = doc.SelectSingleNode("settings"); oldNode.AppendChild(doc.CreateElement(pstrValueToRead)).InnerText = pstrValueToWrite; - doc.Save(settingsFilePath); + doc.Save(_settingsFilePath); return true; } oldNode.InnerText = pstrValueToWrite; - doc.Save(settingsFilePath); + doc.Save(_settingsFilePath); return true; } catch