Beispiel #1
0
bool CMountProg::ReadPathsFromFile(char* sFileName)
{
	sFileName = FormatPath(sFileName, FORMAT_PATH);
	std::ifstream pathFile(sFileName);

	if (pathFile.is_open()) {
		std::string line;

		while (std::getline(pathFile, line)) {
			char *pCurPath = (char*)malloc(line.size() + 1);
			pCurPath = (char*)line.c_str();

			if (pCurPath != NULL) {
				char curPathAlias[MAXPATHLEN];
				strcpy_s(curPathAlias, pCurPath);
				char *pCurPathAlias = (char*)malloc(strlen(curPathAlias));
				pCurPathAlias = curPathAlias;

				Export(pCurPath, pCurPathAlias);
			}
		}
	} else {
		printf("Can't open file %s.\n", sFileName);
		return false;
	}

	return true;
}
void ProjectPanel::recursiveAddFilesFrom(const TCHAR *folderPath, HTREEITEM hTreeItem)
{
    bool isRecursive = true;
    bool isInHiddenDir = false;
    generic_string dirFilter(folderPath);
    if (folderPath[lstrlen(folderPath)-1] != '\\')
        dirFilter += TEXT("\\");

    dirFilter += TEXT("*.*");
    WIN32_FIND_DATA foundData;
    std::vector<generic_string> files;

    HANDLE hFile = ::FindFirstFile(dirFilter.c_str(), &foundData);

    do {
        if (hFile == INVALID_HANDLE_VALUE)
            break;

        if (foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        {
            if (!isInHiddenDir && (foundData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
            {
                // do nothing
            }
            else if (isRecursive)
            {
                if ((lstrcmp(foundData.cFileName, TEXT("."))) && (lstrcmp(foundData.cFileName, TEXT(".."))))
                {
                    generic_string pathDir(folderPath);
                    if (folderPath[lstrlen(folderPath)-1] != '\\')
                        pathDir += TEXT("\\");
                    pathDir += foundData.cFileName;
                    pathDir += TEXT("\\");
                    HTREEITEM addedItem = addFolder(hTreeItem, foundData.cFileName);
                    recursiveAddFilesFrom(pathDir.c_str(), addedItem);
                }
            }
        }
        else
        {
            files.push_back(foundData.cFileName);
        }
    } while (::FindNextFile(hFile, &foundData));

    for (size_t i = 0, len = files.size() ; i < len ; ++i)
    {
        generic_string pathFile(folderPath);
        if (folderPath[lstrlen(folderPath)-1] != '\\')
            pathFile += TEXT("\\");
        pathFile += files[i];
        _treeView.addItem(files[i].c_str(), hTreeItem, INDEX_LEAF, pathFile.c_str());
    }

    ::FindClose(hFile);
}
Beispiel #3
0
bool CMountProg::SetPathFile(char *file)
{
	std::ifstream pathFile(file);

	if (pathFile.good()) {
		pathFile.close();
		m_pPathFile = file;
		return true;
	}

	pathFile.close();
	return false;
}
// sendOfflineEvent
bool sendOfflineEvent(cgcResponse::pointer response, COfflineEvent::pointer offlineEvent)
{
	BOOST_ASSERT (response.get() != 0);
	BOOST_ASSERT (offlineEvent.get() != 0);

	if (response->isInvalidate()) return false;

	switch (offlineEvent->getEvent())
	{
	case 501:
		{
			CMessageInfo::pointer messageInfo = offlineEvent->getMessage();
			BOOST_ASSERT (messageInfo.get() != 0);

			long messageid = messageInfo->messageid();
			short msgtype = messageInfo->type();
			bool newflag = messageInfo->newflag();
			size_t sizeSended = 0;
			size_t tosendSize = 0;

			switch (msgtype)
			{
			case 1:
				{
					size_t toSendSizeTotal = messageInfo->total();
					cgc::cgcAttachment::pointer attach(cgcAttachment::create());
					attach->setName("text");
					attach->setTotal(toSendSizeTotal);
					while (sizeSended < toSendSizeTotal)
					{
						tosendSize = (short)(toSendSizeTotal-sizeSended) > MAX_PACKET_SIZE ? MAX_PACKET_SIZE : (toSendSizeTotal-sizeSended);
						attach->setAttach((const unsigned char*)messageInfo->getdata()+sizeSended, tosendSize);
						attach->setIndex(sizeSended);

						if (attach->getIndex() == 0)
						{
							if (!sendMsg(response, offlineEvent->getFromAccount(), offlineEvent->fromInfo(), messageid, msgtype, attach, newflag, offlineEvent->getMessage()->msgtime()))
							{
								return false;
							}
						}else
						{
							if (!sendMsg(response, offlineEvent->getFromAccount(), offlineEvent->fromInfo(), messageid, attach))
							{
								return false;
							}
						}
						sizeSended += tosendSize;

#ifdef WIN32
						Sleep(5);
#else
						usleep(5000);
#endif
					}
				}break;
			case 3:
				{
					std::string filename = messageInfo->tostring();
					size_t nFilesize = messageInfo->filesize();
					char filepath[256];
					sprintf(filepath, "%s/File/%s", gApplication->getAppConfPath().c_str(), filename.c_str());
					FILE * hfile = fopen(filepath, "rb");
					if (hfile == NULL)
					{
						return false;
					}
					unsigned char * imageBuffer = new unsigned char[nFilesize+1];
					size_t imageSize = fread(imageBuffer, 1, nFilesize, hfile);
					fclose(hfile);
					namespace fs = boost::filesystem;
					fs::path pathFile(filepath, fs::native);
					fs::remove(pathFile);

					if (imageSize == 0)
					{
						delete[] imageBuffer;
						return false;
					}

					cgc::cgcAttachment::pointer attach(cgcAttachment::create());
					attach->setName("image");
					attach->setTotal(imageSize);
					while (sizeSended < imageSize)
					{
						tosendSize = (short)(imageSize-sizeSended) > MAX_PACKET_SIZE ? MAX_PACKET_SIZE : (imageSize-sizeSended);
						attach->setAttach((const unsigned char*)imageBuffer+sizeSended, tosendSize);
						attach->setIndex(sizeSended);

						if (attach->getIndex() == 0)
						{
							long nWidth = messageInfo->imageWidth();
							long nHeight = messageInfo->imageHeight();
							if (!sendMsgImage(response, offlineEvent->getFromAccount(), offlineEvent->fromInfo(), messageid, nWidth, nHeight, msgtype, attach, newflag, offlineEvent->getMessage()->msgtime()))
							{
								delete[] imageBuffer;
								return false;
							}
						}else
						{
							if (!sendMsg(response, offlineEvent->getFromAccount(), offlineEvent->fromInfo(), messageid, attach))
							{
								delete[] imageBuffer;
								return false;
							}
						}
						sizeSended += tosendSize;

#ifdef WIN32
						Sleep(5);
#else
						usleep(5000);
#endif
					}
					delete[] imageBuffer;
				}break;
			default:
				break;
			}

		}break;
	default:
		{
			if (offlineEvent->fromInfo()->fromType() == CFromInfo::FromDialogInfo)
			{
				response->setParameter(cgcParameter::create(_T("DID"), offlineEvent->fromInfo()->fromDialog()->dialogId()));
			}
			response->setParameter(cgcParameter::create(_T("FromAccount"), offlineEvent->getFromAccount()->getAccount()));
			response->sendResponse(0, offlineEvent->getEvent());
		}break;
	}
	return true;
}