JSON添加字段,以适应从设备上传
This commit is contained in:
parent
c53afd8854
commit
cbdcb5434b
|
@ -6,6 +6,7 @@
|
|||
#include "afxdialogex.h"
|
||||
#include "CDlgLang.h"
|
||||
#include "DlgInput.h"
|
||||
#include "DlgAddWords.h"
|
||||
|
||||
#include <file/file_util.h>
|
||||
#include <coding/coding.h>
|
||||
|
@ -168,35 +169,6 @@ namespace sdk_util
|
|||
str = std::move(conv);
|
||||
}
|
||||
|
||||
typedef struct _lang_id
|
||||
{
|
||||
int id;
|
||||
int cp;
|
||||
std::string utf8;
|
||||
|
||||
bool operator==(int i)
|
||||
{
|
||||
return id == i;
|
||||
}
|
||||
bool operator<(struct _lang_id& r)
|
||||
{
|
||||
return id < r.id;
|
||||
}
|
||||
}LANGID;
|
||||
typedef struct _lang_id_w
|
||||
{
|
||||
int id;
|
||||
std::wstring unic;
|
||||
|
||||
bool operator==(int i)
|
||||
{
|
||||
return id == i;
|
||||
}
|
||||
bool operator<(struct _lang_id& r)
|
||||
{
|
||||
return id < r.id;
|
||||
}
|
||||
}LANGIDW;
|
||||
static LANGID g_reserve[] = { {1, 936, "\344\270\255\346\226\207\357\274\210\347\256\200\344\275\223\357\274\211"} // 中文(简体)
|
||||
, {2, 950, "\344\270\255\346\226\207\357\274\210\347\271\201\344\275\223\357\274\211"} // 中文(繁体)
|
||||
, {10, 20127, "\350\213\261\350\257\255"} // 英语
|
||||
|
@ -237,7 +209,7 @@ namespace sdk_util
|
|||
|
||||
return NULL;
|
||||
}
|
||||
int save_2_lang_pak(HWND owner, std::vector<LANGID>& items, int cp = 936)
|
||||
int save_2_lang_pak(HWND owner, std::vector<LANGID>& items, int cp, std::string* raw_data, bool to_file)
|
||||
{
|
||||
uint32_t len = 0,
|
||||
crc = 0,
|
||||
|
@ -320,11 +292,14 @@ namespace sdk_util
|
|||
|
||||
file_util::PATHFILE file = { 0 };
|
||||
tmp = 0;
|
||||
if (file_util::browser_file(owner, &file, L"Language pack(*.pak)\0\0", false))
|
||||
if (to_file && file_util::browser_file(owner, &file, L"Language pack(*.pak)\0\0", false))
|
||||
{
|
||||
tmp = file_util::save_2_file(cont.c_str(), cont.length(), file.path);
|
||||
}
|
||||
|
||||
if (raw_data)
|
||||
*raw_data = std::move(cont);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
@ -384,7 +359,7 @@ namespace sdk_util
|
|||
|
||||
return true;
|
||||
}
|
||||
bool load_lang_pak(const wchar_t* file, std::vector<LANGIDW>& items, int* id = NULL)
|
||||
bool load_lang_pak(const wchar_t* file, std::vector<LANGIDW>& items, int* id)
|
||||
{
|
||||
std::string cont(""), name("");
|
||||
bool ret = false;
|
||||
|
@ -423,7 +398,70 @@ namespace sdk_util
|
|||
return ret;
|
||||
}
|
||||
|
||||
std::wstring get_wnd_text(HWND wnd)
|
||||
{
|
||||
int l = GetWindowTextLengthW(wnd);
|
||||
wchar_t* buf = new wchar_t[l + 4];
|
||||
std::wstring ret(L"");
|
||||
|
||||
l = GetWindowTextW(wnd, buf, l + 1);
|
||||
buf[l] = 0;
|
||||
ret = buf;
|
||||
delete[] buf;
|
||||
|
||||
return std::move(ret);
|
||||
}
|
||||
std::wstring get_wnd_text(HWND dlg, UINT id)
|
||||
{
|
||||
return get_wnd_text(GetDlgItem(dlg, id));
|
||||
}
|
||||
std::wstring load_file(const wchar_t* file, int* bom)
|
||||
{
|
||||
std::string raw("");
|
||||
std::wstring unic(L"");
|
||||
|
||||
file_util::load_file(file, got_str, &raw);
|
||||
if (bom)
|
||||
{
|
||||
if (coding_util::bom::is_unicode(raw.c_str(), NULL))
|
||||
*bom = BOM_UNICODE;
|
||||
else if (coding_util::bom::is_utf8(raw.c_str()))
|
||||
*bom = BOM_UTF8;
|
||||
else
|
||||
*bom = BOM_ANSI;
|
||||
}
|
||||
coding_util::bom::to_unicode(raw.c_str(), raw.length(), got_wstr, &unic);
|
||||
|
||||
return std::move(unic);
|
||||
}
|
||||
int save_file(const wchar_t* file, std::wstring& cont, int bom)
|
||||
{
|
||||
if (bom == BOM_UTF8)
|
||||
{
|
||||
std::string raw(""), bomd("");
|
||||
|
||||
coding_util::unicode_2_utf8(cont.c_str(), got_str, &raw);
|
||||
coding_util::bom::from_utf8(raw.c_str(), raw.length(), got_str, &bomd);
|
||||
|
||||
return file_util::save_2_file(bomd.c_str(), bomd.length(), file);
|
||||
}
|
||||
else if (bom == BOM_UNICODE)
|
||||
{
|
||||
std::string raw("");
|
||||
|
||||
coding_util::bom::from_unicode(cont.c_str(), cont.length() * 2, got_str, &raw);
|
||||
|
||||
return file_util::save_2_file(raw.c_str(), raw.length(), file);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string raw("");
|
||||
|
||||
coding_util::unicode_2_ansi(cont.c_str(), got_str, &raw);
|
||||
|
||||
return file_util::save_2_file(raw.c_str(), raw.length(), file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CDlgLang 对话框
|
||||
|
@ -620,6 +658,7 @@ BEGIN_MESSAGE_MAP(CDlgLang, CDialogEx)
|
|||
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)
|
||||
ON_BN_CLICKED(IDC_BUTTON_BATCH_ADD, &CDlgLang::OnBnClickedButtonBatchAdd)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
|
@ -1045,3 +1084,11 @@ void CDlgLang::OnBnClickedButtonSaveExport()
|
|||
::MessageBoxW(m_hWnd, L"文本内容已经拷贝到剪贴板", L"Ok", MB_OK);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CDlgLang::OnBnClickedButtonBatchAdd()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
CDlgAddWords dlg;
|
||||
dlg.DoModal();
|
||||
}
|
||||
|
|
|
@ -58,4 +58,5 @@ public:
|
|||
afx_msg void OnBnClickedButtonAdd();
|
||||
afx_msg void OnBnClickedButtonAddFile();
|
||||
afx_msg void OnBnClickedButtonSaveExport();
|
||||
afx_msg void OnBnClickedButtonBatchAdd();
|
||||
};
|
||||
|
|
|
@ -0,0 +1,441 @@
|
|||
// DlgAddWords.cpp: 实现文件
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "hgjson.h"
|
||||
#include "afxdialogex.h"
|
||||
#include "DlgAddWords.h"
|
||||
|
||||
|
||||
|
||||
// CDlgAddWords 对话框
|
||||
|
||||
static bool is_id_existing(uint32_t id, void* param)
|
||||
{
|
||||
std::vector<sdk_util::LANGID>* lang = (std::vector<sdk_util::LANGID>*)param;
|
||||
|
||||
return std::find(lang->begin(), lang->end(), (int)id) != lang->end();
|
||||
}
|
||||
|
||||
IMPLEMENT_DYNAMIC(CDlgAddWords, CDialogEx)
|
||||
|
||||
CDlgAddWords::CDlgAddWords(CWnd* pParent /*=nullptr*/)
|
||||
: CDialogEx(IDD_BATCH_ADD_LANG, pParent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CDlgAddWords::~CDlgAddWords()
|
||||
{
|
||||
}
|
||||
|
||||
void CDlgAddWords::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialogEx::DoDataExchange(pDX);
|
||||
DDX_Control(pDX, IDC_LIST1, words_);
|
||||
}
|
||||
BOOL CDlgAddWords::OnInitDialog()
|
||||
{
|
||||
CDialogEx::OnInitDialog();
|
||||
|
||||
// Set the icon for this dialog. The framework does this automatically
|
||||
// when the application's main window is not a dialog
|
||||
int ind = 0;
|
||||
words_.InsertColumn(ind++, TEXT("No."), 0, 48);
|
||||
words_.InsertColumn(ind++, TEXT("中文简体"), 0, 168);
|
||||
words_.InsertColumn(ind++, TEXT("中文繁体"), 0, 168);
|
||||
words_.InsertColumn(ind++, TEXT("英语"), 0, 250);
|
||||
words_.SetExtendedStyle(words_.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_INFOTIP);
|
||||
words_.ModifyStyle(0, LVS_SINGLESEL);
|
||||
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
}
|
||||
void CDlgAddWords::open_pak(int lan_id)
|
||||
{
|
||||
file_util::PATHFILE file = { 0 };
|
||||
|
||||
if (file_util::browser_file(m_hWnd, &file, L"PAK file(*.pak)\0All Files(*.*)\0\0"))
|
||||
{
|
||||
set_lang_pak_file(file.path, lan_id);
|
||||
}
|
||||
}
|
||||
void CDlgAddWords::set_lang_pak_file(const wchar_t* file, int lan_id)
|
||||
{
|
||||
std::vector<sdk_util::LANGIDW> lans;
|
||||
int id = 0;
|
||||
bool ok = false;
|
||||
|
||||
if (sdk_util::load_lang_pak(file, lans, &id))
|
||||
{
|
||||
if (id == lan_id || lan_id == 0)
|
||||
{
|
||||
ok = true;
|
||||
if (id == 936)
|
||||
{
|
||||
::SetDlgItemTextW(m_hWnd, IDC_EDIT_HZ_PAK, file);
|
||||
lan_hz_ = std::move(lans);
|
||||
}
|
||||
else if (id == 950)
|
||||
{
|
||||
::SetDlgItemTextW(m_hWnd, IDC_EDIT_HZT, file);
|
||||
lan_hzt_ = std::move(lans);
|
||||
}
|
||||
else if (id == 20127)
|
||||
{
|
||||
::SetDlgItemTextW(m_hWnd, IDC_EDIT_ENGLISH, file);
|
||||
lan_eng_ = std::move(lans);
|
||||
}
|
||||
else
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
if (!ok && lan_id)
|
||||
::MessageBoxW(m_hWnd, file, L"不是指定的语言包", MB_OK | MB_ICONERROR);
|
||||
}
|
||||
void CDlgAddWords::set_code_file(const wchar_t* file, bool tip)
|
||||
{
|
||||
std::wstring unic(sdk_util::load_file(file));
|
||||
|
||||
if (unic.find(L"unsigned char g_chinese[] = {") == std::wstring::npos)
|
||||
{
|
||||
if(tip)
|
||||
::MessageBoxW(m_hWnd, file, L"不是指定的简体中文语言头文件", MB_OK | MB_ICONERROR);
|
||||
}
|
||||
else
|
||||
::SetDlgItemTextW(m_hWnd, IDC_EDIT_CODE, file);
|
||||
}
|
||||
bool CDlgAddWords::add_words(const wchar_t* pak_file, std::vector<int>& ids, std::string& cont, int lan_id, int src_col, bool init_id)
|
||||
{
|
||||
std::vector<sdk_util::LANGIDW> prev;
|
||||
int id = 0;
|
||||
|
||||
if (sdk_util::load_lang_pak(pak_file, prev, &id))
|
||||
{
|
||||
if (id == lan_id)
|
||||
{
|
||||
std::vector<sdk_util::LANGID> now;
|
||||
|
||||
for (auto& v : prev)
|
||||
{
|
||||
sdk_util::LANGID item;
|
||||
item.cp = id;
|
||||
item.id = v.id;
|
||||
coding_util::unicode_2_utf8(v.unic.c_str(), sdk_util::got_str, &item.utf8);
|
||||
now.push_back(std::move(item));
|
||||
}
|
||||
|
||||
for (int i = 0; i < words_.GetItemCount(); ++i)
|
||||
{
|
||||
wchar_t text[256] = { 0 };
|
||||
sdk_util::LANGID item;
|
||||
|
||||
words_.GetItemText(i, src_col, text, _countof(text) - 1);
|
||||
if (init_id)
|
||||
{
|
||||
ids.push_back(sdk_util::make_string_id(text, &is_id_existing, &now));
|
||||
}
|
||||
item.cp = lan_id;
|
||||
item.id = ids[i];
|
||||
coding_util::unicode_2_utf8(text, sdk_util::got_str, &item.utf8);
|
||||
now.push_back(std::move(item));
|
||||
}
|
||||
|
||||
cont = "";
|
||||
sdk_util::save_2_lang_pak(m_hWnd, now, lan_id, &cont, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
::MessageBoxW(m_hWnd, L"语言包不匹配", L"错误", MB_OK | MB_ICONSTOP);
|
||||
}
|
||||
else
|
||||
::MessageBoxW(m_hWnd, pak_file, L"文件加载失败", MB_OK | MB_ICONSTOP);
|
||||
|
||||
return false;
|
||||
}
|
||||
bool CDlgAddWords::update_head_file(const wchar_t* file, const std::string& cont)
|
||||
{
|
||||
int bom = sdk_util::BOM_ANSI;
|
||||
std::wstring code(sdk_util::load_file(file, &bom)), ar(L"unsigned char g_chinese[] = {");
|
||||
size_t pos = code.find(L"unsigned char g_chinese[] = {"), end = 0;
|
||||
|
||||
|
||||
if (pos == std::wstring::npos)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < cont.length(); ++i)
|
||||
{
|
||||
unsigned char ch = cont[i];
|
||||
wchar_t buf[20] = { 0 };
|
||||
|
||||
swprintf_s(buf, _countof(buf) - 1, L"0x%02X", ch);
|
||||
if ((i % 16) == 0)
|
||||
{
|
||||
if (i)
|
||||
ar += L",";
|
||||
ar += L"\r\n";
|
||||
}
|
||||
else if ((i % 8) == 0)
|
||||
{
|
||||
if (i)
|
||||
ar += L",";
|
||||
ar += L" ";
|
||||
}
|
||||
else if (i)
|
||||
ar += L", ";
|
||||
ar += buf;
|
||||
}
|
||||
ar += L"\r\n};\r\n";
|
||||
|
||||
end = code.find(L";", pos);
|
||||
if (end == std::wstring::npos)
|
||||
code.erase(pos);
|
||||
else
|
||||
code.erase(pos, end - pos + 1);
|
||||
code.insert(pos, ar);
|
||||
|
||||
ar = file;
|
||||
file_util::force_move_file(file, (ar + L".bak").c_str());
|
||||
bom = sdk_util::save_file(file, code, bom);
|
||||
if(bom)
|
||||
file_util::force_move_file((ar + L".bak").c_str(), file);
|
||||
|
||||
return bom == 0;
|
||||
}
|
||||
|
||||
BEGIN_MESSAGE_MAP(CDlgAddWords, CDialogEx)
|
||||
ON_BN_CLICKED(IDC_BUTTON_BROWSE_HZ, &CDlgAddWords::OnBnClickedButtonBrowseHz)
|
||||
ON_BN_CLICKED(IDC_BUTTON_BROWSE_HZT, &CDlgAddWords::OnBnClickedButtonBrowseHzt)
|
||||
ON_BN_CLICKED(IDC_BUTTON_BROWSE_ENG, &CDlgAddWords::OnBnClickedButtonBrowseEng)
|
||||
ON_BN_CLICKED(IDC_BUTTON_BROWSE_CODE, &CDlgAddWords::OnBnClickedButtonBrowseCode)
|
||||
ON_BN_CLICKED(IDC_BUTTON_ADD, &CDlgAddWords::OnBnClickedButtonAdd)
|
||||
ON_BN_CLICKED(IDC_BUTTON_DEL, &CDlgAddWords::OnBnClickedButtonDel)
|
||||
ON_BN_CLICKED(IDC_BUTTON_CLEAR, &CDlgAddWords::OnBnClickedButtonClear)
|
||||
ON_BN_CLICKED(IDC_BUTTON_UPDATE, &CDlgAddWords::OnBnClickedButtonUpdate)
|
||||
ON_WM_DROPFILES()
|
||||
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, &CDlgAddWords::OnNMDblclkList1)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
// CDlgAddWords 消息处理程序
|
||||
|
||||
void CDlgAddWords::OnDropFiles(HDROP hDropInfo)
|
||||
{
|
||||
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
||||
wchar_t path[MAX_PATH] = { 0 };
|
||||
int cnt = DragQueryFileW(hDropInfo, -1, path, _countof(path) - 1);
|
||||
|
||||
for (int i = 0; i < cnt; ++i)
|
||||
{
|
||||
int len = DragQueryFileW(hDropInfo, i, path, _countof(path) - 1);
|
||||
std::wstring file(path, len), ext(file);
|
||||
|
||||
STR_FILE_EXTENSION(ext);
|
||||
if (wcsicmp(ext.c_str(), L"pak") == 0)
|
||||
{
|
||||
set_lang_pak_file(file.c_str());
|
||||
}
|
||||
else if (wcsicmp(ext.c_str(), L"h") == 0)
|
||||
{
|
||||
set_code_file(file.c_str(), false);
|
||||
}
|
||||
}
|
||||
|
||||
CDialogEx::OnDropFiles(hDropInfo);
|
||||
}
|
||||
|
||||
void CDlgAddWords::OnNMDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
|
||||
{
|
||||
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
*pResult = 0;
|
||||
|
||||
wchar_t text[256] = { 0 };
|
||||
|
||||
words_.GetItemText(pNMItemActivate->iItem, 1, text, _countof(text) - 1);
|
||||
::SetDlgItemTextW(m_hWnd, IDC_EDIT_HZ_WORD, text);
|
||||
words_.GetItemText(pNMItemActivate->iItem, 2, text, _countof(text) - 1);
|
||||
::SetDlgItemTextW(m_hWnd, IDC_EDIT_HZT_WORD, text);
|
||||
words_.GetItemText(pNMItemActivate->iItem, 3, text, _countof(text) - 1);
|
||||
::SetDlgItemTextW(m_hWnd, IDC_EDIT_ENG_WORD, text);
|
||||
}
|
||||
|
||||
|
||||
void CDlgAddWords::OnBnClickedButtonBrowseHz()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
open_pak(936);
|
||||
}
|
||||
|
||||
|
||||
void CDlgAddWords::OnBnClickedButtonBrowseHzt()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
open_pak(950);
|
||||
}
|
||||
|
||||
|
||||
void CDlgAddWords::OnBnClickedButtonBrowseEng()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
open_pak(20127);
|
||||
}
|
||||
|
||||
|
||||
void CDlgAddWords::OnBnClickedButtonBrowseCode()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
file_util::PATHFILE file = { 0 };
|
||||
|
||||
if (file_util::browser_file(m_hWnd, &file, L"Header file(*.h)\0\0"))
|
||||
{
|
||||
set_code_file(file.path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CDlgAddWords::OnBnClickedButtonAdd()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
std::wstring hz(sdk_util::get_wnd_text(m_hWnd, IDC_EDIT_HZ_WORD)),
|
||||
hzt(sdk_util::get_wnd_text(m_hWnd, IDC_EDIT_HZT_WORD)),
|
||||
eng(sdk_util::get_wnd_text(m_hWnd, IDC_EDIT_ENG_WORD));
|
||||
wchar_t text[256] = { 0 };
|
||||
int item = 0;
|
||||
|
||||
for (int i = 0; i < words_.GetItemCount(); ++i)
|
||||
{
|
||||
words_.GetItemText(i, 1, text, _countof(text) - 1);
|
||||
if (hz == text)
|
||||
{
|
||||
::MessageBoxW(m_hWnd, text, L"词条已经存在", MB_OK | MB_ICONSTOP);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
item = words_.InsertItem(words_.GetItemCount(), std::to_wstring(words_.GetItemCount() + 1).c_str());
|
||||
words_.SetItemText(item, 1, hz.c_str());
|
||||
words_.SetItemText(item, 2, hzt.c_str());
|
||||
words_.SetItemText(item, 3, eng.c_str());
|
||||
}
|
||||
|
||||
|
||||
void CDlgAddWords::OnBnClickedButtonDel()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
for (int i = 0; i < words_.GetItemCount(); ++i)
|
||||
{
|
||||
if (words_.GetItemState(i, LVIF_STATE) & LVIS_SELECTED)
|
||||
{
|
||||
words_.DeleteItem(i--);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < words_.GetItemCount(); ++i)
|
||||
words_.SetItemText(i, 0, std::to_wstring(i + 1).c_str());
|
||||
}
|
||||
|
||||
|
||||
void CDlgAddWords::OnBnClickedButtonClear()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
words_.DeleteAllItems();
|
||||
}
|
||||
|
||||
|
||||
void CDlgAddWords::OnBnClickedButtonUpdate()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
if (words_.GetItemCount() == 0)
|
||||
{
|
||||
::MessageBoxW(m_hWnd, L"No words should be added into language packet!", L"None", MB_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
std::wstring hzf(sdk_util::get_wnd_text(m_hWnd, IDC_EDIT_HZ_PAK)),
|
||||
hztf(sdk_util::get_wnd_text(m_hWnd, IDC_EDIT_HZT)),
|
||||
engf(sdk_util::get_wnd_text(m_hWnd, IDC_EDIT_ENGLISH)),
|
||||
hf(sdk_util::get_wnd_text(m_hWnd, IDC_EDIT_CODE));
|
||||
bool hzb(file_util::is_file_existing(hzf.c_str())),
|
||||
hztb(file_util::is_file_existing(hztf.c_str())),
|
||||
engb(file_util::is_file_existing(engf.c_str())),
|
||||
hb(file_util::is_file_existing(hf.c_str()));
|
||||
|
||||
if (!hzb)
|
||||
{
|
||||
::MessageBoxW(m_hWnd, hzf.c_str(), L"File Not Found", MB_OK | MB_ICONSTOP);
|
||||
GotoDlgCtrl(GetDlgItem(IDC_EDIT_HZ_PAK));
|
||||
return;
|
||||
}
|
||||
if (!hztb)
|
||||
{
|
||||
::MessageBoxW(m_hWnd, hztf.c_str(), L"File Not Found", MB_OK | MB_ICONSTOP);
|
||||
GotoDlgCtrl(GetDlgItem(IDC_EDIT_HZT));
|
||||
return;
|
||||
}
|
||||
if (!engb)
|
||||
{
|
||||
::MessageBoxW(m_hWnd, hzf.c_str(), L"File Not Found", MB_OK | MB_ICONSTOP);
|
||||
GotoDlgCtrl(GetDlgItem(IDC_EDIT_ENGLISH));
|
||||
return;
|
||||
}
|
||||
if (!hb)
|
||||
{
|
||||
::MessageBoxW(m_hWnd, hzf.c_str(), L"File Not Found", MB_OK | MB_ICONSTOP);
|
||||
GotoDlgCtrl(GetDlgItem(IDC_EDIT_CODE));
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
std::vector<int> ids;
|
||||
std::string cont("");
|
||||
int err = 0;
|
||||
|
||||
while (add_words(hzf.c_str(), ids, cont, 936, 1, true))
|
||||
{
|
||||
file_util::force_move_file(hzf.c_str(), (hzf + L".bak").c_str());
|
||||
err = file_util::save_2_file(cont.c_str(), cont.length(), hzf.c_str());
|
||||
if (err)
|
||||
{
|
||||
::MessageBoxW(m_hWnd, hzf.c_str(), L"Write file failed", MB_OK | MB_ICONERROR);
|
||||
break;
|
||||
}
|
||||
|
||||
// change head file ...
|
||||
if (update_head_file(hf.c_str(), cont))
|
||||
{
|
||||
if (add_words(hztf.c_str(), ids, cont, 950, 2))
|
||||
{
|
||||
file_util::force_move_file(hztf.c_str(), (hztf + L".bak").c_str());
|
||||
err = file_util::save_2_file(cont.c_str(), cont.length(), hztf.c_str());
|
||||
if (err)
|
||||
{
|
||||
::MessageBoxW(m_hWnd, hztf.c_str(), L"Write file failed", MB_OK | MB_ICONERROR);
|
||||
break;
|
||||
}
|
||||
|
||||
if (add_words(engf.c_str(), ids, cont, 20127, 3))
|
||||
{
|
||||
file_util::force_move_file(engf.c_str(), (engf + L".bak").c_str());
|
||||
err = file_util::save_2_file(cont.c_str(), cont.length(), engf.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
err = -2;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (err == 0)
|
||||
::MessageBoxW(m_hWnd, L"All languages have updated!", L"Congratulation", MB_OK | MB_ICONINFORMATION);
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
#pragma once
|
||||
#include "afxdialogex.h"
|
||||
|
||||
|
||||
// CDlgAddWords 对话框
|
||||
|
||||
#include <file/file_util.h>
|
||||
#include <coding/coding.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace sdk_util
|
||||
{
|
||||
typedef struct _lang_id
|
||||
{
|
||||
int id;
|
||||
int cp;
|
||||
std::string utf8;
|
||||
|
||||
bool operator==(int i)
|
||||
{
|
||||
return id == i;
|
||||
}
|
||||
bool operator<(struct _lang_id& r)
|
||||
{
|
||||
return id < r.id;
|
||||
}
|
||||
}LANGID;
|
||||
typedef struct _lang_id_w
|
||||
{
|
||||
int id;
|
||||
std::wstring unic;
|
||||
|
||||
bool operator==(int i)
|
||||
{
|
||||
return id == i;
|
||||
}
|
||||
bool operator==(const wchar_t* text)
|
||||
{
|
||||
return unic == text;
|
||||
}
|
||||
bool operator<(struct _lang_id& r)
|
||||
{
|
||||
return id < r.id;
|
||||
}
|
||||
}LANGIDW;
|
||||
|
||||
INTER_MODULE_CALLBACK(got_str);
|
||||
INTER_MODULE_CALLBACK(got_wstr);
|
||||
uint32_t make_string_id(const wchar_t* str, bool(*is_repeat)(uint32_t, void*), void* param);
|
||||
void trim_left(std::wstring& str);
|
||||
void trim_right(std::wstring& str);
|
||||
unsigned pick_number(const wchar_t* str, const wchar_t** end, int type);
|
||||
void convert_unicode(std::wstring& str);
|
||||
LANGID* lang_info_from_cp(int cp);
|
||||
LANGID* lang_info_from_ID(int id);
|
||||
LANGID* lang_info_from_name(const char* utf8);
|
||||
int save_2_lang_pak(HWND owner, std::vector<LANGID>& items, int cp = 936, std::string* raw_data = NULL, bool to_file = true);
|
||||
bool parse_pak_digest(uint8_t* data, int* id);
|
||||
bool parse_pak(uint8_t* data, std::vector<LANGIDW>& items);
|
||||
bool load_lang_pak(const wchar_t* file, std::vector<LANGIDW>& items, int* id = NULL);
|
||||
|
||||
std::wstring get_wnd_text(HWND wnd);
|
||||
std::wstring get_wnd_text(HWND dlg, UINT id);
|
||||
enum
|
||||
{
|
||||
BOM_ANSI = 0,
|
||||
BOM_UTF8,
|
||||
BOM_UNICODE,
|
||||
};
|
||||
std::wstring load_file(const wchar_t* file, int* bom = NULL);
|
||||
int save_file(const wchar_t* file, std::wstring& cont, int bom = BOM_UNICODE);
|
||||
}
|
||||
|
||||
class CDlgAddWords : public CDialogEx
|
||||
{
|
||||
DECLARE_DYNAMIC(CDlgAddWords)
|
||||
|
||||
public:
|
||||
CDlgAddWords(CWnd* pParent = nullptr); // 标准构造函数
|
||||
virtual ~CDlgAddWords();
|
||||
|
||||
// 对话框数据
|
||||
#ifdef AFX_DESIGN_TIME
|
||||
enum { IDD = IDD_BATCH_ADD_LANG };
|
||||
#endif
|
||||
|
||||
protected:
|
||||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
|
||||
virtual BOOL OnInitDialog();
|
||||
void open_pak(int lan_id);
|
||||
void set_lang_pak_file(const wchar_t* file, int lan_id = 0);
|
||||
void set_code_file(const wchar_t* file, bool tip = true);
|
||||
bool add_words(const wchar_t* pak_file, std::vector<int>& ids, std::string& cont, int lan_id, int src_col, bool init_id = false);
|
||||
bool update_head_file(const wchar_t* file, const std::string& cont);
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
|
||||
std::vector<sdk_util::LANGIDW> lan_hz_;
|
||||
std::vector<sdk_util::LANGIDW> lan_hzt_;
|
||||
std::vector<sdk_util::LANGIDW> lan_eng_;
|
||||
|
||||
public:
|
||||
afx_msg void OnBnClickedButtonBrowseHz();
|
||||
afx_msg void OnBnClickedButtonBrowseHzt();
|
||||
afx_msg void OnBnClickedButtonBrowseEng();
|
||||
afx_msg void OnBnClickedButtonBrowseCode();
|
||||
afx_msg void OnBnClickedButtonAdd();
|
||||
afx_msg void OnBnClickedButtonDel();
|
||||
afx_msg void OnBnClickedButtonClear();
|
||||
afx_msg void OnBnClickedButtonUpdate();
|
||||
CListCtrl words_;
|
||||
afx_msg void OnDropFiles(HDROP hDropInfo);
|
||||
afx_msg void OnNMDblclkList1(NMHDR* pNMHDR, LRESULT* pResult);
|
||||
};
|
Binary file not shown.
|
@ -115,6 +115,7 @@
|
|||
<ClInclude Include="..\..\..\..\code_device\hgdriver\hgdev\scanner_setting.h" />
|
||||
<ClInclude Include="CDlgLang.h" />
|
||||
<ClInclude Include="CDlgMain.h" />
|
||||
<ClInclude Include="DlgAddWords.h" />
|
||||
<ClInclude Include="DlgInput.h" />
|
||||
<ClInclude Include="DlgTwain.h" />
|
||||
<ClInclude Include="hgjson.h" />
|
||||
|
@ -130,6 +131,7 @@
|
|||
</ClCompile>
|
||||
<ClCompile Include="CDlgLang.cpp" />
|
||||
<ClCompile Include="CDlgMain.cpp" />
|
||||
<ClCompile Include="DlgAddWords.cpp" />
|
||||
<ClCompile Include="DlgInput.cpp" />
|
||||
<ClCompile Include="DlgTwain.cpp" />
|
||||
<ClCompile Include="hgjson.cpp" />
|
||||
|
|
|
@ -48,6 +48,9 @@
|
|||
<ClInclude Include="DlgTwain.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="DlgAddWords.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="hgjson.cpp">
|
||||
|
@ -74,6 +77,9 @@
|
|||
<ClCompile Include="DlgTwain.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="DlgAddWords.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="hgjson.rc">
|
||||
|
|
|
@ -31,6 +31,54 @@
|
|||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// sane data types:
|
||||
|
||||
const wchar_t* g_opt_unit_name[] = { // according to SANE_Unit
|
||||
L"None",
|
||||
L"Pixel",
|
||||
L"Bit",
|
||||
L"Millimeters",
|
||||
L"DPI",
|
||||
L"Percent",
|
||||
L"Microsecond"
|
||||
};
|
||||
const wchar_t* g_opt_field[] = {
|
||||
L"Common",
|
||||
L"ImageProc",
|
||||
L"Hardware"
|
||||
};
|
||||
static const wchar_t* unit_name(int ind)
|
||||
{
|
||||
if (ind < 0 || ind >= _countof(g_opt_unit_name))
|
||||
ind = 0;
|
||||
|
||||
return g_opt_unit_name[ind];
|
||||
}
|
||||
static int unit_index(const wchar_t* name)
|
||||
{
|
||||
for (int i = 0; i < _countof(g_opt_unit_name); ++i)
|
||||
{
|
||||
if (wcsicmp(name, g_opt_unit_name[i]) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
static const wchar_t* field_name(int ind)
|
||||
{
|
||||
if (ind < 0 || ind >= _countof(g_opt_field))
|
||||
ind = 0;
|
||||
|
||||
return g_opt_field[ind];
|
||||
}
|
||||
static int field_index(const wchar_t* name)
|
||||
{
|
||||
for (int i = 0; i < _countof(g_opt_field); ++i)
|
||||
{
|
||||
if (wcsicmp(name, g_opt_field[i]) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace coding
|
||||
{
|
||||
|
@ -5941,6 +5989,8 @@ void ChgjsonDlg::DoDataExchange(CDataExchange* pDX)
|
|||
DDX_Control(pDX, IDC_COMBO2, logic_);
|
||||
DDX_Control(pDX, IDC_COMBO1, depend_item_);
|
||||
DDX_Control(pDX, IDC_COMBO_DEFAULT, combo_default_);
|
||||
DDX_Control(pDX, IDC_COMBO5, field_);
|
||||
DDX_Control(pDX, IDC_COMBO6, unit_);
|
||||
}
|
||||
|
||||
BEGIN_MESSAGE_MAP(ChgjsonDlg, CDialogEx)
|
||||
|
@ -6052,6 +6102,8 @@ BOOL ChgjsonDlg::OnInitDialog()
|
|||
constraint_list_.InsertColumn(0, TEXT("Value lists"), 0, 177);
|
||||
constraint_list_.InsertColumn(1, TEXT("Default"), 0, 48);
|
||||
type_.SetCurSel(0);
|
||||
unit_.SetCurSel(0);
|
||||
field_.SetCurSel(0);
|
||||
constraint_.SetCurSel(0);
|
||||
// constraint_list_.ModifyStyleEx(0, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_INFOTIP);
|
||||
constraint_list_.SetExtendedStyle(constraint_list_.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_INFOTIP);
|
||||
|
@ -6063,6 +6115,7 @@ BOOL ChgjsonDlg::OnInitDialog()
|
|||
GetObject(LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1)), sizeof(bmi), &bmi);
|
||||
tree_img_.Create(IDB_BITMAP1, bmi.bmWidth / 2, bmi.bmWidth / 2, RGB(255, 255, 255));
|
||||
tree_.SetImageList(&tree_img_, TVSIL_NORMAL);
|
||||
((CButton*)GetDlgItem(IDC_CHECK_VISIBLE))->SetCheck(BST_CHECKED);
|
||||
init_control_statu();
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
|
@ -6321,6 +6374,11 @@ void ChgjsonDlg::set_control_status(const HGITEM& item)
|
|||
((CButton*)GetDlgItem(IDC_CHECK_ADVANCED))->SetCheck(item.advanced ? BST_CHECKED : BST_UNCHECKED);
|
||||
((CButton*)GetDlgItem(IDC_CHECK_READONLY))->SetCheck(item.readonly ? BST_CHECKED : BST_UNCHECKED);
|
||||
((CButton*)GetDlgItem(IDC_CHECK_DEVICEONLY))->SetCheck(item.deviceonly ? BST_CHECKED : BST_UNCHECKED);
|
||||
((CButton*)GetDlgItem(IDC_CHECK_VISIBLE))->SetCheck(item.visible ? BST_CHECKED : BST_UNCHECKED);
|
||||
|
||||
SetDlgItemInt(IDC_EDIT_POS, item.position);
|
||||
field_.SetCurSel(item.field);
|
||||
unit_.SetCurSel(item.unit);
|
||||
|
||||
// value ...
|
||||
GetDlgItem(IDC_STATIC_FROM)->ShowWindow(SW_HIDE);
|
||||
|
@ -6440,6 +6498,10 @@ void* ChgjsonDlg::create_json(int item, std::vector<DEFH>* def_h, std::wstring*
|
|||
jsn->set_value(L"category", hg_items_[item].advanced ? L"advanced" : L"base");
|
||||
jsn->set_value(L"readonly", hg_items_[item].readonly);
|
||||
jsn->set_value(L"hwonly", hg_items_[item].deviceonly);
|
||||
jsn->set_value(L"visible", hg_items_[item].visible);
|
||||
jsn->set_value(L"field", field_name(hg_items_[item].field));
|
||||
jsn->set_value(L"pos", hg_items_[item].position);
|
||||
jsn->set_value(L"unit", unit_name(hg_items_[item].unit));
|
||||
if (name)
|
||||
{
|
||||
if (opt_name)
|
||||
|
@ -6638,6 +6700,10 @@ std::string ChgjsonDlg::to_json_text(bool for_const, std::wstring* dev)
|
|||
item->set_value(L"category", hg_items_[ind].advanced ? L"advanced" : L"base");
|
||||
item->set_value(L"readonly", hg_items_[ind].readonly);
|
||||
item->set_value(L"hwonly", hg_items_[ind].deviceonly);
|
||||
item->set_value(L"field", field_name(hg_items_[ind].field));
|
||||
item->set_value(L"pos", hg_items_[ind].position);
|
||||
item->set_value(L"visible", hg_items_[ind].visible);
|
||||
item->set_value(L"unit", unit_name(hg_items_[ind].unit));
|
||||
item->release();
|
||||
}
|
||||
std::wstring key(L"");
|
||||
|
@ -6736,8 +6802,22 @@ void ChgjsonDlg::add_item(void* jsn_root, void* jsn_obj, HTREEITEM parent, bool
|
|||
jsn->get_value(L"category", &val);
|
||||
if (val && wcscmp(val, L"advanced") == 0)
|
||||
item.advanced = true;
|
||||
jsn->get_value(L"readonly", item.readonly);
|
||||
jsn->get_value(L"hwonly", item.deviceonly);
|
||||
if (!jsn->get_value(L"readonly", item.readonly))
|
||||
item.readonly = false;
|
||||
if (!jsn->get_value(L"hwonly", item.deviceonly))
|
||||
item.deviceonly = false;
|
||||
if (!jsn->get_value(L"visible", item.visible))
|
||||
item.visible = true;
|
||||
item.field = 0;
|
||||
jsn->get_value(L"field", &val);
|
||||
if (val)
|
||||
item.field = field_index(val);
|
||||
item.unit = 0;
|
||||
jsn->get_value(L"unit", &val);
|
||||
if(val)
|
||||
item.unit = unit_index(val);
|
||||
if (!jsn->get_value(L"pos", item.position))
|
||||
item.position = 0;
|
||||
|
||||
|
||||
jsn->get_value(L"depend_and", &child);
|
||||
|
@ -7752,7 +7832,11 @@ void ChgjsonDlg::OnBnClickedButton4()
|
|||
it->advanced = ((CButton*)GetDlgItem(IDC_CHECK_ADVANCED))->GetCheck() == BST_CHECKED;
|
||||
it->readonly = ((CButton*)GetDlgItem(IDC_CHECK_READONLY))->GetCheck() == BST_CHECKED;
|
||||
it->deviceonly = ((CButton*)GetDlgItem(IDC_CHECK_DEVICEONLY))->GetCheck() == BST_CHECKED;
|
||||
it->visible = ((CButton*)GetDlgItem(IDC_CHECK_VISIBLE))->GetCheck() == BST_CHECKED;
|
||||
it->range.type = constraint_.GetCurSel();
|
||||
it->field = field_.GetCurSel();
|
||||
it->unit = unit_.GetCurSel();
|
||||
it->position = GetDlgItemInt(IDC_EDIT_POS);
|
||||
if (wcscmp(str, L"bool") == 0)
|
||||
it->bytes = sizeof(SANE_Bool);
|
||||
else if (wcscmp(str, L"int") == 0)
|
||||
|
|
|
@ -64,6 +64,10 @@ public:
|
|||
bool advanced;
|
||||
bool readonly;
|
||||
bool deviceonly; // 只能在设备上操作的属性
|
||||
bool visible;
|
||||
int position;
|
||||
int field;
|
||||
int unit;
|
||||
bool depend_or; // or or and
|
||||
std::vector<DEPENDITEM> depend;
|
||||
RANGE range;
|
||||
|
@ -80,7 +84,8 @@ public:
|
|||
init_val = L"true";
|
||||
bytes = 4;
|
||||
advanced = readonly = deviceonly = false;
|
||||
depend_or = true;
|
||||
visible = depend_or = true;
|
||||
position = field = unit = 0;
|
||||
range.type = RANGE_TYPE_NONE;
|
||||
}
|
||||
}HGITEM;
|
||||
|
@ -172,6 +177,8 @@ public:
|
|||
afx_msg void OnBnClickedToFile();
|
||||
afx_msg void OnTreeLoadClipboard();
|
||||
afx_msg void OnTreeUnifySequence();
|
||||
CComboBox field_;
|
||||
CComboBox unit_;
|
||||
};
|
||||
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue