📄 filename.cpp
字号:
//####COPYRIGHTBEGIN####// // ----------------------------------------------------------------------------// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.// Copyright (C) 2003 John Dallaway//// This program is part of the eCos host tools.//// This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the Free // Software Foundation; either version 2 of the License, or (at your option) // any later version.// // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for // more details.// // You should have received a copy of the GNU General Public License along with// this program; if not, write to the Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//// ----------------------------------------------------------------------------// //####COPYRIGHTEND#####ifdef __GNUG__#pragma implementation "filename.h"#endif// Includes other headers for precompiled compilation#include "ecpch.h"#ifdef __BORLANDC__#pragma hdrstop#endif#include "wx/filefn.h"#include "wx/confbase.h" // For wxExpandEnvVars#include "filename.h"#ifdef __WXMSW__//#include <direct.h>//#include <dos.h>#include <windows.h>#include <shlwapi.h>#include "wx/msw/winundef.h"#ifdef CreateDirectory#undef CreateDirectory#endif#ifdef ExpandEnvironmentStrings#undef ExpandEnvironmentStrings#endif#ifdef GetCurrentDirectory#undef GetCurrentDirectory#endif#ifdef SetCurrentDirectory#undef SetCurrentDirectory#endif#ifdef GetTempPath#undef GetTempPath#endif#else// #include <dir.h>#endif#include <sys/stat.h>#define wxTChar wxTconst wxChar ecFileName::cSep=wxFILE_SEP_PATH;ecFileName::ecFileName(const wxChar* psz1,const wxChar* psz2):wxString(psz1){ Normalize(); operator+=(psz2);}ecFileName::ecFileName(const wxChar* psz1,const wxChar* psz2,const wxChar* psz3):wxString(psz1){ Normalize(); operator+=(psz2); operator+=(psz3);}ecFileName::ecFileName(const wxChar* psz1,const wxChar* psz2,const wxChar* psz3,const wxChar* psz4):wxString(psz1){ Normalize(); operator+=(psz2); operator+=(psz3); operator+=(psz4);}ecFileName::ecFileName(const wxChar* psz1,const wxChar* psz2,const wxChar* psz3,const wxChar* psz4,const wxChar* psz5):wxString(psz1){ operator+=(psz2); operator+=(psz3); operator+=(psz4); operator+=(psz5);}/*ecFileName::~ecFileName(){ // Unfortunately we can't do this since GetStringData is private in wxString. // So for now, we may memory leaks since ~wxString is not virtual. //GetStringData()->Unlock();}*/ecFileName operator+(const ecFileName& string1, const ecFileName& string2){ ecFileName s; s.ConcatCopy(string1, string2); return s;}ecFileName operator+(const ecFileName& string, const wxChar* lpsz){ if (lpsz == NULL) return string; ecFileName s; s.ConcatCopy(string, wxString(lpsz)); return s;}ecFileName operator+(const wxChar* lpsz, const ecFileName& string){ if (lpsz == NULL) return string; ecFileName s; s.ConcatCopy(wxString(lpsz), string); return s;}ecFileName operator+(const ecFileName& string1, wxChar ch){ ecFileName s; s.ConcatCopy(string1, wxString(ch)); return s;}ecFileName operator+(wxChar ch, const ecFileName& string){ ecFileName s; s.ConcatCopy(wxString(ch), string); return s;}const ecFileName& ecFileName::operator+=(const wxChar* lpsz){ if (lpsz == NULL) return *this; ConcatInPlace(wxString(lpsz)); return *this;}const ecFileName& ecFileName::operator+=(wxChar ch){ ConcatInPlace(wxString(ch)); return *this;}const ecFileName& ecFileName::operator+=(const ecFileName& string){ ConcatInPlace(string); return *this;}void ecFileName::ConcatInPlace(const wxString& src){ ConcatCopy(* this, src);}void ecFileName::ConcatCopy(const wxString& src1, const wxString& src2){ int nSrc1Len = src1.Len(); int nSrc2Len = src2.Len(); int n=1; int nNewLen = nSrc1Len + nSrc2Len; if(nSrc1Len>0) { if(1==nSrc2Len && cSep==src2[0]) { // Appending a single separator to a non-null string is a no-op return; } else { // Count the intervening separators n=(cSep==src1[nSrc1Len-1])+(cSep==src2[0]); switch(n){ case 0: (*this) = src1 + wxString(cSep) + src2; break; case 1: (*this) = src1 + src2; break; case 2: (*this) = src1 + src2.Mid(1); break; } return; } }}void ecFileName::Normalize(){ // Remove any trailing seperator int len = Len(); if (len > 0 && (*this)[(size_t)(len - 1)] == cSep) (*this) = Mid(0, len - 1);}const ecFileName ecFileName::FullName() const{#ifdef __WXMSW__ TCHAR* pFile; long dwSize=::GetFullPathName (*this, 0, NULL, &pFile); if(dwSize>0){ wxString strCopy; ::GetFullPathName (*this, 1+dwSize, strCopy.GetWriteBuf(1+dwSize), &pFile); strCopy.UngetWriteBuf(); return strCopy; } else { return *this; }#else return wxGetCwd() + wxString(cSep) + wxString(*this);#endif}const ecFileName ecFileName::ShortName() const{#ifdef __WXMSW__ long dwSize=::GetShortPathName (*this, NULL, 0); if(dwSize>0){ wxString strCopy; ::GetShortPathName (*this, strCopy.GetWriteBuf(1+dwSize), 1+dwSize); strCopy.UngetWriteBuf(); return strCopy; } else { return *this; }#else return *this;#endif}const ecFileName ecFileName::NoSpaceName() const// sans spaces{#ifndef __WXMSW__ return *this;#else // Only replace components with spaces with FAT names. wxArrayString ar1,ar2; const wxString str2(ShortName()); size_t i,pcStart; unsigned int len = Len(); pcStart = 0; for (i = 0; i < len; i++) { if(wxTChar('\\')==(*this)[i]) { ar1.Add(this->Mid(pcStart, i - pcStart + 1)); pcStart = i + 1; } } ar1.Add(this->Mid(pcStart, i - pcStart + 1)); len = str2.Len(); pcStart = 0; for (i = 0; i < len; i++) { if(wxTChar('\\')==str2[i]) { ar2.Add(str2.Mid(pcStart, i - pcStart + 1)); pcStart = i + 1; } } ar2.Add(str2.Mid(pcStart, i - pcStart + 1)); wxASSERT(ar1.Count()==ar2.Count()); wxString rc; for(i=0;i<ar1.Count();i++){ rc+=(-1==ar1[i].Find(wxTChar(' ')))?ar1[i]:ar2[i]; } return rc;#endif}//const ecFileName ecFileName::Tail() const{ return AfterLast(cSep);}const ecFileName ecFileName::Head() const{ return BeforeLast(cSep);}time_t ecFileName::LastModificationTime() const{ return wxFileModificationTime(* this); #if 0 // GetFileAttributes is not available in Win95 so we test the water first static HINSTANCE hInst=LoadLibrary(_T("kernel32.dll")); wxASSERT(hInst); #ifdef _UNICODE#define GETFILEATTRIBUTESNAME "GetFileAttributesExW"#else#define GETFILEATTRIBUTESNAME "GetFileAttributesExA"#endif // !UNICODE typedef BOOL (WINAPI *GetFileAttributesP)(const wxChar*,GET_FILEEX_INFO_LEVELS,LPVOID); static GetFileAttributesP p=(GetFileAttributesP)GetProcAddress(hInst,GETFILEATTRIBUTESNAME); if(p){ WIN32_FILE_ATTRIBUTE_DATA data; if((*p)(*this, GetFileExInfoStandard, (LPVOID)&data)){ return data.ftLastWriteTime; } } else { HANDLE h=CreateFile(*this,0,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); FILETIME ft; if(INVALID_HANDLE_VALUE!=h){ BOOL b=::GetFileTime(h,NULL,NULL,&ft); ::CloseHandle(h); if(b){ return ft; } } } static FILETIME ftNull={0,0}; return ftNull;#endif}/* TODObool ecFileName::SetFileAttributes(long dwFileAttributes) const{return ::SetFileAttributes (*this, dwFileAttributes)!=0;}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -