From f526e9612581916471a2d1e34d86026cf3731ca9 Mon Sep 17 00:00:00 2001 From: Codeusa Date: Mon, 13 Jan 2014 06:37:45 -0500 Subject: [PATCH] Patched so you no longer need an internet connection to run the program. Version 4.3 release --- NativeMethods.cs | 84 ++++++++++++++++++++++++++++++++++++++ Program.cs | 65 +---------------------------- Properties/AssemblyInfo.cs | 4 +- version.xml | 4 +- 4 files changed, 90 insertions(+), 67 deletions(-) diff --git a/NativeMethods.cs b/NativeMethods.cs index f3eb340..cfec41d 100644 --- a/NativeMethods.cs +++ b/NativeMethods.cs @@ -7,8 +7,13 @@ // **************************************** using System; +using System.Diagnostics; +using System.Net; +using System.Reflection; using System.Runtime.InteropServices; using System.Text; +using System.Windows.Forms; +using System.Xml; namespace BorderlessGaming { @@ -285,5 +290,84 @@ public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x [DllImport("user32.dll")] public static extern int SetWindowText(IntPtr hWnd, string text); + + private static bool HasInternetConnection() + { + //There is absolutely no way you can reliably check if there is an internet connection + try + { + using (var client = new WebClient()) + using (var stream = client.OpenRead("http://www.google.com")) + return true; + } + catch + { + return false; + } + } + + public static void CheckForUpdates() + { + if (HasInternetConnection()) + { + var _releasePageURL = ""; + Version _newVersion = null; + const string _versionConfig = "https://raw.github.com/Codeusa/Borderless-Gaming/master/version.xml"; + var _reader = new XmlTextReader(_versionConfig); + _reader.MoveToContent(); + var _elementName = ""; + try + { + if ((_reader.NodeType == XmlNodeType.Element) && (_reader.Name == "borderlessgaming")) + while (_reader.Read()) + switch (_reader.NodeType) + { + case XmlNodeType.Element: + _elementName = _reader.Name; + break; + default: + if ((_reader.NodeType == XmlNodeType.Text) && (_reader.HasValue)) + switch (_elementName) + { + case "version": + _newVersion = new Version(_reader.Value); + break; + case "url": + _releasePageURL = _reader.Value; + break; + } + break; + } + } + catch (Exception) + { + Console.WriteLine(("No updates for you")); + } + finally + { + _reader.Close(); + } + var applicationVersion = Assembly.GetExecutingAssembly().GetName().Version; + if (applicationVersion.CompareTo(_newVersion) < 0) + { + var result = + MessageBox.Show("Borderless Gaming has an update, would you like to go to the release page?", + "Warning", + MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); + switch (result) + { + case DialogResult.Yes: + Process.Start(_releasePageURL); + break; + case DialogResult.No: + break; + case DialogResult.Cancel: + break; + } + } + } + /// + /// XML PARSER - WILL BE REMOVED FOR SOMETHING BETTER + } } } \ No newline at end of file diff --git a/Program.cs b/Program.cs index 128e6bc..5949d52 100644 --- a/Program.cs +++ b/Program.cs @@ -14,69 +14,8 @@ internal static class Program [STAThread] private static void Main() { - var _releasePageURL = ""; - Version _newVersion = null; - const string _versionConfig = "https://raw.github.com/Codeusa/Borderless-Gaming/master/version.xml"; - var _reader = new XmlTextReader(_versionConfig); - _reader.MoveToContent(); - var _elementName = ""; - try - { - if ((_reader.NodeType == XmlNodeType.Element) && (_reader.Name == "borderlessgaming")) - { - while (_reader.Read()) - { - if (_reader.NodeType == XmlNodeType.Element) - { - _elementName = _reader.Name; - } - else - { - if ((_reader.NodeType == XmlNodeType.Text) && (_reader.HasValue)) - { - switch (_elementName) - { - case "version": - _newVersion = new Version(_reader.Value); - break; - case "url": - _releasePageURL = _reader.Value; - break; - } - } - } - } - } - } - catch (Exception e) - { - Console.WriteLine(("No updates for you")); - } - finally - { - _reader.Close(); - } - var applicationVersion = Assembly.GetExecutingAssembly().GetName().Version; - if (applicationVersion.CompareTo(_newVersion) < 0) - { - var result = - MessageBox.Show("Borderless Gaming has an update, would you like to go to the release page?", - "Warning", - MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); - if (result == DialogResult.Yes) - { - Process.Start(_releasePageURL); - } - else if (result == DialogResult.No) - { - // do nothing - } - else if (result == DialogResult.Cancel) - { - // do nothing - } - } - + + Native.CheckForUpdates(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Borderless()); diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 66fc1c6..86baaff 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -33,6 +33,6 @@ // 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("4.2.0.0")] -[assembly: AssemblyFileVersion("4.2.0.0")] +[assembly: AssemblyVersion("4.3.0.0")] +[assembly: AssemblyFileVersion("4.3.0.0")] [assembly: NeutralResourcesLanguageAttribute("en-US")] diff --git a/version.xml b/version.xml index ee24c2d..8dff129 100644 --- a/version.xml +++ b/version.xml @@ -1,5 +1,5 @@ - 4.2 - https://github.com/Codeusa/Borderless-Gaming/releases/tag/4.2 + 4.3 + https://github.com/Codeusa/Borderless-Gaming/releases/tag/4.3