Beispiel #1
0
void ExportFilesToDB::dfsFolder(std::string folderPath)
{ 
	_finddata_t FileInfo;
	std::string strfind = folderPath + "\\*";
	long Handle = _findfirst(strfind.c_str(), &FileInfo); 
	if (Handle == -1L)
	{ 
		printf("find Folder Error! \n");
		return ;
	}
	do
	{
		if (FileInfo.attrib & _A_SUBDIR)    
		{
			if( (strcmp(FileInfo.name,".") != 0 ) &&(strcmp(FileInfo.name,"..") != 0))   
			{
				std::string newPath = folderPath + "\\" + FileInfo.name;
				dfsFolder(newPath);
			}
		}
		else  
		{ 
			std::string fileName = FileInfo.name;
			if (std::string::npos != fileName.find(".txt"))
			{ 
				m_vdataFileList.push_back(FileInfo.name);
				printf("Loading File: %s \n",FileInfo.name);
			} 
		}
	}while (_findnext(Handle, &FileInfo) == 0); 
	_findclose(Handle); 
}
void FileView::onFileComboBoxChange(CCObject* pSender, int tag, const char* text)
{
	ComboBox* pComboBox = (ComboBox*)pSender;

	if (pComboBox->getTag() == 1111)	//文件菜单
	{
		if(tag == 0)		//新建
		{
			string strFilePath = OpenDir(L"请选择文件保存目录");
			if(!strFilePath.empty())
			{
				if (m_pDelegate != NULL)
				{
					m_pDelegate->onFileViewNewFileMessage(A2U(strFilePath.c_str()));
				}
			}
		}
		else if (tag == 1)	//文件
		{
			string strFilePath = OpenFile();
			if (!strFilePath.empty())
			{
				//遍历目录下所有xml文件
				vector<string> dfsFileNames = dfsFolder(FKCW_Base_Utils::DeleteLastPathOfComponment(strFilePath));
				//清空ComboBox
				m_pFileSelectComboBox->clear();
				//向ComboBox添加目录下所有文件
				for (unsigned int i=0; i<dfsFileNames.size(); i++)
				{
					m_pFileSelectComboBox->addString(A2U(dfsFileNames.at(i).c_str()).c_str());
				}
				m_pFileSelectComboBox->setText(A2U(strFilePath.c_str()).c_str());

				if (m_pDelegate != NULL)
				{
					m_pDelegate->onFileViewOpenFileMessage(A2U(strFilePath.c_str()));
				}
			}
		}
		else if(tag == 2)	//文件夹
		{
			string strFilePath = OpenDir(L"请选择配置文件文件夹");
			if (!strFilePath.empty())
			{
				//遍历目录下所有xml文件
				vector<string> dfsFileNames = dfsFolder(strFilePath);
				//清空ComboBox
				m_pFileSelectComboBox->clear();
				//向ComboBox添加目录下所有文件
				for (unsigned int i=0; i<dfsFileNames.size(); i++)
				{
					m_pFileSelectComboBox->addString(A2U(dfsFileNames.at(i).c_str()).c_str());
				}
				m_pFileSelectComboBox->setText(A2U("请点击该处选择配置文件").c_str());
			}
		}
	}

	else if(pComboBox->getTag() == 2222)	//文件选择框
	{
		if (m_pDelegate != NULL)
		{
			string strFilePath = m_pFileSelectComboBox->getText();
			m_pDelegate->onFileViewOpenFileMessage(strFilePath);
		}
	}
}