Skip to content

Commit

Permalink
Patched so you no longer need an internet connection to run the progr…
Browse files Browse the repository at this point in the history
…am. Version 4.3 release
  • Loading branch information
Codeusa committed Jan 13, 2014
1 parent 4aaf6b5 commit f526e96
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 67 deletions.
84 changes: 84 additions & 0 deletions NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}
}
}
/// <summary>
/// XML PARSER - WILL BE REMOVED FOR SOMETHING BETTER
}
}
}
65 changes: 2 additions & 63 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
4 changes: 2 additions & 2 deletions version.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<borderlessgaming>
<version>4.2</version>
<url>https://github.com/Codeusa/Borderless-Gaming/releases/tag/4.2</url>
<version>4.3</version>
<url>https://github.com/Codeusa/Borderless-Gaming/releases/tag/4.3</url>
</borderlessgaming>

0 comments on commit f526e96

Please sign in to comment.