⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainwin.cpp

📁 FastCopy 利用缓冲技术加快文件拷贝
💻 CPP
📖 第 1 页 / 共 4 页
字号:
		if (wID >= JOBOBJ_MENUITEM_START && wID <= JOBOBJ_MENUITEM_END) {
			int idx = wID - JOBOBJ_MENUITEM_START;
			if (idx < cfg.jobMax) {
				SetJob(idx);
			}
			return TRUE;
		}
		break;
	}
	return	FALSE;
}

BOOL TMainDlg::EvSysCommand(WPARAM uCmdType, POINTS pos)
{
	switch (uCmdType)
	{
	case SC_RESTORE: case SC_MAXIMIZE:
		return	TRUE;

	case SC_MINIMIZE:
		PostMessage(WM_FASTCOPY_HIDDEN, 0, 0);
		return	TRUE;
	}
	return	FALSE;
}

BOOL TMainDlg::EvSize(UINT fwSizeType, WORD nWidth, WORD nHeight)
{
	if (fwSizeType != SIZE_RESTORED && fwSizeType != SIZE_MAXIMIZED)
		return	FALSE;

	RefreshWindow();
	return	TRUE;
}

void TMainDlg::RefreshWindow(BOOL is_start_stop)
{
	GetWindowRect(&rect);
	int	xdiff = (rect.right - rect.left) - (orgRect.right - orgRect.left);
	int ydiff = (rect.bottom - rect.top) - (orgRect.bottom - orgRect.top) + (isErrEditHide ? normalHeight - miniHeight : 0);

	HDWP	hdwp = ::BeginDeferWindowPos(max_dlgitem);	// MAX item number
	UINT	dwFlg		= SWP_SHOWWINDOW | SWP_NOZORDER;
	UINT	dwHideFlg	= SWP_HIDEWINDOW | SWP_NOZORDER;
	DlgItem	*item;
	int		*target;
	BOOL	is_delete = GetCopyMode() == FastCopy::DELETE_MODE;

	int	slide_y[] = { errstatus_item, errstatic_item, -1 };
	for (target=slide_y; *target != -1; target++) {
		item = dlgItems + *target;
		hdwp = ::DeferWindowPos(hdwp, item->hWnd, 0, item->wpos.x, item->wpos.y + ydiff, item->wpos.cx, item->wpos.cy, isErrEditHide ? dwHideFlg : dwFlg);
	}

	item = dlgItems + erredit_item;
	hdwp = ::DeferWindowPos(hdwp, item->hWnd, 0, item->wpos.x, item->wpos.y + ydiff, item->wpos.cx + xdiff, item->wpos.cy, isErrEditHide ? dwHideFlg : dwFlg);

	item = dlgItems + path_item;
	hdwp = ::DeferWindowPos(hdwp, item->hWnd, 0, item->wpos.x, item->wpos.y, item->wpos.cx + xdiff, item->wpos.cy + ydiff, dwFlg);

	item = dlgItems + filter_item;
	hdwp = ::DeferWindowPos(hdwp, item->hWnd, 0, item->wpos.x + xdiff, item->wpos.y, item->wpos.cx, item->wpos.cy, dwFlg);

	int	harf_growslide_x[] = { exccombo_item, excstatic_item, -1 };
	for (target=harf_growslide_x; *target != -1; target++) {
		item = dlgItems + *target;
		hdwp = ::DeferWindowPos(hdwp, item->hWnd, 0, item->wpos.x + xdiff/2, item->wpos.y, item->wpos.cx + xdiff/2, item->wpos.cy, dwFlg);
	}

	int	harf_glow_x[] = { inccombo_item, incstatic_item, -1 };
	for (target=harf_glow_x; *target != -1; target++) {
		item = dlgItems + *target;
		hdwp = ::DeferWindowPos(hdwp, item->hWnd, 0, item->wpos.x, item->wpos.y, item->wpos.cx + xdiff/2, item->wpos.cy, dwFlg);
	}

	BOOL	is_exec = fastCopy.IsStarting() || isDelay;

	int	slide_x[] = { ok_item, list_item, samedrv_item, top_item, estimate_item, autoslow_item, autoslowstatic_item, ignore_item, bufedit_item, bufstatic_item, help_item, mode_item, -1 };
	for (target=slide_x; *target != -1; target++) {
		item = dlgItems + *target;
		hdwp = ::DeferWindowPos(hdwp, item->hWnd, 0, item->wpos.x + xdiff, item->wpos.y, item->wpos.cx, item->wpos.cy,
			is_exec && (*target == list_item && !IsListing() || *target == ok_item && IsListing()) ||
			is_delete && *target == estimate_item ? dwHideFlg : dwFlg);
	}

	int	grow_x[] = { srccombo_item, dstcombo_item, -1 };
	for (target=grow_x; *target != -1; target++) {
		item = dlgItems + *target;
		hdwp = ::DeferWindowPos(hdwp, item->hWnd, 0, item->wpos.x, item->wpos.y, item->wpos.cx + xdiff, item->wpos.cy, dwFlg);
	}

	item = dlgItems + atonce_item;
	hdwp = ::DeferWindowPos(hdwp, item->hWnd, 0, item->wpos.x, item->wpos.y, item->wpos.cx + xdiff, item->wpos.cy, !isDelay ? dwHideFlg : dwFlg);

	item = dlgItems + status_item;
	hdwp = ::DeferWindowPos(hdwp, item->hWnd, 0, item->wpos.x, item->wpos.y, item->wpos.cx + xdiff, (!isDelay ? dlgItems[atonce_item].wpos.y + dlgItems[atonce_item].wpos.cy - item->wpos.y : item->wpos.cy), dwFlg);

	EndDeferWindowPos(hdwp);

	if (is_start_stop) {
		BOOL	flg = !fastCopy.IsStarting();
		::EnableWindow(dlgItems[estimate_item].hWnd, flg);
		::EnableWindow(dlgItems[ignore_item].hWnd, flg);
	}
}

