int CGitIgnoreItem::IsPathIgnored(const CStringA& patha, int& type) { int pos = patha.ReverseFind('/'); const char* base = (pos >= 0) ? ((const char*)patha + pos + 1) : patha; return IsPathIgnored(patha, base, type); }
bool CIPFilter::ParseFilterLine2(const CStringA& sbuffer, uint32& ip1, uint32& ip2, UINT& level, CStringA& desc) const { int iPos = sbuffer.ReverseFind(':'); if (iPos < 0) return false; desc = sbuffer.Left(iPos); desc.Replace("PGIPDB", ""); desc.Trim(); CStringA strIPRange = sbuffer.Mid(iPos + 1, sbuffer.GetLength() - iPos); UINT u1, u2, u3, u4, u5, u6, u7, u8; if (sscanf(strIPRange, "%u.%u.%u.%u - %u.%u.%u.%u", &u1, &u2, &u3, &u4, &u5, &u6, &u7, &u8) != 8) return false; ((BYTE*)&ip1)[0] = (BYTE)u4; ((BYTE*)&ip1)[1] = (BYTE)u3; ((BYTE*)&ip1)[2] = (BYTE)u2; ((BYTE*)&ip1)[3] = (BYTE)u1; ((BYTE*)&ip2)[0] = (BYTE)u8; ((BYTE*)&ip2)[1] = (BYTE)u7; ((BYTE*)&ip2)[2] = (BYTE)u6; ((BYTE*)&ip2)[3] = (BYTE)u5; level = DFLT_FILTER_LEVEL; return true; }
BOOL CCookie::AdjustPath(CStringA& strPath, LPCSTR lpszDefaultPath) { if(strPath.IsEmpty() && lpszDefaultPath) strPath = lpszDefaultPath; int iLength = strPath.GetLength(); if(iLength == 0) return FALSE; if(strPath.GetAt(iLength - 1) != COOKIE_PATH_SEP_CHAR) { int iPos = strPath.ReverseFind(COOKIE_PATH_SEP_CHAR); if(iPos >= 0) strPath = strPath.Left(iPos + 1); else strPath.Empty(); } if(!strPath.IsEmpty() && strPath.GetAt(0) != COOKIE_PATH_SEP_CHAR) strPath.Insert(0, COOKIE_PATH_SEP_CHAR); return !strPath.IsEmpty(); }
bool QueryRegistryValue(const CStringA strRegPath, CStringA& strValue) { HKEY hRootKey = NULL; CStringA strSubPath; if (!GetRootKeyAndSubPath(strRegPath, hRootKey, strSubPath)) return false; int nVal = strSubPath.ReverseFind('\\'); CStringA strItem = strSubPath.Mid(nVal + 1); strSubPath = strSubPath.Mid(0, nVal); if (strItem == ".") strItem = ""; HKEY hSubKey = NULL; if (RegOpenKeyExA(hRootKey, strSubPath, 0, KEY_READ, &hSubKey) == ERROR_SUCCESS) { CHAR szFile[1024]; DWORD BufferSize = 1024; LONG ret = RegQueryValueExA(hSubKey, strItem, NULL, NULL, (LPBYTE)szFile, &BufferSize); RegCloseKey(hSubKey); if (ret == ERROR_SUCCESS) strValue = szFile; return ret == ERROR_SUCCESS; } return false; }
void EnumDir(CStringA resToken, int nEnumSubdir, std::vector<CString>& vecFiles) { int nEndSlash = resToken.ReverseFind('\\'); if (nEndSlash == -1) return; USES_CONVERSION; CStringA path = resToken.Mid(0, nEndSlash); CStringA findname = resToken.Mid(nEndSlash + 1); // file WIN32_FIND_DATAA fd; memset(&fd, 0, sizeof(WIN32_FIND_DATAA)); HANDLE hFind = FindFirstFileA(resToken, &fd); if (hFind != INVALID_HANDLE_VALUE) { do { CStringA subname = fd.cFileName; if (subname != "." && subname != "..") { CStringA fname = path + "\\" + subname; if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { } else vecFiles.push_back(A2CT(fname)); } } while (FindNextFileA(hFind, &fd) != 0); FindClose(hFind); } // directory if (nEnumSubdir > 0) { hFind = FindFirstFileA(path + "\\*.*", &fd); if (hFind != INVALID_HANDLE_VALUE) { do { CStringA subname = fd.cFileName; if (subname != "." && subname != "..") { CStringA fname = path + "\\" + subname; if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) EnumDir(fname + "\\" + findname, nEnumSubdir, vecFiles); } } while (FindNextFileA(hFind, &fd) != 0); FindClose(hFind); } } }
void CKcsLogging::ClearLogFileByDays(int nDay /* = 7 */) { CHAR szLogFileName[MAX_PATH * 2] = { 0 }; WIN32_FIND_DATAA fd = { 0 }; HANDLE hFile = INVALID_HANDLE_VALUE; SHGetSpecialFolderPathA(NULL, szLogFileName, CSIDL_LOCAL_APPDATA, FALSE); PathAppendA(szLogFileName, "KSafe\\KClear\\Logs"); PathAppendA(szLogFileName, "*.*"); hFile = FindFirstFileA(szLogFileName, &fd); if (INVALID_HANDLE_VALUE == hFile) { goto Clear0; } do { if (0 == stricmp(".", fd.cFileName) || 0 == stricmp("..", fd.cFileName)) continue; time_t lNow = 0; time(&lNow); FILETIME localfiletime; FileTimeToLocalFileTime(&(fd.ftLastWriteTime), &localfiletime); CTime stSys(lNow); CTime stFile(localfiletime); CTimeSpan stSPan; stSPan = stSys - stFile; if (stSPan.GetDays() >= nDay) { CStringA strtemp = szLogFileName ; CStringA strFileName = strtemp.Left(strtemp.ReverseFind(L'\\') + 1); strFileName += fd.cFileName; if (::PathFileExistsA(strFileName)) { ::DeleteFileA(strFileName); } } } while (FindNextFileA(hFile, &fd)); Clear0: if (hFile != INVALID_HANDLE_VALUE) { FindClose(hFile); hFile = INVALID_HANDLE_VALUE; } }
CString GetErrorMessage(pj_status_t status) { CStringA str; char *buf = str.GetBuffer(PJ_ERR_MSG_SIZE-1); pj_strerror(status, buf, PJ_ERR_MSG_SIZE); str.ReleaseBuffer(); int i = str.ReverseFind( '(' ); if (i!=-1) { str = str.Left(i-1); } if (str == "Invalid Request URI" || str == "Invalid URI") { str = "Invalid number"; } return Translate(CString(str).GetBuffer()); }
int CGitIgnoreList::CheckIgnore(const CString &path,const CString &projectroot) { __int64 time = 0; bool dir = 0; CString temp = projectroot + _T("\\") + path; temp.Replace(_T('/'), _T('\\')); CStringA patha; patha = CUnicodeUtils::GetMulti(path, CP_ACP) ; patha.Replace('\\', '/'); if(g_Git.GetFileModifyTime(temp, &time, &dir)) return -1; int type = 0; if (dir) type = DT_DIR; else type = DT_REG; while (!temp.IsEmpty()) { int x; x = temp.ReverseFind(_T('\\')); if(x < 0) x=0; temp=temp.Left(x); temp += _T("\\.gitignore"); char *base; patha.Replace('\\', '/'); int pos = patha.ReverseFind('/'); base = pos >= 0 ? patha.GetBuffer() + pos + 1 : patha.GetBuffer(); CAutoReadLock lock(&this->m_SharedMutex); if(this->m_Map.find(temp) != m_Map.end()) { int ret=-1; if(m_Map[temp].m_pExcludeList) ret = git_check_excluded_1( patha, patha.GetLength(), base, &type, m_Map[temp].m_pExcludeList); if(ret == 1) return 1; if(ret == 0) return 0; } temp = temp.Left(temp.GetLength()-11); temp +=_T("\\.git\\info\\exclude"); if(this->m_Map.find(temp) != m_Map.end()) { int ret = -1; if(m_Map[temp].m_pExcludeList) ret = git_check_excluded_1(patha, patha.GetLength(), base, &type, m_Map[temp].m_pExcludeList); if(ret == 1) return 1; if(ret == 0) return 0; return -1; } temp = temp.Left(temp.GetLength() - 18); } return -1; }
int CIPFilter::AddFromFile(LPCTSTR pszFilePath, bool bShowResponse) { DWORD dwStart = GetTickCount(); FILE* readFile = _tfsopen(pszFilePath, _T("r"), _SH_DENYWR); if (readFile != NULL) { enum EIPFilterFileType { Unknown = 0, FilterDat = 1, // ipfilter.dat/ip.prefix format PeerGuardian = 2, // PeerGuardian text format PeerGuardian2 = 3 // PeerGuardian binary format } eFileType = Unknown; setvbuf(readFile, NULL, _IOFBF, 32768); TCHAR szNam[_MAX_FNAME]; TCHAR szExt[_MAX_EXT]; _tsplitpath(pszFilePath, NULL, NULL, szNam, szExt); if (_tcsicmp(szExt, _T(".p2p")) == 0 || (_tcsicmp(szNam, _T("guarding.p2p")) == 0 && _tcsicmp(szExt, _T(".txt")) == 0)) eFileType = PeerGuardian; else if (_tcsicmp(szExt, _T(".prefix")) == 0) eFileType = FilterDat; else { VERIFY( _setmode(fileno(readFile), _O_BINARY) != -1 ); static const BYTE _aucP2Bheader[] = "\xFF\xFF\xFF\xFFP2B"; BYTE aucHeader[sizeof _aucP2Bheader - 1]; if (fread(aucHeader, sizeof aucHeader, 1, readFile) == 1) { if (memcmp(aucHeader, _aucP2Bheader, sizeof _aucP2Bheader - 1)==0) eFileType = PeerGuardian2; else { (void)fseek(readFile, 0, SEEK_SET); VERIFY( _setmode(fileno(readFile), _O_TEXT) != -1 ); // ugly! } } } int iFoundRanges = 0; int iLine = 0; if (eFileType == PeerGuardian2) { // Version 1: strings are ISO-8859-1 encoded // Version 2: strings are UTF-8 encoded uint8 nVersion; if (fread(&nVersion, sizeof nVersion, 1, readFile)==1 && (nVersion==1 || nVersion==2)) { while (!feof(readFile)) { CHAR szName[256]; int iLen = 0; for (;;) // read until NUL or EOF { int iChar = getc(readFile); if (iChar == EOF) break; if (iLen < sizeof szName - 1) szName[iLen++] = (CHAR)iChar; if (iChar == '\0') break; } szName[iLen] = '\0'; uint32 uStart; if (fread(&uStart, sizeof uStart, 1, readFile) != 1) break; uStart = ntohl(uStart); uint32 uEnd; if (fread(&uEnd, sizeof uEnd, 1, readFile) != 1) break; uEnd = ntohl(uEnd); iLine++; // (nVersion == 2) ? OptUtf8ToStr(szName, iLen) : AddIPRange(uStart, uEnd, DFLT_FILTER_LEVEL, CStringA(szName, iLen)); iFoundRanges++; } } } else { CStringA sbuffer; CHAR szBuffer[1024]; while (fgets(szBuffer, _countof(szBuffer), readFile) != NULL) { iLine++; sbuffer = szBuffer; // ignore comments & too short lines if (sbuffer.GetAt(0) == '#' || sbuffer.GetAt(0) == '/' || sbuffer.GetLength() < 5) { sbuffer.Trim(" \t\r\n"); DEBUG_ONLY( (!sbuffer.IsEmpty()) ? TRACE("IP filter: ignored line %u\n", iLine) : 0 ); continue; } if (eFileType == Unknown) { // looks like html if (sbuffer.Find('>') > -1 && sbuffer.Find('<') > -1) sbuffer.Delete(0, sbuffer.ReverseFind('>') + 1); // check for <IP> - <IP> at start of line UINT u1, u2, u3, u4, u5, u6, u7, u8; if (sscanf(sbuffer, "%u.%u.%u.%u - %u.%u.%u.%u", &u1, &u2, &u3, &u4, &u5, &u6, &u7, &u8) == 8) { eFileType = FilterDat; } else { // check for <description> ':' <IP> '-' <IP> int iColon = sbuffer.Find(':'); if (iColon > -1) { CStringA strIPRange = sbuffer.Mid(iColon + 1); UINT u1, u2, u3, u4, u5, u6, u7, u8; if (sscanf(strIPRange, "%u.%u.%u.%u - %u.%u.%u.%u", &u1, &u2, &u3, &u4, &u5, &u6, &u7, &u8) == 8) { eFileType = PeerGuardian; } } } } bool bValid = false; uint32 start = 0; uint32 end = 0; UINT level = 0; CStringA desc; if (eFileType == FilterDat) bValid = ParseFilterLine1(sbuffer, start, end, level, desc); else if (eFileType == PeerGuardian) bValid = ParseFilterLine2(sbuffer, start, end, level, desc); // add a filter if (bValid) { AddIPRange(start, end, level, desc); iFoundRanges++; } else { sbuffer.Trim(" \t\r\n"); DEBUG_ONLY( (!sbuffer.IsEmpty()) ? TRACE("IP filter: ignored line %u\n", iLine) : 0 ); } } } fclose(readFile); // sort the IP filter list by IP range start addresses qsort(m_iplist.GetData(), m_iplist.GetCount(), sizeof(m_iplist[0]), CmpSIPFilterByStartAddr); // merge overlapping and adjacent filter ranges int iDuplicate = 0; int iMerged = 0; if (m_iplist.GetCount() >= 2) { // On large IP-filter lists there is a noticeable performance problem when merging the list. // The 'CIPFilterArray::RemoveAt' call is way too expensive to get called during the merging, // thus we use temporary helper arrays to copy only the entries into the final list which // are not get deleted. // Reserve a byte array (its used as a boolean array actually) as large as the current // IP-filter list, so we can set a 'to delete' flag for each entry in the current IP-filter list. char* pcToDelete = new char[m_iplist.GetCount()]; memset(pcToDelete, 0, m_iplist.GetCount()); int iNumToDelete = 0; SIPFilter* pPrv = m_iplist[0]; int i = 1; while (i < m_iplist.GetCount()) { SIPFilter* pCur = m_iplist[i]; if ( pCur->start >= pPrv->start && pCur->start <= pPrv->end // overlapping || pCur->start == pPrv->end+1 && pCur->level == pPrv->level) // adjacent { if (pCur->start != pPrv->start || pCur->end != pPrv->end) // don't merge identical entries { //TODO: not yet handled, overlapping entries with different 'level' if (pCur->end > pPrv->end) pPrv->end = pCur->end; //pPrv->desc += _T("; ") + pCur->desc; // this may create a very very long description string... iMerged++; } else { // if we have identical entries, use the lowest 'level' if (pCur->level < pPrv->level) pPrv->level = pCur->level; iDuplicate++; } delete pCur; //m_iplist.RemoveAt(i); // way too expensive (read above) pcToDelete[i] = 1; // mark this entry as 'to delete' iNumToDelete++; i++; continue; } pPrv = pCur; i++; } // Create new IP-filter list which contains only the entries from the original IP-filter list // which are not to be deleted. if (iNumToDelete > 0) { CIPFilterArray newList; newList.SetSize(m_iplist.GetCount() - iNumToDelete); int iNewListIndex = 0; for (int i = 0; i < m_iplist.GetCount(); i++) { if (!pcToDelete[i]) newList[iNewListIndex++] = m_iplist[i]; } ASSERT( iNewListIndex == newList.GetSize() ); // Replace current list with new list. Dump, but still fast enough (only 1 memcpy) m_iplist.RemoveAll(); m_iplist.Append(newList); newList.RemoveAll(); m_bModified = true; } delete[] pcToDelete; } if (thePrefs.GetVerbose()) { DWORD dwEnd = GetTickCount(); AddDebugLogLine(false, _T("Loaded IP filters from \"%s\""), pszFilePath); AddDebugLogLine(false, _T("Parsed lines/entries:%u Found IP ranges:%u Duplicate:%u Merged:%u Time:%s"), iLine, iFoundRanges, iDuplicate, iMerged, CastSecondsToHM((dwEnd-dwStart+500)/1000)); } AddLogLine(bShowResponse, GetResString(IDS_IPFILTERLOADED), m_iplist.GetCount()); } return m_iplist.GetCount(); }
int CGitIgnoreList::CheckIgnore(const CString &path, const CString &projectroot, bool isDir) { CString temp = CombinePath(projectroot, path); temp.Replace(_T('/'), _T('\\')); CStringA patha = CUnicodeUtils::GetMulti(path, CP_UTF8); patha.Replace('\\', '/'); int type = 0; if (isDir) { type = DT_DIR; // strip directory name // we do not need to check for a .ignore file inside a directory we might ignore int i = temp.ReverseFind(_T('\\')); if (i >= 0) temp.Truncate(i); } else { type = DT_REG; int x = temp.ReverseFind(_T('\\')); if (x >= 2) temp.Truncate(x); } int pos = patha.ReverseFind('/'); const char * base = (pos >= 0) ? ((const char*)patha + pos + 1) : patha; int ret = -1; CAutoReadLock lock(m_SharedMutex); while (!temp.IsEmpty()) { CString tempOrig = temp; temp += _T("\\.git"); if (CGit::GitPathFileExists(temp)) { CString gitignore = temp; gitignore += _T("ignore"); if ((ret = CheckFileAgainstIgnoreList(gitignore, patha, base, type)) != -1) break; CString adminDir = g_AdminDirMap.GetAdminDir(tempOrig); CString wcglobalgitignore = adminDir; wcglobalgitignore += _T("info\\exclude"); if ((ret = CheckFileAgainstIgnoreList(wcglobalgitignore, patha, base, type)) != -1) break; CString excludesFile = m_CoreExcludesfiles[adminDir]; if (!excludesFile.IsEmpty()) ret = CheckFileAgainstIgnoreList(excludesFile, patha, base, type); break; } temp += _T("ignore"); if ((ret = CheckFileAgainstIgnoreList(temp, patha, base, type)) != -1) break; int found = 0; int i; for (i = temp.GetLength() - 1; i >= 0; i--) { if (temp[i] == _T('\\')) ++found; if (found == 2) break; } temp.Truncate(i); } return ret; }
void CProgressDlg::ParserCmdOutput(CRichEditCtrl &log,CProgressCtrl &progressctrl,HWND m_hWnd,CComPtr<ITaskbarList3> m_pTaskbarList,CStringA &oneline, char ch, CWnd *CurrentWork) { //TRACE(_T("%c"),ch); if( ch == ('\r') || ch == ('\n')) { CString str; // TRACE(_T("End Char %s \r\n"),ch==_T('\r')?_T("lf"):_T("")); // TRACE(_T("End Char %s \r\n"),ch==_T('\n')?_T("cr"):_T("")); if(ClearESC(oneline)) { ch = ('\r'); } int lines = log.GetLineCount(); g_Git.StringAppend(&str,(BYTE*)oneline.GetBuffer(),CP_ACP); str.Trim(); // TRACE(_T("%s"), str); if(ch == ('\r')) { int start=log.LineIndex(lines-1); log.SetSel(start, log.GetTextLength()); log.ReplaceSel(str); } else { int length = log.GetWindowTextLength(); log.SetSel(length, length); if (length > 0) log.ReplaceSel(_T("\r\n") + str); else log.ReplaceSel(str); } if (lines > 500) //limited log length { int end=log.LineIndex(1); log.SetSel(0,end); log.ReplaceSel(_T("")); } log.LineScroll(log.GetLineCount() - log.GetFirstVisibleLine() - 4); int s1=oneline.ReverseFind(_T(':')); int s2=oneline.Find(_T('%')); if (s1 > 0 && s2 > 0) { if(CurrentWork) CurrentWork->SetWindowTextW(str.Left(s1)); int pos=FindPercentage(str); TRACE(_T("Pos %d\r\n"),pos); if(pos>0) { progressctrl.SetPos(pos); if (m_pTaskbarList) { m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL); m_pTaskbarList->SetProgressValue(m_hWnd, pos, 100); } } } oneline=""; } else { oneline+=ch; } }
CStringA FxInternal::TranscodePlugToHandle(const CStringA& plugStr) { int iLastPos=0; int iThisPos=0; CStringA result; CStringA partial; int rootIdx= plugStr.Find(DirectXShader::RootLongName.asChar()); if(rootIdx != 0) return CStringA(); if( plugStr[(int)DirectXShader::RootLongName.length()] != '.' ) return CStringA(); CStringA rootlessPlugStr= plugStr.Mid(DirectXShader::RootLongName.length()+1); CStringA subStr; while( iLastPos= iThisPos, subStr=rootlessPlugStr.Tokenize(".[]", iThisPos), iThisPos != -1 ) { if(iLastPos == 0) { partial= subStr; int prefixIdx= subStr.Find(DirectXShader::RootShortName.asChar()); if(prefixIdx != 0) return CStringA(); result= subStr.Mid(DirectXShader::RootShortName.length()); } else if(rootlessPlugStr[iLastPos-1]=='.' || (rootlessPlugStr[iLastPos-1]==']' && rootlessPlugStr[iLastPos]=='.')) { DXCC_ASSERT(subStr.Find(partial) == 0); CStringA uniquePart= subStr.Mid( partial.GetLength() ); partial= subStr; result.AppendFormat(".%s", uniquePart); } else if(rootlessPlugStr[iLastPos-1]=='[' && rootlessPlugStr[iThisPos-1]==']') { result.AppendFormat("[%s]", subStr); } else DXCC_ASSERT(false); } //remove last array if( result[result.GetLength()-1] == ']' ) { int lastArrayAccess= result.ReverseFind('['); DXCC_ASSERT(lastArrayAccess != -1); result= result.Left(lastArrayAccess); } int lastMember= result.ReverseFind('.'); if(lastMember == -1) return CStringA(); if(result.Mid(lastMember+1) != "Value") return CStringA(); result= result.Left(lastMember); return result; }
int CGitIgnoreList::CheckIgnore(const CString &path,const CString &projectroot) { __int64 time = 0; bool dir = 0; CString temp = projectroot + _T("\\") + path; temp.Replace(_T('/'), _T('\\')); CStringA patha = CUnicodeUtils::GetMulti(path, CP_UTF8); patha.Replace('\\', '/'); if(g_Git.GetFileModifyTime(temp, &time, &dir)) return -1; int type = 0; if (dir) { type = DT_DIR; // strip directory name // we do not need to check for a .ignore file inside a directory we might ignore int i = temp.ReverseFind(_T('\\')); if (i >= 0) temp = temp.Left(i); } else type = DT_REG; char * base = NULL; int pos = patha.ReverseFind('/'); base = pos >= 0 ? patha.GetBuffer() + pos + 1 : patha.GetBuffer(); int ret = -1; CAutoReadLock lock(&this->m_SharedMutex); while (!temp.IsEmpty()) { CString tempOrig = temp; temp += _T("\\.git"); if (CGit::GitPathFileExists(temp)) { CString gitignore = temp; gitignore += _T("ignore"); if ((ret = CheckFileAgainstIgnoreList(gitignore, patha, base, type)) != -1) break; CString adminDir = g_AdminDirMap.GetAdminDir(tempOrig); CString wcglobalgitignore = adminDir + _T("info\\exclude"); if ((ret = CheckFileAgainstIgnoreList(wcglobalgitignore, patha, base, type)) != -1) break; m_SharedMutex.AcquireShared(); CString excludesFile = m_CoreExcludesfiles[adminDir]; m_SharedMutex.ReleaseShared(); if (!excludesFile.IsEmpty()) ret = CheckFileAgainstIgnoreList(excludesFile, patha, base, type); break; } else { temp += _T("ignore"); if ((ret = CheckFileAgainstIgnoreList(temp, patha, base, type)) != -1) break; } int found = 0; int i; for (i = temp.GetLength() - 1; i >= 0; i--) { if (temp[i] == _T('\\')) ++found; if (found == 2) break; } temp = temp.Left(i); } patha.ReleaseBuffer(); return ret; }
bool ScintillaEditor::ReadProperties(const CString& fileName, const CString& forcedExt) { delete m_props; m_props = NULL; CStringA fileNameForExtension; if (forcedExt.IsEmpty()) { int dotPos = fileName.ReverseFind('.'); if (dotPos != -1) { fileNameForExtension = fileName.Mid(dotPos + 1); fileNameForExtension.MakeLower(); } } else fileNameForExtension = forcedExt; TCHAR moduleFileNameBuffer[_MAX_PATH]; GetModuleFileName(GetModuleHandle(NULL), moduleFileNameBuffer, _MAX_PATH); CStringA modulePath = moduleFileNameBuffer; int slashPos = modulePath.ReverseFind('\\'); modulePath = modulePath.Left(slashPos + 1); m_props = new ScintillaPropertiesFile; m_props->Parse(modulePath + "SciTEGlobal.properties"); m_props->Parse(modulePath + fileNameForExtension + ".properties"); ScintillaPropertiesFile& props = *m_props; const CStringA& language = props.Get("lexer.*." + fileNameForExtension); int lexLanguage; if (language == "python") { lexLanguage = SCLEX_PYTHON; } else if (language == "cpp") { lexLanguage = SCLEX_CPP; } else if (language == "hypertext") { lexLanguage = SCLEX_HTML; } else if (language == "xml") { lexLanguage = SCLEX_XML; } else if (language == "perl") { lexLanguage = SCLEX_PERL; } else if (language == "sql") { lexLanguage = SCLEX_SQL; } else if (language == "vb") { lexLanguage = SCLEX_VB; } else if (language == "props") { lexLanguage = SCLEX_PROPERTIES; } else if (language == "errorlist") { lexLanguage = SCLEX_ERRORLIST; } else if (language == "makefile") { lexLanguage = SCLEX_MAKEFILE; } else if (language == "batch") { lexLanguage = SCLEX_BATCH; } else if (language == "latex") { lexLanguage = SCLEX_LATEX; } else if (language == "lua") { lexLanguage = SCLEX_LUA; } else if (language == "diff") { lexLanguage = SCLEX_DIFF; } else if (language == "container") { lexLanguage = SCLEX_CONTAINER; } else if (language == "conf") { lexLanguage = SCLEX_CONF; } else if (language == "pascal") { lexLanguage = SCLEX_PASCAL; } else if (language == "ave") { lexLanguage = SCLEX_AVE; } else { lexLanguage = SCLEX_NULL; } if ((lexLanguage == SCLEX_HTML) || (lexLanguage == SCLEX_XML)) SendEditor(SCI_SETSTYLEBITS, 7); else SendEditor(SCI_SETSTYLEBITS, 5); SendEditor(SCI_SETLEXER, lexLanguage); // SendOutput(SCI_SETLEXER, SCLEX_ERRORLIST); // apis.Clear(); CStringA kw0 = props.Get("keywords.*." + fileNameForExtension); SendEditorString(SCI_SETKEYWORDS, 0, kw0); CStringA kw1 = props.Get("keywords2.*." + fileNameForExtension); SendEditorString(SCI_SETKEYWORDS, 1, kw1); CStringA kw2 = props.Get("keywords3.*." + fileNameForExtension); SendEditorString(SCI_SETKEYWORDS, 2, kw2); CStringA kw3 = props.Get("keywords4.*." + fileNameForExtension); SendEditorString(SCI_SETKEYWORDS, 3, kw3); CStringA kw4 = props.Get("keywords5.*." + fileNameForExtension); SendEditorString(SCI_SETKEYWORDS, 4, kw4); // char homepath[MAX_PATH + 20]; // if (GetSciteDefaultHome(homepath, sizeof(homepath))) { // props.Set("SciteDefaultHome", homepath); // } // if (GetSciteUserHome(homepath, sizeof(homepath))) { // props.Set("SciteUserHome", homepath); // } ForwardPropertyToEditor("fold"); ForwardPropertyToEditor("fold.compact"); ForwardPropertyToEditor("fold.comment"); ForwardPropertyToEditor("fold.html"); ForwardPropertyToEditor("styling.within.preprocessor"); ForwardPropertyToEditor("tab.timmy.whinge.level"); /* CStringA apifilename = props.Get("api.", fileNameForExtension); if (apifilename.GetLength()) { FILE *fp = fopen(apifilename, fileRead); if (fp) { fseek(fp, 0, SEEK_END); int len = ftell(fp); char *buffer = apis.Allocate(len); if (buffer) { fseek(fp, 0, SEEK_SET); fread(buffer, 1, len, fp); apis.SetFromAllocated(); } fclose(fp); //Platform::DebugPrintf("Finished api file %d\n", len); } } */ if (!props.GetInt("eol.auto")) { CStringA eol_mode = props.Get("eol.mode"); if (eol_mode == "LF") { SendEditor(SCI_SETEOLMODE, SC_EOL_LF); } else if (eol_mode == "CR") { SendEditor(SCI_SETEOLMODE, SC_EOL_CR); } else if (eol_mode == "CRLF") { SendEditor(SCI_SETEOLMODE, SC_EOL_CRLF); } } // codePage = props.GetInt("code.page"); // SendEditor(SCI_SETCODEPAGE, codePage); // characterSet = props.GetInt("character.set"); CStringA colour; colour = props.Get("caret.fore"); if (colour.GetLength()) { SendEditor(SCI_SETCARETFORE, ScintillaPropertiesFile::ColourFromString(colour)); } SendEditor(SCI_SETCARETWIDTH, props.GetInt("caret.width", 1)); // SendOutput(SCI_SETCARETWIDTH, props.GetInt("caret.width", 1)); colour = props.Get("calltip.back"); if (colour.GetLength()) { SendEditor(SCI_CALLTIPSETBACK, ScintillaPropertiesFile::ColourFromString(colour)); } CStringA caretPeriod = props.Get("caret.period"); if (caretPeriod.GetLength()) { SendEditor(SCI_SETCARETPERIOD, value(caretPeriod)); // SendOutput(SCI_SETCARETPERIOD, caretPeriod.value()); } int caretStrict = props.GetInt("caret.policy.strict") ? CARET_STRICT : 0; int caretSlop = props.GetInt("caret.policy.slop", 1) ? CARET_SLOP : 0; int caretLines = props.GetInt("caret.policy.lines"); SendEditor(SCI_SETCARETPOLICY, caretStrict | caretSlop, caretLines); int visibleStrict = props.GetInt("visible.policy.strict") ? VISIBLE_STRICT : 0; int visibleSlop = props.GetInt("visible.policy.slop", 1) ? VISIBLE_SLOP : 0; int visibleLines = props.GetInt("visible.policy.lines"); SendEditor(SCI_SETVISIBLEPOLICY, visibleStrict | visibleSlop, visibleLines); SendEditor(SCI_SETEDGECOLUMN, props.GetInt("edge.column", 0)); SendEditor(SCI_SETEDGEMODE, props.GetInt("edge.mode", EDGE_NONE)); colour = props.Get("edge.colour"); if (colour.GetLength()) { SendEditor(SCI_SETEDGECOLOUR, ScintillaPropertiesFile::ColourFromString(colour)); } CStringA selfore = props.Get("selection.fore"); if (selfore.GetLength()) { SendEditor(SCI_SETSELFORE, 1, ScintillaPropertiesFile::ColourFromString(selfore)); } else { SendEditor(SCI_SETSELFORE, 0, 0); } colour = props.Get("selection.back"); if (colour.GetLength()) { SendEditor(SCI_SETSELBACK, 1, ScintillaPropertiesFile::ColourFromString(colour)); } else { if (selfore.GetLength()) SendEditor(SCI_SETSELBACK, 0, 0); else // Have to show selection somehow SendEditor(SCI_SETSELBACK, 1, RGB(0xC0, 0xC0, 0xC0)); } char bracesStyleKey[200]; sprintf(bracesStyleKey, "braces.%s.style", language); int bracesStyle = props.GetInt(bracesStyleKey, 0); char key[200]; CStringA sval; sprintf(key, "calltip.%s.ignorecase", "*"); sval = props.Get(key); bool callTipIgnoreCase = sval == "1"; sprintf(key, "calltip.%s.ignorecase", language); sval = props.Get(key); if (sval != "") callTipIgnoreCase = sval == "1"; sprintf(key, "autocomplete.%s.ignorecase", "*"); sval = props.Get(key); bool autoCompleteIgnoreCase = sval == "1"; sprintf(key, "autocomplete.%s.ignorecase", language); sval = props.Get(key); if (sval != "") autoCompleteIgnoreCase = sval == "1"; SendEditor(SCI_AUTOCSETIGNORECASE, autoCompleteIgnoreCase ? 1 : 0); int autoCChooseSingle = props.GetInt("autocomplete.choose.single"); SendEditor(SCI_AUTOCSETCHOOSESINGLE, autoCChooseSingle), // Set styles // For each window set the global default style, then the language default style, then the other global styles, then the other language styles SendEditor(SCI_STYLERESETDEFAULT, 0, 0); // SendOutput(SCI_STYLERESETDEFAULT, 0, 0); sprintf(key, "style.%s.%0d", "*", STYLE_DEFAULT); sval = props.Get(key); SetOneStyle(STYLE_DEFAULT, sval); // SetOneStyle(wOutput, STYLE_DEFAULT, sval); sprintf(key, "style.%s.%0d", language, STYLE_DEFAULT); sval = props.Get(key); SetOneStyle(STYLE_DEFAULT, sval); SendEditor(SCI_STYLECLEARALL, 0, 0); SetStyleFor("*"); SetStyleFor(language); // SendOutput(SCI_STYLECLEARALL, 0, 0); // sprintf(key, "style.%s.%0d", "errorlist", STYLE_DEFAULT); // sval = props.Get(key, ""); // SetOneStyle(wOutput, STYLE_DEFAULT, sval); // SendOutput(SCI_STYLECLEARALL, 0, 0); // SetStyleFor(wOutput, "*"); // SetStyleFor(wOutput, "errorlist"); // if (firstPropertiesRead) { ReadPropertiesInitial(); // } SendEditor(SCI_SETUSEPALETTE, props.GetInt("use.palette")); SendEditor(SCI_SETPRINTMAGNIFICATION, props.GetInt("print.magnification")); SendEditor(SCI_SETPRINTCOLOURMODE, props.GetInt("print.colour.mode")); int clearBeforeExecute = props.GetInt("clear.before.execute"); int blankMarginLeft = props.GetInt("blank.margin.left", 1); int blankMarginRight = props.GetInt("blank.margin.right", 1); //long marginCombined = Platform::LongFromTwoShorts(blankMarginLeft, blankMarginRight); SendEditor(SCI_SETMARGINLEFT, 0, blankMarginLeft); SendEditor(SCI_SETMARGINRIGHT, 0, blankMarginRight); // SendOutput(SCI_SETMARGINLEFT, 0, blankMarginLeft); // SendOutput(SCI_SETMARGINRIGHT, 0, blankMarginRight); SendEditor(SCI_SETMARGINWIDTHN, 1, margin ? marginWidth : 0); // SendEditor(SCI_SETMARGINWIDTHN, 0, lineNumbers ? lineNumbersWidth : 0); int bufferedDraw = props.GetInt("buffered.draw", 1); SendEditor(SCI_SETBUFFEREDDRAW, bufferedDraw); int bracesCheck = props.GetInt("braces.check"); int bracesSloppy = props.GetInt("braces.sloppy"); CStringA wordCharacters = props.Get("word.characters." + fileNameForExtension); if (wordCharacters.GetLength()) { SendEditorString(SCI_SETWORDCHARS, 0, wordCharacters); } else { SendEditor(SCI_SETWORDCHARS, 0, 0); } SendEditor(SCI_SETUSETABS, props.GetInt("use.tabs", 1)); int tabSize = props.GetInt("tabsize"); if (tabSize) { SendEditor(SCI_SETTABWIDTH, tabSize); } int indentSize = props.GetInt("indent.size"); SendEditor(SCI_SETINDENT, indentSize); int indentOpening = props.GetInt("indent.opening"); int indentClosing = props.GetInt("indent.closing"); CStringA lookback = props.Get("statement.lookback." + fileNameForExtension); int statementLookback = value(lookback); /* statementIndent = GetStyleAndWords("statement.indent."); statementEnd = GetStyleAndWords("statement.end."); blockStart = GetStyleAndWords("block.start."); blockEnd = GetStyleAndWords("block.end."); */ /* if (props.GetInt("vc.home.key", 1)) { AssignKey(SCK_HOME, 0, SCI_VCHOME); AssignKey(SCK_HOME, SCMOD_SHIFT, SCI_VCHOMEEXTEND); } else { AssignKey(SCK_HOME, 0, SCI_HOME); AssignKey(SCK_HOME, SCMOD_SHIFT, SCI_HOMEEXTEND); } AssignKey('L', SCMOD_SHIFT | SCMOD_CTRL, SCI_LINEDELETE); */ SendEditor(SCI_SETHSCROLLBAR, props.GetInt("horizontal.scrollbar", 1)); // SendOutput(SCI_SETHSCROLLBAR, props.GetInt("output.horizontal.scrollbar", 1)); int tabHideOne = props.GetInt("tabbar.hide.one"); // SetToolsMenu(); SendEditor(SCI_SETFOLDFLAGS, props.GetInt("fold.flags")); // To put the folder markers in the line number region //SendEditor(SCI_SETMARGINMASKN, 0, SC_MASK_FOLDERS); SendEditor(SCI_SETMODEVENTMASK, SC_MOD_CHANGEFOLD); // Create a margin column for the folding symbols SendEditor(SCI_SETMARGINTYPEN, 2, SC_MARGIN_SYMBOL); SendEditor(SCI_SETMARGINWIDTHN, 2, foldMargin ? foldMarginWidth : 0); SendEditor(SCI_SETMARGINMASKN, 2, SC_MASK_FOLDERS); SendEditor(SCI_SETMARGINSENSITIVEN, 2, 1); if (props.GetInt("fold.use.plus")) { SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_MINUS); SendEditor(SCI_MARKERSETFORE, SC_MARKNUM_FOLDEROPEN, RGB(0xff, 0xff, 0xff)); SendEditor(SCI_MARKERSETBACK, SC_MARKNUM_FOLDEROPEN, RGB(0, 0, 0)); SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_PLUS); SendEditor(SCI_MARKERSETFORE, SC_MARKNUM_FOLDER, RGB(0xff, 0xff, 0xff)); SendEditor(SCI_MARKERSETBACK, SC_MARKNUM_FOLDER, RGB(0, 0, 0)); } else { SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_ARROWDOWN); SendEditor(SCI_MARKERSETFORE, SC_MARKNUM_FOLDEROPEN, RGB(0, 0, 0)); SendEditor(SCI_MARKERSETBACK, SC_MARKNUM_FOLDEROPEN, RGB(0, 0, 0)); SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_ARROW); SendEditor(SCI_MARKERSETFORE, SC_MARKNUM_FOLDER, RGB(0, 0, 0)); SendEditor(SCI_MARKERSETBACK, SC_MARKNUM_FOLDER, RGB(0, 0, 0)); } /* if (extender) { extender->Clear(); char defaultDir[MAX_PATH]; GetDefaultDirectory(defaultDir, sizeof(defaultDir)); char scriptPath[MAX_PATH]; if (Exists(defaultDir, "SciTEGlobal.lua", scriptPath)) { // Found fglobal file in global directory extender->Load(scriptPath); } // Check for an extension script CStringA extensionFile = props.Get("extension.", fileNameForExtension); if (extensionFile.GetLength()) { // find file in local directory char docDir[MAX_PATH]; GetDocumentDirectory(docDir, sizeof(docDir)); if (Exists(docDir, extensionFile, scriptPath)) { // Found file in document directory extender->Load(scriptPath); } else if (Exists(defaultDir, extensionFile, scriptPath)) { // Found file in global directory extender->Load(scriptPath); } else if (Exists("", extensionFile, scriptPath)) { // Found as completely specified file name extender->Load(scriptPath); } } } */ // firstPropertiesRead = false; //DWORD dwEnd = timeGetTime(); //Platform::DebugPrintf("Properties read took %d\n", dwEnd - dwStart); return true; }
void DoRegistryPath(CStringA resToken) { int nBrace = -1; int nBraceCnt = 1; for (int i = 2; i < resToken.GetLength(); i++) { if (resToken.GetAt(i) == '{') nBraceCnt++; else if (resToken.GetAt(i) == '}') { nBraceCnt--; if (nBraceCnt == 0) { nBrace = i; break; } } } if (nBrace == -1) return; USES_CONVERSION; bool bIsPath = true; CStringA strRegPath = resToken.Mid(2, nBrace - 2); int nLength = strRegPath.GetLength(); if (nLength > 2 && strRegPath.Mid(nLength - 2).MakeLower() == "|p") { bIsPath = true; strRegPath = strRegPath.Mid(0, nLength - 2); } else if (nLength > 2 && strRegPath.Mid(nLength - 2).MakeLower() == "|f") { bIsPath = false; strRegPath = strRegPath.Mid(0, nLength - 2); } std::vector<CStringA> vecOutRegPaths; EnumRegistry(strRegPath, vecOutRegPaths); int cnt = vecOutRegPaths.size(); for (int i = 0; i < cnt; i++) { CStringA strFilePath; if (QueryRegistryValue(vecOutRegPaths.at(i), strFilePath)) { if (!bIsPath) { strFilePath.Replace('/', '\\'); int nEndSlash = strFilePath.ReverseFind('\\'); if (nEndSlash == -1) continue; strFilePath = strFilePath.Mid(0, nEndSlash); } strFilePath += resToken.Mid(nBrace + 1); DoFilePathName(strFilePath); } } }