Minor clean

This commit is contained in:
niksedk 2023-09-25 06:55:28 +02:00
parent 0863ddb217
commit 1ce86dd197
3 changed files with 27 additions and 25 deletions

View File

@ -32,5 +32,6 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nikse/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Purfview/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tahoma/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tesseract/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unbreak/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Undocked/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -40,21 +40,21 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
comboBoxDictionaries.UsePopupWindow = true;
}
private void LoadDictionaryList(string xmlRessourceName)
private void LoadDictionaryList(string xmlResourceName)
{
_dictionaryDownloadLinks = new List<string>();
_xmlName = xmlRessourceName;
_xmlName = xmlResourceName;
System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
Stream strm = asm.GetManifestResourceStream(_xmlName);
if (strm != null)
var stream = asm.GetManifestResourceStream(_xmlName);
if (stream != null)
{
comboBoxDictionaries.Items.Clear();
XmlDocument doc = new XmlDocument();
using (var rdr = new StreamReader(strm))
var doc = new XmlDocument();
using (var rdr = new StreamReader(stream))
using (var zip = new GZipStream(rdr.BaseStream, CompressionMode.Decompress))
{
byte[] data = new byte[195000];
int bytesRead = zip.Read(data, 0, data.Length);
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
{
@ -68,11 +68,11 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
foreach (XmlNode node in doc.DocumentElement.SelectNodes("Dictionary"))
{
string englishName = node.SelectSingleNode("EnglishName").InnerText;
string downloadLink = node.SelectSingleNode("DownloadLink").InnerText;
var englishName = node.SelectSingleNode("EnglishName").InnerText;
var downloadLink = node.SelectSingleNode("DownloadLink").InnerText;
if (!string.IsNullOrEmpty(downloadLink))
{
string name = englishName;
var name = englishName;
comboBoxDictionaries.Items.Add(name);
_dictionaryDownloadLinks.Add(downloadLink);
@ -101,8 +101,8 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
Refresh();
Cursor = Cursors.WaitCursor;
int index = comboBoxDictionaries.SelectedIndex;
string url = _dictionaryDownloadLinks[index];
var index = comboBoxDictionaries.SelectedIndex;
var url = _dictionaryDownloadLinks[index];
ChosenLanguage = comboBoxDictionaries.Items[index].ToString();
try
@ -232,7 +232,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void linkLabelOpenDictionaryFolder_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string dictionaryFolder = Configuration.Tesseract302DataDirectory;
var dictionaryFolder = Configuration.Tesseract302DataDirectory;
if (!Directory.Exists(dictionaryFolder))
{
Directory.CreateDirectory(dictionaryFolder);

View File

@ -43,9 +43,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
comboBoxDictionaries.BeginUpdate();
comboBoxDictionaries.Items.Clear();
for (int i = 0; i < _dictionaries.Count; i++)
for (var i = 0; i < _dictionaries.Count; i++)
{
TesseractDictionary d = _dictionaries[i];
var d = _dictionaries[i];
if (!string.IsNullOrEmpty(d.Url))
{
comboBoxDictionaries.Items.Add(d);
@ -55,10 +55,12 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
}
}
}
if (comboBoxDictionaries.SelectedIndex < 0)
{
comboBoxDictionaries.SelectedIndex = 0;
}
comboBoxDictionaries.EndUpdate();
}
@ -74,8 +76,8 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void buttonDownload_Click(object sender, EventArgs e)
{
int index = comboBoxDictionaries.SelectedIndex;
string url = _dictionaries[index].Url;
var index = comboBoxDictionaries.SelectedIndex;
var url = _dictionaries[index].Url;
try
{
labelPleaseWait.Text = LanguageSettings.Current.General.PleaseWait;
@ -138,19 +140,19 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
throw new Exception("No content downloaded - missing file or no internet connection!");
}
string dictionaryFolder = Configuration.TesseractDataDirectory;
var dictionaryFolder = Configuration.TesseractDataDirectory;
if (!Directory.Exists(dictionaryFolder))
{
Directory.CreateDirectory(dictionaryFolder);
}
int index = comboBoxDictionaries.SelectedIndex;
var index = comboBoxDictionaries.SelectedIndex;
downloadStream.Position = 0;
var tempFileName = FileUtil.GetTempFileName(".tar");
using (var fs = new FileStream(tempFileName, FileMode.Create))
using (var zip = new GZipStream(downloadStream, CompressionMode.Decompress))
{
byte[] buffer = new byte[1024];
var buffer = new byte[1024];
int nRead;
while ((nRead = zip.Read(buffer, 0, buffer.Length)) > 0)
{
@ -162,7 +164,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{
foreach (var th in tr.Files)
{
string fn = Path.Combine(dictionaryFolder, Path.GetFileName(th.FileName.Trim()));
var fn = Path.Combine(dictionaryFolder, Path.GetFileName(th.FileName.Trim()));
th.WriteData(fn);
}
}
@ -189,12 +191,11 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
Directory.CreateDirectory(dictionaryFolder);
}
int index = comboBoxDictionaries.SelectedIndex;
var index = comboBoxDictionaries.SelectedIndex;
using (var fs = new FileStream(Path.Combine(dictionaryFolder, _dictionaryFileName), FileMode.Create))
{
downloadStream.Position = 0;
byte[] buffer = new byte[1024];
var buffer = new byte[1024];
int nRead;
while ((nRead = downloadStream.Read(buffer, 0, buffer.Length)) > 0)
{