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

📄 ftplistctrl.cpp

📁 一个支持FTP,SFTP的客户端程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				int j = i;
				while (j < 6)
				{
					m_Columns[j] = m_Columns[j+1];
					j++;
				}
				m_Columns[j] = 6;
				DeleteColumn(i);		
				if (m_sortcolumn==i)
					SortList(0, 1);
				if (m_sortcolumn > i)
					m_sortcolumn--;
				break;
			}
		}
	}
	else if (m_nHideColumns&4 && !(nHideColumns&4))
	{
		for (int i=1; i<4; i++)
		{
			if (m_Columns[i] >= 4)
			{
				int j = 6;
				while (j != i)
				{
					m_Columns[j] = m_Columns[j-1];
					j--;
				}
				m_Columns[i] = 3;

				str.LoadString(IDS_HEADER_DATE);
				InsertColumn(i, str, LVCFMT_LEFT, 68);
				if (m_sortcolumn >= i)
					m_sortcolumn++;
				RedrawItems(1, GetItemCount()-1);
				break;
			}
		}
	}
	if (nHideColumns&8 && !(m_nHideColumns&8))
	{
		for (int i=1; i<5; i++)
		{
			if (m_Columns[i] == 4)
			{
				int j = i;
				while (j < 6)
				{
					m_Columns[j] = m_Columns[j+1];
					j++;
				}
				m_Columns[j] = 6;

				DeleteColumn(i);		
				if (m_sortcolumn == i)
					SortList(0, 1);
				if (m_sortcolumn > i)
					m_sortcolumn--;
				break;
			}
		}
	}
	else if (m_nHideColumns&8 && !(nHideColumns&8))
	{
		for (int i=1; i<5; i++)
		{
			if (m_Columns[i] >= 5)
			{
				int j = 6;
				while (j != i)
				{
					m_Columns[j] = m_Columns[j-1];
					j--;
				}
				m_Columns[i] = 4;

				str.LoadString(IDS_HEADER_TIME);
				InsertColumn(i, str, LVCFMT_LEFT, 54);
				if (m_sortcolumn >= i)
					m_sortcolumn++;
				RedrawItems(1, GetItemCount()-1);
				break;
			}
		}
	}
	if (nHideColumns&0x10 && !(m_nHideColumns&0x10))
	{
		for (int i=1; i<6; i++)
		{
			if (m_Columns[i] == 5)
			{
				int j = i;
				while (j < 6)
				{
					m_Columns[j] = m_Columns[j+1];
					j++;
				}
				m_Columns[j] = 6;

				DeleteColumn(i);		
				if (m_sortcolumn == i)
					SortList(0, 1);
				if (m_sortcolumn > i)
					m_sortcolumn--;
				break;
			}
		}
	}
	else if (m_nHideColumns&0x10 && !(nHideColumns&0x10))
	{
		for (int i=1; i<6; i++)
		{
			if (m_Columns[i] >= 6)
			{
				int j = 6;
				while (j != i)
				{
					m_Columns[j] = m_Columns[j-1];
					j--;
				}
				m_Columns[i] = 5;

				str.LoadString(IDS_HEADER_PERMISSIONS);
				InsertColumn(i, str, LVCFMT_LEFT, 90);
				if (m_sortcolumn >= i)
					m_sortcolumn++;
				RedrawItems(1, GetItemCount()-1);
				break;
			}
		}
	}
	if (nHideColumns&0x20 && !(m_nHideColumns&0x20))
	{
		for (int i=1; i<7; i++)
		{
			if (m_Columns[i] == 6)
			{
				DeleteColumn(i);		
				if (m_sortcolumn == i)
					SortList(0, 1);
				if (m_sortcolumn > i)
					m_sortcolumn--;
				break;
			}
		}
	}
	else if (m_nHideColumns&0x20 && !(nHideColumns&0x20))
	{
		for (int i=1; i<7; i++)
		{
			if (m_Columns[i] == 6)
			{
				str.LoadString(IDS_HEADER_OWNERGROUP);
				InsertColumn(i, str, LVCFMT_LEFT, 90);
				if (m_sortcolumn >= i)
					m_sortcolumn++;
				RedrawItems(1, GetItemCount()-1);
				break;
			}
		}
	}
	m_nHideColumns = nHideColumns;
}
void CFtpListCtrl::OnGetdispinfo(NMHDR* pNMHDR, LRESULT* pResult) 
{
	LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
	if (!pDispInfo)
		return;

	LV_ITEM* pItem= &(pDispInfo)->item;
	if (!pItem)
		return;

	if (pItem->iItem < 0 || pItem->iItem >= static_cast<int>(m_IndexMapping.size()))
		return;

	int index = m_IndexMapping[pItem->iItem];
	
	if (pItem->mask & LVIF_IMAGE && !m_Columns[pItem->iSubItem])
	{
		int iIcon;
		std::map<int, int>::iterator iter=m_IconCache.find(m_IndexMapping[pItem->iItem]);
		BOOL found=iter!=m_IconCache.end();
		if (found)
			iIcon = iter->second;
		if (!pItem->iItem)
		{
			if (!found)
			{
				SHFILEINFO shFinfo;
				if (!SHGetFileInfo(_T("{5261C4A9-92B3-4667-A128-3E87564EA628}"),
					FILE_ATTRIBUTE_DIRECTORY,
					&shFinfo,
					sizeof( shFinfo ),
					SHGFI_ICON |
					((m_nStyle != LVS_ICON)?SHGFI_SMALLICON:SHGFI_LARGEICON) |SHGFI_USEFILEATTRIBUTES))
					iIcon=-1;
				else
				{
					DestroyIcon(shFinfo.hIcon);
					iIcon = shFinfo.iIcon;
					m_IconCache[index] = iIcon;
				}
			}
		}
		else
		{
			if (!found)
			{
				
				SHFILEINFO shFinfo;
				memset(&shFinfo, 0, sizeof(shFinfo));
				CString name = m_pDirectory->direntry[index].dir ? "st" : m_pDirectory->direntry[index].name;
				name.Replace(':', '_');
		
				if (!SHGetFileInfo(name,
					m_pDirectory->direntry[index].dir?FILE_ATTRIBUTE_DIRECTORY:FILE_ATTRIBUTE_NORMAL,
					&shFinfo,
					sizeof(shFinfo),
					SHGFI_ICON | //(bLink?(SHGFI_LINKOVERLAY|SHGFI_OVERLAYINDEX):0) |
					((m_nStyle != LVS_ICON)?SHGFI_SMALLICON:SHGFI_LARGEICON) | (SHGFI_USEFILEATTRIBUTES) ) )
					iIcon = -1;
				else
				{
					// we only need the index from the system image list
					DestroyIcon(shFinfo.hIcon);
					iIcon = shFinfo.iIcon;
					m_IconCache[m_IndexMapping[pItem->iItem]] = iIcon;
				}
			}
		}

		pItem->iImage = iIcon;
	}
	if (pItem->mask & LVIF_STATE && !m_Columns[pItem->iSubItem] && pItem->iItem)
	{
		BOOL bLink = m_pDirectory->direntry[index].bLink;
		if (pItem->iItem && bLink)
			pItem->state = INDEXTOOVERLAYMASK(2);
	}
	if (pItem->mask & LVIF_TEXT)
	{
		if (!pItem->iItem)
		{
			if (!pItem->iSubItem)
				lstrcpy(pItem->pszText, _T("..") );
		}
		else
		{
			if (!m_Columns[pItem->iSubItem])
			{
				lstrcpy(pItem->pszText,m_pDirectory->direntry[index].name);
			}
			
			if (m_Columns[pItem->iSubItem]==1)
			{
				if (!m_pDirectory->direntry[index].dir)
				{
					_int64 size=m_pDirectory->direntry[index].size;
					if (size>-1)
					{
						int nFormat=COptions::GetOptionVal(OPTION_REMOTEFILESIZEFORMAT);
						if (!nFormat)
							if (size<1024)
								nFormat=1;
							else if (size<(1024*1024))
								nFormat=2;
							else
								nFormat=3;
						
						CString tmp, sizestr;
						switch (nFormat)
						{
						case 1:
							sizestr.Format(_T("%I64d"), size);
							break;
						case 2:
							tmp.LoadString(IDS_SIZE_KBS);
							sizestr.Format(_T("%I64d %s"), size/1024, tmp);
							break;
						case 3:
							tmp.LoadString(IDS_SIZE_MBS);
							sizestr.Format(_T("%I64d %s"), size/1024/1024, tmp);
							break;
						default:
							ASSERT(FALSE);
						}
						lstrcpy(pItem->pszText,sizestr);
					}
					else 
						lstrcpy(pItem->pszText, _T("???") );
				}
			}
			else if (m_Columns[pItem->iSubItem] == 2)
			{
				CString type = GetType(m_pDirectory->direntry[index].lName, m_pDirectory->direntry[index].dir);
				lstrcpy(pItem->pszText, type);
			}
			else if (m_Columns[pItem->iSubItem]==3)
			{
				if (m_pDirectory->direntry[index].date.hasdate)
				{
					bool y=1;
					bool m=1;
					bool d=1;
					TCHAR date[100];
					memset(date,0,100*sizeof(TCHAR));
					for (int j=0;j<dateformat.GetLength();j++)
					{
						dateformat.MakeLower();
						if (dateformat[j]=='y')
						{
							if (y)
								_stprintf(date,_T("%s%d"),date,m_pDirectory->direntry[index].date.year);
							y=0;
						}
						else if (dateformat[j]=='m')
						{
							if (m)
								_stprintf(date,_T("%s%02d"),date,m_pDirectory->direntry[index].date.month);
							m=0;
						}
						else if (dateformat[j]=='d')
						{
							if (d)
								_stprintf(date,_T("%s%02d"),date,m_pDirectory->direntry[index].date.day);
							d=0;
						}
						else
						{
							date[_tcslen(date)+1]=0;
							date[_tcslen(date)]=dateformat[j];
						}
					}
					lstrcpy(pItem->pszText,date);
				}
				else
					lstrcpy(pItem->pszText,_T("???"));
			}
			else if (m_Columns[pItem->iSubItem] == 4)
			{
				if (m_pDirectory->direntry[index].date.hastime && m_pDirectory->direntry[index].date.hasdate)
				{
					CString str;
					str.Format(_T("%02d:%02d"), m_pDirectory->direntry[index].date.hour, m_pDirectory->direntry[index].date.minute);
					lstrcpy(pItem->pszText, str);
				}
			}
			else if (m_Columns[pItem->iSubItem] == 5)
			{
				lstrcpy(pItem->pszText, m_pDirectory->direntry[index].permissionstr);
			}
			else if (m_Columns[pItem->iSubItem] == 6)
			{
				lstrcpy(pItem->pszText, m_pDirectory->direntry[index].ownergroup);
			}
		}
	}
	
	*pResult = 0;
}

