diff --git a/DnsServerSystemTrayApp/AboutForm.Designer.cs b/DnsServerSystemTrayApp/AboutForm.Designer.cs new file mode 100644 index 00000000..e398607e --- /dev/null +++ b/DnsServerSystemTrayApp/AboutForm.Designer.cs @@ -0,0 +1,239 @@ +namespace DnsServerSystemTrayApp +{ + partial class AboutForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AboutForm)); + this.panel1 = new System.Windows.Forms.Panel(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.lnkTerms = new System.Windows.Forms.LinkLabel(); + this.btnClose = new System.Windows.Forms.Button(); + this.label3 = new System.Windows.Forms.Label(); + this.lnkWebsite = new System.Windows.Forms.LinkLabel(); + this.label1 = new System.Windows.Forms.Label(); + this.lnkContactEmail = new System.Windows.Forms.LinkLabel(); + this.labVersion = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.SuspendLayout(); + // + // panel1 + // + this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(102)))), ((int)(((byte)(153)))), ((int)(((byte)(255))))); + this.panel1.Controls.Add(this.pictureBox1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Left; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(56, 261); + this.panel1.TabIndex = 21; + // + // pictureBox1 + // + this.pictureBox1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(102)))), ((int)(((byte)(153)))), ((int)(((byte)(255))))); + this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Bottom; + this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image"))); + this.pictureBox1.Location = new System.Drawing.Point(0, 205); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Padding = new System.Windows.Forms.Padding(4); + this.pictureBox1.Size = new System.Drawing.Size(56, 56); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBox1.TabIndex = 12; + this.pictureBox1.TabStop = false; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Arial", 30F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(57)))), ((int)(((byte)(69))))); + this.label2.Location = new System.Drawing.Point(75, 24); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(456, 46); + this.label2.TabIndex = 24; + this.label2.Text = "Technitium DNS Server"; + // + // label4 + // + this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.label4.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label4.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(57)))), ((int)(((byte)(69))))); + this.label4.Location = new System.Drawing.Point(62, 193); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(436, 44); + this.label4.TabIndex = 33; + this.label4.Text = resources.GetString("label4.Text"); + // + // lnkTerms + // + this.lnkTerms.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.lnkTerms.AutoSize = true; + this.lnkTerms.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lnkTerms.LinkColor = System.Drawing.Color.FromArgb(((int)(((byte)(102)))), ((int)(((byte)(153)))), ((int)(((byte)(255))))); + this.lnkTerms.Location = new System.Drawing.Point(62, 237); + this.lnkTerms.Name = "lnkTerms"; + this.lnkTerms.Size = new System.Drawing.Size(116, 15); + this.lnkTerms.TabIndex = 32; + this.lnkTerms.TabStop = true; + this.lnkTerms.Text = "Terms && Conditions"; + this.lnkTerms.VisitedLinkColor = System.Drawing.Color.White; + this.lnkTerms.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkTerms_LinkClicked); + // + // btnClose + // + this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.btnClose.Location = new System.Drawing.Point(565, 229); + this.btnClose.Name = "btnClose"; + this.btnClose.Size = new System.Drawing.Size(75, 23); + this.btnClose.TabIndex = 31; + this.btnClose.Text = "&Close"; + this.btnClose.UseVisualStyleBackColor = true; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(57)))), ((int)(((byte)(69))))); + this.label3.Location = new System.Drawing.Point(476, 144); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(59, 16); + this.label3.TabIndex = 37; + this.label3.Text = "Website"; + // + // lnkWebsite + // + this.lnkWebsite.AutoSize = true; + this.lnkWebsite.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lnkWebsite.LinkColor = System.Drawing.Color.FromArgb(((int)(((byte)(102)))), ((int)(((byte)(153)))), ((int)(((byte)(255))))); + this.lnkWebsite.Location = new System.Drawing.Point(476, 160); + this.lnkWebsite.Name = "lnkWebsite"; + this.lnkWebsite.Size = new System.Drawing.Size(129, 16); + this.lnkWebsite.TabIndex = 36; + this.lnkWebsite.TabStop = true; + this.lnkWebsite.Text = "technitium.com/dns"; + this.lnkWebsite.VisitedLinkColor = System.Drawing.Color.White; + this.lnkWebsite.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkWebsite_LinkClicked); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(57)))), ((int)(((byte)(69))))); + this.label1.Location = new System.Drawing.Point(476, 99); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(57, 16); + this.label1.TabIndex = 35; + this.label1.Text = "Contact"; + // + // lnkContactEmail + // + this.lnkContactEmail.AutoSize = true; + this.lnkContactEmail.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lnkContactEmail.LinkColor = System.Drawing.Color.FromArgb(((int)(((byte)(102)))), ((int)(((byte)(153)))), ((int)(((byte)(255))))); + this.lnkContactEmail.Location = new System.Drawing.Point(476, 115); + this.lnkContactEmail.Name = "lnkContactEmail"; + this.lnkContactEmail.Size = new System.Drawing.Size(164, 16); + this.lnkContactEmail.TabIndex = 34; + this.lnkContactEmail.TabStop = true; + this.lnkContactEmail.Text = "support@technitium.com"; + this.lnkContactEmail.VisitedLinkColor = System.Drawing.Color.White; + this.lnkContactEmail.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkContactEmail_LinkClicked); + // + // labVersion + // + this.labVersion.AutoSize = true; + this.labVersion.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.labVersion.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(57)))), ((int)(((byte)(69))))); + this.labVersion.Location = new System.Drawing.Point(86, 132); + this.labVersion.Name = "labVersion"; + this.labVersion.Size = new System.Drawing.Size(147, 18); + this.labVersion.TabIndex = 38; + this.labVersion.Text = "version x.x.x.x (beta)"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Font = new System.Drawing.Font("Arial", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label5.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(57)))), ((int)(((byte)(69))))); + this.label5.Location = new System.Drawing.Point(84, 103); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(206, 29); + this.label5.TabIndex = 39; + this.label5.Text = "System Tray App"; + // + // AboutForm + // + this.AcceptButton = this.btnClose; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(250)))), ((int)(((byte)(250)))), ((int)(((byte)(250))))); + this.CancelButton = this.btnClose; + this.ClientSize = new System.Drawing.Size(652, 261); + this.Controls.Add(this.label5); + this.Controls.Add(this.labVersion); + this.Controls.Add(this.label3); + this.Controls.Add(this.lnkWebsite); + this.Controls.Add(this.label1); + this.Controls.Add(this.lnkContactEmail); + this.Controls.Add(this.label4); + this.Controls.Add(this.lnkTerms); + this.Controls.Add(this.btnClose); + this.Controls.Add(this.label2); + this.Controls.Add(this.panel1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "AboutForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "About Technitium DNS Server"; + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.LinkLabel lnkTerms; + private System.Windows.Forms.Button btnClose; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.LinkLabel lnkWebsite; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.LinkLabel lnkContactEmail; + private System.Windows.Forms.Label labVersion; + private System.Windows.Forms.Label label5; + } +} \ No newline at end of file diff --git a/DnsServerSystemTrayApp/AboutForm.cs b/DnsServerSystemTrayApp/AboutForm.cs new file mode 100644 index 00000000..c8553e6a --- /dev/null +++ b/DnsServerSystemTrayApp/AboutForm.cs @@ -0,0 +1,48 @@ +/* +Technitium DNS Server +Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +*/ + +using System.Windows.Forms; + +namespace DnsServerSystemTrayApp +{ + public partial class AboutForm : Form + { + public AboutForm() + { + InitializeComponent(); + + labVersion.Text = "version " + Application.ProductVersion + " (beta)"; + } + + private void lnkContactEmail_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + { + System.Diagnostics.Process.Start("mailto:" + lnkContactEmail.Text); + } + + private void lnkWebsite_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + { + System.Diagnostics.Process.Start(@"https://" + lnkWebsite.Text); + } + + private void lnkTerms_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + { + System.Diagnostics.Process.Start(@"https://github.com/TechnitiumSoftware/DnsServer/blob/master/LICENSE"); + } + } +} diff --git a/DnsServerTrayIcon/AboutForm.resx b/DnsServerSystemTrayApp/AboutForm.resx similarity index 70% rename from DnsServerTrayIcon/AboutForm.resx rename to DnsServerSystemTrayApp/AboutForm.resx index f6702292..7d34f462 100644 --- a/DnsServerTrayIcon/AboutForm.resx +++ b/DnsServerSystemTrayApp/AboutForm.resx @@ -117,7 +117,111 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + + + True + + + + Qk02DQAAAAAAADYEAAAoAAAAMAAAADAAAAABAAgAAAAAAAAAAAAAAAAAAAAAAAABAAAAAQAAAAAA/wAA + gP8AgAD/AICA/4AAAP+AAID/gIAA/8DAwP/A3MD/8Mqm/wQEBP8ICAj/DAwM/xEREf8WFhb/HBwc/yIi + Iv8pKSn/VVVV/01NTf9CQkL/OTk5/4B8//9QUP//kwDW///szP/G1u//1ufn/5Cprf8AADP/AABm/wAA + mf8AAMz/ADMA/wAzM/8AM2b/ADOZ/wAzzP8AM///AGYA/wBmM/8AZmb/AGaZ/wBmzP8AZv//AJkA/wCZ + M/8AmWb/AJmZ/wCZzP8Amf//AMwA/wDMM/8AzGb/AMyZ/wDMzP8AzP//AP9m/wD/mf8A/8z/MwAA/zMA + M/8zAGb/MwCZ/zMAzP8zAP//MzMA/zMzM/8zM2b/MzOZ/zMzzP8zM///M2YA/zNmM/8zZmb/M2aZ/zNm + zP8zZv//M5kA/zOZM/8zmWb/M5mZ/zOZzP8zmf//M8wA/zPMM/8zzGb/M8yZ/zPMzP8zzP//M/8z/zP/ + Zv8z/5n/M//M/zP///9mAAD/ZgAz/2YAZv9mAJn/ZgDM/2YA//9mMwD/ZjMz/2YzZv9mM5n/ZjPM/2Yz + //9mZgD/ZmYz/2ZmZv9mZpn/ZmbM/2aZAP9mmTP/Zplm/2aZmf9mmcz/Zpn//2bMAP9mzDP/ZsyZ/2bM + zP9mzP//Zv8A/2b/M/9m/5n/Zv/M/8wA////AMz/mZkA/5kzmf+ZAJn/mQDM/5kAAP+ZMzP/mQBm/5kz + zP+ZAP//mWYA/5lmM/+ZM2b/mWaZ/5lmzP+ZM///mZkz/5mZZv+ZmZn/mZnM/5mZ//+ZzAD/mcwz/2bM + Zv+ZzJn/mczM/5nM//+Z/wD/mf8z/5nMZv+Z/5n/mf/M/5n////MAAD/mQAz/8wAZv/MAJn/zADM/5kz + AP/MMzP/zDNm/8wzmf/MM8z/zDP//8xmAP/MZjP/mWZm/8xmmf/MZsz/mWb//8yZAP/MmTP/zJlm/8yZ + mf/Mmcz/zJn//8zMAP/MzDP/zMxm/8zMmf/MzMz/zMz//8z/AP/M/zP/mf9m/8z/mf/M/8z/zP///8wA + M///AGb//wCZ/8wzAP//MzP//zNm//8zmf//M8z//zP///9mAP//ZjP/zGZm//9mmf//Zsz/zGb///+Z + AP//mTP//5lm//+Zmf//mcz//5n////MAP//zDP//8xm///Mmf//zMz//8z/////M//M/2b///+Z//// + zP9mZv//Zv9m/2b/////Zmb//2b/////Zv8hAKX/X19f/3d3d/+Ghob/lpaW/8vLy/+ysrL/19fX/93d + 3f/j4+P/6urq//Hx8f/4+Pj/8Pv//6SgoP+AgID/AAD//wD/AP8A/////wAA//8A/////wD//////9XV + 1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV + 1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV////////1dXV//////////////////// + ///////////////////////////V1dXV////////1dXV//////////////////////////////////// + ///////////V1dXV////////1dXV///////////////////////////////////////////////V1dXV + ////////1dXV///////////////////////////////////////////////V1dXV////////1dXV//// + ///////////////////////////////////////////V1dXV////////1dXV//////////////////// + ///////////////////////////V1dXV////////1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dX////////V + 1dXV1dXV1dXV1dXV////////1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dX////////V1dXV1dXV1dXV1dXV + ////////1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dX////////V1dXV1dXV1dXV1dXV//////////////// + ///////////////////V1dX////////V1dX////////V1dXV//////////////////////////////// + ///V1dX////////V1dX////////V1dXV///////////////////////////////////V1dX////////V + 1dX////////V1dXV///////////////////////////////////V1dX////////V1dX////////V1dXV + ///////////////////////////////////V1dX////////V1dX////////V1dXV//////////////// + ///////////////////V1dX////////V1dX////////V1dXV////////1dXV1dXV1dXV1dXV1dXV1dXV + 1dXV1dX////////V1dX////////V1dXV////////1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dX////////V + 1dX////////V1dXV////////1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dX////////V1dX////////V1dXV + ////////1dXV////////1dXV1dXV1dXV1dXV1dX////////V1dX////////V1dXV////////1dXV//// + ////1dXV1dXV1dXV1dXV1dX////////V1dX////////V1dXV////////1dXV////////1dXV1dXV1dXV + 1dXV1dX////////V1dX////////V1dXV////////1dXV////////1dXV1dXV1dXV1dXV1dX////////V + 1dX////////V1dXV////////1dXV////////1dXV1dXV1dXV1dXV1dX////////V1dX////////V1dXV + ////////1dXV////////1dXV1dXV1dXV1dXV1dX////////V1dX////////V1dXV////////1dXV//// + ////1dXV1dXV1dXV1dXV1dX////////V1dX////////V1dXV////////1dXV////////1dXV1dXV1dXV + 1dXV1dX////////V1dX////////V1dXV////////1dXV////////1dXV1dXV1dXV1dXV1dXV1dXV1dXV + 1dX////////V1dXV////////1dXV////////1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dX////////V1dXV + ////////1dXV////////1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dX////////V1dXV////////1dXV//// + ////1dXV///////////////////////////////////V1dXV////////1dXV////////1dXV//////// + ///////////////////////////V1dXV////////1dXV////////1dXV//////////////////////// + ///////////V1dXV////////1dXV////////1dXV///////////////////////////////////V1dXV + ////////1dXV////////1dXV///////////////////////////////////V1dXV////////1dXV//// + ////1dXV///////////////////////////////////V1dXV1dXV1dXV1dXV////////1dXV1dXV1dXV + 1dXV1dXV1dXV1dXV1dX////////V1dXV1dXV1dXV1dXV////////1dXV1dXV1dXV1dXV1dXV1dXV1dXV + 1dX////////V1dXV1dXV1dXV1dXV////////1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dX////////V1dXV + ///////////////////////////////////////////////V1dX////////V1dXV//////////////// + ///////////////////////////////V1dX////////V1dXV//////////////////////////////// + ///////////////V1dX////////V1dXV///////////////////////////////////////////////V + 1dX////////V1dXV///////////////////////////////////////////////V1dX////////V1dXV + ///////////////////////////////////////////////V1dX////////V1dXV1dXV1dXV1dXV1dXV + 1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV + 1dXV1dXV1dXV1dXV1dXV1dXV1dXV1Q== + + + + True + + + True + + + Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com) +This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. Click link below for details: + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + AAABAAUAICAQAAAAAADoAgAAVgAAACAgAAAAAAAAqAgAAD4DAAAwMAAAAAAAAKgOAADmCwAAEBAQAAAA diff --git a/DnsServerTrayIcon/App.config b/DnsServerSystemTrayApp/App.config similarity index 100% rename from DnsServerTrayIcon/App.config rename to DnsServerSystemTrayApp/App.config diff --git a/DnsServerTrayIcon/DnsServerTrayIcon.csproj b/DnsServerSystemTrayApp/DnsServerSystemTrayApp.csproj similarity index 79% rename from DnsServerTrayIcon/DnsServerTrayIcon.csproj rename to DnsServerSystemTrayApp/DnsServerSystemTrayApp.csproj index 7e27f5d0..767330e7 100644 --- a/DnsServerTrayIcon/DnsServerTrayIcon.csproj +++ b/DnsServerSystemTrayApp/DnsServerSystemTrayApp.csproj @@ -6,8 +6,8 @@ AnyCPU {2F91BD07-2CEE-47FA-8486-457B54612B4C} WinExe - DnsServerTrayIcon - DnsServerTrayIcon + DnsServerSystemTrayApp + DnsServerSystemTrayApp v4.6.1 512 true @@ -32,19 +32,21 @@ prompt 4 + + logo2.ico + + - - - - - - + + False + ..\..\TechnitiumLibrary\bin\TechnitiumLibrary.IO.dll + @@ -53,12 +55,10 @@ AboutForm.cs - - + - AboutForm.cs @@ -86,15 +86,7 @@ - - Always - - - - - {7873b2b8-01ba-48bc-b4b0-0857ffd873c9} - DnsService - + \ No newline at end of file diff --git a/DnsServerSystemTrayApp/MainApplicationContext.cs b/DnsServerSystemTrayApp/MainApplicationContext.cs new file mode 100644 index 00000000..ee967d0c --- /dev/null +++ b/DnsServerSystemTrayApp/MainApplicationContext.cs @@ -0,0 +1,713 @@ +/* +Technitium DNS Server +Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +*/ + +using DnsServerSystemTrayApp.Properties; +using Microsoft.Win32; +using System; +using System.ComponentModel; +using System.Diagnostics; +using System.Drawing; +using System.IO; +using System.Management; +using System.Net; +using System.Net.NetworkInformation; +using System.Net.Sockets; +using System.Reflection; +using System.ServiceProcess; +using System.Text; +using System.Windows.Forms; +using TechnitiumLibrary.IO; + +namespace DnsServerSystemTrayApp +{ + public class MainApplicationContext : ApplicationContext + { + #region variables + + const int SERVICE_WAIT_TIMEOUT_SECONDS = 30; + private readonly ServiceController _service = new ServiceController("DnsService"); + + readonly IPAddress[] _cloudflareDns = new IPAddress[] { IPAddress.Parse("1.1.1.1"), IPAddress.Parse("1.0.0.1") }; + readonly IPAddress[] _googleDns = new IPAddress[] { IPAddress.Parse("8.8.8.8"), IPAddress.Parse("8.8.4.4") }; + readonly IPAddress[] _quad9Dns = new IPAddress[] { IPAddress.Parse("9.9.9.9") }; + + private NotifyIcon TrayIcon; + private ContextMenuStrip TrayIconContextMenu; + private ToolStripMenuItem DashboardMenuItem; + private ToolStripMenuItem NetworkDnsMenuItem; + private ToolStripMenuItem DefaultNetworkDnsMenuItem; + private ToolStripMenuItem TechnitiumNetworkDnsMenuItem; + private ToolStripMenuItem CloudflareNetworkDnsMenuItem; + private ToolStripMenuItem GoogleNetworkDnsMenuItem; + private ToolStripMenuItem Quad9NetworkDnsMenuItem; + private ToolStripMenuItem ServiceMenuItem; + private ToolStripMenuItem StartServiceMenuItem; + private ToolStripMenuItem RestartServiceMenuItem; + private ToolStripMenuItem StopServiceMenuItem; + private ToolStripMenuItem AboutMenuItem; + private ToolStripMenuItem AutoStartMenuItem; + private ToolStripMenuItem ExitMenuItem; + + #endregion + + #region constructor + + public MainApplicationContext() + { + InitializeComponent(); + } + + #endregion + + #region IDisposable + + protected override void Dispose(bool disposing) + { + if (disposing) + { + TrayIcon?.Dispose(); + } + + base.Dispose(disposing); + } + + #endregion + + #region private + + private void InitializeComponent() + { + // + // TrayIconContextMenu + // + TrayIconContextMenu = new ContextMenuStrip(); + TrayIconContextMenu.SuspendLayout(); + + // + // TrayIcon + // + var resources = new ComponentResourceManager(typeof(AboutForm)); + TrayIcon = new NotifyIcon(); + TrayIcon.Icon = (Icon)resources.GetObject("$this.Icon"); + TrayIcon.Visible = true; + TrayIcon.MouseUp += TrayIcon_MouseUp; + TrayIcon.ContextMenuStrip = TrayIconContextMenu; + TrayIcon.Text = Resources.ServiceName; + + // + // DashboardMenuItem + // + DashboardMenuItem = new ToolStripMenuItem(); + DashboardMenuItem.Name = "DashboardMenuItem"; + DashboardMenuItem.Text = Resources.DashboardMenuItem; + DashboardMenuItem.Click += DashboardMenuItem_Click; + + + // + // NetworkDnsMenuItem + // + NetworkDnsMenuItem = new ToolStripMenuItem(); + NetworkDnsMenuItem.Name = "NetworkDnsMenuItem"; + NetworkDnsMenuItem.Text = Resources.NetworkDnsMenuItem; + + DefaultNetworkDnsMenuItem = new ToolStripMenuItem("Default"); + DefaultNetworkDnsMenuItem.Click += DefaultNetworkDnsMenuItem_Click; + + TechnitiumNetworkDnsMenuItem = new ToolStripMenuItem("Technitium"); + TechnitiumNetworkDnsMenuItem.Click += TechnitiumNetworkDnsMenuItem_Click; + + CloudflareNetworkDnsMenuItem = new ToolStripMenuItem("Cloudflare"); + CloudflareNetworkDnsMenuItem.Click += CloudflareNetworkDnsMenuItem_Click; + + GoogleNetworkDnsMenuItem = new ToolStripMenuItem("Google"); + GoogleNetworkDnsMenuItem.Click += GoogleNetworkDnsMenuItem_Click; + + Quad9NetworkDnsMenuItem = new ToolStripMenuItem("IBM Quad9"); + Quad9NetworkDnsMenuItem.Click += Quad9NetworkDnsMenuItem_Click; + + NetworkDnsMenuItem.DropDownItems.AddRange(new ToolStripItem[] + { + DefaultNetworkDnsMenuItem, + new ToolStripSeparator(), + TechnitiumNetworkDnsMenuItem, + CloudflareNetworkDnsMenuItem, + GoogleNetworkDnsMenuItem, + Quad9NetworkDnsMenuItem + }); + + // + // ServiceMenuItem + // + ServiceMenuItem = new ToolStripMenuItem(); + ServiceMenuItem.Name = "ServiceMenuItem"; + ServiceMenuItem.Text = Resources.ServiceMenuItem; + + StartServiceMenuItem = new ToolStripMenuItem(Resources.ServiceStartMenuItem); + StartServiceMenuItem.Click += StartServiceMenuItem_Click; + + RestartServiceMenuItem = new ToolStripMenuItem(Resources.ServiceRestartMenuItem); + RestartServiceMenuItem.Click += RestartServiceMenuItem_Click; + + StopServiceMenuItem = new ToolStripMenuItem(Resources.ServiceStopMenuItem); + StopServiceMenuItem.Click += StopServiceMenuItem_Click; + + ServiceMenuItem.DropDownItems.AddRange(new ToolStripItem[] + { + StartServiceMenuItem, + RestartServiceMenuItem, + StopServiceMenuItem + }); + + // + // AboutMenuItem + // + AboutMenuItem = new ToolStripMenuItem(); + AboutMenuItem.Name = "AboutMenuItem"; + AboutMenuItem.Text = Resources.AboutMenuItem; + AboutMenuItem.Click += AboutMenuItem_Click; + + // + // AutoStartMenuItem + // + AutoStartMenuItem = new ToolStripMenuItem(); + AutoStartMenuItem.Name = "AutoStartMenuItem"; + AutoStartMenuItem.Text = "&Auto Start Icon"; + AutoStartMenuItem.Click += AutoStartMenuItem_Click; + + // + // ExitMenuItem + // + ExitMenuItem = new ToolStripMenuItem(); + ExitMenuItem.Name = "ExitMenuItem"; + ExitMenuItem.Text = Resources.ExitMenuItem; + ExitMenuItem.Click += ExitMenuItem_Click; + + TrayIconContextMenu.Items.AddRange(new ToolStripItem[] + { + DashboardMenuItem, + new ToolStripSeparator(), + NetworkDnsMenuItem, + ServiceMenuItem, + AboutMenuItem, + new ToolStripSeparator(), + AutoStartMenuItem, + ExitMenuItem + }); + + TrayIconContextMenu.ResumeLayout(false); + } + + private static void SetNameServerIPv4(NetworkInterface nic, IPAddress[] dnsAddresses) + { + ManagementClass networkAdapterConfig = new ManagementClass("Win32_NetworkAdapterConfiguration"); + ManagementObjectCollection instances = networkAdapterConfig.GetInstances(); + + foreach (ManagementObject obj in instances) + { + if ((bool)obj["IPEnabled"] && obj["SettingID"].Equals(nic.Id)) + { + string[] dnsServers = new string[dnsAddresses.Length]; + + for (int i = 0; i < dnsServers.Length; i++) + { + if (dnsAddresses[i].AddressFamily != AddressFamily.InterNetwork) + throw new ArgumentException(); + + dnsServers[i] = dnsAddresses[i].ToString(); + } + ManagementBaseObject objParameter = obj.GetMethodParameters("SetDNSServerSearchOrder"); + objParameter["DNSServerSearchOrder"] = dnsServers; + + ManagementBaseObject response = obj.InvokeMethod("SetDNSServerSearchOrder", objParameter, null); + uint returnValue = (uint)response.GetPropertyValue("ReturnValue"); + + switch (returnValue) + { + case 0: //success + case 1: //reboot required + break; + + case 64: + throw new Exception("Method not supported on this platform. WMI error code: " + returnValue); + + case 65: + throw new Exception("Unknown failure. WMI error code: " + returnValue); + + case 70: + throw new Exception("Invalid IP address. WMI error code: " + returnValue); + + case 96: + throw new Exception("Unable to notify DNS service. WMI error code: " + returnValue); + + case 97: + throw new Exception("Interface not configurable. WMI error code: " + returnValue); + + default: + throw new Exception("WMI error code: " + returnValue); + } + + break; + } + } + } + + private static void SetNameServerIPv6(NetworkInterface nic, IPAddress[] dnsAddresses) + { + //HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters\Interfaces\{} + + string nameServer = null; + + foreach (IPAddress dnsAddress in dnsAddresses) + { + if (dnsAddress.AddressFamily != AddressFamily.InterNetworkV6) + throw new ArgumentException(); + + if (nameServer == null) + nameServer = dnsAddress.ToString(); + else + nameServer += "," + dnsAddress.ToString(); + } + + if (nameServer == null) + nameServer = ""; + + using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters\Interfaces\" + nic.Id, true)) + { + if (key != null) + key.SetValue("NameServer", nameServer, RegistryValueKind.String); + } + } + + private static bool AddressExists(IPAddress checkAddress, IPAddress[] addresses) + { + foreach (IPAddress address in addresses) + { + if (checkAddress.Equals(address)) + return true; + } + + return false; + } + + private void TrayIcon_MouseUp(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.Right) + { + #region Network DNS + + bool isDefaultDns = false; + bool isTechnitiumDns = false; + bool isCloudflareDns = false; + bool isGoogleDns = false; + bool isQuad9Dns = false; + + try + { + foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) + { + if (nic.OperationalStatus != OperationalStatus.Up) + continue; + + foreach (IPAddress dnsAddress in nic.GetIPProperties().DnsAddresses) + { + if (IPAddress.IsLoopback(dnsAddress)) + { + isTechnitiumDns = true; + } + else if (AddressExists(dnsAddress, _cloudflareDns)) + { + isCloudflareDns = true; + } + else if (AddressExists(dnsAddress, _googleDns)) + { + isGoogleDns = true; + } + else if (AddressExists(dnsAddress, _quad9Dns)) + { + isQuad9Dns = true; + } + else if (!dnsAddress.IsIPv6SiteLocal) + { + isDefaultDns = true; + } + + if (isDefaultDns && isTechnitiumDns && isCloudflareDns && isGoogleDns && isQuad9Dns) + break; + } + } + } + catch + { } + + DefaultNetworkDnsMenuItem.Checked = isDefaultDns; + TechnitiumNetworkDnsMenuItem.Checked = isTechnitiumDns; + CloudflareNetworkDnsMenuItem.Checked = isCloudflareDns; + GoogleNetworkDnsMenuItem.Checked = isGoogleDns; + Quad9NetworkDnsMenuItem.Checked = isQuad9Dns; + + #endregion + + #region service + + try + { + switch (_service.Status) + { + case ServiceControllerStatus.Stopped: + TechnitiumNetworkDnsMenuItem.Enabled = false; + DashboardMenuItem.Enabled = false; + StartServiceMenuItem.Enabled = true; + RestartServiceMenuItem.Enabled = false; + StopServiceMenuItem.Enabled = false; + break; + + case ServiceControllerStatus.Running: + TechnitiumNetworkDnsMenuItem.Enabled = true; + DashboardMenuItem.Enabled = true; + StartServiceMenuItem.Enabled = false; + RestartServiceMenuItem.Enabled = true; + StopServiceMenuItem.Enabled = true; + break; + + default: + TechnitiumNetworkDnsMenuItem.Enabled = false; + DashboardMenuItem.Enabled = false; + StartServiceMenuItem.Enabled = false; + RestartServiceMenuItem.Enabled = false; + StopServiceMenuItem.Enabled = false; + break; + } + + ServiceMenuItem.Enabled = true; + } + catch + { + TechnitiumNetworkDnsMenuItem.Enabled = false; + DashboardMenuItem.Enabled = false; + ServiceMenuItem.Enabled = false; + } + + #endregion + + #region auto start + + try + { + using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true)) + { + if (key != null) + { + string autoStartPath = key.GetValue("Technitium DNS System Tray") as string; + + AutoStartMenuItem.Checked = (autoStartPath != null) && autoStartPath.Equals("\"" + Assembly.GetEntryAssembly().Location + "\""); + } + } + } + catch + { } + + #endregion + + TrayIcon.ShowContextMenu(); + } + } + + private void DashboardMenuItem_Click(object sender, EventArgs e) + { + int port = 5380; + + try + { + //try finding port number from dns config file + + string dnsConfigFile = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "config", "dns.config"); + + using (FileStream fS = new FileStream(dnsConfigFile, FileMode.Open, FileAccess.Read)) + { + BinaryReader bR = new BinaryReader(fS); + + if (Encoding.ASCII.GetString(bR.ReadBytes(2)) != "DS") //format + throw new InvalidDataException("DnsServer config file format is invalid."); + + int version = bR.ReadByte(); + + if (version > 1) + { + string serverDomain = bR.ReadShortString(); + port = bR.ReadInt32(); + } + } + } + catch + { } + + Process.Start("http://localhost:" + port.ToString()); + } + + private void DefaultNetworkDnsMenuItem_Click(object sender, EventArgs e) + { + try + { + foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) + { + if (nic.OperationalStatus != OperationalStatus.Up) + continue; + + SetNameServerIPv6(nic, new IPAddress[] { }); + + IPInterfaceProperties properties = nic.GetIPProperties(); + + if (properties.GetIPv4Properties().IsDhcpEnabled) + { + SetNameServerIPv4(nic, new IPAddress[] { }); + } + else if (properties.GatewayAddresses.Count > 0) + { + SetNameServerIPv4(nic, new IPAddress[] { properties.GatewayAddresses[0].Address }); + } + else + { + SetNameServerIPv4(nic, new IPAddress[] { }); + } + } + + MessageBox.Show("The network DNS servers were set to default successfully.", "Default DNS Set - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show("Error occured while setting default network DNS servers. " + ex.Message, "Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void TechnitiumNetworkDnsMenuItem_Click(object sender, EventArgs e) + { + try + { + foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) + { + if (nic.OperationalStatus != OperationalStatus.Up) + continue; + + IPInterfaceProperties properties = nic.GetIPProperties(); + + if ((properties.DnsAddresses.Count > 0) && !properties.DnsAddresses[0].IsIPv6SiteLocal) + { + SetNameServerIPv6(nic, new IPAddress[] { IPAddress.IPv6Loopback }); + SetNameServerIPv4(nic, new IPAddress[] { IPAddress.Loopback }); + } + } + + MessageBox.Show("The network DNS servers were set to Technitium DNS successfully.", "Technitium DNS Set - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show("Error occured while setting Technitium as network DNS server. " + ex.Message, "Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CloudflareNetworkDnsMenuItem_Click(object sender, EventArgs e) + { + try + { + foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) + { + if (nic.OperationalStatus != OperationalStatus.Up) + continue; + + IPInterfaceProperties properties = nic.GetIPProperties(); + + if ((properties.DnsAddresses.Count > 0) && !properties.DnsAddresses[0].IsIPv6SiteLocal) + { + SetNameServerIPv6(nic, new IPAddress[] { }); + SetNameServerIPv4(nic, _cloudflareDns); + } + } + + MessageBox.Show("The network DNS servers were set to Cloudflare DNS successfully.", "Cloudflare DNS Set - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show("Error occured while setting Cloudflare as network DNS server. " + ex.Message, "Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void GoogleNetworkDnsMenuItem_Click(object sender, EventArgs e) + { + try + { + foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) + { + if (nic.OperationalStatus != OperationalStatus.Up) + continue; + + IPInterfaceProperties properties = nic.GetIPProperties(); + + if ((properties.DnsAddresses.Count > 0) && !properties.DnsAddresses[0].IsIPv6SiteLocal) + { + SetNameServerIPv6(nic, new IPAddress[] { }); + SetNameServerIPv4(nic, _googleDns); + } + } + + MessageBox.Show("The network DNS servers were set to Google DNS successfully.", "Google DNS Set - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show("Error occured while setting Google as network DNS server. " + ex.Message, "Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void Quad9NetworkDnsMenuItem_Click(object sender, EventArgs e) + { + try + { + foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) + { + if (nic.OperationalStatus != OperationalStatus.Up) + continue; + + IPInterfaceProperties properties = nic.GetIPProperties(); + + if ((properties.DnsAddresses.Count > 0) && !properties.DnsAddresses[0].IsIPv6SiteLocal) + { + SetNameServerIPv6(nic, new IPAddress[] { }); + SetNameServerIPv4(nic, _quad9Dns); + } + } + + MessageBox.Show("The network DNS servers were set to IBM Quad9 DNS successfully.", "IBM Quad9 DNS Set - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show("Error occured while setting IBM Quad9 as network DNS server. " + ex.Message, "Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void StartServiceMenuItem_Click(object sender, EventArgs e) + { + try + { + _service.Start(); + _service.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, SERVICE_WAIT_TIMEOUT_SECONDS)); + + MessageBox.Show("The service was started successfully.", "Service Started - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (System.ServiceProcess.TimeoutException ex) + { + MessageBox.Show("The service did not respond in time." + ex.Message, "Service Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + catch (Exception ex) + { + MessageBox.Show("Error occured while starting service. " + ex.Message, "Service Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void RestartServiceMenuItem_Click(object sender, EventArgs e) + { + try + { + _service.Stop(); + _service.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, SERVICE_WAIT_TIMEOUT_SECONDS)); + _service.Start(); + _service.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, SERVICE_WAIT_TIMEOUT_SECONDS)); + + MessageBox.Show("The service was restarted successfully.", "Service Restarted - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (System.ServiceProcess.TimeoutException ex) + { + MessageBox.Show("The service did not respond in time." + ex.Message, "Service Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + catch (Exception ex) + { + MessageBox.Show("Error occured while restarting service. " + ex.Message, "Service Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void StopServiceMenuItem_Click(object sender, EventArgs e) + { + try + { + _service.Stop(); + _service.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, SERVICE_WAIT_TIMEOUT_SECONDS)); + + MessageBox.Show("The service was stopped successfully.", "Service Stopped - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (System.ServiceProcess.TimeoutException ex) + { + MessageBox.Show("The service did not respond in time." + ex.Message, "Service Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + catch (Exception ex) + { + MessageBox.Show("Error occured while stopping service. " + ex.Message, "Service Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AboutMenuItem_Click(object sender, EventArgs e) + { + using (AboutForm aboutForm = new AboutForm()) + { + aboutForm.ShowDialog(); + } + } + + private void AutoStartMenuItem_Click(object sender, EventArgs e) + { + if (AutoStartMenuItem.Checked) + { + //remove + try + { + using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true)) + { + if (key != null) + key.DeleteValue("Technitium DNS System Tray", false); + } + } + catch (Exception ex) + { + MessageBox.Show("Error occured while removing auto start registry entry. " + ex.Message, "Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + else + { + //add + try + { + using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true)) + { + if (key != null) + key.SetValue("Technitium DNS System Tray", "\"" + Assembly.GetEntryAssembly().Location + "\"", RegistryValueKind.String); + } + } + catch (Exception ex) + { + MessageBox.Show("Error occured while adding auto start registry entry. " + ex.Message, "Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ExitMenuItem_Click(object sender, EventArgs e) + { + if (MessageBox.Show(Resources.AreYouSureYouWantToQuit, Resources.Quit + " - " + Resources.ServiceName, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) + Application.Exit(); + } + + #endregion + } +} diff --git a/DnsServerSystemTrayApp/NotifyIconExtension.cs b/DnsServerSystemTrayApp/NotifyIconExtension.cs new file mode 100644 index 00000000..ffc16afa --- /dev/null +++ b/DnsServerSystemTrayApp/NotifyIconExtension.cs @@ -0,0 +1,33 @@ +/* +Technitium DNS Server +Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +*/ + +using System.Reflection; +using System.Windows.Forms; + +namespace DnsServerSystemTrayApp +{ + public static class NotifyIconExtension + { + public static void ShowContextMenu(this NotifyIcon notifyIcon) + { + MethodInfo methodInfo = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic); + methodInfo.Invoke(notifyIcon, null); + } + } +} diff --git a/DnsServerSystemTrayApp/Program.cs b/DnsServerSystemTrayApp/Program.cs new file mode 100644 index 00000000..f59caa25 --- /dev/null +++ b/DnsServerSystemTrayApp/Program.cs @@ -0,0 +1,94 @@ +/* +Technitium DNS Server +Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +*/ + +using System; +using System.ComponentModel; +using System.Diagnostics; +using System.Reflection; +using System.Security.Principal; +using System.Threading; +using System.Windows.Forms; + +namespace DnsServerSystemTrayApp +{ + static class Program + { + #region variables + + public const string MUTEX_NAME = "TechnitiumDnsServerSystemTrayApp"; + + static Mutex _app; + + #endregion + + #region public + + [STAThread] + public static void Main(string[] args) + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + + #region admin elevation + + bool isAdmin = (new WindowsPrincipal(WindowsIdentity.GetCurrent())).IsInRole(WindowsBuiltInRole.Administrator); + if (!isAdmin) + { + string appPath = Assembly.GetEntryAssembly().Location; + ProcessStartInfo processInfo = new ProcessStartInfo(appPath, string.Join(" ", args)); + + processInfo.UseShellExecute = true; + processInfo.Verb = "runas"; + + try + { + Process.Start(processInfo); + } + catch (Win32Exception) + { } + catch (Exception ex) + { + MessageBox.Show("Error! " + ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + return; + } + + #endregion + + #region check for multiple instances + + bool createdNewMutex; + + _app = new Mutex(true, MUTEX_NAME, out createdNewMutex); + + if (!createdNewMutex) + { + MessageBox.Show("Technitium DNS Server system tray app is already running.", "Already Running!", MessageBoxButtons.OK, MessageBoxIcon.Information); + return; + } + + #endregion + + Application.Run(new MainApplicationContext()); + } + + #endregion + } +} diff --git a/DnsServerTrayIcon/Properties/AssemblyInfo.cs b/DnsServerSystemTrayApp/Properties/AssemblyInfo.cs similarity index 79% rename from DnsServerTrayIcon/Properties/AssemblyInfo.cs rename to DnsServerSystemTrayApp/Properties/AssemblyInfo.cs index 22adc516..4c8c75f2 100644 --- a/DnsServerTrayIcon/Properties/AssemblyInfo.cs +++ b/DnsServerSystemTrayApp/Properties/AssemblyInfo.cs @@ -5,12 +5,12 @@ using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("DnsServerTrayIcon")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyTitle("Technitium DNS Server")] +[assembly: AssemblyDescription("Technitium DNS Server")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Technitium")] -[assembly: AssemblyProduct("DnsServerTrayIcon")] -[assembly: AssemblyCopyright("Copyright © Technitium 2018")] +[assembly: AssemblyProduct("Technitium DNS Server")] +[assembly: AssemblyCopyright("Copyright © 2019")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.1.0.0")] +[assembly: AssemblyFileVersion("1.1.0.0")] diff --git a/DnsServerTrayIcon/Properties/Resources.Designer.cs b/DnsServerSystemTrayApp/Properties/Resources.Designer.cs similarity index 84% rename from DnsServerTrayIcon/Properties/Resources.Designer.cs rename to DnsServerSystemTrayApp/Properties/Resources.Designer.cs index dbbbaed5..8fc404cf 100644 --- a/DnsServerTrayIcon/Properties/Resources.Designer.cs +++ b/DnsServerSystemTrayApp/Properties/Resources.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace DnsServerTrayIcon.Properties { +namespace DnsServerSystemTrayApp.Properties { using System; @@ -39,7 +39,7 @@ namespace DnsServerTrayIcon.Properties { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DnsServerTrayIcon.Properties.Resources", typeof(Resources).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DnsServerSystemTrayApp.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; @@ -61,7 +61,7 @@ namespace DnsServerTrayIcon.Properties { } /// - /// Looks up a localized string similar to A&bout.... + /// Looks up a localized string similar to A&bout. /// internal static string AboutMenuItem { get { @@ -70,7 +70,9 @@ namespace DnsServerTrayIcon.Properties { } /// - /// Looks up a localized string similar to If you quit Technitium DNS Server Tray Icon, Technitium DNS Server will continue to run in the background, are you sure you want to quit?. + /// Looks up a localized string similar to Are you sure to close the system tray icon? + /// + ///Closing the system tray icon will not stop Technitium DNS Server.. /// internal static string AreYouSureYouWantToQuit { get { @@ -79,7 +81,7 @@ namespace DnsServerTrayIcon.Properties { } /// - /// Looks up a localized string similar to D&ashboard.... + /// Looks up a localized string similar to &Dashboard. /// internal static string DashboardMenuItem { get { @@ -87,15 +89,6 @@ namespace DnsServerTrayIcon.Properties { } } - /// - /// Looks up a localized string similar to . - /// - internal static string ErrorOccurred { - get { - return ResourceManager.GetString("ErrorOccurred", resourceCulture); - } - } - /// /// Looks up a localized string similar to E&xit. /// @@ -106,7 +99,16 @@ namespace DnsServerTrayIcon.Properties { } /// - /// Looks up a localized string similar to Quit Technitium DNS Server Tray Icon?. + /// Looks up a localized string similar to Network DNS. + /// + internal static string NetworkDnsMenuItem { + get { + return ResourceManager.GetString("NetworkDnsMenuItem", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Close System Tray Icon?. /// internal static string Quit { get { @@ -115,7 +117,7 @@ namespace DnsServerTrayIcon.Properties { } /// - /// Looks up a localized string similar to Service. + /// Looks up a localized string similar to &Service. /// internal static string ServiceMenuItem { get { @@ -133,7 +135,7 @@ namespace DnsServerTrayIcon.Properties { } /// - /// Looks up a localized string similar to Restart. + /// Looks up a localized string similar to R&estart. /// internal static string ServiceRestartMenuItem { get { @@ -142,7 +144,7 @@ namespace DnsServerTrayIcon.Properties { } /// - /// Looks up a localized string similar to Start. + /// Looks up a localized string similar to &Start. /// internal static string ServiceStartMenuItem { get { @@ -151,7 +153,7 @@ namespace DnsServerTrayIcon.Properties { } /// - /// Looks up a localized string similar to Stop. + /// Looks up a localized string similar to St&op. /// internal static string ServiceStopMenuItem { get { diff --git a/DnsServerTrayIcon/Properties/Resources.resx b/DnsServerSystemTrayApp/Properties/Resources.resx similarity index 93% rename from DnsServerTrayIcon/Properties/Resources.resx rename to DnsServerSystemTrayApp/Properties/Resources.resx index e914f67a..5ea2e9aa 100644 --- a/DnsServerTrayIcon/Properties/Resources.resx +++ b/DnsServerSystemTrayApp/Properties/Resources.resx @@ -118,36 +118,38 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - A&bout... + A&bout - If you quit Technitium DNS Server Tray Icon, Technitium DNS Server will continue to run in the background, are you sure you want to quit? + Are you sure to close the system tray icon? + +Closing the system tray icon will not stop Technitium DNS Server. - D&ashboard... - - - + &Dashboard E&xit + + Network DNS + - Quit Technitium DNS Server Tray Icon? + Close System Tray Icon? - Service + &Service Technitium DNS Server - Restart + R&estart - Start + &Start - Stop + St&op \ No newline at end of file diff --git a/DnsServerTrayIcon/Properties/Settings.Designer.cs b/DnsServerSystemTrayApp/Properties/Settings.Designer.cs similarity index 82% rename from DnsServerTrayIcon/Properties/Settings.Designer.cs rename to DnsServerSystemTrayApp/Properties/Settings.Designer.cs index 6940fec6..801c3350 100644 --- a/DnsServerTrayIcon/Properties/Settings.Designer.cs +++ b/DnsServerSystemTrayApp/Properties/Settings.Designer.cs @@ -8,21 +8,17 @@ // //------------------------------------------------------------------------------ -namespace DnsServerTrayIcon.Properties -{ - - +namespace DnsServerSystemTrayApp.Properties { + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase - { - + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default - { - get - { + + public static Settings Default { + get { return defaultInstance; } } diff --git a/DnsServerTrayIcon/Properties/Settings.settings b/DnsServerSystemTrayApp/Properties/Settings.settings similarity index 100% rename from DnsServerTrayIcon/Properties/Settings.settings rename to DnsServerSystemTrayApp/Properties/Settings.settings diff --git a/DnsServerTrayIcon/Favicon.ico b/DnsServerSystemTrayApp/logo2.ico similarity index 100% rename from DnsServerTrayIcon/Favicon.ico rename to DnsServerSystemTrayApp/logo2.ico diff --git a/DnsServerTrayIcon/AboutForm.Designer.cs b/DnsServerTrayIcon/AboutForm.Designer.cs deleted file mode 100644 index 82fe6e6b..00000000 --- a/DnsServerTrayIcon/AboutForm.Designer.cs +++ /dev/null @@ -1,64 +0,0 @@ -namespace DnsServerTrayIcon -{ - partial class AboutForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AboutForm)); - this.VersionLabel = new System.Windows.Forms.Label(); - this.SuspendLayout(); - // - // VersionLabel - // - this.VersionLabel.AutoSize = true; - this.VersionLabel.Location = new System.Drawing.Point(24, 23); - this.VersionLabel.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); - this.VersionLabel.Name = "VersionLabel"; - this.VersionLabel.Size = new System.Drawing.Size(0, 25); - this.VersionLabel.TabIndex = 0; - // - // AboutForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(656, 142); - this.Controls.Add(this.VersionLabel); - this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); - this.Name = "AboutForm"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "About"; - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.Label VersionLabel; - } -} \ No newline at end of file diff --git a/DnsServerTrayIcon/AboutForm.cs b/DnsServerTrayIcon/AboutForm.cs deleted file mode 100644 index ae1890ef..00000000 --- a/DnsServerTrayIcon/AboutForm.cs +++ /dev/null @@ -1,33 +0,0 @@ -using DnsServerTrayIcon.Properties; -using System.Diagnostics; -using System.Drawing; -using System.IO; -using System.Reflection; -using System.Windows.Forms; - -namespace DnsServerTrayIcon -{ - public partial class AboutForm : Form - { - public AboutForm() - { - InitializeComponent(); - - Image image = Image.FromFile("Favicon.ico"); - var bitmap = new Bitmap(image); - Icon = Icon.FromHandle(bitmap.GetHicon()); - - VersionLabel.Text = Resources.ServiceName; - VersionLabel.Text += "\r\n"; - VersionLabel.Text += GetLegalCopyright(); - VersionLabel.Text += "\r\n"; - VersionLabel.Text += Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName) + " " + Assembly.GetExecutingAssembly().GetBuildVersion(); - } - - private string GetLegalCopyright() - { - var versionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location); - return versionInfo.LegalCopyright; - } - } -} diff --git a/DnsServerTrayIcon/BuildAssemblyExtensions.cs b/DnsServerTrayIcon/BuildAssemblyExtensions.cs deleted file mode 100644 index 70b1014c..00000000 --- a/DnsServerTrayIcon/BuildAssemblyExtensions.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.IO; -using System.Reflection; - -namespace DnsServerTrayIcon -{ - public static class BuildAssemblyExtensions - { - public static DateTime GetLinkerTime(this Assembly assembly, TimeZoneInfo target = null) - { - var filePath = assembly.Location; - const int c_PeHeaderOffset = 60; - const int c_LinkerTimestampOffset = 8; - - var buffer = new byte[2048]; - - using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) - stream.Read(buffer, 0, 2048); - - var offset = BitConverter.ToInt32(buffer, c_PeHeaderOffset); - var secondsSince1970 = BitConverter.ToInt32(buffer, offset + c_LinkerTimestampOffset); - var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); - - var linkTimeUtc = epoch.AddSeconds(secondsSince1970); - - var tz = target ?? TimeZoneInfo.Local; - var localTime = TimeZoneInfo.ConvertTimeFromUtc(linkTimeUtc, tz); - - return localTime; - } - - public static string GetBuildVersion(this Assembly assembly) - { - var linkTimeLocal = assembly.GetLinkerTime(TimeZoneInfo.Utc); - return new Version(1, 0, 0, - ((int)new TimeSpan(linkTimeLocal.Hour, linkTimeLocal.Minute, linkTimeLocal.Second).TotalSeconds) / 2).ToString(); - } - } -} diff --git a/DnsServerTrayIcon/ContextMenuNotifyIconExtensions.cs b/DnsServerTrayIcon/ContextMenuNotifyIconExtensions.cs deleted file mode 100644 index d16bf286..00000000 --- a/DnsServerTrayIcon/ContextMenuNotifyIconExtensions.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Reflection; -using System.Windows.Forms; - -namespace DnsServerTrayIcon -{ - public static class ContextMenuNotifyIconExtensions - { - public static void ShowContextMenu(this NotifyIcon notifyIcon) - { - MethodInfo methodInfo = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic); - methodInfo.Invoke(notifyIcon, null); - } - } -} diff --git a/DnsServerTrayIcon/MainApplicationContext.cs b/DnsServerTrayIcon/MainApplicationContext.cs deleted file mode 100644 index 43f03271..00000000 --- a/DnsServerTrayIcon/MainApplicationContext.cs +++ /dev/null @@ -1,199 +0,0 @@ -using DnsServerTrayIcon.Properties; -using System; -using System.ComponentModel; -using System.Diagnostics; -using System.Drawing; -using System.Windows.Forms; - -namespace DnsServerTrayIcon -{ - public class MainApplicationContext : ApplicationContext - { - private readonly WindowsServiceController _service = new WindowsServiceController("DnsService"); - - private NotifyIcon TrayIcon; - private ContextMenuStrip TrayIconContextMenu; - private ToolStripMenuItem DashboardMenuItem; - private ToolStripMenuItem ServiceMenuItem; - private ToolStripMenuItem StartServiceMenuItem; - private ToolStripMenuItem RestartServiceMenuItem; - private ToolStripMenuItem StopServiceMenuItem; - private ToolStripMenuItem AboutMenuItem; - private ToolStripSeparator DividerMenuItem; - private ToolStripMenuItem ExitMenuItem; - - public MainApplicationContext() - { - Application.ApplicationExit += new EventHandler(OnApplicationExit); - InitializeComponent(); - } - - private void InitializeComponent() - { - // - // TrayIconContextMenu - // - TrayIconContextMenu = new ContextMenuStrip(); - TrayIconContextMenu.SuspendLayout(); - - // - // TrayIcon - // - var resources = new ComponentResourceManager(typeof(AboutForm)); - TrayIcon = new NotifyIcon(); - TrayIcon.Icon = (Icon)resources.GetObject("$this.Icon"); - TrayIcon.Visible = true; - TrayIcon.MouseUp += TrayIcon_MouseUp; - TrayIcon.ContextMenuStrip = TrayIconContextMenu; - TrayIcon.Text = Resources.ServiceName; - - // - // DashboardMenuItem - // - DashboardMenuItem = new ToolStripMenuItem(); - DashboardMenuItem.Name = "DashboardMenuItem"; - DashboardMenuItem.Text = Resources.DashboardMenuItem; - DashboardMenuItem.Click += new EventHandler(DashboardMenuItem_Click); - - // - // ServiceMenuItem - // - ServiceMenuItem = new ToolStripMenuItem(); - ServiceMenuItem.Name = "ServiceMenuItem"; - ServiceMenuItem.Text = Resources.ServiceMenuItem; - ServiceMenuItem.MouseHover += new EventHandler(ServiceMenuItem_MouseHover); - // Prove the user feedback that there is a sub menu. - ServiceMenuItem.DropDownItems.Add(new ToolStripMenuItem()); - - StartServiceMenuItem = new ToolStripMenuItem(Resources.ServiceStartMenuItem); - StartServiceMenuItem.Click += new EventHandler(StartServiceMenuItem_Click); - - RestartServiceMenuItem = new ToolStripMenuItem(Resources.ServiceRestartMenuItem); - RestartServiceMenuItem.Click += new EventHandler(RestartServiceMenuItem_Click); - - StopServiceMenuItem = new ToolStripMenuItem(Resources.ServiceStopMenuItem); - StopServiceMenuItem.Click += new EventHandler(StopServiceMenuItem_Click); - - // - // AboutMenuItem - // - AboutMenuItem = new ToolStripMenuItem(); - AboutMenuItem.Name = "AboutMenuItem"; - AboutMenuItem.Text = Resources.AboutMenuItem; - AboutMenuItem.Click += new EventHandler(AboutMenuItem_Click); - - // - // DividerMenuItem - // - DividerMenuItem = new ToolStripSeparator(); - - // - // CloseMenuItem - // - ExitMenuItem = new ToolStripMenuItem(); - ExitMenuItem.Name = "ExitMenuItem"; - ExitMenuItem.Text = Resources.ExitMenuItem; - ExitMenuItem.Click += new EventHandler(ExitMenuItem_Click); - - TrayIconContextMenu.ResumeLayout(false); - } - - private void TrayIcon_MouseUp(object sender, MouseEventArgs e) - { - if (e.Button == MouseButtons.Right) - { - BuildContextMenu(); - TrayIcon.ShowContextMenu(); - } - } - - private void BuildContextMenu() - { - TrayIconContextMenu.Hide(); - TrayIconContextMenu.Items.Clear(); - - TrayIconContextMenu.Items.Add(DashboardMenuItem); - - if (_service.IsInstalled) - TrayIconContextMenu.Items.Add(ServiceMenuItem); - - TrayIconContextMenu.Items.AddRange(new ToolStripItem[] - { - DividerMenuItem, - AboutMenuItem, - DividerMenuItem, - ExitMenuItem - }); - } - - private void ServiceMenuItem_MouseHover(object sender, EventArgs e) - { - ServiceMenuItem.DropDownItems.Clear(); - if (_service.IsRunning) - { - ServiceMenuItem.DropDownItems.Add(RestartServiceMenuItem); - ServiceMenuItem.DropDownItems.Add(StopServiceMenuItem); - } - else - { - ServiceMenuItem.DropDownItems.Add(StartServiceMenuItem); - } - ServiceMenuItem.ShowDropDown(); - } - - private void StartServiceMenuItem_Click(object sender, EventArgs e) - { - _service.Start(); - } - - private void RestartServiceMenuItem_Click(object sender, EventArgs e) - { - _service.Restart(); - } - - private void StopServiceMenuItem_Click(object sender, EventArgs e) - { - _service.Stop(); - } - - private void OnApplicationExit(object sender, EventArgs e) - { - try - { - // Clean up so that the icon will be removed when the application is closed. - TrayIcon.Visible = false; - } - catch (NullReferenceException) - { - // The application is probably closing so safe to ignore. - } - } - - private void DashboardMenuItem_Click(object sender, EventArgs e) - { - //TODO: Parse the config file to determine the port. - Process.Start("http://127.0.0.1:5380"); - } - - private void AboutMenuItem_Click(object sender, EventArgs e) - { - var aboutForm = new AboutForm(); - aboutForm.ShowDialog(); - } - - private void ExitMenuItem_Click(object sender, EventArgs e) - { - DialogResult dialogResult = MessageBox.Show( - Resources.AreYouSureYouWantToQuit, - Resources.Quit, - MessageBoxButtons.YesNo, - MessageBoxIcon.None, - MessageBoxDefaultButton.Button2); - - if (dialogResult == DialogResult.Yes) - { - Application.Exit(); - } - } - } -} diff --git a/DnsServerTrayIcon/Program.cs b/DnsServerTrayIcon/Program.cs deleted file mode 100644 index 08263543..00000000 --- a/DnsServerTrayIcon/Program.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Windows.Forms; - -namespace DnsServerTrayIcon -{ - static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - Application.EnableVisualStyles(); - Application.Run(new MainApplicationContext()); - } - } -} diff --git a/DnsServerTrayIcon/WindowsServiceController.cs b/DnsServerTrayIcon/WindowsServiceController.cs deleted file mode 100644 index 5e048b73..00000000 --- a/DnsServerTrayIcon/WindowsServiceController.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System.Linq; -using System.ServiceProcess; - -namespace DnsServerTrayIcon -{ - public class WindowsServiceController - { - private readonly string _serviceName; - - public WindowsServiceController(string serviceName) - { - _serviceName = serviceName; - } - - public void Restart() - { - Stop(); - Start(); - } - - public void Stop() - { - try - { - using (var service = new ServiceController(_serviceName)) - { - service.Stop(); - service.WaitForStatus(ServiceControllerStatus.Stopped); - } - } - catch - { } - } - - public void Start() - { - try - { - using (var service = new ServiceController(_serviceName)) - { - service.Start(); - service.WaitForStatus(ServiceControllerStatus.Running); - } - } - catch - { } - } - - public bool IsRunning => Status == ServiceControllerStatus.Running; - - public bool IsStopped => Status == ServiceControllerStatus.Stopped; - - public ServiceControllerStatus Status - { - get - { - using (var service = new ServiceController(_serviceName)) - { - return service.Status; - } - } - } - - public bool IsInstalled - { - get - { - return ServiceController.GetServices().Any(s => s.ServiceName == _serviceName); - } - } - } -}