Files
AscEmu/dep/loadlib/loadlib.cpp
2023-01-02 17:56:56 +02:00

86 lines
1.9 KiB
C++

/*
* AscEmu Framework based on ArcEmu MMORPG Server
* Copyright (c) 2014-2023 AscEmu Team <http://www.ascemu.org>
* Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#define _CRT_SECURE_NO_DEPRECATE
#include "loadlib.h"
#include "mpq_libmpq04.h"
#include <cstdio>
class MPQFile;
u_map_fcc MverMagic = { {'R','E','V','M'} };
FileLoader::FileLoader()
{
data = 0;
data_size = 0;
version = 0;
}
FileLoader::~FileLoader()
{
free();
}
bool FileLoader::loadFile(std::string const& fileName, bool log)
{
free();
MPQFile mf(fileName.c_str());
if(mf.isEof())
{
if (log)
printf("No such file %s\n", fileName.c_str());
return false;
}
data_size = mf.getSize();
data = new uint8_t [data_size];
mf.read(data, data_size);
mf.close();
if (prepareLoadedData())
return true;
printf("Error loading %s", fileName.c_str());
mf.close();
free();
return false;
}
bool FileLoader::prepareLoadedData()
{
// Check version
version = (file_MVER *) data;
if (version->fcc != MverMagic.fcc)
return false;
if (version->ver != FILE_FORMAT_VERSION)
return false;
return true;
}
void FileLoader::free()
{
if (data) delete[] data;
data = 0;
data_size = 0;
version = 0;
}