26 wxString* aResultPath )
28 wxCHECK_MSG( aPathA.IsAbsolute(),
false, aPathA.GetPath() +
" is not an absolute path." );
29 wxCHECK_MSG( aPathB.IsAbsolute(),
false, aPathB.GetPath() +
" is not an absolute path." );
31 if( aPathA.GetPath() == aPathB.GetPath() )
34 if( ( aPathA.GetDirCount() > aPathB.GetDirCount() )
35 || ( aPathA.HasVolume() && !aPathB.HasVolume() )
36 || ( !aPathA.HasVolume() && aPathB.HasVolume() )
37 || ( ( aPathA.HasVolume() && aPathB.HasVolume() )
38 && ( aPathA.GetVolume() != aPathB.GetVolume() ) ) )
41 wxArrayString aDirs = aPathA.GetDirs();
42 wxArrayString bDirs = aPathB.GetDirs();
46 while( i < aDirs.GetCount() )
48 if( aDirs[i] != bDirs[i] )
56 while( i < bDirs.GetCount() )
58 *aResultPath += bDirs[i] + wxT(
"/" );
68 const wxString& aProjectPath )
72 wxString remainingPath;
73 wxString normalizedFullPath;
78 for(
auto& entry : *aEnvVars )
81 if( !wxFileName::DirExists( entry.second.GetValue() )
82 || !wxFileName::IsDirReadable( entry.second.GetValue() ) )
85 envPath.SetPath( entry.second.GetValue() );
90 int newDepth = envPath.GetDirs().GetCount();
93 if( newDepth > pathDepth )
96 varName = entry.first;
103 if( varName.IsEmpty() && !aProjectPath.IsEmpty()
104 && wxFileName( aProjectPath ).IsAbsolute() && wxFileName( aFilePath ).IsAbsolute() )
106 envPath.SetPath( aProjectPath );
112 if( !varName.IsEmpty() )
116 if( !remainingPath.IsEmpty() )
117 normalizedFullPath += remainingPath;
119 normalizedFullPath += aFilePath.GetFullName();
122 return normalizedFullPath;
139 static wxString
createFilePath(
const wxString& aPath,
const wxString& aFileName )
141 wxString path( aPath );
143 if( !path.EndsWith( wxFileName::GetPathSeparator() ) )
144 path.Append( wxFileName::GetPathSeparator() );
146 return path + aFileName;
153 wxFileName full( aFileName );
155 if( full.IsAbsolute() )
156 return full.GetFullPath();
163 return fn.GetFullPath();
168 for(
auto& entry : *aEnvVars )
170 wxFileName fn(
createFilePath( entry.second.GetValue(), aFileName ) );
173 return fn.GetFullPath();
177 return wxEmptyString;
183 wxFileName fn( aFileName );
186 wxArrayString pdirs = prj.GetDirs();
187 wxArrayString fdirs = fn.GetDirs();
189 if( fdirs.size() < pdirs.size() )
192 for(
size_t i = 0; i < pdirs.size(); i++ )
194 if( fdirs[i] != pdirs[i] )
203 for(
size_t i = pdirs.size(); i < fdirs.size(); i++ )
204 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.
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
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.
bool PathIsInsideProject(const wxString &aFileName, const PROJECT *aProject, wxFileName *aSubPath)
Check if a given filename is within a given project directory (not whether it exists!...
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)