1 |
26 |
unneback |
//####COPYRIGHTBEGIN####
|
2 |
|
|
//
|
3 |
|
|
// ----------------------------------------------------------------------------
|
4 |
|
|
// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
|
5 |
|
|
//
|
6 |
|
|
// This program is part of the eCos host tools.
|
7 |
|
|
//
|
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)
|
11 |
|
|
// any later version.
|
12 |
|
|
//
|
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
|
16 |
|
|
// more details.
|
17 |
|
|
//
|
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.
|
21 |
|
|
//
|
22 |
|
|
// ----------------------------------------------------------------------------
|
23 |
|
|
//
|
24 |
|
|
//####COPYRIGHTEND####
|
25 |
|
|
//===========================================================================
|
26 |
|
|
//#####DESCRIPTIONBEGIN####
|
27 |
|
|
//
|
28 |
|
|
// Author(s): sdf
|
29 |
|
|
// Contact(s): sdf
|
30 |
|
|
// Date: 1998/09/11
|
31 |
|
|
// Version: 0.01
|
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
|
37 |
|
|
// Requires:
|
38 |
|
|
// Provides:
|
39 |
|
|
// See also:
|
40 |
|
|
// Known bugs:
|
41 |
|
|
// Usage:
|
42 |
|
|
//
|
43 |
|
|
//####DESCRIPTIONEND####
|
44 |
|
|
//
|
45 |
|
|
//===========================================================================
|
46 |
|
|
|
47 |
|
|
#ifndef _ECOS_FILENAME_H_
|
48 |
|
|
#define _ECOS_FILENAME_H_
|
49 |
|
|
|
50 |
|
|
#include "wx/wxchar.h"
|
51 |
|
|
#include "wx/dir.h"
|
52 |
|
|
|
53 |
|
|
/*
|
54 |
|
|
* ecFileName
|
55 |
|
|
*
|
56 |
|
|
* This class extends wxString with functionality related
|
57 |
|
|
* to filenames.
|
58 |
|
|
*/
|
59 |
|
|
|
60 |
|
|
class ecFileName : public wxString {
|
61 |
|
|
public:
|
62 |
|
|
void ReplaceExtension (const wxString& newExt);
|
63 |
|
|
|
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;
|
70 |
|
|
|
71 |
|
|
static const wxChar cSep; // The path separator ('\' on windows)
|
72 |
|
|
|
73 |
|
|
// Standard ctors
|
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();}
|
78 |
|
|
|
79 |
|
|
ecFileName(/*LPCSTR*/ const wxChar* lpsz):wxString(lpsz){Normalize();}
|
80 |
|
|
|
81 |
|
|
/* TODO
|
82 |
|
|
ecFileName(LPCWSTR lpsz):wxString(lpsz){Normalize();}
|
83 |
|
|
*/
|
84 |
|
|
|
85 |
|
|
ecFileName(/*LPCSTR*/ const wxChar* lpch, int nLength):wxString(lpch,nLength){Normalize();}
|
86 |
|
|
|
87 |
|
|
/* TODO
|
88 |
|
|
ecFileName(LPCWSTR lpch, int nLength):wxString(lpch,nLength){Normalize();}
|
89 |
|
|
*/
|
90 |
|
|
ecFileName(const unsigned char* psz):wxString(psz){Normalize();}
|
91 |
|
|
|
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*);
|
97 |
|
|
|
98 |
|
|
//~ecFileName();
|
99 |
|
|
|
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);
|
103 |
|
|
#ifdef _UNICODE
|
104 |
|
|
const ecFileName& operator+=(char ch);
|
105 |
|
|
#endif
|
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);
|
110 |
|
|
#ifdef _UNICODE
|
111 |
|
|
friend ecFileName operator+(const ecFileName& string, char ch);
|
112 |
|
|
friend ecFileName operator+(char ch, const ecFileName& string);
|
113 |
|
|
#endif
|
114 |
|
|
friend ecFileName operator+(const ecFileName& string, const wxChar* lpsz);
|
115 |
|
|
friend ecFileName operator+(const wxChar* lpsz, const ecFileName& string);
|
116 |
|
|
|
117 |
|
|
// Textual append - no separator functionality
|
118 |
|
|
const ecFileName& Append (wxChar ch);
|
119 |
|
|
const ecFileName& Append (const wxChar* psz);
|
120 |
|
|
|
121 |
|
|
// Utility functions
|
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
|
128 |
|
|
|
129 |
|
|
static ecFileName GetCurrentDirectory();
|
130 |
|
|
const ecFileName& ExpandEnvironmentStrings();
|
131 |
|
|
static ecFileName ExpandEnvironmentStrings(const wxChar* psz);
|
132 |
|
|
|
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);
|
136 |
|
|
|
137 |
|
|
bool SameFile (const ecFileName &strOther) const;
|
138 |
|
|
|
139 |
|
|
/* TODO
|
140 |
|
|
bool SetFileAttributes (long dwFileAttributes) const;
|
141 |
|
|
|
142 |
|
|
long Attributes() const { return ::GetFileAttributes(*this); }
|
143 |
|
|
*/
|
144 |
|
|
|
145 |
|
|
bool Exists () const ;
|
146 |
|
|
bool IsDir () const ;
|
147 |
|
|
bool IsFile () const ;
|
148 |
|
|
bool IsReadOnly () const ;
|
149 |
|
|
|
150 |
|
|
time_t LastModificationTime() const;
|
151 |
|
|
|
152 |
|
|
bool RecursivelyDelete();
|
153 |
|
|
|
154 |
|
|
bool CreateDirectory (bool bParentsToo=true,bool bFailIfAlreadyExists=false) const;
|
155 |
|
|
|
156 |
|
|
static int FindFiles (const wxString& pszDir,wxArrayString &ar,const wxString& pszPattern=wxT("*.*"),bool bRecurse=TRUE,long dwExclude=wxDIR_DIRS|wxDIR_HIDDEN);
|
157 |
|
|
|
158 |
|
|
protected:
|
159 |
|
|
|
160 |
|
|
/* Don't appear to be necessary
|
161 |
|
|
// Helpers for Relative():
|
162 |
|
|
const wxChar* *Chop ();
|
163 |
|
|
static ecFileName Drive(const wxChar* psz);
|
164 |
|
|
*/
|
165 |
|
|
|
166 |
|
|
// Remove trailing '/' (helper for ctors)
|
167 |
|
|
void Normalize();
|
168 |
|
|
|
169 |
|
|
// Implementating catenation functionality:
|
170 |
|
|
void ConcatInPlace(const wxString& src);
|
171 |
|
|
void ConcatCopy(const wxString& src1, const wxString& src2);
|
172 |
|
|
};
|
173 |
|
|
|
174 |
|
|
class wxSaveExcursion {
|
175 |
|
|
const ecFileName m_strPrevDir;
|
176 |
|
|
public:
|
177 |
|
|
wxSaveExcursion(const wxChar* pszDir) : m_strPrevDir(ecFileName::SetCurrentDirectory(pszDir)) {}
|
178 |
|
|
~wxSaveExcursion() { ecFileName::SetCurrentDirectory(m_strPrevDir); }
|
179 |
|
|
bool Ok() const { return !m_strPrevDir.IsEmpty(); }
|
180 |
|
|
};
|
181 |
|
|
|
182 |
|
|
#endif
|
183 |
|
|
// _ECOS_FILENAME_H_
|