Skip to content

Commit 5e090aa

Browse files
authored
Merge pull request #126 from killkimno/1.300v
1.300v 업데이트
2 parents 563b0d9 + 99ffb14 commit 5e090aa

File tree

16 files changed

+516
-60
lines changed

16 files changed

+516
-60
lines changed

MORT/Form1.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//만든이 : 몽키해드
22
//블로그 주소 : https://blog.naver.com/killkimno
33

4+
using MORT.Logger;
45
using MORT.Manager;
56
using MORT.Model;
67
using MORT.OcrApi.WindowOcr;
@@ -661,6 +662,8 @@ private void InitTransCode()
661662
public Form1()
662663
{
663664
_versionCheckLogic = new VersionCheckLogic(this);
665+
//var logger = new LoggerForm();
666+
//logger.Show();
664667
try
665668
{
666669
_currentState = CurrentStateType.Init;
@@ -3230,7 +3233,9 @@ private void ChangeMainOcrLangauge(OcrLanguageType ocrLanguageType)
32303233
if(code != "other")
32313234
{
32323235
SetTransLangugage(code);
3233-
}
3236+
}
3237+
3238+
_currentOcrLanguage = ocrLanguageType;
32343239
}
32353240

32363241

MORT/FormOption.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ private void SetValueToUIValue()
169169
{
170170
_currentOcrLanguage = MySettingManager.OcrLanguageType;
171171
}
172-
int index = _ocrLanguages.IndexOf(_currentOcrLanguage);
172+
int index = _ocrLanguages.IndexOf(_currentOcrLanguage);
173173
cbOneOcrLanguage.SelectedIndex = index;
174174

175175
//색 관련 처리
@@ -707,7 +707,7 @@ public void ApplyUIValueToSetting()
707707