void TMainDlg::SetDlgItem(UINT ctl_id, DlgItem *item)
{
	WINDOWPLACEMENT wp;
	wp.length = sizeof(wp);

	item->hWnd = GetDlgItem(ctl_id);
	::GetWindowPlacement(item->hWnd, &wp);
	item->wpos.x = wp.rcNormalPosition.left;
	item->wpos.y = wp.rcNormalPosition.top;
	item->wpos.cx = wp.rcNormalPosition.right - wp.rcNormalPosition.left;
	item->wpos.cy = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top;
}

void TMainDlg::SetSize(void)
{
	SetDlgItem(SRC_FILE_BUTTON,	&dlgItems[srcbutton_item]);
	SetDlgItem(DST_FILE_BUTTON,	&dlgItems[dstbutton_item]);
	SetDlgItem(SRC_COMBO,		&dlgItems[srccombo_item]);
	SetDlgItem(DST_COMBO,		&dlgItems[dstcombo_item]);
	SetDlgItem(STATUS_EDIT,		&dlgItems[status_item]);
	SetDlgItem(MODE_COMBO,		&dlgItems[mode_item]);
	SetDlgItem(BUF_STATIC,		&dlgItems[bufstatic_item]);
	SetDlgItem(BUFSIZE_EDIT,	&dlgItems[bufedit_item]);
	SetDlgItem(HELP_BUTTON,		&dlgItems[help_item]);
	SetDlgItem(IGNORE_CHECK,	&dlgItems[ignore_item]);
	SetDlgItem(ESTIMATE_CHECK,	&dlgItems[estimate_item]);
	SetDlgItem(AUTOSLOW_CHECK,	&dlgItems[autoslow_item]);
	SetDlgItem(AUTOSLOW_STATIC,	&dlgItems[autoslowstatic_item]);
	SetDlgItem(TOPLEVEL_CHECK,	&dlgItems[top_item]);
	SetDlgItem(LIST_BUTTON,		&dlgItems[list_item]);
	SetDlgItem(IDOK,			&dlgItems[ok_item]);
	SetDlgItem(ATONCE_BUTTON,	&dlgItems[atonce_item]);
	SetDlgItem(SAMEDRV_STATIC,	&dlgItems[samedrv_item]);
	SetDlgItem(INC_STATIC,		&dlgItems[incstatic_item]);
	SetDlgItem(EXC_STATIC,		&dlgItems[excstatic_item]);
	SetDlgItem(INCLUDE_COMBO,	&dlgItems[inccombo_item]);
	SetDlgItem(EXCLUDE_COMBO,	&dlgItems[exccombo_item]);
	SetDlgItem(FILTER_CHECK,	&dlgItems[filter_item]);
	SetDlgItem(PATH_EDIT,		&dlgItems[path_item]);
	SetDlgItem(ERR_STATIC,		&dlgItems[errstatic_item]);
	SetDlgItem(ERRSTATUS_STATIC,&dlgItems[errstatus_item]);
	SetDlgItem(ERR_EDIT,		&dlgItems[erredit_item]);

	GetWindowRect(&rect);
	orgRect = rect;
}

