mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 13:37:05 +00:00
[Rel21] Stage 1 of updates for Rel21 Build System
This commit is contained in:
parent
13292befd6
commit
fdefc0869a
1951 changed files with 40474 additions and 252610 deletions
168
dep/loadlib/loadlib.cpp
Normal file
168
dep/loadlib/loadlib.cpp
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
/**
|
||||
* MaNGOS is a full featured server for World of Warcraft, supporting
|
||||
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
|
||||
*
|
||||
* Copyright (C) 2005-2015 MaNGOS project <http://getmangos.eu>
|
||||
*
|
||||
* 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 2 of the License, or
|
||||
* (at your option) 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
|
||||
* and lore are copyrighted by Blizzard Entertainment, Inc.
|
||||
*/
|
||||
|
||||
#include "loadlib.h"
|
||||
|
||||
ArchiveSet gOpenArchives;
|
||||
|
||||
ArchiveSetBounds GetArchivesBounds()
|
||||
{
|
||||
return ArchiveSetBounds(gOpenArchives.begin(), gOpenArchives.end());
|
||||
}
|
||||
|
||||
bool OpenArchive(char const* mpqFileName, HANDLE* mpqHandlePtr /*= NULL*/)
|
||||
{
|
||||
HANDLE mpqHandle;
|
||||
|
||||
if (!SFileOpenArchive(mpqFileName, 0, MPQ_OPEN_READ_ONLY, &mpqHandle))
|
||||
return false;
|
||||
|
||||
gOpenArchives.push_back(mpqHandle);
|
||||
|
||||
if (mpqHandlePtr)
|
||||
*mpqHandlePtr = mpqHandle;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OpenNewestFile(char const* filename, HANDLE* fileHandlerPtr)
|
||||
{
|
||||
for (ArchiveSet::const_reverse_iterator i = gOpenArchives.rbegin(); i != gOpenArchives.rend();++i)
|
||||
{
|
||||
// always prefer get updated file version
|
||||
if (SFileOpenFileEx(*i, filename, SFILE_OPEN_PATCHED_FILE, fileHandlerPtr))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ExtractFile(char const* mpq_name, std::string const& filename)
|
||||
{
|
||||
for (ArchiveSet::const_reverse_iterator i = gOpenArchives.rbegin(); i != gOpenArchives.rend();++i)
|
||||
{
|
||||
HANDLE fileHandle;
|
||||
if (!SFileOpenFileEx(*i, mpq_name, SFILE_OPEN_PATCHED_FILE, &fileHandle))
|
||||
continue;
|
||||
|
||||
if (SFileGetFileSize(fileHandle, NULL) == 0) // some files removed in next updates and its reported size 0
|
||||
{
|
||||
printf("Skipping zero-size file: %s\n", mpq_name);
|
||||
SFileCloseFile(fileHandle);
|
||||
return false;
|
||||
}
|
||||
|
||||
SFileCloseFile(fileHandle);
|
||||
|
||||
if (!SFileExtractFile(*i, mpq_name, filename.c_str(), SFILE_OPEN_PATCHED_FILE))
|
||||
{
|
||||
printf("Can't extract file: %s\n", mpq_name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CloseArchives()
|
||||
{
|
||||
for (ArchiveSet::const_iterator i = gOpenArchives.begin(); i != gOpenArchives.end();++i)
|
||||
SFileCloseArchive(*i);
|
||||
|
||||
gOpenArchives.clear();
|
||||
}
|
||||
|
||||
FileLoader::FileLoader()
|
||||
{
|
||||
data = 0;
|
||||
data_size = 0;
|
||||
version = 0;
|
||||
}
|
||||
|
||||
FileLoader::~FileLoader()
|
||||
{
|
||||
free();
|
||||
}
|
||||
|
||||
bool FileLoader::loadFile(char* filename, bool log)
|
||||
{
|
||||
free();
|
||||
HANDLE fileHandle = 0;
|
||||
|
||||
if (!OpenNewestFile(filename, &fileHandle))
|
||||
{
|
||||
if (log)
|
||||
{ printf("No such file %s\n", filename); }
|
||||
return false;
|
||||
}
|
||||
|
||||
data_size = SFileGetFileSize(fileHandle, NULL);
|
||||
|
||||
data = new uint8 [data_size];
|
||||
if (!data)
|
||||
{
|
||||
SFileCloseFile(fileHandle);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!SFileReadFile(fileHandle, data, data_size, NULL, NULL))
|
||||
{
|
||||
if (log)
|
||||
printf("Can't read file %s\n", filename);
|
||||
|
||||
SFileCloseFile(fileHandle);
|
||||
return false;
|
||||
}
|
||||
|
||||
SFileCloseFile(fileHandle);
|
||||
|
||||
if (!prepareLoadedData())
|
||||
{
|
||||
printf("Error loading %s\n\n", filename);
|
||||
free();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool FileLoader::prepareLoadedData()
|
||||
{
|
||||
// Check version
|
||||
version = (file_MVER*) data;
|
||||
if (version->fcc != 'MVER')
|
||||
{ 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue