?? senddlg.cpp
字號:
capa = IPMSG_RSA_512 | IPMSG_RC2_40;
else
return FALSE;
// KeyBlob 嶌惉
host->pubKey.KeyBlob(data, sizeof(data), &len);
// 岞奐尞偺 import
if (!pCryptImportKey(target_csp, data, len, 0, 0, &hExKey))
return GetLastErrorMsg("CryptImportKey"), FALSE;
// 僙僢僔儑儞僉乕偺嶌惉
if (capa & IPMSG_BLOWFISH_128) { // blowfish
// blowfish 梡儔儞僟儉尞嶌惉
if (!pCryptGenRandom(target_csp, len = 128/8, data))
return GetLastErrorMsg("CryptGenRandom"), FALSE;
// blowfish 梡尞偺僙僢僩
CBlowFish bl(data, len);
//尞偺埫崋壔
if (!pCryptEncrypt(hExKey, 0, TRUE, 0, data, (DWORD *)&len, MAX_BUF))
return GetLastErrorMsg("CryptEncrypt"), FALSE;
bin2hexstr_bigendian(data, len, (char *)skey); // 尞傪hex暥帤楍偵
// UNIX 宍幃偺夵峴偵曄姺
MsgMng::LocalNewLineToUnix(msgstr, (char *)data, MAX_CRYPTLEN);
// 儊僢僙乕僕埫崋壔
msgLen = bl.Encrypt(data, data, strlen(msgstr)+1);
}
else { // RC2
if (!pCryptGenKey(target_csp, CALG_RC2, CRYPT_EXPORTABLE, &hKey))
return GetLastErrorMsg("CryptGenKey"), FALSE;
pCryptExportKey(hKey, hExKey, SIMPLEBLOB, 0, NULL, (DWORD *)&len);
if (!pCryptExportKey(hKey, hExKey, SIMPLEBLOB, 0, data, (DWORD *)&len))
return GetLastErrorMsg("CryptExportKey"), FALSE;
len -= SKEY_HEADER_SIZE;
bin2hexstr_bigendian(data + SKEY_HEADER_SIZE, len, (char *)skey);
// UNIX 宍幃偺夵峴偵曄姺
if (capa & IPMSG_RC2_40)
MsgMng::LocalNewLineToUnix(msgstr, (char *)data, MAX_CRYPTLEN);
else
strncpyz((char *)data, msgstr, MAX_CRYPTLEN); // beta1-4 only
msgLen = strlen((char *)data) + 1;
// 儊僢僙乕僕偺埫崋壔
if (!pCryptEncrypt(hKey, 0, TRUE, 0, data, &msgLen, MAX_UDPBUF))
return GetLastErrorMsg("CryptEncrypt RC2"), FALSE;
pCryptDestroyKey(hKey);
}
wsprintf(buf, "%X:%s:", capa, skey);
bin2hexstr(data, (int)msgLen, buf + strlen(buf));
pCryptDestroyKey(hExKey);
return TRUE;
}
/*
捠忢憲怣Sub routine
*/
BOOL TSendDlg::SendMsgSub(void)
{
BOOL makeNomalMsg = TRUE; // 旕埫崋僷働僢僩嶌惉
for (int cnt=0; cnt < sendEntryNum; cnt++)
{
if (sendEntry[cnt].Status() == ST_GETCRYPT) {
char spec_str[MAX_BUF];
int spec = IPMSG_RSA_512 | IPMSG_RC2_40;
if (cfg->pubKey.Key())
spec |= IPMSG_RSA_1024 | IPMSG_BLOWFISH_128;
wsprintf(spec_str, "%x", spec);
msgMng->Send(&sendEntry[cnt].Host()->hostSub, IPMSG_GETPUBKEY, spec_str);
}
if (sendEntry[cnt].Status() == ST_MAKECRYPTMSG) {
MakeEncryptPacket(sendEntry + cnt); // ST_MAKECRYPTMSG -> ST_SENDMSG
}
if (sendEntry[cnt].Status() == ST_MAKEMSG) {
sendEntry[cnt].SetStatus(ST_SENDMSG);
if (makeNomalMsg)
msgMng->MakeMsg(msgBuf, packetNo, command & ~IPMSG_ENCRYPTOPT, msg.msgBuf, shareStr, &packetLen), makeNomalMsg = FALSE;
}
if (sendEntry[cnt].Status() == ST_SENDMSG) {
const char *str = sendEntry[cnt].Msg() ? sendEntry[cnt].Msg() : msgBuf;
int len = sendEntry[cnt].Msg() ? sendEntry[cnt].MsgLen() : packetLen;
msgMng->UdpSend(sendEntry[cnt].Host()->hostSub.addr, sendEntry[cnt].Host()->hostSub.portNo, str, len);
}
}
return TRUE;
}
inline char *strtoupper(char *buf, const char *org)
{
BOOL dbcsFlg = FALSE;
for (int cnt=0; buf[cnt] = org[cnt]; cnt++) {
if (dbcsFlg)
dbcsFlg = FALSE;
else if (IsDBCSLeadByte(org[cnt]))
dbcsFlg = TRUE;
else
buf[cnt] = toupper(org[cnt]);
}
return buf;
}
/*
専嶕
*/
BOOL TSendDlg::FindHost(char *findStr, BOOL isAllfind)
{
int startNo = hostListView.GetFocusIndex() + 1;
char find_buf[MAX_NAMEBUF], buf[MAX_NAMEBUF];
if (*findStr == '\0')
return FALSE;
strtoupper(find_buf, findStr);
for (int cnt=0; cnt < memberCnt; cnt++) {
int index = (cnt + startNo) % memberCnt;
if (*hostArray[index]->nickName)
strtoupper(buf, hostArray[index]->nickName);
else
strtoupper(buf, hostArray[index]->hostSub.userName);
if (strstr(buf, find_buf) || isAllfind &&
(strstr(strtoupper(buf, hostArray[index]->groupName), find_buf)
|| strstr(strtoupper(buf, hostArray[index]->hostSub.hostName), find_buf)
|| strstr(strtoupper(buf, hostArray[index]->hostSub.userName), find_buf))) {
SelectHost(&hostArray[index]->hostSub, TRUE);
return TRUE;
}
}
return FALSE;
}
/*
憲怣廔椆捠抦
packet_no偑丄偙偺 SendDialog偺憲偭偨憲怣packet偱偁傟偽丄TRUE
*/
BOOL TSendDlg::SendFinishNotify(HostSub *hostSub, ULONG packet_no)
{
for (int cnt=0; cnt < sendEntryNum; cnt++)
{
if (sendEntry[cnt].Status() == ST_SENDMSG && sendEntry[cnt].Host()->hostSub.addr == hostSub->addr && sendEntry[cnt].Host()->hostSub.portNo == hostSub->portNo && (packet_no == packetNo || packet_no == 0))
{
sendEntry[cnt].SetStatus(ST_DONE);
if (IsSendFinish() && hWnd) //嵞憲MessageBox傪徚偡
{
HWND hMessageWnd = ::GetNextWindow(hWnd, GW_HWNDPREV);
if (hMessageWnd && ::GetWindow(hMessageWnd, GW_OWNER) == hWnd)
::PostMessage(hMessageWnd, WM_SYSCOMMAND, SC_CLOSE, 0);
}
return TRUE;
}
}
return FALSE;
}
/*
憲怣廔椆捠抦
packet_no偑丄偙偺 SendDialog偺憲偭偨憲怣packet偱偁傟偽丄TRUE
*/
BOOL TSendDlg::SendPubKeyNotify(HostSub *hostSub, BYTE *pubkey, int len, int e, int capa)
{
for (int cnt=0; cnt < sendEntryNum; cnt++)
{
if (sendEntry[cnt].Status() == ST_GETCRYPT && sendEntry[cnt].Host()->hostSub.addr == hostSub->addr && sendEntry[cnt].Host()->hostSub.portNo == hostSub->portNo)
{
sendEntry[cnt].Host()->pubKey.Set(pubkey, len, e, capa);
MakeEncryptPacket(sendEntry + cnt);
msgMng->UdpSend(sendEntry[cnt].Host()->hostSub.addr, sendEntry[cnt].Host()->hostSub.portNo, sendEntry[cnt].Msg(), sendEntry[cnt].MsgLen());
return TRUE;
}
}
return FALSE;
}
/*
憲怣(妋擣)拞偐偳偆偐
*/
BOOL TSendDlg::IsSending(void)
{
return timerID ? TRUE : FALSE;
}
/*
憲怣廔椆偟偨偐偳偆偐
*/
BOOL TSendDlg::IsSendFinish(void)
{
BOOL finish = TRUE;
for (int cnt=0; cnt < sendEntryNum; cnt++)
{
if (sendEntry[cnt].Status() != ST_DONE)
{
finish = FALSE;
break;
}
}
return finish;
}
/*
Font 愝掕
*/
void TSendDlg::SetFont(void)
{
HFONT hDlgFont;
if ((hDlgFont = (HFONT)SendMessage(WM_GETFONT, 0, 0)) == NULL)
return;
if (::GetObject(hDlgFont, sizeof(LOGFONT), (LPSTR)&orgFont) == NULL)
return;
if (*cfg->SendEditFont.lfFaceName == 0) //弶婜僨乕僞僙僢僩
cfg->SendEditFont = orgFont;
if (*cfg->SendListFont.lfFaceName == 0) {
cfg->SendListFont = orgFont;
#ifdef JAPANESE
strcpy(cfg->SendListFont.lfFaceName, PROPORTIONAL_FONT);
#endif
}
if (*cfg->SendListFont.lfFaceName && (hDlgFont = ::CreateFontIndirect(&cfg->SendListFont)) != NULL)
{
SendDlgItemMessage(HOST_LIST, WM_SETFONT, (WPARAM)hDlgFont, 0);
if (hListFont)
::DeleteObject(hListFont);
hListFont = hDlgFont;
}
if (*cfg->SendEditFont.lfFaceName && (hDlgFont = ::CreateFontIndirect(&cfg->SendEditFont)) != NULL)
{
SendDlgItemMessage(SEND_EDIT, WM_SETFONT, (WPARAM)hDlgFont, 0);
if (hEditFont)
::DeleteObject(hEditFont);
hEditFont = hDlgFont;
}
static HIMAGELIST himlState;
static int lfHeight;
static HICON hiconItem[MAX_ICON];
if (himlState == NULL || lfHeight != cfg->SendListFont.lfHeight) {
if (hiconItem[0] == NULL) {
hiconItem[0] = ::LoadIcon(TApp::hI, (LPCSTR)IPMSGV1ABS_ICON);
hiconItem[1] = ::LoadIcon(TApp::hI, (LPCSTR)IPMSGV1_ICON);
hiconItem[2] = ::LoadIcon(TApp::hI, (LPCSTR)FILEABS_ICON);
hiconItem[3] = ::LoadIcon(TApp::hI, (LPCSTR)FILE_ICON);
hiconItem[4] = ::LoadIcon(TApp::hI, (LPCSTR)ABSENCE_ICON);
}
if (himlState)
ImageList_Destroy(himlState);
lfHeight = cfg->SendListFont.lfHeight;
himlState = ImageList_Create(abs(cfg->SendListFont.lfHeight) / 4, abs(cfg->SendListFont.lfHeight), TRUE, 1, 1);
for (int cnt=0; cnt < MAX_ICON; cnt++)
ImageList_AddIcon(himlState, hiconItem[cnt]);
}
SendDlgItemMessage(HOST_LIST, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himlState);
if (SendDlgItemMessage(HOST_LIST, LVM_GETIMAGELIST, LVSIL_STATE, 0))
lvStateEnable = TRUE;
else {
SendDlgItemMessage(HOST_LIST, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himlState);
lvStateEnable = FALSE;
}
}
/*
Size 愝掕
*/
void TSendDlg::SetSize(void)
{
WINDOWPLACEMENT wp;
wp.length = sizeof(wp);
::GetWindowPlacement(GetDlgItem(HOST_LIST), &wp);
RectToWinPos(&wp.rcNormalPosition, &item[host_item]);
::GetWindowPlacement(GetDlgItem(MEMBERCNT_TEXT), &wp);
RectToWinPos(&wp.rcNormalPosition, &item[member_item]);
::GetWindowPlacement(GetDlgItem(REFRESH_BUTTON), &wp);
RectToWinPos(&wp.rcNormalPosition, &item[refresh_item]);
::GetWindowPlacement(GetDlgItem(SEND_EDIT), &wp);
RectToWinPos(&wp.rcNormalPosition, &item[edit_item]);
::GetWindowPlacement(GetDlgItem(IDOK), &wp);
RectToWinPos(&wp.rcNormalPosition, &item[ok_item]);
::GetWindowPlacement(GetDlgItem(FILE_BUTTON), &wp);
RectToWinPos(&wp.rcNormalPosition, &item[file_item]);
::GetWindowPlacement(GetDlgItem(SECRET_CHECK), &wp);
RectToWinPos(&wp.rcNormalPosition, &item[secret_item]);
::GetWindowPlacement(GetDlgItem(PASSWORD_CHECK), &wp);
RectToWinPos(&wp.rcNormalPosition, &item[passwd_item]);
::GetWindowPlacement(GetDlgItem(SEPARATE_STATIC), &wp);
RectToWinPos(&wp.rcNormalPosition, &item[separate_item]);
GetWindowRect(&rect);
orgRect = rect;
int cx = ::GetSystemMetrics(SM_CXFULLSCREEN), cy = ::GetSystemMetrics(SM_CYFULLSCREEN);
int xsize = rect.right - rect.left + cfg->SendXdiff, ysize = rect.bottom - rect.top + cfg->SendYdiff;
int x = cfg->SendXpos, y = cfg->SendYpos;
if (cfg->SendSavePos == 0)
{
x = (cx - xsize)/2 + (rand() % (cx/4)) - cx/8;
y = (cy - ysize)/2 + (rand() % (cy/4)) - cy/8;
}
if (x + xsize > cx)
x = cx - xsize;
if (y + ysize > cy)
y = cy - ysize;
EvSize(SIZE_RESTORED, 0, 0);
MoveWindow((x < 0) ? 0 : x, (y < 0) ? 0 : y, xsize, ysize, TRUE);
}
void TSendDlg::PopupContextMenu(POINTS pos)
{
HMENU hMenu = ::CreatePopupMenu();
HMENU hPriorityMenu = ::CreateMenu();
HMENU hGroupMenu = ::CreateMenu();
int cnt;
char buf[MAX_BUF];
int selectNum = (int)SendDlgItemMessage(HOST_LIST, LVM_GETSELECTEDCOUNT, 0, 0);
// char *appendStr = selectNum > 0 ? MOVETO_MSGSTR : SELECT_MSGSTR;
char *appendStr = selectNum > 0 ? MOVETO_MSGSTR : MOVETO_MSGSTR;
u_int flag = selectNum <= 0 ? MF_GRAYED : 0;
if (hMenu == NULL || hPriorityMenu == NULL || hGroupMenu == NULL)
return;
// priority menu
for (cnt=cfg->PriorityMax; cnt >= 0; cnt--)
{
char *ptr = buf;
#ifndef JAPANESE
ptr += wsprintf(ptr, "%s ", appendStr);
#endif
if (cnt == 0)
ptr += wsprintf(ptr, NODISP_MSGSTR);
else if (cnt == 1)
ptr += wsprintf(ptr, DEFAULTDISP_MSGSTR);
else
ptr += wsprintf(ptr, DISPPRIORITY_MSGSTR, cfg->PriorityMax - cnt + 1);
#ifdef JAPANESE
ptr += wsprintf(ptr, " %s ", appendStr);
#endif
wsprintf(ptr, cnt == 1 ? MEMBERCOUNTDEF_MSGSTR : MEMBERCOUNT_MSGSTR, hosts->PriorityHostCnt(cnt * PRIORITY_OFFSET, PRIORITY_OFFSET), cfg->priorityHosts.PriorityHostCnt(cnt * PRIORITY_OFFSET, PRIORITY_OFFSET));
::AppendMenu(hPriorityMenu, MF_STRING|flag, MENU_PRIORITY_START + cnt * PRIORITY_OFFSET, buf);
}
::AppendMenu(hPriorityMenu, MF_SEPARATOR, 0, 0);
::AppendMenu(hPriorityMenu, MF_STRING|(hiddenDisp ? MF_CHECKED : 0), MENU_PRIORITY_HIDDEN, TMPNODISPDISP_MSGSTR);
::AppendMenu(hPriorityMenu, MF_STRING, MENU_PRIORITY_RESET, RESETPRIORITY_MSGSTR);
::AppendMenu(hMenu, MF_POPUP, (UINT)hPriorityMenu, SORTFILTER_MSGSTR);
// ::AppendMenu(hMenu, MF_SEPARATOR, 0, 0);
// group select
int rowMax = ::GetSystemMetrics(SM_CYSCREEN) / ::GetSystemMetrics(SM_CYMENU) -1;
for (cnt=0; cnt < memberCnt; cnt++)
{
int menuMax = ::GetMenuItemCount(hGroupMenu), cnt2;
for (cnt2=0; cnt2 < menuMax; cnt2++)
{
::GetMenuString(hGroupMenu, cnt2, buf, sizeof(buf), MF_BYPOSITION);
if (strcmp(buf, hostArray[cnt]->groupName) == 0)
break;
}
if (cnt2 == menuMax && *hostArray[cnt]->groupName)
::AppendMenu(hGroupMenu, MF_STRING|((menuMax % rowMax || menuMax == 0) ? 0 : MF_MENUBREAK), MENU_GROUP_START + menuMax, hostArray[cnt]->groupName);
}
::AppendMenu(hMenu, MF_POPUP|(::GetMenuItemCount(hGroupMenu) ? 0 : MF_GRAYED), (UINT)hGroupMenu, GROUPSELECT_MSGSTR);
// ::AppendMenu(hMenu, MF_SEPARATOR, 0, 0);
SetMainMenu(hMenu);
::TrackPopupMenu(hMenu, TPM_RIGHTBUTTON, pos.x, pos.y, 0, hWnd, NULL);
::DestroyMenu(hMenu);
}
void TSendDlg::SetMainMenu(HMENU hMenu)
{
::AppendMenu(hMenu, MF_STRING, MENU_FINDDLG, FINDDLG_MSGSTR);
::AppendMenu(hMenu, MF_STRING, MENU_FILEADD, FILEATTACHMENU_MSGSTR);
::AppendMenu(hMenu, MF_STRING, MENU_FOLDERADD, FOLDERATTACHMENU_MSGSTR);
::AppendMenu(hMenu, MF_SEPARATOR, 0, 0);
::AppendMenu(hMenu, MF_STRING, MENU_SAVECOLUMN, SAVECOLUMN_MSGSTR);
::AppendMenu(hMenu, MF_POPUP, (UINT)::LoadMenu(TApp::hI, (LPCSTR)SENDFONT_MENU), FONTSET_MSGSTR);
::AppendMenu(hMenu, MF_POPUP, (UINT)::LoadMenu(TApp::hI, (LPCSTR)SIZE_MENU), SIZESET_MSGSTR);
::AppendMenu(hMenu, MF_STRING, MENU_SAVEPOS, SAVEPOS_MSGSTR);
::AppendMenu(hMenu, MF_STRING, MENU_MEMBERDISP, MEMBERDISP_MSGSTR);
}
BOOL SetFileButton(TDlg *dlg, int buttonID, ShareInfo *info)
{
char buf[MAX_BUF] = "", fname[MAX_PATH];
int offset = 0;
for (int cnt=0; cnt < info->fileCnt; cnt++)
{
if (dlg->ResId() == SEND_DIALOG)
ForcePathToFname(info->fileInfo[cnt]->Fname(), fname);
else
strncpyz(fname, info->fileInfo[cnt]->Fname(), MAX_PATH);
offset += wsprintf(buf + offset, "%s ", fname);
if (offset + MAX_PATH >= sizeof(buf))
break;
}
dlg->SetDlgItemText(buttonID, buf);
::ShowWindow(dlg->GetDlgItem(buttonID), info->fileCnt ? SW_SHOW : SW_HIDE);
::EnableWindow(dlg->GetDlgItem(buttonID), info->fileCnt ? TRUE : FALSE);
return TRUE;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -