Esempio n. 1
0
void CEllipseCenterGroup::AddPoint(CAtlList<EllipseCenter>& centers, IntersectFunction intersect, int x, int y)
{
    POSITION pos = centers.GetTailPosition();
    while (pos) {
        POSITION posCur = pos;
        auto& center = centers.GetPrev(pos);

        int dyIntersect = intersect(x - center.x, y - center.y);
        if (dyIntersect != CEllipse::NO_INTERSECT_INNER) {
            int yIntersect = (dyIntersect == CEllipse::NO_INTERSECT_OUTER) ? (y - m_pEllipse->GetYRadius() - 1) : (center.y + dyIntersect);
            if (yIntersect < center.yStopDrawing) {
                center.yStopDrawing = yIntersect;
                if (pos && center.yStopDrawing <= centers.GetAt(pos).yStopDrawing) {
                    centers.RemoveAt(posCur);
                }
            } else {
                break;
            }
        }
    }

    auto& center = centers.GetAt(centers.AddTail());
    center.x = x;
    center.y = y;
    center.yStopDrawing = y + m_pEllipse->GetYRadius();
}
Esempio n. 2
0
void CDSFilters::SortInfoByExtension(CAtlList<DSFilterInfo*>& InfoList, const TCHAR* pcszExtension)
{
	DSFilterInfo* pInfo = NULL;
	POSITION pos = InfoList.GetHeadPosition();
	while (pos)
	{
		BOOL bMatched = FALSE;
		pInfo = InfoList.GetAt(pos);
		if (pInfo != NULL)
		{
			POSITION pos2 = pInfo->extensions.GetHeadPosition();
			while (pos2)
			{
				CString& extension = pInfo->extensions.GetNext(pos2);
				if (extension.CompareNoCase(pcszExtension+1))
				{
					bMatched = TRUE;
					break;
				}
			}
			if (bMatched)
			{
				InfoList.MoveToHead(pos);
			}
		}
		InfoList.GetNext(pos);
	}
}
Esempio n. 3
0
HRESULT CHdmvClipInfo::FindMainMovie(LPCTSTR strFolder, CString& strPlaylistFile, CAtlList<PlaylistItem>& MainPlaylist, CAtlList<PlaylistItem>& MPLSPlaylists)
{
    HRESULT hr = E_FAIL;

    CString strPath(strFolder);
    CString strFilter;

    MPLSPlaylists.RemoveAll();

    CAtlList<PlaylistItem> Playlist;
    WIN32_FIND_DATA fd = {0};

    strPath.Replace(_T("\\PLAYLIST\\"), _T("\\"));
    strPath.Replace(_T("\\STREAM\\"), _T("\\"));
    strPath += _T("\\BDMV\\");
    strFilter.Format(_T("%sPLAYLIST\\*.mpls"), strPath);

    HANDLE hFind = FindFirstFile(strFilter, &fd);
    if (hFind != INVALID_HANDLE_VALUE) {
        REFERENCE_TIME rtMax = 0;
        REFERENCE_TIME rtCurrent;
        CString strCurrentPlaylist;
        do {
            strCurrentPlaylist.Format(_T("%sPLAYLIST\\%s"), strPath, fd.cFileName);
            Playlist.RemoveAll();

            // Main movie shouldn't have duplicate M2TS filename...
            if (ReadPlaylist(strCurrentPlaylist, rtCurrent, Playlist) == S_OK) {
                if (rtCurrent > rtMax) {
                    rtMax = rtCurrent;
                    strPlaylistFile = strCurrentPlaylist;
                    MainPlaylist.RemoveAll();
                    POSITION pos = Playlist.GetHeadPosition();
                    while (pos) {
                        MainPlaylist.AddTail(Playlist.GetNext(pos));
                    }
                    hr = S_OK;
                }
                if (rtCurrent >= (REFERENCE_TIME)MIN_LIMIT * 600000000) {
                    PlaylistItem Item;
                    Item.m_strFileName = strCurrentPlaylist;
                    Item.m_rtIn = 0;
                    Item.m_rtOut = rtCurrent;
                    MPLSPlaylists.AddTail(Item);
                }

            }
        } while (FindNextFile(hFind, &fd));

        FindClose(hFind);
    }

    if (MPLSPlaylists.GetCount() > 1) {
        // bubble sort
        for (size_t j = 0; j < MPLSPlaylists.GetCount(); j++) {
            for (size_t i = 0; i < MPLSPlaylists.GetCount() - 1; i++) {
                if (MPLSPlaylists.GetAt(MPLSPlaylists.FindIndex(i)).Duration() < MPLSPlaylists.GetAt(MPLSPlaylists.FindIndex(i + 1)).Duration()) {
                    MPLSPlaylists.SwapElements(MPLSPlaylists.FindIndex(i), MPLSPlaylists.FindIndex(i + 1));
                }
            }
        }
    }

    return hr;
}
CString CBaseSplitterOutputPin::GetMediaTypeDesc(CAtlArray<CMediaType>& mts, LPCWSTR pName, CBaseFilter* pFilter)
{
	if (mts.IsEmpty()) {
		return pName;
	}

	CLSID clSID;
	HRESULT hr = pFilter->GetClassID(&clSID);
	if ((clSID == __uuidof(CMpegSourceFilter)) || (clSID == __uuidof(CMpegSplitterFilter))) {
		return pName;
	}

	CAtlList<CString> Infos;
	const CMediaType* pmt = &mts[0];

	if (pmt->majortype == MEDIATYPE_Video) {
		const VIDEOINFOHEADER *pVideoInfo	= NULL;
		const VIDEOINFOHEADER2 *pVideoInfo2	= NULL;

		BOOL bAdd = FALSE;

		if (pmt->formattype == FORMAT_VideoInfo) {
			pVideoInfo = GetFormatHelper(pVideoInfo, pmt);

		} else if (pmt->formattype == FORMAT_MPEGVideo) {
			Infos.AddTail(L"MPEG");

			const MPEG1VIDEOINFO *pInfo = GetFormatHelper(pInfo, pmt);
			pVideoInfo = &pInfo->hdr;

			bAdd = TRUE;
		} else if (pmt->formattype == FORMAT_MPEG2_VIDEO) {
			const MPEG2VIDEOINFO *pInfo = GetFormatHelper(pInfo, pmt);
			pVideoInfo2 = &pInfo->hdr;

			bool bIsAVC = false;
			bool bIsMPEG2 = false;

			if (pInfo->hdr.bmiHeader.biCompression == FCC('AVC1') || pInfo->hdr.bmiHeader.biCompression == FCC('H264')) {
				bIsAVC = true;
				Infos.AddTail(L"AVC (H.264)");
				bAdd = TRUE;
			} else if (pInfo->hdr.bmiHeader.biCompression == FCC('AMVC')) {
				bIsAVC = true;
				Infos.AddTail(L"MVC (Full)");
				bAdd = TRUE;
			} else if (pInfo->hdr.bmiHeader.biCompression == FCC('EMVC')) {
				bIsAVC = true;
				Infos.AddTail(L"MVC (Subset)");
				bAdd = TRUE;
			} else if (pInfo->hdr.bmiHeader.biCompression == 0) {
				Infos.AddTail(L"MPEG2");
				bIsMPEG2 = true;
				bAdd = TRUE;
			}

			if (bIsMPEG2) {
				Infos.AddTail(MPEG2_Profile[pInfo->dwProfile]);
			} else if (pInfo->dwProfile) {
				if (bIsAVC) {
					switch (pInfo->dwProfile) {
						case 44:
							Infos.AddTail(L"CAVLC Profile");
							break;
						case 66:
							Infos.AddTail(L"Baseline Profile");
							break;
						case 77:
							Infos.AddTail(L"Main Profile");
							break;
						case 88:
							Infos.AddTail(L"Extended Profile");
							break;
						case 100:
							Infos.AddTail(L"High Profile");
							break;
						case 110:
							Infos.AddTail(L"High 10 Profile");
							break;
						case 118:
							Infos.AddTail(L"Multiview High Profile");
							break;
						case 122:
							Infos.AddTail(L"High 4:2:2 Profile");
							break;
						case 244:
							Infos.AddTail(L"High 4:4:4 Profile");
							break;
						case 128:
							Infos.AddTail(L"Stereo High Profile");
							break;
						default:
							Infos.AddTail(FormatString(L"Profile %d", pInfo->dwProfile));
							break;
					}
				} else {
					Infos.AddTail(FormatString(L"Profile %d", pInfo->dwProfile));
				}
			}

			if (bIsMPEG2) {
				Infos.AddTail(MPEG2_Level[pInfo->dwLevel]);
			} else if (pInfo->dwLevel) {
				if (bIsAVC) {
					Infos.AddTail(FormatString(L"Level %1.1f", double(pInfo->dwLevel)/10.0));
				} else {
					Infos.AddTail(FormatString(L"Level %d", pInfo->dwLevel));
				}
			}
		} else if (pmt->formattype == FORMAT_VIDEOINFO2) {
			const VIDEOINFOHEADER2 *pInfo = GetFormatHelper(pInfo, pmt);
			pVideoInfo2 = pInfo;
		}

		if (!bAdd) {
			BITMAPINFOHEADER bih;
			bool fBIH = ExtractBIH(pmt, &bih);
			if (fBIH) {
				CString codecName = CMediaTypeEx::GetVideoCodecName(pmt->subtype, bih.biCompression);
				if (codecName.GetLength() > 0) {
					Infos.AddTail(codecName);
				}
			}
		}

		if (pVideoInfo2) {
			if (pVideoInfo2->bmiHeader.biWidth && pVideoInfo2->bmiHeader.biHeight) {
				Infos.AddTail(FormatString(L"%dx%d", pVideoInfo2->bmiHeader.biWidth, pVideoInfo2->bmiHeader.biHeight));
			}
			if (pVideoInfo2->AvgTimePerFrame) {
				Infos.AddTail(FormatString(L"%.3f fps", 10000000.0/double(pVideoInfo2->AvgTimePerFrame)));
			}
			if (pVideoInfo2->dwBitRate) {
				Infos.AddTail(FormatBitrate(pVideoInfo2->dwBitRate));
			}
		} else if (pVideoInfo) {
			if (pVideoInfo->bmiHeader.biWidth && pVideoInfo->bmiHeader.biHeight) {
				Infos.AddTail(FormatString(L"%dx%d", pVideoInfo->bmiHeader.biWidth, pVideoInfo->bmiHeader.biHeight));
			}
			if (pVideoInfo->AvgTimePerFrame) {
				Infos.AddTail(FormatString(L"%.3f fps", 10000000.0/double(pVideoInfo->AvgTimePerFrame)));
			}
			if (pVideoInfo->dwBitRate) {
				Infos.AddTail(FormatBitrate(pVideoInfo->dwBitRate));
			}
		}
	} else if (pmt->majortype == MEDIATYPE_Audio) {
		if (pmt->formattype == FORMAT_WaveFormatEx) {
			const WAVEFORMATEX *pInfo = GetFormatHelper(pInfo, pmt);

			if (pmt->subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO) {
				Infos.AddTail(L"DVD LPCM");
			} else if (pmt->subtype == MEDIASUBTYPE_HDMV_LPCM_AUDIO) {
				const WAVEFORMATEX_HDMV_LPCM *pInfoHDMV = GetFormatHelper(pInfoHDMV, pmt);
				UNREFERENCED_PARAMETER(pInfoHDMV);
				Infos.AddTail(L"HDMV LPCM");
			}
			if (pmt->subtype == MEDIASUBTYPE_DOLBY_DDPLUS) {
				Infos.AddTail(L"Dolby Digital Plus");
			} else {
				switch (pInfo->wFormatTag) {
					case WAVE_FORMAT_MPEG: {
						const MPEG1WAVEFORMAT* pInfoMPEG1 = GetFormatHelper(pInfoMPEG1, pmt);

						int layer = GetHighestBitSet32(pInfoMPEG1->fwHeadLayer) + 1;
						Infos.AddTail(FormatString(L"MPEG1 - Layer %d", layer));
					}
					break;
					default: {
						CString codecName = CMediaTypeEx::GetAudioCodecName(pmt->subtype, pInfo->wFormatTag);
						if (codecName.GetLength() > 0) {
							Infos.AddTail(codecName);
						}
					}
					break;
				}
			}

			if (pInfo->nSamplesPerSec) {
				Infos.AddTail(FormatString(L"%.1f kHz", double(pInfo->nSamplesPerSec)/1000.0));
			}
			if (pInfo->nChannels) {
				Infos.AddTail(FormatString(L"%d chn", pInfo->nChannels));
			}
			if (pInfo->wBitsPerSample) {
				Infos.AddTail(FormatString(L"%d bit", pInfo->wBitsPerSample));
			}
			if (pInfo->nAvgBytesPerSec) {
				Infos.AddTail(FormatBitrate(pInfo->nAvgBytesPerSec * 8));
			}
		} else if (pmt->formattype == FORMAT_VorbisFormat) {
			const VORBISFORMAT *pInfo = GetFormatHelper(pInfo, pmt);

			Infos.AddTail(CMediaTypeEx::GetAudioCodecName(pmt->subtype, 0));

			if (pInfo->nSamplesPerSec) {
				Infos.AddTail(FormatString(L"%.1f kHz", double(pInfo->nSamplesPerSec)/1000.0));
			}
			if (pInfo->nChannels) {
				Infos.AddTail(FormatString(L"%d chn", pInfo->nChannels));
			}

			if (pInfo->nAvgBitsPerSec) {
				Infos.AddTail(FormatString(L"%d bit", pInfo->nAvgBitsPerSec));
			}
			if (pInfo->nAvgBitsPerSec) {
				Infos.AddTail(FormatBitrate(pInfo->nAvgBitsPerSec * 8));
			}
		} else if (pmt->formattype == FORMAT_VorbisFormat2) {
			const VORBISFORMAT2 *pInfo = GetFormatHelper(pInfo, pmt);

			Infos.AddTail(CMediaTypeEx::GetAudioCodecName(pmt->subtype, 0));

			if (pInfo->SamplesPerSec) {
				Infos.AddTail(FormatString(L"%.1f kHz", double(pInfo->SamplesPerSec)/1000.0));
			}
			if (pInfo->Channels) {
				Infos.AddTail(FormatString(L"%d chn", pInfo->Channels));
			}
		}
	}

	if (!Infos.IsEmpty()) {
		CString Ret = pName;
		Ret += " (";

		bool bFirst = true;

		for (POSITION pos = Infos.GetHeadPosition(); pos; Infos.GetNext(pos)) {
			const CString& String = Infos.GetAt(pos);

			if (bFirst) {
				Ret += String;
			} else {
				Ret += L", " + String;
			}

			bFirst = false;
		}

		Ret += ')';

		return Ret;
	}

	return pName;
}
Esempio n. 5
0
//THIS FUNCTION IS QUITE COMPLICATED BECAUSE 
//IT HAS TO DEAL WITH MAYA NAME MANGLING!
//tokenize the path.
//add each token into the element list which tracks the attributes and indices
//for each entry added make sure there are no parents left out from maya name mangling.
//after the list is populated and missing elements area added 
//we reiterate and produce the final result.
MPlug		FxInternal::DecodePlug(const CStringA& plugStr)
{

	MPlug result;
	MFnDependencyNode depNode(GetSite());

	CAtlList<PathDecodeElement> elementList;

	//tokenize the path
	int iLastPos=0;
	int iThisPos=0;
	CStringA subStr;
	while( iLastPos= iThisPos, 
		subStr=plugStr.Tokenize(".[]", iThisPos), 
		iThisPos != -1 )
	{
		//char lastChar= subStr[iLastPos];
		//char thisChar= subStr[iThisPos];

		//are we looking at a named portion?
		if(iLastPos == 0 
			|| plugStr[iLastPos-1]=='.'
			|| (plugStr[iLastPos-1]==']' && plugStr[iLastPos]=='.'))
		{
			//if the name is length zero then it must be the case when 
			// you do last[#].  The situation is caused by  the sequence "]."
			//if we dont have a name we can skip since only 1d arrays are allowed.

			if(subStr.GetLength() > 0)
			{
		
				//everything we add is going to be based on the current tail.
				//because we are adding parents, as we find parents we can continue
				//to add them to this position so that they will order themselves properly
				POSITION insertPos= elementList.GetTailPosition();

				//calculate the cancel condition.
				//it is the current tail's object if a tail exists otherwise NULL
				//NULL indicates go all the way to the root
				MObject cancelObj= MObject::kNullObj;
				if(elementList.GetCount() > 0)
				{
					cancelObj= elementList.GetTail().Attribute.object();
				}


				//get the object we are currently working with
				MObject thisObj= depNode.attribute(subStr.GetString());
				if(thisObj.isNull())
					return MPlug();//Critical element of the path was not found...return NULL


				//add it to the list so that we have something to insertBefore
				elementList.AddTail();
				elementList.GetTail().Name= subStr;
				elementList.GetTail().Attribute.setObject(thisObj);



				//walk through all of the parents until we reach cancel condition.
				//we can add  the current element onto the list in the same way.
				for( MFnAttribute itrAttr( elementList.GetTail().Attribute.parent() );
					!itrAttr.object().isNull()  && (cancelObj != itrAttr.object());
					itrAttr.setObject(itrAttr.parent()))
				{
					PathDecodeElement element;
					element.Attribute.setObject( itrAttr.object() );

					//we change the position so that the grandparent is inserted before the parent
					insertPos= elementList.InsertBefore( insertPos, element);
				}
			}
		}
		//are we looking at a numbered portion?
		else if(plugStr[iLastPos-1]=='[' && plugStr[iThisPos-1]==']')
		{
			//if so change the array index.
			elementList.GetTail().IsArray= true;
			elementList.GetTail().Index = atoi( subStr.GetString() );
		}
		else
			DXCC_ASSERT(false);//VERY POORLY FORMED STRING

	}

	//produce the result plug off of the elementList.
	bool first= true;
	for(POSITION pos= elementList.GetHeadPosition();
		pos != NULL;
		elementList.GetNext(pos))
	{
		PathDecodeElement& element= elementList.GetAt(pos);

		if(first)
		{//on first one we initialize the result 
			first= false;
			result= MPlug( GetSite(), element.Attribute.object() );
		}
		else
		{
			result= result.child( element.Attribute.object() );
		}

		if(element.IsArray)
		{
			result= result.elementByLogicalIndex(element.Index);
		}


		if(result.isNull())
			return MPlug();//Critical element of the path was not found...return NULL
	}


	return result;
}
Esempio n. 6
0
BOOL bigfilehelper::GetAutoDestDirFromSize(CString& strDir)
{
    BOOL retval = FALSE;
    CAtlArray<TCHAR> buffer;
    TCHAR* pBuffer = NULL;
    DWORD dwSize;
    CAtlList<CString> logicalDrvs;
    CString strDrv;
    POSITION pos = NULL;
    POSITION max_size_pos = NULL;
    ULONGLONG uMaxSize = 0;
    DWORD dwSectorsPerCluster;
    DWORD dwBytesPerSector;
    DWORD dwNumberOfFreeClusters;
    DWORD dwTotalNumberOfClusters;
    CString strSysDrv;
    TCHAR szVolName[MAX_PATH+1] = { 0 };
    TCHAR szFileSystem[MAX_PATH+1] = { 0 };
    BOOL fRetCode;

    SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS);

    if (!GetSystemDrive(strSysDrv))
        goto clean0;

    buffer.SetCount(512);
    pBuffer = buffer.GetData();
    dwSize = (DWORD)buffer.GetCount();
    memset(pBuffer, 0, dwSize * sizeof(TCHAR));
    dwSize = GetLogicalDriveStrings(dwSize, buffer.GetData());

    if (dwSize > 2) 
    {
        strDrv = pBuffer;
        logicalDrvs.AddTail(strDrv);

        for (DWORD i = 3; i < dwSize; ++i) 
        {
            if (pBuffer[i] != 0 && pBuffer[i - 1] == 0) 
            {
                strDrv = pBuffer + i;
                logicalDrvs.AddTail(strDrv);
            }
        }
    }

    pos = logicalDrvs.GetHeadPosition();
    while (pos)
    {
        POSITION current = pos;
        CString _drv = logicalDrvs.GetNext(pos);
        _drv.MakeLower();
        if (_drv == _T("a:\\") || _drv == _T("b:\\"))
        {
            logicalDrvs.RemoveAt(current);
            continue;
        }

        UINT uType = GetDriveType(_drv);
        if (uType != DRIVE_FIXED &&
            uType != DRIVE_REMOVABLE)
        {
            logicalDrvs.RemoveAt(current);
            continue;
        }

        if (strSysDrv.CompareNoCase(_drv)==0)
        {
            logicalDrvs.RemoveAt(current);
            continue;
        }

        RtlZeroMemory(szVolName, sizeof(szVolName));
        RtlZeroMemory(szFileSystem, sizeof(szFileSystem));
        fRetCode = GetVolumeInformation(
            _drv,
            szVolName,
            MAX_PATH+1,
            NULL,
            NULL,
            NULL,
            szFileSystem,
            MAX_PATH+1
            );
        if (!fRetCode)
        {
            logicalDrvs.RemoveAt(current);
            continue;
        }
    }

    pos = logicalDrvs.GetHeadPosition();
    while (pos)
    {
        POSITION current = pos;
        const CString& _drv = logicalDrvs.GetNext(pos);
        BOOL fRetCode = GetDiskFreeSpace(
            _drv,
            &dwSectorsPerCluster,
            &dwBytesPerSector,
            &dwNumberOfFreeClusters,
            &dwTotalNumberOfClusters
            );
        if (!fRetCode)
            continue;

        ULONGLONG uCurrentFreeSize = (ULONGLONG)dwNumberOfFreeClusters * dwSectorsPerCluster * dwBytesPerSector;
        if (uCurrentFreeSize > uMaxSize)
        {
            max_size_pos = current;
            uMaxSize = uCurrentFreeSize;
        }
    }
    if (max_size_pos==NULL)
        goto clean0;
    strDir = logicalDrvs.GetAt(max_size_pos);
    strDir += _T("系统盘大文件");

    retval = TRUE;

