Example #1
0
PRGINTERFACE_API void  PrepareArrayForReport(CMapStringToString &mstr)
{
	const static char * Panhao[] ={
	_T("0.001Ω"),_T("0.01Ω"),_T("0.1Ω"),_T("1Ω"),_T("10Ω"),_T("100Ω"),_T("1000Ω"),_T("10000Ω")};

	//check the start position of the resister group
	int grpoffset=0;
	CString skey,sval;
	do{
		skey.Format("Z%d",31+grpoffset++*20);
		if(mstr.Lookup(skey,sval) && sval.FindOneOf("0123456789") >= 0)
			break;
	}while(grpoffset<9);
	
	--grpoffset;
	
				
	for (int grpindex = 0;grpindex < 8;grpindex++){
		skey.Format("Z%d",31+grpindex*20);
		if (mstr.Lookup(skey,sval) && (sval.FindOneOf("0123456789") >= 0) )
		{
			if(sval.FindOneOf("0123456789") != -1)
			{
				skey.Format("Z%d",31+grpindex*20+12);
				mstr.SetAt(skey,CString(Panhao[grpindex]));
				skey.Format("jhsel%d",grpindex);
				if(mstr.Lookup(skey,sval) && (sval.FindOneOf("0123456789") >= 0))
				{
					sval = _T("±")+sval;
					skey.Format("Z%d",31+grpindex*20+13);
					mstr.SetAt(skey,sval);
				}
			}
		}
	}
	return;
	//move the table and insert "/" at corresponding place
	for ( grpindex = 0;grpindex < 8;grpindex++)
		for (int subindex = 0;subindex< 14;subindex++){
			skey.Format("Z%d",31+grpindex*20+subindex);
			if (!mstr.Lookup(skey,sval) || sval.FindOneOf("0123456789") < 0)
				mstr.SetAt(skey,_T("/"));
			else	if(sval.FindOneOf("0123456789") == -1)
				mstr.SetAt(skey,_T("/"));
			else {
				mstr.RemoveKey(skey);
				skey.Format("Z%d",31+(grpindex-grpoffset)*20+subindex);
				mstr.SetAt(skey,sval);
			}
			
		}
}
Example #2
0
void CNbzHandler::DataIntegrateForCheck(CMapStringToString& mstr,int indexmax,bool colormark)
{
    mstr.SetAt("0.005","0");
    mstr.SetAt("0.01","1");
    mstr.SetAt("0.02","2");
    mstr.SetAt("0.05","3");
    mstr.SetAt("0.1","4");
    mstr.SetAt("0.2","5");
    mstr.SetAt("0.5","6");
    mstr.SetAt("1","7");
    mstr.SetAt("2","8");
    mstr.SetAt("5","9");
    static int g_Digipos[] = {-7,-6,-6,-6,-5,-5,-5,-4,-4,-4,-3};
    static int g_Mantissa[]= { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
    CString perrecord;
    CString jherr("");
    int ipos = indexmax;

    while(ipos-- > 0)
    {
        CString sid;
        double accuracy;
        sid.Format("Z%d",ipos);
        if(mstr.Lookup(sid,perrecord))
        {
            if(perrecord.Find("--") >= 0)
                continue;
            sid.Format("jhsel%d",INDEX2GROUP(ipos));
            if(!mstr.Lookup(sid,sid))		continue;//retrieve the jhsel

            accuracy = atof(sid)/100.0;

            if(!mstr.Lookup(sid,sid))		continue;//translate the jhsel
            perrecord = DataIntergrate(ipos,atof(perrecord),g_Digipos[atoi(sid)]-2,g_Mantissa[atoi(sid)]);
            if((!CheckData(ipos,atof(perrecord),accuracy)))
            {
                //add the a message to the error
                CString stmp;
                stmp.Format("%s盘第%d点不合格;\n",Panhao[INDEX2GROUP(ipos)],INDEX2REST(ipos));
                jherr += stmp;
                if(colormark)
                    perrecord = "<font color='red'>"+perrecord+"</font>";
            }
            sid.Format("Z%d",ipos);
            mstr.SetAt(sid,perrecord);
        }
    }
    mstr.SetAt("jdjg",jherr);//检定结果
}
Example #3
0
void CDz3Handler::PrepareArrayForReport(CMapStringToString& mstr)
{
	//check the start position of the resister group
	int grpoffset=0;
	CString skey,sval;
	do{
		skey.Format("Z%d",31+grpoffset++*20);
		if(mstr.Lookup(skey,sval))
			break;
	}while(grpoffset<9);
	
	--grpoffset;
	
				
		for (int grpindex = 0;grpindex < 8;grpindex++){
			skey.Format("Z%d",31+grpindex*20);
			if (mstr.Lookup(skey,sval))
			{
				if(sval.FindOneOf("0123456789") != -1)
				{
					skey.Format("Z%d",31+grpindex*20+12);
					mstr.SetAt(skey,CString(Panhao[grpindex]));
					skey.Format("jhsel%d",grpindex);
					if(mstr.Lookup(skey,sval))
					{
						sval = _T("±")+sval;
						skey.Format("Z%d",31+grpindex*20+13);
						mstr.SetAt(skey,sval);
					}
				}
			}
		}
		
		//move the table and insert "/" at corresponding place
		for ( grpindex = 0;grpindex < 8;grpindex++)
			for (int subindex = 0;subindex< 14;subindex++){
				skey.Format("Z%d",31+grpindex*20+subindex);
				if (!mstr.Lookup(skey,sval))
					mstr.SetAt(skey,_T("/"));
				else	if(sval.FindOneOf("0123456789") == -1)
							mstr.SetAt(skey,_T("/"));
						else {
							mstr.RemoveKey(skey);
							skey.Format("Z%d",31+(grpindex-grpoffset)*20+subindex);
							mstr.SetAt(skey,sval);
						}
				
			}
}
BOOL CFileWindow::OpenProjectWorkspace(LPCTSTR lpszPathName)
{
	if( ! RemoveAllProjectItems() ) return FALSE;
	ifstream fin(lpszPathName, ios::in | ios::nocreate);

	CMapStringToString mapAttr; TCHAR szText[4096]; 
	fin >> szText; // get first tocken

	// load project
	if( ! _stricmp(szText, "<project") ) {
		fin.getline(szText, 4096, '>'); // get attributes
		if( ! ParseProjectItemAttr( szText, mapAttr ) ) return FALSE;

		CString szVersion; BOOL bLookup = mapAttr.Lookup("version", szVersion);
		if( ! bLookup ) { AfxMessageBox(IDS_ERR_WRONG_PRJ_FILE); return FALSE; }

		HTREEITEM hItem = InsertProjectItem(TVI_ROOT, GetFileName(lpszPathName), PROJECT_ITEM_PROJECT, 0, lpszPathName, 0);
		fin >> szText; // get next tocken

		while( _stricmp(szText, "</project>") ) {
			if( ! LoadProjectItem(fin, szText, hItem) ) return FALSE;
		}
		fin >> szText; // get next tocken

		// expand and select root item
		if( ! m_treProjectTree.Expand( hItem, TVE_EXPAND ) ) ; // there could be only one root item;
		if( ! m_treProjectTree.SelectItem( hItem ) ) return FALSE;

	} else { AfxMessageBox(IDS_ERR_WRONG_PRJ_FILE); return FALSE; }
Example #5
0
BOOL CConfigLoader::GetValue( CString szSection, CString szKey, CString &szValue )
{
	CMapStringToString *lpKeyMap = NULL;
	if( m_SectionMap.Lookup( szSection, lpKeyMap ) )
		return lpKeyMap->Lookup( szKey,szValue );
	return FALSE;
}
Example #6
0
PRGINTERFACE_API void  DataIntegrateForCheck(CMapStringToString &mstr, int indexmax, bool colormark)
{
	CString perrecord;
	CString jherr("");
	int ipos = indexmax;

	zero = 0.0;
	if(mstr.Lookup(_T("Z19"),perrecord) && (perrecord.FindOneOf("0123456789") >= 0)){
		zero = atof(perrecord);
	}
	z14 = 0;
	if(mstr.Lookup(_T("Z14"),perrecord) && (perrecord.FindOneOf("0123456789") >= 0)){
		z14 = atoi(perrecord);
	}
	while(ipos-- > 0)
	{
		CString sid;
		double accuracy;
		sid.Format("Z%d",ipos);
		if(mstr.Lookup(sid,perrecord) && (perrecord.FindOneOf("0123456789") >= 0))
		{
			if(perrecord.Find("--") >= 0)
				continue;
			sid.Format("jhsel%d",INDEX2GROUP(ipos));
			if(!mstr.Lookup(sid,sid) || (sid.FindOneOf("0123456789") < 0) )		continue;//retrieve the jhsel
						
			accuracy = atof(sid)/100.0;
			
			int iid = CheckPrecious(sid);
			if(iid < 0)		continue;//translate the jhsel//translate the jhsel
			perrecord = DataIntergrate(ipos,atof(perrecord),g_PrecBase[iid].iDigipos-2,g_PrecBase[iid].iMantissa);
			if((!CheckData(ipos,atof(perrecord),accuracy)))
			{
				//add the a message to the error
				CString stmp;
				stmp.Format("%s盘第%d点不合格;\n",Panhao[INDEX2GROUP(ipos)],INDEX2REST(ipos));
				jherr += stmp;
				if(colormark)
					perrecord = "<font color='red'>"+perrecord+"</font>";
			}
			sid.Format("Z%d",ipos);
			mstr.SetAt(sid,perrecord);
		}

	}
	mstr.SetAt("jdjg",jherr);//检定结果
}
Example #7
0
void CNbzHandler::DataIntegrateForCompensate(CMapStringToString& mstr,int indexmax)
{
    mstr.SetAt("0.005","0");
    mstr.SetAt("0.01","1");
    mstr.SetAt("0.02","2");
    mstr.SetAt("0.05","3");
    mstr.SetAt("0.1","4");
    mstr.SetAt("0.2","5");
    mstr.SetAt("0.5","6");
    mstr.SetAt("1","7");
    mstr.SetAt("2","8");
    mstr.SetAt("5","9");
    mstr.SetAt("5","10");
    static int g_Digipos[] = {-7,-6,-6,-6,-5,-5,-5,-4,-4,-4,-3};
    static int g_Mantissa[]= { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
    CString perrecord;
    int ipos = indexmax;

    while(ipos-- > 0)
    {
        CString sid;
        double accuracy;
        sid.Format("Z%d",ipos);
        if(mstr.Lookup(sid,perrecord))
        {
            if(perrecord.Find("--") >= 0)
                continue;
            sid.Format("jhsel%d",INDEX2GROUP(ipos));
            if(!mstr.Lookup(sid,sid))		continue;//retrieve the jhsel

            accuracy = atof(sid)/100.0;

            if(!mstr.Lookup(sid,sid))		continue;//translate the jhsel
            perrecord = DataIntergrate(ipos,atof(perrecord),g_Digipos[atoi(sid)]-2,g_Mantissa[atoi(sid)]);
            sid=SJD2SByPosition(GetDiffData(ipos,atof(perrecord),accuracy),INDEX2GROUP(ipos)+g_Digipos[atoi(sid)]-3);
            if(!CheckData(ipos,atof(perrecord),accuracy))
            {
                sid = "<font color='red'>"+sid+"</font>";
            }
            perrecord = sid;
            sid.Format("Z%d",ipos);
            mstr.SetAt(sid,perrecord);
        }
    }
}
Example #8
0
bool DetectItems(CMapStringToString &mstr,int i,int j,int k,double &di,double &dj, double &dk)
{
	CString skey,sval;
	skey.Format("Z%d",i);
	if (!mstr.Lookup(skey,sval) || sval.FindOneOf("0123456789") < 0)
		return false;
	di = atof(sval);

	skey.Format("Z%d",j);
	if (!mstr.Lookup(skey,sval) || sval.FindOneOf("0123456789") < 0)
		return false;
	dj = atof(sval);

	skey.Format("Z%d",k);
	if (!mstr.Lookup(skey,sval) || sval.FindOneOf("0123456789") < 0)
		return false;
	dk = atof(sval);
	return true;
}
Example #9
0
CString MR_PreProcLine(const char *pLine)
{
	// scan the line and seardh for predefined keyword
	CString lReturnValue;

	if(pLine != NULL) {
		const char *lPtr = pLine;
		BOOL lEnd = FALSE;
		const char *lTokenStart = NULL;

		while(!lEnd) {
			switch (*lPtr) {
				case 0:
					lEnd = TRUE;
				case ' ':
				case ',':
				case '\n':
				case '\r':
				case '\t':

					if(lTokenStart) {
						CString lValue;

						CString lKey(lTokenStart, lPtr - lTokenStart);

						lTokenStart = NULL;

						if(gDefineMap.Lookup(lKey, lValue)) {
							lReturnValue += lValue;
						}
						else {
							lReturnValue += lKey;
						}

					}

					if(!lEnd) {
						lReturnValue += *lPtr;
					}

					break;

				default:
					if(!lTokenStart) {
						lTokenStart = lPtr;
					}
					break;
			}

			lPtr++;
		}
	}
	return lReturnValue;
}
Example #10
0
CString CDownloadManager::GetDownloadDirectory(const CMapStringToString& mapSharedPaths)
{
	CString csDirectory;
	if (!mapSharedPaths.Lookup("online", csDirectory))
	{
		CString csProgramFilesDir;
		Util::GetProgramFilesDir(csProgramFilesDir);
		Util::ConstructPath(csDirectory, csProgramFilesDir, "Mindscape\\Online");
	}
	return csDirectory;
}
Example #11
0
PRGINTERFACE_API void DataIntegrateForCompensate(CMapStringToString &mstr,int indexmax)
{
	CString perrecord;
	int ipos = indexmax;
	zero = 0.0;
	if(mstr.Lookup(_T("Z19"),perrecord) && (perrecord.FindOneOf("0123456789") >= 0)){
		zero = atof(perrecord);
	}
	z14 = 0;
	if(mstr.Lookup(_T("Z14"),perrecord) && (perrecord.FindOneOf("0123456789") >= 0)){
		z14 = atoi(perrecord);
	}
	
	while(ipos-- > 0)
	{
		CString sid;
		double accuracy;
		sid.Format("Z%d",ipos);
		if(mstr.Lookup(sid,perrecord) && (perrecord.FindOneOf("0123456789") >= 0))
		{
			if(perrecord.Find("--") >= 0)
				continue;
			sid.Format("jhsel%d",INDEX2GROUP(ipos));
			if(!mstr.Lookup(sid,sid) || sid.FindOneOf("0123456789") < 0)		continue;//retrieve the jhsel
			
			accuracy = atof(sid)/100.0;
			
			int iid = CheckPrecious(sid);
			if(iid < 0)		continue;//translate the jhsel
			perrecord = DataIntergrate(ipos,atof(perrecord),g_PrecBase[iid].iDigipos-2,g_PrecBase[iid].iMantissa);
			sid=SJD2SByPosition(GetDiffData(ipos,atof(perrecord),accuracy),INDEX2GROUP(ipos)+g_PrecBase[iid].iDigipos-3);
			if(!CheckData(ipos,atof(perrecord),accuracy))
			{
				sid = "<font color='red'>"+sid+"</font>";
			}
			perrecord = sid;
			sid.Format("Z%d",ipos);
			mstr.SetAt(sid,perrecord);
		}
	}
}
Example #12
0
void CDownloadManager::AddDownloadDirectory(CMapStringToString& mapSharedPaths, LPCSTR pszDirectory)
{
	// See if this directory exists in the current shared paths.
	BOOL fExists = FALSE;
	POSITION pos = mapSharedPaths.GetStartPosition();
	while (pos != NULL)
	{
		// Get the next pair.
		CString csKey, csValue;
		mapSharedPaths.GetNextAssoc(pos, csKey, csValue);

		// See if this is the directory we just used.
		if (csValue.CompareNoCase(pszDirectory) == 0)
		{
			// The path exists!
			fExists = TRUE;
			break;
		}
	}

	// If we did not find it, add it now.
	if (!fExists)
	{
		for (int n = 0; n < 4096; n++)
		{
			CString csKey;
			if (n == 0)
			{
				csKey = "Online";
			}
			else
			{
				csKey.Format("Online%d", n);
			}
			CString csValue;
			if (!mapSharedPaths.Lookup(csKey, csValue))
			{
				// We have found a slot to use.
				AddSharedPath(csKey, pszDirectory);

				// Add it to our map, too.
				csKey.MakeLower();
				mapSharedPaths.SetAt(csKey, pszDirectory);
				break;
			}
		}
	}
}
Example #13
0
//
// =======================================================================================================================
//    Map_ImportFile Timo 09/01/99:: called by CXYWnd::Paste & Map_ImportFile if Map_ImportFile ( prefab ), the buffer
//    may contain brushes in old format ( conversion needed )
// =======================================================================================================================
//
void Map_ImportBuffer(char *buf, bool renameEntities) {
	entity_t	*ent;
	brush_t		*b = NULL;
	CPtrArray	ptrs;

	Select_Deselect();

	Undo_Start("import buffer");

	g_qeglobals.d_parsed_brushes = 0;
	if (buf) {
		CMapStringToString	mapStr;
		StartTokenParsing(buf);
		g_qeglobals.d_num_entities = 0;

		//
		// Timo will be used in Entity_Parse to detect if a conversion between brush
		// formats is needed
		//
		g_qeglobals.bNeedConvert = false;
		g_qeglobals.bOldBrushes = false;
		g_qeglobals.bPrimitBrushes = false;
		g_qeglobals.mapVersion = 1.0;

		if (GetToken(true)) {
			if (stricmp(token, "Version") == 0) {
				GetToken(false);
				g_qeglobals.mapVersion = atof(token);
				common->Printf("Map version: %1.2f\n", g_qeglobals.mapVersion);
			} else {
				UngetToken();
			}
		}

		idDict RemappedNames;	// since I can't use "map <string, string>"... sigh. So much for STL...

		while (1) {
			//
			// use the selected brushes list as it's handy ent = Entity_Parse (false,
			// &selected_brushes);
			//
			ent = Entity_Parse(false, &active_brushes);
			if (!ent) {
				break;
			}

			// end entity for undo
			Undo_EndEntity(ent);

			// end brushes for undo
			for (b = ent->brushes.onext; b && b != &ent->brushes; b = b->onext) {
				Undo_EndBrush(b);
			}

			if (!strcmp(ValueForKey(ent, "classname"), "worldspawn")) {
				// world brushes need to be added to the current world entity
				b = ent->brushes.onext;
				while (b && b != &ent->brushes) {
					brush_t *bNext = b->onext;
					Entity_UnlinkBrush(b);
					Entity_LinkBrush(world_entity, b);
					ptrs.Add(b);
					b = bNext;
				}
			}
			else {
				// the following bit remaps conflicting target/targetname key/value pairs
				CString str = ValueForKey(ent, "target");
				CString strKey;
				CString strTarget("");
				if (str.GetLength() > 0) {
					if (FindEntity("target", str.GetBuffer(0))) {
						if (!mapStr.Lookup(str, strKey)) {
							idStr key;
							UniqueTargetName(key);
							strKey = key;
							mapStr.SetAt(str, strKey);
						}

						strTarget = strKey;
						SetKeyValue(ent, "target", strTarget.GetBuffer(0));
					}
				}

				/*
				 * str = ValueForKey(ent, "name"); if (str.GetLength() > 0) { if
				 * (FindEntity("name", str.GetBuffer(0))) { if (!mapStr.Lookup(str, strKey)) {
				 * UniqueTargetName(strKey); mapStr.SetAt(str, strKey); } Entity_SetName(ent,
				 * strKey.GetBuffer(0)); } }
				 */
				CString cstrNameOld = ValueForKey(ent, "name");
				Entity_Name(ent, renameEntities);
				CString cstrNameNew = ValueForKey(ent, "name");
				if (cstrNameOld != cstrNameNew)
				{
					RemappedNames.Set(cstrNameOld, cstrNameNew);
				}
				//
				// if (strTarget.GetLength() > 0) SetKeyValue(ent, "target",
				// strTarget.GetBuffer(0));
				// add the entity to the end of the entity list
				//
				ent->next = &entities;
				ent->prev = entities.prev;
				entities.prev->next = ent;
				entities.prev = ent;
				g_qeglobals.d_num_entities++;

				for (b = ent->brushes.onext; b != &ent->brushes; b = b->onext) {
					ptrs.Add(b);
				}
			}
		}

		// now iterate through the remapped names, and see if there are any target-connections that need remaking...
		//
		// (I could probably write this in half the size with STL, but WTF, work with what we have...)
		//
		int iNumKeyVals = RemappedNames.GetNumKeyVals();
		for (int iKeyVal=0; iKeyVal < iNumKeyVals; iKeyVal++)
		{
			const idKeyValue *pKeyVal = RemappedNames.GetKeyVal( iKeyVal );

			LPCSTR psOldName = pKeyVal->GetKey().c_str();
			LPCSTR psNewName = pKeyVal->GetValue().c_str();

			entity_t *pEntOld = FindEntity("name", psOldName);	// original ent we cloned from
			entity_t *pEntNew = FindEntity("name", psNewName);	// cloned ent

			if (pEntOld && pEntNew)
			{
				CString cstrTargetNameOld = ValueForKey(pEntOld, "target");
				if (!cstrTargetNameOld.IsEmpty())
				{
					// ok, this ent was targeted at another ent, so it's clone needs updating to point to
					//	the clone of that target, so...
					//
					entity_t *pEntOldTarget = FindEntity("name", cstrTargetNameOld);
					if ( pEntOldTarget )
					{
						LPCSTR psNewTargetName = RemappedNames.GetString( cstrTargetNameOld );
						if (psNewTargetName && psNewTargetName[0])
						{
							SetKeyValue(pEntNew, "target", psNewTargetName);
						}
					}
				}
			}
		}
	}

	//
	// ::ShowWindow(g_qeglobals.d_hwndEntity, FALSE);
	// ::LockWindowUpdate(g_qeglobals.d_hwndEntity);
	//
	g_bScreenUpdates = false;
	for (int i = 0; i < ptrs.GetSize(); i++) {
		Brush_Build(reinterpret_cast < brush_t * > (ptrs[i]), true, false);
		Select_Brush(reinterpret_cast < brush_t * > (ptrs[i]), true, false);
	}

	// ::LockWindowUpdate(NULL);
	g_bScreenUpdates = true;

	ptrs.RemoveAll();

	//
	// reset the "need conversion" flag conversion to the good format done in
	// Map_BuildBrushData
	//
	g_qeglobals.bNeedConvert = false;

	Sys_UpdateWindows(W_ALL);

	// Sys_MarkMapModified();
	mapModified = 1;

	Undo_End();
}
Example #14
0
HRESULT GetRibbonText(BSTR * RibbonXml)
{
	LPBYTE content = NULL;
	DWORD content_length = 0;

	ASSERT_RETURN_VALUE(LoadResourceFromModule(
		AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_RESOURCE_H), L"TEXT", &content, &content_length), S_FALSE);

	CMemFile mf(content, content_length);
	CTextFileRead rdr(&mf);

	CMapStringToString replacements;

	CString line;
	while (rdr.ReadLine(line))
	{
		CSimpleArray<CString> tokens;

		CString token;
		token.Preallocate(30);

		for (LPCWSTR pos = line; *pos; ++pos)
		{
			if (*pos == ' ' || *pos == '\t')
			{
				if (!token.IsEmpty())
				{
					tokens.Add(token);
					token = CString();
				}
			}
			else
			{
				token += *pos;
			}
		}

		if (!token.IsEmpty())
			tokens.Add(token);

		if (tokens.GetSize() != 3)
			continue;

		if (tokens[0] != "#define")
			continue;

		replacements[tokens[1]] = tokens[2];
	}

	CString ribbon = LoadTextFromModule(AfxGetInstanceHandle(), IDR_RIBBON);

	for (int pos = 0; pos < ribbon.GetLength(); ++pos)
	{
		if (ribbon[pos] != '{')
			continue;

		int endpos = ribbon.Find('}', pos);
		ASSERT_CONTINUE(endpos != -1);

		CString token = ribbon.Mid(pos+1, endpos-pos-1);
		CString token_found;

		ASSERT_CONTINUE(replacements.Lookup(token, token_found));	

		ribbon.Delete(pos, endpos-pos+1);
		ribbon.Insert(pos, token_found);

		pos += (token_found.GetLength()-1);
	}

	*RibbonXml = ribbon.AllocSysString();
	return S_OK;
}
Example #15
0
// Inserts a video object in MMS message
// Input:	csObjPath=String with file path
void CMMSSender::InsertVideo(CString csObjPath)
{
	CMapStringToString mssContentType;
	mssContentType.SetAt("avi","video/avi");
	mssContentType.SetAt("asf","video/x-ms-asf");
	mssContentType.SetAt("mpg","video/mpeg");
	mssContentType.SetAt("mpeg","video/mpeg");
	mssContentType.SetAt("wmv","video/x-ms-wmv");

	CString csContentType;
	int nPosPunto=csObjPath.ReverseFind('.');
	if(nPosPunto!=-1)
	{
		CString csExtension=csObjPath.Mid(nPosPunto+1);
		mssContentType.Lookup(csExtension,csContentType);

		if(csContentType.IsEmpty())
			return;
	}

	CString csData;
	CString csURL;

	CString csCookie;

	CString csHeaders;
	CString csRetHeaders;
	CString csRetData;

	BYTE* pbtFile=(BYTE*)malloc(OBJ_BUFFER_SIZE);
	memset(pbtFile,0,OBJ_BUFFER_SIZE);

	BYTE* pbtContents=(BYTE*)malloc(OBJ_BUFFER_SIZE);
	memset(pbtContents,0,OBJ_BUFFER_SIZE);
	int nPosicionDatos=0;

	CString csSeparator="---------------------------7d77df567a4b9";

	// Object data generation
	CString csFilenamePart;
	csFilenamePart.Format("--%s\r\nContent-Disposition: form-data; name=\"file\"; filename=\"%s\"\r\nContent-Type: %s\r\n\r\n",csSeparator,csObjPath,csContentType);
	memcpy(&pbtContents[nPosicionDatos],csFilenamePart.GetBuffer(0),csFilenamePart.GetLength());
	nPosicionDatos+=csFilenamePart.GetLength();

	CFile fl;
	BOOL bRes=fl.Open(csObjPath,CFile::modeRead);
	if(bRes)
	{
		int nLeidos=fl.Read(pbtFile,OBJ_BUFFER_SIZE);
		fl.Close();

		memcpy(&pbtContents[nPosicionDatos],pbtFile,nLeidos);
		nPosicionDatos+=nLeidos;
	}

	CString csFinal;
	csFinal.Format("\r\n--%s--\r\n",csSeparator);
	memcpy(&pbtContents[nPosicionDatos],csFinal.GetBuffer(0),csFinal.GetLength());
	nPosicionDatos+=csFinal.GetLength();

    CString csContentType2;
	csContentType2.Format("multipart/form-data; boundary=%s",csSeparator);
	csHeaders = "Accept-Encoding: gzip, deflate\r\n"
				"Accept-Language: es\r\n"
				"Accept: */*\r\n"
				"Connection: Keep-Alive\r\n";
	csHeaders += "Content-type: "+csContentType2+"\r\n";
	csHeaders += "Cookie: "+m_csCookie+"\r\n";
	csURL.Format("http://%s/do/multimedia/uploadEnd",m_csServer);
	UINT nCode=PostHTTP(csURL,pbtContents,nPosicionDatos,csHeaders,csRetHeaders,csRetData);

	free(pbtFile);
	free(pbtContents);
}
Example #16
0
int main()
{
    CMapStringToString map;

    if( !map.IsEmpty() ) _fail;
    if( map.GetCount() != 0 ) _fail;
    if( map.GetSize() != 0 ) _fail;

    map.SetAt( _T("0"), _T(" ") );
    map.SetAt( _T("1"), _T("A") );
    map.SetAt( _T("2"), _T("B") );

    CString value;
    if( !map.Lookup( _T("0"), value ) ) _fail;
    if( value != _T(" ") ) _fail;
    if( !map.Lookup( _T("1"), value ) ) _fail;
    if( value != _T("A") ) _fail;
    if( !map.Lookup( _T("2"), value ) ) _fail;
    if( value != _T("B") ) _fail;
    if( map.Lookup( _T("3"), value ) ) _fail;

    POSITION    position = map.GetStartPosition();
    CString     key;
    BOOL        bFound0 = FALSE;
    BOOL        bFound1 = FALSE;
    BOOL        bFound2 = FALSE;
    while( position != NULL ) {
        map.GetNextAssoc( position, key, value );
        if( key == _T("0") ) {
            if( bFound0 ) _fail;
            if( value != _T(" ") ) _fail;
            bFound0 = TRUE;
        } else if( key == _T("1") ) {
            if( bFound1 ) _fail;
            if( value != _T("A") ) _fail;
            bFound1 = TRUE;
        } else if( key == _T("2") ) {
            if( bFound2 ) _fail;
            if( value != _T("B") ) _fail;
            bFound2 = TRUE;
        } else {
            _fail;
        }
    }
    if( !bFound0 ) _fail;
    if( !bFound1 ) _fail;
    if( !bFound2 ) _fail;

    map.RemoveKey( _T("0") );
    if( map.Lookup( _T("0"), value ) ) _fail;

    CMapStringToString smap1;
    CMapStringToString smap2;
    smap1[_T("0")] = _T(" ");
    smap1[_T("1")] = _T("A");
    smap1[_T("2")] = _T("B");
    
    CMemFile file;
    CArchive ar( &file, CArchive::store );
    smap1.Serialize( ar );
    ar.Close();

    file.Seek( 0, CFile::begin );
    CArchive ar2( &file, CArchive::load );
    smap2.Serialize( ar2 );
    ar2.Close();

    if( smap2[_T("0")] != _T(" ") ) _fail;
    if( smap2[_T("1")] != _T("A") ) _fail;
    if( smap2[_T("2")] != _T("B") ) _fail;

    _PASS;
}
BOOL CCapDownload::retrievePackages()
{
	CString					csCertFile,
		csId,
		csValue;
	COptDownloadPackage		*pOptDownloadPackage;
	CMapStringToStringArray	*pMapArray = NULL;
	CMapStringToString		*pMap = NULL;
	INT_PTR					nPack = 0;

	/***
	*
	* Environnement checking
	*
	***/

	// Working directory
	if (directoryCreate(getDownloadFolder()) == FALSE)
	{
		m_pLogger->log(LOG_PRIORITY_ERROR, _T("DOWNLOAD => Cannot create working directory (%s)"), LookupError(GetLastError()));
		return FALSE;
	}
	// Open package history file, create it if needed
	CFilePackageHistory cFileHistory;
	if (!cFileHistory.Open(getPackageHistoryFilename(), FALSE, TRUE))
	{
		m_pLogger->log(LOG_PRIORITY_ERROR, _T("DOWNLOAD => Cannot create history file <%>"), getPackageHistoryFilename());
		return FALSE;
	}
	if (!m_pPrologResp->isDownloadRequired())
	{
		m_pLogger->log(LOG_PRIORITY_DEBUG, _T("DOWNLOAD => No package available for download"));
		return FALSE;
	}
	// Trying to create suspend Download tool
	if (!suspendDownload())
	{
		m_pLogger->log(LOG_PRIORITY_ERROR, _T("DOWNLOAD => Cannot suspend Download and Setup Tool using <%s> file"), OCS_DOWNLOAD_SUSPEND);
		return FALSE;
	}
	// Trying to get exclusive access to download
	if (!lockDownload())
	{
		m_pLogger->log(LOG_PRIORITY_ERROR, _T("DOWNLOAD => Cannot lock directory <%s>"), getDownloadFolder());
		resumeDownload();
		return FALSE;
	}
	// Get generic download parameters and write them for using with download tool
	pMapArray = m_pPrologResp->getDownloadParameters();
	if ((pMapArray == NULL) || pMapArray->IsEmpty())
	{
		m_pLogger->log(LOG_PRIORITY_DEBUG, _T("DOWNLOAD => No download parameter available"));
		unlockDownload();
		resumeDownload();
		return FALSE;
	}
	// There is only one record for download parameters
	pMap = pMapArray->GetAt(0);
	pMap->Lookup(_T("FRAG_LATENCY"), m_csDownloadFragLatency);
	pMap->Lookup(_T("CYCLE_LATENCY"), m_csDownloadCycleLatency);
	pMap->Lookup(_T("PERIOD_LATENCY"), m_csDownloadPeriodLatency);
	pMap->Lookup(_T("PERIOD_LENGTH"), m_csDownloadPeriodLength);
	pMap->Lookup(_T("TIMEOUT"), m_csDownloadTimeout);
	pMap->Lookup(_T("EXECUTION_TIMEOUT"), m_csCommandTimeout);
	if (m_csCommandTimeout.IsEmpty())
		m_csCommandTimeout = COMMAND_TIMEOUT_DEFAULT;
	pMap->Lookup(_T("ON"), m_csDownloadOn);
	writeConfig();
	delete pMapArray;
	pMapArray = NULL;

	// Now get each package information
	pMapArray = m_pPrologResp->getDownloadPackages();
	for (nPack = 0; (pMapArray != NULL) && (nPack<pMapArray->GetCount()); nPack++)
	{
		if (((pMap = pMapArray->GetAt(nPack)) == NULL) || pMap->IsEmpty())
			continue;
		csId.Empty();
		pMap->Lookup(_T("ID"), csId);
		// Try to find if package was not previously downloaded, parsing package history file
		CString csHistBuf;
		BOOL	bAlreadySetup = FALSE;
		cFileHistory.SeekToBegin();
		while (cFileHistory.ReadPackage(csHistBuf))
		{
			if (csHistBuf.Find(csId) != -1)
			{
				// Package ID found in history
				bAlreadySetup = TRUE;
				break;
			}
		}
		pOptDownloadPackage = new COptDownloadPackage(this);
		pOptDownloadPackage->setId(csId);
		// If CERT_PATH or CERT_FILE option is provided
		csValue.Empty();
		pMap->Lookup(_T("CERT_PATH"), csValue);
		pOptDownloadPackage->setCertPath(csValue);
		csValue.Empty();
		pMap->Lookup(_T("CERT_FILE"), csValue);
		pOptDownloadPackage->setCertFile(csValue);
		// Set URL where to download INFO metadata
		csValue.Empty();
		pMap->Lookup(_T("INFO_LOC"), csValue);
		pOptDownloadPackage->setInfoLocation(csValue);
		// Set URL where to download fragment
		csValue.Empty();
		pMap->Lookup(_T("PACK_LOC"), csValue);
		pOptDownloadPackage->setPackLocation(csValue);
		// Set if we have to force package setup, even if already installed
		csValue.Empty();
		pMap->Lookup(_T("FORCE"), csValue);
		pOptDownloadPackage->setForce(csValue);
		// Set if we have to schedule package setup at specified date
		csValue.Empty();
		pMap->Lookup(_T("SCHEDULE"), csValue);
		pOptDownloadPackage->setSchedule(csValue);
		// Set post execution command if package action succeeded
		csValue.Empty();
		pMap->Lookup(_T("POSTCMD"), csValue);
		pOptDownloadPackage->setPostCmd(csValue);
		if (bAlreadySetup && !pOptDownloadPackage->isForced())
		{
			// Package ID found in history, do not download
			m_pLogger->log(LOG_PRIORITY_NOTICE, _T("DOWNLOAD => Will not download package <%s>, already in the package history"), csId);
			sendMessage(csId, SUCCESS_ALREADY_SETUP);
			// Delete already download directory if needed 
			pOptDownloadPackage->clean();
			delete pOptDownloadPackage;
		}
		else
		{
			// Package not already downloaded, or setup forced, put it in the download queue
			if (pOptDownloadPackage->isForced())
				m_pLogger->log(LOG_PRIORITY_DEBUG, _T("DOWNLOAD => Package <%s> forced, ignoring package history check"), csId);
			m_tPackages.Add(pOptDownloadPackage);
		}
	}
	cFileHistory.Close();
	delete pMapArray;
	// Cleaning file history for duplicates
	switch (CFilePackageHistory::CleanDuplicates(getPackageHistoryFilename()))
	{
	case 1:
		m_pLogger->log(LOG_PRIORITY_DEBUG, _T("DOWNLOAD => Package history file successfully cleaned for duplicate IDs"));
		break;
	case 2:
		m_pLogger->log(LOG_PRIORITY_DEBUG, _T("DOWNLOAD => Package history file cleaning not required"));
		break;
	default:
		m_pLogger->log(LOG_PRIORITY_DEBUG, _T("DOWNLOAD => Failed to clean Package history file for duplicate IDs"));
		break;
	}

	// Now, prepare directories and download instructions for download tool
	for (nPack = 0; nPack<m_tPackages.GetSize(); nPack++)
	{
		pOptDownloadPackage = (COptDownloadPackage*)(m_tPackages[nPack]);
		// Check if package is not expired
		if (pOptDownloadPackage->isExpired(m_csDownloadTimeout))
		{
			ULONG ulNow = time(NULL);
			m_pLogger->log(LOG_PRIORITY_ERROR, _T("DOWNLOAD => Package <%s> timed out (now:%lu, since:%lu, Timeout:%s)"), pOptDownloadPackage->getId(), ulNow, (ULONG)pOptDownloadPackage->getTimeStamp(), m_csDownloadTimeout);
			if (sendMessage(pOptDownloadPackage->getId(), ERR_TIMEOUT))
				// Server successfully notified => remove package
				if (!pOptDownloadPackage->clean())
					m_pLogger->log(LOG_PRIORITY_ERROR, _T("DOWNLOAD => Failed to remove timed out package <%s>"), pOptDownloadPackage->getId());
		}
		else
		{
			// Check if package not already added to download queue
			if (pOptDownloadPackage->makeDirectory() && !fileExists(pOptDownloadPackage->getLocalMetadataFilename()))
			{
				// Download metadata from deployment server
				if (pOptDownloadPackage->downloadInfoFile())
					m_pLogger->log(LOG_PRIORITY_NOTICE, _T("DOWNLOAD => Package <%s> added to download queue"), pOptDownloadPackage->getId());
				else
					// Error dowloading metadata => remove package directory to avoid error message into download tool
					pOptDownloadPackage->clean();
			}
			else
				m_pLogger->log(LOG_PRIORITY_DEBUG, _T("DOWNLOAD => Package <%s> already in download queue, keeping on package"), pOptDownloadPackage->getId());
		}
	}
	// Now, allow Download tool
	unlockDownload();
	resumeDownload();
	return TRUE;
}
Example #18
0
//
//================
//Map_ImportFile
// Timo 09/01/99 : called by CXYWnd::Paste & Map_ImportFile
// if Map_ImportFile ( prefab ), the buffer may contain brushes in old format ( conversion needed )
//================
//
void Map_ImportBuffer (char* buf)
{
	entity_t* ent;
	brush_t* b = NULL;
	CPtrArray ptrs;

	Select_Deselect();

	Undo_Start("import buffer");

	g_qeglobals.d_parsed_brushes = 0;
	if (buf)
	{
		CMapStringToString mapStr;
		StartTokenParsing (buf);
		g_qeglobals.d_num_entities = 0;

		// Timo
		// will be used in Entity_Parse to detect if a conversion between brush formats is needed
		g_qeglobals.bNeedConvert = false;
		g_qeglobals.bOldBrushes = false;
		g_qeglobals.bPrimitBrushes = false;

		while (1)
		{

			// use the selected brushes list as it's handy
			//ent = Entity_Parse (false, &selected_brushes);
			ent = Entity_Parse (false, &active_brushes);
			if (!ent)
				break;
			//end entity for undo
			Undo_EndEntity(ent);
			//end brushes for undo
			for(b = ent->brushes.onext; b && b != &ent->brushes; b = b->onext)
			{
				Undo_EndBrush(b);
			}

			if (!strcmp(ValueForKey (ent, "classname"), "worldspawn"))
			{
				// world brushes need to be added to the current world entity

				b=ent->brushes.onext;
				while (b && b != &ent->brushes)
				{
					brush_t* bNext = b->onext;
					Entity_UnlinkBrush(b);
					Entity_LinkBrush(world_entity, b);
					ptrs.Add(b);
					b = bNext;
				}
			}
			else
			{
				// the following bit remaps conflicting target/targetname key/value pairs
				CString str = ValueForKey(ent, "target");
				CString strKey;
				CString strTarget("");
				if (str.GetLength() > 0)
				{
					if (FindEntity("target", str.GetBuffer(0)))
					{
						if (!mapStr.Lookup(str, strKey))
						{
							UniqueTargetName(strKey);
							mapStr.SetAt(str, strKey);
						}
						strTarget = strKey;
						SetKeyValue(ent, "target", strTarget.GetBuffer(0));
					}
				}
				str = ValueForKey(ent, "targetname");
				if (str.GetLength() > 0)
				{
					if (FindEntity("targetname", str.GetBuffer(0)))
					{
						if (!mapStr.Lookup(str, strKey))
						{
							UniqueTargetName(strKey);
							mapStr.SetAt(str, strKey);
						}
						SetKeyValue(ent, "targetname", strKey.GetBuffer(0));
					}
				}
				//if (strTarget.GetLength() > 0)
				//  SetKeyValue(ent, "target", strTarget.GetBuffer(0));

				// add the entity to the end of the entity list
				ent->next = &entities;
				ent->prev = entities.prev;
				entities.prev->next = ent;
				entities.prev = ent;
				g_qeglobals.d_num_entities++;

				for (b=ent->brushes.onext ; b != &ent->brushes ; b=b->onext)
				{
					ptrs.Add(b);
				}
			}
		}
	}

	//::ShowWindow(g_qeglobals.d_hwndEntity, FALSE);
	//::LockWindowUpdate(g_qeglobals.d_hwndEntity);
	g_bScreenUpdates = false; 
	for (int i = 0; i < ptrs.GetSize(); i++)
	{
		Brush_Build(reinterpret_cast<brush_t*>(ptrs[i]), true, false);
		Select_Brush(reinterpret_cast<brush_t*>(ptrs[i]), true, false);
	}
	//::LockWindowUpdate(NULL);
	g_bScreenUpdates = true; 

	ptrs.RemoveAll();

	// reset the "need conversion" flag
	// conversion to the good format done in Map_BuildBrushData
	g_qeglobals.bNeedConvert=false;

	Sys_UpdateWindows (W_ALL);
  //Sys_MarkMapModified();
	modified = true;

	Undo_End();

}