mirror of
https://github.com/PredatH0r/ChanSort.git
synced 2026-01-16 04:12:03 +01:00
- reworked UI
- fixed various issues with incorrect selection and program# assignment
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
public readonly int lnbCount;
|
||||
public readonly int lnbLength;
|
||||
public readonly int[] dvbsSubblockLength;
|
||||
public readonly int dvbsBlockTotalLength;
|
||||
|
||||
public int LnbBlockHeaderSize = 12;
|
||||
|
||||
@@ -36,6 +37,9 @@
|
||||
12 + dvbsMaxChannelCount/8 + dvbsMaxChannelCount*sizeOfChannelLinkedListEntry + dvbsMaxChannelCount * dvbsChannelLength, // channels
|
||||
LnbBlockHeaderSize - 4 + lnbCount * lnbLength // sat/LNB-Config
|
||||
};
|
||||
|
||||
foreach (int len in this.dvbsSubblockLength)
|
||||
this.dvbsBlockTotalLength += len + 4;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
9
ChanSort.Loader.TllFile/Resource.Designer.cs
generated
9
ChanSort.Loader.TllFile/Resource.Designer.cs
generated
@@ -95,14 +95,5 @@ namespace ChanSort.Loader.TllFile {
|
||||
return ResourceManager.GetString("TllFileSerializerPlugin_ERR_modelUnknown", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to LG-Electronics *.tll Loader.
|
||||
/// </summary>
|
||||
internal static string TllFileSerializerPlugin_PluginName {
|
||||
get {
|
||||
return ResourceManager.GetString("TllFileSerializerPlugin_PluginName", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,9 +126,6 @@
|
||||
<data name="TllFileSerializerPlugin_ERR_fileTooBig" xml:space="preserve">
|
||||
<value>Dateigröße {0} überschreitet das erlaubte Maximum von {1}</value>
|
||||
</data>
|
||||
<data name="TllFileSerializerPlugin_PluginName" xml:space="preserve">
|
||||
<value>LG-Electronics *.tll Loader</value>
|
||||
</data>
|
||||
<data name="TllFileSerializer_ERR_dupeChannel" xml:space="preserve">
|
||||
<value>Sender #{0} (Pr# {1}) wurde gelöscht da er ein Duplikat von Sender #{2} (Pr# {3}) ist: {4}</value>
|
||||
</data>
|
||||
|
||||
@@ -107,9 +107,6 @@
|
||||
<data name="TllFileSerializerPlugin_ERR_fileTooBig" xml:space="preserve">
|
||||
<value>File size {0} is larger than allowed maxiumum of {1}</value>
|
||||
</data>
|
||||
<data name="TllFileSerializerPlugin_PluginName" xml:space="preserve">
|
||||
<value>LG-Electronics *.tll Loader</value>
|
||||
</data>
|
||||
<data name="TllFileSerializer_ERR_dupeChannel" xml:space="preserve">
|
||||
<value>Channel #{0} (Pr# {1}) was erased because it is a duplicate of channel #{2} (Pr# {3}): {4}</value>
|
||||
</data>
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace ChanSort.Loader.TllFile
|
||||
{
|
||||
public partial class TllFileSerializer : SerializerBase
|
||||
{
|
||||
private const long DVBS_S2 = 0x0032532D53425644; // reverse of "DVBS-S2\0"
|
||||
private const long MaxFileSize = 2000000;
|
||||
private readonly string ERR_fileTooBig = Resource.TllFileSerializerPlugin_ERR_fileTooBig;
|
||||
private readonly string ERR_modelUnknown = Resource.TllFileSerializerPlugin_ERR_modelUnknown;
|
||||
@@ -83,8 +84,6 @@ namespace ChanSort.Loader.TllFile
|
||||
this.DataRoot.AddChannelList(atvChannels);
|
||||
this.DataRoot.AddChannelList(dtvChannels);
|
||||
this.DataRoot.AddChannelList(radioChannels);
|
||||
this.DataRoot.AddChannelList(satTvChannels);
|
||||
this.DataRoot.AddChannelList(satRadioChannels);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -123,7 +122,7 @@ namespace ChanSort.Loader.TllFile
|
||||
{
|
||||
long fileSize = new FileInfo(this.FileName).Length;
|
||||
if (fileSize > MaxFileSize)
|
||||
throw new InvalidOperationException(string.Format(ERR_fileTooBig, fileSize, MaxFileSize));
|
||||
throw new FileLoadException(string.Format(ERR_fileTooBig, fileSize, MaxFileSize));
|
||||
|
||||
this.fileContent = File.ReadAllBytes(this.FileName);
|
||||
int off = 0;
|
||||
@@ -146,7 +145,7 @@ namespace ChanSort.Loader.TllFile
|
||||
private void ReadFileHeader(ref int off)
|
||||
{
|
||||
if (fileContent.Length < 4)
|
||||
throw new InvalidOperationException(ERR_modelUnknown);
|
||||
throw new FileLoadException(ERR_modelUnknown);
|
||||
if (BitConverter.ToUInt32(fileContent, off) == 0x5A5A5A5A)
|
||||
off += 4;
|
||||
}
|
||||
@@ -184,7 +183,7 @@ namespace ChanSort.Loader.TllFile
|
||||
private void ReadDvbSBlock(ref int off)
|
||||
{
|
||||
int blockSize;
|
||||
if (!IsDvbsBlock(off, out blockSize))
|
||||
if (!IsDvbsBlock(ref off, out blockSize))
|
||||
return;
|
||||
|
||||
this.dvbsBlockSize = blockSize;
|
||||
@@ -259,7 +258,7 @@ namespace ChanSort.Loader.TllFile
|
||||
{
|
||||
long len = BitConverter.ToUInt32(fileContent, off);
|
||||
if (len < minSize || off + 4 + len > fileContent.Length)
|
||||
throw new InvalidOperationException(ERR_modelUnknown);
|
||||
throw new FileLoadException(ERR_modelUnknown);
|
||||
return (int)len;
|
||||
}
|
||||
#endregion
|
||||
@@ -268,17 +267,17 @@ namespace ChanSort.Loader.TllFile
|
||||
private int GetActChannelRecordSize(int off, int blockSize, int channelCount)
|
||||
{
|
||||
if ((blockSize - 4) % channelCount != 0)
|
||||
throw new InvalidOperationException(ERR_modelUnknown);
|
||||
throw new FileLoadException(ERR_modelUnknown);
|
||||
int recordSize = (blockSize - 4) / channelCount;
|
||||
if (off + channelCount * recordSize > fileContent.Length)
|
||||
throw new InvalidOperationException(ERR_modelUnknown);
|
||||
throw new FileLoadException(ERR_modelUnknown);
|
||||
return recordSize;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region IsDvbsBlock()
|
||||
private bool IsDvbsBlock(int off, out int blockSize)
|
||||
private bool IsDvbsBlock(ref int off, out int blockSize)
|
||||
{
|
||||
blockSize = 0;
|
||||
if (off >= fileContent.Length)
|
||||
@@ -286,16 +285,30 @@ namespace ChanSort.Loader.TllFile
|
||||
blockSize = this.GetBlockSize(off);
|
||||
if (blockSize < 12)
|
||||
return false;
|
||||
ulong blockId = BitConverter.ToUInt64(fileContent, off + 8);
|
||||
if (blockId != 0x0032532D53425644) // reverse "DVBS-S2\0"
|
||||
return false;
|
||||
return true;
|
||||
long blockId = BitConverter.ToInt64(fileContent, off + 8);
|
||||
if (blockId == DVBS_S2)
|
||||
return true;
|
||||
|
||||
if (blockId == -1)
|
||||
{
|
||||
this.satConfig = satConfigs.TryGet(blockSize);
|
||||
if (this.satConfig != null)
|
||||
{
|
||||
this.EraseDvbsBlock(off);
|
||||
this.UpdateDvbsChecksums();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ReadDvbsSubblocks()
|
||||
private void ReadDvbsSubblocks(ref int off)
|
||||
{
|
||||
this.DataRoot.AddChannelList(satTvChannels);
|
||||
this.DataRoot.AddChannelList(satRadioChannels);
|
||||
|
||||
this.ScanDvbSSubBlockChecksums(off);
|
||||
|
||||
// subblock 1 (DVBS header)
|
||||
@@ -334,7 +347,7 @@ namespace ChanSort.Loader.TllFile
|
||||
uint fileCrc = BitConverter.ToUInt32(fileContent, off);
|
||||
uint calcCrc = Crc32.CalcCrc32(fileContent, off + 4, subblockLength);
|
||||
if (fileCrc != calcCrc)
|
||||
throw new IOException(string.Format(ERR_wrongChecksum, calcCrc, fileCrc));
|
||||
throw new FileLoadException(string.Format(ERR_wrongChecksum, calcCrc, fileCrc));
|
||||
off += 4 + subblockLength;
|
||||
}
|
||||
}
|
||||
@@ -468,7 +481,84 @@ namespace ChanSort.Loader.TllFile
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region EraseDvbsBlock()
|
||||
|
||||
/// <summary>
|
||||
/// The model LM640T has the whole DVB-S2 block filled with 0xFF bytes, including the checksums.
|
||||
/// When a file (even the originally saved one) is loaded back, the TV crashes and performs a factory reset.
|
||||
/// </summary>
|
||||
private void EraseDvbsBlock(int off)
|
||||
{
|
||||
this.dvbsBlockOffset = off;
|
||||
this.dvbsBlockSize = satConfig.dvbsBlockTotalLength;
|
||||
this.dvbsSubblockCrcOffset = new int[satConfig.dvbsSubblockLength.Length];
|
||||
|
||||
int p = this.dvbsBlockOffset + 4;
|
||||
for (int i = 0; i < this.dvbsBlockSize; i++)
|
||||
this.fileContent[p++] = 0;
|
||||
|
||||
using (MemoryStream stream = new MemoryStream(this.fileContent))
|
||||
using (BinaryWriter wrt = new BinaryWriter(stream))
|
||||
{
|
||||
stream.Seek(this.dvbsBlockOffset+4, SeekOrigin.Begin); // skip length
|
||||
|
||||
// header
|
||||
this.dvbsSubblockCrcOffset[0] = (int)stream.Position;
|
||||
stream.Seek(4, SeekOrigin.Current); // skip CRC32
|
||||
stream.Write(Encoding.ASCII.GetBytes("DVBS-S2\0"), 0, 8);
|
||||
wrt.Write((ushort) 7);
|
||||
wrt.Write((ushort) 4);
|
||||
|
||||
// satellite
|
||||
this.dvbsSubblockCrcOffset[1] = (int)stream.Position;
|
||||
stream.Seek(4, SeekOrigin.Current); // skip CRC32
|
||||
stream.Seek(2 + satConfig.satCount/8 + 2 + 2 + satConfig.satCount + 2, SeekOrigin.Current);
|
||||
for (int i = 0; i < satConfig.satCount; i++)
|
||||
{
|
||||
stream.Seek(36, SeekOrigin.Current);
|
||||
wrt.Write((short) -1);
|
||||
wrt.Write((short) -1);
|
||||
stream.Seek(2 + 2, SeekOrigin.Current);
|
||||
}
|
||||
|
||||
// transponders
|
||||
this.dvbsSubblockCrcOffset[2] = (int)stream.Position;
|
||||
stream.Seek(4, SeekOrigin.Current); // skip CRC32
|
||||
stream.Seek(5*2 + satConfig.transponderCount/8, SeekOrigin.Current);
|
||||
wrt.Write((short) -1);
|
||||
wrt.Write((short) -1);
|
||||
stream.Seek(2 + (satConfig.transponderCount - 1)*6 + 2, SeekOrigin.Current);
|
||||
for (int i = 0; i < satConfig.transponderCount; i++)
|
||||
{
|
||||
wrt.Write(-1);
|
||||
wrt.Write((ushort)0);
|
||||
wrt.Write((short)-1);
|
||||
wrt.Write((byte)0xfe);
|
||||
for (int j = 9; j < satConfig.transponderLength; j++)
|
||||
wrt.Write((byte)0xFF);
|
||||
}
|
||||
|
||||
// channels
|
||||
this.dvbsSubblockCrcOffset[3] = (int)stream.Position;
|
||||
stream.Seek(4, SeekOrigin.Current); // skip CRC32
|
||||
stream.Seek(12 + satConfig.dvbsMaxChannelCount/8, SeekOrigin.Current);
|
||||
wrt.Write((short) -1);
|
||||
wrt.Write((short) -1);
|
||||
stream.Seek(4 + (satConfig.dvbsMaxChannelCount - 1)*8, SeekOrigin.Current);
|
||||
for (int i = 0; i < satConfig.dvbsMaxChannelCount*satConfig.dvbsChannelLength; i++)
|
||||
wrt.Write((byte) 0xFF);
|
||||
|
||||
// sat/LNB-config
|
||||
this.dvbsSubblockCrcOffset[4] = (int)stream.Position;
|
||||
stream.Seek(4, SeekOrigin.Current); // skip CRC32
|
||||
stream.Seek(2, SeekOrigin.Current);
|
||||
wrt.Write((byte) 1);
|
||||
stream.Seek(satConfig.lnbCount/8 - 1, SeekOrigin.Current);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Save()
|
||||
public override void Save(string tvOutputFile, string csvOutputFile)
|
||||
{
|
||||
|
||||
@@ -1,27 +1,17 @@
|
||||
using System.IO;
|
||||
using ChanSort.Api;
|
||||
using ChanSort.Api;
|
||||
|
||||
namespace ChanSort.Loader.TllFile
|
||||
{
|
||||
public class TllFileSerializerPlugin : ISerializerPlugin
|
||||
{
|
||||
private const int MAX_FILE_SIZE = 16*1000*1000;
|
||||
private readonly string ERR_fileTooBig = Resource.TllFileSerializerPlugin_ERR_fileTooBig;
|
||||
|
||||
|
||||
public string PluginName { get { return Resource.TllFileSerializerPlugin_PluginName; } }
|
||||
public string PluginName { get { return "LG-Electronics *.tll"; } }
|
||||
public string FileFilter { get { return "*.TLL"; } }
|
||||
|
||||
#region CreateSerializer()
|
||||
public SerializerBase CreateSerializer(string inputFile)
|
||||
{
|
||||
long fileSize = new FileInfo(inputFile).Length;
|
||||
if (fileSize > MAX_FILE_SIZE)
|
||||
throw new IOException(string.Format(ERR_fileTooBig, fileSize, MAX_FILE_SIZE));
|
||||
|
||||
return new TllFileSerializer(inputFile);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user