//***************************************************************************************** // Copyright (c) 2017 Wil van Antwerpen // All rights reserved, LGPL license // // // $FileName : cSourceFilesList.pkg // $ProjectName : Hammer 3 // $Author : Wil van Antwerpen // $Created : 2017-10-10 // // Contents: // An object that finds all the current source files from th workspace // so that they can be used in a autocomplete list. // $Rev History // //***************************************************************************************** //TH-RevisionStart //TH-RevisionEnd Use cFileSystem.pkg Use vWin32fh.pkg Struct tSourceFile String sFileName String sPath String sSearchPath End_Struct Class cSourceFilesList Is a cObject Procedure Construct_Object Forward Send Construct_Object Property tSourceFile[] pSourceFiles Property String[] pExcludePaths // contains paths that should be excluded, paths should not have a trailing path separator! End_Procedure // Construct_Object Function PathOnExcludeList String sPath Returns Boolean Boolean bOnList Integer iPath Integer iPathCount String[] ExcludePaths Move False To bOnList Get pExcludePaths to ExcludePaths Move (SizeOfArray(ExcludePaths)) To iPathCount For iPath from 0 To (iPathCount-1) If (Lowercase(sPath)=lowercase(ExcludePaths[iPath])) Begin Move True To bOnList Move iPathCount To iPath End Loop Function_Return bOnList End_Function Procedure SearchDirectory String sSearchPath Boolean bRecursive String[] ByRef Files String sPath String sMask String sExt Integer iFiles Integer iFile Handle hoFS tsSearchResult[] SR Get ParseFolderName sSearchpath to sPath Get ParseFileName sSearchPath to sMask Get Create (RefClass(cFilesystem)) to hoFS If (hoFS) Begin Get FileSearch of hoFS (sPath+sMask) to SR Move (SizeOfArray(SR)) To iFiles For iFile From 0 To (iFiles-1) If (SR[iFile].sFilename<>"." and SR[iFile].sFilename<>"..") Begin If ((SR[iFile].iFileAttributes iAND FILE_ATTRIBUTE_DIRECTORY)=FILE_ATTRIBUTE_DIRECTORY) Begin If (bRecursive) Begin If (PathOnExcludeList(Self,SR[iFile].sFilename)=false) Begin Send SearchDirectory (sPath+SR[iFile].sFileName+"\"+sMask) True (&Files) End End End Else Begin Get ParseFileExtension SR[iFile].sFileName To sExt Move (Lowercase(sExt)) To sExt If (sExt<>"bak" and sExt<>"dat" and sExt<>"hdr" and sExt<>"k1") Begin // just filter most common rest is filtered out later Move (sPath+SR[iFile].sFilename) To Files[SizeOfArray(Files)] End End End Loop Send Destroy of hoFS End End_Procedure Procedure AddFilteredFiles String sSearchPath String sFilter String[] ByRef Files tSourceFile[] ByRef SourceFiles Integer iFile Integer iFileCount Integer iCount String sExt Move (SizeOfArray(Files)) To iFileCount For iFile From 0 To (iFileCount-1) Get ParseFileExtension Files[iFile] To sExt If (Pos(Uppercase(sExt),sFilter)) Begin Move (SizeOfArray(SourceFiles)) To iCount Get ParseFolderName Files[iFile] to SourceFiles[iCount].sPath Get ParseFileName Files[iFile] To SourceFiles[iCount].sFileName Move sSearchPath To SourceFiles[iCount].sSearchPath End Loop End_Procedure Procedure AddPathToExcludeList String sPath String[] ByRef ExcludePaths Move (Trim(sPath)) To sPath If (Right(sPath,1)="\") Move (Left(sPath,Length(sPath)-1)) To sPath If (sPath<>"") Begin Move sPath To ExcludePaths[SizeOfArray(ExcludePaths)] End End_Procedure Function MakeRelativePath String sFullPath Returns String Integer iPos Integer iLength String sRemove String sPath String sHome String sWSFile String sBase Move "" To sPath Get CurrentWSFile of ghoWorkSpaceHandlerEx to sWSFile Get CurrentHomePath of ghoWorkspaceHandlerEx to sHome Get ParseFolderName sWSfile To sBase If (sHome=".." or sHome="..\") Begin // not perfect, but most home paths are just this Get vParentPath sBase to sBase End If (sBase<>"") Begin Move (Trim(Lowercase(sBase))) To sBase Get vFolderFormat sBase to sBase Move (Pos(sBase,Lowercase(sFullPath))) To iPos If (iPos<>0) Begin Move (Length(sBase)) To iLength Move (Left(sFullPath,iLength)) To sRemove Move (Replace(sRemove,sFullPath,"")) To sPath End End Function_Return sPath End_Function Procedure DefineExcludePaths String sSearchPath String[] saExcludes Integer iFolder Integer iFolders String sWSFile String sBase String sWSPath String sPath String[] ExcludePaths Move (ResizeArray(ExcludePaths,0)) To ExcludePaths // exclude source control paths to speed up things, always add these by default Move ".svn" To ExcludePaths[0] Move ".git" To ExcludePaths[1] Move ".hg" To ExcludePaths[2] // No need to list the files under an SCTBackup folder either Move "SCTBackup" To ExcludePaths[3] Get CurrentWSFile of ghoWorkSpaceHandlerEx to sWSFile Get ParseFolderName sWSfile To sBase If (Pos(Lowercase(sSearchPath),Lowercase(sBase))>0) Begin Get CurrentIdeSrcPath of ghoWorkSpaceHandlerEx to sWSPath // IdeSrc should have no source files Get MakeRelativePath sWSPath to sPath Send AddPathToExcludeList sPath (&ExcludePaths) Get CurrentProgramPath of ghoWorkSpaceHandlerEx to sWSPath // same for program Get MakeRelativePath sWSPath to sPath Send AddPathToExcludeList sPath (&ExcludePaths) Get CurrentBitmapPath of ghoWorkSpaceHandlerEx to sWSPath // and bitmap Get MakeRelativePath sWSPath to sPath Send AddPathToExcludeList sPath (&ExcludePaths) Get CurrentHelpPath of ghoWorkSpaceHandlerEx to sWSPath // and help Get MakeRelativePath sWSPath to sPath Send AddPathToExcludeList sPath (&ExcludePaths) End Move (SizeOfArray(saExcludes)) to iFolders For iFolder From 0 to (iFolders-1) Move "" To sPath Move saExcludes[iFolder] To sWSPath If (Pos(Lowercase(sSearchPath),Lowercase(sWSPath))>0) Begin Get MakeRelativePath sWSPath to sPath End Else If (Pos("\",sWSPath)=0) Begin // you can just add a local path to the exclude list eg: "DDSrc" Move sWSPath To sPath End Send AddPathToExcludeList sPath (&ExcludePaths) Loop Set pExcludePaths to ExcludePaths End_Procedure // Tests if the current package runtime folder is already in the list // and if not, it will add it, so the DataFlex framework files do show // up as well. Procedure AddRuntimePackageFolder String[] ByRef saFolders Boolean bHasDirPKG Integer iFolder Integer iFolders String sPath String sDirPKG Move False To bHasDirPKG Move (SizeOfArray(saFolders)) To iFolders Get CurrentRuntimePkgPath Of ghoWorkSpaceHandlerEx To sDirPKG Get vFolderFormat sDirPKG to sDirPKG For iFolder From 0 To (iFolders-1) Move saFolders[iFolder] To sPath Get vFolderFormat sPath To sPath If (lowercase(sPath)=lowercase(sDirPKG)) Begin Move iFolders To iFolder Move True to bHasDirPKG End Loop If (bHasDirPKG=false) Begin Move sDirPKG To saFolders[iFolders] End End_Procedure // // Find all source files that match the settings in the THWorkspace // Function EnumerateFilesInWorkspace Returns tSourceFile[] Integer iFolder Integer iFolders Integer iType String sPath String sFilter String[] Filters String[] Files tSourceFile[] SourceFiles tTHWorkspace THWorkspace Move "" To sFilter Move (ResizeArray(SourceFiles,0)) To SourceFiles Get pTHWorkspace Of ghoApplication To THWorkspace Move THWorkspace.saFiles To Filters For iType From 0 To (SizeOfArray(Filters)-1) Move (sFilter+Uppercase(Filters[iType])+";") To sFilter Loop Send AddRuntimePackageFolder (&THWorkspace.saFolders) Move (SizeOfArray(THWorkspace.saFolders)) To iFolders For iFolder from 0 to (iFolders-1) Move (ResizeArray(Files,0)) To Files Move THWorkspace.saFolders[iFolder] To sPath Get vFolderFormat sPath to sPath Send DefineExcludePaths sPath THWorkspace.saExclude Send SearchDirectory (sPath+"*.*") True (&Files) Send AddFilteredFiles sPath sFilter (&Files) (&SourceFiles) Loop Function_Return SourceFiles End_Function End_Class // cSourceFilesList Object oSourceFilesList Is a cSourceFilesList End_Object