//
// This method starts the parser that will either load one file
//	or many based on pszFilePath.
// Input: pszFilePath - FS path to KeyValue file(s) for parsing.
//						extentions are defined using .X
//
void CScriptParser::InitParser( const char *pszPath, bool bAllowNonEncryptedSearch /*=true*/, bool bAllowEncryptedSearch /*=true*/ )
{
	// If you hit this assert, check to see where your instancing 
	// CScriptParser, make sure it isn't before the filesystem inits
	Assert( filesystem );
	Assert( pszPath );

	// Have we already been parsed?
	// TODO: Maybe just issue a DevWarning here instead of bailing
	if( m_bParsed )
		return;

	// Copy the file path to tweak the extensions and fix it up
	char szFilePath[FILE_PATH_MAX_LENGTH];
	V_FixupPathName( szFilePath, FILE_PATH_MAX_LENGTH, pszPath );

	//Search for unencrypted files
	if( bAllowNonEncryptedSearch )
	{
		Q_SetExtension( szFilePath, GetNonEncryptedEXT(), FILE_PATH_MAX_LENGTH );
		SearchForFiles( szFilePath );
	}

	//Search for encrypted files
	if( bAllowEncryptedSearch )
	{
		Q_SetExtension( szFilePath, GetEncryptedEXT(), FILE_PATH_MAX_LENGTH );
		SearchForFiles( szFilePath );
	}

	m_bParsed = true;
}
Пример #2
0
void SearchForFiles(Index<String>& files, String dir, String mask, int readonly, Progress& pi) {
	FindFile ff(AppendFileName(dir, "*.*"));
	while(ff) {
		if(ff.IsFolder() && *ff.GetName() != '.')
			SearchForFiles(files, AppendFileName(dir, ff.GetName()), mask, readonly, pi);
		else
		if(ff.IsFile() && PatternMatchMulti(mask, ff.GetName())) {
			if(IsNull(readonly) || !!readonly == !!ff.IsReadOnly()) {
				if(pi.StepCanceled()) return;
				files.FindAdd(AppendFileName(dir, ff.GetName()));
			}
		}
		ff.Next();
	}
}
Пример #3
0
void SearchForFiles( const std::string& strSearchFileName, const std::string& strFilePath, const bool& bRecursive, 
	std::vector<std::string> &shortFileNames, std::vector<std::string> &paths)
{
    std::string strFoundFilePath;
    WIN32_FIND_DATA file;

    std::string strPathToSearch = strFilePath + "\\";

    HANDLE hFile = FindFirstFile((strPathToSearch + "*").c_str(), &file);
    if ( hFile != INVALID_HANDLE_VALUE )
    {
        do
        {
            std::string strTheNameOfTheFile = file.cFileName;

			if (strTheNameOfTheFile != "." && strTheNameOfTheFile != "..")
			{
				if ( file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
				{
					if( bRecursive )
					{
						SearchForFiles( strSearchFileName, strPathToSearch + strTheNameOfTheFile, bRecursive, shortFileNames, paths);
					}
				}
				else
				{
					if (strTheNameOfTheFile.find(strSearchFileName) != std::string::npos)
					{
						std::transform(strTheNameOfTheFile.begin(), strTheNameOfTheFile.end(), strTheNameOfTheFile.begin(), ::tolower);		
						shortFileNames.push_back(strTheNameOfTheFile);
						paths.push_back(strFilePath);
					}
				}
			}
        }
        while ( FindNextFile(hFile, &file) );

        FindClose( hFile );
    }
}
Пример #4
0
void Ide::FindInFiles(bool replace) {
	CodeEditor::FindReplaceData d = editor.GetFindReplaceData();
	CtrlRetriever rf;
	rf(ff.find, d.find)
	  (ff.replace, d.replace)
	  (ff.ignorecase, d.ignorecase)
	  (ff.samecase, d.samecase)
	  (ff.wholeword, d.wholeword)
	  (ff.wildcards, d.wildcards)
	  (ff.regexp, d.regexp)
	;
	WriteList(ff.find, d.find_list);
	WriteList(ff.replace, d.replace_list);
	ff.Sync();
	if(IsNull(~ff.folder))
		ff.folder <<= GetUppDir();
	ff.style <<= STYLE_NO_REPLACE;
	ff.Sync();
	ff.itext = editor.GetI();
	ff.Setup(replace);
	
	int c = ff.Execute();

	ff.find.AddHistory();
	ff.replace.AddHistory();

	rf.Retrieve();
	d.find_list = ReadList(ff.find);
	d.replace_list = ReadList(ff.replace);
	editor.SetFindReplaceData(d);
	
	if(c == IDOK) {
		ffound.HeaderTab(2).SetText("Source line");
		Renumber();
		ff.find.AddHistory();
		ff.files.AddHistory();
		ff.folder.AddHistory();
		ff.replace.AddHistory();
		Progress pi("Found %d files to search.");
		pi.AlignText(ALIGN_LEFT);
		Index<String> files;
		if(ff.workspace) {
			const Workspace& wspc = GetIdeWorkspace();
			for(int i = 0; i < wspc.GetCount(); i++)
				SearchForFiles(files, GetFileFolder(PackagePath(wspc[i])),
					           ~ff.files, ~ff.readonly, pi);
		}
		else
			SearchForFiles(files, NormalizePath(~~ff.folder, GetUppDir()), ~ff.files, ~ff.readonly, pi);
		if(!pi.Canceled()) {
			String pattern;
			RegExp rx, *regexp = NULL;
			if(ff.regexp) {
				rx.SetPattern(~ff.find);
				regexp = &rx;
				pattern = "dummy";
			}
			else
			if(ff.wildcards) {
				String q = ~ff.find;
				for(const char *s = q; *s; s++)
					if(*s == '\\') {
						s++;
						if(*s == '\0') break;
						pattern.Cat(*s);
					}
					else
					switch(*s) {
					case '*': pattern.Cat(WILDANY); break;
					case '?': pattern.Cat(WILDONE); break;
					case '%': pattern.Cat(WILDSPACE); break;
					case '#': pattern.Cat(WILDNUMBER); break;
					case '$': pattern.Cat(WILDID); break;
					default:  pattern.Cat(*s);
					}
			}
			else
				pattern = ~ff.find;
			pi.SetTotal(files.GetCount());
			ShowConsole2();
			ffound.Clear();
			pi.SetPos(0);
			int n = 0;
			for(int i = 0; i < files.GetCount(); i++) {
				pi.SetText(files[i]);
				if(pi.StepCanceled()) break;
				if(!IsNull(pattern)) {
					if(!SearchInFile(files[i], pattern, ff.wholeword, ff.ignorecase, n, regexp))
						break;
				}
				else {
					ErrorInfo f;
					f.file = files[i];
					f.lineno = 1;
					f.linepos = 0;
					f.kind = 0;
					f.message = files[i];
					ffound.Add(f.file, 1, f.message, RawToValue(f));
					ffound.Sync();
					n++;
				}
			}
			if(!IsNull(pattern))
				ffound.Add(Null, Null, AsString(n) + " occurrence(s) have been found.");
			else
				ffound.Add(Null, Null, AsString(n) + "  matching file(s) have been found.");
			ffound.HeaderTab(2).SetText(Format("Source line (%d)", ffound.GetCount()));
		}
	}
}