Refactor - fix minor issues from codacy

This commit is contained in:
Nikolaj Olsson 2019-01-22 07:30:08 +01:00
parent 3a34e45fbb
commit e4bbb5c401
5 changed files with 59 additions and 62 deletions

View File

@ -10,15 +10,15 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.MaterialExchangeFormat
/// </summary>
public class KlvPacket
{
public static byte[] PartitionPack = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0D, 0x01, 0x02, 0x01, 0x01, 0xff, 0xff, 0x00 }; // 0xff can have different values
public static byte[] Preface = { 0x06, 0x0E, 0x2B, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x2F, 0x00 };
public static byte[] EssenceElement = { 0x06, 0x0E, 0x2B, 0x34, 0x01, 0x02, 0x01, 0x01, 0x0D, 0x01, 0x03, 0x01, 0xff, 0xff, 0xff, 0xff };
public static byte[] OperationalPattern = { 0x06, 0x0E, 0x2B, 0x34, 0x04, 0x01, 0x01, 0x01, 0x0D, 0x01, 0x02, 0x01, 0x00, 0xff, 0xff, 0x00 };
public static byte[] PartitionMetadata = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01, 0x01, 0x04, 0x04, 0x00 };
public static byte[] StructuralMetadata = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x01, 0x01, 0x00, 0xff, 0xff, 0x00 };
public static byte[] DataDefinitionVideo = { 0x06, 0x0E, 0x2B, 0x34, 0x04, 0x01, 0x01, 0x01, 0x01, 0x03, 0x02, 0x02, 0x01, 0xff, 0xff, 0x00 };
public static byte[] DataDefinitionAudio = { 0x06, 0x0E, 0x2B, 0x34, 0x04, 0x01, 0x01, 0x01, 0x01, 0x03, 0x02, 0x02, 0x02, 0xff, 0xff, 0x00 };
public static byte[] Primer = { 0x06, 0xe, 0x2b, 0x34, 0x02, 0x05, 0x1, 0xff, 0x0d, 0x01, 0x02, 0x01, 0x01, 0x05, 0x01, 0xff };
public static readonly byte[] PartitionPack = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0D, 0x01, 0x02, 0x01, 0x01, 0xff, 0xff, 0x00 }; // 0xff can have different values
public static readonly byte[] Preface = { 0x06, 0x0E, 0x2B, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x2F, 0x00 };
public static readonly byte[] EssenceElement = { 0x06, 0x0E, 0x2B, 0x34, 0x01, 0x02, 0x01, 0x01, 0x0D, 0x01, 0x03, 0x01, 0xff, 0xff, 0xff, 0xff };
public static readonly byte[] OperationalPattern = { 0x06, 0x0E, 0x2B, 0x34, 0x04, 0x01, 0x01, 0x01, 0x0D, 0x01, 0x02, 0x01, 0x00, 0xff, 0xff, 0x00 };
public static readonly byte[] PartitionMetadata = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01, 0x01, 0x04, 0x04, 0x00 };
public static readonly byte[] StructuralMetadata = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x01, 0x01, 0x00, 0xff, 0xff, 0x00 };
public static readonly byte[] DataDefinitionVideo = { 0x06, 0x0E, 0x2B, 0x34, 0x04, 0x01, 0x01, 0x01, 0x01, 0x03, 0x02, 0x02, 0x01, 0xff, 0xff, 0x00 };
public static readonly byte[] DataDefinitionAudio = { 0x06, 0x0E, 0x2B, 0x34, 0x04, 0x01, 0x01, 0x01, 0x01, 0x03, 0x02, 0x02, 0x02, 0xff, 0xff, 0x00 };
public static readonly byte[] Primer = { 0x06, 0xe, 0x2b, 0x34, 0x02, 0x05, 0x1, 0xff, 0x0d, 0x01, 0x02, 0x01, 0x01, 0x05, 0x01, 0xff };
private const int KeySize = 16;

View File

