include/fileutils/fileutils.h

Go to the documentation of this file.
00001 
00002 // Name:        fileutils.h
00003 // Purpose:     General-purpose file utility classes and functions
00004 // Author:      Julian Smart
00005 // Modified by:
00006 // Created:     2006-02-09
00007 // RCS-ID:      $Id$
00008 // Copyright:   (c) Julian Smart
00009 // Licence:     New BSD License
00011 
00012 #ifndef _FILEUTILS_H_
00013 #define _FILEUTILS_H_
00014 
00015 class wxInputStream;
00016 class wxOutputStream;
00017 class wxFileHistory;
00018 class wxFileOutputStream;
00019 class wxConfigBase;
00020 class wxZipEntry;
00021 class wxZipInputStream;
00022 class wxProgressDialog;
00023 
00024 #include "wx/dir.h"
00025 #include "wx/filename.h"
00026 #include "wx/accel.h"
00027 
00028 class wxMenuBar;
00029 class wxFile;
00030 class wxFFile;
00031 
00032 enum
00033 {
00034         // overwrite the destination file if it exists
00035         FILEUTILS_COPYFILE_OVERWRITE = 1,
00036 
00037         // don't fail if the permissions of the destination file can't be
00038         // set (after successful copy)
00039         FILEUTILS_COPYFILE_IGNORE_PERMISSIONS = 2
00040 };
00041 
00046 class FileUtilities
00047 {
00048 public:
00049 
00051     static bool FilesEqual(const wxString& filename1, const wxString& filename2);
00052 
00055     static bool RenameOrCopyFile(const wxString& filename1, const wxString& filename2);
00056 
00058     static wxString GetTempDirectory();
00059 
00061     static wxString GetDocumentDirectory();
00062 
00064     static wxString GetUserAppDataDirectory(const wxString& appName);
00065 
00067     static wxString GetDownloadDirectory();
00068 
00070     static bool DirExists(const wxString& str);
00071 
00073     static wxString GetExtension(const wxString& filename);
00074 
00076     static bool HasExtension(const wxString& filename, const wxString& ext);
00077 
00081     static bool StripExtension(wxString& path, const wxString& validExtensions = wxEmptyString);
00082 
00084     static void EnsureExtension(wxString& path, const wxString& requiredExt);
00085 
00087     static bool RemoveTrailingSeparator(wxString& filename);
00088 
00090     static bool MkDirRecursively(const wxString& path);
00091 
00093     static bool RemoveDirRecursively(const wxString& path);
00094 
00096     static bool IsReadOnly(const wxString& filename);
00097 
00099     static bool IsAbsolutePath(const wxString& path);
00100 
00102     static wxString MakeRelative(const wxString& path, const wxString& appPath);
00103 
00105     static wxString MakeAbsolute(const wxString& path, const wxString& appPath);
00106 
00107 #if defined(__WXMSW__) && !defined(__WXWINCE__)
00109     static bool CreateShortcut(const wxString& path, const wxString& pathLink, const wxString descr);
00110 
00112     static wxString GetShortcutTarget(const wxString& LinkFileName);
00113 #endif
00114 
00116     static bool ExploreFolder(const wxString& folder);
00117     
00119     static wxString AppendPaths(const wxString& p1, const wxString& p2, const wxString& sep = wxFILE_SEP_PATH);
00120     
00122     static bool DriveExists(const wxString& drive);
00123     
00125     static bool GetAvailableDrives(wxArrayString& paths, wxArrayString& names, bool removableOnly = false);
00126     
00128     static bool GetVolumeFromFilename(const wxString& filename, wxString& volume);
00129     
00131     static bool SplitVolume(const wxString& path, wxString& filename, wxString& volume);
00132     
00134     static bool GetFilenameSubstitutingVolume(const wxString& filename, wxString& newFilename, const wxString& newVolume, const wxString& oldVolume,
00135         bool isFilename = true);
00136     
00138     static void FileHistoryLoadWithVolumeSubstitution(wxFileHistory& fileHistory, wxConfigBase& config, const wxString& newVolume, const wxString& oldVolume);
00139     
00141     static bool Chmod(const wxString& path, int mode, bool addMode = false);
00142 
00144     static int GetFileMode(const wxString& path);
00145 
00147     static bool FindAndChmod(const wxString& searchPath, const wxString& filename, int mode, bool addMode = false);
00148 
00150     
00153     static bool BufferedCopy(wxInputStream& inStream, wxOutputStream& outStream, size_t size);
00154     
00157     static bool BufferedCopy(wxInputStream& inStream, wxOutputStream& outStream);
00158     
00160     static bool CopyFileToStream(wxOutputStream& stream, const wxString& filename);
00161     
00163     static bool CopyStreamToFile(wxInputStream& stream, const wxString& filename, size_t size);
00164 
00166     static wxArrayString SplitCommand(const wxString& command);
00167 
00169     static bool SplitPath(const wxString& fullpath,
00170                           wxString *path,
00171                           wxString *name,
00172                           wxString *ext,
00173                           wxPathFormat format = wxPATH_NATIVE);
00174     
00176     static wxString FindInPath(const wxString& cmd);
00177 
00179     static bool CopyDir(const wxString& sourceDir, const wxString& destDir, bool ifNotExists = true, const wxString& wildcard = wxT("*"), int dirFlags = wxDIR_FILES);
00180 
00181     // Replacement for wxWidgets function that fails if can't set permissions
00182     static bool CopyFile(const wxString& file1, const wxString& file2, int flags = FILEUTILS_COPYFILE_OVERWRITE | FILEUTILS_COPYFILE_IGNORE_PERMISSIONS);
00183 
00184     // Copy temp filename to target filename prompting if the rename/copy failed.
00185     // If backupFilename was non-empty, it will first be deleted before the copy if it
00186     // exists, and the old targetFilename will be copied to backupFilename before
00187     // targetFilename is overwritten.
00188     static bool SafelyCopyFile(const wxString& tempFilename, const wxString& targetFilename, const wxString& backupFilename = wxEmptyString, bool leaveBackup = true, wxWindow* parent = NULL);
00189 
00190     // Create stream, prompting for a retry, and if failing, returning false.
00191     // If it returns false, there is no need for the app to delete the stream:
00192     // it will have been deleted.
00193     static bool SafelyCreateFileOutputStream(wxFileOutputStream** stream, const wxString& filename, wxWindow* parent = NULL, const wxString& msg = wxEmptyString, const wxString& title = wxEmptyString);
00194 
00195     // Create file, prompting for a retry, and if failing, returning false.
00196     // If it returns false, there is no need for the app to delete the file:
00197     // it will have been deleted.
00198     static bool SafelyCreateFile(wxFFile** file, const wxString& filename, wxWindow* parent = NULL, const wxString& msg = wxEmptyString, const wxString& title = wxEmptyString);
00199 
00200     static bool SafelyCreateFile(wxFile** file, const wxString& filename, wxWindow* parent = NULL, const wxString& msg = wxEmptyString, const wxString& title = wxEmptyString);
00201 
00203     static wxString FindHtmlEncoding(const wxString& filename);
00204 
00206     static wxString MakeValidFilename(const wxString& filename, bool allowSpaces = false);
00207 };
00208 
00213 class ArchiveUtilities
00214 {
00215 public:
00217     static wxZipEntry* FindEntry(wxZipInputStream& stream, const wxString& filename);
00218 
00221     static bool BufferedCopy(wxInputStream& inStream, wxOutputStream& outStream, size_t size);
00222 
00224     static bool CopyStreamToFile(wxInputStream& stream, const wxString& filename, size_t size);
00225 
00227     static bool CopyEntryToFile(wxZipInputStream& stream, const wxString& filename, wxZipEntry* entry);
00228 
00230     static bool UnzipTo(const wxString& archive, const wxString& destinationFolder, wxProgressDialog* progressDialog = NULL);
00231 
00233     static bool GUnzipTo(const wxString& archive, const wxString& destinationFile);
00234 
00236     static bool UntarTo(const wxString& archive, const wxString& destinationFolder, wxProgressDialog* progressDialog = NULL);
00237 
00240     static bool CopyTo(const wxString& relativeTo, const wxArrayString& files, const wxString& destinationFolder, wxProgressDialog* progressDialog = NULL);
00241 
00243     static int GetZipEntryCount(const wxString& filename);
00244 };
00245 
00246 
00247 #endif
00248  // _FILEUTILS_H_
00249 

Generated on Wed May 6 19:20:19 2009 for AxTk by  doxygen 1.5.1