bool wxGxOpenFileGDB::Rename(const wxString &sNewName) { wxGISDataset* pDSet = GetDatasetFast(); if (NULL != pDSet) { pDSet->Close(); wsDELETE(pDSet); } wxFileName PathName(wxString(m_sPath, wxConvUTF8)); PathName.SetName(ClearExt(sNewName)); wxString sNewPath = PathName.GetFullPath(); CPLString szNewPath(sNewPath.mb_str(wxConvUTF8)); if (RenameFile(m_sPath, szNewPath)) { if (m_bIsChildrenLoaded) Refresh(); return true; } else { const char* err = CPLGetLastErrorMsg(); wxLogError(_("Operation '%s' failed! GDAL error: %s, file '%s'"), _("Rename"), wxString(err, wxConvUTF8).c_str(), wxString(m_sPath, wxConvUTF8).c_str()); return false; } return false; }
bool wxGxArchive::Rename(const wxString &sNewName) { CPLString szType("/"); int nCount = 0; for(size_t i = 1; i < m_sPath.length(); ++i) { nCount++; szType += m_sPath[i]; if(m_sPath[i] == '/') break; } m_sPath.erase(0, nCount + 1); wxFileName PathName(wxString(m_sPath, wxConvUTF8)); PathName.SetName(ClearExt(sNewName)); wxString sNewPath = PathName.GetFullPath(); CPLString szNewPath(sNewPath.mb_str(wxConvUTF8)); if(RenameFile(m_sPath, szNewPath)) { return true; } else { const char* err = CPLGetLastErrorMsg(); wxLogError(_("Operation '%s' failed! GDAL error: %s, file '%s'"), _("Rename"), wxString(err, wxConvUTF8).c_str(), wxString(m_sPath, wxConvUTF8).c_str()); return false; } return false; }
bool wxGxFile::Rename(const wxString &sNewName) { wxFileName PathName(wxString(m_sPath, wxConvUTF8)); PathName.SetName(ClearExt(sNewName)); wxString sNewPath = PathName.GetFullPath(); CPLString szNewPath(sNewPath.mb_str(wxConvUTF8)); if(RenameFile(m_sPath, szNewPath)) { return true; } else { const char* err = CPLGetLastErrorMsg(); wxLogError(_("Operation '%s' failed! GDAL error: %s, file '%s'"), _("Rename"), wxString(err, wxConvUTF8).c_str(), wxString(m_sPath, wxConvUTF8).c_str()); return false; } return false; }
bool wxGISDataset::Rename(const wxString &sNewName, ITrackCancel* const pTrackCancel) { wxCriticalSectionLocker locker(m_CritSect); Close(); CPLString szDirPath = CPLGetPath(m_sPath); CPLString szName = CPLGetBasename(m_sPath); CPLString szNewName(ClearExt(sNewName).mb_str(wxConvUTF8)); char** papszFileList = GetFileList(); papszFileList = CSLAddString( papszFileList, m_sPath ); if(!papszFileList) { if(pTrackCancel) pTrackCancel->PutMessage(_("No files to rename"), wxNOT_FOUND, enumGISMessageErr); return false; } char **papszNewFileList = NULL; for(int i = 0; papszFileList[i] != NULL; ++i ) { CPLString szNewPath(CPLFormFilename(szDirPath, szNewName, GetExtension(papszFileList[i], szName))); papszNewFileList = CSLAddString(papszNewFileList, szNewPath); if(!RenameFile(papszFileList[i], papszNewFileList[i], pTrackCancel)) { // Try to put the ones we moved back. for( --i; i >= 0; i-- ) RenameFile( papszNewFileList[i], papszFileList[i]); CSLDestroy( papszFileList ); CSLDestroy( papszNewFileList ); return false; } } m_sPath = CPLString(CPLFormFilename(szDirPath, szNewName, CPLGetExtension(m_sPath))); CSLDestroy( papszFileList ); CSLDestroy( papszNewFileList ); return true; }