25 #include <wx/filename.h> 28 wxString* aResultPath )
30 wxCHECK_MSG( aPathA.IsAbsolute(),
false, aPathA.GetPath() + wxT(
" is not an absolute path." ) );
31 wxCHECK_MSG( aPathB.IsAbsolute(),
false, aPathB.GetPath() + wxT(
" is not an absolute path." ) );
33 if( aPathA.GetPath() == aPathB.GetPath() )
38 if( ( aPathA.GetDirCount() > aPathB.GetDirCount() )
39 || ( aPathA.HasVolume() && !aPathB.HasVolume() )
40 || ( !aPathA.HasVolume() && aPathB.HasVolume() )
41 || ( ( aPathA.HasVolume() && aPathB.HasVolume() )
42 && ( aPathA.GetVolume().CmpNoCase( aPathB.GetVolume() ) != 0 ) ) )
45 wxArrayString aDirs = aPathA.GetDirs();
46 wxArrayString bDirs = aPathB.GetDirs();
50 while( i < aDirs.GetCount() )
52 if( aDirs[i] != bDirs[i] )
60 while( i < bDirs.GetCount() )
62 *aResultPath += bDirs[i] + wxT(
"/" );
72 const wxString& aProjectPath )
76 wxString remainingPath;
77 wxString normalizedFullPath;
82 for(
auto& entry : *aEnvVars )
85 if( !wxFileName::DirExists( entry.second.GetValue() )
86 || !wxFileName::IsDirReadable( entry.second.GetValue() ) )
89 envPath.SetPath( entry.second.GetValue() );
95 int newDepth = envPath.GetDirs().GetCount();
98 if( newDepth > pathDepth )
100 pathDepth = newDepth;
101 varName = entry.first;
111 if( varName.IsEmpty() && !aProjectPath.IsEmpty()
112 && wxFileName( aProjectPath ).IsAbsolute() && wxFileName( aFilePath ).IsAbsolute() )
114 envPath.SetPath( aProjectPath );
120 if( varName.IsEmpty() )
122 normalizedFullPath = aFilePath.GetFullPath();
128 if( !remainingPath.IsEmpty() )
129 normalizedFullPath += remainingPath;
131 normalizedFullPath += aFilePath.GetFullName();
134 return normalizedFullPath;
151 static wxString
createFilePath(
const wxString& aPath,
const wxString& aFileName )
153 wxString
path( aPath );
155 if( !
path.EndsWith( wxFileName::GetPathSeparator() ) )
156 path.Append( wxFileName::GetPathSeparator() );
158 return path + aFileName;
165 wxFileName full( aFileName );
167 if( full.IsAbsolute() )
168 return full.GetFullPath();
175 return fn.GetFullPath();
180 for(
auto& entry : *aEnvVars )
182 wxFileName fn(
createFilePath( entry.second.GetValue(), aFileName ) );
185 return fn.GetFullPath();
189 return wxEmptyString;
195 wxFileName fn( aFileName );
198 wxArrayString pdirs = prj.GetDirs();
199 wxArrayString fdirs = fn.GetDirs();
201 if( fdirs.size() < pdirs.size() )
204 for(
size_t i = 0; i < pdirs.size(); i++ )
206 if( fdirs[i] != pdirs[i] )
215 for(
size_t i = pdirs.size(); i < fdirs.size(); i++ )
216 aSubPath->AppendDir( fdirs[i] );
wxString ResolveFile(const wxString &aFileName, const ENV_VAR_MAP *aEnvVars, const PROJECT *aProject)
Search the default paths trying to find one with the requested file.
Container for project specific data.
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
virtual const wxString GetProjectPath() const
Return the full path of the project.
static wxString createFilePath(const wxString &aPath, const wxString &aFileName)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
bool PathIsInsideProject(const wxString &aFileName, const PROJECT *aProject, wxFileName *aSubPath)
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalize a file path to an environmental variable, if possible.
static bool normalizeAbsolutePaths(const wxFileName &aPathA, const wxFileName &aPathB, wxString *aResultPath)