Files
ChanSort/source/ChanSort/UpdateCheck.cs
hbeham b0277bd4a3 - Samsung J series: fixed deleting of channels
- LG GlobalClone: modified channel names were not written to the file
- LG GlobalClone: ask whether the conflicting xx*.TLL files should be
  renamed so that the TV can import the GlobalClone file.
- LG GlobalClone: improved support for old file format with may
  have caused errors due to invalid XML characters inside the file.
- Panasonic: re-enabled channel lists with gaps in the numbers
- Update-Check: looking for latest version at github.com
- Detecting corrupted files with 0 size or all bytes with value 0
- upgraded to latest DevExpress version
2015-09-19 23:24:31 +02:00

62 lines
1.7 KiB
C#

using System.Net;
using System.Threading;
using ChanSort.Ui.Properties;
using DevExpress.XtraEditors;
namespace ChanSort.Ui
{
class UpdateCheck
{
private const string UpdateUrl = "http://github.com/PredatH0r/ChanSort/releases";
private const string SearchString = "ChanSort_";
public static void CheckForNewVersion()
{
var check = new UpdateCheck();
Thread thread = new Thread(check.Check);
thread.Start();
}
private void Check()
{
try
{
var newVersion = this.GetLatestVersion();
if (newVersion.CompareTo(MainForm.AppVersion.TrimStart('v')) > 0)
this.NotifyAboutNewVersion(newVersion);
}
catch { }
}
private string GetLatestVersion()
{
string response;
using (WebClient client = new WebClient())
{
client.Proxy = null; // prevent a 1min wait/timeout by a .NET bug
response = client.DownloadString(UpdateUrl);
}
int start = response.IndexOf(SearchString);
if (start >= 0)
{
int end = response.IndexOf(".zip", start);
if (end == start + SearchString.Length + 10)
return response.Substring(start + SearchString.Length, 10);
}
return string.Empty;
}
private void NotifyAboutNewVersion(string newVersion)
{
if (XtraMessageBox.Show(
string.Format(Resources.UpdateCheck_NotifyAboutNewVersion_Message, newVersion),
Resources.UpdateCheck_NotifyAboutNewVersion_Caption,
System.Windows.Forms.MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Question,
System.Windows.Forms.MessageBoxDefaultButton.Button1) != System.Windows.Forms.DialogResult.Yes)
return;
BrowserHelper.OpenUrl(UpdateUrl);
}
}
}