- added function to mark a channel for swapping + swap with current channel

- replaced misuse of "FileLoadException" with a custom LoaderException to handle file loading issues with better continue/fail logic
- removed "Save As" and replaced it with "Convert list" menu item that shows information on how to use a reference list instead of direct conversion
This commit is contained in:
Horst Beham
2022-11-29 14:56:23 +01:00
parent 954b44ed7a
commit 4a1a39b1e7
60 changed files with 5295 additions and 3841 deletions

View File

@@ -169,7 +169,7 @@ namespace ChanSort.Loader.Philips
}
else
{
throw new FileLoadException("Only Philips channel list format version 1.x and 25-45 are supported by this loader");
throw LoaderException.Fail("Only Philips channel list format version 1.x and 25-45 are supported by this loader");
}
// for a proper ChanSort backup/restore with .bak files, the Philips _backup.dat files must also be included
@@ -234,7 +234,7 @@ namespace ChanSort.Loader.Philips
mapping.SetDword("offChecksum", 0);
var crc = FaultyCrc32(data, mapping.BaseOffset + mapping.GetConst("offChecksum", 0), recordSize);
if (crc != checksum)
throw new FileLoadException($"Invalid CRC in record {i} in {path}");
throw LoaderException.Fail($"Invalid CRC in record {i} in {path}");
}
var ch = new Channel(list.SignalSource & SignalSource.MaskAntennaCableSat, i, progNr, channelName);
@@ -326,7 +326,7 @@ namespace ChanSort.Loader.Philips
recordSize = BitConverter.ToInt32(data, 8);
recordCount = BitConverter.ToInt32(data, 12);
if (data.Length != 20 + recordCount * recordSize)
throw new FileLoadException("Unsupported file content: " + path);
throw LoaderException.Fail("Unsupported file content: " + path);
}
else
{
@@ -336,7 +336,7 @@ namespace ChanSort.Loader.Philips
recordSize = 156; // Map45
recordCount = BitConverter.ToInt32(data, 8);
if (data.Length != 12 + recordCount * recordSize)
throw new FileLoadException("Unsupported file content: " + path);
throw LoaderException.Fail("Unsupported file content: " + path);
}
@@ -442,7 +442,7 @@ namespace ChanSort.Loader.Philips
var crcObj = new Crc32(false, Crc32.NormalPoly);
var crc = ~crcObj.CalcCrc32(data, 0, data.Length - 4);
if (checksum != crc)
throw new FileLoadException("Invalid CRC32 in " + path);
throw LoaderException.Fail("Invalid CRC32 in " + path);
}
@@ -456,7 +456,7 @@ namespace ChanSort.Loader.Philips
// 12 bytes header, then a "next/prev" table, then the service records, then a CRC32
// the "next/prev" table is a ring-list, every entry consists of 2 ushorts with the next and previous channel, wrapping around on the ends
if (data.Length != 12 + recordCount * 4 + recordCount * recordSize + 4)
throw new FileLoadException("Unsupported file content: " + path);
throw LoaderException.Fail("Unsupported file content: " + path);
}
this.dataFilePaths.Add(path);

View File

@@ -136,7 +136,7 @@ namespace ChanSort.Loader.Philips
switch (dlg.SelectedAction)
{
case 0:
throw new FileLoadException("Aborted due to checksum errors");
throw LoaderException.Fail("Aborted due to checksum errors");
}
}
}

View File

