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;
154 wxFileName fn( aPath );
155 wxFileName base = wxFileName::DirName( aBaseDir );
157 if( aBaseDir.IsEmpty() || !fn.IsAbsolute() || !base.IsAbsolute() )
160 if( wxFileName::DirName( aPath ).SameAs( base ) )
163 if( !fn.MakeRelativeTo( base.GetPath() ) )
166 return fn.GetFullPath( wxPATH_UNIX );
171 const wxString& aProjectPath,
bool aAllowParentDirs )
173 wxFileName fn( aPath );
175 if( !fn.IsAbsolute() )
180 if( relPath != aPath && relPath != wxS(
".." ) && !relPath.StartsWith( wxS(
"../" ) ) )
184 wxString envPath =
NormalizePath( fn, aEnvVars, wxEmptyString );
186 if( envPath != fn.GetFullPath() || !aAllowParentDirs )
196static wxString
createFilePath(
const wxString& aPath,
const wxString& aFileName )
198 wxString
path( aPath );
200 if( !
path.EndsWith( wxFileName::GetPathSeparator() ) )
201 path.Append( wxFileName::GetPathSeparator() );
203 return path + aFileName;
210 wxFileName full( aFileName );
212 if( full.IsAbsolute() )
213 return full.GetFullPath();
220 return fn.GetFullPath();
225 for(
const std::pair<const wxString, ENV_VAR_ITEM>& entry : *aEnvVars )
227 wxFileName fn(
createFilePath( entry.second.GetValue(), aFileName ) );
230 return fn.GetFullPath();
234 return wxEmptyString;
240 wxFileName fn( aFileName );
243 wxArrayString pdirs = prj.GetDirs();
244 wxArrayString fdirs = fn.GetDirs();
246 if( fdirs.size() < pdirs.size() )
249 for(
size_t i = 0; i < pdirs.size(); i++ )
251 if( fdirs[i] != pdirs[i] )
260 for(
size_t i = pdirs.size(); i < fdirs.size(); i++ )
261 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.
wxString MakeRelativePath(const wxString &aPath, const wxString &aBaseDir)
Express an absolute path relative to a base directory, stepping out with ".." when needed.
wxString NormalizePathForProject(const wxString &aPath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath, bool aAllowParentDirs)
Choose how to store a path the user picked for a project.
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.