/*
	DropFiles Event CallBack
*/
BOOL TMainDlg::EvDropFiles(HDROP hDrop)
{
	PathArray	pathArray;
	WCHAR	path[MAX_PATH_EX];
	BOOL	isDstDrop = IsDestDropFiles(hDrop);
	BOOL	isDeleteMode = GetCopyMode() == FastCopy::DELETE_MODE;
	int		max = isDstDrop ? 1 : ::DragQueryFileV(hDrop, 0xffffffff, 0, 0), max_len = 0;

	// CTL 偑墴偝傟偰偄傞応崌丄尰嵼偺撪梕傪壛嶼
	if (!isDstDrop) {
		if (::GetAsyncKeyState(VK_CONTROL) & 0x8000) {
			max_len = ::GetWindowTextLengthV(GetDlgItem(SRC_COMBO)) + 1;
			WCHAR	*buf = new WCHAR [max_len];
			GetDlgItemTextV(SRC_COMBO, buf, max_len);
			pathArray.RegisterMultiPath(buf);
			delete [] buf;
		}
		else
			isNetPlaceSrc = FALSE;
	}

	for (int i=0; i < max; i++) {
		if (::DragQueryFileV(hDrop, i, path, sizeof(path) / CHAR_LEN_V) <= 0)
			break;

		if (isDstDrop || !isDeleteMode) {
			if (NetPlaceConvertV(path, path) && !isDstDrop)
				isNetPlaceSrc = TRUE;
		}
		max_len += strlenV(path) + 3;
		pathArray.RegisterPath(path);
	}
	::DragFinish(hDrop);

	if (max_len > 0) {
		WCHAR	*buf = new WCHAR [max_len += pathArray.Num() * 2];	// 暥帤楍楢寢梡椞堟

		if (isDstDrop) {
			DWORD	attr = ::GetFileAttributesV(pathArray.Path(0));
			if (attr & FILE_ATTRIBUTE_DIRECTORY) {	// 0xffffffff 傕擣傔傞(for 95宯OS偺root懳嶔)
				MakePathV(path, pathArray.Path(0), EMPTY_STR_V);
				SetDlgItemTextV(DST_COMBO, path);
			}
		}
		else {
			if (pathArray.GetMultiPath(buf, max_len))
				SetDlgItemTextV(SRC_COMBO, buf);
		}
		delete [] buf;
	}
	return	TRUE;
}

FastCopy::Mode TMainDlg::GetCopyMode(void)
{
	return	COPYINFO_LIST[SendDlgItemMessage(MODE_COMBO, CB_GETCURSEL, 0, 0)].mode;
}

void TMainDlg::ReflectFilterCheck(BOOL is_invert)
{
	BOOL	is_show_filter = GetCopyMode() != FastCopy::MOVE_MODE;
	BOOL	is_checked = IsDlgButtonChecked(FILTER_CHECK);
	BOOL	new_status = (is_invert ? !is_checked : is_checked) && is_show_filter;

//	::ShowWindow(GetDlgItem(FILTER_CHECK), is_show_filter ? SW_SHOW : SW_HIDE);
//	::ShowWindow(GetDlgItem(INCLUDE_COMBO), is_show_filter ? SW_SHOW : SW_HIDE);
//	::ShowWindow(GetDlgItem(EXCLUDE_COMBO), is_show_filter ? SW_SHOW : SW_HIDE);
//	if (is_show_filter)
		::CheckDlgButton(hWnd, FILTER_CHECK, new_status);
	::EnableWindow(GetDlgItem(FILTER_CHECK), is_show_filter);
	::EnableWindow(GetDlgItem(INCLUDE_COMBO), new_status);
	::EnableWindow(GetDlgItem(EXCLUDE_COMBO), new_status);
}

