mirror of
https://github.com/PredatH0r/ChanSort.git
synced 2026-03-05 11:40:43 +01:00
- added unit tests for Enigma2 and Grundig loaders
- added round-trip unit test for all loaders to check reordering channels and favorites, saving and reloading - internal code clean-up regarding different favorite list modes (none vs. flags vs. ordered per source vs. mixed source)
This commit is contained in:
@@ -1,80 +1,63 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using ChanSort.Api;
|
||||
|
||||
namespace ChanSort.Loader.VDR
|
||||
{
|
||||
class Serializer : SerializerBase
|
||||
internal class Serializer : SerializerBase
|
||||
{
|
||||
private readonly ChannelList allChannels = new ChannelList(0, "All");
|
||||
|
||||
#region ctor()
|
||||
public Serializer(string inputFile) : base(inputFile)
|
||||
{
|
||||
DepencencyChecker.AssertVc2010RedistPackageX86Installed();
|
||||
Features.ChannelNameEdit = ChannelNameEditMode.None;
|
||||
Features.DeleteMode = DeleteMode.Physically;
|
||||
Features.FavoritesMode = FavoritesMode.None;
|
||||
|
||||
this.Features.ChannelNameEdit = ChannelNameEditMode.None;
|
||||
this.Features.DeleteMode = DeleteMode.Physically;
|
||||
this.Features.SortedFavorites = false;
|
||||
//this.Features.SupportedFavorites = new Favorites();
|
||||
|
||||
this.DataRoot.AddChannelList(this.allChannels);
|
||||
DataRoot.AddChannelList(allChannels);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Load()
|
||||
public override void Load()
|
||||
{
|
||||
this.ReadChannels();
|
||||
ReadChannels();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ReadChannels()
|
||||
private void ReadChannels()
|
||||
{
|
||||
string line;
|
||||
int pos = 0;
|
||||
var pos = 0;
|
||||
|
||||
using (StreamReader file = new StreamReader(this.FileName))
|
||||
{
|
||||
while ((line = file.ReadLine()) != null)
|
||||
{
|
||||
ChannelInfo channel = new Channels(pos, line, this.DataRoot);
|
||||
this.DataRoot.AddChannel(this.allChannels, channel);
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
using var file = new StreamReader(FileName);
|
||||
string line;
|
||||
while ((line = file.ReadLine()) != null)
|
||||
{
|
||||
ChannelInfo channel = new Channels(pos, line, DataRoot);
|
||||
DataRoot.AddChannel(allChannels, channel);
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Save()
|
||||
public override void Save(string tvOutputFile)
|
||||
{
|
||||
if (tvOutputFile != this.FileName)
|
||||
{
|
||||
File.Copy(this.FileName, tvOutputFile);
|
||||
this.FileName = tvOutputFile;
|
||||
}
|
||||
if (tvOutputFile != FileName)
|
||||
{
|
||||
File.Copy(FileName, tvOutputFile);
|
||||
FileName = tvOutputFile;
|
||||
}
|
||||
|
||||
using (StreamWriter file = new StreamWriter(tvOutputFile))
|
||||
{
|
||||
foreach (ChannelInfo 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 is Channels vdrChannel && !channel.IsDeleted)
|
||||
file.WriteLine(vdrChannel.confLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetFileInformation()
|
||||
public override string GetFileInformation()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append(base.GetFileInformation());
|
||||
return sb.ToString();
|
||||
using var file = new StreamWriter(tvOutputFile);
|
||||
foreach (var channel in allChannels.GetChannelsByNewOrder())
|
||||
{
|
||||
// when a reference list was applied, the list may contain proxy entries for deleted channels, which must be ignored
|
||||
if (channel is Channels vdrChannel && !channel.IsDeleted)
|
||||
file.WriteLine(vdrChannel.confLine);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user