2021-09-19 23:32:38 +02:00
using System.IO ;
using System.Text ;
using ChanSort.Api ;
2013-04-12 00:47:50 +02:00
namespace ChanSort.Loader.Panasonic
{
2021-01-23 14:22:18 +01:00
public class PanasonicPlugin : ISerializerPlugin
2013-04-12 00:47:50 +02:00
{
2017-10-28 13:20:39 +02:00
public string DllName { get ; set ; }
2021-09-19 23:32:38 +02:00
public string PluginName = > "Panasonic (*.db, *.bin, *.xml)" ;
public string FileFilter = > "*.db;*.bin;*.xml" ;
2021-01-23 14:22:18 +01:00
2013-04-12 00:47:50 +02:00
public SerializerBase CreateSerializer ( string inputFile )
{
2022-10-01 19:51:14 +02:00
// check for files in the 2022 /mnt/vendor/tvdata/database/channel/ directory structure file format with tv.db and idtvChannel.bin
var name = Path . GetFileName ( inputFile ) . ToLowerInvariant ( ) ;
var baseDir = Path . GetDirectoryName ( inputFile ) ;
2022-10-05 18:03:12 +02:00
if ( name = = "idtvchannel.bin" )
baseDir = Path . GetDirectoryName ( Path . GetDirectoryName ( Path . GetDirectoryName ( Path . GetDirectoryName ( Path . GetDirectoryName ( baseDir ) ) ) ) ) ; // go down channel/database/tvdata/vendor/mnt
else if ( name = = "tv.db" )
baseDir = Path . GetDirectoryName ( Path . GetDirectoryName ( Path . GetDirectoryName ( Path . GetDirectoryName ( baseDir ) ) ) ) ; // go down database/tvdata/vendor/mnt
var hotelBin = Path . Combine ( baseDir , "hotel.bin" ) ;
if ( File . Exists ( hotelBin ) & & File . Exists ( Path . Combine ( baseDir , "mnt/vendor/tvdata/database" , "tv.db" ) ) & & File . Exists ( Path . Combine ( baseDir , "mnt/vendor/tvdata/database/channel" , "idtvChannel.bin" ) ) )
return new IdtvChannelSerializer ( hotelBin ) ;
2022-10-01 19:51:14 +02:00
// Android based models use an .xml format. Unfortunately that format is utter garbage and not really useful
var ext = Path . GetExtension ( inputFile ) . ToLowerInvariant ( ) ;
if ( ext = = ".xml" )
2021-09-19 23:32:38 +02:00
{
var data = File . ReadAllBytes ( inputFile ) ;
var header = Encoding . ASCII . GetBytes ( "<ChannelList>\n<ChannelInfo IsModified=" ) ;
for ( int i = 0 ; i < header . Length ; i + + )
{
if ( data [ i ] ! = header [ i ] )
return null ;
}
return new XmlSerializer ( inputFile ) ;
}
2022-10-01 19:51:14 +02:00
// old svl.db / svl.bin formats
2022-11-29 18:21:52 +01:00
return new SvlSerializer ( inputFile ) ;
2013-04-12 00:47:50 +02:00
}
}
}