From 8c4e3e06cfedeb1d1fa9fb528e828fe0450f7bb1 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Sun, 20 Jan 2019 14:53:58 +0100 Subject: [PATCH] Refactor - fix minor issues from codacy --- libse/BluRaySup/BluRaySupPicture.cs | 7 +- libse/ContainerFormats/AviRiffData.cs | 24 --- libse/ContainerFormats/Mp4/Boxes/Tkhd.cs | 2 - libse/ContainerFormats/RiffParser.cs | 5 - libse/SubtitleFormats/Ebu.cs | 1 - libse/SubtitleFormats/F4Text.cs | 12 +- libse/SubtitleFormats/Json.cs | 2 +- libse/SubtitleFormats/NciCaption.cs | 6 - libse/SubtitleFormats/Pac.cs | 7 +- .../ScenaristClosedCaptions.cs | 2 +- libse/SubtitleFormats/Ultech130.cs | 187 ------------------ libse/VobSub/Mpeg2Header.cs | 10 - libse/VobSub/VobSubWriter.cs | 1 - libse/WaveToVisualizer.cs | 11 +- src/Controls/AudioVisualizer.cs | 6 - src/Controls/VideoPlayerContainer.cs | 2 +- src/Forms/AudioToText.cs | 1 - src/Forms/HardSubExtract.cs | 2 +- src/Forms/Main.cs | 4 +- src/Forms/Ocr/VobSubEditCharacters.cs | 13 +- src/Forms/Ocr/VobSubOcr.cs | 2 +- src/Forms/Ocr/VobSubOcrNOcrCharacter.cs | 2 - src/Logic/DarkTheme.cs | 2 - src/Logic/NikseBitmapImageSplitter.cs | 6 - src/Logic/VideoPlayers/QuartsPlayer.cs | 6 - 25 files changed, 22 insertions(+), 301 deletions(-) diff --git a/libse/BluRaySup/BluRaySupPicture.cs b/libse/BluRaySup/BluRaySupPicture.cs index 2fb56554a..db87f70e1 100644 --- a/libse/BluRaySup/BluRaySupPicture.cs +++ b/libse/BluRaySup/BluRaySupPicture.cs @@ -111,7 +111,6 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup var bytes = new List(); for (int y = 0; y < bm.Height; y++) { - //eol = false; int x; int len; for (x = 0; x < bm.Width; x += len) @@ -185,7 +184,7 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup } } } - if (/*!eol &&*/ x == bm.Width) + if (x == bm.Width) { bytes.Add(0); // rle id bytes.Add(0); @@ -562,7 +561,7 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup } packetHeader[10] = 0x15; // ID - timestamp = 0; //dts + imageDecodeTime; + timestamp = 0; ToolBox.SetDWord(packetHeader, 2, timestamp); // PTS ToolBox.SetDWord(packetHeader, 6, dts); // DTS ToolBox.SetWord(packetHeader, 11, headerOdsFirst.Length + bufSize); // size @@ -627,7 +626,7 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup // write PCS end packetHeader[10] = 0x16; // ID ToolBox.SetDWord(packetHeader, 2, pic.EndTimeForWrite); // PTS - dts = pic.EndTimeForWrite - 90; //dts = pic.StartTimeForWrite - 1; + dts = pic.EndTimeForWrite - 90; ToolBox.SetDWord(packetHeader, 6, dts); // DTS ToolBox.SetWord(packetHeader, 11, headerPcsEnd.Length); // size for (int i = 0; i < packetHeader.Length; i++) diff --git a/libse/ContainerFormats/AviRiffData.cs b/libse/ContainerFormats/AviRiffData.cs index 0dbf45fe3..5e8c26c3f 100644 --- a/libse/ContainerFormats/AviRiffData.cs +++ b/libse/ContainerFormats/AviRiffData.cs @@ -70,24 +70,6 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats public int cFrames; } - //internal struct TIMECODEDATA - //{ - // private TIMECODE time; - // public int dwSMPTEflags; - // public int dwUser; - //} - - //internal struct WAVEFORMATEX - //{ - // public short wFormatTag; - // public short nChannels; - // public int nSamplesPerSec; - // public int nAvgBytesPerSec; - // public short nBlockAlign; - // public short wBitsPerSample; - // public short cbSize; - //} - internal static class AviRiffData { #region AVI constants @@ -117,18 +99,12 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats // AVI stream FourCC codes public static readonly int streamtypeVIDEO = RiffParser.ToFourCc("vids"); public static readonly int streamtypeAUDIO = RiffParser.ToFourCc("auds"); - //public static readonly int streamtypeMIDI = RiffParser.ToFourCC("mids"); - //public static readonly int streamtypeTEXT = RiffParser.ToFourCC("txts"); // AVI section FourCC codes public static readonly int ckidAVIHeaderList = RiffParser.ToFourCc("hdrl"); public static readonly int ckidMainAVIHeader = RiffParser.ToFourCc("avih"); - //public static readonly int ckidODML = RiffParser.ToFourCC("odml"); - //public static readonly int ckidAVIExtHeader = RiffParser.ToFourCC("dmlh"); public static readonly int ckidAVIStreamList = RiffParser.ToFourCc("strl"); public static readonly int ckidAVIStreamHeader = RiffParser.ToFourCc("strh"); - //public static readonly int ckidStreamFormat = RiffParser.ToFourCC("strf"); - //public static readonly int ckidAVIOldIndex = RiffParser.ToFourCC("idx1"); public static readonly int ckidINFOList = RiffParser.ToFourCc("INFO"); public static readonly int ckidAVIISFT = RiffParser.ToFourCc("ISFT"); public const int ckidMP3 = 0x0055; diff --git a/libse/ContainerFormats/Mp4/Boxes/Tkhd.cs b/libse/ContainerFormats/Mp4/Boxes/Tkhd.cs index a7078996b..a005da917 100644 --- a/libse/ContainerFormats/Mp4/Boxes/Tkhd.cs +++ b/libse/ContainerFormats/Mp4/Boxes/Tkhd.cs @@ -41,8 +41,6 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.Mp4.Boxes Width = (uint)GetWord(76 + addToIndex64Bit); // skip decimals Height = (uint)GetWord(80 + addToIndex64Bit); // skip decimals - //System.Windows.Forms.MessageBox.Show("Width: " + GetWord(76 + addToIndex64Bit).ToString() + "." + GetWord(78 + addToIndex64Bit).ToString()); - //System.Windows.Forms.MessageBox.Show("Height: " + GetWord(80 + addToIndex64Bit).ToString() + "." + GetWord(82 + addToIndex64Bit).ToString()); } } } diff --git a/libse/ContainerFormats/RiffParser.cs b/libse/ContainerFormats/RiffParser.cs index 4051a28ee..42b3fde6f 100644 --- a/libse/ContainerFormats/RiffParser.cs +++ b/libse/ContainerFormats/RiffParser.cs @@ -163,8 +163,6 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats _shortName = fi.Name; _fileSize = fi.Length; - //Console.WriteLine(ShortName + " is a valid file."); - // Read the RIFF header _stream = new FileStream(_fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); int fourCc; @@ -187,9 +185,6 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats } // Good header. Check size - //Console.WriteLine(ShortName + " has a valid type \"" + riff + "\""); - //Console.WriteLine(ShortName + " has a specific type of \"" + FromFourCC(fileType) + "\""); - _dataSize = datasize; if (_fileSize < _dataSize + TwoDWordSize) { diff --git a/libse/SubtitleFormats/Ebu.cs b/libse/SubtitleFormats/Ebu.cs index 3b75a644b..a7a9dd258 100644 --- a/libse/SubtitleFormats/Ebu.cs +++ b/libse/SubtitleFormats/Ebu.cs @@ -310,7 +310,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats else if (ch == 'ı' && TextField.Substring(index).StartsWith("ı̂")) // extended unicode char - rewritten as simple 'î' - looks the same as "î" but it's not...) { sbTwoChar.Append(encoding.GetString(new byte[] { 0xc3, 0x69 })); // Ãi - simple î - // sbTwoChar.Append(encoding.GetString(new byte[] { 0xc3, 0xf5 })); skipNext = true; } else if ("ÀÈÌÒÙàèìòù".Contains(ch)) diff --git a/libse/SubtitleFormats/F4Text.cs b/libse/SubtitleFormats/F4Text.cs index bb2dd9e25..8951b04d2 100644 --- a/libse/SubtitleFormats/F4Text.cs +++ b/libse/SubtitleFormats/F4Text.cs @@ -11,7 +11,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats /// public class F4Text : SubtitleFormat { - private static readonly Regex regexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d-\d$", RegexOptions.Compiled); + private static readonly Regex RegexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d-\d$", RegexOptions.Compiled); public override string Extension => ".txt"; @@ -30,15 +30,10 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats public static string ToF4Text(Subtitle subtitle) { var sb = new StringBuilder(); - //double lastEndTimeMilliseconds = -1; const string writeFormat = "{0}{1}"; foreach (Paragraph p in subtitle.Paragraphs) { - // if (p.StartTime.TotalMilliseconds == lastEndTimeMilliseconds) sb.AppendFormat(writeFormat, HtmlUtil.RemoveHtmlTags(p.Text, true), EncodeTimeCode(p.EndTime)); - //else - // sb.Append(string.Format("{0}{1}{2}", EncodeTimeCode(p.StartTime), HtmlUtil.RemoveHtmlTags(p.Text), EncodeTimeCode(p.EndTime))); - //lastEndTimeMilliseconds = p.EndTime.TotalMilliseconds; } return sb.ToString().Trim(); } @@ -79,7 +74,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats var currentText = new StringBuilder(); foreach (string line in arr) { - if (regexTimeCodes.IsMatch(line)) + if (RegexTimeCodes.IsMatch(line)) { if (p == null) { @@ -110,8 +105,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats { if (p == null && subtitle.Paragraphs.Count > 0) { - p = new Paragraph(); - p.StartTime.TotalMilliseconds = subtitle.Paragraphs[subtitle.Paragraphs.Count - 1].EndTime.TotalMilliseconds; + p = new Paragraph { StartTime = { TotalMilliseconds = subtitle.Paragraphs[subtitle.Paragraphs.Count - 1].EndTime.TotalMilliseconds } }; } currentText.AppendLine(line.Trim()); } diff --git a/libse/SubtitleFormats/Json.cs b/libse/SubtitleFormats/Json.cs index 506de409d..3e3d7ad4e 100644 --- a/libse/SubtitleFormats/Json.cs +++ b/libse/SubtitleFormats/Json.cs @@ -207,7 +207,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats } startIndex += tag.Length + 2; - string res = s.Substring(startIndex).TrimStart().TrimStart(':').TrimStart(); //.TrimStart('[').TrimStart(); + string res = s.Substring(startIndex).TrimStart().TrimStart(':').TrimStart(); int tagLevel = 1; int oldStart = 0; if (oldStart < res.Length && res[oldStart] == '[') diff --git a/libse/SubtitleFormats/NciCaption.cs b/libse/SubtitleFormats/NciCaption.cs index b8ff901a6..407bcaa86 100644 --- a/libse/SubtitleFormats/NciCaption.cs +++ b/libse/SubtitleFormats/NciCaption.cs @@ -15,10 +15,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats public static void Save(string fileName) { - using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write)) - { - //... - } } public override bool IsMine(List lines, string fileName) @@ -137,7 +133,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats buffer[7] == 0x32) { i = 396; - int start = i; int number = 0; while (i < buffer.Length - 66) { @@ -178,7 +173,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats } else { - //System.Windows.Forms.MessageBox.Show("Problem at with a length of " + length.ToString() + " at file position " + (i + 2) + " which gives remainer: " + (length % 14)); if (length % 14 == 8) { count++; diff --git a/libse/SubtitleFormats/Pac.cs b/libse/SubtitleFormats/Pac.cs index 7ecfd922b..2c31ad91d 100644 --- a/libse/SubtitleFormats/Pac.cs +++ b/libse/SubtitleFormats/Pac.cs @@ -1205,7 +1205,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats } } } - // text = text.Replace("", " "); text = text.Replace("", " "); text = text.Replace(" ", " "); return text.Replace(" " + Environment.NewLine, Environment.NewLine).Trim(); @@ -1627,7 +1626,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats return HebrewCodes[b].Character; } - return string.Empty;//string.Format("({0})", b); + return string.Empty; } public static string GetLatinString(Encoding encoding, byte[] buffer, ref int index) @@ -1681,7 +1680,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats } } - return string.Empty;//string.Format("({0})", b); + return string.Empty; } public static string GetGreekString(byte[] buffer, ref int index) @@ -1734,7 +1733,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats } } - return string.Empty;//string.Format("({0})", b); + return string.Empty; } internal static TimeCode GetTimeCode(int timeCodeIndex, byte[] buffer) diff --git a/libse/SubtitleFormats/ScenaristClosedCaptions.cs b/libse/SubtitleFormats/ScenaristClosedCaptions.cs index 4f68fd4bd..eb2b248e6 100644 --- a/libse/SubtitleFormats/ScenaristClosedCaptions.cs +++ b/libse/SubtitleFormats/ScenaristClosedCaptions.cs @@ -36,7 +36,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats private const string TimeCodeRegEx = @"^\d+:\d\d:\d\d[:,]\d\d\t"; private static readonly Regex Regex = new Regex(TimeCodeRegEx, RegexOptions.Compiled); protected virtual Regex RegexTimeCodes => Regex; - protected bool DropFrame = false; + protected bool DropFrame; public static List> LetterDictionary = new List> { diff --git a/libse/SubtitleFormats/Ultech130.cs b/libse/SubtitleFormats/Ultech130.cs index 9544b8cff..f69b2b433 100644 --- a/libse/SubtitleFormats/Ultech130.cs +++ b/libse/SubtitleFormats/Ultech130.cs @@ -118,34 +118,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats 0x17, 0x21, // 0x1721=center, 0x1722=right ? }; - //if (text.StartsWith("{\\a6}")) - //{ - // text = p.Text.Remove(0, 5); - // buffer[7] = 1; // align top - //} - //else if (text.StartsWith("{\\a1}")) - //{ - // text = p.Text.Remove(0, 5); - // buffer[8] = 0x0A; // align left - //} - //else if (text.StartsWith("{\\a3}")) - //{ - // text = p.Text.Remove(0, 5); - // buffer[8] = 0x1E; // align right - //} - //else if (text.StartsWith("{\\a5}")) - //{ - // text = p.Text.Remove(0, 5); - // buffer[7] = 1; // align top - // buffer[8] = 05; // align left - //} - //else if (text.StartsWith("{\\a7}")) - //{ - // text = p.Text.Remove(0, 5); - // buffer[7] = 1; // align top - // buffer[8] = 0xc; // align right - //} - fs.WriteByte(0xF1); //ID of start record // length @@ -248,7 +220,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats sb.Clear(); int skipCount = 0; bool italics = false; - //bool font = false; for (int k = start; k < length + i; k++) { byte b = buffer[k]; @@ -262,178 +233,23 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats skipCount = 1; if (sb.Length > 0 && !sb.ToString().EndsWith(Environment.NewLine, StringComparison.Ordinal) && !sb.EndsWith('>')) { - //if (font) - // sb.Append(""); if (italics) { sb.Append(""); } sb.AppendLine(); - //font = false; italics = false; } - //string code = VobSub.Helper.IntToBin(buffer[k] * 256 + buffer[k+1], 16); - //var codeBytes = new List(); - //if (b == 0x11 && b2 == 0x28) - //{ - // sb.Append(""); - // font = true; - //} - //else if (b == 0x11 && b2 == 0x2e) { sb.Append(""); italics = true; } - - //foreach (char ch in code) - // codeBytes.Insert(0, ch); - //if (codeBytes[13] == '0' && codeBytes[14] == '0' && codeBytes[12] == '1' && codeBytes[6] == '1') - //{ // preamble address code - // if (code.Substring(11, 4) == "1000") - // { - // sb.Append(""); - // font = true; - // } - // else if (code.Substring(11, 4) == "0010") - // { - // sb.Append(""); - // font = true; - // } - // else if (code.Substring(11, 4) == "0011") - // { - // sb.Append(""); - // font = true; - // } - // else if (code.Substring(11, 4) == "0100") - // { - // sb.Append(""); - // font = true; - // } - // else if (code.Substring(11, 4) == "0101") - // { - // sb.Append(""); - // font = true; - // } - // //else if (code.Substring(11, 4) == "0110") - // //{ - // // sb.Append(""); - // // font = true; - // //} - //} - //else if (codeBytes[14] == '0' && codeBytes[13] == '0' && codeBytes[10] == '0' && codeBytes[9] == '0' && codeBytes[6] == '0' && - // codeBytes[12] == '1' && codeBytes[8] == '1' && codeBytes[6] == '1') - //{ // midrow code - - // if (code.Substring(11, 4) == "1000") - // { - // sb.Append(""); - // font = true; - // } - // else if (code.Substring(11, 4) == "0010") - // { - // sb.Append(""); - // font = true; - // } - // else if (code.Substring(11, 4) == "0011") - // { - // sb.Append(""); - // font = true; - // } - // else if (code.Substring(11, 4) == "0100") - // { - // sb.Append(""); - // font = true; - // } - // else if (code.Substring(11, 4) == "0101") - // { - // sb.Append(""); - // font = true; - // } - // //else if (code.Substring(11, 4) == "0110") - // //{ - // // sb.Append(""); - // // font = true; - // //} - //} - //else if ((codeBytes[14] == '0' && codeBytes[13] == '0' && codeBytes[9] == '0' && codeBytes[6] == '0' && codeBytes[4] == '0' && - // codeBytes[12] == '1' && codeBytes[10] == '1' && codeBytes[5] == '1') || b == 0x11) - //{ // codeBytes[10] == 0 ??? - // //control codes - // if (code.Substring(11, 4) == "0111" && buffer[k] == 0x11) - // { - // sb.Append(""); - // italics = true; - // } - // else if (code.Substring(11, 4) == "1000") - // { - // sb.Append(""); - // font = true; - // } - // else if (code.Substring(11, 4) == "0010") - // { - // sb.Append(""); - // font = true; - // } - // else if (code.Substring(11, 4) == "0011") - // { - // sb.Append(""); - // font = true; - // } - // else if (code.Substring(11, 4) == "0100") - // { - // sb.Append(""); - // font = true; - // } - // else if (code.Substring(11, 4) == "0101") - // { - // sb.Append(""); - // font = true; - // } - // //else if (code.Substring(11, 4) == "0110") - // //{ - // // sb.Append(""); - // // font = true; - // //} - //} - //else - //{ - // if (code.Substring(11, 4) == "0111" && buffer[k] == 0x11) - // { - // sb.Append(""); - // italics = true; - // } - // else if (code.Substring(11, 4) == "0101" && b == 0x11) - // { - // sb.Append(""); - // font = true; - // } - //// if (code.Substring(11, 4) == "0111") - //// { - //// //System.Windows.Forms.MessageBox.Show(code); - //// sb.Append(""); - //// } - //// else if (code.Substring(11, 4) == "0101") - //// sb.Append(""); - //} } else if (b == 0x80) { - //if (sb.Length == 0) - // break; - - //if (sb.Length > 0 && !sb.ToString().EndsWith(Environment.NewLine)) - //{ - // if (font) - // sb.Append(""); - // if (italics) - // sb.Append(""); - // sb.AppendLine(); - // font = false; - // italics = false; - //} } else { @@ -441,8 +257,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats } } p.Text = sb.ToString().Trim(); - //if (font) - // p.Text += ""; if (italics) { p.Text += ""; @@ -478,6 +292,5 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats } public override List AlternateExtensions => new List { ".uld" }; // Ultech drop frame - } } diff --git a/libse/VobSub/Mpeg2Header.cs b/libse/VobSub/Mpeg2Header.cs index 0cd29f9e0..1fb82034c 100644 --- a/libse/VobSub/Mpeg2Header.cs +++ b/libse/VobSub/Mpeg2Header.cs @@ -11,8 +11,6 @@ namespace Nikse.SubtitleEdit.Core.VobSub public readonly UInt32 StartCode; public readonly byte PackIndentifier; - //public readonly UInt64 SystemClockReferenceQuotient; - //public readonly UInt64 SystemClockReferenceRemainder; public readonly UInt64 ProgramMuxRate; public readonly int PackStuffingLength; @@ -20,15 +18,7 @@ namespace Nikse.SubtitleEdit.Core.VobSub { StartCode = Helper.GetEndian(buffer, 0, 3); PackIndentifier = buffer[3]; - - //string b4To9AsBinary = Helper.GetBinaryString(buffer, 4, 6); - //b4To9AsBinary = b4To9AsBinary.Substring(2,3) + b4To9AsBinary.Substring(6,15) + b4To9AsBinary.Substring(22,15); - //SystemClockReferenceQuotient = Helper.GetUInt32FromBinaryString(b4To9AsBinary); - - //SystemClockReferenceRemainder = (ulong)(((buffer[8] & Helper.B00000011) << 8) + buffer[9]) - ProgramMuxRate = Helper.GetEndian(buffer, 10, 3) >> 2; - PackStuffingLength = buffer[13] & Helper.B00000111; } diff --git a/libse/VobSub/VobSubWriter.cs b/libse/VobSub/VobSubWriter.cs index e652f493f..dcec2fa20 100644 --- a/libse/VobSub/VobSubWriter.cs +++ b/libse/VobSub/VobSubWriter.cs @@ -124,7 +124,6 @@ namespace Nikse.SubtitleEdit.Core.VobSub // Control Sequence Table // Write delay - subtitle duration WriteEndianWord(Convert.ToInt32(p.Duration.TotalMilliseconds * 90.0) >> 10, ms); - // WriteEndianWord(Convert.ToInt32(p.Duration.TotalMilliseconds * 90.0 - 1023) >> 10, ms); // next display control sequence table address (use current is last) WriteEndianWord(startDisplayControlSequenceTableAddress + 24, ms); // start of display control sequence table address diff --git a/libse/WaveToVisualizer.cs b/libse/WaveToVisualizer.cs index 02c0696fa..0a5d4ef44 100644 --- a/libse/WaveToVisualizer.cs +++ b/libse/WaveToVisualizer.cs @@ -812,7 +812,6 @@ namespace Nikse.SubtitleEdit.Core if (endPaddingSampleCount > 0) { Array.Clear(chunkSamples, chunkSampleOffset, endPaddingSampleCount); - chunkSampleOffset += endPaddingSampleCount; } // generate spectrogram for this chunk @@ -820,10 +819,7 @@ namespace Nikse.SubtitleEdit.Core images.Add(bmp); // wait for previous image to finish saving - if (saveImageTask != null) - { - saveImageTask.Wait(); - } + saveImageTask?.Wait(); // save image string imagePath = Path.Combine(spectrogramDirectory, iChunk + ".gif"); @@ -834,10 +830,7 @@ namespace Nikse.SubtitleEdit.Core } // wait for last image to finish saving - if (saveImageTask != null) - { - saveImageTask.Wait(); - } + saveImageTask?.Wait(); var doc = new XmlDocument(); var culture = CultureInfo.InvariantCulture; diff --git a/src/Controls/AudioVisualizer.cs b/src/Controls/AudioVisualizer.cs index e4f5ce5db..7ea4a710a 100644 --- a/src/Controls/AudioVisualizer.cs +++ b/src/Controls/AudioVisualizer.cs @@ -1503,12 +1503,6 @@ namespace Nikse.SubtitleEdit.Controls } else { - //SHOW DEBUG MSG SolidBrush tBrush = new SolidBrush(Color.Turquoise); - //var g = this.CreateGraphics(); - //g.DrawString("AllowMovePrevOrNext: " + AllowMovePrevOrNext.ToString() + ", GapStart: " + _gapAtStart.ToString(), Font, tBrush, new PointF(100, 100)); - //tBrush.Dispose(); - //g.Dispose(); - OnTimeChanged?.Invoke(this, new ParagraphEventArgs(seconds, _mouseDownParagraph, _oldParagraph, _mouseDownParagraphType, AllowMovePrevOrNext)); Refresh(); return; diff --git a/src/Controls/VideoPlayerContainer.cs b/src/Controls/VideoPlayerContainer.cs index a73c67329..533a3e13d 100644 --- a/src/Controls/VideoPlayerContainer.cs +++ b/src/Controls/VideoPlayerContainer.cs @@ -727,7 +727,7 @@ namespace Nikse.SubtitleEdit.Controls Cursor.Hide(); } - private int _cursorStatus = 0; + private int _cursorStatus; public void ShowCursor() { diff --git a/src/Forms/AudioToText.cs b/src/Forms/AudioToText.cs index c3d49d15b..f712091c1 100644 --- a/src/Forms/AudioToText.cs +++ b/src/Forms/AudioToText.cs @@ -172,7 +172,6 @@ namespace Nikse.SubtitleEdit.Forms var output = new StringBuilder(); var path = Path.Combine(Configuration.DataDirectory, "pocketsphinx"); var fileName = Path.Combine(path, "bin", "Release", "Win32", "pocketsphinx_continuous.exe"); - // var fileName = Path.Combine(path, "bin", "Release", "x64", "pocketsphinx_continuous.exe"); var hmm = Path.Combine(path, "model", "en-us", "en-us"); var lm = Path.Combine(path, "model", "en-us", "en-us.lm.bin"); var dict = Path.Combine(path, "model", "en-us", "cmudict-en-us.dict"); diff --git a/src/Forms/HardSubExtract.cs b/src/Forms/HardSubExtract.cs index 1b7a70964..86151a711 100644 --- a/src/Forms/HardSubExtract.cs +++ b/src/Forms/HardSubExtract.cs @@ -20,7 +20,7 @@ namespace Nikse.SubtitleEdit.Forms //private System.Windows.Forms.Timer timer1; private const int lineChecksWidth = 50; private const int lineChecksHeight = 25; - public string OcrFileName = null; + public string OcrFileName; public HardSubExtract(string videoFileName) { diff --git a/src/Forms/Main.cs b/src/Forms/Main.cs index 1211226a4..a7f1f95f0 100644 --- a/src/Forms/Main.cs +++ b/src/Forms/Main.cs @@ -91,7 +91,7 @@ namespace Nikse.SubtitleEdit.Forms private int _repeatCount = -1; private double _endSeconds = -1; private double _endSecondsNewPosition = -1; - private long _endSecondsNewPositionTicks = 0; + private long _endSecondsNewPositionTicks; private const double EndDelay = 0.05; private int _autoContinueDelayCount = -1; private long _lastTextKeyDownTicks; @@ -104,7 +104,7 @@ namespace Nikse.SubtitleEdit.Forms private string _textAutoBackup; private string _textAutoBackupOriginal; private List _statusLog = new List(); - private bool _hideStatusLog = false; + private bool _hideStatusLog; private StatusLog _statusLogForm; private bool _makeHistoryPaused; private bool _saveAsCalled; diff --git a/src/Forms/Ocr/VobSubEditCharacters.cs b/src/Forms/Ocr/VobSubEditCharacters.cs index 671a22f37..cbdffe440 100644 --- a/src/Forms/Ocr/VobSubEditCharacters.cs +++ b/src/Forms/Ocr/VobSubEditCharacters.cs @@ -192,7 +192,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr } } texts.Sort(); - labelCount.Text = string.Format("{0:#,##0}", count); + labelCount.Text = $"{count:#,##0}"; comboBoxTexts.Items.Clear(); foreach (string text in texts) @@ -303,15 +303,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr if (bob != null) { bmp = bob.ToOldBitmap(); - labelImageInfo.Text = string.Format("Top:{0}, {1} colored pixels of {2}", bob.Y, bob.NumberOfColoredPixels, (bob.Width * bob.Height)); - - //bool italicI; - //var isI = bob.IsLowercaseI(out italicI); - //labelImageInfo.Text = string.Format("T:{0} j{1} :{2} i{3}{4} '{5} #{6}/{7}", bob.Y, bob.IsLowercaseJ(), bob.IsColon(), isI, italicI ? "i" : "", bob.IsApostrophe(), bob.NumberOfColoredPixels, (bob.Width * bob.Height)); - + labelImageInfo.Text = $"Top:{bob.Y}, {bob.NumberOfColoredPixels} colored pixels of {(bob.Width * bob.Height)}"; if (bob.ExpandCount > 0) { - labelExpandCount.Text = string.Format("Expand count: {0}", bob.ExpandCount); + labelExpandCount.Text = $"Expand count: {bob.ExpandCount}"; } } } @@ -353,7 +348,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr var bob = GetSelectedBinOcrBitmap(); foreach (var a in Additions) { - if (bob != null && bob.Text != null && bob.Key == a.Name) + if (bob?.Text != null && bob.Key == a.Name) { textBoxText.Text = a.Text; checkBoxItalic.Checked = a.Italic; diff --git a/src/Forms/Ocr/VobSubOcr.cs b/src/Forms/Ocr/VobSubOcr.cs index 36620b576..5a2d75545 100644 --- a/src/Forms/Ocr/VobSubOcr.cs +++ b/src/Forms/Ocr/VobSubOcr.cs @@ -2854,7 +2854,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr { if (!oc.IsSensitive) { - if (Math.Abs(oc.WidthPercent - widthPercent) < 40 && nbmp.Height > 11) // && oc.Height > 12 && oc.Width > 16 && nbmp.Width > 16 && nbmp.Height > 12 && Math.Abs(oc.MarginTop - topMargin) < 15) + if (Math.Abs(oc.WidthPercent - widthPercent) < 40 && nbmp.Height > 11) { bool ok = true; foreach (NOcrPoint op in oc.LinesForeground) diff --git a/src/Forms/Ocr/VobSubOcrNOcrCharacter.cs b/src/Forms/Ocr/VobSubOcrNOcrCharacter.cs index 4ddfdf157..91cb83916 100644 --- a/src/Forms/Ocr/VobSubOcrNOcrCharacter.cs +++ b/src/Forms/Ocr/VobSubOcrNOcrCharacter.cs @@ -615,7 +615,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr if (ok && IsMatchPointForeGround(op, !tempVeryPrecise, nbmp, nOcrChar)) { nOcrChar.LinesForeground.Add(op); - //AddHistoryItem(nOcrChar); hits++; } count++; @@ -675,7 +674,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr if (ok && IsMatchPointBackGround(op, !tempVeryPrecise, nbmp, nOcrChar)) { nOcrChar.LinesBackground.Add(op); - //AddHistoryItem(nOcrChar); hits++; } count++; diff --git a/src/Logic/DarkTheme.cs b/src/Logic/DarkTheme.cs index 2e65434d2..fa4b22497 100644 --- a/src/Logic/DarkTheme.cs +++ b/src/Logic/DarkTheme.cs @@ -74,7 +74,6 @@ namespace Nikse.SubtitleEdit.Logic if (iterations < 1) { // note: no need to restore the colors set are constants - //_isConfigUpdated = false; return; } @@ -146,7 +145,6 @@ namespace Nikse.SubtitleEdit.Logic c.BackColor = BackColor; c.ForeColor = ForeColor; - //c.Paint += C_Paint; } } FixControl(ctrl); diff --git a/src/Logic/NikseBitmapImageSplitter.cs b/src/Logic/NikseBitmapImageSplitter.cs index 60f53fff9..9f689d298 100644 --- a/src/Logic/NikseBitmapImageSplitter.cs +++ b/src/Logic/NikseBitmapImageSplitter.cs @@ -75,8 +75,6 @@ namespace Nikse.SubtitleEdit.Logic startTop++; } - //if (startTop > 9) - //startTop -= 5; // if top space > 9, then allways leave blank 5 pixels on top (so . is not confused with '). topCropping = startTop; int h = bmp.Height; @@ -204,9 +202,7 @@ namespace Nikse.SubtitleEdit.Logic if (size > 2) { NikseBitmap part = bmp.CopyRectangle(new Rectangle(0, startY, bmp.Width, size + 1)); - // part.Save("c:\\line_0_to_width.bmp"); parts.Add(new ImageSplitterItem(0, startY, part)); - // bmp.Save("c:\\original.bmp"); } size = 0; startY = y; @@ -264,9 +260,7 @@ namespace Nikse.SubtitleEdit.Logic if (size > 8) { NikseBitmap part = bmp.CopyRectangle(new Rectangle(0, startY, bmp.Width, size + 1)); - // part.Save("c:\\line_0_to_width.bmp"); parts.Add(new ImageSplitterItem(0, startY, part)); - // bmp.Save("c:\\original.bmp"); } size = 0; startY = y; diff --git a/src/Logic/VideoPlayers/QuartsPlayer.cs b/src/Logic/VideoPlayers/QuartsPlayer.cs index 6545b05bc..819256cfc 100644 --- a/src/Logic/VideoPlayers/QuartsPlayer.cs +++ b/src/Logic/VideoPlayers/QuartsPlayer.cs @@ -220,13 +220,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers private void VideoLoaderDoWork(object sender, DoWorkEventArgs e) { - //int i = 0; - //while (CurrentPosition < 1 && i < 100) - //{ Application.DoEvents(); - // System.Threading.Thread.Sleep(5); - // i++; - //} } private void VideoLoaderRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)