@ -8,33 +8,33 @@ namespace Nikse.SubtitleEdit.Core
{
public class IfoParser : IDisposable
{
public struct AudioStream
public class AudioStream
{
public int LanguageTypeSpecified;
public string Language;
public string LanguageCode;
public string CodingMode;
public int Channels;
public string Extension;
public int LanguageTypeSpecified { get; set; }
public string Language { get; set; }
public string LanguageCode { get; set; }
public string CodingMode { get; set; }
public int Channels { get; set; }
public string Extension { get; set; }
};
public struct VideoStream
public class VideoStream
{
public string Aspect;
public string Standard;
public string CodingMode;
public string Resolution;
public string Aspect { get; set; }
public string Standard { get; set; }
public string CodingMode { get; set; }
public string Resolution { get; set; }
}
public class VtsVobs
{
public int NumberOfAudioStreams;
public int NumberOfSubtitles;
public VideoStream VideoStream;
public List<AudioStream> AudioStreams;
public List<string> Subtitles;
public List<string> SubtitleIDs;
public List<string> SubtitleTypes;
public int NumberOfAudioStreams { get; set; }
public int NumberOfSubtitles { get; set; }
public VideoStream VideoStream { get; set; }
public List<AudioStream> AudioStreams { get; set; }
public List<string> Subtitles { get; set; }
public List<string> SubtitleIDs { get; set; }
public List<string> SubtitleTypes { get; set; }
public List<string> GetAllLanguages()
{
@ -85,15 +85,15 @@ namespace Nikse.SubtitleEdit.Core
public class ProgramChain
{
public int NumberOfPgc;
public int NumberOfCells;
public string PlaybackTime;
public List<byte> PgcEntryCells;
public List<string> PgcPlaybackTimes;
public List<string> PgcStartTimes;
public List<char> AudioStreamsAvailable;
public List<byte[]> SubtitlesAvailable;
public List<Color> ColorLookupTable;
public int NumberOfPgc { get; set; }
public int NumberOfCells { get; set; }
public string PlaybackTime { get; set; }
public List<byte> PgcEntryCells { get; set; }
public List<string> PgcPlaybackTimes { get; set; }
public List<string> PgcStartTimes { get; set; }
public List<char> AudioStreamsAvailable { get; set; }
public List<byte[]> SubtitlesAvailable { get; set; }
public List<Color> ColorLookupTable { get; set; }
public ProgramChain()
{
@ -131,8 +131,8 @@ namespace Nikse.SubtitleEdit.Core
private readonly List<string> _arrayOfNtscResolution = new List<string> { "720x480", "704x480", "352x480", "352x240" };
private readonly List<string> _arrayOfPalResolution = new List<string> { "720x576", "704x576", "352x576", "352x288" };
public VtsPgci VideoTitleSetProgramChainTable { get { return _vtsPgci; } }
public VtsVobs VideoTitleSetVobs { get { return _vtsVobs; } }
public VtsPgci VideoTitleSetProgramChainTable => _vtsPgci;
public VtsVobs VideoTitleSetVobs => _vtsVobs;
public string ErrorMessage { get; private set; }
private readonly VtsVobs _vtsVobs = new VtsVobs();
@ -465,7 +465,7 @@ namespace Nikse.SubtitleEdit.Core
if (programChain.HasNoSpecificSubs)
{
// only one unspezified subpicture stream exists
_vtsVobs.SubtitleIDs.Add(string.Format("0x{0:x2}", subStream++));
_vtsVobs.SubtitleIDs.Add($"0x{subStream++:x2}");
_vtsVobs.SubtitleTypes.Add("unspecific");
}
else
@ -495,7 +495,7 @@ namespace Nikse.SubtitleEdit.Core
string subType = string.Empty;
if (programChain.Has43Subs)
{
sub = string.Format("0x{0:x2}", subStream + pos43Subs);
sub = $"0x{subStream + pos43Subs:x2}";
subType = "4:3";
}
if (programChain.HasWideSubs)
@ -505,7 +505,7 @@ namespace Nikse.SubtitleEdit.Core
sub += ", ";
subType += ", ";
}
sub += string.Format("0x{0:x2}", subStream + posWideSubs);
sub += $"0x{subStream + posWideSubs:x2}";
subType += "wide";
}
if (programChain.HasLetterSubs)
@ -515,7 +515,7 @@ namespace Nikse.SubtitleEdit.Core
sub += ", ";
subType += ", ";
}
sub += string.Format("0x{0:x2}", subStream + posLetterSubs);
sub += $"0x{subStream + posLetterSubs:x2}";
subType += "letterboxed";
}
if (programChain.HasPanSubs)
@ -525,7 +525,7 @@ namespace Nikse.SubtitleEdit.Core
sub += ", ";
subType += ", ";
}
sub += string.Format("0x{0:x2}", subStream + posPanSubs);
sub += $"0x{subStream + posPanSubs:x2}";
subType += "pan&scan";
}
@ -577,7 +577,7 @@ namespace Nikse.SubtitleEdit.Core
private static string MsToTime(double milliseconds)
{
var ts = TimeSpan.FromMilliseconds(milliseconds);
string s = string.Format("{0:#0}:{1:00}:{2:00}.{3:000}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
string s = $"{ts.Hours:#0}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds:000}";
return s;
}

View File

@ -20,7 +20,7 @@ namespace Nikse.SubtitleEdit.Core
public string FileName { get; set; }
public const int MaximumHistoryItems = 100;
public static int MaximumHistoryItems => 100;
public SubtitleFormat OriginalFormat { get; private set; }

View File

@ -45,9 +45,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
var s = line.Replace("&gt;", ">").Substring(0, idx);
s = s.Remove(0, s.IndexOf(':') + 1);
var arr = s.Split(new[] { '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
var p = new Paragraph();
p.StartTime = DecodeTimeCode(arr[0]);
p.EndTime = DecodeTimeCode(arr[1]);
var p = new Paragraph { StartTime = DecodeTimeCode(arr[0]), EndTime = DecodeTimeCode(arr[1]) };
int start = line.IndexOf("<img src=", StringComparison.Ordinal) + 9;
int end = line.IndexOf(".png", StringComparison.Ordinal) + 4;
p.Text = line.Substring(start, end - start).Trim('"', '\'');
@ -64,7 +62,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
subtitle.Renumber();
}
private TimeCode DecodeTimeCode(string timeCode)
private static TimeCode DecodeTimeCode(string timeCode)
{
var parts = timeCode.Split(new[] { ':', '-', '>', ',', '.' }, StringSplitOptions.RemoveEmptyEntries);
int milliseconds = int.Parse(parts[parts.Length - 1]);

View File

@ -24,13 +24,13 @@ namespace Nikse.SubtitleEdit.Core.TransportStream
public Bitmap Image { get; set; }
private FastBitmap _fastImage;
public const int PixelDecoding2Bit = 0x10;
public const int PixelDecoding4Bit = 0x11;
public const int PixelDecoding8Bit = 0x12;
public const int MapTable2To4Bit = 0x20;
public const int MapTable2To8Bit = 0x21;
public const int MapTable4To8Bit = 0x22;
public const int EndOfObjectLineCode = 0xf0;
public static int PixelDecoding2Bit => 0x10;
public static int PixelDecoding4Bit => 0x11;
public static int PixelDecoding8Bit => 0x12;
public static int MapTable2To4Bit => 0x20;
public static int MapTable2To8Bit => 0x21;
public static int MapTable4To8Bit => 0x22;
public static int EndOfObjectLineCode => 0xf0;
public int BufferIndex { get; private set; }
@ -198,11 +198,10 @@ namespace Nikse.SubtitleEdit.Core.TransportStream
private static int CalculateSize(byte[] buffer, int index, ref int dataType, int start, ref int x, ref int y, int length, ref int runLength, ref int width)
{
int pixelCode;
if (dataType == PixelDecoding2Bit)
{
int bitIndex = 0;
while (index < start + length - 1 && TwoBitPixelDecoding(buffer, ref index, ref bitIndex, out pixelCode, out runLength))
while (index < start + length - 1 && TwoBitPixelDecoding(buffer, ref index, ref bitIndex, out _, out runLength))
{
x += runLength;
}
@ -210,14 +209,14 @@ namespace Nikse.SubtitleEdit.Core.TransportStream
else if (dataType == PixelDecoding4Bit)
{
bool startHalf = false;
while (index < start + length - 1 && FourBitPixelDecoding(buffer, ref index, ref startHalf, out pixelCode, out runLength))
while (index < start + length - 1 && FourBitPixelDecoding(buffer, ref index, ref startHalf, out _, out runLength))
{
x += runLength;
}
}
else if (dataType == PixelDecoding8Bit)
{
while (index < start + length - 1 && EightBitPixelDecoding(buffer, ref index, out pixelCode, out runLength))
while (index < start + length - 1 && EightBitPixelDecoding(buffer, ref index, out _, out runLength))
{
x += runLength;
}
@ -343,7 +342,7 @@ namespace Nikse.SubtitleEdit.Core.TransportStream
int first = Next4Bits(buffer, ref index, ref startHalf);
if (first != 0)
{
pixelCode = first; // Next4Bits(buffer, ref index, ref startHalf);
pixelCode = first;
runLength = 1;
}
else