?? share.cpp
字號:
memset(&lvC, 0, sizeof(lvC));
lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
char *title[] = { "No", "Files", "Size", "All/done/trans", "Users", NULL };
int size[] = { 30, 110, 70, 100, 100 };
int fmt[] = { LVCFMT_RIGHT, LVCFMT_LEFT, LVCFMT_RIGHT, LVCFMT_RIGHT, LVCFMT_LEFT };
for (lvC.iSubItem = 0; title[lvC.iSubItem]; lvC.iSubItem++)
{
lvC.pszText = title[lvC.iSubItem];
lvC.fmt = fmt[lvC.iSubItem];
lvC.cx = size[lvC.iSubItem];
SendDlgItemMessage(SHARE_LIST, LVM_INSERTCOLUMN, lvC.iSubItem, (LPARAM)&lvC);
}
shareListView.CreateByWnd(GetDlgItem(SHARE_LIST));
SetAllList();
SendDlgItemMessage(MODIFY_CHECK, BM_SETCHECK, (cfg->fileTransOpt & FT_STRICTDATE) ? TRUE : FALSE, 0);
if (rect.left == CW_USEDEFAULT)
{
GetWindowRect(&rect);
int xsize = rect.right - rect.left, ysize = rect.bottom - rect.top;
int cx = ::GetSystemMetrics(SM_CXFULLSCREEN), cy = ::GetSystemMetrics(SM_CYFULLSCREEN);
int x = (cx - xsize)/2;
int y = (cy - ysize)/2;
MoveWindow((x < 0) ? 0 : x % (cx - xsize), (y < 0) ? 0 : y % (cy - ysize), xsize, ysize, FALSE);
}
else
MoveWindow(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, FALSE);
Show();
::SetFocus(shareListView.hWnd);
return TRUE;
}
BOOL TShareStatDlg::Refresh(void)
{
if (hWnd == NULL)
return FALSE;
SetAllList();
return TRUE;
}
BOOL TShareStatDlg::SetAllList(void)
{
SendDlgItemMessage(SHARE_LIST, LVM_DELETEALLITEMS, 0, 0);
LV_ITEM lvi;
memset(&lvi, 0, sizeof(lvi));
int cnt = 0;
for (ShareInfo *info=shareMng->Top(); info; info=shareMng->Next(info))
{
if (info->hostCnt == 0)
continue;
lvi.iItem = cnt++;
lvi.mask = LVIF_TEXT|LVIF_PARAM;
lvi.pszText = LPSTR_TEXTCALLBACK;
lvi.lParam = (LPARAM)info->packetNo;
SendDlgItemMessage(SHARE_LIST, LVM_INSERTITEM, 0, (LPARAM)&lvi);
}
return TRUE;
}
BOOL TShareStatDlg::DelList(int cnt)
{
LV_ITEM lvi;
memset(&lvi, 0, sizeof(lvi));
lvi.iItem = cnt;
lvi.mask = LVIF_PARAM;
SendDlgItemMessage(SHARE_LIST, LVM_GETITEM, 0, (LPARAM)&lvi);
SendDlgItemMessage(SHARE_LIST, LVM_DELETEITEM, cnt, 0);
ShareInfo *info = shareMng->Search(lvi.lParam);
if (info == NULL)
return FALSE;
for (cnt=info->fileCnt * info->hostCnt -1; cnt >= 0; cnt--)
if (info->transStat[cnt] == ShareMng::TRANS_BUSY)
return FALSE;
shareMng->DestroyShare(info);
return TRUE;
}
BOOL TShareStatDlg::EvNotify(UINT ctlID, NMHDR *pNmHdr)
{
if (pNmHdr->code == LVN_GETDISPINFO)
{
LV_DISPINFO *dispInfo = (LV_DISPINFO *)pNmHdr;
ShareInfo *info = shareMng->Search(dispInfo->item.lParam);
ShareCntInfo cntInfo;
char buf[MAX_BUF] = "";
int len = 0, cnt;
dispInfo->item.pszText = lvBuf;
switch (dispInfo->item.iSubItem) {
case 0: wsprintf(lvBuf, "%d", dispInfo->item.iItem); break;
case 1:
for (cnt=0; cnt < info->fileCnt && len < sizeof(lvBuf); cnt++)
{
ForcePathToFname(info->fileInfo[cnt]->Fname(), lvBuf);
len += wsprintf(buf + len, "%s ", lvBuf);
}
strncpyz(lvBuf, buf, sizeof(lvBuf));
break;
case 2:
shareMng->GetShareCntInfo(&cntInfo, info);
MakeSizeString(lvBuf, cntInfo.totalSize, MSS_SPACE);
if (cntInfo.dirCnt)
wsprintf(lvBuf + strlen(lvBuf), "/%dDIR", cntInfo.dirCnt);
break;
case 3:
shareMng->GetShareCntInfo(&cntInfo, info);
wsprintf(lvBuf, "%d / %d/ %d", cntInfo.fileCnt, cntInfo.doneCnt, cntInfo.transferCnt);
break;
case 4:
for (cnt=0; cnt < info->hostCnt && len < sizeof(lvBuf); cnt++)
len += wsprintf(buf + len, "%.14s(%.10s) ", *info->host[cnt]->nickName ? info->host[cnt]->nickName : info->host[cnt]->hostSub.userName, info->host[cnt]->hostSub.hostName);
strncpyz(lvBuf, buf, sizeof(lvBuf));
break;
default: return FALSE;
}
return TRUE;
}
return FALSE;
}
BOOL TShareStatDlg::EvCommand(WORD wNotifyCode, WORD wID, LPARAM hWndCtl)
{
switch (wID)
{
case IDOK: EndDialog(TRUE); break;
case IDCANCEL: EndDialog(FALSE); break;
case DEL_BUTTON:
{
for (int cnt=SendDlgItemMessage(SHARE_LIST, LVM_GETITEMCOUNT, 0, 0)-1; cnt >= 0; cnt--)
{
if ((SendDlgItemMessage(SHARE_LIST, LVM_GETITEMSTATE, cnt, LVIS_SELECTED) & LVIS_SELECTED) == 0)
continue;
DelList(cnt);
}
SetAllList();
}
break;
case MODIFY_CHECK:
cfg->fileTransOpt = SendDlgItemMessage(MODIFY_CHECK, BM_GETCHECK, 0, 0) ? FT_STRICTDATE : 0;
cfg->WriteRegistry(CFG_GENERAL);
break;
default: break;
}
return TRUE;
}
#define PRIOR_BUTTON 2000
#define NEXT_BUTTON 2001
#define LUMP_CHECK 2002
#define RESULT_STATIC 2003
TSaveCommonDlg::TSaveCommonDlg(ShareInfo *_shareInfo, Cfg *_cfg, TWin *_parentWin) : TDlg((UINT)0, _parentWin)
{
parentWin = _parentWin;
shareInfo = _shareInfo;
cfg = _cfg;
offset = 0;
for (int cnt=0; cnt < shareInfo->fileCnt; cnt++)
shareInfo->fileInfo[cnt]->SetSelected(FALSE);
}
int TSaveCommonDlg::Exec(void)
{
modalFlg = TRUE;
char fname[MAX_BUF];
FileInfo *fileInfo = shareInfo->fileInfo[offset];
// 嵟廔曐懚僨傿儗僋僩儕偑柍偔側偭偰偄傞応崌丄彮偟偝偐偺傏傞
for (int cnt=0; cnt < 5; cnt++)
if (*cfg->lastSaveDir && GetFileAttributes(cfg->lastSaveDir) == 0xffffffff)
if (PathToDir(cfg->lastSaveDir, cfg->lastSaveDir) == FALSE)
break;
if (*cfg->lastSaveDir && strstr(fileInfo->Fname(), ":\\") == NULL) {
MakePath(fname, cfg->lastSaveDir, fileInfo->Fname());
fname[MAX_PATH -1] = 0;
}
else strncpyz(fname, fileInfo->Fname(), MAX_PATH);
while (1)
{
// 僼傽僀儖僟僀傾儘僌
TApp::AddWin(this);
BOOL ret = OpenFileDlg(parentWin, OpenFileDlg::NODEREF_SAVE, (LPOFNHOOKPROC)TApp::WinProc).Exec(fname, SAVEFILE_MSGSTR, OPENFILEALL_MSGSTR, cfg->lastSaveDir);
TApp::DelWin(this);
hWnd = NULL;
if (ret == FALSE)
return FALSE;
fileInfo = shareInfo->fileInfo[offset];
PathToDir(fname, cfg->lastSaveDir);
ForcePathToFname(fname, fname);
fileInfo->SetFname(fname);
fileInfo->SetSelected(TRUE);
// 忋彂偒妋擣
for (int cnt=0; cnt < shareInfo->fileCnt; cnt++)
{
if (shareInfo->fileInfo[cnt]->IsSelected() == FALSE)
continue;
MakePath(fname, cfg->lastSaveDir, shareInfo->fileInfo[cnt]->Fname());
if (::GetFileAttributes(fname) != 0xffffffff)
{
if ((ret = parentWin->MessageBox(OVERWRITE_MSGSTR, ATTENTION_MSGSTR, MB_OKCANCEL|MB_ICONEXCLAMATION) == IDOK) == FALSE)
for (int cnt2=0; cnt2 < shareInfo->fileCnt; cnt2++)
shareInfo->fileInfo[cnt2]->SetSelected(FALSE);
break;
}
}
if (ret)
return cfg->WriteRegistry(CFG_GENERAL), TRUE;
}
// not reach
}
BOOL TSaveCommonDlg::EvCreate(LPARAM lParam)
{
RECT ok_rect = { 0, 0, 50, 20 }, cl_rect;
HWND pWnd = ::GetParent(hWnd);
::ShowWindow(::GetDlgItem(pWnd, 0x441), SW_HIDE);
::ShowWindow(::GetDlgItem(pWnd, 0x470), SW_HIDE);
// if (shareInfo->fileCnt == 1)
// return TRUE;
if (::GetWindowRect(::GetDlgItem(pWnd, IDOK), &ok_rect) == FALSE)
return TRUE;
int ok_xsize = ok_rect.right - ok_rect.left;
int ok_ysize = ok_rect.bottom - ok_rect.top;
// 儃僞儞崅偝偺2攞暘峀偘傞
SetWindowLong(GWL_STYLE, GetWindowLong(GWL_STYLE)|WS_CLIPSIBLINGS);
::GetClientRect(pWnd, &cl_rect);
GetWindowRect(&rect);
MoveWindow(0, 0, cl_rect.right, (rect.bottom - rect.top) + ok_ysize * 5 / 2, FALSE);
GetWindowRect(&rect);
int cx = 20, cy = ok_ysize;
::CreateWindow(STATIC_CLASS, "", WS_CHILD|WS_VISIBLE|SS_LEFT, cx, 0, rect.right, ok_ysize, hWnd, (HMENU)RESULT_STATIC, TApp::hI, NULL);
DWORD flg = (shareInfo->fileCnt == 1 ? WS_DISABLED : 0)|WS_CHILD|WS_VISIBLE;
::CreateWindow(BUTTON_CLASS, PREVBUTTON_MSGSTR, flg | BS_PUSHBUTTON, cx, cy, ok_xsize, ok_ysize, hWnd, (HMENU)PRIOR_BUTTON, TApp::hI, NULL);
::CreateWindow(BUTTON_CLASS, NEXTBUTTON_MSGSTR, flg | BS_PUSHBUTTON, cx+=ok_xsize+20, cy, ok_xsize, ok_ysize, hWnd, (HMENU)NEXT_BUTTON, TApp::hI, NULL);
::CreateWindow(BUTTON_CLASS, "", WS_CHILD|WS_VISIBLE|BS_CHECKBOX, cx+=ok_xsize+20, cy, ok_xsize * 2, ok_ysize, hWnd, (HMENU)LUMP_CHECK, TApp::hI, NULL);
HFONT hDlgFont = (HFONT)::SendDlgItemMessage(pWnd, IDOK, WM_GETFONT, 0, 0L);
if (hDlgFont)
{
SendDlgItemMessage(RESULT_STATIC, WM_SETFONT, (UINT)hDlgFont, 0L);
SendDlgItemMessage(PRIOR_BUTTON, WM_SETFONT, (UINT)hDlgFont, 0L);
SendDlgItemMessage(NEXT_BUTTON, WM_SETFONT, (UINT)hDlgFont, 0L);
SendDlgItemMessage(LUMP_CHECK, WM_SETFONT, (UINT)hDlgFont, 0L);
}
SetInfo();
return TRUE;
}
BOOL TSaveCommonDlg::EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl)
{
switch (wID) {
case PRIOR_BUTTON:
if (offset > 0)
offset--;
SetInfo();
return TRUE;
case NEXT_BUTTON:
if (offset < shareInfo->fileCnt -1)
offset++;
SetInfo();
return TRUE;
case LUMP_CHECK:
{
BOOL checked = ::SendMessage((HWND)hwndCtl, BM_GETCHECK, 0, 0) == 0;
::SendMessage((HWND)hwndCtl, BM_SETCHECK, checked, 0);
for (int cnt=0; cnt < shareInfo->fileCnt; cnt++)
shareInfo->fileInfo[cnt]->SetSelected(checked);
}
return TRUE;
}
return FALSE;
}
BOOL TSaveCommonDlg::EventUser(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
return FALSE;
}
BOOL TSaveCommonDlg::SetInfo(void)
{
char buf[MAX_BUF], sizestr[MAX_LISTBUF];
::SetDlgItemText(::GetParent(hWnd), 0x480, shareInfo->fileInfo[offset]->Fname());
if (GET_MODE(shareInfo->fileInfo[offset]->Attr()) == IPMSG_FILE_DIR)
strcpy(sizestr, DIRSAVE_MSGSTR);
else
MakeSizeString(sizestr, shareInfo->fileInfo[offset]->Size());
wsprintf(buf, FILEINFO_MSGSTR, offset + 1, shareInfo->fileCnt, shareInfo->fileInfo[offset]->Fname(), sizestr);
SetDlgItemText(RESULT_STATIC, buf);
_int64 total_size = 0;
for (int cnt=0; cnt < shareInfo->fileCnt; cnt++)
total_size += shareInfo->fileInfo[cnt]->Size();
MakeSizeString(sizestr, total_size);
wsprintf(buf, LUMPBUTTON_MSGSTR, sizestr, shareInfo->fileCnt);
SetDlgItemText(LUMP_CHECK, buf);
return TRUE;
}
/*
僼傽僀儖嫟桳乮揧晅乯忣曬傪僄儞僐乕僪
*/
BOOL EncodeShareMsg(ShareInfo *info, char *buf, int bufsize)
{
int offset=0;
char fname[MAX_PATH];
*buf = 0;
for (int cnt=0; cnt < info->fileCnt; cnt++)
{
ForcePathToFname(info->fileInfo[cnt]->Fname(), fname);
info->fileInfo[cnt]->SetId(cnt);
offset += wsprintf(buf + offset, (info->fileInfo[cnt]->Size() >> 32) ? "%d:%s:%x%08x:%x:%s" : "%d:%s:%x%x:%x:", cnt, fname, (int)(info->fileInfo[cnt]->Size() >> 32), (int)info->fileInfo[cnt]->Size(), info->fileInfo[cnt]->Mtime());
// if (GET_MODE(info->fileInfo[cnt]->Attr()) == IPMSG_FILE_DIR)
offset += wsprintf(buf + offset, "%x:", info->fileInfo[cnt]->Attr());
offset += wsprintf(buf + offset, "%c", FILELIST_SEPARATOR);
if (offset + MAX_BUF > bufsize)
break;
}
return TRUE;
}
/*
僼傽僀儖柤偵 ':' 傪娷傓応崌丄"::" 偲僄僗働乕僾偝傟偰偄傞偑丄
Windows 偱偼巊偊側偄偺偱丄';' 偵抲偒姺偊傞
*/
void ConvertShareMsgEscape(char *str)
{
char *ptr;
while ((ptr = strstr(str, "::")) != NULL)
{
*ptr++ = ';';
memmove(ptr, ptr + 1, strlen(ptr));
}
}
/*
僼傽僀儖嫟桳乮揧晅乯忣曬傪僨僐乕僪
拲堄丗攋夡撉弌偟丅巊梡偑廔傢傝師戞 FreeDecodeShareMsg 傪屇傃弌偡偙偲丅
*/
ShareInfo *DecodeShareMsg(char *buf)
{
ShareInfo *shareInfo = new ShareInfo;
FileInfo *fileInfo = NULL;
char *tok, *p, *p2, *p3;
char *file = separate_token(buf, FILELIST_SEPARATOR, &p);
for (int cnt=0; file; cnt++, file=separate_token(NULL, FILELIST_SEPARATOR, &p))
{
ConvertShareMsgEscape(file); // "::" -> ';'
if ((tok = separate_token(file, ':', &p2)) == NULL)
break;
fileInfo = new FileInfo(atoi(tok));
if ((tok = separate_token(NULL, ':', &p2)) == NULL || strlen(tok) >= MAX_PATH)
break;
while ((p3 = strchr(tok, '?')) != NULL) // UNICODE 傑偱偺巄掕
*p3 = '_';
fileInfo->SetFname(tok);
if ((tok = separate_token(NULL, ':', &p2)) == NULL)
break;
fileInfo->SetSize(hex2ll(tok));
if ((tok = separate_token(NULL, ':', &p2)) == NULL)
break;
fileInfo->SetMtime(strtoul(tok, 0, 16));
if ((tok = separate_token(NULL, ':', &p2)))
{
fileInfo->SetAttr(strtoul(tok, 0, 16));
u_int attr_type = GET_MODE(fileInfo->Attr());
if (attr_type != IPMSG_FILE_DIR && attr_type != IPMSG_FILE_REGULAR)
{
delete fileInfo;
continue;
}
}
else fileInfo->SetAttr(IPMSG_FILE_REGULAR);
if ((shareInfo->fileCnt % BIG_ALLOC) == 0)
shareInfo->fileInfo = (FileInfo **)realloc(shareInfo->fileInfo, (shareInfo->fileCnt + BIG_ALLOC) * sizeof(FileInfo *));
shareInfo->fileInfo[shareInfo->fileCnt++] = fileInfo;
fileInfo = NULL;
}
if (fileInfo) // 僨僐乕僪拞偵敳偗偨
delete fileInfo;
if (shareInfo->fileCnt <= 0)
{
delete shareInfo;
return NULL;
}
return shareInfo;
}
/*
僨僐乕僪忣曬偺奐曻
*/
BOOL FreeDecodeShareMsg(ShareInfo *info)
{
while (info->fileCnt-- > 0)
delete info->fileInfo[info->fileCnt];
free(info->fileInfo);
delete info;
return TRUE;
}
/*
僨僐乕僪忣曬撪偺僼傽僀儖忣曬嶍彍
*/
BOOL FreeDecodeShareMsgFile(ShareInfo *info, int index)
{
if (index >= info->fileCnt)
return FALSE;
delete info->fileInfo[index];
memmove(info->fileInfo + index, info->fileInfo + index +1, sizeof(FileInfo *) * (--info->fileCnt - index));
return TRUE;
}
ShareInfo::ShareInfo(int _packetNo)
{
packetNo = _packetNo;
host = NULL;
transStat = NULL;
fileInfo = NULL;
hostCnt = fileCnt = 0;
}
void ShareInfo::LinkList(ShareInfo *top)
{
prior = top->prior;
next = top;
top->prior->next = this;
top->prior = this;
}
BOOL GetFileInfomation(const char *path, WIN32_FIND_DATA *fdata)
{
HANDLE fh;
if ((fh = ::FindFirstFile(path, fdata)) != INVALID_HANDLE_VALUE)
{
::FindClose(fh);
return TRUE;
}
memset(fdata, 0, sizeof(WIN32_FIND_DATA));
if ((fh = ::CreateFile(path, GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)) != INVALID_HANDLE_VALUE)
{
BY_HANDLE_FILE_INFORMATION info;
BOOL info_ret = ::GetFileInformationByHandle(fh, &info);
::CloseHandle(fh);
if (info_ret)
return memcpy(fdata, &info, (char *)&info.dwVolumeSerialNumber - (char *)&info), TRUE;
}
return (fdata->dwFileAttributes = ::GetFileAttributes(path)) == 0xffffffff ? FALSE : TRUE;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -