From 16694534f00721a8aa64ed10a4c10fb30ca46ab3 Mon Sep 17 00:00:00 2001 From: hbeham Date: Mon, 8 Apr 2013 10:08:49 +0200 Subject: [PATCH] - added online-version check --- ChanSort.Loader.TllFile/TllFileSerializer.cs | 25 +++++--- ChanSort/ChanSort.csproj | 2 +- ChanSort/MainForm.cs | 14 +++-- ChanSort/Properties/Resources.Designer.cs | 19 ++++++ ChanSort/Properties/Resources.de.resx | 7 +++ ChanSort/Properties/Resources.resx | 7 +++ ChanSort/UpdateCheck.cs | 62 ++++++++++++++++++++ 7 files changed, 121 insertions(+), 15 deletions(-) create mode 100644 ChanSort/UpdateCheck.cs diff --git a/ChanSort.Loader.TllFile/TllFileSerializer.cs b/ChanSort.Loader.TllFile/TllFileSerializer.cs index 60a3cb9..d3ed715 100644 --- a/ChanSort.Loader.TllFile/TllFileSerializer.cs +++ b/ChanSort.Loader.TllFile/TllFileSerializer.cs @@ -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) { diff --git a/ChanSort/ChanSort.csproj b/ChanSort/ChanSort.csproj index 94f5bde..08647bf 100644 --- a/ChanSort/ChanSort.csproj +++ b/ChanSort/ChanSort.csproj @@ -89,7 +89,6 @@ Component - Form @@ -110,6 +109,7 @@ True + Form diff --git a/ChanSort/MainForm.cs b/ChanSort/MainForm.cs index db511ef..e45eb47 100644 --- a/ChanSort/MainForm.cs +++ b/ChanSort/MainForm.cs @@ -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 diff --git a/ChanSort/Properties/Resources.Designer.cs b/ChanSort/Properties/Resources.Designer.cs index cee968d..df78028 100644 --- a/ChanSort/Properties/Resources.Designer.cs +++ b/ChanSort/Properties/Resources.Designer.cs @@ -333,5 +333,24 @@ namespace ChanSort.Ui.Properties { return ResourceManager.GetString("paypal_button", resourceCulture); } } + + /// + /// Looks up a localized string similar to New Version. + /// + internal static string UpdateCheck_NotifyAboutNewVersion_Caption { + get { + return ResourceManager.GetString("UpdateCheck_NotifyAboutNewVersion_Caption", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to A newer version is available: v{0}. + ///Do you want to open the download website?. + /// + internal static string UpdateCheck_NotifyAboutNewVersion_Message { + get { + return ResourceManager.GetString("UpdateCheck_NotifyAboutNewVersion_Message", resourceCulture); + } + } } } diff --git a/ChanSort/Properties/Resources.de.resx b/ChanSort/Properties/Resources.de.resx index 9bf5b0f..364b033 100644 --- a/ChanSort/Properties/Resources.de.resx +++ b/ChanSort/Properties/Resources.de.resx @@ -227,4 +227,11 @@ Möchten Sie fortfahren? Die Fehlermeldung lautet: + + Eine neuere Version ist verfügbar: v{0}. +Möchten Sie die Downloadseite öffnen? + + + Neue Version + \ No newline at end of file diff --git a/ChanSort/Properties/Resources.resx b/ChanSort/Properties/Resources.resx index 1c4df20..fb6692d 100644 --- a/ChanSort/Properties/Resources.resx +++ b/ChanSort/Properties/Resources.resx @@ -226,4 +226,11 @@ The error message is: File write error + + A newer version is available: v{0}. +Do you want to open the download website? + + + New Version + \ No newline at end of file diff --git a/ChanSort/UpdateCheck.cs b/ChanSort/UpdateCheck.cs new file mode 100644 index 0000000..446294a --- /dev/null +++ b/ChanSort/UpdateCheck.cs @@ -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/"); + } + } +}