extern BOOL greater(const CString &str1, const CString &str2, BOOL isdir1, BOOL isdir2);
extern BOOL lesser(const CString &str1, const CString &str2, BOOL isdir1, BOOL isdir2);
extern BOOL lesserbysize(const __int64 &size1,const __int64 &size2, BOOL isdir1, BOOL isdir2, const CString &fn1, const CString &fn2);
extern BOOL greaterbysize(const __int64 &size1,const __int64 &size2, BOOL isdir1, BOOL isdir2, const CString &fn1, const CString &fn2);
extern BOOL lesserbytype(const CString &str1, const CString &str2, const BOOL isdir1, const BOOL isdir2, const CString &fn1, const CString &fn2);
extern BOOL greaterbytype(const CString &str1, const CString &str2, const BOOL isdir1, const BOOL isdir2, const CString &fn1, const CString &fn2);

void CFtpListCtrl::QSortByName(int begin, int end)
{
	int l=begin;
	int r=end;
	CString tmp;
	CString refname=m_pDirectory->direntry[m_IndexMapping[(l+r)/2]].lName;
	BOOL bRefIsDir=m_pDirectory->direntry[m_IndexMapping[(l+r)/2]].dir;
	do
    {
		if (m_sortdir&1)
		{
			while (lesser(m_pDirectory->direntry[m_IndexMapping[l]].lName,refname,m_pDirectory->direntry[m_IndexMapping[l]].dir,bRefIsDir) && l<end) l++;
			while (greater(m_pDirectory->direntry[m_IndexMapping[r]].lName,refname,m_pDirectory->direntry[m_IndexMapping[r]].dir,bRefIsDir) && r>begin) r--;
		}
		else
		{
			while (greater(m_pDirectory->direntry[m_IndexMapping[l]].lName,refname,m_pDirectory->direntry[m_IndexMapping[l]].dir,bRefIsDir) && l<end) l++;
			while (lesser(m_pDirectory->direntry[m_IndexMapping[r]].lName,refname,m_pDirectory->direntry[m_IndexMapping[r]].dir,bRefIsDir) && r>begin) r--;
		}
		if (l<=r)
		{
			int tmp=m_IndexMapping[l];
			m_IndexMapping[l]=m_IndexMapping[r];
			m_IndexMapping[r]=tmp;
			l++;
			r--;
		}
    } 
	while (l<=r);

  if (begin<r) QSortByName(begin,r);
  if (l<end) QSortByName(l,end);
}

