From 8918bb1bbf97268045195396cc9ac8c1c6857d8f Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Wed, 23 Jan 2019 12:28:03 +0100 Subject: [PATCH] Refactor - fix minor issues from codacy --- libse/VobSub/VobSubParser.cs | 4 ++-- libse/VobSub/VobSubWriter.cs | 36 +++++++++++++++--------------- src/UpdateLanguageFiles/Program.cs | 20 +++++++++++++++++ 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/libse/VobSub/VobSubParser.cs b/libse/VobSub/VobSubParser.cs index 57bd05503..5b2303f0d 100644 --- a/libse/VobSub/VobSubParser.cs +++ b/libse/VobSub/VobSubParser.cs @@ -9,8 +9,8 @@ namespace Nikse.SubtitleEdit.Core.VobSub { public bool IsPal { get; private set; } public List VobSubPacks { get; private set; } - public List IdxPalette = new List(); - public List IdxLanguages = new List(); + public List IdxPalette { get; private set; } = new List(); + public List IdxLanguages { get; private set; } = new List(); private const int PacketizedElementaryStreamMaximumLength = 2028; diff --git a/libse/VobSub/VobSubWriter.cs b/libse/VobSub/VobSubWriter.cs index e5dd26dc3..07f7d97a4 100644 --- a/libse/VobSub/VobSubWriter.cs +++ b/libse/VobSub/VobSubWriter.cs @@ -42,21 +42,21 @@ namespace Nikse.SubtitleEdit.Core.VobSub private readonly string _subFileName; private FileStream _subFile; - private readonly StringBuilder _idx = new StringBuilder(); - private readonly int _screenWidth = 720; - private readonly int _screenHeight = 480; - private readonly int _bottomMargin = 15; - private readonly int _leftRightMargin = 15; + private readonly StringBuilder _idx; + private readonly int _screenWidth; + private readonly int _screenHeight; + private readonly int _bottomMargin; + private readonly int _leftRightMargin; private readonly int _languageStreamId; - private Color _background = Color.Transparent; - private Color _pattern = Color.White; - private Color _emphasis1 = Color.Black; - private readonly bool _useInnerAntialiasing = true; + private readonly Color _background = Color.Transparent; + private readonly Color _pattern; + private readonly Color _emphasis1; + private readonly bool _useInnerAntiAliasing; private Color _emphasis2 = Color.FromArgb(240, Color.Black); - private readonly string _languageName = "English"; - private readonly string _languageNameShort = "en"; + private readonly string _languageName; + 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; _screenWidth = screenWidth; @@ -66,7 +66,7 @@ namespace Nikse.SubtitleEdit.Core.VobSub _languageStreamId = languageStreamId; _pattern = pattern; _emphasis1 = emphasis1; - _useInnerAntialiasing = useInnerAntialiasing; + _useInnerAntiAliasing = useInnerAntiAliasing; _languageName = language.NativeName; _languageNameShort = language.Code; _idx = CreateIdxHeader(); @@ -83,7 +83,7 @@ namespace Nikse.SubtitleEdit.Core.VobSub { var ms = new MemoryStream(); - // sup picture datasize + // sup picture data size WriteEndianWord(twoPartBuffer.Length + 34, ms); // first display control sequence table address @@ -131,7 +131,7 @@ namespace Nikse.SubtitleEdit.Core.VobSub // Control command 2 = StopDisplay ms.WriteByte(2); - // extra byte - for compatability with gpac/MP4BOX + // extra byte - for compatibility with gpac/MP4BOX ms.WriteByte(255); // 1 byte 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()}"); 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 imageBuffer = GetSubImageBuffer(twoPartBuffer, nbmp, p, alignment, overridePosition); @@ -153,7 +153,7 @@ namespace Nikse.SubtitleEdit.Core.VobSub byte[] subHeader = new byte[30]; 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 subHeader[0] = 0x00; // MPEG 2 PACK HEADER subHeader[1] = 0x00; @@ -300,7 +300,7 @@ namespace Nikse.SubtitleEdit.Core.VobSub } 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) { diff --git a/src/UpdateLanguageFiles/Program.cs b/src/UpdateLanguageFiles/Program.cs index afb5e7b3a..ce9ddf0f6 100644 --- a/src/UpdateLanguageFiles/Program.cs +++ b/src/UpdateLanguageFiles/Program.cs @@ -46,7 +46,10 @@ namespace UpdateLanguageFiles var languageAsXml = language.GetCurrentLanguageAsXml(); var oldLanguageAsXml = string.Empty; if (File.Exists(args[0])) + { oldLanguageAsXml = File.ReadAllText(args[0]); + } + if (oldLanguageAsXml != languageAsXml) { language.Save(args[0]); @@ -57,7 +60,10 @@ namespace UpdateLanguageFiles var languageDeserializerContent = Nikse.SubtitleEdit.Logic.LanguageDeserializerGenerator.GenerateCSharpXmlDeserializerForLanguage(); var oldLanguageDeserializerContent = string.Empty; if (File.Exists(args[1])) + { oldLanguageDeserializerContent = File.ReadAllText(args[1]); + } + if (oldLanguageDeserializerContent != languageDeserializerContent) { File.WriteAllText(args[1], languageDeserializerContent, Encoding.UTF8); @@ -89,15 +95,29 @@ namespace UpdateLanguageFiles { var templateFileName = Path.Combine("src", "Properties", "AssemblyInfo.cs.template"); if (!File.Exists(templateFileName)) + { templateFileName = Path.Combine("..", templateFileName); + } + if (!File.Exists(templateFileName)) + { templateFileName = Path.Combine("..", templateFileName); + } + if (!File.Exists(templateFileName)) + { templateFileName = Path.Combine("..", templateFileName); + } + if (!File.Exists(templateFileName)) + { templateFileName = Path.Combine("..", templateFileName); + } + if (!File.Exists(templateFileName)) + { templateFileName = Path.Combine("..", templateFileName); + } if (File.Exists(templateFileName)) {