Add some err msg when user ocr fix replacelist is not valid - thx

sialivi :)
Related to #5845
This commit is contained in:
niksedk 2022-03-23 15:13:58 +01:00
parent b5e102bb0a
commit dfb4472d24
4 changed files with 30 additions and 3 deletions

View File

@ -30,6 +30,8 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
private const string ReplaceListFileNamePostFix = "_OCRFixReplaceList.xml";
public string ErrorMessage { get; set; }
public OcrFixReplaceList(string replaceListXmlFileName)
{
_replaceListXmlFileName = replaceListXmlFileName;
@ -994,9 +996,10 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
{
doc.Load(_replaceListXmlFileName);
}
catch
catch (Exception exception)
{
doc.LoadXml(xmlText);
ErrorMessage = $"Unable to load ocr replace list {_replaceListXmlFileName}: " + exception.Message;
}
}
else
@ -1018,9 +1021,10 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
{
doc.Load(ReplaceListXmlFileNameUser);
}
catch
catch (Exception exception)
{
doc.LoadXml(xmlText);
ErrorMessage = $"Unable to load ocr replace list {ReplaceListXmlFileNameUser}: " + exception.Message;
}
}
else
@ -1105,7 +1109,7 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
{
newNode.Attributes.Append(aFrom);
newNode.Attributes.Append(aTo);
wholeWordsNode?.AppendChild(newNode);
wholeWordsNode.AppendChild(newNode);
userDoc.Save(ReplaceListXmlFileNameUser);
}

View File

@ -729,6 +729,11 @@ namespace Nikse.SubtitleEdit.Forms
_ocrFixEngine?.Dispose();
_ocrFixEngineLanguage = threeLetterIsoLanguageName;
_ocrFixEngine = new OcrFixEngine(_ocrFixEngineLanguage, null, this);
var error = _ocrFixEngine.GetOcrFixReplaceListError();
if (error != null)
{
MessageBox.Show(error);
}
}
var fixAction = _language.FixCommonOcrErrors;

View File

@ -7320,6 +7320,12 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
}
var tempOcrFixEngine = new OcrFixEngine(threeLetterIsoLanguageName, hunspellName, this, _ocrMethodIndex == _ocrMethodBinaryImageCompare || _ocrMethodIndex == _ocrMethodNocr);
var error = _ocrFixEngine.GetOcrFixReplaceListError();
if (error != null)
{
MessageBox.Show(error);
}
if (tempOcrFixEngine.IsDictionaryLoaded)
{
_ocrFixEngine?.Dispose();

View File

@ -146,6 +146,18 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
UnknownWordsFound = new List<LogItem>();
}
public string GetOcrFixReplaceListError()
{
if (_ocrFixReplaceList == null)
{
return null;
}
var errorMessage = _ocrFixReplaceList.ErrorMessage;
_ocrFixReplaceList.ErrorMessage = null;
return errorMessage;
}
private void LoadSpellingDictionaries(string threeLetterIsoLanguageName, string hunspellName)
{
string dictionaryFolder = Utilities.DictionaryFolder;