- added online-version check

This commit is contained in:
hbeham
2013-04-08 10:08:49 +02:00
parent bae9a82efa
commit 16694534f0
7 changed files with 121 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
#define SYMBOL_RATE_ROUNDING
#undef STORE_DVBS_CHANNELS_IN_DATABASE
//#define STORE_DVBS_CHANNELS_IN_DATABASE
//#define TESTING_LM640T_HACK
using System;
using System.Collections.Generic;
@@ -309,7 +310,7 @@ namespace ChanSort.Loader.TllFile
this.DataRoot.AddChannelList(satTvChannels);
this.DataRoot.AddChannelList(satRadioChannels);
this.ScanDvbSSubBlockChecksums(off);
this.VerifyDvbsSubblockChecksums(off);
// subblock 1 (DVBS header)
off += 16;
@@ -329,15 +330,15 @@ namespace ChanSort.Loader.TllFile
off += satConfig.dvbsMaxChannelCount/8; // skip allocation bitmap
this.ReadDvbsChannelLinkedList(ref off);
this.ReadDvbSChannels(ref off, header.LinkedListStartIndex);
this.ReadDvbsChannels(ref off, header.LinkedListStartIndex);
// subblock 5 (satellite/LNB config)
off += satConfig.LnbBlockHeaderSize + satConfig.lnbCount*satConfig.lnbLength;
}
#endregion
#region ScanDvbSSubBlockChecksums()
private void ScanDvbSSubBlockChecksums(int off)
#region VerifyDvbsSubblockChecksums()
private void VerifyDvbsSubblockChecksums(int off)
{
this.dvbsSubblockCrcOffset = new int[satConfig.dvbsSubblockLength.Length];
for (int i = 0; i < dvbsSubblockCrcOffset.Length; i++)
@@ -423,8 +424,8 @@ namespace ChanSort.Loader.TllFile
}
#endregion
#region ReadDvbSChannels()
private void ReadDvbSChannels(ref int off, int startIndex)
#region ReadDvbsChannels()
private void ReadDvbsChannels(ref int off, int startIndex)
{
var mapping = this.dvbsMappings.GetMapping(satConfig.dvbsChannelLength);
int index = startIndex;
@@ -505,10 +506,16 @@ namespace ChanSort.Loader.TllFile
// header
this.dvbsSubblockCrcOffset[0] = (int)stream.Position;
stream.Seek(4, SeekOrigin.Current); // skip CRC32
#if TESTING_LM640T_HACK
stream.Write(Encoding.ASCII.GetBytes("DVBS-S2\0"), 0, 8);
//stream.Write(new byte[] { 255, 255, 255, 255, 255, 255, 255, 255 }, 0, 8);
wrt.Write((ushort)0);
wrt.Write((ushort)0);
#else
stream.Write(Encoding.ASCII.GetBytes("DVBS-S2\0"), 0, 8);
wrt.Write((ushort) 7);
wrt.Write((ushort) 4);
#endif
// satellite
this.dvbsSubblockCrcOffset[1] = (int)stream.Position;
stream.Seek(4, SeekOrigin.Current); // skip CRC32
@@ -613,7 +620,7 @@ namespace ChanSort.Loader.TllFile
newDvbctChannelCount = 0;
foreach (var list in this.DataRoot.ChannelLists)
{
foreach (TllChannelBase channel in list.Channels)
foreach (ChannelInfo channel in list.Channels)
{
if (channel.NewProgramNr != 0)
{

View File

@@ -89,7 +89,6 @@
<Compile Include="GlobalImageCollection.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ImageListDumper.cs" />
<Compile Include="InfoBox.cs">
<SubType>Form</SubType>
</Compile>
@@ -110,6 +109,7 @@
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="Settings.cs" />
<Compile Include="UpdateCheck.cs" />
<Compile Include="WaitForm1.cs">
<SubType>Form</SubType>
</Compile>

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Reflection;
@@ -23,7 +22,7 @@ namespace ChanSort.Ui
{
public partial class MainForm : XtraForm
{
public const string AppVersion = "v2013-04-07";
public const string AppVersion = "v2013-04-08";
#region enum EditMode
private enum EditMode
@@ -74,9 +73,13 @@ namespace ChanSort.Ui
else this.rbInsertSwap.Checked = true;
this.cbAppendUnsortedChannels.Checked = true;
this.ActiveControl = this.gridRight;
}
#endregion
Xaron.UIHelpers.ImageListDumper.WriteToDirectory(this.globalImageCollection1.ImageSource, @"c:\temp\chansort", "",
ImageFormat.Png);
#region InitAppAfterMainWindowWasShown()
private void InitAppAfterMainWindowWasShown()
{
this.BeginInvoke((Action)UpdateCheck.CheckForNewVersion);
}
#endregion
@@ -1146,7 +1149,8 @@ namespace ChanSort.Ui
#region MainForm_Load
private void MainForm_Load(object sender, EventArgs e)
{
TryExecute(this.LoadSettings);
this.TryExecute(this.LoadSettings);
this.TryExecute(this.InitAppAfterMainWindowWasShown);
}
#endregion

View File

@@ -333,5 +333,24 @@ namespace ChanSort.Ui.Properties {
return ResourceManager.GetString("paypal_button", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to New Version.
/// </summary>
internal static string UpdateCheck_NotifyAboutNewVersion_Caption {
get {
return ResourceManager.GetString("UpdateCheck_NotifyAboutNewVersion_Caption", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to A newer version is available: v{0}.
///Do you want to open the download website?.
/// </summary>
internal static string UpdateCheck_NotifyAboutNewVersion_Message {
get {
return ResourceManager.GetString("UpdateCheck_NotifyAboutNewVersion_Message", resourceCulture);
}
}
}
}

View File

@@ -227,4 +227,11 @@ Möchten Sie fortfahren?</value>
Die Fehlermeldung lautet:
</value>
</data>
<data name="UpdateCheck_NotifyAboutNewVersion_Message" xml:space="preserve">
<value>Eine neuere Version ist verfügbar: v{0}.
Möchten Sie die Downloadseite öffnen?</value>
</data>
<data name="UpdateCheck_NotifyAboutNewVersion_Caption" xml:space="preserve">
<value>Neue Version</value>
</data>
</root>

View File

@@ -226,4 +226,11 @@ The error message is:
<data name="MainForm_SaveFiles_ErrorTitle" xml:space="preserve">
<value>File write error</value>
</data>
<data name="UpdateCheck_NotifyAboutNewVersion_Message" xml:space="preserve">
<value>A newer version is available: v{0}.
Do you want to open the download website?</value>
</data>
<data name="UpdateCheck_NotifyAboutNewVersion_Caption" xml:space="preserve">
<value>New Version</value>
</data>
</root>

62
ChanSort/UpdateCheck.cs Normal file
View File

@@ -0,0 +1,62 @@
using System.Net.Sockets;
using System.Text;
using ChanSort.Ui.Properties;
using DevExpress.XtraEditors;
namespace ChanSort.Ui
{
class UpdateCheck
{
private const string SearchString = "ChanSort_";
public static void CheckForNewVersion()
{
try
{
var check = new UpdateCheck();
check.Check();
}
catch
{
}
}
private void Check()
{
// NOTE: tried using WebRequest class, but that causes massive timeout problems after program start (DLL loading/init?)
using (Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
sock.ReceiveTimeout = 1000;
sock.Connect("sourceforge.net", 80);
var request = Encoding.UTF8.GetBytes("GET /projects/chansort/ HTTP/1.1\r\nHost: sourceforge.net\r\n\r\n");
sock.Send(request);
byte[] buffer = new byte[100000];
int len = sock.Receive(buffer);
var response = Encoding.ASCII.GetString(buffer, 0, len);
int start = response.IndexOf(SearchString);
if (start >= 0)
{
int end = response.IndexOf(".zip", start);
if (end == start + SearchString.Length + 10)
{
string newVersion = response.Substring(start + SearchString.Length, 10);
if (newVersion.CompareTo(MainForm.AppVersion.TrimStart('v')) > 0)
this.NotifyAboutNewVersion(newVersion);
}
}
}
}
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("http://sourceforge.net/p/chansort/files/");
}
}
}