From 65600756daaf2721d3d08a4f4294109502d5bb99 Mon Sep 17 00:00:00 2001 From: hbeham Date: Fri, 8 Nov 2019 19:35:59 +0100 Subject: [PATCH] some more code cleanup and a few minor fixes --- readme.md | 2 +- readme_de.md | 2 +- source/ChanSort.Api/ChanSort.Api.csproj | 1 - source/ChanSort.Api/Controller/Editor.cs | 70 --------------- .../ChanSort.Api/Controller/SerializerBase.cs | 88 ++++++++++++------- source/ChanSort.Api/Model/DataRoot.cs | 70 ++++++++++++++- .../ChanSort.Loader.Panasonic/Serializer.cs | 11 ++- .../ChanSort.Loader.Samsung/ScmSerializer.cs | 48 +++++----- .../ChanSort.Loader.SamsungJ/DbSerializer.cs | 9 +- .../ChanSort.Loader.Toshiba/DbSerializer.cs | 18 ++-- source/ChanSort/MainForm.cs | 15 +++- source/ChanSort/MainForm.resx | 4 +- source/ChanSort/ReferenceListForm.Designer.cs | 13 --- source/ChanSort/ReferenceListForm.cs | 12 +++ .../LgGlobalCloneTest.cs | 4 +- .../HisenseChannelDbTest.cs | 4 +- .../HisenseServicelistDbTest.cs | 4 +- source/Test.Loader.LG/LM/TestLM.cs | 4 +- .../Test.Loader.Panasonic/PanasonicSvlTest.cs | 4 +- .../Test.Loader.PhilipsXml/PhilipsXmlTest.cs | 4 +- source/Test.Loader.Samsung/SamsungTest.cs | 8 +- .../Test.Loader.Samsung.csproj | 3 - source/Test.Loader.SamsungJ/SamsungZipTest.cs | 4 +- source/Test.Loader.SilvaSchneider/SdxTest.cs | 4 +- source/Test.Loader.Sony/SonyXmlTest.cs | 8 +- .../Test.Loader.Toshiba/ToshibaChmgtDbTest.cs | 4 +- source/Test.Loader.VDR/LinuxVdrTest.cs | 4 +- source/makeDistribZip.cmd | 2 +- 28 files changed, 206 insertions(+), 218 deletions(-) diff --git a/readme.md b/readme.md index 0f9bed5..f9880fb 100644 --- a/readme.md +++ b/readme.md @@ -56,7 +56,7 @@ Special thanks to Hisense for supporting ChanSort with technical information and **Samsung** .scm files: B (2009)*, B (2013), C, D, E, F, H, J series -.zip files: H, J, K, M, N and Q series +.zip files: H, J, K, M, N and Q, R series Lists: Air analog, Air digital, Cable analog, Cable digital, Cable Prime, Sat digital, Astra HD+, Freesat, TivuSat, Canal Digital Sat, Digital+, Cyfra+ diff --git a/readme_de.md b/readme_de.md index 4a6a89c..dc7eb5e 100644 --- a/readme_de.md +++ b/readme_de.md @@ -55,7 +55,7 @@ Besonderen Dank an Hisense f **Samsung** .scm Dateien: Serien B (2009)*, B (2013), C, D, E, F, H, J -.zip Dateien: Serien H, J, K, M, N and Q series +.zip Dateien: Serien H, J, K, M, N, Q, R Listen: Air analog, Air digital, Cable analog, Cable digital, Cable Prime, Sat digital, Astra HD+, Freesat, TivuSat, Canal Digital Sat, Digital+, Cyfra+ diff --git a/source/ChanSort.Api/ChanSort.Api.csproj b/source/ChanSort.Api/ChanSort.Api.csproj index 3bc94e2..583e547 100644 --- a/source/ChanSort.Api/ChanSort.Api.csproj +++ b/source/ChanSort.Api/ChanSort.Api.csproj @@ -58,7 +58,6 @@ - diff --git a/source/ChanSort.Api/Controller/Editor.cs b/source/ChanSort.Api/Controller/Editor.cs index 09c0558..4479435 100644 --- a/source/ChanSort.Api/Controller/Editor.cs +++ b/source/ChanSort.Api/Controller/Editor.cs @@ -10,7 +10,6 @@ namespace ChanSort.Api public DataRoot DataRoot; public ChannelList ChannelList; public int SubListIndex; - private UnsortedChannelMode unsortedChannelMode; #region AddChannels() @@ -344,75 +343,6 @@ namespace ChanSort.Api #endregion - #region AutoNumberingForUnassignedChannels() - - public void AutoNumberingForUnassignedChannels(UnsortedChannelMode mode) - { - this.unsortedChannelMode = mode; - foreach (var list in DataRoot.ChannelLists) - { - if (list.IsMixedSourceFavoritesList) - continue; - - // sort the channels by assigned numbers, then unassigned by original order or alphabetically, then deleted channels - var sortedChannels = list.Channels.OrderBy(ChanSortCriteria).ToList(); - int maxProgNr = 0; - - foreach (var appChannel in sortedChannels) - { - if (appChannel.IsProxy) - continue; - - if (appChannel.NewProgramNr == -1) - { - if (mode == UnsortedChannelMode.Delete) - appChannel.IsDeleted = true; - else // append (hidden if possible) - { - appChannel.Hidden = true; - appChannel.Skip = true; - } - - // assign a valid number or 0 .... because -1 will never be a valid value for the TV - appChannel.NewProgramNr = mode != UnsortedChannelMode.Delete || this.DataRoot.DeletedChannelsNeedNumbers ? ++maxProgNr : 0; - } - else - { - if (appChannel.NewProgramNr > maxProgNr) - maxProgNr = appChannel.NewProgramNr; - } - } - } - } - - #region ChanSortCriteria() - - private string ChanSortCriteria(ChannelInfo channel) - { - // explicitly sorted - var pos = channel.NewProgramNr; - if (pos != -1) - return pos.ToString("d5"); - - // eventually hide unsorted channels - if (this.unsortedChannelMode == UnsortedChannelMode.Delete) - return "Z" + channel.RecordIndex.ToString("d5"); - - // eventually append in old order - if (this.unsortedChannelMode == UnsortedChannelMode.AppendInOrder) - return "B" + channel.OldProgramNr.ToString("d5"); - - // sort alphabetically, with "." and "" on the bottom - if (channel.Name == ".") - return "B"; - if (channel.Name == "") - return "C"; - return "A" + channel.Name; - } - - #endregion - - #endregion #region SetFavorites() public void SetFavorites(List list, Favorites favorites, bool set) diff --git a/source/ChanSort.Api/Controller/SerializerBase.cs b/source/ChanSort.Api/Controller/SerializerBase.cs index 3eeb5d7..603ad9e 100644 --- a/source/ChanSort.Api/Controller/SerializerBase.cs +++ b/source/ChanSort.Api/Controller/SerializerBase.cs @@ -1,11 +1,11 @@ -using System.IO; +using System; +using System.IO; using System.IO.Compression; using System.Text; -using System.Windows.Forms; namespace ChanSort.Api { - public abstract class SerializerBase + public abstract class SerializerBase : IDisposable { #region class SupportedFeatures @@ -33,10 +33,6 @@ namespace ChanSort.Api public bool MixedSourceFavorites { get; set; } public bool AllowGapsInFavNumbers { get; set; } - public bool CanDeleteChannelsWithFlag => this.DeleteMode == DeleteMode.FlagWithPrNr || this.DeleteMode == DeleteMode.FlagWithoutPrNr; - public bool CanDeleteChannelsFromFile => this.DeleteMode == DeleteMode.Physically; - public bool DeletedChannelsNeedNumbers => this.DeleteMode == DeleteMode.FlagWithPrNr; - } #endregion @@ -107,43 +103,67 @@ namespace ChanSort.Api // common implementation helper methods - protected string UnzipFileToTempFolder() - { - var tempDir = this.FileName + ".tmp"; + protected string TempPath { get; set; } - if (Directory.Exists(tempDir)) - Directory.Delete(tempDir, true); - Directory.CreateDirectory(tempDir); - ZipFile.ExtractToDirectory(this.FileName, tempDir); - this.DeleteOnExit(tempDir); - return tempDir; + #region UnzipToTempFolder(), ZipToOutputFile() + + protected void UnzipFileToTempFolder() + { + this.DeleteTempPath(); + this.TempPath = Path.Combine(Path.GetTempPath(), "ChanSort_" + Path.GetRandomFileName()); + + if (Directory.Exists(this.TempPath)) + Directory.Delete(this.TempPath, true); + Directory.CreateDirectory(this.TempPath); + ZipFile.ExtractToDirectory(this.FileName, this.TempPath); } protected void ZipToOutputFile(string tvOutputFile) { - var tempDir = this.FileName + ".tmp"; File.Delete(tvOutputFile); - ZipFile.CreateFromDirectory(tempDir, tvOutputFile); + ZipFile.CreateFromDirectory(this.TempPath, tvOutputFile); this.FileName = tvOutputFile; } + #endregion - // TODO: replace this with a SerializerBase implementing IDisposable - protected virtual void DeleteOnExit(string fileOrFolder) + #region IDisposable + + public void Dispose() { - Application.ApplicationExit += (sender, args) => - { - try - { - if (Directory.Exists(fileOrFolder)) - Directory.Delete(fileOrFolder, true); - else if (File.Exists(fileOrFolder)) - File.Delete(fileOrFolder); - } - catch - { - // ignore - } - }; + this.Dispose(true); + GC.SuppressFinalize(this); } + + ~SerializerBase() + { + this.Dispose(false); + } + + protected virtual void Dispose(bool disposing) + { + this.DeleteTempPath(); + } + + #endregion + + #region DeleteTempPath() + protected void DeleteTempPath() + { + var path = this.TempPath; + if (string.IsNullOrEmpty(path)) + return; + try + { + if (Directory.Exists(path)) + Directory.Delete(path, true); + else if (File.Exists(path)) + File.Delete(path); + } + catch + { + // ignore + } + } + #endregion } } diff --git a/source/ChanSort.Api/Model/DataRoot.cs b/source/ChanSort.Api/Model/DataRoot.cs index 9611e8f..819796d 100644 --- a/source/ChanSort.Api/Model/DataRoot.cs +++ b/source/ChanSort.Api/Model/DataRoot.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using System.Text; namespace ChanSort.Api @@ -21,7 +22,7 @@ namespace ChanSort.Api public bool SortedFavorites => this.loader.Features.SortedFavorites; public bool MixedSourceFavorites => this.loader.Features.MixedSourceFavorites; public bool AllowGapsInFavNumbers => this.loader.Features.AllowGapsInFavNumbers; - public bool DeletedChannelsNeedNumbers => this.loader.Features.DeletedChannelsNeedNumbers; + public bool DeletedChannelsNeedNumbers => this.loader.Features.DeleteMode == SerializerBase.DeleteMode.FlagWithPrNr; public DataRoot(SerializerBase loader) { @@ -142,6 +143,73 @@ namespace ChanSort.Api } #endregion + #region AssignNumbersToUnsortedAndDeletedChannels() + + public void AssignNumbersToUnsortedAndDeletedChannels(UnsortedChannelMode mode) + { + foreach (var list in this.ChannelLists) + { + if (list.IsMixedSourceFavoritesList) + continue; + + // sort the channels by assigned numbers, then unassigned by original order or alphabetically, then deleted channels + var sortedChannels = list.Channels.OrderBy(ch => ChanSortCriteria(ch, mode)); + int maxProgNr = 0; + + foreach (var appChannel in sortedChannels) + { + if (appChannel.IsProxy) + continue; + + if (appChannel.NewProgramNr == -1) + { + if (mode == UnsortedChannelMode.Delete) + appChannel.IsDeleted = true; + else // append (hidden if possible) + { + appChannel.Hidden = true; + appChannel.Skip = true; + } + + // assign a valid number or 0 .... because -1 will never be a valid value for the TV + appChannel.NewProgramNr = mode != UnsortedChannelMode.Delete || this.DeletedChannelsNeedNumbers ? ++maxProgNr : 0; + } + else + { + appChannel.IsDeleted = false; + if (appChannel.NewProgramNr > maxProgNr) + maxProgNr = appChannel.NewProgramNr; + } + } + } + } + + private string ChanSortCriteria(ChannelInfo channel, UnsortedChannelMode mode) + { + // explicitly sorted + var pos = channel.NewProgramNr; + if (pos != -1) + return pos.ToString("d5"); + + // eventually hide unsorted channels + if (mode == UnsortedChannelMode.Delete) + return "Z" + channel.RecordIndex.ToString("d5"); + + // eventually append in old order + if (mode == UnsortedChannelMode.AppendInOrder) + return "B" + channel.OldProgramNr.ToString("d5"); + + // sort alphabetically, with "." and "" on the bottom + if (channel.Name == ".") + return "B"; + if (channel.Name == "") + return "C"; + return "A" + channel.Name; + } + + #endregion + + #region ValidateAfterSave() public virtual void ValidateAfterSave() { diff --git a/source/ChanSort.Loader.Panasonic/Serializer.cs b/source/ChanSort.Loader.Panasonic/Serializer.cs index 7ec32a5..10ff2d2 100644 --- a/source/ChanSort.Loader.Panasonic/Serializer.cs +++ b/source/ChanSort.Loader.Panasonic/Serializer.cs @@ -98,15 +98,14 @@ namespace ChanSort.Loader.Panasonic if (cypherMode == CypherMode.None) return this.FileName; - var tempFile = this.FileName + ".tmp"; - File.Delete(tempFile); - this.DeleteOnExit(tempFile); + this.TempPath = Path.GetTempFileName(); + this.DeleteTempPath(); if (cypherMode == CypherMode.Encryption) - this.CypherFile(this.FileName, tempFile, false); + this.CypherFile(this.FileName, this.TempPath, false); else - this.RemoveHeader(this.FileName, tempFile); - return tempFile; + this.RemoveHeader(this.FileName, this.TempPath); + return this.TempPath; } #endregion diff --git a/source/ChanSort.Loader.Samsung/ScmSerializer.cs b/source/ChanSort.Loader.Samsung/ScmSerializer.cs index bac5741..aa3a7fc 100644 --- a/source/ChanSort.Loader.Samsung/ScmSerializer.cs +++ b/source/ChanSort.Loader.Samsung/ScmSerializer.cs @@ -105,33 +105,33 @@ namespace ChanSort.Loader.Samsung #region Load() public override void Load() { - var tempDir = this.UnzipFileToTempFolder(); + this.UnzipFileToTempFolder(); - DetectModelConstants(tempDir); + DetectModelConstants(this.TempPath); Features.SupportedFavorites = c.supportedFavorites; Features.SortedFavorites = c.SortedFavorites == FavoritesIndexMode.IndividuallySorted; - ReadAnalogFineTuning(tempDir); - ReadAnalogChannels(tempDir, "map-AirA", this.avbtChannels, out this.avbtFileContent, this.avbtFrequency); - ReadAnalogChannels(tempDir, "map-CableA", this.avbcChannels, out this.avbcFileContent, this.avbcFrequency); - ReadAnalogChannels(tempDir, "map-AirCableMixedA", this.avbxChannels, out this.avbxFileContent, this.avbcFrequency); - ReadDvbTransponderFrequenciesFromPtc(tempDir, "PTCAIR", this.dvbtFrequency); - ReadDvbServiceProviders(tempDir); - ReadDvbctChannels(tempDir, "map-AirD", this.dvbtChannels, out this.dvbtFileContent, this.dvbtFrequency); - ReadDvbTransponderFrequenciesFromPtc(tempDir, "PTCCABLE", this.dvbcFrequency); - ReadDvbctChannels(tempDir, "map-CableD", this.dvbcChannels, out this.dvbcFileContent, this.dvbcFrequency); - ReadDvbctChannels(tempDir, "map-AirCableMixedD", this.dvbxChannels, out this.dvbxFileContent, this.dvbcFrequency); - ReadDvbctChannels(tempDir, "map-CablePrime_D", this.primeChannels, out this.primeFileContent, this.dvbcFrequency); - ReadDvbctChannels(tempDir, "map-FreesatD", this.freesatChannels, out this.freesatFileContent, this.dvbcFrequency); - ReadDvbctChannels(tempDir, "map-TivusatD", this.tivusatChannels, out this.tivusatFileContent, this.dvbcFrequency); - ReadDvbctChannels(tempDir, "map-CanalDigitalSatD", this.canalDigitalChannels, out this.canalDigitalFileContent, this.dvbcFrequency); - ReadDvbctChannels(tempDir, "map-DigitalPlusD", this.digitalPlusChannels, out this.digitalPlusFileContent, this.dvbcFrequency); - ReadSatellites(tempDir); - ReadTransponder(tempDir, "UserTransponderDataBase.dat"); // read user data first so it has priority over overridden default transponsers - ReadTransponder(tempDir, "TransponderDataBase.dat"); - ReadDvbsChannels(tempDir, "map-SateD", this.dvbsChannels, out this.dvbsFileContent, c.dvbsChannelLength); - ReadDvbsChannels(tempDir, "map-CyfraPlusD", this.cyfraPlusChannels, out this.cyfraPlusFileContent, c.cyfraPlusChannelSize); - ReadAstraHdPlusChannels(tempDir); + ReadAnalogFineTuning(this.TempPath); + ReadAnalogChannels(this.TempPath, "map-AirA", this.avbtChannels, out this.avbtFileContent, this.avbtFrequency); + ReadAnalogChannels(this.TempPath, "map-CableA", this.avbcChannels, out this.avbcFileContent, this.avbcFrequency); + ReadAnalogChannels(this.TempPath, "map-AirCableMixedA", this.avbxChannels, out this.avbxFileContent, this.avbcFrequency); + ReadDvbTransponderFrequenciesFromPtc(this.TempPath, "PTCAIR", this.dvbtFrequency); + ReadDvbServiceProviders(this.TempPath); + ReadDvbctChannels(this.TempPath, "map-AirD", this.dvbtChannels, out this.dvbtFileContent, this.dvbtFrequency); + ReadDvbTransponderFrequenciesFromPtc(this.TempPath, "PTCCABLE", this.dvbcFrequency); + ReadDvbctChannels(this.TempPath, "map-CableD", this.dvbcChannels, out this.dvbcFileContent, this.dvbcFrequency); + ReadDvbctChannels(this.TempPath, "map-AirCableMixedD", this.dvbxChannels, out this.dvbxFileContent, this.dvbcFrequency); + ReadDvbctChannels(this.TempPath, "map-CablePrime_D", this.primeChannels, out this.primeFileContent, this.dvbcFrequency); + ReadDvbctChannels(this.TempPath, "map-FreesatD", this.freesatChannels, out this.freesatFileContent, this.dvbcFrequency); + ReadDvbctChannels(this.TempPath, "map-TivusatD", this.tivusatChannels, out this.tivusatFileContent, this.dvbcFrequency); + ReadDvbctChannels(this.TempPath, "map-CanalDigitalSatD", this.canalDigitalChannels, out this.canalDigitalFileContent, this.dvbcFrequency); + ReadDvbctChannels(this.TempPath, "map-DigitalPlusD", this.digitalPlusChannels, out this.digitalPlusFileContent, this.dvbcFrequency); + ReadSatellites(this.TempPath); + ReadTransponder(this.TempPath, "UserTransponderDataBase.dat"); // read user data first so it has priority over overridden default transponsers + ReadTransponder(this.TempPath, "TransponderDataBase.dat"); + ReadDvbsChannels(this.TempPath, "map-SateD", this.dvbsChannels, out this.dvbsFileContent, c.dvbsChannelLength); + ReadDvbsChannels(this.TempPath, "map-CyfraPlusD", this.cyfraPlusChannels, out this.cyfraPlusFileContent, c.cyfraPlusChannelSize); + ReadAstraHdPlusChannels(this.TempPath); foreach (var list in this.DataRoot.ChannelLists) @@ -630,7 +630,7 @@ namespace ChanSort.Loader.Samsung #region Save() public override void Save(string tvOutputFile) { - string zip = this.FileName + ".tmp"; + string zip = this.TempPath; this.SaveChannels(zip, "map-AirA", this.avbtChannels, this.avbtFileContent); this.SaveChannels(zip, "map-CableA", this.avbcChannels, this.avbcFileContent); this.SaveChannels(zip, "map-AirCableMixedA", this.avbxChannels, this.avbxFileContent); diff --git a/source/ChanSort.Loader.SamsungJ/DbSerializer.cs b/source/ChanSort.Loader.SamsungJ/DbSerializer.cs index 7e7dca5..923fc39 100644 --- a/source/ChanSort.Loader.SamsungJ/DbSerializer.cs +++ b/source/ChanSort.Loader.SamsungJ/DbSerializer.cs @@ -16,7 +16,6 @@ namespace ChanSort.Loader.SamsungJ { private readonly Dictionary channelById = new Dictionary(); private readonly Dictionary dbPathByChannelList = new Dictionary(); - private string tempDir; private enum FileType { Unknown, SatDb, ChannelDbDvb, ChannelDbAnalog } @@ -39,12 +38,12 @@ namespace ChanSort.Loader.SamsungJ { try { - this.tempDir = this.UnzipFileToTempFolder(); - if (File.Exists(tempDir + "\\sat")) + this.UnzipFileToTempFolder(); + if (File.Exists(this.TempPath + "\\sat")) { try { - using (var conn = new SQLiteConnection("Data Source=" + tempDir + "\\sat")) + using (var conn = new SQLiteConnection("Data Source=" + this.TempPath + "\\sat")) { conn.Open(); this.ReadSatDatabase(conn); @@ -55,7 +54,7 @@ namespace ChanSort.Loader.SamsungJ } } - var files = Directory.GetFiles(tempDir, "*."); + var files = Directory.GetFiles(this.TempPath, "*."); if (files.Length == 0) throw new FileLoadException("The Samsung .zip channel list archive does not contain any supported files."); diff --git a/source/ChanSort.Loader.Toshiba/DbSerializer.cs b/source/ChanSort.Loader.Toshiba/DbSerializer.cs index 797623e..6188604 100644 --- a/source/ChanSort.Loader.Toshiba/DbSerializer.cs +++ b/source/ChanSort.Loader.Toshiba/DbSerializer.cs @@ -7,9 +7,9 @@ namespace ChanSort.Loader.Toshiba { class DbSerializer : SerializerBase { - private const string FILE_chmgt_db = "chmgt_type001\\chmgt.db"; - private const string FILE_dvbSysData_db = "dvb_type001\\dvbSysData.db"; - private const string FILE_dvbMainData_db = "dvb_type001\\dvbMainData.db"; + private const string FILE_chmgt_db = "\\chmgt_type001\\chmgt.db"; + private const string FILE_dvbSysData_db = "\\dvb_type001\\dvbSysData.db"; + private const string FILE_dvbMainData_db = "\\dvb_type001\\dvbMainData.db"; private readonly ChannelList atvChannels = new ChannelList(SignalSource.AnalogCT, "Analog"); private readonly ChannelList dtvTvChannels = new ChannelList(SignalSource.DvbCT | SignalSource.Tv, "DTV"); @@ -18,8 +18,6 @@ namespace ChanSort.Loader.Toshiba private readonly ChannelList satRadioChannels = new ChannelList(SignalSource.DvbS | SignalSource.Radio, "Sat-Radio"); private readonly Dictionary channelInfoByUid = new Dictionary(); - private string tempDir; - #region ctor() public DbSerializer(string inputFile) : base(inputFile) { @@ -39,9 +37,9 @@ namespace ChanSort.Loader.Toshiba #region Load() public override void Load() { - this.tempDir = this.UnzipFileToTempFolder() + "\\"; + this.UnzipFileToTempFolder(); - string sysDataConnString = "Data Source=" + tempDir + FILE_dvbSysData_db; + string sysDataConnString = "Data Source=" + this.TempPath + FILE_dvbSysData_db; using (var conn = new SQLiteConnection(sysDataConnString)) { conn.Open(); @@ -53,7 +51,7 @@ namespace ChanSort.Loader.Toshiba } } - string mainDataConnString = "Data Source=" + tempDir + FILE_dvbMainData_db; + string mainDataConnString = "Data Source=" + this.TempPath + FILE_dvbMainData_db; using (var conn = new SQLiteConnection(mainDataConnString)) { conn.Open(); @@ -63,7 +61,7 @@ namespace ChanSort.Loader.Toshiba } } - string channelConnString = "Data Source=" + tempDir + FILE_chmgt_db; + string channelConnString = "Data Source=" + this.TempPath + FILE_chmgt_db; using (var conn = new SQLiteConnection(channelConnString)) { conn.Open(); @@ -236,7 +234,7 @@ namespace ChanSort.Loader.Toshiba #region Save() public override void Save(string tvOutputFile) { - string channelConnString = "Data Source=" + this.tempDir + FILE_chmgt_db; + string channelConnString = "Data Source=" + this.TempPath + FILE_chmgt_db; using (var conn = new SQLiteConnection(channelConnString)) { conn.Open(); diff --git a/source/ChanSort/MainForm.cs b/source/ChanSort/MainForm.cs index 16f4d13..0ac3027 100644 --- a/source/ChanSort/MainForm.cs +++ b/source/ChanSort/MainForm.cs @@ -498,9 +498,10 @@ namespace ChanSort.Ui var errorMsgs = new StringBuilder(); foreach (var plugin in candidates) { + SerializerBase serializer = null; try { - var serializer = plugin.CreateSerializer(inputFileName); + serializer = plugin.CreateSerializer(inputFileName); if (serializer != null) { serializer.DefaultEncoding = this.defaultEncoding; @@ -511,6 +512,7 @@ namespace ChanSort.Ui } catch (Exception ex) { + serializer?.Dispose(); errorMsgs.AppendLine($"{plugin.DllName} ({plugin.PluginName}): {ex}\n\n"); if (ex is ArgumentException) { @@ -551,6 +553,8 @@ namespace ChanSort.Ui if (!this.PromptSaveAndContinue()) return false; + this.currentTvSerializer?.Dispose(); + serializer.DataRoot.ValidateAfterLoad(); this.SetFileName(tvDataFile); this.currentPlugin = plugin; @@ -795,7 +799,7 @@ namespace ChanSort.Ui { foreach (var channel in list.Channels) { - if (channel.NewProgramNr < 0 && (!channel.IsDeleted /* || DataRoot.DeletedChannelsNeedNumbers */)) + if (channel.NewProgramNr < 0 && !channel.IsDeleted) { hasUnsorted = true; break; @@ -812,7 +816,7 @@ namespace ChanSort.Ui using (var dlg = new ActionBoxDialog(msg)) { dlg.AddAction(Resources.MainForm_PromptHandlingOfUnsortedChannels_Append, DialogResult.Yes, dlg.FullList); - if (this.currentTvSerializer.Features.CanDeleteChannelsWithFlag || this.currentTvSerializer.Features.CanDeleteChannelsFromFile) + if (this.currentTvSerializer.Features.DeleteMode != SerializerBase.DeleteMode.NotSupported) dlg.AddAction(Resources.MainForm_PromptHandlingOfUnsortedChannels_Delete, DialogResult.No, dlg.Delete); dlg.AddAction(Resources.MainForm_Cancel, DialogResult.Cancel, dlg.Cancel); res = dlg.ShowDialog(this); @@ -825,7 +829,7 @@ namespace ChanSort.Ui } // ensure unsorted and deleted channels have a valid program number - this.Editor.AutoNumberingForUnassignedChannels(mode); + this.DataRoot.AssignNumbersToUnsortedAndDeletedChannels(mode); return true; } @@ -2543,7 +2547,10 @@ namespace ChanSort.Ui try { if (this.PromptSaveAndContinue()) + { this.SaveSettings(); + this.currentTvSerializer?.Dispose(); + } else e.Cancel = true; } diff --git a/source/ChanSort/MainForm.resx b/source/ChanSort/MainForm.resx index 35469bf..008beee 100644 --- a/source/ChanSort/MainForm.resx +++ b/source/ChanSort/MainForm.resx @@ -1246,7 +1246,7 @@ globalImageCollection1 - ChanSort.Ui.GlobalImageCollection, ChanSort, Version=1.0.7248.39737, Culture=neutral, PublicKeyToken=null + ChanSort.Ui.GlobalImageCollection, ChanSort, Version=1.0.7251.34158, Culture=neutral, PublicKeyToken=null gviewRight @@ -1933,7 +1933,7 @@ DevExpress.XtraEditors.XtraForm, DevExpress.Utils.v19.2, Version=19.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a - 11/05/2019 22:23:13 + 11/08/2019 19:29:15 16, 16 diff --git a/source/ChanSort/ReferenceListForm.Designer.cs b/source/ChanSort/ReferenceListForm.Designer.cs index 57ba8c4..f4e28b5 100644 --- a/source/ChanSort/ReferenceListForm.Designer.cs +++ b/source/ChanSort/ReferenceListForm.Designer.cs @@ -7,19 +7,6 @@ /// private System.ComponentModel.IContainer components = null; - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - #region Windows Form Designer generated code /// diff --git a/source/ChanSort/ReferenceListForm.cs b/source/ChanSort/ReferenceListForm.cs index a47f350..c522745 100644 --- a/source/ChanSort/ReferenceListForm.cs +++ b/source/ChanSort/ReferenceListForm.cs @@ -27,6 +27,16 @@ namespace ChanSort.Ui this.UpdateButtons(); } + protected override void Dispose(bool disposing) + { + if (disposing) + { + this.components?.Dispose(); + this.serializer.Dispose(); + } + base.Dispose(disposing); + } + #region UpdateButtons() private void UpdateButtons() { @@ -91,6 +101,8 @@ namespace ChanSort.Ui #region SetInput() private void SetInput(SerializerBase ser) { + this.serializer?.Dispose(); + this.serializer = ser; this.edFile.Text = serializer.FileName; this.rbAuto.Enabled = this.rbManual.Enabled = true; diff --git a/source/Test.Loader.GlobalClone/LgGlobalCloneTest.cs b/source/Test.Loader.GlobalClone/LgGlobalCloneTest.cs index d80b2a7..59a69ee 100644 --- a/source/Test.Loader.GlobalClone/LgGlobalCloneTest.cs +++ b/source/Test.Loader.GlobalClone/LgGlobalCloneTest.cs @@ -83,9 +83,7 @@ namespace Test.Loader.GlobalClone Assert.IsFalse(orf2w.IsDeleted); orf2w.NewProgramNr = -1; - var editor = new Editor(); - editor.DataRoot = data; - editor.AutoNumberingForUnassignedChannels(UnsortedChannelMode.Delete); + data.AssignNumbersToUnsortedAndDeletedChannels(UnsortedChannelMode.Delete); Assert.IsTrue(orf2w.IsDeleted); Assert.AreNotEqual(-1, orf2w.NewProgramNr); diff --git a/source/Test.Loader.Hisense/HisenseChannelDbTest.cs b/source/Test.Loader.Hisense/HisenseChannelDbTest.cs index 4829547..094cbaa 100644 --- a/source/Test.Loader.Hisense/HisenseChannelDbTest.cs +++ b/source/Test.Loader.Hisense/HisenseChannelDbTest.cs @@ -72,9 +72,7 @@ namespace Test.Loader.Hisense Assert.IsFalse(orf2e.IsDeleted); orf2e.NewProgramNr = -1; - var editor = new Editor(); - editor.DataRoot = data; - editor.AutoNumberingForUnassignedChannels(UnsortedChannelMode.AppendInOrder); + data.AssignNumbersToUnsortedAndDeletedChannels(UnsortedChannelMode.AppendInOrder); Assert.IsFalse(orf2e.IsDeleted); Assert.IsTrue(orf2e.NewProgramNr > 0); diff --git a/source/Test.Loader.Hisense2017/HisenseServicelistDbTest.cs b/source/Test.Loader.Hisense2017/HisenseServicelistDbTest.cs index 686bee7..7e96bbc 100644 --- a/source/Test.Loader.Hisense2017/HisenseServicelistDbTest.cs +++ b/source/Test.Loader.Hisense2017/HisenseServicelistDbTest.cs @@ -71,9 +71,7 @@ namespace Test.Loader.Hisense2017 Assert.IsFalse(orf2e.IsDeleted); orf2e.NewProgramNr = -1; - var editor = new Editor(); - editor.DataRoot = data; - editor.AutoNumberingForUnassignedChannels(UnsortedChannelMode.Delete); + data.AssignNumbersToUnsortedAndDeletedChannels(UnsortedChannelMode.Delete); Assert.IsTrue(orf2e.IsDeleted); Assert.IsTrue(orf2e.NewProgramNr > 0); diff --git a/source/Test.Loader.LG/LM/TestLM.cs b/source/Test.Loader.LG/LM/TestLM.cs index 660bb1b..bb7df25 100644 --- a/source/Test.Loader.LG/LM/TestLM.cs +++ b/source/Test.Loader.LG/LM/TestLM.cs @@ -62,9 +62,7 @@ namespace Test.Loader.LG Assert.IsFalse(orf2.IsDeleted); orf2.NewProgramNr = -1; - var editor = new Editor(); - editor.DataRoot = data; - editor.AutoNumberingForUnassignedChannels(UnsortedChannelMode.Delete); + data.AssignNumbersToUnsortedAndDeletedChannels(UnsortedChannelMode.Delete); Assert.IsTrue(orf2.IsDeleted); Assert.AreEqual(0, orf2.NewProgramNr); diff --git a/source/Test.Loader.Panasonic/PanasonicSvlTest.cs b/source/Test.Loader.Panasonic/PanasonicSvlTest.cs index d87be03..10fb3b6 100644 --- a/source/Test.Loader.Panasonic/PanasonicSvlTest.cs +++ b/source/Test.Loader.Panasonic/PanasonicSvlTest.cs @@ -72,9 +72,7 @@ namespace Test.Loader.Panasonic Assert.IsFalse(orf2e.IsDeleted); orf2e.NewProgramNr = -1; - var editor = new Editor(); - editor.DataRoot = data; - editor.AutoNumberingForUnassignedChannels(UnsortedChannelMode.Delete); + data.AssignNumbersToUnsortedAndDeletedChannels(UnsortedChannelMode.Delete); Assert.IsTrue(orf2e.IsDeleted); Assert.IsTrue(orf2e.NewProgramNr == 0); diff --git a/source/Test.Loader.PhilipsXml/PhilipsXmlTest.cs b/source/Test.Loader.PhilipsXml/PhilipsXmlTest.cs index 1cdc1ab..bdab13f 100644 --- a/source/Test.Loader.PhilipsXml/PhilipsXmlTest.cs +++ b/source/Test.Loader.PhilipsXml/PhilipsXmlTest.cs @@ -80,9 +80,7 @@ namespace Test.Loader.PhilipsXml Assert.IsFalse(ntvHd.IsDeleted); ntvHd.NewProgramNr = -1; - var editor = new Editor(); - editor.DataRoot = data; - editor.AutoNumberingForUnassignedChannels(UnsortedChannelMode.Delete); + data.AssignNumbersToUnsortedAndDeletedChannels(UnsortedChannelMode.Delete); Assert.IsTrue(ntvHd.IsDeleted); Assert.IsTrue(ntvHd.NewProgramNr == 0); diff --git a/source/Test.Loader.Samsung/SamsungTest.cs b/source/Test.Loader.Samsung/SamsungTest.cs index 6c2e4dc..ae762a5 100644 --- a/source/Test.Loader.Samsung/SamsungTest.cs +++ b/source/Test.Loader.Samsung/SamsungTest.cs @@ -166,9 +166,7 @@ namespace Test.Loader.Samsung Assert.IsFalse(orf2w.IsDeleted); orf2w.NewProgramNr = -1; - var editor = new Editor(); - editor.DataRoot = data; - editor.AutoNumberingForUnassignedChannels(UnsortedChannelMode.Delete); + data.AssignNumbersToUnsortedAndDeletedChannels(UnsortedChannelMode.Delete); Assert.IsTrue(orf2w.IsDeleted); Assert.AreNotEqual(-1, orf2w.NewProgramNr); @@ -218,9 +216,7 @@ namespace Test.Loader.Samsung Assert.IsFalse(orf2w.IsDeleted); orf2w.NewProgramNr = -1; - var editor = new Editor(); - editor.DataRoot = data; - editor.AutoNumberingForUnassignedChannels(UnsortedChannelMode.Delete); + data.AssignNumbersToUnsortedAndDeletedChannels(UnsortedChannelMode.Delete); Assert.IsTrue(orf2w.IsDeleted); Assert.AreNotEqual(-1, orf2w.NewProgramNr); diff --git a/source/Test.Loader.Samsung/Test.Loader.Samsung.csproj b/source/Test.Loader.Samsung/Test.Loader.Samsung.csproj index 9eded4a..f5caeae 100644 --- a/source/Test.Loader.Samsung/Test.Loader.Samsung.csproj +++ b/source/Test.Loader.Samsung/Test.Loader.Samsung.csproj @@ -54,9 +54,6 @@ MinimumRecommendedRules.ruleset - - ..\DLL\ICSharpCode.SharpZipLib.dll - diff --git a/source/Test.Loader.SamsungJ/SamsungZipTest.cs b/source/Test.Loader.SamsungJ/SamsungZipTest.cs index 9cb2980..725d291 100644 --- a/source/Test.Loader.SamsungJ/SamsungZipTest.cs +++ b/source/Test.Loader.SamsungJ/SamsungZipTest.cs @@ -85,9 +85,7 @@ namespace Test.Loader.SamsungJ Assert.IsFalse(orf2e.IsDeleted); orf2e.NewProgramNr = -1; - var editor = new Editor(); - editor.DataRoot = data; - editor.AutoNumberingForUnassignedChannels(UnsortedChannelMode.Delete); + data.AssignNumbersToUnsortedAndDeletedChannels(UnsortedChannelMode.Delete); Assert.IsTrue(orf2e.IsDeleted); Assert.AreNotEqual(-1, orf2e.NewProgramNr); diff --git a/source/Test.Loader.SilvaSchneider/SdxTest.cs b/source/Test.Loader.SilvaSchneider/SdxTest.cs index 2131b9d..4796e80 100644 --- a/source/Test.Loader.SilvaSchneider/SdxTest.cs +++ b/source/Test.Loader.SilvaSchneider/SdxTest.cs @@ -66,9 +66,7 @@ namespace Test.Loader.SilvaSchneider Assert.IsFalse(orf2e.IsDeleted); orf2e.NewProgramNr = -1; - var editor = new Editor(); - editor.DataRoot = data; - editor.AutoNumberingForUnassignedChannels(UnsortedChannelMode.Delete); + data.AssignNumbersToUnsortedAndDeletedChannels(UnsortedChannelMode.Delete); Assert.IsTrue(orf2e.IsDeleted); Assert.IsTrue(orf2e.NewProgramNr == 0); diff --git a/source/Test.Loader.Sony/SonyXmlTest.cs b/source/Test.Loader.Sony/SonyXmlTest.cs index 779d5e2..d12a116 100644 --- a/source/Test.Loader.Sony/SonyXmlTest.cs +++ b/source/Test.Loader.Sony/SonyXmlTest.cs @@ -102,9 +102,7 @@ namespace Test.Loader.Sony Assert.IsFalse(orf2e.IsDeleted); orf2e.NewProgramNr = -1; - var editor = new Editor(); - editor.DataRoot = data; - editor.AutoNumberingForUnassignedChannels(UnsortedChannelMode.Delete); + data.AssignNumbersToUnsortedAndDeletedChannels(UnsortedChannelMode.Delete); Assert.IsTrue(orf2e.IsDeleted); Assert.IsTrue(orf2e.NewProgramNr > 0); @@ -151,9 +149,7 @@ namespace Test.Loader.Sony Assert.IsFalse(orf2e.IsDeleted); orf2e.NewProgramNr = -1; - var editor = new Editor(); - editor.DataRoot = data; - editor.AutoNumberingForUnassignedChannels(UnsortedChannelMode.Delete); + data.AssignNumbersToUnsortedAndDeletedChannels(UnsortedChannelMode.Delete); Assert.IsTrue(orf2e.IsDeleted); Assert.IsTrue(orf2e.NewProgramNr == 0); diff --git a/source/Test.Loader.Toshiba/ToshibaChmgtDbTest.cs b/source/Test.Loader.Toshiba/ToshibaChmgtDbTest.cs index 213cc9b..38161b6 100644 --- a/source/Test.Loader.Toshiba/ToshibaChmgtDbTest.cs +++ b/source/Test.Loader.Toshiba/ToshibaChmgtDbTest.cs @@ -89,9 +89,7 @@ namespace Test.Loader.Toshiba Assert.IsFalse(orf2e.IsDeleted); orf2e.NewProgramNr = -1; - var editor = new Editor(); - editor.DataRoot = data; - editor.AutoNumberingForUnassignedChannels(UnsortedChannelMode.Delete); + data.AssignNumbersToUnsortedAndDeletedChannels(UnsortedChannelMode.Delete); Assert.IsTrue(orf2e.IsDeleted); Assert.IsTrue(orf2e.NewProgramNr == 0); diff --git a/source/Test.Loader.VDR/LinuxVdrTest.cs b/source/Test.Loader.VDR/LinuxVdrTest.cs index 7aaed8d..b4103a7 100644 --- a/source/Test.Loader.VDR/LinuxVdrTest.cs +++ b/source/Test.Loader.VDR/LinuxVdrTest.cs @@ -60,9 +60,7 @@ namespace Test.Loader.VDR Assert.IsFalse(orf2e.IsDeleted); orf2e.NewProgramNr = -1; - var editor = new Editor(); - editor.DataRoot = data; - editor.AutoNumberingForUnassignedChannels(UnsortedChannelMode.Delete); + data.AssignNumbersToUnsortedAndDeletedChannels(UnsortedChannelMode.Delete); Assert.IsTrue(orf2e.IsDeleted); Assert.IsTrue(orf2e.NewProgramNr == 0); diff --git a/source/makeDistribZip.cmd b/source/makeDistribZip.cmd index 1ed062e..2c4124b 100644 --- a/source/makeDistribZip.cmd +++ b/source/makeDistribZip.cmd @@ -2,7 +2,7 @@ cd /d %~dp0 set curdate=%date:~6,4%-%date:~3,2%-%date:~0,2% set target=%cd%\..\..\ChanSort_%curdate% -set DXversion=19.1 +set DXversion=19.2 mkdir "%target%" 2>nul del /s /q "%target%\*" copy debug\ChanSort.exe* "%target%"