From d38315df30415b030d93172123920d69c5c5e3b6 Mon Sep 17 00:00:00 2001 From: Francesco Montorsi Date: Sat, 19 Jun 2010 11:07:16 +0000 Subject: [PATCH] Remove identic implementations of wxDir::Exists from platform-specific files and put it in dircmn.cpp (they all used wxDirExists). Add wxDir::Make() and wxDir::Remove() for coherency with wxDir::Exists() and document them as simple aliases to wxFileName functions, just a bit more readable. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64632 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dir.h | 17 +++++++++++++++-- interface/wx/dir.h | 17 +++++++++++++++++ interface/wx/filename.h | 4 ++-- src/common/dircmn.cpp | 22 ++++++++++++++++++++++ src/mgl/dirmgl.cpp | 11 ----------- src/msdos/dir.cpp | 11 ----------- src/msw/dir.cpp | 11 ----------- src/os2/dir.cpp | 12 ------------ src/osx/carbon/dirmac.cpp | 11 ----------- src/palmos/dir.cpp | 11 ----------- src/unix/dir.cpp | 10 ---------- 11 files changed, 56 insertions(+), 81 deletions(-) diff --git a/include/wx/dir.h b/include/wx/dir.h index fa50bb2..980e5f2 100644 --- a/include/wx/dir.h +++ b/include/wx/dir.h @@ -83,8 +83,6 @@ class WXDLLIMPEXP_FWD_BASE wxDirData; class WXDLLIMPEXP_BASE wxDir { public: - // test for existence of a directory with the given name - static bool Exists(const wxString& dir); // ctors // ----- @@ -106,6 +104,7 @@ public: // get the full name of the directory (without '/' at the end) wxString GetName() const; + // file enumeration routines // ------------------------- @@ -151,6 +150,20 @@ public: static wxULongLong GetTotalSize(const wxString &dir, wxArrayString *filesSkipped = NULL); #endif // wxUSE_LONGLONG + + // static utilities for directory management + // (alias to wxFileName's functions for dirs) + // ----------------------------------------- + + // test for existence of a directory with the given name + static bool Exists(const wxString& dir); + + static bool Make(const wxString &dir, int perm = wxS_DIR_DEFAULT, + int flags = 0); + + static bool Remove(const wxString &dir, int flags = 0); + + private: friend class wxDirData; diff --git a/interface/wx/dir.h b/interface/wx/dir.h index 1b9ba58..213db2b 100644 --- a/interface/wx/dir.h +++ b/interface/wx/dir.h @@ -267,12 +267,29 @@ public: bool IsOpened() const; /** + Creates a directory. + + This is just an alias for wxFileName::Mkdir(); refer to that function + for more info. + */ + static bool Make(const wxString &dir, int perm = wxS_DIR_DEFAULT, + int flags = 0); + + /** Open the directory for enumerating, returns @true on success or @false if an error occurred. */ bool Open(const wxString& dir); /** + Removes a directory. + + This is just an alias for wxFileName::Rmdir(); refer to that function + for more info. + */ + static bool Remove(const wxString &dir, int flags = 0); + + /** Enumerate all files and directories under the given directory recursively calling the element of the provided wxDirTraverser object for each of them. diff --git a/interface/wx/filename.h b/interface/wx/filename.h index 0e78b2d..8cbf0c3 100644 --- a/interface/wx/filename.h +++ b/interface/wx/filename.h @@ -456,7 +456,7 @@ public: bool DirExists() const; /** - Returns @true if the directory with this name exists. + Returns @true if the directory with name @a dir exists. */ static bool DirExists(const wxString& dir); @@ -475,7 +475,7 @@ public: bool FileExists() const; /** - Returns @true if the file with this name exists. + Returns @true if the file with name @a file exists. @see DirExists() */ diff --git a/src/common/dircmn.cpp b/src/common/dircmn.cpp index 79ce97e..20d2268 100644 --- a/src/common/dircmn.cpp +++ b/src/common/dircmn.cpp @@ -356,4 +356,26 @@ wxULongLong wxDir::GetTotalSize(const wxString &dirname, wxArrayString *filesSki return traverser.GetTotalSize(); } +// ---------------------------------------------------------------------------- +// wxDir helpers +// ---------------------------------------------------------------------------- + +/* static */ +bool wxDir::Exists(const wxString& dir) +{ + return wxFileName::DirExists(dir); +} + +/* static */ +bool wxDir::Make(const wxString &dir, int perm, int flags) +{ + return wxFileName::Mkdir(dir, perm, flags); +} + +/* static */ +bool wxDir::Remove(const wxString &dir, int flags) +{ + return wxFileName::Rmdir(dir, flags); +} + #endif // wxUSE_LONGLONG diff --git a/src/mgl/dirmgl.cpp b/src/mgl/dirmgl.cpp index cc28a6a..8405be0 100644 --- a/src/mgl/dirmgl.cpp +++ b/src/mgl/dirmgl.cpp @@ -179,17 +179,6 @@ bool wxDirData::Read(wxString *filename) return true; } - -// ---------------------------------------------------------------------------- -// wxDir helpers -// ---------------------------------------------------------------------------- - -/* static */ -bool wxDir::Exists(const wxString& dir) -{ - return wxDirExists(dir); -} - // ---------------------------------------------------------------------------- // wxDir construction/destruction // ---------------------------------------------------------------------------- diff --git a/src/msdos/dir.cpp b/src/msdos/dir.cpp index d62fadd..7693fb1 100644 --- a/src/msdos/dir.cpp +++ b/src/msdos/dir.cpp @@ -30,7 +30,6 @@ #endif // PCH #include "wx/dir.h" -#include "wx/filefn.h" // for wxDirExists() // ---------------------------------------------------------------------------- // define the types and functions used for file searching @@ -59,16 +58,6 @@ // ============================================================================ // ---------------------------------------------------------------------------- -// wxDir helpers -// ---------------------------------------------------------------------------- - -/* static */ -bool wxDir::Exists(const wxString& WXUNUSED(dir)) -{ - return false; -} - -// ---------------------------------------------------------------------------- // wxDir construction/destruction // ---------------------------------------------------------------------------- diff --git a/src/msw/dir.cpp b/src/msw/dir.cpp index d7302d2..81c312e 100644 --- a/src/msw/dir.cpp +++ b/src/msw/dir.cpp @@ -30,7 +30,6 @@ #endif // PCH #include "wx/dir.h" -#include "wx/filefn.h" // for wxDirExists() #ifdef __WINDOWS__ #include "wx/msw/private.h" @@ -288,16 +287,6 @@ bool wxDirData::Read(wxString *filename) } // ---------------------------------------------------------------------------- -// wxDir helpers -// ---------------------------------------------------------------------------- - -/* static */ -bool wxDir::Exists(const wxString& dir) -{ - return wxDirExists(dir); -} - -// ---------------------------------------------------------------------------- // wxDir construction/destruction // ---------------------------------------------------------------------------- diff --git a/src/os2/dir.cpp b/src/os2/dir.cpp index f0ec71d..1b81050 100644 --- a/src/os2/dir.cpp +++ b/src/os2/dir.cpp @@ -309,18 +309,6 @@ bool wxDirData::Read( } // end of wxDirData::Read // ---------------------------------------------------------------------------- -// wxDir helpers -// ---------------------------------------------------------------------------- - -/* static */ -bool wxDir::Exists( - const wxString& rsDir -) -{ - return wxDirExists(rsDir); -} // end of wxDir::Exists - -// ---------------------------------------------------------------------------- // wxDir construction/destruction // ---------------------------------------------------------------------------- diff --git a/src/osx/carbon/dirmac.cpp b/src/osx/carbon/dirmac.cpp index 6ac3a14..493829f 100644 --- a/src/osx/carbon/dirmac.cpp +++ b/src/osx/carbon/dirmac.cpp @@ -31,7 +31,6 @@ #include "wx/log.h" #endif // PCH -#include "wx/filefn.h" // for wxDirExists() #include "wx/filename.h" #include "wx/osx/private.h" @@ -186,16 +185,6 @@ bool wxDirData::Read(wxString *filename) } // ---------------------------------------------------------------------------- -// wxDir helpers -// ---------------------------------------------------------------------------- - -/* static */ -bool wxDir::Exists(const wxString& dir) -{ - return wxDirExists(dir); -} - -// ---------------------------------------------------------------------------- // wxDir construction/destruction // ---------------------------------------------------------------------------- diff --git a/src/palmos/dir.cpp b/src/palmos/dir.cpp index 0ad3719..6e1d490 100644 --- a/src/palmos/dir.cpp +++ b/src/palmos/dir.cpp @@ -30,7 +30,6 @@ #endif // PCH #include "wx/dir.h" -#include "wx/filefn.h" // for wxDirExists() #include "pfall.h" @@ -199,16 +198,6 @@ bool wxDirData::Read(wxString *filename) } // ---------------------------------------------------------------------------- -// wxDir helpers -// ---------------------------------------------------------------------------- - -/* static */ -bool wxDir::Exists(const wxString& dir) -{ - return wxDirExists(dir); -} - -// ---------------------------------------------------------------------------- // wxDir construction/destruction // ---------------------------------------------------------------------------- diff --git a/src/unix/dir.cpp b/src/unix/dir.cpp index 5a0554e..d016047 100644 --- a/src/unix/dir.cpp +++ b/src/unix/dir.cpp @@ -198,16 +198,6 @@ bool wxDirData::Read(wxString * WXUNUSED(filename)) #endif // not or new VMS/old VMS // ---------------------------------------------------------------------------- -// wxDir helpers -// ---------------------------------------------------------------------------- - -/* static */ -bool wxDir::Exists(const wxString& dir) -{ - return wxDirExists(dir); -} - -// ---------------------------------------------------------------------------- // wxDir construction/destruction // ---------------------------------------------------------------------------- -- 2.7.4