708708
setTessdata(tessData, isUseUnicode);
709709
}
710-
else if(MySettingManager.OCRType == SettingManager.OcrType.Window || MySettingManager.OCRType == SettingManager.OcrType.EasyOcr)
710+
else if(MySettingManager.OCRType is SettingManager.OcrType.Window or SettingManager.OcrType.EasyOcr or OcrType.OneOcr )
711711
{
712712
bool isUseJpn = false;
713713

MORT/Logger/LoggerForm.Designer.cs

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

MORT/Logger/LoggerForm.cs

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Windows.Forms;
4+
5+
namespace MORT.Logger
6+
{
7+
public partial class LoggerForm : Form
8+
{
9+
public LoggerForm()
10+
{
11+
InitializeComponent();
12+
SubscribeLogger();
13+
RefreshAll();
14+
}
15+
16+
// 폼이 닫힐 때 이벤트 구독 해제
17+
protected override void OnFormClosed(FormClosedEventArgs e)
18+
{
19+
UnsubscribeLogger();
20+
base.OnFormClosed(e);
21+
}
22+
23+
private void SubscribeLogger()
24+
{
25+
var logger = Logger.Instance;
26+
logger.LogAdded += Logger_LogAdded;
27+
logger.OcrCountIncreased += Logger_OcrCountIncreased;
28+
logger.TransCountIncreased += Logger_TransCountIncreased;
29+
}
30+
31+
private void UnsubscribeLogger()
32+
{
33+
var logger = Logger.Instance;
34+
logger.LogAdded -= Logger_LogAdded;
35+
logger.OcrCountIncreased -= Logger_OcrCountIncreased;
36+
logger.TransCountIncreased -= Logger_TransCountIncreased;
37+
}
38+
39+
private void Logger_LogAdded(object? sender, Logger.LogEventArgs e)
40+
{
41+
SafeInvoke(() =>
42+
{
43+
// 새 로그를 끝에 추가
44+
if(string.IsNullOrEmpty(richTextBox1.Text))
45+
richTextBox1.Text = e.Message;
46+
else
47+
richTextBox1.AppendText(Environment.NewLine + e.Message);
48+
49+
ScrollRichTextBoxToBottom();
50+
});
51+
}
52+
53+
private void Logger_OcrCountIncreased(object? sender, Logger.CountChangedEventArgs e)
54+
{
55+
RefreshCountsSafe();
56+
}
57+
58+
private void Logger_TransCountIncreased(object? sender, Logger.CountChangedEventArgs e)
59+
{
60+
RefreshCountsSafe();
61+
}
62+
63+
private void RefreshAll()
64+
{
65+
SafeInvoke(() =>
66+
{
67+
richTextBox1.Text = string.Join(Environment.NewLine, Logger.Instance.LogList);
68+
ScrollRichTextBoxToBottom();
69+
RefreshCounts();
70+
});
71+
}
72+
73+
private void RefreshCountsSafe()
74+
{
75+
SafeInvoke(RefreshCounts);
76+
}
77+
78+
private void RefreshCounts()
79+
{
80+
richTextBox2.Text = $"OCR Count: {Logger.Instance.OcrTryCount}{Environment.NewLine}Trans Count: {Logger.Instance.TransCount}";
81+
}
82+
83+
private void ScrollRichTextBoxToBottom()
84+
{
85+
// caret 이동 후 스크롤
86+
richTextBox1.SelectionStart = richTextBox1.TextLength;
87+
richTextBox1.SelectionLength = 0;
88+
richTextBox1.ScrollToCaret();
89+
}
90+
91+
private void SafeInvoke(Action action)
92+
{
93+
if(InvokeRequired)
94+
BeginInvoke(action);
95+
else
96+
action();
97+
}
98+
}
99+
100+
// Logger 클래스는 변경없음 (생략 가능)
101+
public class Logger
102+
{
103+
// 내부 데이터
104+
private readonly List<string> logList = new List<string>();
105+
private int ocrTryCount;
106+
private int transCount;
107+
108+
// 로그 인덱스 카운터 (스레드 안전하게 증가)
109+
private int logCounter;
110+
111+
// 싱글톤 인스턴스 (static 메서드가 내부 상태를 변경할 수 있도록)
112+
private static readonly Logger _instance = new Logger();
113+
public static Logger Instance => _instance;
114+
115+
// 이벤트 인자
116+
public class LogEventArgs : EventArgs
117+
{
118+
public string Message { get; }
119+
public LogEventArgs(string message) => Message = message;
120+
}
121+
122+
public class CountChangedEventArgs : EventArgs
123+
{
124+
public int NewValue { get; }
125+
public CountChangedEventArgs(int newValue) => NewValue = newValue;
126+
}
127+
128+
// 이벤트: 스트링 추가, ocr 카운트 업, trans 카운트 업
129+
public event EventHandler<LogEventArgs>? LogAdded;
130+
public event EventHandler<CountChangedEventArgs>? OcrCountIncreased;
131+
public event EventHandler<CountChangedEventArgs>? TransCountIncreased;
132+
133+
// 외부 접근용 읽기 전용
134+
public IReadOnlyList<string> LogList => logList.AsReadOnly();
135+
public int OcrTryCount => ocrTryCount;
136+
public int TransCount => transCount;
137+
138+
// 로그 추가 (static wrapper)
139+
public static void AddLog(string message)
140+
{
141+
return;
142+
if(message == null) throw new ArgumentNullException(nameof(message));
143+
_instance.AddLogInternal(message);
144+
}
145+
146+
private void AddLogInternal(string message)
147+
{
148+
// 인덱스 생성 (1부터 시작)
149+
var index = System.Threading.Interlocked.Increment(ref logCounter);
150+
var formatted = $"[{index}] {message}";
151+
152+
lock(logList)
153+
{
154+
logList.Add(formatted);
155+
}
156+
LogAdded?.Invoke(this, new LogEventArgs(formatted));
157+
}
158+
159+
// OCR/Trans 카운트 증가 - static wrapper
160+
public static void IncrementOcr()
161+
{
162+
return;
163+
_instance.IncrementOcrInternal();
164+
}
165+
166+
// Trans 카운트 증가 - static wrapper
167+
public static void IncrementTrans()
168+
{
169+
return;
170+
_instance.IncrementTransInternal();
171+
}
172+
173+
// 내부 인스턴스 구현 (직접 호출 금지)
174+
private void IncrementOcrInternal()
175+
{
176+
var newVal = System.Threading.Interlocked.Increment(ref ocrTryCount);
177+
OcrCountIncreased?.Invoke(this, new CountChangedEventArgs(newVal));
178+
}
179+
180+
private void IncrementTransInternal()
181+
{
182+
var newVal = System.Threading.Interlocked.Increment(ref transCount);
183+
TransCountIncreased?.Invoke(this, new CountChangedEventArgs(newVal));
184+
}
185+
186+
// 선택적 인스턴스 메서드 유지
187+
public void IncrementOcrInstance() => IncrementOcrInternal();
188+
public void IncrementTransInstance() => IncrementTransInternal();
189+
}
190+
}

0 commit comments

Comments
 (0)