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; }
ff::String ff::CleanFileName(StringRef name) { String szNewName(name); for (size_t i = PreviousSize(szNewName.length()); i != INVALID_SIZE; i = PreviousSize(i)) { wchar_t ch = szNewName[i]; if (ch == '.' && (i == szNewName.length() - 1 || (i > 0 && szNewName[i - 1] == '.'))) { // Don't allow more than one period in a row, // and don't allow a period at the end szNewName.erase(i, 1); } else if (ch < 32 || ch > 125) { szNewName[i] = '-'; } else switch (ch) { case '<': szNewName[i] = '('; break; case '>': szNewName[i] = ')'; break; case ':': szNewName[i] = '-'; break; case '\"': szNewName[i] = '\''; break; case '/': szNewName[i] = '-'; break; case '\\': szNewName[i] = '-'; break; case '|': szNewName[i] = '-'; break; case '?': szNewName[i] = '-'; break; case '*': szNewName[i] = '-'; break; } } String szExt = GetPathExtension(szNewName); ChangePathExtension(szNewName, GetEmptyString()); if (!_wcsicmp(szNewName.c_str(), L"CON") || !_wcsicmp(szNewName.c_str(), L"PRN") || !_wcsicmp(szNewName.c_str(), L"AUX") || !_wcsicmp(szNewName.c_str(), L"NUL") || !_wcsicmp(szNewName.c_str(), L"COM1") || !_wcsicmp(szNewName.c_str(), L"COM2") || !_wcsicmp(szNewName.c_str(), L"COM3") || !_wcsicmp(szNewName.c_str(), L"COM4") || !_wcsicmp(szNewName.c_str(), L"COM5") || !_wcsicmp(szNewName.c_str(), L"COM6") || !_wcsicmp(szNewName.c_str(), L"COM7") || !_wcsicmp(szNewName.c_str(), L"COM8") || !_wcsicmp(szNewName.c_str(), L"COM9") || !_wcsicmp(szNewName.c_str(), L"LPT1") || !_wcsicmp(szNewName.c_str(), L"LPT2") || !_wcsicmp(szNewName.c_str(), L"LPT3") || !_wcsicmp(szNewName.c_str(), L"LPT4") || !_wcsicmp(szNewName.c_str(), L"LPT5") || !_wcsicmp(szNewName.c_str(), L"LPT6") || !_wcsicmp(szNewName.c_str(), L"LPT7") || !_wcsicmp(szNewName.c_str(), L"LPT8") || !_wcsicmp(szNewName.c_str(), L"LPT9")) { szNewName += L"-File"; } ChangePathExtension(szNewName, szExt); return szNewName; }
void MainDialog::Notify(TNotifyUI& msg) { if( msg.sType == _T("windowinit") ) OnPrepare(msg); else if( msg.sType == _T("click") ) { if( msg.pSender == m_pCloseBtn ) { PostQuitMessage(0); return; } else if( msg.pSender == m_pMinBtn ) { SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0); return; } else if( msg.pSender == m_pMaxBtn ) { SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0); return; } else if( msg.pSender == m_pRestoreBtn ) { SendMessage(WM_SYSCOMMAND, SC_RESTORE, 0); return; } else if (msg.pSender->GetName() == _T("upload")) { } else if (msg.pSender == m_pClose) { } } else if(msg.sType==_T("setfocus")) { } else if( msg.sType == _T("itemexpand") ) { CTreeNodeUI* pNowNode = static_cast<CTreeNodeUI*>(msg.pSender); pNowNode->Select(true); CTreeViewUI* pTree = static_cast<CTreeViewUI*>(m_pm.FindControl(_T("tree"))); CListUI* pList = static_cast<CListUI*>(m_pm.FindControl(_T("file_list"))); g_bUpdateDir = false; if (!pNowNode->IsHasChild()) { g_bUpdateDir = true; } pList->RemoveAll(); WIN32_FIND_DATA FindFileData; HANDLE hListFile; TCHAR szFilePath[MAX_PATH]; lstrcpy(szFilePath,pNowNode->GetUserData()); lstrcat(szFilePath, _T("\\*")); hListFile = FindFirstFile(szFilePath,&FindFileData); if(hListFile==INVALID_HANDLE_VALUE) { return; } else { do { if(lstrcmp(FindFileData.cFileName,TEXT("."))==0|| lstrcmp(FindFileData.cFileName,TEXT(".."))==0) { continue; } SYSTEMTIME st; FileTimeToSystemTime(&FindFileData.ftLastWriteTime,&st); DWORDLONG dwlSize = (DWORDLONG)(FindFileData.nFileSizeHigh * (MAXDWORD+1)) + FindFileData.nFileSizeLow; DWORD dwSize = (DWORD)(dwlSize / 1024); if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (g_bUpdateDir) { CTreeNodeUI* pNode = new CTreeNodeUI; pNode->SetAttribute(_T("folderattr"),_T("padding=\"0,1,0,0\" width=\"36\" height=\"16\" normalimage=\"file='treeview_b.png' source='0,0,36,16'\" hotimage=\"file='treeview_b.png' source='36,0,72,16'\" selectedimage=\"file='treeview_a.png' source='0,0,36,16' selectedhotimage=\"file='treeview_a.png' source='36,0,72,16'\"")); pNowNode->AddChildNode(pNode); pNode->SetItemText(FindFileData.cFileName); CDuiString szUserData = pNowNode->GetUserData() + _T("\\") + pNode->GetItemText(); pNode->SetUserData(szUserData); } } else { CListTextElementUI* pLine = new CListTextElementUI; pList->Add(pLine); CDuiString szNewName(FindFileData.cFileName); int pos = szNewName.ReverseFind('.'); CDuiString szExt = szNewName.Right(szNewName.GetLength() - pos); SHFILEINFO shfi; memset(&shfi,0,sizeof(shfi)); SHGetFileInfo(szExt, FILE_ATTRIBUTE_NORMAL, &shfi, sizeof(shfi), SHGFI_ICON|SHGFI_USEFILEATTRIBUTES); pLine->SetIcon(0,shfi.hIcon); pLine->SetText(0,szNewName); SYSTEMTIME st; FileTimeToSystemTime(&FindFileData.ftLastWriteTime,&st); CDuiString szTime; szTime.Format(_T("%04d/%02d/%02d %02d:%02d:%02d"), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond); pLine->SetText(1,szTime); DWORDLONG dwlSize = (DWORDLONG)(FindFileData.nFileSizeHigh * (MAXDWORD+1)) + FindFileData.nFileSizeLow; CDuiString szSize; if (dwlSize <1024) { szSize.Format(_T("%ldB"),dwlSize); } else { szSize.Format(_T("%ldK"),dwlSize/1024); } pLine->SetText(2,szSize); CDuiString szArrtib; szArrtib.Format(_T("%d"),FindFileData.dwFileAttributes); pLine->SetText(3,szArrtib); } } while(FindNextFile(hListFile, &FindFileData)); } } }