Refactor - fix minor issues from codacy

This commit is contained in:
Nikolaj Olsson 2019-01-23 12:28:03 +01:00
parent 85a0a1fee0
commit 8918bb1bbf
3 changed files with 40 additions and 20 deletions

View File

@ -9,8 +9,8 @@ namespace Nikse.SubtitleEdit.Core.VobSub
{ {
public bool IsPal { get; private set; } public bool IsPal { get; private set; }
public List<VobSubPack> VobSubPacks { get; private set; } public List<VobSubPack> VobSubPacks { get; private set; }
public List<Color> IdxPalette = new List<Color>(); public List<Color> IdxPalette { get; private set; } = new List<Color>();
public List<string> IdxLanguages = new List<string>(); public List<string> IdxLanguages { get; private set; } = new List<string>();
private const int PacketizedElementaryStreamMaximumLength = 2028; private const int PacketizedElementaryStreamMaximumLength = 2028;

View File

@ -42,21 +42,21 @@ namespace Nikse.SubtitleEdit.Core.VobSub
private readonly string _subFileName; private readonly string _subFileName;
private FileStream _subFile; private FileStream _subFile;
private readonly StringBuilder _idx = new StringBuilder(); private readonly StringBuilder _idx;
private readonly int _screenWidth = 720; private readonly int _screenWidth;
private readonly int _screenHeight = 480; private readonly int _screenHeight;
private readonly int _bottomMargin = 15; private readonly int _bottomMargin;
private readonly int _leftRightMargin = 15; private readonly int _leftRightMargin;
private readonly int _languageStreamId; private readonly int _languageStreamId;
private Color _background = Color.Transparent; private readonly Color _background = Color.Transparent;
private Color _pattern = Color.White; private readonly Color _pattern;
private Color _emphasis1 = Color.Black; private readonly Color _emphasis1;
private readonly bool _useInnerAntialiasing = true; private readonly bool _useInnerAntiAliasing;
private Color _emphasis2 = Color.FromArgb(240, Color.Black); private Color _emphasis2 = Color.FromArgb(240, Color.Black);
private readonly string _languageName = "English"; private readonly string _languageName;
private readonly string _languageNameShort = "en"; private readonly string _languageNameShort;
public VobSubWriter(string subFileName, int screenWidth, int screenHeight, int bottomMargin, int leftRightMargin, int languageStreamId, Color pattern, Color emphasis1, bool useInnerAntialiasing, DvdSubtitleLanguage language) public VobSubWriter(string subFileName, int screenWidth, int screenHeight, int bottomMargin, int leftRightMargin, int languageStreamId, Color pattern, Color emphasis1, bool useInnerAntiAliasing, DvdSubtitleLanguage language)
{ {
_subFileName = subFileName; _subFileName = subFileName;
_screenWidth = screenWidth; _screenWidth = screenWidth;
@ -66,7 +66,7 @@ namespace Nikse.SubtitleEdit.Core.VobSub
_languageStreamId = languageStreamId; _languageStreamId = languageStreamId;
_pattern = pattern; _pattern = pattern;
_emphasis1 = emphasis1; _emphasis1 = emphasis1;
_useInnerAntialiasing = useInnerAntialiasing; _useInnerAntiAliasing = useInnerAntiAliasing;
_languageName = language.NativeName; _languageName = language.NativeName;
_languageNameShort = language.Code; _languageNameShort = language.Code;
_idx = CreateIdxHeader(); _idx = CreateIdxHeader();
@ -131,7 +131,7 @@ namespace Nikse.SubtitleEdit.Core.VobSub
// Control command 2 = StopDisplay // Control command 2 = StopDisplay
ms.WriteByte(2); ms.WriteByte(2);
// extra byte - for compatability with gpac/MP4BOX // extra byte - for compatibility with gpac/MP4BOX
ms.WriteByte(255); // 1 byte ms.WriteByte(255); // 1 byte
return ms.ToArray(); return ms.ToArray();
@ -143,7 +143,7 @@ namespace Nikse.SubtitleEdit.Core.VobSub
_idx.AppendLine($"timestamp: {p.StartTime.Hours:00}:{p.StartTime.Minutes:00}:{p.StartTime.Seconds:00}:{p.StartTime.Milliseconds:000}, filepos: {_subFile.Position.ToString("X").PadLeft(9, '0').ToLowerInvariant()}"); _idx.AppendLine($"timestamp: {p.StartTime.Hours:00}:{p.StartTime.Minutes:00}:{p.StartTime.Seconds:00}:{p.StartTime.Milliseconds:000}, filepos: {_subFile.Position.ToString("X").PadLeft(9, '0').ToLowerInvariant()}");
var nbmp = new NikseBitmap(bmp); var nbmp = new NikseBitmap(bmp);
_emphasis2 = nbmp.ConverToFourColors(_background, _pattern, _emphasis1, _useInnerAntialiasing); _emphasis2 = nbmp.ConverToFourColors(_background, _pattern, _emphasis1, _useInnerAntiAliasing);
var twoPartBuffer = nbmp.RunLengthEncodeForDvd(_background, _pattern, _emphasis1, _emphasis2); var twoPartBuffer = nbmp.RunLengthEncodeForDvd(_background, _pattern, _emphasis1, _emphasis2);
var imageBuffer = GetSubImageBuffer(twoPartBuffer, nbmp, p, alignment, overridePosition); var imageBuffer = GetSubImageBuffer(twoPartBuffer, nbmp, p, alignment, overridePosition);
@ -153,7 +153,7 @@ namespace Nikse.SubtitleEdit.Core.VobSub
byte[] subHeader = new byte[30]; byte[] subHeader = new byte[30];
byte[] ts = new byte[4]; byte[] ts = new byte[4];
// Lended from "Son2VobSub" by Alain Vielle and Petr Vyskocil // Lent from "Son2VobSub" by Alain Vielle and Petr Vyskocil
// And also from Sup2VobSub by Emmel // And also from Sup2VobSub by Emmel
subHeader[0] = 0x00; // MPEG 2 PACK HEADER subHeader[0] = 0x00; // MPEG 2 PACK HEADER
subHeader[1] = 0x00; subHeader[1] = 0x00;
@ -300,7 +300,7 @@ namespace Nikse.SubtitleEdit.Core.VobSub
} }
if (alignment == ContentAlignment.MiddleLeft || alignment == ContentAlignment.MiddleCenter || alignment == ContentAlignment.MiddleRight) if (alignment == ContentAlignment.MiddleLeft || alignment == ContentAlignment.MiddleCenter || alignment == ContentAlignment.MiddleRight)
{ {
startY = (ushort)((_screenHeight / 2) - (nbmp.Height / 2)); startY = (ushort)(_screenHeight / 2 - nbmp.Height / 2);
} }
if (alignment == ContentAlignment.TopLeft || alignment == ContentAlignment.MiddleLeft || alignment == ContentAlignment.BottomLeft) if (alignment == ContentAlignment.TopLeft || alignment == ContentAlignment.MiddleLeft || alignment == ContentAlignment.BottomLeft)
{ {

View File

@ -46,7 +46,10 @@ namespace UpdateLanguageFiles
var languageAsXml = language.GetCurrentLanguageAsXml(); var languageAsXml = language.GetCurrentLanguageAsXml();
var oldLanguageAsXml = string.Empty; var oldLanguageAsXml = string.Empty;
if (File.Exists(args[0])) if (File.Exists(args[0]))
{
oldLanguageAsXml = File.ReadAllText(args[0]); oldLanguageAsXml = File.ReadAllText(args[0]);
}
if (oldLanguageAsXml != languageAsXml) if (oldLanguageAsXml != languageAsXml)
{ {
language.Save(args[0]); language.Save(args[0]);
@ -57,7 +60,10 @@ namespace UpdateLanguageFiles
var languageDeserializerContent = Nikse.SubtitleEdit.Logic.LanguageDeserializerGenerator.GenerateCSharpXmlDeserializerForLanguage(); var languageDeserializerContent = Nikse.SubtitleEdit.Logic.LanguageDeserializerGenerator.GenerateCSharpXmlDeserializerForLanguage();
var oldLanguageDeserializerContent = string.Empty; var oldLanguageDeserializerContent = string.Empty;
if (File.Exists(args[1])) if (File.Exists(args[1]))
{
oldLanguageDeserializerContent = File.ReadAllText(args[1]); oldLanguageDeserializerContent = File.ReadAllText(args[1]);
}
if (oldLanguageDeserializerContent != languageDeserializerContent) if (oldLanguageDeserializerContent != languageDeserializerContent)
{ {
File.WriteAllText(args[1], languageDeserializerContent, Encoding.UTF8); File.WriteAllText(args[1], languageDeserializerContent, Encoding.UTF8);
@ -89,15 +95,29 @@ namespace UpdateLanguageFiles
{ {
var templateFileName = Path.Combine("src", "Properties", "AssemblyInfo.cs.template"); var templateFileName = Path.Combine("src", "Properties", "AssemblyInfo.cs.template");
if (!File.Exists(templateFileName)) if (!File.Exists(templateFileName))
{
templateFileName = Path.Combine("..", templateFileName); templateFileName = Path.Combine("..", templateFileName);
}
if (!File.Exists(templateFileName)) if (!File.Exists(templateFileName))
{
templateFileName = Path.Combine("..", templateFileName); templateFileName = Path.Combine("..", templateFileName);
}
if (!File.Exists(templateFileName)) if (!File.Exists(templateFileName))
{
templateFileName = Path.Combine("..", templateFileName); templateFileName = Path.Combine("..", templateFileName);
}
if (!File.Exists(templateFileName)) if (!File.Exists(templateFileName))
{
templateFileName = Path.Combine("..", templateFileName); templateFileName = Path.Combine("..", templateFileName);
}
if (!File.Exists(templateFileName)) if (!File.Exists(templateFileName))
{
templateFileName = Path.Combine("..", templateFileName); templateFileName = Path.Combine("..", templateFileName);
}
if (File.Exists(templateFileName)) if (File.Exists(templateFileName))
{ {