// ************************************************************* // SaveStyle() // ************************************************************* bool OgrStyleHelper::SaveStyle(GDALDataset* dataset, CStringW xml, CStringW layerName, CStringW styleName) { xml.Replace(L"\n", L""); xml.Replace(L"'", L"''''"); if (xml.GetLength() == 0) return false; CStringW sql; sql.Format(L"INSERT INTO %s(layername, stylename, style) VALUES ('%s', '%s', '%s')", GetStyleTableName(layerName), layerName, styleName, xml); CPLErrorReset(); OGRLayer* layer = dataset->ExecuteSQL(OgrHelper::String2OgrString(sql), NULL, NULL); return CPLGetLastErrorNo() == OGRERR_NONE; }
void CPlayerPlaylistBar::Append(CStringW vdn, CStringW adn, int vinput, int vchannel, int ainput) { CPlaylistItem pli; pli.m_type = CPlaylistItem::device; pli.m_fns.AddTail(CString(vdn)); pli.m_fns.AddTail(CString(adn)); pli.m_vinput = vinput; pli.m_vchannel = vchannel; pli.m_ainput = ainput; CAtlList<CStringW> sl; CStringW vfn = GetFriendlyName(vdn); CStringW afn = GetFriendlyName(adn); if (!vfn.IsEmpty()) { sl.AddTail(vfn); } if (!afn.IsEmpty()) { sl.AddTail(afn); } CStringW label = Implode(sl, '|'); label.Replace(L"|", L" - "); pli.m_label = CString(label); m_pl.AddTail(pli); Refresh(); SavePlaylist(); }
CStringW CHistoryManager::Redirect(CStringW strFileName) { bool bRedirect = false; CStringW strRedirect; strFileName.Replace(L'/', L'\\'); bool bLeadSlash = false; if (strFileName.GetLength() >= 4 && _wcsnicmp(strFileName, L"\\\\?\\", 4) == 0) bLeadSlash = true; std::vector<std::wstring> vecParts; std::wstring strPath = strFileName; transform(strPath.begin(), strPath.end(), strPath.begin(), tolower); SplitPath(strPath, vecParts); for (int i = 0; i < TEMP_KEY_COUNT; i++) { int nPartCount = g_TempPaths[i].vecShortParts.size(); if (nPartCount == 0 || (int)vecParts.size() < nPartCount) continue; bool bSame = true; for (int j = 0; j < nPartCount; j++) { if (g_TempPaths[i].vecShortParts[j] != vecParts[j] && g_TempPaths[i].vecLongParts[j] != vecParts[j]) { bSame = false; break; } } if (bSame) { bRedirect = true; if (bLeadSlash) strRedirect = L"\\\\?\\"; strRedirect += m_strRedirectPath; strRedirect += g_TempPaths[i].strRegKey.c_str(); for (std::vector<std::wstring>::size_type j = nPartCount; j < vecParts.size(); j++) // gao { strRedirect += L"\\"; strRedirect += vecParts[j].c_str(); } if (strFileName[strFileName.GetLength() - 1] == L'\\') strRedirect += L'\\'; break; } } return bRedirect ? strRedirect : strFileName; }
void SourceEdit::Search(LPCWSTR text, std::vector<SearchWindow::Result>& results) { CWaitCursor wc; int len = (int)CallEdit(SCI_GETLENGTH); TextToFind find; find.chrg.cpMin = 0; find.chrg.cpMax = len; CString textUtf = TextFormat::UnicodeToUTF8(text); find.lpstrText = (char*)(LPCSTR)textUtf; while (true) { // Search for the text if (CallEdit(SCI_FINDTEXT,0,(sptr_t)&find) == -1) return; // Get the surrounding text as context CStringW leading = GetTextRange(find.chrgText.cpMin-4,find.chrgText.cpMin,len); CStringW match = GetTextRange(find.chrgText.cpMin,find.chrgText.cpMax,len); CStringW trailing = GetTextRange(find.chrgText.cpMax,find.chrgText.cpMax+32,len); CStringW context = leading + match + trailing; context.Replace(L'\n',L' '); context.Replace(L'\r',L' '); context.Replace(L'\t',L' '); // Store the found result SearchWindow::Result result; result.context = context; result.inContext.cpMin = leading.GetLength(); result.inContext.cpMax = leading.GetLength() + match.GetLength(); result.sourceLocation = SOURCE_FILE; result.inSource.cpMin = find.chrgText.cpMin; result.inSource.cpMax = find.chrgText.cpMax; results.push_back(result); // Look for the next match find.chrg.cpMin = find.chrgText.cpMax; theApp.RunMessagePump(); } }
BOOL CHistoryManager::PrepareTempDirs() { for (int i = 0; i < TEMP_KEY_COUNT; i++) { HKEY key; if (RegOpenKeyExA(HKEY_CURRENT_USER, REG_TEMP_FOLDER, 0, KEY_QUERY_VALUE, &key) != ERROR_SUCCESS) continue; g_TempPaths[i].strRegKey = g_TempKey[i]; WCHAR szPath[1024]; DWORD Size = 1024; if (RegQueryValueExW(key, g_TempPaths[i].strRegKey.c_str(), NULL, NULL, (LPBYTE)szPath, &Size) != ERROR_SUCCESS) { RegCloseKey(key); continue; } CStringW strPath = szPath; strPath.Replace(L'/', L'\\'); if (strPath[strPath.GetLength() - 1] != L'\\') strPath += L'\\'; ////////////////////////////////////////////////////////////////////////// // Create Redirect Directory CStringW strTemp = m_strRedirectPath + CStringW(g_TempPaths[i].strRegKey.c_str()); if (!CreateDirectoryW(strTemp, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) continue; SetFileAttributesW(strTemp, FILE_ATTRIBUTE_HIDDEN); ////////////////////////////////////////////////////////////////////////// // WCHAR szDir[1024], szShort[1024], szLong[1024]; ExpandEnvironmentStringsW((LPWSTR)(LPCWSTR)strPath, (LPWSTR)szDir, _countof(szDir)); GetShortPathNameW(szDir, szShort, _countof(szShort)); GetLongPathNameW(szDir, szLong, _countof(szLong)); _wcslwr_s(szShort); _wcslwr_s(szLong); g_TempPaths[i].strShortTempDir = szShort; g_TempPaths[i].strLongTempDir = szLong; SplitPath(g_TempPaths[i].strShortTempDir, g_TempPaths[i].vecShortParts); SplitPath(g_TempPaths[i].strLongTempDir, g_TempPaths[i].vecLongParts); RegCloseKey(key); } return true; }
BOOL CFileBasedProjectTemplateItem::CreateMainFile(LPCTSTR lpszTargetPath, LPCTSTR lpszCrLf) { CStringW text; TextDocument doc; bool result = doc.Read(m_strPath,text); if (result) { const CStringW lineendings(L"\r\n"); int index = text.FindOneOf(lineendings); if (index != -1) { CStringW line = text.Left(index); const CStringW strKey(L"%DESCRIPTION: "); CStringW strStartOfLine = line.Left(strKey.GetLength()); strStartOfLine.MakeUpper(); if (strKey == strStartOfLine) { text.Delete(0,index); text.TrimLeft(lineendings + L' '); } } LPCWSTR le = GetLineEnding(static_cast<LPCWSTR>(text),text.GetLength()); USES_CONVERSION; if (std::wcscmp(le,T2CW(lpszCrLf)) != 0) // Line endings not equal text.Replace(le,lpszCrLf); result = doc.Write(lpszTargetPath,text); } return result; }
CHistoryManagerXP::CHistoryManagerXP(void) { LPWSTR lpszTempPath = new WCHAR[MAX_PATH + 1]; int nLength = GetTempPathW(MAX_PATH, lpszTempPath); if (nLength > MAX_PATH) { delete[] lpszTempPath; lpszTempPath = new WCHAR[nLength + 1]; GetTempPathW(nLength, lpszTempPath); } lpszTempPath[nLength] = '\0'; CStringW strTempPath = lpszTempPath; delete[] lpszTempPath; strTempPath.Replace(L'/', L'\\'); if (strTempPath[strTempPath.GetLength() - 1] != '\\') strTempPath += L"\\"; m_strWinTemp = strTempPath; strTempPath += L"BankTemp"; if (!CreateDirectoryW(strTempPath, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) return; SetFileAttributesW(strTempPath, FILE_ATTRIBUTE_HIDDEN); LPWSTR pBuf = NULL; // short path pBuf = m_strRedirectPath.GetBuffer(1024); GetShortPathNameW(strTempPath, pBuf, 1024); m_strRedirectPath.ReleaseBuffer(); m_strRedirectPath += L"\\"; m_strRedirectPath.MakeLower(); }
HRESULT CStreamSwitcherInputPin::CompleteConnect(IPin* pReceivePin) { HRESULT hr = __super::CompleteConnect(pReceivePin); if (FAILED(hr)) { return hr; } (static_cast<CStreamSwitcherFilter*>(m_pFilter))->CompleteConnect(PINDIR_INPUT, this, pReceivePin); m_fCanBlock = false; bool fForkedSomewhere = false; CStringW fileName; CStringW pinName; IPin* pPin = (IPin*)this; IBaseFilter* pBF = (IBaseFilter*)m_pFilter; pPin = GetUpStreamPin(pBF, pPin); if (pPin) { pBF = GetFilterFromPin(pPin); } while (pPin && pBF) { if (IsSplitter(pBF)) { pinName = GetPinName(pPin); } CLSID clsid = GetCLSID(pBF); if (clsid == CLSID_AviSplitter || clsid == CLSID_OggSplitter) { m_fCanBlock = true; } int nIn, nOut, nInC, nOutC; CountPins(pBF, nIn, nOut, nInC, nOutC); fForkedSomewhere = fForkedSomewhere || nIn > 1 || nOut > 1; DWORD cStreams = 0; if (CComQIPtr<IAMStreamSelect> pSSF = pBF) { hr = pSSF->Count(&cStreams); if (SUCCEEDED(hr)) { for (int i = 0; i < (int)cStreams; i++) { AM_MEDIA_TYPE* pmt = nullptr; hr = pSSF->Info(i, &pmt, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); if (SUCCEEDED(hr) && pmt && pmt->majortype == MEDIATYPE_Audio) { m_pSSF = pSSF; DeleteMediaType(pmt); break; } DeleteMediaType(pmt); } } } if (CComQIPtr<IFileSourceFilter> pFSF = pBF) { WCHAR* pszName = nullptr; AM_MEDIA_TYPE mt; if (SUCCEEDED(pFSF->GetCurFile(&pszName, &mt)) && pszName) { fileName = pszName; CoTaskMemFree(pszName); fileName.Replace('\\', '/'); CStringW fn = fileName.Mid(fileName.ReverseFind('/') + 1); if (!fn.IsEmpty()) { fileName = fn; } // Haali & LAVFSplitter return only one "Audio" pin name, cause CMainFrame::OnInitMenuPopup lookup find the wrong popmenu, // add space at the end to prevent this, internal filter never return "Audio" only. if (!pinName.IsEmpty()) { fileName = pinName + L" "; } WCHAR* pName = DEBUG_NEW WCHAR[fileName.GetLength() + 1]; if (pName) { wcscpy_s(pName, fileName.GetLength() + 1, fileName); if (m_pName) { delete [] m_pName; } m_pName = pName; if (cStreams == 1) { // Simple external track, no need to use the info from IAMStreamSelect m_pSSF.Release(); } } } break; } pPin = GetFirstPin(pBF); pPin = GetUpStreamPin(pBF, pPin); if (pPin) { pBF = GetFilterFromPin(pPin); } } if (!fForkedSomewhere) { m_fCanBlock = true; } m_hNotifyEvent = nullptr; return S_OK; }
HRESULT CStreamSwitcherInputPin::CompleteConnect(IPin* pReceivePin) { HRESULT hr = __super::CompleteConnect(pReceivePin); if(FAILED(hr)) return hr; ((CStreamSwitcherFilter*)m_pFilter)->CompleteConnect(PINDIR_INPUT, this, pReceivePin); m_fCanBlock = false; bool fForkedSomewhere = false; CStringW fileName; CStringW pinName; IPin* pPin = (IPin*)this; IBaseFilter* pBF = (IBaseFilter*)m_pFilter; while((pPin = GetUpStreamPin(pBF, pPin)) && (pBF = GetFilterFromPin(pPin))) { if(IsSplitter(pBF)) { pinName = GetPinName(pPin); } CLSID clsid = GetCLSID(pBF); if(clsid == CLSID_AviSplitter || clsid == CLSID_OggSplitter) m_fCanBlock = true; int nIn, nOut, nInC, nOutC; CountPins(pBF, nIn, nOut, nInC, nOutC); fForkedSomewhere = fForkedSomewhere || nIn > 1 || nOut > 1; if(CComQIPtr<IFileSourceFilter> pFSF = pBF) { WCHAR* pszName = NULL; AM_MEDIA_TYPE mt; if(SUCCEEDED(pFSF->GetCurFile(&pszName, &mt)) && pszName) { fileName = pszName; CoTaskMemFree(pszName); fileName.Replace('\\', '/'); CStringW fn = fileName.Mid(fileName.ReverseFind('/')+1); if(!fn.IsEmpty()) fileName = fn; if(!pinName.IsEmpty()) fileName += L" / " + pinName; WCHAR* pName = new WCHAR[fileName.GetLength()+1]; if(pName) { wcscpy(pName, fileName); if(m_pName) delete [] m_pName; m_pName = pName; } } break; } pPin = GetFirstPin(pBF); } if(!fForkedSomewhere) m_fCanBlock = true; m_hNotifyEvent = NULL; return S_OK; }
void TabDoc::Search(LPCWSTR text, std::vector<SearchWindow::Result>& results) { CWaitCursor wc; CStringW textLow(text); textLow.MakeLower(); if (m_docTexts.IsEmpty()) { CFileFind findDoc; for (int i = 0; i < 2; i++) { CString findPath; switch (i) { case 0: findPath.Format("%s\\Documentation\\doc*.html",theApp.GetAppDir()); break; case 1: findPath.Format("%s\\Documentation\\rdoc*.html",theApp.GetAppDir()); break; } BOOL found = findDoc.FindFile(findPath); while (found) { // Get the filename of a documentation file found = findDoc.FindNextFile(); // Extract the title and text DecodeHTML(findDoc.GetFilePath(),i); theApp.RunMessagePump(); } } } for (int i = 0; i < m_docTexts.GetSize(); i++) { DocText* docText = m_docTexts[i]; // Make everything lower case CStringW bodyLow(docText->body); bodyLow.MakeLower(); // Look for a match int found1 = bodyLow.Find(textLow); if (found1 != -1) { int found2 = found1+textLow.GetLength(); // Create a larger range to extract the context int context1 = found1-8; if (context1 < 0) context1 = 0; int context2 = found2+32; if (context2 > docText->body.GetLength()-1) context2 = docText->body.GetLength()-1; // Get the surrounding text as context CStringW context = docText->body.Mid(context1,context2-context1); context.Replace(L'\n',L' '); context.Replace(L'\r',L' '); context.Replace(L'\t',L' '); SearchWindow::Result result; result.context = context; result.inContext.cpMin = found1-context1; result.inContext.cpMax = found2-context1; CString location; location.Format("%s: %s",docText->section,docText->title); result.sourceLocation = location; result.sourceSort = docText->sort; result.sourceFile = docText->file; result.colourScheme = docText->colourScheme; results.push_back(result); } theApp.RunMessagePump(); } // Sort the search results by the documentation page they are found in std::sort(results.begin(),results.end(),SortBySource); }
void Definition::Dump(OutputStream& s, int level, bool fLast) { if(m_predefined) return; CStringW tabs(' ', level * 4); CStringW str = tabs; if(m_predefined) str += '?'; if(m_priority == PLow) str += '*'; else if(m_priority == PHigh) str += '!'; if(!IsTypeUnknown() && !m_autotype) str += m_type; if(!IsNameUnknown()) str += '#' + m_name; str += ':'; s.PutString(L"%s", str); if(!m_nodes.IsEmpty()) { POSITION pos = m_nodes.GetHeadPosition(); while(pos) { Node* pNode = m_nodes.GetNext(pos); if(Reference* pRef = dynamic_cast<Reference*>(pNode)) { pRef->Dump(s, level, fLast); } else { ASSERT(!pNode->IsNameUnknown()); s.PutString(L" %s", pNode->m_name); } } s.PutString(L";\n"); if(!fLast && (!m_nodes.IsEmpty() || level == 0)) s.PutString(L"\n"); } else if(m_status == string) { CStringW str = m_value; str.Replace(L"\"", L"\\\""); s.PutString(L" \"%s\";\n", str); } else if(m_status == number) { CStringW str = m_value; if(!m_unit.IsEmpty()) str += m_unit; s.PutString(L" %s;\n", str); } else if(m_status == boolean) { s.PutString(L" %s;\n", m_value); } else if(m_status == block) { s.PutString(L" {%s};\n", m_value); } else { s.PutString(L" null;\n"); } }
void Definition::GetAsNumber(Number<T>& n, StringMapW<T>* n2n) { CStringW str = m_value; str.Replace(L" ", L""); n.value = 0; n.unit = m_unit; n.sign = 0; if(n2n) { if(m_status == node) throw Exception(_T("expected value type")); if(StringMapW<T>::CPair* p = n2n->Lookup(str)) { n.value = p->m_value; return; } } if(m_status != number) throw Exception(_T("expected number")); n.sign = str.Find('+') == 0 ? 1 : str.Find('-') == 0 ? -1 : 0; str.TrimLeft(L"+-"); if(str.Find(L"0x") == 0) { if(n.sign) throw Exception(_T("hex values must be unsigned")); n.value = (T)wcstoul(str.Mid(2), NULL, 16); } else { CStringW num_string = m_value + m_unit; if(m_num_string != num_string) { Split sa(':', str); Split sa2('.', sa ? sa[sa-1] : L""); if(sa == 0 || sa2 == 0 || sa2 > 2) throw Exception(_T("invalid number")); float f = 0; for(size_t i = 0; i < sa; i++) { f *= 60; f += wcstoul(sa[i], NULL, 10); } if(sa2 > 1) f += (float)wcstoul(sa2[1], NULL, 10) / pow((float)10, sa2[1].GetLength()); if(n.unit == L"ms") { f /= 1000; n.unit = L"s"; } else if(n.unit == L"m") { f *= 60; n.unit = L"s"; } else if(n.unit == L"h") { f *= 3600; n.unit = L"s"; } m_num.value = f; m_num.unit = n.unit; m_num_string = num_string; n.value = (T)f; } else { n.value = (T)m_num.value; n.unit = m_num.unit; } if(n.sign) n.value *= n.sign; } }
// Time 字符串中不能有空格 HRESULT KppUserLog::WriteSingleLog( /* [in] */const std::wstring& wstLogString ) { std::wstring strLog; HRESULT hrRet = E_FAIL; SYSTEMTIME sysTime = {0}; CStringW strTmep; if (!m_bInitFlag) { return E_FAIL; } _LockWork(); FILE* pfile = NULL; if (::PathFileExists(m_strPathName.c_str())) { pfile = ::_wfopen(m_strPathName.c_str(), L"at,ccs=UNICODE"); } else { pfile = ::_wfopen(m_strPathName.c_str(), L"wt,ccs=UNICODE"); } if (!pfile) { hrRet = S_OK; goto _Exit; } GetLocalTime( &sysTime ); ParseTime(strLog, &sysTime); strTmep = wstLogString.c_str(); strTmep.Replace('\r', ' '); strTmep.Replace('\n', ' '); strLog += strTmep; strLog += '\n'; ::fwrite(strLog.c_str(), sizeof(WCHAR), ::wcslen(strLog.c_str()), pfile); hrRet = S_OK; _Exit: if (pfile) { ::fclose(pfile); pfile = NULL; } _UnlockWork(); return hrRet; }
HRESULT CStreamSwitcherInputPin::CompleteConnect(IPin* pReceivePin) { HRESULT hr = __super::CompleteConnect(pReceivePin); if (FAILED(hr)) { return hr; } (static_cast<CStreamSwitcherFilter*>(m_pFilter))->CompleteConnect(PINDIR_INPUT, this, pReceivePin); m_fCanBlock = false; bool fForkedSomewhere = false; CStringW fileName; CStringW pinName; IPin* pPin = (IPin*)this; IBaseFilter* pBF = (IBaseFilter*)m_pFilter; pPin = GetUpStreamPin(pBF, pPin); if (pPin) { pBF = GetFilterFromPin(pPin); } while (pPin && pBF) { if (IsSplitter(pBF)) { pinName = GetPinName(pPin); } CLSID clsid = GetCLSID(pBF); if (clsid == CLSID_AviSplitter || clsid == CLSID_OggSplitter) { m_fCanBlock = true; } int nIn, nOut, nInC, nOutC; CountPins(pBF, nIn, nOut, nInC, nOutC); fForkedSomewhere = fForkedSomewhere || nIn > 1 || nOut > 1; if (CComQIPtr<IFileSourceFilter> pFSF = pBF) { WCHAR* pszName = NULL; AM_MEDIA_TYPE mt; if (SUCCEEDED(pFSF->GetCurFile(&pszName, &mt)) && pszName) { fileName = pszName; CoTaskMemFree(pszName); fileName.Replace('\\', '/'); CStringW fn = fileName.Mid(fileName.ReverseFind('/')+1); if (!fn.IsEmpty()) { fileName = fn; } // Haali & LAVFSplitter return only one "Audio" pin name, cause CMainFrame::OnInitMenuPopup lookup find the wrong popmenu, // add space at the end to prevent this, internal filter never return "Audio" only. if (!pinName.IsEmpty()) { fileName = pinName + L" "; } WCHAR* pName = DNew WCHAR[fileName.GetLength()+1]; if (pName) { wcscpy_s(pName, fileName.GetLength() + 1, fileName); if (m_pName) { delete [] m_pName; } m_pName = pName; } } break; } pPin = GetFirstPin(pBF); pPin = GetUpStreamPin(pBF, pPin); if (pPin) { pBF = GetFilterFromPin(pPin); } } if (!fForkedSomewhere) { m_fCanBlock = true; } m_hNotifyEvent = NULL; return S_OK; }