00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef MS_FILEUTILITIES_HPP
00020 #define MS_FILEUTILITIES_HPP
00021
00022
00023 #include <string>
00024
00025
00026 #ifdef _WIN32
00027 #include <io.h>
00028 #endif
00029
00030
00031 #ifdef __GNU__
00032 #include <unistd.h>
00033 #endif
00034
00035 namespace matrix_science {
00036 class ms_mascotoptions;
00042 #ifdef _WIN32
00043 #if defined(_MSC_VER) && (_MSC_VER < 1300)
00044 #define OFFSET64_C(c) c ## i64
00045 #else
00046 #define OFFSET64_C(c) c ## LL
00047 #endif
00048 typedef INT64 OFFSET64_T;
00049 #else // !_WIN32
00050 #define OFFSET64_C(c) c ## LL
00051 typedef off_t OFFSET64_T;
00052 #endif // !_WIN32
00053
00055
00060 class MS_MASCOTRESFILE_API ms_fileutilities
00061 {
00062 public:
00064 ms_fileutilities();
00065
00067 static time_t getLastModificationTime(const char* filename, ms_errs* err = NULL);
00068
00070 static void setLastModificationTime(const char* filename, time_t modificationTime, ms_errs* err = NULL);
00071
00073 static UINT64 getFileSize(const char* filename, ms_errs* err = NULL);
00074
00076 static std::string findMascotDat(const char *szMascotDatFilename,
00077 ms_errs * err = NULL,
00078 const int timeoutSec = 0 );
00079
00081 static bool doesFileExist(const char* filename);
00082
00083 static bool isFileWritable(const char * filePath);
00084
00086 enum err_sar {
00087 SAR_SUCCESS,
00088 SAR_FAIL_CHMOD,
00089 SAR_FAIL_GET_NAMED_SECURITY_INFO,
00090 SAR_FAIL_SET_ENTRIES_IN_ACL,
00091 SAR_FAIL_SET_NAMED_SECURITY_INFO,
00092 SAR_FAIL_CHOWN
00093 };
00095
00098 err_sar setAccessRights(const char * filename,
00099 const bool bWrite,
00100 const bool bExecute,
00101 const bool isFile,
00102 const ms_mascotoptions & Options,
00103 const bool avoid_reapply = false);
00104 unsigned long getSARExtendedErrorCode() const;
00105
00107 static bool isDirectory(const char * path);
00108
00109 #ifndef SWIG
00110
00111 static int createDirectory(const std::string & directory, std::string & errorDirectory);
00112 #else // SWIG Multiple return values
00113 static int createDirectory(const std::string & directory, std::string & OUTPUT);
00114 #endif
00115
00116 static int deleteDirectory(const std::string & directory, const bool bDeleteSubdirectories = true);
00117
00119 bool findOpen(const std::string directory,
00120 const std::string wildcard);
00121
00123 bool findNext(std::string & fileName);
00124
00126 void findClose();
00127
00129 static std::string stripLastFolder(const std::string pathname);
00130
00132 static std::string getMD5Sum(const std::string &str, const bool b32bitEncoding = true);
00133
00135 enum CMD_ARGUMENT_PARSE_RESULT {
00136 CMD_ARGUMENT_PARSE_OK = 0,
00137 CMD_ARGUMENT_PARSE_UNBALANCED = -1,
00138 CMD_ARGUMENT_PARSE_COLLISION = -2,
00139 CMD_ARGUMENT_PARSE_INVALIDCHAR = -3,
00140 };
00141
00143 static int parseCommandLineArgumentString(const std::string &command, std::vector<std::string> &components);
00144
00146 enum compareXMLFiles_flags {
00147 CMPXML_NO_FLAG = 0x0000,
00148 CMPXML_IGN_DBL_IDENTICAL = 0x0001,
00149 CMPXML_IGN_DBL_DIFF_100_PPM = 0x0002,
00150 CMPXML_IGN_DBL_DIFF_10_PPM = 0x0004,
00151 CMPXML_IGN_DBL_DIFF_1_PPM = 0x0008,
00152 CMPXML_IGN_DBL_MASK = (CMPXML_IGN_DBL_IDENTICAL | CMPXML_IGN_DBL_DIFF_100_PPM | CMPXML_IGN_DBL_DIFF_10_PPM | CMPXML_IGN_DBL_DIFF_1_PPM),
00153
00154 CMPXML_STRIP_TRAILING_ZEROS = 0x0010,
00155 CMPXML_IGN_COL_SIZE_EQ_ONE = 0x0020,
00156 CMPXML_IGN_TODAY_DATE = 0x0040,
00157 CMPXML_IGN_INF_999999 = 0x0080,
00158 CMPXML_IGN_FILE_URL = 0x0100,
00159 CMPXML_IGN_RAWFILE_NAME = 0x0200,
00160
00161
00162 };
00163 #ifndef SWIG
00164
00165 static bool compareXmlFiles(const std::string & filePath1,
00166 const std::string & filePath2,
00167 const std::string & schemaPath,
00168 const int flags,
00169 const std::vector<std::string> & ignoreElements,
00170 const std::vector<std::string> & ignoreAttributes,
00171 ms_errs & errs,
00172 std::string & differences,
00173 std::string & lhsOnly,
00174 std::string & rhsOnly);
00175 #else // SWIG Multiple return values
00176 static bool compareXmlFiles(const std::string & filePath1,
00177 const std::string & filePath2,
00178 const std::string & schemaPath,
00179 const int flags,
00180 const std::vector<std::string> & ignoreElements,
00181 const std::vector<std::string> & ignoreAttributes,
00182 ms_errs & errs,
00183 std::string & OUTPUT,
00184 std::string & OUTPUT,
00185 std::string & OUTPUT);
00186 #endif
00187
00188 private:
00189 unsigned long errorCode_;
00190 #ifdef _WIN32
00191 #if defined(_MSC_VER) && (_MSC_VER < 1300)
00192 struct _finddata_t fileFindInfo_;
00193 int fileFindPtr_;
00194 #else
00195 struct __finddata64_t fileFindInfo_;
00196 intptr_t fileFindPtr_;
00197 #endif
00198 #else
00199 void * fileFindDir_;
00200 #endif
00201 std::string fileFindWildcard_;
00202 std::string fileFindDirectory_;
00203
00204 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);
00205
00206 static const std::string ws_delims_;
00207 static const char begin_quote_ = '"';
00208 static const char end_quote_ = '"';
00209 static const std::string invalid_chars_;
00210
00211 };
00213 }
00214 #endif // MS_FILEUTILITIES_HPP
00215
00216