Refactor dictionary loading in GetTesseract302Dictionaries

Streamlined the loading of dictionaries in the GetTesseract302Dictionaries file by using XmlReader directly on the decompressed stream. This change simplifies the processing flow and reduces the overall amount of coding needed.

Signed-off-by: Ivandro Jao <ivandrofly@gmail.com>
This commit is contained in:
Ivandro Jao 2024-06-29 03:03:57 +01:00
parent 06f8d56aeb
commit 6f4e25e022

View File

@ -61,15 +61,12 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
comboBoxDictionaries.Items.Clear();
var doc = new XmlDocument();
using (var rdr = new StreamReader(stream))
using (var zip = new GZipStream(rdr.BaseStream, CompressionMode.Decompress))
using (var zip = new GZipStream(stream, CompressionMode.Decompress))
using (var reader = XmlReader.Create(zip, new XmlReaderSettings { IgnoreProcessingInstructions = true }))
{
var data = new byte[195000];
var bytesRead = zip.Read(data, 0, data.Length);
var s = System.Text.Encoding.UTF8.GetString(data, 0, bytesRead).Trim();
try
{
doc.LoadXml(s);
doc.Load(reader);
}
catch (Exception exception)
{