void CFtpListCtrl::QSortBySize(int begin, int end)
{
	int l=begin;
	int r=end;
	CString tmp;
	CString refname=m_pDirectory->direntry[m_IndexMapping[(l+r)/2]].lName;
	BOOL bRefIsDir=m_pDirectory->direntry[m_IndexMapping[(l+r)/2]].dir;
	__int64 nRefSize=m_pDirectory->direntry[m_IndexMapping[(l+r)/2]].size;
	do
    {
		if (m_sortdir&1)
		{
			while (lesserbysize(m_pDirectory->direntry[m_IndexMapping[l]].size,nRefSize,m_pDirectory->direntry[m_IndexMapping[l]].dir,bRefIsDir,m_pDirectory->direntry[m_IndexMapping[l]].lName,refname) && l<end) l++;
			while (greaterbysize(m_pDirectory->direntry[m_IndexMapping[r]].size,nRefSize,m_pDirectory->direntry[m_IndexMapping[r]].dir,bRefIsDir,m_pDirectory->direntry[m_IndexMapping[r]].lName,refname) && r>begin) r--;
		}
		else
		{
			while (greaterbysize(m_pDirectory->direntry[m_IndexMapping[l]].size,nRefSize,m_pDirectory->direntry[m_IndexMapping[l]].dir,bRefIsDir,m_pDirectory->direntry[m_IndexMapping[l]].lName,refname) && l<end) l++;
			while (lesserbysize(m_pDirectory->direntry[m_IndexMapping[r]].size,nRefSize,m_pDirectory->direntry[m_IndexMapping[r]].dir,bRefIsDir,m_pDirectory->direntry[m_IndexMapping[r]].lName,refname) && r>begin) r--;
		}
		if (l<=r)
		{
			int tmp=m_IndexMapping[l];
			m_IndexMapping[l]=m_IndexMapping[r];
			m_IndexMapping[r]=tmp;
			l++;
			r--;
		}
    } 
	while (l<=r);

  if (begin<r) QSortBySize(begin,r);
  if (l<end) QSortBySize(l,end);
}

