/**
 * comparator function that compares 2 filenames by using the full name
 * only (wxFileName::GetDirs().Last())
 */
static bool DirNameCmp(const wxFileName& a, const wxFileName& b) {
    if (a.GetDirCount() == 0) {
        return true;
    }
    if (b.GetDirCount() == 0) {
        return false;
    }
    wxString aName = a.GetDirs().Last();
    wxString bName = b.GetDirs().Last();
    return aName.compare(bName) < 0;
}
Example #2
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 #3
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 #4
0
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);
}
Example #5
0
void BundlePane::OnMenuExport(wxCommandEvent& WXUNUSED(event)) {
	const wxTreeItemId selItem = m_bundleTree->GetSelection();
	if (!selItem.IsOk()) return;
	
	// Get the item name
	const BundleItemData* data = (BundleItemData*)m_bundleTree->GetItemData(selItem);
	wxString name;
	if (data->IsBundle()) {
		const wxFileName bundlePath = m_plistHandler.GetBundlePath(data->m_bundleId);
		name = bundlePath.GetDirs().Last();
	}
	else {
		const wxFileName bundlePath = m_plistHandler.GetBundleItemPath(data->m_type, data->m_bundleId, data->m_itemId);
		name = bundlePath.GetFullName();
	}

	// Get destination path from user
	const wxString msg = data->IsBundle() ? _("Export Bundle as..") : _("Export Bundle Item as");
	wxFileDialog dlg(this, msg, wxEmptyString, name, wxFileSelectorDefaultWildcardStr, wxFD_SAVE);
	if (dlg.ShowModal() != wxID_OK) return;
	const wxString path = dlg.GetPath();
	if (path.empty()) return;

	// Export the item
	if (data->IsBundle()) {
		wxFileName dstPath;
		dstPath.AssignDir(path);
		m_plistHandler.ExportBundle(dstPath, data->m_bundleId);
	}
	else m_plistHandler.ExportBundleItem(path, data->m_type, data->m_bundleId, data->m_itemId);
}
Example #6
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 #7
0
/*
    $(prefix)/share/doc/mmex
*/
const wxFileName mmex::GetDocDir()
{
    static wxFileName fname;

    if (!fname.IsOk()) 
    {
        fname = GetSharedDir();

        const wxArrayString &dirs = fname.GetDirs();
        if (dirs.Last().Lower() == GetAppName())
            fname.RemoveLastDir(); // mmex folder

        fname.AppendDir("doc");
        fname.AppendDir(GetAppName());
    }

    return fname;
}
Example #8
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;
}
Example #9
0
bool NewFileDialog::GetIsFileNameValid(const wxFileName& fileName) const
{

    if (!fileName.IsOk())
    {
        return false;
    }

    // Check if the file name has illegal characters in it.

    wxString forbidden = fileName.GetForbiddenChars();

    const wxArrayString dirs = fileName.GetDirs();

    for (unsigned int i = 0; i < dirs.Count(); ++i)
    {
        for (unsigned int j = 0; j < dirs[i].Length(); ++j)
        {
            if (forbidden.Find(dirs[i][j]) != wxNOT_FOUND)
            {
                return false;
            }
        }
    }

    wxString fullName = fileName.GetFullName();

    for (unsigned int j = 0; j < fullName.Length(); ++j)
    {
        if (forbidden.Find(fullName[j]) != wxNOT_FOUND)
        {
            return false;
        }
    }

    return true;

}
Example #10
0
void AddFilesDialog::AddDir(const wxString& path, const wxFileName& base_offset)
{
	if (::wxDirExists(path))
	{
		if (this->progress)
			this->progress->Update(0, "Adding " + path);

		::wxSafeYield();

		wxDir d(path);

		if (d.IsOpened() && d.HasFiles())
		{
			wxString file;
			bool cont = d.GetFirst(&file);

			while (cont)
			{
				wxFileName fn(path, file);
				
				if (fn.DirExists())
				{
					wxFileName base(base_offset);
					base.AppendDir(file);
					this->AddDir(fn.GetFullPath(), base);
				} else if (fn.FileExists()) {
					this->files.push_back(new ManifestCreationFile(base_offset.GetDirs(), fn));
				}

				cont = d.GetNext(&file);
			}
		}
	} else {
		// do nothing
	}
}
 wxString    GetName() const { return m_file_name.GetDirs().Last(); }