void File::ParseTypes(InputStream& s, CAtlList<CStringW>& types) { types.RemoveAll(); CStringW str; for(int c = s.SkipWhiteSpace(); iswcsym(c) || c == '.' || c == '@'; c = s.PeekChar()) { c = s.GetChar(); if(c == '.') { if(str.IsEmpty()) s.ThrowError(_T("'type' cannot be an empty string")); if(!iswcsym(s.PeekChar())) s.ThrowError(_T("unexpected dot after type '%s'"), CString(str)); types.AddTail(str); str.Empty(); } else { if(str.IsEmpty() && iswdigit(c)) s.ThrowError(_T("'type' cannot start with a number")); if((!str.IsEmpty() || !types.IsEmpty()) && c == '@') s.ThrowError(_T("unexpected @ in 'type'")); str += (WCHAR)c; } } if(!str.IsEmpty()) { types.AddTail(str); } }
bool CFileAssoc::GetAssociatedExtensionsFromRegistry(CAtlList<CString>& exts) const { exts.RemoveAll(); CRegKey rkHKCR(HKEY_CLASSES_ROOT); LONG ret; DWORD i = 0; CString keyName, ext; DWORD len = MAX_PATH; while ((ret = rkHKCR.EnumKey(i, keyName.GetBuffer(len), &len)) != ERROR_NO_MORE_ITEMS) { if (ret == ERROR_SUCCESS) { keyName.ReleaseBuffer(len); if (keyName.Find(PROGID) == 0) { ext = keyName.Mid(_countof(PROGID) - 1); if (IsRegistered(ext)) { exts.AddTail(ext); } } i++; len = MAX_PATH; } } return !exts.IsEmpty(); }
static bool SearchFiles(CString mask, CAtlList<CString>& sl) { if (mask.Find(_T("://")) >= 0) { return false; } mask.Trim(); sl.RemoveAll(); CMediaFormats& mf = AfxGetAppSettings().m_Formats; WIN32_FILE_ATTRIBUTE_DATA fad; bool fFilterKnownExts = (GetFileAttributesEx(mask, GetFileExInfoStandard, &fad) && (fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)); if (fFilterKnownExts) { mask = CString(mask).TrimRight(_T("\\/")) + _T("\\*.*"); } { CString dir = mask.Left(max(mask.ReverseFind('\\'), mask.ReverseFind('/')) + 1); WIN32_FIND_DATA fd; HANDLE h = FindFirstFile(mask, &fd); if (h != INVALID_HANDLE_VALUE) { do { if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { continue; } CString fn = fd.cFileName; //CString ext = fn.Mid(fn.ReverseFind('.')+1).MakeLower(); CString ext = fn.Mid(fn.ReverseFind('.')).MakeLower(); CString path = dir + fd.cFileName; if (!fFilterKnownExts || mf.FindExt(ext)) { for (size_t i = 0; i < mf.GetCount(); i++) { CMediaFormatCategory& mfc = mf.GetAt(i); /* playlist files are skipped when playing the contents of an entire directory */ if ((mfc.FindExt(ext)) && (mf[i].GetLabel().CompareNoCase(_T("pls")) != 0)) { sl.AddTail(path); break; } } } } while (FindNextFile(h, &fd)); FindClose(h); if (sl.GetCount() == 0 && mask.Find(_T(":\\")) == 1) { GetCDROMType(mask[0], sl); } } } return (sl.GetCount() > 1 || sl.GetCount() == 1 && sl.GetHead().CompareNoCase(mask) || sl.GetCount() == 0 && mask.FindOneOf(_T("?*")) >= 0); }
HRESULT CHdmvClipInfo::FindMainMovie(LPCTSTR strFolder, CString& strPlaylistFile, CAtlList<PlaylistItem>& MainPlaylist) { HRESULT hr = E_FAIL; CString strPath (strFolder); CString strFilter; CAtlList<PlaylistItem> Playlist; WIN32_FIND_DATA fd = {0}; strPath.Replace(_T("\\PLAYLIST\\"), _T("\\")); //strPath.Replace(_T("\\BDMV\\"), _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 && rtCurrent > rtMax) { rtMax = rtCurrent; strPlaylistFile = strCurrentPlaylist; MainPlaylist.RemoveAll(); POSITION pos = Playlist.GetHeadPosition(); while(pos) { MainPlaylist.AddTail(Playlist.GetNext(pos)); } hr = S_OK; } } while(FindNextFile(hFind, &fd)); FindClose(hFind); } return hr; }
void SubtitleFile::SegmentList::Lookup(float at, CAtlList<SegmentItem>& sis) { sis.RemoveAll(); size_t k; if(Lookup(at, k)) { sis.AddTailList(GetSegment(k)); } }
void NodeFactory::GetNewDefs(CAtlList<Definition*>& defs) { defs.RemoveAll(); POSITION pos = m_newnodes.GetHeadPosition(); while(pos) { if(Definition* pDef = GetDefByName(m_newnodes.GetNext(pos))) { defs.AddTail(pDef); } } }
void CPhPhoneLineProgressInfo::GetExtraHeaders(CAtlList<CHeaderDataPtr>& listHeaderInfo) const { struct phCustomHeaderInfo *custom_header; listHeaderInfo.RemoveAll(); for (custom_header = m_pRegStateInfo->custom_headers; custom_header != NULL; custom_header = custom_header->next) { if ((custom_header->name) && (custom_header->value)) { CHeaderDataPtr pHeaderInfo = new CHeaderData(custom_header->name, custom_header->value); listHeaderInfo.AddTail(pHeaderInfo); } } }
size_t Misc::SplitString(const CString & str, LPCTSTR tokens, CAtlList<CString> & list) { list.RemoveAll(); CAtlString token; int curPos = 0; token = str.Tokenize(tokens, curPos); while (-1 != curPos) { if (!token.IsEmpty()) { list.AddTail(token); } token = str.Tokenize(tokens, curPos); } return list.GetCount(); }
bool CFileAssoc::GetAssociatedExtensions(const CMediaFormats& mf, CAtlList<CString>& exts) { exts.RemoveAll(); CAtlList<CString> mfcExts; for (size_t i = 0, cnt = mf.GetCount(); i < cnt; i++) { ExplodeMin(mf[i].GetExtsWithPeriod(), mfcExts, _T(' ')); POSITION pos = mfcExts.GetHeadPosition(); while (pos) { const CString ext = mfcExts.GetNext(pos); if (CFileAssoc::IsRegistered(ext)) { exts.AddTail(ext); } } } return !exts.IsEmpty(); }
HRESULT CReportFileDB::GetUnReportList( CAtlList<CReportFile>& rfArray ) { HRESULT hr = S_OK; CComPtr<Skylark::ISQLiteComResultSet3> piRtm; CReportFile rfile; if ( NULL == m_piSlDB ) { hr = E_NOINTERFACE; goto Exit0; } hr = m_piSlDB->ExecuteQuery( REPORT_FILE_LOAD_REPORTLIST, &piRtm ); if ( FAILED( hr ) ) { goto Exit0; } rfArray.RemoveAll(); while( !piRtm->IsEof() ) { rfile.m_strFilePath = piRtm->GetAsString( 0 ); rfile.m_nFileSize = piRtm->GetInt( 1 ); rfile.m_nReportState = piRtm->GetInt( 2 ); rfile.m_nTrack = piRtm->GetInt( 3 ); rfile.SetCreateTime( piRtm->GetInt64( 4 ) ); rfile.SetCommitTime( piRtm->GetInt64( 5 ) ); rfile.SetReportTime( piRtm->GetInt64( 6 ) ); rfile.m_nRescanState = piRtm->GetInt( 7 ); rfArray.AddTail( rfile ); piRtm->NextRow(); } Exit0: return hr; }
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; }
void CMediaTypeEx::Dump(CAtlList<CString>& sl) { CString str; sl.RemoveAll(); int fmtsize = 0; CString major = CStringFromGUID(majortype); CString sub = CStringFromGUID(subtype); CString format = CStringFromGUID(formattype); sl.AddTail(ToString() + _T("\n")); sl.AddTail(_T("AM_MEDIA_TYPE: ")); str.Format(_T("majortype: %s %s"), CString(GuidNames[majortype]), major); sl.AddTail(str); str.Format(_T("subtype: %s %s"), CString(GuidNames[subtype]), sub); sl.AddTail(str); str.Format(_T("formattype: %s %s"), CString(GuidNames[formattype]), format); sl.AddTail(str); str.Format(_T("bFixedSizeSamples: %d"), bFixedSizeSamples); sl.AddTail(str); str.Format(_T("bTemporalCompression: %d"), bTemporalCompression); sl.AddTail(str); str.Format(_T("lSampleSize: %d"), lSampleSize); sl.AddTail(str); str.Format(_T("cbFormat: %d"), cbFormat); sl.AddTail(str); sl.AddTail(_T("")); if (formattype == FORMAT_VideoInfo || formattype == FORMAT_VideoInfo2 || formattype == FORMAT_MPEGVideo || formattype == FORMAT_MPEG2_VIDEO) { fmtsize = formattype == FORMAT_VideoInfo ? sizeof(VIDEOINFOHEADER) : formattype == FORMAT_VideoInfo2 ? sizeof(VIDEOINFOHEADER2) : formattype == FORMAT_MPEGVideo ? sizeof(MPEG1VIDEOINFO)-1 : formattype == FORMAT_MPEG2_VIDEO ? sizeof(MPEG2VIDEOINFO)-4 : 0; VIDEOINFOHEADER& vih = *(VIDEOINFOHEADER*)pbFormat; BITMAPINFOHEADER* bih = &vih.bmiHeader; sl.AddTail(_T("VIDEOINFOHEADER:")); str.Format(_T("rcSource: (%d,%d)-(%d,%d)"), vih.rcSource.left, vih.rcSource.top, vih.rcSource.right, vih.rcSource.bottom); sl.AddTail(str); str.Format(_T("rcTarget: (%d,%d)-(%d,%d)"), vih.rcTarget.left, vih.rcTarget.top, vih.rcTarget.right, vih.rcTarget.bottom); sl.AddTail(str); str.Format(_T("dwBitRate: %d"), vih.dwBitRate); sl.AddTail(str); str.Format(_T("dwBitErrorRate: %d"), vih.dwBitErrorRate); sl.AddTail(str); str.Format(_T("AvgTimePerFrame: %I64d"), vih.AvgTimePerFrame); sl.AddTail(str); sl.AddTail(_T("")); if (formattype == FORMAT_VideoInfo2 || formattype == FORMAT_MPEG2_VIDEO) { VIDEOINFOHEADER2& vih = *(VIDEOINFOHEADER2*)pbFormat; bih = &vih.bmiHeader; sl.AddTail(_T("VIDEOINFOHEADER2:")); str.Format(_T("dwInterlaceFlags: 0x%08x"), vih.dwInterlaceFlags); sl.AddTail(str); str.Format(_T("dwCopyProtectFlags: 0x%08x"), vih.dwCopyProtectFlags); sl.AddTail(str); str.Format(_T("dwPictAspectRatioX: %d"), vih.dwPictAspectRatioX); sl.AddTail(str); str.Format(_T("dwPictAspectRatioY: %d"), vih.dwPictAspectRatioY); sl.AddTail(str); str.Format(_T("dwControlFlags: 0x%08x"), vih.dwControlFlags); sl.AddTail(str); str.Format(_T("dwReserved2: 0x%08x"), vih.dwReserved2); sl.AddTail(str); sl.AddTail(_T("")); } if (formattype == FORMAT_MPEGVideo) { MPEG1VIDEOINFO& mvih = *(MPEG1VIDEOINFO*)pbFormat; sl.AddTail(_T("MPEG1VIDEOINFO:")); str.Format(_T("dwStartTimeCode: %d"), mvih.dwStartTimeCode); sl.AddTail(str); str.Format(_T("cbSequenceHeader: %d"), mvih.cbSequenceHeader); sl.AddTail(str); sl.AddTail(_T("")); } else if (formattype == FORMAT_MPEG2_VIDEO) { MPEG2VIDEOINFO& mvih = *(MPEG2VIDEOINFO*)pbFormat; sl.AddTail(_T("MPEG2VIDEOINFO:")); str.Format(_T("dwStartTimeCode: %d"), mvih.dwStartTimeCode); sl.AddTail(str); str.Format(_T("cbSequenceHeader: %d"), mvih.cbSequenceHeader); sl.AddTail(str); str.Format(_T("dwProfile: 0x%08x"), mvih.dwProfile); sl.AddTail(str); str.Format(_T("dwLevel: 0x%08x"), mvih.dwLevel); sl.AddTail(str); str.Format(_T("dwFlags: 0x%08x"), mvih.dwFlags); sl.AddTail(str); sl.AddTail(_T("")); } sl.AddTail(_T("BITMAPINFOHEADER:")); str.Format(_T("biSize: %d"), bih->biSize); sl.AddTail(str); str.Format(_T("biWidth: %d"), bih->biWidth); sl.AddTail(str); str.Format(_T("biHeight: %d"), bih->biHeight); sl.AddTail(str); str.Format(_T("biPlanes: %d"), bih->biPlanes); sl.AddTail(str); str.Format(_T("biBitCount: %d"), bih->biBitCount); sl.AddTail(str); if (bih->biCompression < 256) { str.Format(_T("biCompression: %d"), bih->biCompression); } else { str.Format(_T("biCompression: %4.4hs"), &bih->biCompression); } sl.AddTail(str); str.Format(_T("biSizeImage: %d"), bih->biSizeImage); sl.AddTail(str); str.Format(_T("biXPelsPerMeter: %d"), bih->biXPelsPerMeter); sl.AddTail(str); str.Format(_T("biYPelsPerMeter: %d"), bih->biYPelsPerMeter); sl.AddTail(str); str.Format(_T("biClrUsed: %d"), bih->biClrUsed); sl.AddTail(str); str.Format(_T("biClrImportant: %d"), bih->biClrImportant); sl.AddTail(str); sl.AddTail(_T("")); } else if (formattype == FORMAT_WaveFormatEx || formattype == FORMAT_WaveFormatExFFMPEG) { WAVEFORMATEX *pWfe = NULL; if (formattype == FORMAT_WaveFormatExFFMPEG) { fmtsize = sizeof(WAVEFORMATEXFFMPEG); WAVEFORMATEXFFMPEG *wfeff = (WAVEFORMATEXFFMPEG*)pbFormat; pWfe = &wfeff->wfex; sl.AddTail(_T("WAVEFORMATEXFFMPEG:")); str.Format(_T("nCodecId: 0x%04x"), wfeff->nCodecId); sl.AddTail(str); sl.AddTail(_T("")); } else { fmtsize = sizeof(WAVEFORMATEX); pWfe = (WAVEFORMATEX*)pbFormat; } WAVEFORMATEX& wfe = *pWfe; sl.AddTail(_T("WAVEFORMATEX:")); str.Format(_T("wFormatTag: 0x%04x"), wfe.wFormatTag); sl.AddTail(str); str.Format(_T("nChannels: %d"), wfe.nChannels); sl.AddTail(str); str.Format(_T("nSamplesPerSec: %d"), wfe.nSamplesPerSec); sl.AddTail(str); str.Format(_T("nAvgBytesPerSec: %d"), wfe.nAvgBytesPerSec); sl.AddTail(str); str.Format(_T("nBlockAlign: %d"), wfe.nBlockAlign); sl.AddTail(str); str.Format(_T("wBitsPerSample: %d"), wfe.wBitsPerSample); sl.AddTail(str); str.Format(_T("cbSize: %d (extra bytes)"), wfe.cbSize); sl.AddTail(str); sl.AddTail(_T("")); if (wfe.wFormatTag != WAVE_FORMAT_PCM && wfe.cbSize > 0 && formattype == FORMAT_WaveFormatEx) { if (wfe.wFormatTag == WAVE_FORMAT_EXTENSIBLE && wfe.cbSize == sizeof(WAVEFORMATEXTENSIBLE)-sizeof(WAVEFORMATEX)) { fmtsize = sizeof(WAVEFORMATEXTENSIBLE); WAVEFORMATEXTENSIBLE& wfe = *(WAVEFORMATEXTENSIBLE*)pbFormat; sl.AddTail(_T("WAVEFORMATEXTENSIBLE:")); if (wfe.Format.wBitsPerSample != 0) { str.Format(_T("wValidBitsPerSample: %d"), wfe.Samples.wValidBitsPerSample); } else { str.Format(_T("wSamplesPerBlock: %d"), wfe.Samples.wSamplesPerBlock); } sl.AddTail(str); str.Format(_T("dwChannelMask: 0x%08x"), wfe.dwChannelMask); sl.AddTail(str); str.Format(_T("SubFormat: %s"), CStringFromGUID(wfe.SubFormat)); sl.AddTail(str); sl.AddTail(_T("")); } else if (wfe.wFormatTag == WAVE_FORMAT_DOLBY_AC3 && wfe.cbSize == sizeof(DOLBYAC3WAVEFORMAT)-sizeof(WAVEFORMATEX)) { fmtsize = sizeof(DOLBYAC3WAVEFORMAT); DOLBYAC3WAVEFORMAT& wfe = *(DOLBYAC3WAVEFORMAT*)pbFormat; sl.AddTail(_T("DOLBYAC3WAVEFORMAT:")); str.Format(_T("bBigEndian: %d"), wfe.bBigEndian); sl.AddTail(str); str.Format(_T("bsid: %d"), wfe.bsid); sl.AddTail(str); str.Format(_T("lfeon: %d"), wfe.lfeon); sl.AddTail(str); str.Format(_T("copyrightb: %d"), wfe.copyrightb); sl.AddTail(str); str.Format(_T("nAuxBitsCode: %d"), wfe.nAuxBitsCode); sl.AddTail(str); sl.AddTail(_T("")); } } } else if (formattype == FORMAT_VorbisFormat) { fmtsize = sizeof(VORBISFORMAT); VORBISFORMAT& vf = *(VORBISFORMAT*)pbFormat; sl.AddTail(_T("VORBISFORMAT:")); str.Format(_T("nChannels: %d"), vf.nChannels); sl.AddTail(str); str.Format(_T("nSamplesPerSec: %d"), vf.nSamplesPerSec); sl.AddTail(str); str.Format(_T("nMinBitsPerSec: %d"), vf.nMinBitsPerSec); sl.AddTail(str); str.Format(_T("nAvgBitsPerSec: %d"), vf.nAvgBitsPerSec); sl.AddTail(str); str.Format(_T("nMaxBitsPerSec: %d"), vf.nMaxBitsPerSec); sl.AddTail(str); str.Format(_T("fQuality: %.3f"), vf.fQuality); sl.AddTail(str); sl.AddTail(_T("")); } else if (formattype == FORMAT_VorbisFormat2) { fmtsize = sizeof(VORBISFORMAT2); VORBISFORMAT2& vf = *(VORBISFORMAT2*)pbFormat; sl.AddTail(_T("VORBISFORMAT:")); str.Format(_T("Channels: %d"), vf.Channels); sl.AddTail(str); str.Format(_T("SamplesPerSec: %d"), vf.SamplesPerSec); sl.AddTail(str); str.Format(_T("BitsPerSample: %d"), vf.BitsPerSample); sl.AddTail(str); str.Format(_T("HeaderSize: {%d, %d, %d}"), vf.HeaderSize[0], vf.HeaderSize[1], vf.HeaderSize[2]); sl.AddTail(str); sl.AddTail(_T("")); } else if (formattype == FORMAT_SubtitleInfo) { fmtsize = sizeof(SUBTITLEINFO); SUBTITLEINFO& si = *(SUBTITLEINFO*)pbFormat; sl.AddTail(_T("SUBTITLEINFO:")); str.Format(_T("dwOffset: %d"), si.dwOffset); sl.AddTail(str); str.Format(_T("IsoLang: %s"), CString(CStringA(si.IsoLang, sizeof(si.IsoLang)-1))); sl.AddTail(str); str.Format(_T("TrackName: %s"), CString(CStringW(si.TrackName, sizeof(si.TrackName)-1))); sl.AddTail(str); sl.AddTail(_T("")); } if (cbFormat > 0) { sl.AddTail(_T("pbFormat:")); for (ptrdiff_t i = 0, j = (cbFormat + 15) & ~15; i < j; i += 16) { str.Format(_T("%04x:"), i); for (ptrdiff_t k = i, l = min(i + 16, (int)cbFormat); k < l; k++) { CString byte; byte.Format(_T("%c%02x"), fmtsize > 0 && fmtsize == k ? '|' : ' ', pbFormat[k]); str += byte; } for (ptrdiff_t k = min(i + 16, (int)cbFormat), l = i + 16; k < l; k++) { str += _T(" "); } str += ' '; for (ptrdiff_t k = i, l = min(i + 16, (int)cbFormat); k < l; k++) { unsigned char c = (unsigned char)pbFormat[k]; CStringA ch; ch.Format("%c", c >= 0x20 ? c : '.'); str += ch; } sl.AddTail(str); } sl.AddTail(_T("")); } }
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 = ¶ms; 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 = ¶ms; 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; }