1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
25 //===========================================================================
26 //#####DESCRIPTIONBEGIN####
32 // Purpose: Class to encapsulate filename operations (i.e. broadly on a file which probably do not involve opening
33 // it). Importantly, the + and += operators performs filename segment addition, making sure that only one '\\'
34 // comes between each piece.
35 // Translated to wxWindows conventions by julians (in progress)
36 // Description: Interface of the filename class
43 //####DESCRIPTIONEND####
45 //===========================================================================
47 #ifndef _ECOS_FILENAME_H_
48 #define _ECOS_FILENAME_H_
50 #include "wx/wxchar.h"
56 * This class extends wxString with functionality related
60 class ecFileName : public wxString {
62 void ReplaceExtension (const wxString& newExt);
64 // previous directory is returned:
65 static ecFileName SetCurrentDirectory (const wxChar* pszDir);
66 const wxString Root() const;
67 const wxString Extension() const;
68 static ecFileName GetTempPath();
69 bool IsAbsolute() const;
71 static const wxChar cSep; // The path separator ('\' on windows)
74 ecFileName():wxString(){}
75 ecFileName(const ecFileName& stringSrc):wxString(stringSrc){Normalize();}
76 ecFileName(const wxString& stringSrc):wxString(stringSrc){Normalize();}
77 ecFileName(wxChar ch, int nRepeat = 1):wxString(ch,nRepeat){Normalize();}
79 ecFileName(/*LPCSTR*/ const wxChar* lpsz):wxString(lpsz){Normalize();}
82 ecFileName(LPCWSTR lpsz):wxString(lpsz){Normalize();}
85 ecFileName(/*LPCSTR*/ const wxChar* lpch, int nLength):wxString(lpch,nLength){Normalize();}
88 ecFileName(LPCWSTR lpch, int nLength):wxString(lpch,nLength){Normalize();}
90 ecFileName(const unsigned char* psz):wxString(psz){Normalize();}
92 // Construct from path fragments
93 ecFileName(const wxChar*,const wxChar*);
94 ecFileName(const wxChar*,const wxChar*,const wxChar*);
95 ecFileName(const wxChar*,const wxChar*,const wxChar*,const wxChar*);
96 ecFileName(const wxChar*,const wxChar*,const wxChar*,const wxChar*,const wxChar*);
100 // catenation operators: exactly one separator is placed between L and R
101 const ecFileName& operator+=(const ecFileName& string);
102 const ecFileName& operator+=(wxChar ch);
104 const ecFileName& operator+=(char ch);
106 const ecFileName& operator+=(const wxChar* lpsz);
107 friend ecFileName operator+(const ecFileName& string1,const ecFileName& string2);
108 friend ecFileName operator+(const ecFileName& string, wxChar ch);
109 friend ecFileName operator+(wxChar ch, const ecFileName& string);
111 friend ecFileName operator+(const ecFileName& string, char ch);
112 friend ecFileName operator+(char ch, const ecFileName& string);
114 friend ecFileName operator+(const ecFileName& string, const wxChar* lpsz);
115 friend ecFileName operator+(const wxChar* lpsz, const ecFileName& string);
117 // Textual append - no separator functionality
118 const ecFileName& Append (wxChar ch);
119 const ecFileName& Append (const wxChar* psz);
122 const ecFileName FullName() const; // full path name
123 const ecFileName NoSpaceName() const;// sans spaces
124 const ecFileName ShortName() const; // the type with ~s in it
125 const ecFileName Tail() const; // file name sans directory part
126 const ecFileName Head() const; // directory part
127 const ecFileName CygPath() const; // path mangled for CygWin
129 static ecFileName GetCurrentDirectory();
130 const ecFileName& ExpandEnvironmentStrings();
131 static ecFileName ExpandEnvironmentStrings(const wxChar* psz);
133 // Form path name relative to given parameter (if NULL, current directory)
134 const ecFileName& MakeRelative(const wxChar* pszRelativeTo=0);
135 static ecFileName Relative(const wxChar* psz,const wxChar* pszRelativeTo=0);
137 bool SameFile (const ecFileName &strOther) const;
140 bool SetFileAttributes (long dwFileAttributes) const;
142 long Attributes() const { return ::GetFileAttributes(*this); }
145 bool Exists () const ;
146 bool IsDir () const ;
147 bool IsFile () const ;
148 bool IsReadOnly () const ;
150 time_t LastModificationTime() const;
152 bool RecursivelyDelete();
154 bool CreateDirectory (bool bParentsToo=true,bool bFailIfAlreadyExists=false) const;
156 static int FindFiles (const wxString& pszDir,wxArrayString &ar,const wxString& pszPattern=wxT("*.*"),bool bRecurse=TRUE,long dwExclude=wxDIR_DIRS|wxDIR_HIDDEN);
160 /* Don't appear to be necessary
161 // Helpers for Relative():
162 const wxChar* *Chop ();
163 static ecFileName Drive(const wxChar* psz);
166 // Remove trailing '/' (helper for ctors)
169 // Implementating catenation functionality:
170 void ConcatInPlace(const wxString& src);
171 void ConcatCopy(const wxString& src1, const wxString& src2);
174 class wxSaveExcursion {
175 const ecFileName m_strPrevDir;
177 wxSaveExcursion(const wxChar* pszDir) : m_strPrevDir(ecFileName::SetCurrentDirectory(pszDir)) {}
178 ~wxSaveExcursion() { ecFileName::SetCurrentDirectory(m_strPrevDir); }
179 bool Ok() const { return !m_strPrevDir.IsEmpty(); }