Matrix Science Mascot Parser toolkit
 
Loading...
Searching...
No Matches
ms_fileutilities.hpp
1/*
2##############################################################################
3# file: ms_fileutilities.hpp #
4# 'msparser' toolkit #
5# Utilities class that encompasses all file-system-related functionality #
6##############################################################################
7# COPYRIGHT NOTICE #
8# Copyright 1998-2012 Matrix Science Limited All Rights Reserved. #
9# #
10##############################################################################
11# $Archive:: /Mowse/ms_mascotresfile/include/ms_fileutilities.hpp $ #
12# $Author: robertog@matrixscience.com $ #
13# $Date: 2023-01-30 13:52:08 +0000 $ #
14# $Revision: fe39c307262d12f8f7b679ca3ee7d4195657e703 | MSPARSER_REL_3_0_0-2024-09-24-0-g93ebaeb4f4 $ #
15# $NoKeywords:: $ #
16##############################################################################
17*/
18
19#ifndef MS_FILEUTILITIES_HPP
20#define MS_FILEUTILITIES_HPP
21
22
23#include <string>
24
25// For _finddata_t
26#ifdef _WIN32
27#include <io.h>
28#endif
29
30// For off_t
31#ifdef __GNU__
32#include <unistd.h>
33#endif
34
35namespace matrix_science {
36 class ms_mascotoptions;
42#ifdef _WIN32
43#if defined(_MSC_VER) && (_MSC_VER < 1300)
44#define OFFSET64_C(c) c ## i64
45#else
46#define OFFSET64_C(c) c ## LL
47#endif
48 typedef INT64 OFFSET64_T;
49#else // !_WIN32
50#define OFFSET64_C(c) c ## LL
51 typedef off_t OFFSET64_T;
52#endif // !_WIN32
53
55
60 class MS_MASCOTRESFILE_API ms_fileutilities
61 {
62 public:
65
67 static time_t getLastModificationTime(const char* filename, ms_errs* err = NULL);
68
70 static void setLastModificationTime(const char* filename, time_t modificationTime, ms_errs* err = NULL);
71
73 static UINT64 getFileSize(const char* filename, ms_errs* err = NULL);
74
76 static std::string findMascotDat(const char *szMascotDatFilename,
77 ms_errs * err = NULL,
78 const int timeoutSec = 0 );
79
81 static bool doesFileExist(const char* filename);
82
83 static bool isFileWritable(const char * filePath);
84
86 enum err_sar {
92 SAR_FAIL_CHOWN
93 };
95
98 err_sar setAccessRights(const char * filename,
99 const bool bWrite,
100 const bool bExecute,
101 const bool isFile,
102 const ms_mascotoptions & Options,
103 const bool avoid_reapply = false);
104 unsigned long getSARExtendedErrorCode() const;
105
107 static bool isDirectory(const char * path);
108
109#ifndef SWIG
111 static int createDirectory(const std::string & directory, std::string & errorDirectory);
112#else // SWIG Multiple return values
113 static int createDirectory(const std::string & directory, std::string & OUTPUT);
114#endif
116 static int deleteDirectory(const std::string & directory, const bool bDeleteSubdirectories = true);
117
119 bool findOpen(const std::string directory,
120 const std::string wildcard);
121
123 bool findNext(std::string & fileName);
124
126 void findClose();
127
129 static std::string stripLastFolder(const std::string pathname);
130
132 static std::string getMD5Sum(const std::string &str, const bool b32bitEncoding = true);
133
136 CMD_ARGUMENT_PARSE_OK = 0,
137 CMD_ARGUMENT_PARSE_UNBALANCED = -1,
138 CMD_ARGUMENT_PARSE_COLLISION = -2,
139 CMD_ARGUMENT_PARSE_INVALIDCHAR = -3,
140 };
141
143 static int parseCommandLineArgumentString(const std::string &command, std::vector<std::string> &components);
144
147 CMPXML_NO_FLAG = 0x0000,
148 CMPXML_IGN_DBL_IDENTICAL = 0x0001,
149 CMPXML_IGN_DBL_DIFF_100_PPM = 0x0002,
150 CMPXML_IGN_DBL_DIFF_10_PPM = 0x0004,
151 CMPXML_IGN_DBL_DIFF_1_PPM = 0x0008,
152 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),
153
154 CMPXML_STRIP_TRAILING_ZEROS = 0x0010,
155 CMPXML_IGN_COL_SIZE_EQ_ONE = 0x0020,
156 CMPXML_IGN_TODAY_DATE = 0x0040,
157 CMPXML_IGN_INF_999999 = 0x0080,
158 CMPXML_IGN_FILE_URL = 0x0100,
159 CMPXML_IGN_RAWFILE_NAME = 0x0200,
160
161 // CMPXML_IGN_IF_CWD_INCLUDED = 0x0100, //!< If there's a path name in an attribute and if that contains the current directory, then it's unlikey to match
162 };
163#ifndef SWIG
165 static bool compareXmlFiles(const std::string & filePath1,
166 const std::string & filePath2,
167 const std::string & schemaPath,
168 const int flags,
169 const std::vector<std::string> & ignoreElements,
170 const std::vector<std::string> & ignoreAttributes,
171 ms_errs & errs,
172 std::string & differences,
173 std::string & lhsOnly,
174 std::string & rhsOnly);
175#else // SWIG Multiple return values
176 static bool compareXmlFiles(const std::string & filePath1,
177 const std::string & filePath2,
178 const std::string & schemaPath,
179 const int flags,
180 const std::vector<std::string> & ignoreElements,
181 const std::vector<std::string> & ignoreAttributes,
182 ms_errs & errs,
183 std::string & OUTPUT,
184 std::string & OUTPUT,
185 std::string & OUTPUT);
186#endif
187
188 static std::string getCacheDirectory(const std::string& resFilePath,
189 const std::string& cacheDirPattern,
190 std::string& fileNameNoPath,
191 ms_errs* errorHandler);
192
193 private:
194 unsigned long errorCode_;
195#ifdef _WIN32
196#if defined(_MSC_VER) && (_MSC_VER < 1300)
197 struct _finddata_t fileFindInfo_;
198 int fileFindPtr_;
199#else
200 struct __finddata64_t fileFindInfo_;
201 intptr_t fileFindPtr_;
202#endif
203#else
204 void * fileFindDir_; // void * rather than DIR * so no need to include dirent.h
205#endif
206 std::string fileFindWildcard_;
207 std::string fileFindDirectory_;
208
209 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);
210
211 static const std::string ws_delims_;
212 static const char begin_quote_ = '"';
213 static const char end_quote_ = '"';
214 static const std::string invalid_chars_;
215
216 }; // class ms_fileutilities // end of tools_group
218} // namespace matrix_science
219#endif // MS_FILEUTILITIES_HPP
220
221/*------------------------------- End of File -------------------------------*/
All errors are collected in an instance of this class.
Definition: ms_errors.hpp:37
This utility class mainly contains static members.
Definition: ms_fileutilities.hpp:61
compareXMLFiles_flags
Flags for the compareXmlFiles() function.
Definition: ms_fileutilities.hpp:146
CMD_ARGUMENT_PARSE_RESULT
Return status from parseCommandLineArgumentString().
Definition: ms_fileutilities.hpp:135
err_sar
setAccessRights() return value.
Definition: ms_fileutilities.hpp:86
@ SAR_FAIL_SET_ENTRIES_IN_ACL
Error returned by call to SetEntriesInAcl().
Definition: ms_fileutilities.hpp:90
@ SAR_SUCCESS
Success!
Definition: ms_fileutilities.hpp:87
@ SAR_FAIL_GET_NAMED_SECURITY_INFO
Error returned by call to GetNamedSecurityInfo().
Definition: ms_fileutilities.hpp:89
@ SAR_FAIL_CHMOD
Error returned by call to chmod().
Definition: ms_fileutilities.hpp:88
@ SAR_FAIL_SET_NAMED_SECURITY_INFO
Error returned by call to SetNamedSecurityInfo().
Definition: ms_fileutilities.hpp:91
An instance of this class represents all the parameters specified in the Options section of mascot....
Definition: ms_mascotoptions.hpp:91