Example #1
0
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
}
Example #2
0
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;
}
Example #3
0
wxFileName wxDirName::Combine(const wxFileName &right) const
{
    pxAssertMsg(IsDir(), L"Warning: Malformed directory name detected during wxDirName concatenation.");
    if (right.IsAbsolute())
        return right;

    // Append any directory parts from right, and then set the filename.
    // Except we can't do that because our m_members are private (argh!) and there is no API
    // for getting each component of the path.  So instead let's use Normalize:

    wxFileName result(right);
    result.Normalize(wxPATH_NORM_ENV_VARS | wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE, GetPath());
    return result;
}
Example #4
0
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());
}
Example #5
0
// 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;
}
Example #6
0
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;
}
FilePath FilePath::FromAbsoluteWx(const wxFileName& wxFn){
  assert(wxFn.IsAbsolute());
  assert(!wxFn.IsDir());
  return FilePath(new PathImpl(wxFn));
}