From 39f2c59f94a840364a2e3a774f82e8a855e7e720 Mon Sep 17 00:00:00 2001 From: Horst Beham Date: Sun, 5 Sep 2021 18:20:39 +0200 Subject: [PATCH] - Philips loaders will show model and file format version under File / File information... --- .../ChanSort.Api/Controller/SerializerBase.cs | 3 ++ .../BinarySerializer.cs | 3 ++ source/ChanSort.Loader.Philips/ChanLstBin.cs | 2 +- .../ChanSort.Loader.Philips.ini | 2 +- .../ChanSort.Loader.Philips/DbSerializer.cs | 36 +++++++++++++++++++ .../ChanSort.Loader.Philips/XmlSerializer.cs | 8 +++++ source/ChanSort/MainForm.cs | 14 ++++++-- 7 files changed, 63 insertions(+), 5 deletions(-) diff --git a/source/ChanSort.Api/Controller/SerializerBase.cs b/source/ChanSort.Api/Controller/SerializerBase.cs index da2e334..010aa48 100644 --- a/source/ChanSort.Api/Controller/SerializerBase.cs +++ b/source/ChanSort.Api/Controller/SerializerBase.cs @@ -138,6 +138,9 @@ namespace ChanSort.Api } #endregion + public virtual string TvModelName { get; set; } + public virtual string FileFormatVersion { get; set; } + public virtual void ShowDeviceSettingsForm(object parentWindow) { } public virtual string CleanUpChannelData() { return ""; } diff --git a/source/ChanSort.Loader.Philips/BinarySerializer.cs b/source/ChanSort.Loader.Philips/BinarySerializer.cs index 48f52db..79be91a 100644 --- a/source/ChanSort.Loader.Philips/BinarySerializer.cs +++ b/source/ChanSort.Loader.Philips/BinarySerializer.cs @@ -95,6 +95,9 @@ namespace ChanSort.Loader.Philips { this.chanLstBin = new ChanLstBin(); this.chanLstBin.Load(this.FileName, msg => this.logMessages.AppendLine(msg)); + this.TvModelName = this.chanLstBin.ModelName; + this.FileFormatVersion = $"{chanLstBin.VersionMajor}.{chanLstBin.VersionMinor}"; + this.dataFilePaths.Add(this.FileName); var dir = Path.GetDirectoryName(this.FileName) ?? ""; diff --git a/source/ChanSort.Loader.Philips/ChanLstBin.cs b/source/ChanSort.Loader.Philips/ChanLstBin.cs index 927f48f..9b76973 100644 --- a/source/ChanSort.Loader.Philips/ChanLstBin.cs +++ b/source/ChanSort.Loader.Philips/ChanLstBin.cs @@ -117,7 +117,7 @@ namespace ChanSort.Loader.Philips var actualCrc = Crc16.Calc(data, 0, length); if (actualCrc != expectedCrc) { - var msg = $"chanLst.bin: stored CRC for {entry.Key} is {expectedCrc:x4} but calculated {actualCrc:x4}"; + var msg = $"chanLst.bin: stored CRC for {entry.Key} is {expectedCrc:X4} but calculated {actualCrc:X4}"; errors += "\n" + msg; } } diff --git a/source/ChanSort.Loader.Philips/ChanSort.Loader.Philips.ini b/source/ChanSort.Loader.Philips/ChanSort.Loader.Philips.ini index 3e7023a..2c33ce5 100644 --- a/source/ChanSort.Loader.Philips/ChanSort.Loader.Philips.ini +++ b/source/ChanSort.Loader.Philips/ChanSort.Loader.Philips.ini @@ -95,7 +95,7 @@ reorderRecordsByChannelNumber=false ############################################################################ -# ChannelMap_45 with list.db, tv.db, HsvDvbCSettings, CableDb.bin, HsvDvbTSettings.bin, TerrestrialDb.bin, SatelliteDb.bin - experimental +# ChannelMap_45 with list.db, tv.db, HsvDvbCSettings, CableDb.bin, HsvDvbTSettings.bin, TerrestrialDb.bin, SatelliteDb.bin - stable [Map45] incrementFavListVersion=false diff --git a/source/ChanSort.Loader.Philips/DbSerializer.cs b/source/ChanSort.Loader.Philips/DbSerializer.cs index 44280e9..eb46d0e 100644 --- a/source/ChanSort.Loader.Philips/DbSerializer.cs +++ b/source/ChanSort.Loader.Philips/DbSerializer.cs @@ -62,6 +62,9 @@ namespace ChanSort.Loader.Philips var lc = Path.GetFileName(file).ToLowerInvariant(); switch (lc) { + case "channel_db_ver.db": + LoadVersion(file); + break; case "mgr_chan_s_fta.db": LoadDvbs(file); validList = true; @@ -72,7 +75,40 @@ namespace ChanSort.Loader.Philips if (!validList) throw new FileLoadException(this.FileName + " is not a supported Philips Repair/mgr_chan_s_fta.db channel list"); } + #endregion + #region LoadVersion() + private void LoadVersion(string file) + { + var data = File.ReadAllBytes(file); + this.FileFormatVersion = "FLASH/.db"; + if (data.Length >= 2) + this.FileFormatVersion += " " + BitConverter.ToInt16(data, 0); + if (data.Length >= 3) + this.FileFormatVersion += $"-{data[2]:D2}"; + if (data.Length >= 4) + this.FileFormatVersion += $"-{data[3]:D2}"; + if (data.Length >= 5) + this.FileFormatVersion += $" {data[4]:D2}"; + if (data.Length >= 6) + this.FileFormatVersion += $":{data[5]:D2}"; + if (data.Length >= 7) + this.FileFormatVersion += $":{data[6]:D2}"; + + // Philips doesn't export any information about the TV model in this format. For automated stats I manually place modelinfo.txt files in the folders + for (var dir = Path.GetDirectoryName(file); dir != ""; dir = Path.GetDirectoryName(dir)) + { + var path = Path.Combine(dir, "modelinfo.txt"); + if (File.Exists(path)) + { + this.TvModelName = File.ReadAllText(path); + break; + } + } + } + #endregion + + #region LoadDvbs() private void LoadDvbs(string file) { var data = File.ReadAllBytes(file); diff --git a/source/ChanSort.Loader.Philips/XmlSerializer.cs b/source/ChanSort.Loader.Philips/XmlSerializer.cs index 57b8991..b0703df 100644 --- a/source/ChanSort.Loader.Philips/XmlSerializer.cs +++ b/source/ChanSort.Loader.Philips/XmlSerializer.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Reflection; using System.Text; +using System.Text.RegularExpressions; using System.Xml; using System.Xml.Schema; using ChanSort.Api; @@ -173,6 +174,8 @@ namespace ChanSort.Loader.Philips isChannelMapFolderStructure = true; this.chanLstBin = new ChanLstBin(); this.chanLstBin.Load(this.FileName, msg => this.logMessages.AppendLine(msg)); + this.TvModelName = this.chanLstBin.ModelName; + this.FileFormatVersion = $"{chanLstBin.VersionMajor}.{chanLstBin.VersionMinor}"; } else if (Path.GetExtension(this.FileName).ToLowerInvariant() == ".bin") { @@ -183,6 +186,11 @@ namespace ChanSort.Loader.Philips try { File.SetAttributes(xmlPath, FileAttributes.Archive);} catch { /**/ } this.FileName = xmlPath; + var baseName = Path.GetFileNameWithoutExtension(xmlPath).ToUpperInvariant(); + if (baseName.StartsWith("CM_")) + baseName = baseName.Substring(3); + this.TvModelName = baseName; + this.FileFormatVersion = "Legacy XML"; } } diff --git a/source/ChanSort/MainForm.cs b/source/ChanSort/MainForm.cs index 80d3d2e..5e645db 100644 --- a/source/ChanSort/MainForm.cs +++ b/source/ChanSort/MainForm.cs @@ -1890,17 +1890,25 @@ namespace ChanSort.Ui { if (this.currentTvSerializer == null) return; - var info = this.currentTvSerializer.GetFileInformation(); + + var info = new StringBuilder(); + if (!string.IsNullOrEmpty(this.currentTvSerializer.TvModelName)) + info.AppendLine("TV model name: " + this.currentTvSerializer.TvModelName); + if (!string.IsNullOrEmpty(this.currentTvSerializer.FileFormatVersion)) + info.AppendLine("List format version: " + this.currentTvSerializer.FileFormatVersion); + + info.AppendLine(); + info.AppendLine(this.currentTvSerializer.GetFileInformation()); if (this.DataRoot.Warnings.Length > 0) { var lines = this.DataRoot.Warnings.ToString().Split('\n'); Array.Sort(lines); var sortedWarnings = string.Join("\n", lines); - info += "\r\n\r\n\r\n" + Resources.MainForm_LoadFiles_ValidationWarningMsg + "\r\n\r\n" + sortedWarnings; + info.Append("\r\n\r\n\r\n").Append(Resources.MainForm_LoadFiles_ValidationWarningMsg).Append("\r\n\r\n").Append(sortedWarnings); } - InfoBox.Show(this, info, this.miFileInformation.Caption.Replace("...", "").Replace("&", "")); + InfoBox.Show(this, info.ToString(), this.miFileInformation.Caption.Replace("...", "").Replace("&", "")); } #endregion