void CFtpListCtrl::QSortByType(const std::vector<CString> &typeArray, int begin, int end)
{
	int l = begin;
	int r = end;
	CString tmp;
	CString refname = m_pDirectory->direntry[m_IndexMapping[(l+r)/2]].lName;
	BOOL bRefIsDir = m_pDirectory->direntry[m_IndexMapping[(l+r)/2]].dir;
	CString refType = typeArray[m_IndexMapping[(l+r)/2]];
	do
    {
		if (m_sortdir&1)
		{
			while (lesserbytype(typeArray[m_IndexMapping[l]], refType,
								m_pDirectory->direntry[m_IndexMapping[l]].dir, bRefIsDir,
								m_pDirectory->direntry[m_IndexMapping[l]].lName, refname) 
				   && l<end)
				   l++;
			while (greaterbytype(typeArray[m_IndexMapping[r]], refType,
								 m_pDirectory->direntry[m_IndexMapping[r]].dir, bRefIsDir,
								 m_pDirectory->direntry[m_IndexMapping[r]].lName, refname)
				   && r>begin)
				   r--;
		}
		else
		{
			while (greaterbytype(typeArray[m_IndexMapping[l]], refType, m_pDirectory->direntry[m_IndexMapping[l]].dir,bRefIsDir,m_pDirectory->direntry[m_IndexMapping[l]].lName,refname) && l<end) l++;
			while (lesserbytype(typeArray[m_IndexMapping[r]], refType, m_pDirectory->direntry[m_IndexMapping[r]].dir,bRefIsDir,m_pDirectory->direntry[m_IndexMapping[r]].lName,refname) && r>begin) r--;
		}
		if (l<=r)
		{
			int tmp=m_IndexMapping[l];
			m_IndexMapping[l]=m_IndexMapping[r];
			m_IndexMapping[r]=tmp;
			l++;
			r--;
		}
    } 
	while (l<=r);

  if (begin<r) QSortByType(typeArray, begin,r);
  if (l<end) QSortByType(typeArray, l,end);
}

BOOL lesserbydate(const t_directory::t_direntry::t_date &date1,const t_directory::t_direntry::t_date &date2,BOOL isdir1,BOOL isdir2,CString fn1,CString fn2)
{
	if (isdir1 && !isdir2)
		return TRUE;
	if (!isdir1 && isdir2)
		return FALSE;
	if (!date1.hasdate && date2.hasdate)
		return TRUE;
	if (date1.hasdate && !date2

⌨️ 快捷键说明

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