This repository has been archived by the owner on Nov 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFMain.Methods.cs
256 lines (224 loc) · 6.72 KB
/
FMain.Methods.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
using OpenCCNET;
using System.Diagnostics;
using SubtitleGenerator.Commons.Extensions;
using SubtitleGenerator.Commons.Sets;
using static SubtitleGenerator.Commons.Sets.EnumSet;
using SubtitleGenerator.Commons.Utils;
using System.Reflection;
namespace SubtitleGenerator;
// 阻擋設計工具。
partial class DesignerBlocker { }
/// <summary>
/// FMain 的方法
/// </summary>
partial class FMain
{
/// <summary>
/// 自定義初始化
/// </summary>
private async void CustomInit()
{
// 設定顯示應用程式的版本號。
LVersion.InvokeIfRequired(() =>
{
LVersion.Text = $"版本:v{Assembly.GetExecutingAssembly().GetName().Version?.ToString()}";
});
// 設定控制項的工具提示。
GlobalTT.SetToolTip(CBModel, "模型");
GlobalTT.SetToolTip(CBQuantization, "量化");
GlobalTT.SetToolTip(CBLanguages, "語言");
GlobalTT.SetToolTip(CBSamplingStrategies, "抽樣策略");
GlobalTT.SetToolTip(CBEnableSpeedUp2x, "可能可以加快轉錄的速度,但同時也有可能會造成轉錄的內容更不精確");
GlobalTT.SetToolTip(CBEnableTranslate, "將轉錄的內容翻譯成英文");
GlobalTT.SetToolTip(CBEnableOpenCCS2TWP, "使用 OpenCC 將轉錄的內容,從「簡體中文」轉換成「繁體中文(臺灣)」");
GlobalTT.SetToolTip(CBEnableOpenCCTW2SP, "使用 OpenCC 將轉錄的內容,從「繁體中文(臺灣)」轉換成「簡體中文」");
// 設定控制項。
CBModel.InvokeIfRequired(() =>
{
CBModel.Text = "Medium";
});
CBQuantization.InvokeIfRequired(() =>
{
CBQuantization.Text = "No Quantization";
});
CBLanguages.InvokeIfRequired(() =>
{
CBLanguages.Text = "auto";
});
CBSamplingStrategies.InvokeIfRequired(() =>
{
CBSamplingStrategies.Text = "Default";
});
BtnCancel.InvokeIfRequired(() =>
{
BtnCancel.Enabled = false;
});
// 檢查資料夾。
CheckFolders();
// 檢查 FFmpeg。
await FFmpegUtil.CheckFFmpeg(this);
// 初始化 OpenCC。
ZhConverter.Initialize();
}
/// <summary>
/// 檢查資料夾
/// </summary>
private void CheckFolders()
{
if (!Directory.Exists(FolderSet.BinsFolderPath))
{
Directory.CreateDirectory(FolderSet.BinsFolderPath);
WriteLog(this, $"已建立資料夾:{FolderSet.BinsFolderPath}");
}
else
{
WriteLog(this, $"已找到資料夾:{FolderSet.BinsFolderPath}");
}
if (!Directory.Exists(FolderSet.ModelsFolderPath))
{
Directory.CreateDirectory(FolderSet.ModelsFolderPath);
WriteLog(this, $"已建立資料夾:{FolderSet.ModelsFolderPath}");
}
else
{
WriteLog(this, $"已找到資料夾:{FolderSet.ModelsFolderPath}");
}
if (!Directory.Exists(FolderSet.TempFolderPath))
{
Directory.CreateDirectory(FolderSet.TempFolderPath);
WriteLog(this, $"已建立資料夾:{FolderSet.TempFolderPath}");
}
else
{
WriteLog(this, $"已找到資料夾:{FolderSet.TempFolderPath}");
}
}
/// <summary>
/// 設定 OpenCC 相關的變數
/// </summary>
private void SetOpenCCVariables()
{
EnableOpenCC = CBEnableOpenCCS2TWP.Checked | CBEnableOpenCCTW2SP.Checked;
if (EnableOpenCC)
{
if (CBEnableOpenCCS2TWP.Checked)
{
GlobalOCCMode = OpenCCMode.S2TWP;
}
else if (CBEnableOpenCCTW2SP.Checked)
{
GlobalOCCMode = OpenCCMode.TW2SP;
}
else
{
GlobalOCCMode = OpenCCMode.None;
}
}
}
/// <summary>
/// 顯示錯誤訊息
/// </summary>
public static readonly Action<Form, string> ShowMsg =
new((Form form, string message) =>
{
if (string.IsNullOrEmpty(message))
{
return;
}
MessageBox.Show(
message,
form.Text,
MessageBoxButtons.OK);
});
/// <summary>
/// 顯示錯誤訊息
/// </summary>
public static readonly Action<Form, string> ShowErrMsg =
new((Form form, string message) =>
{
if (string.IsNullOrEmpty(message))
{
return;
}
MessageBox.Show(
message,
form.Text,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
});
/// <summary>
/// 顯示警告訊息
/// </summary>
public static readonly Action<Form, string> ShowWarnMsg =
new((Form form, string message) =>
{
if (string.IsNullOrEmpty(message))
{
return;
}
MessageBox.Show(
message,
form.Text,
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
});
/// <summary>
/// 開啟資料夾
/// </summary>
/// <param name="form">FMain</param>
/// <param name="path">字串,路徑</param>
public static void OpenFolder(FMain form, string path)
{
if (string.IsNullOrEmpty(path))
{
return;
}
try
{
Process.Start(new ProcessStartInfo
{
FileName = path,
UseShellExecute = true
});
}
catch (Exception ex)
{
ShowErrMsg(form, ex.ToString());
}
}
/// <summary>
/// 取得 TBLog(
/// </summary>
/// <returns>TextBox</returns>
public TextBox GetTBLog()
{
return TBLog;
}
/// <summary>
/// 寫紀錄
/// </summary>
/// <param name="form">FMain</param>
/// <param name="message">字串,訊息內容</param>
public static void WriteLog(FMain form, string message)
{
if (string.IsNullOrEmpty(message))
{
return;
}
try
{
TextBox textBox = form.GetTBLog();
textBox.InvokeIfRequired(() =>
{
textBox.Text += $"[{DateTime.Now:yyyy/MM/dd HH:mm:ss}] " +
$"{message}{Environment.NewLine}";
textBox.SelectionStart = textBox.TextLength;
textBox.ScrollToCaret();
});
}
catch (Exception ex)
{
ShowErrMsg(form, ex.ToString());
}
}
}