86{
87 int fdot = pfilename.find_last_of('.');
88 string ending = pfilename.substr(fdot);
89 string filename;
90
91 if (ending == ".fld" || ending == ".chk" || ending == ".rst")
92 {
93 TiXmlDocument *xmlFldFile;
94 fs::path pathfilename(pfilename);
95
96 if (fs::is_directory(pathfilename))
97 {
98 std::vector<fs::path> dirfiles;
99
100
101 copy(fs::directory_iterator(pathfilename), fs::directory_iterator(),
102 back_inserter(dirfiles));
103
104 xmlFldFile = new TiXmlDocument;
105
106
107 for (int i = 0; i < dirfiles.size(); ++i)
108 {
110 std::ifstream file(infile.c_str());
111 ASSERTL0(file.good(),
"Unable to open file: " + infile);
112 file >> (*xmlFldFile);
113 }
114 }
115 else
116 {
117 xmlFldFile = new TiXmlDocument(pfilename);
118 xmlFldFile->LoadFile(pfilename);
119 }
120
121
122 TiXmlElement *vNektar = xmlFldFile->FirstChildElement("NEKTAR");
123 while (vNektar)
124 {
125
126 TiXmlNode *vMetaData = vNektar->FirstChild("Metadata");
127
128
129 if (vMetaData)
130 {
131 vNektar->RemoveChild(vMetaData);
132 }
133 vNektar = vNektar->NextSiblingElement("NEKTAR");
134 }
135
136 filename = pfilename + ".tmp";
137 xmlFldFile->SaveFile(filename);
138 }
139 else
140 {
141 filename = pfilename;
142 }
143
144
145 std::ifstream testFile(filename.c_str(), std::ios::binary);
146 ASSERTL0(testFile.is_open(),
"Error opening file " + filename);
147
148
149 std::vector<char> fileContents((std::istreambuf_iterator<char>(testFile)),
150 std::istreambuf_iterator<char>());
151
152
153 unsigned char hash[20];
154 char strhash[41];
155
156 sha1::calc((
void *)&fileContents[0], fileContents.size(), hash);
158
159
160 testFile.close();
161
162 return std::string(strhash);
163}
static std::string PortablePath(const fs::path &path)
create portable path on different platforms for std::filesystem path.
void toHexString(const unsigned char *hash, char *hexstring)
Calculate a string which represents the SHA1 hash as a hexadecimal number.
void calc(const void *src, const int bytelength, unsigned char *hash)
Calculate the SHA1 hash of some data set.