mirror of
https://github.com/PredatH0r/ChanSort.git
synced 2026-05-13 03:16:38 +02:00
- removed superfluous parameter from SerializerBase.Save()
- added "Pooling=False" parameter to all Sqlite connection strings to prevent open file locks after closing the connection and to avoid extreme delays when using CloseAllPools()
- C# code refactoring "using var" instead of "using ( ) { }" where possible
This commit is contained in:
@@ -46,27 +46,25 @@ namespace ChanSort.Api
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
using (var stream = new StreamReader(this.FileName))
|
||||
{
|
||||
var lineNr = 0;
|
||||
using var stream = new StreamReader(this.FileName);
|
||||
var lineNr = 0;
|
||||
|
||||
var line = stream.ReadLine();
|
||||
if (line != null && line.StartsWith("--------") && line.Contains(" Program Data!--------"))
|
||||
throw LoaderException.TryNext("ignoring .csv file with Sharp/Dyon/Blaupunkt/Hisense header line");
|
||||
var line = stream.ReadLine();
|
||||
if (line != null && line.StartsWith("--------") && line.Contains(" Program Data!--------"))
|
||||
throw LoaderException.TryNext("ignoring .csv file with Sharp/Dyon/Blaupunkt/Hisense header line");
|
||||
|
||||
try
|
||||
try
|
||||
{
|
||||
while (line != null)
|
||||
{
|
||||
while (line != null)
|
||||
{
|
||||
this.ReadChannel(line, ++lineNr);
|
||||
line = stream.ReadLine();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw LoaderException.TryNext($"Error in reference file line #{lineNr}: {line}", ex);
|
||||
this.ReadChannel(line, ++lineNr);
|
||||
line = stream.ReadLine();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw LoaderException.TryNext($"Error in reference file line #{lineNr}: {line}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -314,18 +312,15 @@ namespace ChanSort.Api
|
||||
|
||||
#region Save()
|
||||
|
||||
public override void Save(string tvDataFile)
|
||||
public override void Save()
|
||||
{
|
||||
Save(tvDataFile, this.DataRoot);
|
||||
this.FileName = tvDataFile;
|
||||
Save(this.FileName, this.DataRoot);
|
||||
}
|
||||
|
||||
public static void Save(string tvDataFile, DataRoot dataRoot)
|
||||
{
|
||||
using (var stream = new StreamWriter(tvDataFile))
|
||||
{
|
||||
Save(stream, dataRoot);
|
||||
}
|
||||
using var stream = new StreamWriter(tvDataFile);
|
||||
Save(stream, dataRoot);
|
||||
}
|
||||
|
||||
public static void Save(TextWriter stream, DataRoot dataRoot, bool includeDeletedChannels = true)
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace ChanSort.Api
|
||||
}
|
||||
|
||||
public abstract void Load();
|
||||
public abstract void Save(string tvOutputFile);
|
||||
public abstract void Save();
|
||||
|
||||
public virtual Encoding DefaultEncoding
|
||||
{
|
||||
@@ -165,11 +165,10 @@ namespace ChanSort.Api
|
||||
ZipFile.ExtractToDirectory(this.FileName, this.TempPath);
|
||||
}
|
||||
|
||||
protected void ZipToOutputFile(string tvOutputFile, bool compress = true)
|
||||
protected void ZipToOutputFile(bool compress = true)
|
||||
{
|
||||
File.Delete(tvOutputFile);
|
||||
ZipFile.CreateFromDirectory(this.TempPath, tvOutputFile, compress ? CompressionLevel.Optimal : CompressionLevel.NoCompression, false);
|
||||
this.FileName = tvOutputFile;
|
||||
File.Delete(this.FileName);
|
||||
ZipFile.CreateFromDirectory(this.TempPath, this.FileName, compress ? CompressionLevel.Optimal : CompressionLevel.NoCompression, false);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -199,6 +198,7 @@ namespace ChanSort.Api
|
||||
var path = this.TempPath;
|
||||
if (string.IsNullOrEmpty(path))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(path))
|
||||
|
||||
@@ -52,37 +52,35 @@ namespace ChanSort.Api
|
||||
{
|
||||
var lineNr = 0;
|
||||
|
||||
using (var file = new StreamReader(this.FileName))
|
||||
using var file = new StreamReader(this.FileName);
|
||||
string line;
|
||||
while ((line = file.ReadLine()) != null)
|
||||
{
|
||||
string line;
|
||||
while ((line = file.ReadLine()) != null)
|
||||
{
|
||||
++lineNr;
|
||||
var parts = line.Split(Separators);
|
||||
if (parts.Length < 2)
|
||||
continue;
|
||||
int progNr;
|
||||
if (!int.TryParse(parts[0], out progNr))
|
||||
continue;
|
||||
++lineNr;
|
||||
var parts = line.Split(Separators);
|
||||
if (parts.Length < 2)
|
||||
continue;
|
||||
int progNr;
|
||||
if (!int.TryParse(parts[0], out progNr))
|
||||
continue;
|
||||
|
||||
var channel = new ChannelInfo(SignalSource.All, lineNr, progNr, parts[1]);
|
||||
if (parts.Length >= 3)
|
||||
var channel = new ChannelInfo(SignalSource.All, lineNr, progNr, parts[1]);
|
||||
if (parts.Length >= 3)
|
||||
{
|
||||
var subParts = parts[2].Split('-');
|
||||
if (subParts.Length >= 3)
|
||||
{
|
||||
var subParts = parts[2].Split('-');
|
||||
if (subParts.Length >= 3)
|
||||
{
|
||||
int val;
|
||||
if (int.TryParse(subParts[0], out val))
|
||||
channel.OriginalNetworkId = val;
|
||||
if (int.TryParse(subParts[1], out val))
|
||||
channel.TransportStreamId = val;
|
||||
if (int.TryParse(subParts[2], out val))
|
||||
channel.ServiceId = val;
|
||||
}
|
||||
int val;
|
||||
if (int.TryParse(subParts[0], out val))
|
||||
channel.OriginalNetworkId = val;
|
||||
if (int.TryParse(subParts[1], out val))
|
||||
channel.TransportStreamId = val;
|
||||
if (int.TryParse(subParts[2], out val))
|
||||
channel.ServiceId = val;
|
||||
}
|
||||
this.DataRoot.AddChannel(this.allChannels, channel);
|
||||
lineNr++;
|
||||
}
|
||||
this.DataRoot.AddChannel(this.allChannels, channel);
|
||||
lineNr++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,36 +100,33 @@ namespace ChanSort.Api
|
||||
|
||||
#region Save()
|
||||
|
||||
public override void Save(string tvOutputFile)
|
||||
public override void Save()
|
||||
{
|
||||
Save(tvOutputFile, this.allChannels);
|
||||
this.FileName = tvOutputFile;
|
||||
Save(this.FileName, this.allChannels);
|
||||
}
|
||||
|
||||
public static void Save(string fileName, ChannelList list)
|
||||
{
|
||||
var samToolBoxMode = (Path.GetExtension(fileName) ?? "").ToLowerInvariant() == ".chl";
|
||||
|
||||
using (var writer = new StreamWriter(fileName, false, Encoding.UTF8))
|
||||
using var writer = new StreamWriter(fileName, false, Encoding.UTF8);
|
||||
foreach (var channel in list.GetChannelsByNewOrder())
|
||||
{
|
||||
foreach (var channel in list.GetChannelsByNewOrder())
|
||||
{
|
||||
if (channel.NewProgramNr == -1) continue;
|
||||
if (channel.NewProgramNr == -1) continue;
|
||||
|
||||
writer.Write(channel.NewProgramNr);
|
||||
writer.Write(channel.NewProgramNr);
|
||||
writer.Write(Separators[0]);
|
||||
writer.Write(channel.Name);
|
||||
if (!samToolBoxMode)
|
||||
{
|
||||
writer.Write(Separators[0]);
|
||||
writer.Write(channel.Name);
|
||||
if (!samToolBoxMode)
|
||||
{
|
||||
writer.Write(Separators[0]);
|
||||
writer.Write(channel.OriginalNetworkId);
|
||||
writer.Write("-");
|
||||
writer.Write(channel.TransportStreamId);
|
||||
writer.Write("-");
|
||||
writer.Write(channel.ServiceId);
|
||||
}
|
||||
writer.WriteLine();
|
||||
writer.Write(channel.OriginalNetworkId);
|
||||
writer.Write("-");
|
||||
writer.Write(channel.TransportStreamId);
|
||||
writer.Write("-");
|
||||
writer.Write(channel.ServiceId);
|
||||
}
|
||||
writer.WriteLine();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user