@@ -145,7 +145,7 @@ namespace ChanSort.Loader.Philips
}
if (!validList)
throw new FileLoadException(this.FileName + " is not a supported Philips Repair/channel_db_ver.db channel list");
throw LoaderException.TryNext(this.FileName + " is not a supported Philips Repair/channel_db_ver.db channel list");
foreach (var channelList in this.DataRoot.ChannelLists)
{
@@ -206,7 +206,7 @@ namespace ChanSort.Loader.Philips
var expectedChecksum = BitConverter.ToUInt16(data, offChecksum);
var actualChecksum = (UInt16)CalcChecksum(data, 0, offChecksum);
if (actualChecksum != expectedChecksum)
throw new FileLoadException($"File {path} contains invalid checksum. Expected {expectedChecksum:x4} but calculated {actualChecksum:x4}");
throw LoaderException.Fail($"File {path} contains invalid checksum. Expected {expectedChecksum:x4} but calculated {actualChecksum:x4}");
channelRecordLength = lenEntry;
@@ -302,7 +302,7 @@ namespace ChanSort.Loader.Philips
var expectedChecksum = BitConverter.ToUInt32(data, data.Length - 4);
var actualChecksum = CalcChecksum(data, 0, data.Length - 4);
if (actualChecksum != expectedChecksum)
throw new FileLoadException($"File {path} contains invalid checksum. Expected {expectedChecksum:x8} but calculated {actualChecksum:x8}");
throw LoaderException.Fail($"File {path} contains invalid checksum. Expected {expectedChecksum:x8} but calculated {actualChecksum:x8}");
var settings = this.ini.GetSection(sectionName + ":" + dbChannelRecordLength, true);
var mapping = new DataMapping(settings, data);

View File

@@ -138,7 +138,7 @@ namespace ChanSort.Loader.Philips
if (majorVersion == -1)
return new DbSerializer(inputFile);
throw new FileLoadException(majorVersion == int.MinValue ? SerializerBase.ERR_UnknownFormat : $"Philips ChannelMap format version {majorVersion} is not supported (yet).");
throw LoaderException.Fail(majorVersion == int.MinValue ? SerializerBase.ERR_UnknownFormat : $"Philips ChannelMap format version {majorVersion} is not supported (yet).");
}
}
}

View File

@@ -209,7 +209,7 @@ namespace ChanSort.Loader.Philips
this.LoadFile(fullPath);
}
if (this.fileDataList.Count == 0)
throw new FileLoadException("No XML files found in folder structure");
throw LoaderException.TryNext("No XML files found in folder structure");
}
else
{
@@ -285,7 +285,7 @@ namespace ChanSort.Loader.Philips
if (root?.LocalName == "ECSM")
root = root.FirstChild;
if (fail || root == null || (root.LocalName != "ChannelMap" && root.LocalName != "FavoriteListMAP"))
throw new FileLoadException("\"" + fileName + "\" is not a supported Philips XML file");
throw LoaderException.TryNext("\"" + fileName + "\" is not a supported Philips XML file");
int rowId = 0;
ChannelList curList = null;
@@ -312,8 +312,8 @@ namespace ChanSort.Loader.Philips
private ChannelList DetectFormatAndFeatures(FileData file, XmlNode node)
{
var setupNode = node["Setup"] ?? throw new FileLoadException("Missing Setup XML element");
var bcastNode = node["Broadcast"] ?? throw new FileLoadException("Missing Broadcast XML element");
var setupNode = node["Setup"] ?? throw LoaderException.Fail("Missing Setup XML element");
var bcastNode = node["Broadcast"] ?? throw LoaderException.Fail("Missing Broadcast XML element");
var fname = Path.GetFileNameWithoutExtension(file.path).ToLowerInvariant();
var medium = bcastNode.GetAttribute("medium");
@@ -359,7 +359,7 @@ namespace ChanSort.Loader.Philips
hasEncrypt = setupNode.HasAttribute("Scramble") || setupNode.HasAttribute("Scrambled");
}
else
throw new FileLoadException("Unknown data format");
throw LoaderException.Fail("Unknown data format");
ChannelList chList = null;
switch (medium)
@@ -420,8 +420,8 @@ namespace ChanSort.Loader.Philips
#region ReadChannel()
private void ReadChannel(FileData file, ChannelList curList, XmlNode node, int rowId)
{
var setupNode = node["Setup"] ?? throw new FileLoadException("Missing Setup XML element");
var bcastNode = node["Broadcast"] ?? throw new FileLoadException("Missing Broadcast XML element");
var setupNode = node["Setup"] ?? throw LoaderException.Fail("Missing Setup XML element");
var bcastNode = node["Broadcast"] ?? throw LoaderException.Fail("Missing Broadcast XML element");
var data = new Dictionary<string,string>(StringComparer.InvariantCultureIgnoreCase);
foreach (var n in new[] {setupNode, bcastNode})
{