示例#1
0
void CMetadata::AddToMeta(CString Str)
{
	CValue *pCurPos=&vMeta;

	int nPoint=Str.ReverseFind('.');
	CString csType;
	if(nPoint>0)
	{
		csType=mUpper(Str.Mid(nPoint));
		Str=Str.Left(nPoint);
	}

	CString csName;
	int nIndex1=0;
	int nIndex2=Str.Find("\\",nIndex1);
	while(nIndex2>0)
	{
		csName=Str.Mid(nIndex1,nIndex2-nIndex1);

		if(pCurPos->GetType()!=TYPE_ARRAY)
			pCurPos->CreateObject("Структура");
		pCurPos=&pCurPos->GetAt(csName);
		

		nIndex1=nIndex2+1;
		nIndex2=Str.Find("\\",nIndex1);
	}
	csName=Str.Mid(nIndex1);
	if(pCurPos->GetType()!=TYPE_ARRAY)
		pCurPos->CreateObject("Структура");

	if(csType!=".ATR")//&&csType!=".INF") 
	{
		if(pCurPos->GetAt(csName).GetType()!=TYPE_ARRAY)
			pCurPos->SetAt(csName,CValue());
	}
	else
	if(csType==".ATR") 
	{
		CMetaObject *pObj=GetMetaObject(Str,csName,1);
		if(pObj)
		{
			CValue Val;
			Val.LoadFromString(pObj->csAttr);
			Val.SetAt(String("#"),1);//признак атрибута
			pCurPos->SetAt(csName,Val);

			Val.SetAt("Идентификатор",String(csName));
			Val.SetAt("Синоним",String(pObj->csAlias));
			Val.SetAt("Комментарий",String(pObj->csComment));
		}
	}
}
示例#2
0
BOOL CMyClient::Receive(CValue &rez,CValue**ppV)
{
	int nIsTextCommand=ppV[0]->GetNumber();

	if(!nWasConnect)
		Error("Не было соединения с сервером");

    CMemFile f(BUF_SIZE);
	//получение данных с сервера
	char buff[BUF_SIZE];
	int y;
	while(y=recv(conn,buff,BUF_SIZE,0))
	{
		if(y<0)
			break;
		f.Write(buff,y);
	}
	CString Str;
	int nLength=f.GetLength();
	if(nLength>0)
	{
		f.SeekToBegin();
		f.ReadHuge(Str.GetBuffer(nLength),nLength);
		Str.ReleaseBuffer();
	}
	if(nIsTextCommand)
	{
		rez=String(Str);
	}
	else
	{
		//преобразование данных в значение (объект)
		rez.LoadFromString(Str);
	}
	return TRUE; 
};
示例#3
0
CValue CValueMetadata::Method(int iName,CValue **p)
{
	CMetadata *pMeta=0;
	if(bWasOpenZip==0 && iName!=enOpen && iName!=enClose && AfxGetModuleManager()==NULL)
	{
		Error("Конфигурация не инициализирована");
	}
	if(AfxGetModuleManager())
		pMeta=AfxGetModuleManager()->pMetadata; 


	CValue Ret;
	switch(iName)
	{
		case enOpen:
			{ 
				if(bWasOpenZip)
					Close();

				CString csFileName=p[0]->GetString();
				BOOL bReadOnly=p[1]->GetNumber();

				if(!bReadOnly)
				if(!FileExist(csFileName))
				{
					try 
					{
						m_zip.Open(csFileName, CZipArchive::create,0);//Новый архив
						m_zip.Close();	
					}
					catch(...)
					{
						Error("Ошибка при попытке создания нового файла: %s",csFileName);
						return 0;
					}

				}

				if(m_zip.FileExists(csFileName))
				{
					try 
					{
						if(bReadOnly)
							m_zip.Open(csFileName, CZipArchive::openReadOnly,0);
						else
							m_zip.Open(csFileName, CZipArchive::open,0);
					}
					catch(...)
					{
						Error("Ошибка открытия файла: %s",csFileName);
						return 0;
					}
				}
				else
					Error("Не найден файл: %s",csFileName);

				m_zip.EnableFindFast(1);
				bWasOpenZip=1;
				return 1;
			}

		case enSaveData3:
			{   
				CString csPath=GetFullMetaPath(csPathObject,p[0]->GetString());
				CString csFile=p[1]->GetString();
				int nSize=0;
				char *buf=LoadFromFileBin(csFile,nSize);
				if(buf)
				{
					if(bWasOpenZip)
					{
						return ::WriteFileFromStream(buf,nSize,csFile,m_zip,p[0]->GetString(),p[2]->GetString(),p[3]->GetString(),1);
					}
					else
					{
						return pMeta->WriteFileFromStream(buf,nSize,csFile,csPath,p[2]->GetString(),p[3]->GetString());
					}
				}
			}
		case enSaveData:
		case enSaveData2:
		case enSaveText:
			{
				CString csData;
				CString csPath=GetFullMetaPath(csPathObject,p[0]->GetString());
				if(enSaveText==iName)
				{
					csData=p[1]->GetString();
				}
				else
				{
					p[1]->SaveToString(csData);
				}
				if(bWasOpenZip)
				{
					return ::WriteFileFromString(csData,m_zip,p[0]->GetString(),p[2]->GetString(),p[3]->GetString(),1);
				}
				else
				{
					return pMeta->WriteFileFromString(csData,csPath,p[2]->GetString(),p[3]->GetString());
				}
			}
		case enLoadData3:
			{
				CString csAlias,csComment;
				CString csPath=GetFullMetaPath(csPathObject,p[0]->GetString());
				CString csFile=p[1]->GetString();
				
				if(bWasOpenZip)
				{
					if(!csPath.IsEmpty())
					{
						int nRes=m_zip.FindFile(csPath);
						if(nRes>=0)
						{
							bool bRes=m_zip.OpenFile(nRes);
							CZipFileHeader fhInfo;
							m_zip.GetFileInfo(fhInfo, nRes);
							CString csDescription=fhInfo.GetComment();
							int nIndex=csDescription.Find("\n");
							csAlias=csDescription.Left(nIndex);
							csComment=csDescription.Mid(nIndex+1);
							int nSize=fhInfo.m_uUncomprSize;
							char* pBuffer=new char [nSize+1];
							pBuffer[nSize]=0;
							DWORD nRez=m_zip.ReadFile(pBuffer,nSize);
							if(FILE *sFile=fopen(csFile,"w+b"))
							{
						
								fwrite(pBuffer,sizeof(char),nSize, sFile);
								fclose(sFile);
							}
							delete []pBuffer;
							m_zip.CloseFile();
						}
					}
				}
				Ret=1;
				p[2]->SetString(csAlias);
				p[3]->SetString(csComment);

				break;
			}
		case enLoadData:
		case enLoadData2:
		case enLoadText:
			{
				CString csAlias,csComment;
				CString csPath=GetFullMetaPath(csPathObject,p[0]->GetString());
				CString csData;
				if(bWasOpenZip)
				{
					csData=::ReadFileToString(m_zip,p[0]->GetString(),csAlias,csComment);
				}
				else
				{
					csData=pMeta->ReadFileToString(csPath,csAlias,csComment);
				}
				if(enLoadText==iName)
				{
					Ret=String(csData);
				}
				else
				{
					Ret.LoadFromString(csData);
				}
				*p[1]=Ret;
				p[2]->SetString(csAlias);
				p[3]->SetString(csComment);

				break;
			}
		case enDeleteData:
			{
				CString csPath=METADATANAME+"\\"+csPathObject+p[0]->GetString();
				if(bWasOpenZip)
				{
					if(m_zip.FindFile(p[0]->GetString()))
						return ::DeleteFile(m_zip,p[0]->GetString());
					else
						return ::DeleteFolder(m_zip,p[0]->GetString());
				}
				else
				{
					return pMeta->DeleteData(csPath);
				}
			}
		case enClose:
			{
				Close();
				break;
			}
		case enGetCountEntries:
			{
				if(!bWasOpenZip)
					Error("Внешний файл метаданных не открыт");

				return m_zip.GetNoEntries();
			}
		case enGetName:
			{
				if(!bWasOpenZip)
					Error("Внешний файл метаданных не открыт");

				int n=p[0]->GetNumber();
				if(n<1 || n>m_zip.GetNoEntries())
					Error("Значение индекса выходит за границу допустимых значений");

				CZipFileHeader fhInfo;
				m_zip.GetFileInfo(fhInfo, n-1);
				return String(fhInfo.GetFileName());
			}

	}
	return Ret;
}