TrinityCore
DB2FileSystemSource.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "DB2FileSystemSource.h"
19#include <boost/filesystem/operations.hpp>
20
21DB2FileSystemSource::DB2FileSystemSource(std::string const& fileName)
22{
23 _fileName = fileName;
24 _file = fopen(_fileName.c_str(), "rb");
25}
26
28{
29 if (_file)
30 fclose(_file);
31}
32
34{
35 return _file != nullptr;
36}
37
38bool DB2FileSystemSource::Read(void* buffer, std::size_t numBytes)
39{
40 return fread(buffer, numBytes, 1, _file) == 1;
41}
42
44{
45 return ftell(_file);
46}
47
49{
50 return fseek(_file, position, SEEK_SET) == 0;
51}
52
54{
55 boost::system::error_code error;
56 int64 size = boost::filesystem::file_size(_fileName, error);
57 return !error ? size : 0;
58}
59
61{
62 return _fileName.c_str();
63}
64
66{
68}
DB2EncryptedSectionHandling
Definition: DB2FileLoader.h:95
int64_t int64
Definition: Define.h:137
constexpr std::size_t size()
Definition: UpdateField.h:796
char const * GetFileName() const override
bool IsOpen() const override
int64 GetPosition() const override
DB2FileSystemSource(std::string const &fileName)
int64 GetFileSize() const override
bool Read(void *buffer, std::size_t numBytes) override
DB2EncryptedSectionHandling HandleEncryptedSection(DB2SectionHeader const &sectionHeader) const override
bool SetPosition(int64 position) override