void Path::CreateDirectoryPath(const wxFileName &path){ if(!path.IsDir() || path.DirExists()) return; wxArrayString folders = path.GetDirs(); wxString workingpath; //We need to do things differently with a unc path if(path.GetFullPath().Left(2) == "\\\\") workingpath = "\\\\?\\UNC\\" + path.GetVolume() + "\\"; else workingpath = "\\\\?\\" + path.GetVolume() + wxFileName::GetVolumeSeparator() + wxFILE_SEP_PATH; for(unsigned int i = 0; i < folders.GetCount(); i++){ workingpath = workingpath + folders.Item(i) + wxFILE_SEP_PATH; #ifdef __WXMSW__ if(!wxDirExists(workingpath) && !CreateDirectory(workingpath.fn_str(), NULL)){ #else if(!wxDirExists(workingpath) && !wxMkdir(workingpath)){ #endif wxLogError(_("Could not create") + " " + workingpath); } } } wxFileName Path::Normalise(const wxFileName &filename){ wxString path = Path::Normalise(filename.GetFullPath()); return wxFileName(path); }
// Checks whether 'suffix' could be a suffix of 'path' and therefore represents // the same path. This is used to check whether a relative path could represent // the same path as absolute path. For instance, for // suffix = sdk/globals.cpp // path = /home/user/codeblocks/trunk/src/sdk/globals.cpp // it returns true. The function expects that 'path' is normalized and compares // 'path' with 'suffix' starting from the end of the path. When it reaches .. in // 'suffix' it gives up (there is no way to check relative filename names // exactly) and if the path compared so far is identical, it returns true bool IsSuffixOfPath(wxFileName const & suffix, wxFileName const & path) { if (path.GetFullName() != suffix.GetFullName()) { return false; } wxArrayString suffixDirArray = suffix.GetDirs(); wxArrayString pathDirArray = path.GetDirs(); int j = pathDirArray.GetCount() - 1; for (int i = suffixDirArray.GetCount() - 1; i >= 0; i--) { if (suffixDirArray[i] == _T(".") || suffixDirArray[i] == _T("")) { // skip paths like /./././ and //// continue; } if (j < 0) { // suffix has more directories than path - cannot represent the same path return false; } if (suffixDirArray[i] == _T("..")) { // suffix contains ".." - from now on we cannot precisely determine // whether suffix and path match - we assume that they do return true; } else if (suffixDirArray[i] != pathDirArray[j]) { // the corresponding directories of the two paths differ return false; } j--; } if (suffix.IsAbsolute() && (j >= 0 || suffix.GetVolume() != path.GetVolume())) { return false; } // 'suffix' is a suffix of 'path' return true; }
wxString eDocumentPath::WinPathToCygwin(const wxFileName& path) { wxASSERT(path.IsOk() && path.IsAbsolute()); #ifndef __WXMSW__ return path.GetFullPath(); #else wxString fullpath = path.GetFullPath(); // Check if we have a foward-slash unc path; cygwin can handle these directly. if (fullpath.StartsWith(wxT("//"))) { return fullpath; } // Check if we have a backslash unc path; convert to forward slash and pass on. if (fullpath.StartsWith(wxT("\\\\"))) { fullpath.Replace(wxT("\\"), wxT("/")); return fullpath; } // Convert C:\... to /cygdrive/c/... wxString unixPath = eDocumentPath::s_cygdrivePrefix + path.GetVolume().Lower(); // Convert slashs in path segments const wxArrayString& dirs = path.GetDirs(); for (unsigned int i = 0; i < dirs.GetCount(); ++i) { unixPath += wxT('/') + dirs[i]; } // Add the filename, if there is one if (path.HasName()) unixPath += wxT('/') + path.GetFullName(); return unixPath; #endif }
static bool normalizeAbsolutePaths( const wxFileName& aPathA, const wxFileName& aPathB, wxString* aResultPath ) { wxCHECK_MSG( aPathA.IsAbsolute(), false, aPathA.GetPath() + " is not an absolute path." ); wxCHECK_MSG( aPathB.IsAbsolute(), false, aPathB.GetPath() + " is not an absolute path." ); if( aPathA.GetPath() == aPathB.GetPath() ) return true; if( ( aPathA.GetDirCount() > aPathB.GetDirCount() ) || ( aPathA.HasVolume() && !aPathB.HasVolume() ) || ( !aPathA.HasVolume() && aPathB.HasVolume() ) || ( ( aPathA.HasVolume() && aPathB.HasVolume() ) && ( aPathA.GetVolume() != aPathB.GetVolume() ) ) ) return false; wxArrayString aDirs = aPathA.GetDirs(); wxArrayString bDirs = aPathB.GetDirs(); size_t i = 0; while( i < aDirs.GetCount() ) { if( aDirs[i] != bDirs[i] ) return false; i++; } if( aResultPath ) { while( i < bDirs.GetCount() ) { *aResultPath += bDirs[i] + wxT( "/" ); i++; } } return true; }
void IniLoader::Entry( const wxString& var, wxFileName& value, const wxFileName defvalue, bool isAllowRelative ) { wxString dest( defvalue.GetFullPath() ); if( m_Config ) m_Config->Read( var, &dest, defvalue.GetFullPath() ); value = dest; if( isAllowRelative ) value = g_fullBaseDirName + value; if( value.IsAbsolute() ) value.Normalize(); if (value.HasVolume()) value.SetVolume(value.GetVolume().Upper()); }
wxString WinPathToCygwin(const wxFileName& path) { // static wxASSERT(path.IsOk() && path.IsAbsolute()); // Drive wxString unixPath = wxT("/cygdrive/"); unixPath += path.GetVolume().Lower(); // Dirs const wxArrayString& dirs = path.GetDirs(); for (unsigned int i = 0; i < dirs.GetCount(); ++i) { unixPath += wxT('/') + dirs[i]; } // Filename if (path.HasName()) { unixPath += wxT('/') + path.GetFullName(); } return unixPath; }