include/ax/ax_utils.h

Go to the documentation of this file.
00001 
00002 // Name:        ax_utils.h
00003 // Purpose:     AxTk framework - utilities for archives and more
00004 // Author:      Julian Smart
00005 // Modified by: 
00006 // Created:     2009-02-27
00007 // RCS-ID:      
00008 // Copyright:   (c) Julian Smart
00009 // Licence:     New BSD License
00011 
00012 #ifndef _AX_UTILS_H_
00013 #define _AX_UTILS_H_
00014 
00015 /*
00016  * Includes
00017  */
00018 
00019 #include "wx/dir.h"
00020 #include "wx/filename.h"
00021 
00022 /*
00023  * Styles and types
00024  */
00025 
00026 enum
00027 {
00028         // overwrite the destination file if it exists
00029         AX_COPYFILE_OVERWRITE = 1,
00030 
00031         // don't fail if the permissions of the destination file can't be
00032         // set (after successful copy)
00033         AX_COPYFILE_IGNORE_PERMISSIONS = 2
00034 };
00035 
00036 /*
00037  * Forward declarations
00038  */
00039 
00040 class wxInputStream;
00041 class wxOutputStream;
00042 class wxFileHistory;
00043 class wxFileOutputStream;
00044 class wxConfigBase;
00045 class wxZipEntry;
00046 class wxZipInputStream;
00047 class wxProgressDialog;
00048 
00057 class AxFileUtilities
00058 {    
00059 public:
00061     AxFileUtilities() {}
00062 
00064     static wxString GetDocumentDirectory();
00065 
00067     static wxString GetUserAppDataDirectory(const wxString& appName);
00068 
00070     static wxString AppendPaths(const wxString& p1, const wxString& p2, const wxString& sep = wxFILE_SEP_PATH);
00071     
00073     static bool MkDirRecursively(const wxString& path);
00074 
00076     static bool RemoveDirRecursively(const wxString& path);
00077 
00079     static bool Chmod(const wxString& path, int mode, bool addMode = false);
00080 
00082     static int GetFileMode(const wxString& path);
00083 
00085     static bool FindAndChmod(const wxString& searchPath, const wxString& filename, int mode, bool addMode = false);
00086 
00088     static bool CopyDir(const wxString& sourceDir, const wxString& destDir, bool ifNotExists = true, const wxString& wildcard = wxT("*"), int dirFlags = wxDIR_FILES);
00089 
00091     static bool CopyFile(const wxString& file1, const wxString& file2, int flags = AX_COPYFILE_OVERWRITE | AX_COPYFILE_IGNORE_PERMISSIONS);
00092 
00095     static bool BufferedCopy(wxInputStream& inStream, wxOutputStream& outStream, size_t size);
00096     
00099     static bool BufferedCopy(wxInputStream& inStream, wxOutputStream& outStream);
00100     
00102     static bool CopyFileToStream(wxOutputStream& stream, const wxString& filename);
00103     
00105     static bool CopyStreamToFile(wxInputStream& stream, const wxString& filename, size_t size);
00106 
00108     static wxString GetExtension(const wxString& filename);
00109 
00111     static bool HasExtension(const wxString& filename, const wxString& ext);
00112 
00116     static bool StripExtension(wxString& path, const wxString& validExtensions = wxEmptyString);
00117 
00119     static void EnsureExtension(wxString& path, const wxString& requiredExt);
00120 
00122     static bool SplitPath(const wxString& fullpath,
00123                           wxString *path,
00124                           wxString *name,
00125                           wxString *ext,
00126                           wxPathFormat format = wxPATH_NATIVE);
00127 
00129     static bool RemoveTrailingSeparator(wxString& filename);
00130 
00132     static bool ExecuteFile(const wxString& command, const wxString& specificErrorMessage = wxEmptyString);
00133 
00135     static wxString MakeValidFilename(const wxString& filename, bool allowSpaces = true);
00136 
00137 };
00138 
00147 class AxArchiveUtilities
00148 {    
00149 public:
00150     AxArchiveUtilities() {}
00151 
00153     static wxZipEntry* FindEntry(wxZipInputStream& stream, const wxString& filename);
00154 
00157     static bool BufferedCopy(wxInputStream& inStream, wxOutputStream& outStream, size_t size);
00158 
00160     static bool CopyStreamToFile(wxInputStream& stream, const wxString& filename, size_t size);
00161 
00163     static bool CopyEntryToFile(wxZipInputStream& stream, const wxString& filename, wxZipEntry* entry);
00164 
00166     static bool UnzipTo(const wxString& archive, const wxString& destinationFolder, wxProgressDialog* progressDialog = NULL);
00167 
00169     static bool GUnzipTo(const wxString& archive, const wxString& destinationFile);
00170 
00172     static bool UntarTo(const wxString& archive, const wxString& destinationFolder, wxProgressDialog* progressDialog = NULL);
00173 
00176     static bool CopyTo(const wxString& relativeTo, const wxArrayString& files, const wxString& destinationFolder, wxProgressDialog* progressDialog = NULL);
00177 
00179     static int GetZipEntryCount(const wxString& filename);
00180 
00181 };
00182 
00191 class wxOutputStream;
00192 class wxInputStream;
00193 class wxDataOutputStream;
00194 class wxDataInputStream;
00195 
00196 class AxUIUtilities
00197 {    
00198 public:
00199     AxUIUtilities() {}
00200 
00202     static wxBorder GetSuitableThemedBorderStyle();
00203 
00205     static void ChooseFolder(wxTextCtrl* textCtrl, wxWindow* win);
00206 
00208     static void ChooseFile(wxTextCtrl* textCtrl, const wxString& wildcard, const wxString& ext, wxWindow* win);
00209 
00211     static wxWindow* FindWindowByClass(wxWindow* parent, wxClassInfo* info);
00212 
00214     static wxWindow* ChildWindowFromPoint(wxWindow* win, const wxPoint& pt, bool hidden = true, int depth = -1);
00215     static wxWindow* ChildWindowFromPoint(const wxPoint& pt, bool hidden = true, int depth = -1);
00216 };
00217 
00219 wxSize AxCalculateScaledImageSize(const wxSize& maxSize, const wxSize& imageSize);
00220 
00222 bool AxRemoveNonFilenameCharacters(wxString& str);
00223 
00225 wxString AxGetSpeakableTextForKeyCode(int keycode);
00226 
00227 #endif
00228     // _AX_UTILS_H_

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