clean0:
    return retval;
}
Esempio n. 7
0
void SZYamlDocument::Dump(CString& strText, int nDumpIndent/* = SZYAML_DUMP_INDENT*/)
{
    POSITION pos = m_YamlItemList.GetHeadPosition();
    struct _KeyStackNode 
    {
        _KeyStackNode()
            : nIndent(0)
            , nChildIndent(0)
            , bIsList(FALSE)
        {
        }
        int nIndent;
        int nChildIndent;
        CString strKey;
        BOOL bIsList;
    };
    CAtlList<_KeyStackNode> listKeyStack;
    int nLastIndent = -1;
    BOOL bListItem = FALSE, bPrintThisLine = TRUE;
    CString strLine;

    strText = _T("");

    while (pos)
    {
        _YamlItem &item = m_YamlItemList.GetAt(pos);

        if (listKeyStack.IsEmpty())
            bListItem = FALSE;
        else
            bListItem = listKeyStack.GetTail().bIsList;

        if (item.nIndent == nLastIndent + 1)
        {
            _KeyStackNode &newkey = listKeyStack.GetAt(listKeyStack.AddTail());
            POSITION posNext = _GetNextPos(pos, TRUE);

            newkey.nIndent = item.nIndent;
            newkey.strKey = item.node.Key();
            newkey.bIsList = (posNext != NULL);
        }
        else if (item.nIndent == nLastIndent)
        {
            _KeyStackNode &newkey = listKeyStack.GetTail();
            POSITION posNext = _GetNextPos(pos, TRUE);

            newkey.nIndent = item.nIndent;
            newkey.strKey = item.node.Key();
            newkey.bIsList = (posNext != NULL);
        }
        else if (item.nIndent < nLastIndent)
        {
            for (nLastIndent -= item.nIndent; nLastIndent > 0; -- nLastIndent)
                listKeyStack.RemoveTail();

            if (listKeyStack.IsEmpty())
                bPrintThisLine = TRUE;
            else
            {
                _KeyStackNode &newkey = listKeyStack.GetTail();

                newkey.nIndent = item.nIndent;
                if (newkey.strKey != item.node.Key())
                {
                    newkey.strKey = item.node.Key();
                    POSITION posNext = _GetNextPos(pos, TRUE);
                    newkey.bIsList = (posNext != NULL);
                }
                else
                    bPrintThisLine = !newkey.bIsList;
            }
        }

#ifdef _SZYAML_DEBUG_TRACE
        { // Trace Key Stack
            kconsole::printf(_T("  "));

            for (POSITION pos = listKeyStack.GetHeadPosition(); pos != NULL; listKeyStack.GetNext(pos))
            {
                _KeyStackNode key = listKeyStack.GetAt(pos);
                kconsole::settextcolor(TRUE, TRUE, TRUE, FALSE);
                kconsole::printf(_T("(%d, '%s', %d)"), key.nIndent, key.strKey, key.bIsList);
                kconsole::settextcolor(TRUE, TRUE, TRUE, TRUE);
            }

            kconsole::printf(_T("\r\n"));
        }
#endif

        // 这里对不确定长度的%s不使用Format,是因为MIN_CRT的格式化输出限制长度为1024,见atlstr.h
        // by bbcallen 2009-07-02
        if (bPrintThisLine)
        {
            if (bListItem)
            {
                strLine.Format(
                    _T("%s-%s"),  
                    CString(_T(' '), (item.nIndent - 1) * nDumpIndent),  
                    CString(_T(' '), nDumpIndent - 1)
                    );
                strLine.Append(item.node.Key());
                strLine.Append(_T(": "));
                strLine.Append(item.node.String());
                strLine.Append(_T("\r\n"));
            }
            else
            {
                strLine.Format(
                    _T("%s"),  
                    CString(_T(' '), item.nIndent * nDumpIndent)
                    );

                strLine.Append(item.node.Key());
                strLine.Append(_T(": "));
                strLine.Append(item.node.String());
                strLine.Append(_T("\r\n"));
            }
#ifdef _SZYAML_DEBUG_TRACE
            kconsole::printf(strLine);
#endif
            strText += strLine;
        }
        else
            bPrintThisLine = TRUE;

        nLastIndent = item.nIndent;

        m_YamlItemList.GetNext(pos);
    }
}
Esempio n. 8
0
BOOL SZYamlDocument::Load(LPCTSTR lpszText)
{
    BOOL bResult = FALSE;
    BOOL bNotFinish = TRUE;
    CString strText = lpszText, strLine, strKey, strValue;
    int nThisLinePos = 0, nNextLinePos = 0, nColonPos = 0;
    int nIndent = 0, nLineNum = 1;
    struct _KeyStackNode 
    {
        _KeyStackNode()
            : nIndent(0)
            , nChildIndent(0)
            , bIsList(FALSE)
        {
        }
        int nIndent;
        int nChildIndent;
        CString strKey;
        BOOL bIsList;
    };
    CAtlList<_KeyStackNode> listKeyStack;
    BOOL bNewChild = FALSE, bIsListItem = FALSE;

    m_YamlItemList.RemoveAll();

    if (!lpszText)
        goto Exit0;

    while (bNotFinish)
    {
        nNextLinePos = strText.Find(_T('\n'), nThisLinePos);
        if (-1 == nNextLinePos)
        {
            bNotFinish = FALSE;
            strLine = strText.Mid(nThisLinePos);
        }
        else
            strLine = strText.Mid(nThisLinePos, nNextLinePos - nThisLinePos);

        nIndent = 0;

        // Get indent
        while (_T(' ') == strLine[nIndent])
            nIndent ++;

        nColonPos = strLine.Find(_T(':'));

        strKey = strLine.Left(nColonPos).Trim();
        strValue = strLine.Mid(nColonPos + 1).Trim();

        if (_T('-') == strKey[0])
        {
            int nIndentMore = 1;

            while (_T(' ') == strKey[nIndentMore])
                nIndentMore ++;

            nIndent += nIndentMore;

            strKey = strKey.Mid(nIndentMore);

            bIsListItem = TRUE;
        }
        else
            bIsListItem = FALSE;

        if (bNewChild)
        {
            _KeyStackNode &LastKey = listKeyStack.GetTail();
            LastKey.nChildIndent = nIndent;

            if (bIsListItem)
                LastKey.bIsList = TRUE;

#ifdef _SZYAML_DEBUG_TRACE
            { // Trace Key Stack
                kconsole::printf(_T("  "));

                for (POSITION pos = listKeyStack.GetHeadPosition(); pos != NULL; listKeyStack.GetNext(pos))
                {
                    _KeyStackNode key = listKeyStack.GetAt(pos);
                    kconsole::printf(_T("(%d, '%s', %d)"), key.nChildIndent, key.strKey, key.bIsList);
                }

                kconsole::printf(_T("\r\n"));
            }
#endif
        }

        strLine = strLine.Mid(nIndent);

        if (strLine.IsEmpty())
            continue;

        while (!listKeyStack.IsEmpty())
        {
            _KeyStackNode &LastKey = listKeyStack.GetTail();
            if (LastKey.nChildIndent == nIndent)
                break;

#ifdef _SZYAML_DEBUG_TRACE
            kconsole::printf(_T(" ### (%d, %d)\r\n"), LastKey.nChildIndent, nIndent);
#endif

            if (LastKey.nChildIndent < nIndent)
            {
#ifdef _SZYAML_DEBUG_TRACE
                kconsole::printf(_T(" * ERROR: Line %d, Indent Error\r\n"), nLineNum);
#endif
                goto Exit0;
            }

            listKeyStack.RemoveTail();

#ifdef _SZYAML_DEBUG_TRACE
            { // Trace Key Stack
                kconsole::printf(_T("  "));

                for (POSITION pos = listKeyStack.GetHeadPosition(); pos != NULL; listKeyStack.GetNext(pos))
                {
                    _KeyStackNode key = listKeyStack.GetAt(pos);
                    kconsole::printf(_T("(%d, '%s', %d)"), key.nChildIndent, key.strKey, key.bIsList);
                }

                kconsole::printf(_T("\r\n"));
            }
#endif
        }

        if (bIsListItem && !bNewChild)
        {
            _KeyStackNode &LastKey = listKeyStack.GetTail();
            SZYamlNode newNode;

            newNode.SetKey(LastKey.strKey);
            _AppendNode((int)listKeyStack.GetCount() - 1, newNode);
        }

        if (1 < strValue.GetLength() && strValue[0] == strValue[strValue.GetLength() - 1]
            && (_T('\'') == strValue[0] || _T('\"') == strValue[0]))
            strValue = strValue.Mid(1, strValue.GetLength() - 2);

        if (strValue.IsEmpty())
        {
            _KeyStackNode &NewKey = listKeyStack.GetAt(listKeyStack.AddTail());

            NewKey.nIndent = nIndent;
            NewKey.strKey = strKey;

            bNewChild = TRUE;
        }
        else
            bNewChild = FALSE;

        {
            SZYamlNode newNode;

            newNode.SetKey(strKey);
            newNode.SetValue(strValue);
            _AppendNode((int)listKeyStack.GetCount() - (bNewChild ? 1 : 0), newNode);
        }

        nThisLinePos = nNextLinePos + 1;
        ++ nLineNum;
    }

    SZYamlHandle::_SetPosition(this, m_YamlItemList.GetHeadPosition());

    bResult = TRUE;

Exit0:

    return bResult;
}
VOID CBeikeSafeSoftmgrNecessHandler::OnBtnQuerySoft()
{
	CString	strSearch;
	m_editQuery.GetWindowText(strSearch);

	if (strSearch == BkString::Get(IDS_SOFTMGR_8016) )
		return;
	else if (strSearch.IsEmpty())
	{
		if (!m_strViewDetailSoftId.IsEmpty())
		{
			m_pSoftMgrMainUI->_QuerySoftMark(m_strViewDetailSoftId);
			m_strViewDetailSoftId.Empty();

			m_IEDetail.Show2(_T("about:blank"),NULL);
			m_pMainDlg->SetItemVisible(IDC_SOFT_NECESS_DIV_RIGHT_LIST_SHOW,TRUE);

			m_pMainDlg->SetItemVisible(IDC_SOFT_NECESS_DIV_RIGHT_DETAIL_SHOW,FALSE);
			m_pMainDlg->SetItemVisible(IDC_SOFT_NECESS_SHOW_FREE_SOFT,TRUE);
			m_pMainDlg->SetItemVisible(IDC_SOFT_NECESS_SHOW_NOPLUG_SOFT,TRUE);

			if ( ::GetFocus() != m_editQuery.m_hWnd )
				m_pSoftMgrMainUI->m_pDlg->SetFocus();
		}
		OnBtnSearchBack();
	}
	else 
	{
		m_bShowType = TRUE;
		BOOL bFreeChecked = m_pMainDlg->GetItemCheck(IDC_SOFT_NECESS_SHOW_FREE_SOFT);
		BOOL bPlugChecked = m_pMainDlg->GetItemCheck(IDC_SOFT_NECESS_SHOW_NOPLUG_SOFT);

		ATLASSERT (m_pSoftMgrMainUI->m_pSoftMgr!=NULL);
		m_arrRightList.RemoveAll();

		//读取
		CSimpleArray<CSoftListItemData*> arrQuery;
		void *pos = m_pSoftMgrMainUI->m_pSoftMgr->SearchSoft(strSearch, L"ar");
		CAtlMap<CString,CString> soft;
		while(0 == m_pSoftMgrMainUI->m_pSoftMgr->GetNextSoft(pos, GetInfoUseMap,&soft))
		{	
			CString strTmp = soft[_T("softid")];
			CSoftListItemData*	pData = GetSoftDataByID(strTmp);
			BOOL bCanInsert = FALSE;
			if (pData)
			{
				if( bPlugChecked && bFreeChecked )
				{
					if ( !pData->m_bCharge && !pData->m_bPlug )
						bCanInsert = TRUE;
				}
				else if ( bPlugChecked && !bFreeChecked )
				{
					if ( !pData->m_bPlug )
						bCanInsert = TRUE;
				}
				else if ( !bPlugChecked && bFreeChecked )
				{
					if ( !pData->m_bCharge )
						bCanInsert = TRUE;
				}
				else
					bCanInsert = TRUE;

				if (bCanInsert)
					arrQuery.Add(pData);
			}
		}
		m_pSoftMgrMainUI->m_pSoftMgr->FinalizeGet(pos);

		//排序
		CAtlList<CSoftListItemData*> arrOrder;
		m_pSoftMgrMainUI->_SortArrayByOrder(arrQuery, arrOrder);

		//构造
		BOOL bQueryMark = FALSE;
		CSoftListItemData *pDataTemp = NULL;
		POSITION posTemp =  arrOrder.GetHeadPosition();
		while (posTemp)
		{
			pDataTemp = arrOrder.GetAt(posTemp);
			if (pDataTemp)
			{
				NECESS_SOFT_LIST_DATA	data;
				data.bTitle		= FALSE;
				data.strSoftId	= pDataTemp->m_strSoftID;
				m_arrRightList.Add(data);

				if (m_pSoftMgrMainUI->m_pInfoQuery)
				{
					// 获取分数
					if (pDataTemp->m_fMark==0 )
					{
						int nTmp = _wtoi( pDataTemp->m_strSoftID );
						m_pSoftMgrMainUI->m_pInfoQuery->AddSoft(nTmp);
						bQueryMark = TRUE;
					}
				}
			}

			arrOrder.GetNext(posTemp);
		}

		m_necessList->SetItemCount(m_arrRightList.GetSize());
		if (!m_strViewDetailSoftId.IsEmpty())
		{
			m_pSoftMgrMainUI->_QuerySoftMark(m_strViewDetailSoftId);
			m_strViewDetailSoftId.Empty();

			m_IEDetail.Show2(_T("about:blank"),NULL);
			m_pMainDlg->SetItemVisible(IDC_SOFT_NECESS_DIV_RIGHT_LIST_SHOW,TRUE);

			m_pMainDlg->SetItemVisible(IDC_SOFT_NECESS_DIV_RIGHT_DETAIL_SHOW,FALSE);
			m_pMainDlg->SetItemVisible(IDC_SOFT_NECESS_SHOW_FREE_SOFT,TRUE);
			m_pMainDlg->SetItemVisible(IDC_SOFT_NECESS_SHOW_NOPLUG_SOFT,TRUE);

			if ( ::GetFocus() != m_editQuery.m_hWnd )
				m_pSoftMgrMainUI->m_pDlg->SetFocus();
		}
		if (m_arrRightList.GetSize() > 0 )
		{
			m_pMainDlg->FormatRichText(
				IDC_SOFT_NECESS_BTN_SEARCH_TEXT, 
				BkString::Get(IDS_RESULT_QUERY_SOFTMGR), 
				strSearch, m_arrRightList.GetSize());

			m_pMainDlg->SetItemVisible(IDC_SOFT_NECESS_DIV_SEARCH_TIP,TRUE);
			m_pMainDlg->SetItemAttribute(IDC_SOFTMGR_SOFTLIST_NECESS, "pos", "0,24,-0,-0");

			m_pMainDlg->SetItemVisible(IDC_SOFT_NECESS_DIV_NO_FIND, FALSE);
			m_pMainDlg->SetItemVisible(IDC_SOFTMGR_SOFTLIST_NECESS, TRUE);
		}
		else
		{
			m_pMainDlg->FormatRichText(
				IDC_SOFT_NECESS_BTN_SEARCH_TEXT, 
				BkString::Get(IDS_NO_QUERY_SOFTMGR), 
				strSearch);
			m_pMainDlg->SetItemVisible(IDC_SOFT_NECESS_DIV_NO_FIND, TRUE);
			m_pMainDlg->SetItemVisible(IDC_SOFTMGR_SOFTLIST_NECESS, FALSE);
			m_pMainDlg->SetItemVisible(IDC_SOFT_NECESS_DIV_SEARCH_TIP,TRUE);

		}
		m_necessList->InvalidateRect(NULL,FALSE);

		if (bQueryMark)
		{
			m_pSoftMgrMainUI->m_pInfoQuery->Query();
		}

		m_strKeyWord = strSearch;
		m_pSoftMgrMainUI->m_pDlg->SetTimer( TIMER_ID_NECESS_KEYWORD, 5000, NULL );
		
	}
}
Esempio n. 10
0
INT_PTR CALLBACK
ServicesPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    UNREFERENCED_PARAMETER(lParam);
    UNREFERENCED_PARAMETER(wParam);

    switch (message)
    {
        case WM_INITDIALOG:
        {
            hServicesPage     = hDlg;
            hServicesListCtrl = GetDlgItem(hServicesPage, IDC_SERVICES_LIST);

            //
            // Correctly display message strings.
            //
            LPCWSTR szOSVendor = (bIsWindows ? IDS_MICROSOFT : IDS_REACTOS);

            size_t itemLength = 0;
            LPWSTR szItem = NULL, szNewItem = NULL;

            itemLength = GetWindowTextLength(GetDlgItem(hServicesPage, IDC_STATIC_SERVICES_WARNING)) + 1;
            szItem     = (LPWSTR)MemAlloc(0, itemLength * sizeof(WCHAR));
            GetDlgItemText(hServicesPage, IDC_STATIC_SERVICES_WARNING, szItem, (int)itemLength);
            szNewItem  = FormatString(szItem, szOSVendor);
            SetDlgItemText(hServicesPage, IDC_STATIC_SERVICES_WARNING, szNewItem);
            MemFree(szNewItem);
            MemFree(szItem);

            itemLength = GetWindowTextLength(GetDlgItem(hServicesPage, IDC_CBX_SERVICES_MASK_PROPRIETARY_SVCS)) + 1;
            szItem     = (LPWSTR)MemAlloc(0, itemLength * sizeof(WCHAR));
            GetDlgItemText(hServicesPage, IDC_CBX_SERVICES_MASK_PROPRIETARY_SVCS, szItem, (int)itemLength);
            szNewItem  = FormatString(szItem, szOSVendor);
            SetDlgItemText(hServicesPage, IDC_CBX_SERVICES_MASK_PROPRIETARY_SVCS, szNewItem);
            MemFree(szNewItem);
            MemFree(szItem);

            //
            // Initialize the styles.
            //
            DWORD dwStyle = ListView_GetExtendedListViewStyle(hServicesListCtrl);
            ListView_SetExtendedListViewStyle(hServicesListCtrl, dwStyle | LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES);
            SetWindowTheme(hServicesListCtrl, L"Explorer", NULL);

            //
            // Initialize the application page's controls.
            //
            LVCOLUMN column = {};

            // First column : Service's name.
            column.mask = LVCF_TEXT | LVCF_WIDTH;
            column.pszText = LoadResourceString(hInst, IDS_SERVICES_COLUMN_SERVICE);
            column.cx = 150;
            ListView_InsertColumn(hServicesListCtrl, 0, &column);
            MemFree(column.pszText);

            // Second column : Whether the service is required or not.
            column.mask = LVCF_TEXT | LVCF_WIDTH;
            column.pszText = LoadResourceString(hInst, IDS_SERVICES_COLUMN_REQ);
            column.cx = 60;
            ListView_InsertColumn(hServicesListCtrl, 1, &column);
            MemFree(column.pszText);

            // Third column : Service's vendor.
            column.mask = LVCF_TEXT | LVCF_WIDTH;
            column.pszText = LoadResourceString(hInst, IDS_SERVICES_COLUMN_VENDOR);
            column.cx = 150;
            ListView_InsertColumn(hServicesListCtrl, 2, &column);
            MemFree(column.pszText);

            // Fourth column : Service's status.
            column.mask = LVCF_TEXT | LVCF_WIDTH;
            column.pszText = LoadResourceString(hInst, IDS_SERVICES_COLUMN_STATUS);
            column.cx = 60;
            ListView_InsertColumn(hServicesListCtrl, 3, &column);
            MemFree(column.pszText);

            // Fifth column : Service's disabled date.
            column.mask = LVCF_TEXT | LVCF_WIDTH;
            column.pszText = LoadResourceString(hInst, IDS_SERVICES_COLUMN_DATEDISABLED);
            column.cx = 120;
            ListView_InsertColumn(hServicesListCtrl, 4, &column);
            MemFree(column.pszText);

            //
            // Populate and sort the list.
            //
            GetServices();
            ListView_Sort(hServicesListCtrl, 0);
            Update_Btn_States(hDlg);

            // Select the first item.
            ListView_SetItemState(hServicesListCtrl, 0, LVIS_SELECTED, LVIS_SELECTED);

            return TRUE;
        }

        case WM_DESTROY:
        {
            ClearServicesList();
            userModificationsList.RemoveAll();
            return 0;
        }

        case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
                case IDC_BTN_SERVICES_ACTIVATE:
                {
                    BOOL bAreThereModifs = FALSE;

                    int index = -1; // From the beginning.
                    while ((index = ListView_GetNextItem(hServicesListCtrl, index, LVNI_ALL)) != -1)
                    {
                        bAreThereModifs = ValidateItem(index, TRUE, FALSE) || bAreThereModifs; // The order is verrrrrry important !!!!
                    }

                    if (bAreThereModifs)
                    {
                        Update_Btn_States(hDlg);
                        PropSheet_Changed(GetParent(hServicesPage), hServicesPage);
                    }

                    return TRUE;
                }

                case IDC_BTN_SERVICES_DEACTIVATE:
                {
                    BOOL bAreThereModifs = FALSE;

                    int index = -1; // From the beginning.
                    while ((index = ListView_GetNextItem(hServicesListCtrl, index, LVNI_ALL)) != -1)
                    {
                        bAreThereModifs = ValidateItem(index, FALSE, FALSE) || bAreThereModifs; // The order is verrrrrry important !!!!
                    }

                    if (bAreThereModifs)
                    {
                        Update_Btn_States(hDlg);
                        PropSheet_Changed(GetParent(hServicesPage), hServicesPage);
                    }

                    return TRUE;
                }

                case IDC_CBX_SERVICES_MASK_PROPRIETARY_SVCS:
                {
                    bMaskProprietarySvcs = !bMaskProprietarySvcs;
                    GetServices(bMaskProprietarySvcs);
                    Update_Btn_States(hDlg);

                    return TRUE;
                }

                default:
                    return FALSE;
            }
            return FALSE;
        }

        case UM_CHECKSTATECHANGE:
        {
            BOOL bNewCheckState = !!((ListView_GetCheckState(hServicesListCtrl, int(lParam)) + 1) % 2);

            if (ValidateItem(/*reinterpret_cast<int>*/ int(lParam), bNewCheckState, !HideEssentialServiceWarning()))
            {
                Update_Btn_States(hDlg);
                PropSheet_Changed(GetParent(hServicesPage), hServicesPage);
            }

            return TRUE;
        }

        case WM_NOTIFY:
        {
            if (reinterpret_cast<LPNMHDR>(lParam)->hwndFrom == hServicesListCtrl)
            {
                switch (reinterpret_cast<LPNMHDR>(lParam)->code)
                {
                    case NM_CLICK:
                    case NM_RCLICK:
                    {
                        DWORD         dwpos = GetMessagePos();
                        LVHITTESTINFO ht    = {};
                        ht.pt.x = GET_X_LPARAM(dwpos);
                        ht.pt.y = GET_Y_LPARAM(dwpos);
                        MapWindowPoints(HWND_DESKTOP /*NULL*/, hServicesListCtrl, &ht.pt, 1);

                        /*
                         * We use ListView_SubItemHitTest(...) and not ListView_HitTest(...)
                         * because ListView_HitTest(...) returns bad flags when one clicks
                         * on a sub-item different from 0. The flags then contain LVHT_ONITEMSTATEICON
                         * which must not be obviously present in this case.
                         */
                        ListView_SubItemHitTest(hServicesListCtrl, &ht);

                        if (LVHT_ONITEMSTATEICON & ht.flags)
                        {
                            PostMessage(hDlg, UM_CHECKSTATECHANGE, 0, (LPARAM)ht.iItem);

                            // Disable default behaviour. Needed for the UM_CHECKSTATECHANGE
                            // custom notification to work as expected.
                            SetWindowLongPtr(hDlg, DWLP_MSGRESULT, TRUE);
                        }

                        return TRUE;
                    }

                    case NM_DBLCLK:
                    case NM_RDBLCLK:
                    {
                        // We deactivate double-clicks.
                        SetWindowLongPtr(hDlg, DWLP_MSGRESULT, TRUE);
                        return TRUE;
                    }

                    case LVN_KEYDOWN:
                    {
                        if (reinterpret_cast<LPNMLVKEYDOWN>(lParam)->wVKey == VK_SPACE)
                        {
                            int iItem = ListView_GetSelectionMark(hServicesListCtrl);
                            PostMessage(hDlg, UM_CHECKSTATECHANGE, 0, (LPARAM)iItem);

                            // Disable default behaviour. Needed for the UM_CHECKSTATECHANGE
                            // custom notification to work as expected.
                            SetWindowLongPtr(hDlg, DWLP_MSGRESULT, TRUE);
                        }

                        return TRUE;
                    }

                    case LVN_COLUMNCLICK:
                    {
                        int iSortingColumn = reinterpret_cast<LPNMLISTVIEW>(lParam)->iSubItem;

                        ListView_SortEx(hServicesListCtrl, iSortingColumn, iSortedColumn);
                        iSortedColumn = iSortingColumn;

                        return TRUE;
                    }
                }
            }
            else
            {
                switch (reinterpret_cast<LPNMHDR>(lParam)->code)
                {
                    case PSN_APPLY:
                    {
                        // Try to apply the modifications to the system.
                        MessageBox(NULL, _T("In Services page: PSN_APPLY"), _T("Info"), MB_ICONINFORMATION);

                        /*
                        //
                        // Move this away...
                        //
                        int iRetVal = MessageBox(NULL, _T("Would you really want to modify the configuration of your system ?"), _T("Warning"), MB_ICONWARNING | MB_YESNOCANCEL);

                        if (iRetVal == IDYES /\* modifications are OK *\/)
                            SetWindowLongPtr(hServicesPage, DWLP_MSGRESULT, PSNRET_NOERROR);
                        else if (iRetVal == IDNO /\* modifications are not OK *\/)
                            SetWindowLongPtr(hServicesPage, DWLP_MSGRESULT, PSNRET_NOERROR);
                        else // if (iRetVal == IDCANCEL) // There was an error...
                            SetWindowLongPtr(hServicesPage, DWLP_MSGRESULT, PSNRET_INVALID);
                        */

                        //
                        // We modify the services which are stored in the user modification list.
                        //

                        // 1- Open the Service Control Manager for modifications.
                        SC_HANDLE hSCManager = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
                        if (hSCManager != NULL)
                        {
                            LPCWSTR svcName;

                            for (POSITION it = userModificationsList.GetHeadPosition(); it; userModificationsList.GetNext(it))
                            {
                                svcName = userModificationsList.GetAt(it);

                                // 2- Retrieve a handle to the service.
                                SC_HANDLE hService = OpenServiceW(hSCManager, svcName, SERVICE_QUERY_CONFIG | SERVICE_CHANGE_CONFIG);
                                if (hService == NULL)
                                {
                                    // TODO : Show a message box.
                                    continue;
                                }

                                DWORD dwBytesNeeded = 0;
                                QueryServiceConfigW(hService, NULL, 0, &dwBytesNeeded);
                                // if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)

                                LPQUERY_SERVICE_CONFIG lpServiceConfig = (LPQUERY_SERVICE_CONFIG)MemAlloc(0, dwBytesNeeded);
                                if (!lpServiceConfig)
                                {
                                    CloseServiceHandle(hService);
                                    continue; // TODO ? Show a message box...
                                }
                                QueryServiceConfigW(hService, lpServiceConfig, dwBytesNeeded, &dwBytesNeeded);

                                if (lpServiceConfig->dwStartType == SERVICE_DISABLED) // We have a disabled service which is becoming to be enabled.
                                {
                                    // 3a- Retrive the properties of the disabled service from the registry.
                                    RegistryDisabledServiceItemParams params = {};

                                    QUERY_REGISTRY_KEYS_TABLE KeysQueryTable[2] = {};
                                    KeysQueryTable[0].QueryRoutine = GetRegistryKeyedDisabledServicesQueryRoutine;
                                    KeysQueryTable[0].EntryContext = &params;
                                    RegQueryRegistryKeys(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\services", KeysQueryTable, (PVOID)svcName);

                                    if (bIsWindows && bIsPreVistaOSVersion && !params.bIsPresent)
                                    {
                                        QUERY_REGISTRY_VALUES_TABLE ValuesQueryTable[2] = {};
                                        ValuesQueryTable[0].QueryRoutine = GetRegistryValuedDisabledServicesQueryRoutine;
                                        ValuesQueryTable[0].EntryContext = &params;
                                        RegQueryRegistryValues(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\services", ValuesQueryTable, (PVOID)svcName);
                                    }

                                    if (params.bIsPresent)
                                    {
                                        // 4a- Modify the service.
                                        ChangeServiceConfigW(hService, SERVICE_NO_CHANGE, params.dwStartType, SERVICE_NO_CHANGE, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

                                        // 5a- Remove the registry entry of the service.
                                        if (params.bIsKeyed)
                                        {
                                            CAtlStringW serviceRegKey(L"SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\services\\");
                                            serviceRegKey += svcName;
                                            RegDeleteKeyW(HKEY_LOCAL_MACHINE, serviceRegKey);

                                            /***** HACK for Windows < Vista (e.g. 2000, Xp, 2003...) *****/
                                            //
                                            // Delete also the valued-entry of the service.
                                            //
                                            if (bIsWindows && bIsPreVistaOSVersion)
                                            {
                                                HKEY hSubKey = NULL;
                                                if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\services", 0, KEY_SET_VALUE /*KEY_READ*/, &hSubKey) == ERROR_SUCCESS)
                                                {
                                                    RegDeleteValue(hSubKey, svcName);
                                                    RegCloseKey(hSubKey);
                                                }
                                            }
                                            /*************************************************************/
                                        }
                                        else
                                        {
                                            HKEY hSubKey = NULL;
                                            if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\services", 0, KEY_SET_VALUE /*KEY_READ*/, &hSubKey) == ERROR_SUCCESS)
                                            {
                                                RegDeleteValue(hSubKey, svcName);
                                                RegCloseKey(hSubKey);
                                            }
                                        }

                                        ////////// HACKHACKHACKHACKHACKHACKHACKHACKHACKHACKHACK ///////////
                                        // userModificationsList.RemoveAt(it);
                                    }
                                    else
                                    {
                                        // Ohoh !! We have a very big problem.
                                        MessageBox(NULL, _T("WTF ??"), _T("FATAL ERROR !!!!"), MB_ICONERROR);
                                    }
                                }
                                else // We have an enabled service which is becoming to be disabled.
                                {
                                    // 3b- Retrieve the local time of disabling.
                                    SYSTEMTIME disableDate = {};
                                    GetLocalTime(&disableDate);

                                    // 4b- Modify the service.
                                    ChangeServiceConfigW(hService, SERVICE_NO_CHANGE, SERVICE_DISABLED, SERVICE_NO_CHANGE, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

                                    // 5b- Register the service into the registry.
                                    CAtlStringW serviceRegKey(L"SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\services\\");
                                    serviceRegKey += svcName;
                                    HKEY hSubKey = NULL;
                                    if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, serviceRegKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hSubKey, NULL) == ERROR_SUCCESS)
                                    {
                                        RegSetDWORDValue(hSubKey, NULL, svcName, FALSE, lpServiceConfig->dwStartType);

                                    #if 1 // DisableDate
                                        RegSetDWORDValue(hSubKey, NULL, L"DAY"   , FALSE, disableDate.wDay   );
                                        RegSetDWORDValue(hSubKey, NULL, L"HOUR"  , FALSE, disableDate.wHour  );
                                        RegSetDWORDValue(hSubKey, NULL, L"MINUTE", FALSE, disableDate.wMinute);
                                        RegSetDWORDValue(hSubKey, NULL, L"MONTH" , FALSE, disableDate.wMonth );
                                        RegSetDWORDValue(hSubKey, NULL, L"SECOND", FALSE, disableDate.wSecond);
                                        RegSetDWORDValue(hSubKey, NULL, L"YEAR"  , FALSE, disableDate.wYear  );
                                    #endif

                                        RegCloseKey(hSubKey);
                                    }

                                    /***** HACK for Windows < Vista (e.g. 2000, Xp, 2003...) *****/
                                    //
                                    // Save also a valued-entry for the service.
                                    //
                                    if (bIsWindows && bIsPreVistaOSVersion)
                                    {
                                        RegSetDWORDValue(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\services", svcName, TRUE, lpServiceConfig->dwStartType);
                                    }
                                    /*************************************************************/

                                    ////////// HACKHACKHACKHACKHACKHACKHACKHACKHACKHACKHACK ///////////
                                    // userModificationsList.RemoveAt(it);
                                }

                                MemFree(lpServiceConfig);
                                CloseServiceHandle(hService);
                            }

                            //////////// HACK HACK !!!! ////////////
                            userModificationsList.RemoveAll();
                            ////////////////////////////////////////

                            CloseServiceHandle(hSCManager);


                            //// PropSheet_UnChanged(GetParent(hServicesPage), hServicesPage); ////
                            PropSheet_CancelToClose(GetParent(hDlg));

                            /* Modifications are OK */
                            SetWindowLongPtr(hServicesPage, DWLP_MSGRESULT, PSNRET_NOERROR);
                        }
                        else
                        {
                            MessageBox(hDlg, _T("Impossible to open the SC manager..."), _T("Error"), MB_ICONERROR);

                            // There was an error...
                            SetWindowLongPtr(hServicesPage, DWLP_MSGRESULT, PSNRET_INVALID);
                        }

                        GetServices(bMaskProprietarySvcs);
                        Update_Btn_States(hDlg);

                        return TRUE;
                    }

                    case PSN_HELP:
                    {
                        MessageBox(hServicesPage, _T("Help not implemented yet!"), _T("Help"), MB_ICONINFORMATION | MB_OK);
                        return TRUE;
                    }

                    case PSN_KILLACTIVE: // Is going to lose activation.
                    {
                        // Changes are always valid of course.
                        SetWindowLongPtr(hServicesPage, DWLP_MSGRESULT, FALSE);
                        return TRUE;
                    }

                    case PSN_QUERYCANCEL:
                    {
                        // RefreshStartupList();

                        // Allows cancellation.
                        SetWindowLongPtr(hServicesPage, DWLP_MSGRESULT, FALSE);

                        return TRUE;
                    }

                    case PSN_QUERYINITIALFOCUS:
                    {
                        // Give the focus on and select the first item.
                        ListView_SetItemState(hServicesListCtrl, 0, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);

                        SetWindowLongPtr(hServicesPage, DWLP_MSGRESULT, (LONG_PTR)hServicesListCtrl);
                        return TRUE;
                    }

                    //
                    // DO NOT TOUCH THESE NEXT MESSAGES, THEY ARE OK LIKE THIS...
                    //
                    case PSN_RESET: // Perform final cleaning, called before WM_DESTROY.
                        return TRUE;

                    case PSN_SETACTIVE: // Is going to gain activation.
                    {
                        SetWindowLongPtr(hServicesPage, DWLP_MSGRESULT, 0);
                        return TRUE;
                    }

                    default:
                        break;
                }
            }
        }

        default:
            return FALSE;
    }

    return FALSE;
}