mirror of
https://github.com/PredatH0r/ChanSort.git
synced 2026-01-13 19:02:05 +01:00
105 lines
3.1 KiB
C#
105 lines
3.1 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
using ChanSort.Api;
|
|
|
|
namespace ChanSort.Loader.SatcoDX
|
|
{
|
|
internal class Serializer : SerializerBase
|
|
{
|
|
private readonly ChannelList allChannels = new ChannelList(0, "All");
|
|
|
|
private byte[] content;
|
|
|
|
#region ctor()
|
|
|
|
public Serializer(string inputFile) : base(inputFile)
|
|
{
|
|
this.Features.ChannelNameEdit = ChannelNameEditMode.None;
|
|
this.Features.DeleteMode = DeleteMode.Physically;
|
|
this.Features.CanSkipChannels = false;
|
|
this.Features.CanLockChannels = false;
|
|
this.Features.CanHideChannels = false;
|
|
this.Features.SortedFavorites = false;
|
|
this.Features.SupportedFavorites = 0;
|
|
|
|
this.DataRoot.AddChannelList(this.allChannels);
|
|
|
|
// hide columns for fields that don't exist in Silva-Schneider channel list
|
|
foreach (var list in this.DataRoot.ChannelLists)
|
|
{
|
|
list.VisibleColumnFieldNames.Remove("PcrPid");
|
|
list.VisibleColumnFieldNames.Remove("VideoPid");
|
|
list.VisibleColumnFieldNames.Remove("AudioPid");
|
|
list.VisibleColumnFieldNames.Remove("Lock");
|
|
list.VisibleColumnFieldNames.Remove("Skip");
|
|
list.VisibleColumnFieldNames.Remove("Hidden");
|
|
list.VisibleColumnFieldNames.Remove("Encrypted");
|
|
list.VisibleColumnFieldNames.Remove("Favorites");
|
|
list.VisibleColumnFieldNames.Remove("ServiceType");
|
|
list.VisibleColumnFieldNames.Add("ServiceTypeName");
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Load()
|
|
|
|
public override void Load()
|
|
{
|
|
var decoder = new DvbStringDecoder(this.DefaultEncoding);
|
|
|
|
var pos = 0;
|
|
content = File.ReadAllBytes(this.FileName);
|
|
int prevPos = 0, nextPos;
|
|
while (prevPos < content.Length && (nextPos = Array.FindIndex(content, prevPos, ch => ch == (byte)'\n')) >= 0)
|
|
{
|
|
if (nextPos - prevPos == 0)
|
|
continue;
|
|
string line = Encoding.ASCII.GetString(content, prevPos, nextPos-prevPos);
|
|
ChannelInfo channel = new Channel(pos, line, content, prevPos, nextPos-prevPos, decoder);
|
|
this.DataRoot.AddChannel(this.allChannels, channel);
|
|
pos++;
|
|
prevPos = nextPos + 1;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Save()
|
|
|
|
public override void Save(string tvOutputFile)
|
|
{
|
|
if (tvOutputFile != this.FileName)
|
|
{
|
|
File.Copy(this.FileName, tvOutputFile);
|
|
this.FileName = tvOutputFile;
|
|
}
|
|
|
|
using (var file = new FileStream(tvOutputFile, FileMode.Create))
|
|
{
|
|
foreach (var channel in this.allChannels.GetChannelsByNewOrder())
|
|
{
|
|
// when a reference list was applied, the list may contain proxy entries for deleted channels, which must be ignored
|
|
if (channel.IsProxy || channel.IsDeleted)
|
|
continue;
|
|
if (channel is Channel realChannel)
|
|
file.Write(this.content, realChannel.FileOffset, realChannel.Length + 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region GetFileInformation()
|
|
|
|
public override string GetFileInformation()
|
|
{
|
|
var sb = new StringBuilder();
|
|
sb.Append(base.GetFileInformation());
|
|
return sb.ToString();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |