mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 03:02:35 +01:00
Minor clean
This commit is contained in:
parent
0863ddb217
commit
1ce86dd197
@ -32,5 +32,6 @@
|
|||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nikse/@EntryIndexedValue">True</s:Boolean>
|
<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/=Purfview/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tahoma/@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/=Unbreak/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Undocked/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Undocked/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
@ -40,21 +40,21 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
|
|||||||
comboBoxDictionaries.UsePopupWindow = true;
|
comboBoxDictionaries.UsePopupWindow = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadDictionaryList(string xmlRessourceName)
|
private void LoadDictionaryList(string xmlResourceName)
|
||||||
{
|
{
|
||||||
_dictionaryDownloadLinks = new List<string>();
|
_dictionaryDownloadLinks = new List<string>();
|
||||||
_xmlName = xmlRessourceName;
|
_xmlName = xmlResourceName;
|
||||||
System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
|
System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
|
||||||
Stream strm = asm.GetManifestResourceStream(_xmlName);
|
var stream = asm.GetManifestResourceStream(_xmlName);
|
||||||
if (strm != null)
|
if (stream != null)
|
||||||
{
|
{
|
||||||
comboBoxDictionaries.Items.Clear();
|
comboBoxDictionaries.Items.Clear();
|
||||||
XmlDocument doc = new XmlDocument();
|
var doc = new XmlDocument();
|
||||||
using (var rdr = new StreamReader(strm))
|
using (var rdr = new StreamReader(stream))
|
||||||
using (var zip = new GZipStream(rdr.BaseStream, CompressionMode.Decompress))
|
using (var zip = new GZipStream(rdr.BaseStream, CompressionMode.Decompress))
|
||||||
{
|
{
|
||||||
byte[] data = new byte[195000];
|
var data = new byte[195000];
|
||||||
int bytesRead = zip.Read(data, 0, data.Length);
|
var bytesRead = zip.Read(data, 0, data.Length);
|
||||||
var s = System.Text.Encoding.UTF8.GetString(data, 0, bytesRead).Trim();
|
var s = System.Text.Encoding.UTF8.GetString(data, 0, bytesRead).Trim();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -68,11 +68,11 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
|
|||||||
|
|
||||||
foreach (XmlNode node in doc.DocumentElement.SelectNodes("Dictionary"))
|
foreach (XmlNode node in doc.DocumentElement.SelectNodes("Dictionary"))
|
||||||
{
|
{
|
||||||
string englishName = node.SelectSingleNode("EnglishName").InnerText;
|
var englishName = node.SelectSingleNode("EnglishName").InnerText;
|
||||||
string downloadLink = node.SelectSingleNode("DownloadLink").InnerText;
|
var downloadLink = node.SelectSingleNode("DownloadLink").InnerText;
|
||||||
if (!string.IsNullOrEmpty(downloadLink))
|
if (!string.IsNullOrEmpty(downloadLink))
|
||||||
{
|
{
|
||||||
string name = englishName;
|
var name = englishName;
|
||||||
|
|
||||||
comboBoxDictionaries.Items.Add(name);
|
comboBoxDictionaries.Items.Add(name);
|
||||||
_dictionaryDownloadLinks.Add(downloadLink);
|
_dictionaryDownloadLinks.Add(downloadLink);
|
||||||
@ -101,8 +101,8 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
|
|||||||
Refresh();
|
Refresh();
|
||||||
Cursor = Cursors.WaitCursor;
|
Cursor = Cursors.WaitCursor;
|
||||||
|
|
||||||
int index = comboBoxDictionaries.SelectedIndex;
|
var index = comboBoxDictionaries.SelectedIndex;
|
||||||
string url = _dictionaryDownloadLinks[index];
|
var url = _dictionaryDownloadLinks[index];
|
||||||
ChosenLanguage = comboBoxDictionaries.Items[index].ToString();
|
ChosenLanguage = comboBoxDictionaries.Items[index].ToString();
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -232,7 +232,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
|
|||||||
|
|
||||||
private void linkLabelOpenDictionaryFolder_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
private void linkLabelOpenDictionaryFolder_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
||||||
{
|
{
|
||||||
string dictionaryFolder = Configuration.Tesseract302DataDirectory;
|
var dictionaryFolder = Configuration.Tesseract302DataDirectory;
|
||||||
if (!Directory.Exists(dictionaryFolder))
|
if (!Directory.Exists(dictionaryFolder))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(dictionaryFolder);
|
Directory.CreateDirectory(dictionaryFolder);
|
||||||
|
@ -43,9 +43,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
|
|||||||
{
|
{
|
||||||
comboBoxDictionaries.BeginUpdate();
|
comboBoxDictionaries.BeginUpdate();
|
||||||
comboBoxDictionaries.Items.Clear();
|
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))
|
if (!string.IsNullOrEmpty(d.Url))
|
||||||
{
|
{
|
||||||
comboBoxDictionaries.Items.Add(d);
|
comboBoxDictionaries.Items.Add(d);
|
||||||
@ -55,10 +55,12 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (comboBoxDictionaries.SelectedIndex < 0)
|
if (comboBoxDictionaries.SelectedIndex < 0)
|
||||||
{
|
{
|
||||||
comboBoxDictionaries.SelectedIndex = 0;
|
comboBoxDictionaries.SelectedIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
comboBoxDictionaries.EndUpdate();
|
comboBoxDictionaries.EndUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,8 +76,8 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
|
|||||||
|
|
||||||
private void buttonDownload_Click(object sender, EventArgs e)
|
private void buttonDownload_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
int index = comboBoxDictionaries.SelectedIndex;
|
var index = comboBoxDictionaries.SelectedIndex;
|
||||||
string url = _dictionaries[index].Url;
|
var url = _dictionaries[index].Url;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
labelPleaseWait.Text = LanguageSettings.Current.General.PleaseWait;
|
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!");
|
throw new Exception("No content downloaded - missing file or no internet connection!");
|
||||||
}
|
}
|
||||||
|
|
||||||
string dictionaryFolder = Configuration.TesseractDataDirectory;
|
var dictionaryFolder = Configuration.TesseractDataDirectory;
|
||||||
if (!Directory.Exists(dictionaryFolder))
|
if (!Directory.Exists(dictionaryFolder))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(dictionaryFolder);
|
Directory.CreateDirectory(dictionaryFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = comboBoxDictionaries.SelectedIndex;
|
var index = comboBoxDictionaries.SelectedIndex;
|
||||||
downloadStream.Position = 0;
|
downloadStream.Position = 0;
|
||||||
var tempFileName = FileUtil.GetTempFileName(".tar");
|
var tempFileName = FileUtil.GetTempFileName(".tar");
|
||||||
using (var fs = new FileStream(tempFileName, FileMode.Create))
|
using (var fs = new FileStream(tempFileName, FileMode.Create))
|
||||||
using (var zip = new GZipStream(downloadStream, CompressionMode.Decompress))
|
using (var zip = new GZipStream(downloadStream, CompressionMode.Decompress))
|
||||||
{
|
{
|
||||||
byte[] buffer = new byte[1024];
|
var buffer = new byte[1024];
|
||||||
int nRead;
|
int nRead;
|
||||||
while ((nRead = zip.Read(buffer, 0, buffer.Length)) > 0)
|
while ((nRead = zip.Read(buffer, 0, buffer.Length)) > 0)
|
||||||
{
|
{
|
||||||
@ -162,7 +164,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
|
|||||||
{
|
{
|
||||||
foreach (var th in tr.Files)
|
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);
|
th.WriteData(fn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -189,12 +191,11 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
|
|||||||
Directory.CreateDirectory(dictionaryFolder);
|
Directory.CreateDirectory(dictionaryFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = comboBoxDictionaries.SelectedIndex;
|
var index = comboBoxDictionaries.SelectedIndex;
|
||||||
|
|
||||||
using (var fs = new FileStream(Path.Combine(dictionaryFolder, _dictionaryFileName), FileMode.Create))
|
using (var fs = new FileStream(Path.Combine(dictionaryFolder, _dictionaryFileName), FileMode.Create))
|
||||||
{
|
{
|
||||||
downloadStream.Position = 0;
|
downloadStream.Position = 0;
|
||||||
byte[] buffer = new byte[1024];
|
var buffer = new byte[1024];
|
||||||
int nRead;
|
int nRead;
|
||||||
while ((nRead = downloadStream.Read(buffer, 0, buffer.Length)) > 0)
|
while ((nRead = downloadStream.Read(buffer, 0, buffer.Length)) > 0)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user