From 1aa1a762bee430a0436002d12ce7c69853ddb6f7 Mon Sep 17 00:00:00 2001 From: mcored Date: Mon, 31 Mar 2014 19:23:47 +0800 Subject: [PATCH] DNS Changer moved to its own exe DNS Changer moved to its own exe to be able to elevate for UAC prompt --- DNSChanger/DNSChanger.csproj | 91 ++++++++++++++ .../DNSChangerForm.Designer.cs | 6 +- .../Forms => DNSChanger}/DNSChangerForm.cs | 13 +- .../Forms => DNSChanger}/DNSChangerForm.resx | 0 {HelpersLib => DNSChanger}/DNSInfo.cs | 2 +- DNSChanger/Program.cs | 21 ++++ DNSChanger/Properties/AssemblyInfo.cs | 36 ++++++ DNSChanger/Properties/Resources.Designer.cs | 71 +++++++++++ DNSChanger/Properties/Resources.resx | 117 ++++++++++++++++++ DNSChanger/Properties/Settings.Designer.cs | 30 +++++ DNSChanger/Properties/Settings.settings | 7 ++ HelpersLib/HelpersLib.csproj | 10 -- ShareX.sln | 6 + ShareX/Forms/MainForm.cs | 10 +- ShareX/ShareX.csproj | 4 + 15 files changed, 400 insertions(+), 24 deletions(-) create mode 100644 DNSChanger/DNSChanger.csproj rename {HelpersLib/Forms => DNSChanger}/DNSChangerForm.Designer.cs (98%) rename {HelpersLib/Forms => DNSChanger}/DNSChangerForm.cs (91%) rename {HelpersLib/Forms => DNSChanger}/DNSChangerForm.resx (100%) rename {HelpersLib => DNSChanger}/DNSInfo.cs (98%) create mode 100644 DNSChanger/Program.cs create mode 100644 DNSChanger/Properties/AssemblyInfo.cs create mode 100644 DNSChanger/Properties/Resources.Designer.cs create mode 100644 DNSChanger/Properties/Resources.resx create mode 100644 DNSChanger/Properties/Settings.Designer.cs create mode 100644 DNSChanger/Properties/Settings.settings diff --git a/DNSChanger/DNSChanger.csproj b/DNSChanger/DNSChanger.csproj new file mode 100644 index 000000000..3a9643eca --- /dev/null +++ b/DNSChanger/DNSChanger.csproj @@ -0,0 +1,91 @@ + + + + + Debug + AnyCPU + {F1061D2B-4C92-42B9-9A98-34118D6B45A8} + WinExe + Properties + DNSChanger + DNSChanger + v3.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + Form + + + DNSChangerForm.cs + + + + + + DNSChangerForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + {327750e1-9fb7-4cc3-8aea-9bc42180cad3} + HelpersLib + + + + + \ No newline at end of file diff --git a/HelpersLib/Forms/DNSChangerForm.Designer.cs b/DNSChanger/DNSChangerForm.Designer.cs similarity index 98% rename from HelpersLib/Forms/DNSChangerForm.Designer.cs rename to DNSChanger/DNSChangerForm.Designer.cs index cbe5b6943..4b9d392df 100644 --- a/HelpersLib/Forms/DNSChangerForm.Designer.cs +++ b/DNSChanger/DNSChangerForm.Designer.cs @@ -1,4 +1,4 @@ -namespace HelpersLib +namespace DNSChanger { partial class DNSChangerForm { @@ -100,7 +100,7 @@ private void InitializeComponent() this.btnSave.Name = "btnSave"; this.btnSave.Size = new System.Drawing.Size(80, 24); this.btnSave.TabIndex = 5; - this.btnSave.Text = "Apply"; + this.btnSave.Text = "&Apply"; this.btnSave.UseVisualStyleBackColor = true; this.btnSave.Click += new System.EventHandler(this.btnSave_Click); // @@ -110,7 +110,7 @@ private void InitializeComponent() this.btnCancel.Name = "btnCancel"; this.btnCancel.Size = new System.Drawing.Size(80, 23); this.btnCancel.TabIndex = 6; - this.btnCancel.Text = "Cancel"; + this.btnCancel.Text = "&Close"; this.btnCancel.UseVisualStyleBackColor = true; this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); // diff --git a/HelpersLib/Forms/DNSChangerForm.cs b/DNSChanger/DNSChangerForm.cs similarity index 91% rename from HelpersLib/Forms/DNSChangerForm.cs rename to DNSChanger/DNSChangerForm.cs index b69e177d1..c6008890e 100644 --- a/HelpersLib/Forms/DNSChangerForm.cs +++ b/DNSChanger/DNSChangerForm.cs @@ -23,10 +23,11 @@ You should have received a copy of the GNU General Public License #endregion License Information (GPL v3) +using HelpersLib; using System; using System.Windows.Forms; -namespace HelpersLib +namespace DNSChanger { public partial class DNSChangerForm : Form { @@ -148,27 +149,27 @@ private void btnSave_Click(object sender, EventArgs e) } else { - throw new Exception("Not valid ip address."); + throw new Exception("Not valid IP address."); } } if (result == 0) { NativeMethods.DnsFlushResolverCache(); - MessageBox.Show("DNS successfully set.", "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show("DNS successfully set.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (result == 1) { - MessageBox.Show("DNS successfully set. Reboot is required.", "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show("DNS successfully set. Reboot is required.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (result > 1) { - MessageBox.Show("DNS set failed with error code: " + result, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Setting DNS failed with error code: " + result, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { - MessageBox.Show("DNS set failed.\r\n" + ex.ToString(), "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Setting DNS failed.\r\n" + ex.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } diff --git a/HelpersLib/Forms/DNSChangerForm.resx b/DNSChanger/DNSChangerForm.resx similarity index 100% rename from HelpersLib/Forms/DNSChangerForm.resx rename to DNSChanger/DNSChangerForm.resx diff --git a/HelpersLib/DNSInfo.cs b/DNSChanger/DNSInfo.cs similarity index 98% rename from HelpersLib/DNSInfo.cs rename to DNSChanger/DNSInfo.cs index 796515285..a3a4bd48b 100644 --- a/HelpersLib/DNSInfo.cs +++ b/DNSChanger/DNSInfo.cs @@ -23,7 +23,7 @@ You should have received a copy of the GNU General Public License #endregion License Information (GPL v3) -namespace HelpersLib +namespace DNSChanger { public class DNSInfo { diff --git a/DNSChanger/Program.cs b/DNSChanger/Program.cs new file mode 100644 index 000000000..60ce2d05b --- /dev/null +++ b/DNSChanger/Program.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace DNSChanger +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + private static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new DNSChangerForm()); + } + } +} \ No newline at end of file diff --git a/DNSChanger/Properties/AssemblyInfo.cs b/DNSChanger/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..065f815d0 --- /dev/null +++ b/DNSChanger/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +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("ShareX DNS Changer")] +[assembly: AssemblyDescription("ShareX DNS Changer")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("ShareX Developers")] +[assembly: AssemblyProduct("ShareX DNS Changer")] +[assembly: AssemblyCopyright("Copyright (C) 2008-2014 ShareX Developers")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("c32059eb-20be-49fd-b50b-874d7fb3be3d")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// 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")] \ No newline at end of file diff --git a/DNSChanger/Properties/Resources.Designer.cs b/DNSChanger/Properties/Resources.Designer.cs new file mode 100644 index 000000000..8fdc8a078 --- /dev/null +++ b/DNSChanger/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.34011 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace DNSChanger.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DNSChanger.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/DNSChanger/Properties/Resources.resx b/DNSChanger/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/DNSChanger/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/DNSChanger/Properties/Settings.Designer.cs b/DNSChanger/Properties/Settings.Designer.cs new file mode 100644 index 000000000..c8556571c --- /dev/null +++ b/DNSChanger/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.34011 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace DNSChanger.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 + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/DNSChanger/Properties/Settings.settings b/DNSChanger/Properties/Settings.settings new file mode 100644 index 000000000..39645652a --- /dev/null +++ b/DNSChanger/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/HelpersLib/HelpersLib.csproj b/HelpersLib/HelpersLib.csproj index d73116362..cde6af8c7 100644 --- a/HelpersLib/HelpersLib.csproj +++ b/HelpersLib/HelpersLib.csproj @@ -88,14 +88,7 @@ - - - Form - - - DNSChangerForm.cs - Form @@ -318,9 +311,6 @@ ClipboardFormatForm.cs - - DNSChangerForm.cs - ErrorForm.cs diff --git a/ShareX.sln b/ShareX.sln index 642862632..426493d49 100644 --- a/ShareX.sln +++ b/ShareX.sln @@ -28,6 +28,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{B1CCDF EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShareXPortable", "ShareXPortable\ShareXPortable.csproj", "{3D19A94A-7A58-4451-A686-EE70B471C206}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DNSChanger", "DNSChanger\DNSChanger.csproj", "{F1061D2B-4C92-42B9-9A98-34118D6B45A8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -68,6 +70,10 @@ Global {D13441B6-96E1-4D1B-8A95-58A7D6CB1E24}.Release|Any CPU.Build.0 = Release|Any CPU {3D19A94A-7A58-4451-A686-EE70B471C206}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3D19A94A-7A58-4451-A686-EE70B471C206}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F1061D2B-4C92-42B9-9A98-34118D6B45A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F1061D2B-4C92-42B9-9A98-34118D6B45A8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F1061D2B-4C92-42B9-9A98-34118D6B45A8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F1061D2B-4C92-42B9-9A98-34118D6B45A8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ShareX/Forms/MainForm.cs b/ShareX/Forms/MainForm.cs index 722788a49..22246b936 100644 --- a/ShareX/Forms/MainForm.cs +++ b/ShareX/Forms/MainForm.cs @@ -29,7 +29,9 @@ You should have received a copy of the GNU General Public License using ScreenCaptureLib; using ShareX.Properties; using System; +using System.Diagnostics; using System.Drawing; +using System.IO; using System.Linq; using System.Threading; using System.Windows.Forms; @@ -610,10 +612,10 @@ private void OpenMonitorTest() private void OpenDNSChanger() { - using (DNSChangerForm dnsForm = new DNSChangerForm()) - { - dnsForm.ShowDialog(); - } + ProcessStartInfo psi = new ProcessStartInfo(Path.Combine(Application.StartupPath, "DNSChanger.exe")); + psi.UseShellExecute = true; + psi.Verb = "runas"; + Process.Start(psi); } #region Form events diff --git a/ShareX/ShareX.csproj b/ShareX/ShareX.csproj index 183e8e4bb..a0413f814 100644 --- a/ShareX/ShareX.csproj +++ b/ShareX/ShareX.csproj @@ -286,6 +286,10 @@ + + {f1061d2b-4c92-42b9-9a98-34118d6b45a8} + DNSChanger + {E7DE6237-AEA2-498B-8F56-9B392472C490} HistoryLib