Skip to content

Commit 563b0d9

Browse files
authored
Merge pull request #123 from killkimno/1.300v
1.304 업데이트
2 parents 5f55a11 + 4131abf commit 563b0d9

File tree

8 files changed

+166
-124
lines changed

8 files changed

+166
-124
lines changed

MORT/Manager/TransManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ private async Task<string> GetTransLinesAsync(List<string> textList, SettingMana
647647
}
648648
else if(transType == SettingManager.TransType.deepl)
649649
{
650-
transResult = _deepLTranslateAPI.DoTrans(ocrText, ref isError);
650+
transResult = _deepLTranslateAPI.DoTrans(ocrText, ref isError, _cts.Token);
651651

652652
if(isError && AdvencedOptionManager.UseDeeplAltOption)
653653
{

MORT/Properties/Settings.Designer.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MORT/Properties/Settings.settings

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
<Profiles />
44
<Settings>
55
<Setting Name="MORT_VERSION" Type="System.String" Scope="Application">
6-
<Value Profile="(Default)">1.303V</Value>
6+
<Value Profile="(Default)">1.304V</Value>
77
</Setting>
88
<Setting Name="LAYER_TEXT" Type="System.String" Scope="Application">
99
<Value Profile="(Default)">MORT {0}
1010
레이어 번역창</Value>
1111
</Setting>
1212
<Setting Name="MORT_VERSION_VALUE" Type="System.Int32" Scope="Application">
13-
<Value Profile="(Default)">1303</Value>
13+
<Value Profile="(Default)">1304</Value>
1414
</Setting>
1515
<Setting Name="TOOLTIP_LIST" Type="System.String" Scope="Application">
1616
<Value Profile="(Default)">MORT를 처음 쓰시면 그 외-&gt; MORT 사용법을 확인해 주세요,

MORT/Service/ProcessTranslateService/ProcessTranslateService.cs

Lines changed: 53 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -717,84 +717,78 @@ private async Task DoTrans(OcrMethodType ocrMethodType)
717717

718718
else if(_settingManager.OCRType == SettingManager.OcrType.OneOcr)
719719
{
720-
if(_winOcr.GetIsAvailable())
720+
721+
unsafe
721722
{
722-
unsafe
723-
{
724-
Util.CheckTimeSpan(true);
725-
int ocrAreaCount = FormManager.Instace.GetOcrAreaCount();
726-
List<ImgData> imgDataList = new List<ImgData>();
723+
Util.CheckTimeSpan(true);
724+
int ocrAreaCount = FormManager.Instace.GetOcrAreaCount();
725+
List<ImgData> imgDataList = new List<ImgData>();
727726

728-
if(_settingManager.isUseAttachedCapture)
729-
{
730-
MakeImgModelsFromCapture(ocrAreaCount, imgDataList, ref clientPositionX, ref clientPositionY);
731-
}
732-
else
733-
{
734-
MakeImgModels(ocrAreaCount, imgDataList, ref clientPositionX, ref clientPositionY);
735-
}
727+
if(_settingManager.isUseAttachedCapture)
728+
{
729+
MakeImgModelsFromCapture(ocrAreaCount, imgDataList, ref clientPositionX, ref clientPositionY);
730+
}
731+
else
732+
{
733+
MakeImgModels(ocrAreaCount, imgDataList, ref clientPositionX, ref clientPositionY);
734+
}
736735

737-
if(isEndFlag)
738-
{
739-
break;
740-
}
736+
if(isEndFlag)
737+
{
738+
break;
739+
}
741740

742-
string ocrResult = "";
743-
string transResult = "";
744-
finalTransResult = "";
741+
string ocrResult = "";
742+
string transResult = "";
743+
finalTransResult = "";
745744

746-
OCRDataManager.Instace.ClearData();
747-
for(int j = 0; j < imgDataList.Count; j++)
748-
{
749-
Util.CheckTimeSpan(false);
745+
OCRDataManager.Instace.ClearData();
746+
for(int j = 0; j < imgDataList.Count; j++)
747+
{
748+
Util.CheckTimeSpan(false);
750749

751-
var task = _oneOcr.ConvertToTextAsync(imgDataList[j].data, imgDataList[j].channels, imgDataList[j].x, imgDataList[j].y, imgDataList[j].Clear).ConfigureAwait(false);
750+
var task = _oneOcr.ConvertToTextAsync(imgDataList[j].data, imgDataList[j].channels, imgDataList[j].x, imgDataList[j].y, imgDataList[j].Clear).ConfigureAwait(false);
752751

753-
var result = task.GetAwaiter().GetResult();
754-
if(result == null)
752+
var result = task.GetAwaiter().GetResult();
753+
if(result == null)
754+
{
755+
// 백그라운드에서 UI를 직접 호출하지 않음. UI 스레드에서 알리고 종료 트리거.
756+
_parent.BeginInvoke((Action)(() =>
755757
{
756-
// 백그라운드에서 UI를 직접 호출하지 않음. UI 스레드에서 알리고 종료 트리거.
757-
_parent.BeginInvoke((Action)(() =>
758+
if(MessageBox.Show(LocalizeString("Unable Use OCR Snipping Tool OCR Error"), "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
758759
{
759-
if(MessageBox.Show(LocalizeString("Unable Use OCR Snipping Tool OCR Error"), "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
760-
{
761760

762-
Util.OpenURL("https://blog.naver.com/killkimno/224097385261");
763-
}
761+
Util.OpenURL("https://blog.naver.com/killkimno/224097385261");
762+
}
764763

765-
OnStopTranslate?.Invoke(true);
766-
}));
764+
OnStopTranslate?.Invoke(true);
765+
}));
767766

768-
// 작업 취소 플래그 설정 후 안전히 반환
769-
_cts.Cancel();
770-
isEndFlag = true;
771-
return;
772-
}
773-
774-
ocrResult = "";
775-
foreach(var line in result)
776-
{
777-
ocrResult += line.Text + System.Environment.NewLine;
778-
}
767+
// 작업 취소 플래그 설정 후 안전히 반환
768+
_cts.Cancel();
769+
isEndFlag = true;
770+
return;
771+
}
779772

780-
OCRDataManager.ResultData resultModel = OCRDataManager.Instace.AddData(new OcrResult(result), j, ocrMethodType == OcrMethodType.Snap, _settingManager.NowIsRemoveSpace);
773+
ocrResult = "";
774+
foreach(var line in result)
775+
{
776+
ocrResult += line.Text + System.Environment.NewLine;
777+
}
781778

782-
MakeFinalOcrAndTrans(j, resultModel, imgDataList, ocrResult, ref ocrResult, ref finalTransResult);
779+
OCRDataManager.ResultData resultModel = OCRDataManager.Instace.AddData(new OcrResult(result), j, ocrMethodType == OcrMethodType.Snap, _settingManager.NowIsRemoveSpace);
783780

784-
imgDataList[j].ClearOriginalData();
781+
MakeFinalOcrAndTrans(j, resultModel, imgDataList, ocrResult, ref ocrResult, ref finalTransResult);
785782

786-
}
783+
imgDataList[j].ClearOriginalData();
787784

788-
NowOcrString = ocrResult;
789-
imgDataList.Clear();
790-
imgDataList = null;
791785
}
786+
787+
NowOcrString = ocrResult;
788+
imgDataList.Clear();
789+
imgDataList = null;
792790
}
793-
else
794-
{
795-
//준비되지 않았으면 이전과 같게 처리.
796-
NowOcrString = formerOcrString;
797-
}
791+
798792
}
799793
#endregion
800794

MORT/TransAPI/DeepLTranslateAPI.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Text.RegularExpressions;
3+
using System.Threading;
34
using System.Threading.Tasks;
45

56
namespace MORT.TransAPI
@@ -123,7 +124,7 @@ public void ShowWebview()
123124
}
124125
}
125126

126-
public string DoTrans(string original, ref bool isError)
127+
public string DoTrans(string original, ref bool isError, CancellationToken ct)
127128
{
128129
if(_unavailableWebview)
129130
{
@@ -155,7 +156,7 @@ public string DoTrans(string original, ref bool isError)
155156
{
156157
_view.DoTrans(original, _transCode, _resultCode);
157158
}
158-
var task = WaitResultAsync();
159+
var task = WaitResultAsync(ct);
159160
string result = task.Result.Item1;
160161
if(result.Length >=4)
161162
{
@@ -189,17 +190,17 @@ public string DoTrans(string original, ref bool isError)
189190
return result;
190191
}
191192

192-
private async Task<(string, bool)> WaitResultAsync()
193+
private async Task<(string, bool)> WaitResultAsync(CancellationToken ct)
193194
{
194195
while(!_view.Complete)
195196
{
196-
if (_dtTimeOut < DateTime.Now)
197+
if (_dtTimeOut < DateTime.Now && false)
197198
{
198199
Console.WriteLine($"api {_dtTimeOut} / now {DateTime.Now}");
199200

200201
return ("TimeOut", true);
201202
}
202-
await Task.Delay(80);
203+
await Task.Delay(80, cancellationToken:ct);
203204
}
204205

205206
return (_view.LastResult, false);

0 commit comments

Comments
 (0)