25#include <wx/filename.h>
28 wxString* aResultPath )
30 wxCHECK_MSG( aPathA.IsAbsolute(),
false,
31 aPathA.GetPath() + wxS(
" is not an absolute path." ) );
32 wxCHECK_MSG( aPathB.IsAbsolute(),
false,
33 aPathB.GetPath() + wxS(
" is not an absolute path." ) );
35 if( aPathA.GetPath() == aPathB.GetPath() )
40 if( ( aPathA.GetDirCount() > aPathB.GetDirCount() )
41 || ( aPathA.HasVolume() && !aPathB.HasVolume() )
42 || ( !aPathA.HasVolume() && aPathB.HasVolume() )
43 || ( ( aPathA.HasVolume() && aPathB.HasVolume() )
44 && ( aPathA.GetVolume().CmpNoCase( aPathB.GetVolume() ) != 0 ) ) )
47 wxArrayString aDirs = aPathA.GetDirs();
48 wxArrayString bDirs = aPathB.GetDirs();
52 while( i < aDirs.GetCount() )
54 if( aDirs[i] != bDirs[i] )
62 while( i < bDirs.GetCount() )
64 *aResultPath += bDirs[i] + wxT(
"/" );
74 const wxString& aProjectPath )
78 wxString remainingPath;
79 wxString normalizedFullPath;
84 for(
const std::pair<const wxString, ENV_VAR_ITEM>& entry : *aEnvVars )
87 if( !wxFileName::DirExists( entry.second.GetValue() )
88 || !wxFileName::IsDirReadable( entry.second.GetValue() ) )
93 envPath.SetPath( entry.second.GetValue() );
99 int newDepth = envPath.GetDirs().GetCount();
102 if( newDepth > pathDepth )
104 pathDepth = newDepth;
105 varName = entry.first;
115 if( varName.IsEmpty() && !aProjectPath.IsEmpty()
116 && wxFileName( aProjectPath ).IsAbsolute() && wxFileName( aFilePath ).IsAbsolute() )
118 envPath.SetPath( aProjectPath );
124 if( varName.IsEmpty() )
126 normalizedFullPath = aFilePath.GetFullPath();
130 normalizedFullPath = wxString::Format(
"${%s}/", varName );
132 if( !remainingPath.IsEmpty() )
133 normalizedFullPath += remainingPath;
135 normalizedFullPath += aFilePath.GetFullName();
138 return normalizedFullPath;
155static wxString
createFilePath(
const wxString& aPath,
const wxString& aFileName )
157 wxString
path( aPath );
159 if( !
path.EndsWith( wxFileName::GetPathSeparator() ) )
160 path.Append( wxFileName::GetPathSeparator() );
162 return path + aFileName;
169 wxFileName full( aFileName );
171 if( full.IsAbsolute() )
172 return full.GetFullPath();
179 return fn.GetFullPath();
184 for(
const std::pair<const wxString, ENV_VAR_ITEM>& entry : *aEnvVars )
186 wxFileName fn(
createFilePath( entry.second.GetValue(), aFileName ) );
189 return fn.GetFullPath();
193 return wxEmptyString;
199 wxFileName fn( aFileName );
202 wxArrayString pdirs = prj.GetDirs();
203 wxArrayString fdirs = fn.GetDirs();
205 if( fdirs.size() < pdirs.size() )
208 for(
size_t i = 0; i < pdirs.size(); i++ )
210 if( fdirs[i] != pdirs[i] )
219 for(
size_t i = pdirs.size(); i < fdirs.size(); i++ )
220 aSubPath->AppendDir( fdirs[i] );
Container for project specific data.
virtual const wxString GetProjectPath() const
Return the full path of the project.
static bool normalizeAbsolutePaths(const wxFileName &aPathA, const wxFileName &aPathB, wxString *aResultPath)
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalize a file path to an environmental variable, if possible.
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.
static wxString createFilePath(const wxString &aPath, const wxString &aFileName)
bool PathIsInsideProject(const wxString &aFileName, const PROJECT *aProject, wxFileName *aSubPath)
Helper functions to substitute paths with environmental variables.
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.