174{
176 LOG_INFO(
"server.loading",
">> Loading Cinematic Camera files");
177
180 {
181 std::string filenameWork = dataPath;
182 filenameWork.append(dbcentry->Model);
183
184
185 std::replace(filenameWork.begin(), filenameWork.end(), '\\', '/');
186
187 boost::filesystem::path filename = filenameWork;
188
189
190 filename.make_preferred();
191
192
193 filename.replace_extension("m2");
194
195 std::ifstream m2file(filename.string().c_str(), std::ios::in | std::ios::binary);
196 if (!m2file.is_open())
197 continue;
198
199
200 m2file.seekg(0, std::ios::end);
201 std::streamoff fileSize = m2file.tellg();
202
203
205 {
206 LOG_ERROR(
"server.loading",
"Camera file {} is damaged. File is smaller than header size", filename.string());
207 m2file.close();
208 continue;
209 }
210
211
212 m2file.seekg(0, std::ios::beg);
213 char fileCheck[5];
214 m2file.read(fileCheck, 4);
215 fileCheck[4] = 0;
216
217
218 if (strcmp(fileCheck, "MD20"))
219 {
220 LOG_ERROR(
"server.loading",
"Camera file {} is damaged. File identifier not found", filename.string());
221 m2file.close();
222 continue;
223 }
224
225
226 std::vector<char> buffer(fileSize);
227 m2file.seekg(0, std::ios::beg);
228 if (!m2file.read(buffer.data(), fileSize))
229 {
230 m2file.close();
231 continue;
232 }
233 m2file.close();
234
235
237
239 {
240 LOG_ERROR(
"server.loading",
"Camera file {} is damaged. Camera references position beyond file end", filename.string());
241 continue;
242 }
243
244
246 if (!
readCamera(cam, fileSize, header, dbcentry))
247 LOG_ERROR(
"server.loading",
"Camera file {} is damaged. Camera references position beyond file end", filename.string());
248 }
249
252}
#define LOG_INFO(filterType__,...)
Definition: Log.h:165
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:131
uint32 getMSTime()
Definition: Timer.h:103
std::uint32_t uint32
Definition: Define.h:107
DBCStorage< CinematicCameraEntry > sCinematicCameraStore(CinematicCameraEntryfmt)
bool readCamera(M2Camera const *cam, uint32 buffSize, M2Header const *header, CinematicCameraEntry const *dbcentry)
Definition: M2Stores.cpp:50
Definition: M2Structure.h:35
uint32 ofsCameras
Definition: M2Structure.h:95
Definition: M2Structure.h:120
Definition: DBCStructure.h:703