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

📄 ftptranserdoc.cpp

📁 大家好,好久没做什么东西了,前些日子偶然看到本论坛的一个FTP多线程断点续传的源代码
💻 CPP
字号:
// FTPTranserDoc.cpp :  CFTPTranserDoc 类的实现
//

#include "stdafx.h"
#include "FTPTranser.h"

#include "FTPTranserDoc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CFTPTranserDoc

IMPLEMENT_DYNCREATE(CFTPTranserDoc, CDocument)

BEGIN_MESSAGE_MAP(CFTPTranserDoc, CDocument)
END_MESSAGE_MAP()

FileInfo::FileInfo(CString str)
{	
	//是否是文件夹
	isDir = (*str.GetBuffer() == 'd');

	//属性
	int index = str.Find(' ');
	mPro = str.Left(index);
	str = str.Right(str.GetLength()-index).Trim();
	
	//去掉user数
	index = str.Find(' ');
	str = str.Right(str.GetLength()-index).Trim();

	//去掉user
	index = str.Find(' ');
	str = str.Right(str.GetLength()-index).Trim();

	//去掉group
	index = str.Find(' ');
	str = str.Right(str.GetLength()-index).Trim();

	//大小
	index = str.Find(' ');
	mSize = atoi(str.Left(index).GetBuffer());
	str = str.Right(str.GetLength()-index).Trim();

	//日期
	index = str.Find(' ');
	mDate = str.Left(index + 1);
	str = str.Right(str.GetLength()-index).Trim();
	index = str.Find(' ');
	mDate = mDate + str.Left(index + 1);
	str = str.Right(str.GetLength()-index).Trim();
	index = str.Find(' ');
	mDate = mDate + str.Left(index + 1);
	
	//文件名
	mName = str.Right(str.GetLength()-index).Trim();
	if(!isDir)
	{
		str = str.Right(str.GetLength()-index).Trim();
		index = str.Find('.');
		while(index != -1)
		{
			str = str.Right(str.GetLength() - index - 1).Trim();
			index = str.Find('.');
		}
		mType = str;
	}
}


// CFTPTranserDoc 构造/析构

CFTPTranserDoc::CFTPTranserDoc()
{
	// TODO: 在此添加一次性构造代码
	count = 0;
	current = 0;
	last = 0;
	imageList.Create(24, 24, ILC_COLOR24, 0, 64);
	imageList.SetBkColor(RGB(255,255,255));
	GetImageIndex("",true);
}

CFTPTranserDoc::~CFTPTranserDoc()
{
	imageList.DeleteImageList();
}

BOOL CFTPTranserDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	//myList.AddTail(CString("The First str"));
	//myList.AddTail(CString("The Second Str"));

	return TRUE;
}




// CFTPTranserDoc 序列化

void CFTPTranserDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: 在此添加存储代码
	}
	else
	{
		// TODO: 在此添加加载代码
	}
}


// CFTPTranserDoc 诊断

#ifdef _DEBUG
void CFTPTranserDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CFTPTranserDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

void CFTPTranserDoc::AddFileInfo(CString str)
{
	FileInfo info(str);
	fileList.AddTail(info);


}

FileInfo & CFTPTranserDoc::GetFileInfo(CString name)
{
	int lennum = (int)fileList.GetSize();
	
	POSITION pos = fileList.GetHeadPosition();	
	for(int i = 0; i<lennum ; i++)
	{
		FileInfo& str = fileList.GetAt(pos);		
		if(name.CompareNoCase(str.mName) == 0)
		{
			return str;
		}
		fileList.GetNext(pos);
	}
	return FileInfo("");
}

int CFTPTranserDoc::GetImageIndex(CString type,bool isDir )
{
	SHFILEINFO shfi;
	if(isDir)
	{
		if(imageList.GetImageCount() <= 0)
		{	
			//目录
			memset(&shfi,0,sizeof(shfi));
			SHGetFileInfo("C:\\windows", 
			FILE_ATTRIBUTE_DIRECTORY,
			&shfi, sizeof(shfi),
			SHGFI_ICON|SHGFI_USEFILEATTRIBUTES);
			if(shfi.hIcon)
				imageList.Add(shfi.hIcon);
			//未知文件
			memset(&shfi,0,sizeof(shfi));
			SHGetFileInfo("foo", 
			FILE_ATTRIBUTE_SPARSE_FILE,
			&shfi, sizeof(shfi),
			SHGFI_ICON|SHGFI_USEFILEATTRIBUTES);
			if(shfi.hIcon)
				imageList.Add(shfi.hIcon);
		}
		return 0;
	}
	if(type.GetLength() <= 0) 
		return 1;

	int lennum = (int)typeList.GetSize();
	if(lennum >= 64) 
		return 1;
	POSITION pos = typeList.GetHeadPosition();	
	for(int i = 0; i<lennum ; i++)
	{
		CString& str = typeList.GetAt(pos);		
		if(str.CompareNoCase(type) == 0)
		{
			return i+2;
		}
		typeList.GetNext(pos);
	}

	//文件
	memset(&shfi,0,sizeof(shfi));
	SHGetFileInfo("foo."+type, 
	FILE_ATTRIBUTE_NORMAL,
	&shfi, sizeof(shfi),
	SHGFI_ICON|SHGFI_USEFILEATTRIBUTES);
	if(shfi.hIcon)
	{
		imageList.Add(shfi.hIcon);
		typeList.AddTail(type);
	}
	else
		return 1;
	return imageList.GetImageCount() - 1;
}


// CFTPTranserDoc 命令

⌨️ 快捷键说明

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