25#include <wx/filename.h>
28 wxString* aResultPath )
30 wxCHECK_MSG( aPathA.IsAbsolute(),
false, aPathA.GetPath() + wxS(
" is not an absolute path." ) );
31 wxCHECK_MSG( aPathB.IsAbsolute(),
false, aPathB.GetPath() + wxS(
" 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(
const std::pair<const wxString, ENV_VAR_ITEM>& entry : *aEnvVars )
85 if( !wxFileName::DirExists( entry.second.GetValue() )
86 || !wxFileName::IsDirReadable( entry.second.GetValue() ) )
91 envPath.SetPath( entry.second.GetValue() );
97 int newDepth = envPath.GetDirs().GetCount();
100 if( newDepth > pathDepth )
102 pathDepth = newDepth;
103 varName = entry.first;
113 if( varName.IsEmpty() && !aProjectPath.IsEmpty()
114 && wxFileName( aProjectPath ).IsAbsolute() && wxFileName( aFilePath ).IsAbsolute() )
116 envPath.SetPath( aProjectPath );
122 if( varName.IsEmpty() )
124 normalizedFullPath = aFilePath.GetFullPath();
128 normalizedFullPath = wxString::Format(
"${%s}/", varName );
130 if( !remainingPath.IsEmpty() )
131 normalizedFullPath += remainingPath;
133 normalizedFullPath += aFilePath.GetFullName();
136 return normalizedFullPath;
153static wxString
createFilePath(
const wxString& aPath,
const wxString& aFileName )
155 wxString
path( aPath );
157 if( !
path.EndsWith( wxFileName::GetPathSeparator() ) )
158 path.Append( wxFileName::GetPathSeparator() );
160 return path + aFileName;
167 wxFileName full( aFileName );
169 if( full.IsAbsolute() )
170 return full.GetFullPath();
177 return fn.GetFullPath();
182 for(
const std::pair<const wxString, ENV_VAR_ITEM>& entry : *aEnvVars )
184 wxFileName fn(
createFilePath( entry.second.GetValue(), aFileName ) );
187 return fn.GetFullPath();
191 return wxEmptyString;
197 wxFileName fn( aFileName );
200 wxArrayString pdirs = prj.GetDirs();
201 wxArrayString fdirs = fn.GetDirs();
203 if( fdirs.size() < pdirs.size() )
206 for(
size_t i = 0; i < pdirs.size(); i++ )
208 if( fdirs[i] != pdirs[i] )
217 for(
size_t i = pdirs.size(); i < fdirs.size(); i++ )
218 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)
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.