Matrix Science header

ms_fileutilities.hpp

00001 /*
00002 ##############################################################################
00003 # file: ms_fileutilities.hpp                                                 #
00004 # 'msparser' toolkit                                                         #
00005 # Utilities class that encompasses all file-system-related functionality     #
00006 ##############################################################################
00007 # COPYRIGHT NOTICE                                                           #
00008 # Copyright 1998-2012 Matrix Science Limited  All Rights Reserved.           #
00009 #                                                                            #
00010 ##############################################################################
00011 #    $Archive:: /Mowse/ms_mascotresfile/include/ms_fileutilities.hpp       $ #
00012 #     $Author: davidc $ #
00013 #       $Date: 2017/04/07 14:05:05 $ #
00014 #   $Revision: 1.26 $ #
00015 # $NoKeywords::                                                            $ #
00016 ##############################################################################
00017 */
00018 
00019 #ifndef MS_FILEUTILITIES_HPP
00020 #define MS_FILEUTILITIES_HPP
00021 
00022 #ifdef _WIN32
00023 #pragma warning(disable:4251)   // Don't want all classes to be exported
00024 #pragma warning(disable:4786)   // Debug symbols too long
00025 #   ifndef _MATRIX_USE_STATIC_LIB
00026 #       ifdef MS_MASCOTRESFILE_EXPORTS
00027 #           define MS_MASCOTRESFILE_API __declspec(dllexport)
00028 #       else
00029 #           define MS_MASCOTRESFILE_API __declspec(dllimport)
00030 #       endif
00031 #   else
00032 #       define MS_MASCOTRESFILE_API
00033 #   endif
00034 #else
00035 #   define MS_MASCOTRESFILE_API
00036 #endif
00037 
00038 // for the sake of #include <string>
00039 #ifdef __ALPHA_UNIX__
00040 #include <ctype.h>
00041 #endif
00042 #include <string>
00043 
00044 // For _finddata_t
00045 #ifdef _WIN32
00046 #include <io.h>
00047 #endif
00048 
00049 namespace matrix_science {
00050     class ms_mascotoptions;
00056 #ifdef _WIN32
00057 #if defined(_MSC_VER) && (_MSC_VER < 1300)
00058 #define OFFSET64_C(c) c ## i64
00059 #else
00060 #define OFFSET64_C(c) c ## LL
00061 #endif
00062     typedef INT64 OFFSET64_T;
00063 #else // !_WIN32
00064 #define OFFSET64_C(c) c ## LL
00065     typedef off_t   OFFSET64_T;
00066 #endif // !_WIN32
00067 
00069 
00074     class MS_MASCOTRESFILE_API ms_fileutilities
00075     {
00076     public:
00078         ms_fileutilities();
00079 
00081         static time_t getLastModificationTime(const char* filename, ms_errs* err = NULL);
00082 
00084         static void setLastModificationTime(const char* filename, time_t modificationTime, ms_errs* err = NULL);
00085 
00087         static UINT64 getFileSize(const char* filename, ms_errs* err = NULL);
00088 
00090         static std::string findMascotDat(const char *szMascotDatFilename, 
00091                                          ms_errs * err = NULL,
00092                                          const int timeoutSec = 0 );
00093 
00095         static bool doesFileExist(const char* filename);
00096 
00098         enum err_sar {
00099             SAR_SUCCESS,                        
00100             SAR_FAIL_CHMOD,                     
00101             SAR_FAIL_GET_NAMED_SECURITY_INFO,   
00102             SAR_FAIL_SET_ENTRIES_IN_ACL,        
00103             SAR_FAIL_SET_NAMED_SECURITY_INFO,   
00104             SAR_FAIL_CHOWN                      
00105         };
00107 
00110         err_sar setAccessRights(const char * filename, 
00111                                 const bool bWrite, 
00112                                 const bool bExecute, 
00113                                 const bool isFile,
00114                                 const ms_mascotoptions & Options);
00115         unsigned long getSARExtendedErrorCode() const;
00116 
00118         static bool isDirectory(const char * path);
00119 
00121         static int createDirectory(const std::string & directory, std::string & errorDirectory);
00122 
00124         static int deleteDirectory(const std::string & directory, const bool bDeleteSubdirectories = true);
00125 
00127         bool findOpen(const std::string directory,
00128                       const std::string wildcard);
00129 
00131         bool findNext(std::string & fileName);
00132 
00134         void findClose();
00135 
00137         static std::string stripLastFolder(const std::string pathname);
00138 
00140         static std::string getMD5Sum(const std::string &str, const bool b32bitEncoding = true);
00141 
00143         enum CMD_ARGUMENT_PARSE_RESULT {
00144             CMD_ARGUMENT_PARSE_OK = 0, 
00145             CMD_ARGUMENT_PARSE_UNBALANCED = -1, 
00146             CMD_ARGUMENT_PARSE_COLLISION = -2, 
00147             CMD_ARGUMENT_PARSE_INVALIDCHAR = -3, 
00148         };
00149 
00151         static int parseCommandLineArgumentString(const std::string &command, std::vector<std::string> &components);
00152 
00153     private:
00154         unsigned long errorCode_;
00155 #ifdef _WIN32
00156 #if defined(_MSC_VER) && (_MSC_VER < 1300)
00157         struct _finddata_t fileFindInfo_;
00158         int fileFindPtr_;
00159 #else
00160         struct __finddata64_t fileFindInfo_;
00161         intptr_t fileFindPtr_;
00162 #endif
00163 #else
00164         void * fileFindDir_;     // void * rather than DIR * so no need to include dirent.h
00165 #endif
00166         std::string fileFindWildcard_;
00167         std::string fileFindDirectory_;
00168 
00169         static CMD_ARGUMENT_PARSE_RESULT splitCommandString(const std::string &command, const std::string::size_type j1, const std::string::size_type j2, std::vector<std::string> &argvstr);
00170 
00171         static const std::string ws_delims_;
00172         static const char begin_quote_ = '"';
00173         static const char end_quote_ = '"';
00174         static const std::string invalid_chars_;
00175 
00176     }; // class ms_fileutilities // end of tools_group
00178 } // namespace matrix_science
00179 #endif // MS_FILEUTILITIES_HPP
00180 
00181 /*------------------------------- End of File -------------------------------*/
Copyright © 2016 Matrix Science Ltd.  All Rights Reserved. Generated on Fri Jun 2 2017 01:44:51