优化语言包工具

This commit is contained in:
gb 2023-01-28 15:21:23 +08:00
parent 5a4d19a165
commit 32ee6eb73d
5 changed files with 86 additions and 1 deletions

View File

@ -515,7 +515,7 @@ void CDlgLang::add_2_list(void* lang_list, int id, bool unic)
list_.SetItemText(ind, 1, std::to_wstring(v.id).c_str());
coding_util::utf8_2_unicode(v.utf8.c_str(), sdk_util::got_wstr, &text);
list_.SetItemText(ind, 2, std::to_wstring(v.id).c_str());
list_.SetItemText(ind, 2, text.c_str());
}
}
}
@ -578,7 +578,9 @@ void CDlgLang::on_hz_pak_initialized(bool success)
lang_.EnableWindow(success);
list_.EnableWindow(success);
GetDlgItem(IDC_BUTTON_SAVE)->EnableWindow(success);
GetDlgItem(IDC_BUTTON_SAVE_EXPORT)->EnableWindow(success);
GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(cur_cp_ == 936);
GetDlgItem(IDC_BUTTON_ADD_FILE)->EnableWindow(cur_cp_ == 936);
}
bool CDlgLang::find_repeat_in_vector(uint32_t val, void* param)
{
@ -607,6 +609,8 @@ BEGIN_MESSAGE_MAP(CDlgLang, CDialogEx)
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, &CDlgLang::OnNMDblclkList1)
ON_BN_CLICKED(IDC_BUTTON_SAVE, &CDlgLang::OnBnClickedButtonSave)
ON_BN_CLICKED(IDC_BUTTON_ADD, &CDlgLang::OnBnClickedButtonAdd)
ON_BN_CLICKED(IDC_BUTTON_ADD_FILE, &CDlgLang::OnBnClickedButtonAddFile)
ON_BN_CLICKED(IDC_BUTTON_SAVE_EXPORT, &CDlgLang::OnBnClickedButtonSaveExport)
END_MESSAGE_MAP()
@ -761,6 +765,7 @@ void CDlgLang::OnCbnSelchangeLanguage()
::MessageBoxW(m_hWnd, unic.c_str(), L"Error", MB_OK | MB_ICONSTOP);
select_code_page(cur_cp_);
GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(cur_cp_ == 936);
GetDlgItem(IDC_BUTTON_ADD_FILE)->EnableWindow(cur_cp_ == 936);
return;
}
list_.DeleteAllItems();
@ -768,6 +773,7 @@ void CDlgLang::OnCbnSelchangeLanguage()
add_2_list(&lans, cur_cp_, true);
select_code_page(cur_cp_);
GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(cur_cp_ == 936);
GetDlgItem(IDC_BUTTON_ADD_FILE)->EnableWindow(cur_cp_ == 936);
return;
}
}
@ -854,6 +860,7 @@ void CDlgLang::OnCbnSelchangeLanguage()
}
}
GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(cur_cp_ == 936);
GetDlgItem(IDC_BUTTON_ADD_FILE)->EnableWindow(cur_cp_ == 936);
}
void CDlgLang::OnNMDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
@ -935,3 +942,79 @@ void CDlgLang::OnBnClickedButtonAdd()
hz_.push_back(h);
}
}
void CDlgLang::OnBnClickedButtonAddFile()
{
// TODO: 在此添加控件通知处理程序代码
file_util::PATHFILE file = { 0 };
if (file_util::browser_file(m_hWnd, &file, L"Text File(*.txt)\0\0"))
{
std::string bom("");
std::wstring unic(L""), line(L"");
int id = 0, next = 0, same = 0, added = 0, off = 0;
file_util::load_file(file.path, sdk_util::got_str, &bom);
coding_util::bom::to_unicode(bom.c_str(), bom.length(), sdk_util::got_wstr, &unic);
bom.clear();
coding_util::pick_line(unic.c_str(), sdk_util::got_wstr, &line, &next);
while (next)
{
if (!line.empty())
{
id = find_hz_ID(line.c_str());
if (id == -1)
{
HZMAP h;
h.hz = std::move(line);
h.id = sdk_util::make_string_id(h.hz.c_str(), &CDlgLang::find_repeat_in_list, &list_);
insert_item_2_list(h.hz.c_str(), h.id);
hz_.push_back(h);
added++;
}
else
{
same++;
}
}
off += next;
line = L"";
coding_util::pick_line(unic.c_str() + off, sdk_util::got_wstr, &line, &next);
}
::MessageBoxW(m_hWnd, (std::wstring(L"新增加 ") + std::to_wstring(added) + L" 个词条,有" + std::to_wstring(same) + L" 个词条重复。").c_str(), L"OK", MB_OK);
}
}
void CDlgLang::OnBnClickedButtonSaveExport()
{
// TODO: 在此添加控件通知处理程序代码
if (list_.GetItemCount())
{
std::wstring text(L"");
for (int i = 0; i < list_.GetItemCount(); ++i)
{
TCHAR buf[512] = { 0 };
std::wstring l(L"");
list_.GetItemText(i, 1, buf, _countof(buf) - 1);
l = buf;
if (l.length() < 5)
l.insert(0, 5 - l.length(), L' ');
l += L"\t\t";
text += l;
list_.GetItemText(i, 2, buf, _countof(buf) - 1);
text += buf;
text += L"\r\n";
}
file_util::set_clipboard(text.c_str(), text.length() * 2, CF_UNICODETEXT);
::MessageBoxW(m_hWnd, L"文本内容已经拷贝到剪贴板", L"Ok", MB_OK);
}
}

View File

@ -56,4 +56,6 @@ public:
std::vector<HZMAP> hz_;
afx_msg void OnBnClickedButtonSave();
afx_msg void OnBnClickedButtonAdd();
afx_msg void OnBnClickedButtonAddFile();
afx_msg void OnBnClickedButtonSaveExport();
};

Binary file not shown.

Binary file not shown.

Binary file not shown.