BOOL TMainDlg::IsDestDropFiles(HDROP hDrop)
{
	POINT	pt;
	RECT	dst_rect;

	if (::DragQueryPoint(hDrop, &pt) == FALSE || ::ClientToScreen(hWnd, &pt) == FALSE)
		return	FALSE;

	if (::GetWindowRect(GetDlgItem(DST_COMBO), &dst_rect) == FALSE || PtInRect(&dst_rect, pt) == FALSE)
		return	FALSE;

	return	TRUE;
}


BOOL TMainDlg::ExecCopy(DWORD exec_flags)
{
	int		idx = SendDlgItemMessage(MODE_COMBO, CB_GETCURSEL, 0, 0);
	BOOL	is_delete_mode = COPYINFO_LIST[idx].mode == FastCopy::DELETE_MODE;
	BOOL	is_filter = IsDlgButtonChecked(FILTER_CHECK);
	BOOL	is_listing = (exec_flags & LISTING_EXEC) ? TRUE : FALSE;

	info.ignoreErr		= IsDlgButtonChecked(IGNORE_CHECK);
	info.mode			= COPYINFO_LIST[idx].mode;
	info.overWrite		= COPYINFO_LIST[idx].overWrite;
	info.isPhysLock		= IS_WINNT_V ? TRUE : FALSE;
	info.lcid			= cfg.lcid > 0 && IsWinNT() ? ::GetThreadLocale() : 0;
	info.flags			= cfg.copyFlags
		| (!is_delete_mode && IsDlgButtonChecked(ESTIMATE_CHECK) && !is_listing ? FastCopy::PRE_SEARCH : 0)
		| (cfg.isSameDirRename ? FastCopy::SAMEDIR_RENAME : 0)
		| (cfg.isAutoSlowIo ? FastCopy::AUTOSLOW_IOLIMIT : 0)
		| (is_listing ? FastCopy::LISTING_ONLY : 0)
		| (skipEmptyDir && is_filter ? FastCopy::SKIP_EMPTYDIR : 0)
		| (diskMode == 0 ? 0 : diskMode == 1 ? FastCopy::FIX_SAMEDISK : FastCopy::FIX_DIFFDISK);
	info.bufSize		= GetDlgItemInt(BUFSIZE_EDIT) * 1024 * 1024;
	info.maxTransSize	= cfg.maxTransSize * 1024 * 1024;
	info.maxOpenFiles	= cfg.maxOpenFiles;
	info.maxAttrSize	= cfg.maxAttrSize;
	info.maxDirSize		= cfg.maxDirSize;
	info.nbMinSizeNtfs	= cfg.nbMinSizeNtfs * 1024;
	info.nbMinSizeFat	= cfg.nbMinSizeFat * 1024;
	info.notifyWnd		= this;
	info.uNotifyMsg		= WM_FASTCOPY_MSG;
	errBufOffset		= 0;
	listBufOffset		= 0;

	memset(&ti, 0, sizeof(ti));

	int		src_len = ::GetWindowTextLengthV(GetDlgItem(SRC_COMBO)) + 1;
	int		dst_len = ::GetWindowTextLengthV(GetDlgItem(DST_COMBO)) + 1;
	if (src_len <= 1 || !is_delete_mode && dst_len <= 1)
		return	FALSE;

	WCHAR	*src = new WCHAR [src_len], dst[MAX_PATH_EX] = L"";
	BOOL	ret = TRUE;
	BOOL	exec_confirm = cfg.execConfirm || (::GetAsyncKeyState(VK_CONTROL) & 0x8000);

	if (!exec_confirm) {
		if (isShellExt && (exec_flags & CMDLINE_EXEC))
			exec_confirm = is_delete_mode ? !cfg.shextRNoConfirm : !cfg.shextDdNoConfirm;
		else
			exec_confirm = is_delete_mode ? !noConfirmDel : cfg.execConfirm;
	}

	if (GetDlgItemTextV(SRC_COMBO, src, src_len) == 0 || !is_delete_mode && GetDlgItemTextV(DST_COMBO, dst, MAX_PATH_EX) == 0) {
		TMsgBox(this).Exec("Can't get src or dst field");
		ret = FALSE;
	}
	SendDlgItemMessage(PATH_EDIT, WM_SETTEXT, 0, (LPARAM)"");
	SendDlgItemMessage(STATUS_EDIT, WM_SETTEXT, 0, (LPARAM)"");

	PathArray	srcArray, dstArray, incArray, excArray;
	srcArray.RegisterMultiPath(src);
	if (!is_delete_mode)
		dstArray.RegisterPath(dst);

	// 僼傿儖僞
	WCHAR	inc[MAX_PATH] = L"", exc[MAX_PATH] = L"";
	if (is_filter) {
		GetDlgItemTextV(INCLUDE_COMBO, inc, MAX_PATH);
		GetDlgItemTextV(EXCLUDE_COMBO, exc, MAX_PATH);
		incArray.RegisterMultiPath(inc);
		excArray.RegisterMultiPath(exc);
	}

	// 妋擣梡僼傽僀儖堦棗
	if (ret && (ret = fastCopy.RegisterInfo(&srcArray, &dstArray, &info, &incArray, &excArray))) {
		if (!is_delete_mode && cfg.EntryPathHistory(src, dst))
			SetPathHistory();
		if (is_filter && cfg.EntryFilterHistory(inc, exc))
			SetFilterHistory();
		cfg.WriteIni();
	}
	else
		SetDlgItemText(STATUS_EDIT, "Error");

	int	src_list_len = src_len + srcArray.Num() * 4;
	void *src_list = new WCHAR [src_list_len];

	if (ret && exec_confirm && (exec_flags & LISTING_EXEC) == 0) {
		srcArray.GetMultiPath(src_list, src_list_len, NEWLINE_STR_V, EMPTY_STR_V);
		void	*title = info.mode == FastCopy::MOVE_MODE ? GetLoadStrV(IDS_MOVECONFIRM) : info.isRenameMode ? GetLoadStrV(IDS_DUPCONFIRM): NULL;
		if (TExecConfirmDlg(info.mode, &cfg, this, title).Exec(src_list, is_delete_mode ? NULL : dst) != IDOK) {
			ret = FALSE;
			if (isShellExt && !is_delete_mode)
				autoCloseLevel = NO_CLOSE;
		}
	}

	int		pathLogMax = src_len * CHAR_LEN_V + sizeof(dst);

	if (ret && (pathLogBuf = new char [pathLogMax])) {
		if (IS_WINNT_V) {
			srcArray.GetMultiPath(src_list, src_list_len);
			::WideCharToMultiByte(CP_ACP, 0, (WCHAR *)src_list, -1, (char *)src, src_len * CHAR_LEN_V, 0, 0);
			if (!is_delete_mode)
				::WideCharToMultiByte(CP_ACP, 0, (WCHAR *)dstArray.Path(0), -1, (char *)dst, sizeof(dst), 0, 0);
		}
		int len = sprintf(pathLogBuf, "<Source>  %s", src);
		if (!is_delete_mode) {
			len += sprintf(pathLogBuf + len, "\r\n<DestDir> %s", dst);
		}
		if (GetChar(inc, 0)) {
			len += sprintf(pathLogBuf + len, "\r\n<Include> ");
			len += GetDlgItemText(INCLUDE_COMBO, pathLogBuf + len, MAX_PATH);
		}
		if (GetChar(exc, 0)) {
			len += sprintf(pathLogBuf + len, "\r\n<Exclude> ");
			len += GetDlgItemText(EXCLUDE_COMBO, pathLogBuf + len, MAX_PATH);
		}
		len += sprintf(pathLogBuf + len, "\r\n<Command> %s\r\n\r\n", COPYINFO_LIST[idx].list_str);
	}

	delete [] src_list;
	delete [] src;

	if (ret) {
		SendDlgItemMessage(PATH_EDIT, EM_SETTARGETDEVICE, 0, IsListing() ? 1 : 0);	// 愜傝曉偟
		SetMiniWindow();
		SetDlgItemText(ERR_EDIT, "");

		if (forceStart == 1 || forceStart == 0 && is_delete_mode || fastCopy.TakeExclusivePriv()) {
			if (forceStart == 1 && !is_delete_mode)
				fastCopy.TakeExclusivePriv();
			ret = ExecCopyCore();
		}
		else {
			isDelay = TRUE;
			::SetTimer(hWnd, FASTCOPY_TIMER, 300, NULL);
			if (isTaskTray)
				TaskTray(NIM_MODIFY, hMainIcon[FCWAIT_ICON_INDEX], FASTCOPY);
		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -