Directory Structure [step 1]: moving files

working on #672

NOTE: This commit can't be compiled!!
This commit is contained in:
Yehonal
2017-10-12 20:00:52 +02:00
parent 4df28fd29c
commit f06f32849f
2508 changed files with 0 additions and 1325 deletions

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C)
*
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*/
#include "ChunkedData.h"
#include "MPQManager.h"
#include "Utils.h"
#include <string>
ChunkedData::ChunkedData( FILE* stream, uint32 maxLength, uint32 chunksHint /*= 300*/ ) :
Stream(stream)
{
if (!Stream)
return;
Load(maxLength, chunksHint);
}
ChunkedData::ChunkedData( const std::string& file, uint32 chunksHint /*= 300*/ )
{
Stream = MPQHandler->GetFile(file);
if (!Stream)
return;
Load(0, chunksHint);
}
void ChunkedData::Load( uint32 maxLength, uint32 chunksHint )
{
if (!maxLength)
maxLength = Utils::Size(Stream);
Chunks.reserve(chunksHint);
uint32 baseOffset = ftell(Stream);
uint32 calcOffset = 0;
while ((calcOffset + baseOffset) < Utils::Size(Stream) && (calcOffset < maxLength))
{
char nameBytes[5];
uint32 read = fread(&nameBytes, sizeof(char), 4, Stream);
nameBytes[read] = '\0';
std::string name = std::string(nameBytes);
// Utils::Reverse(nameBytes);
name = std::string(name.rbegin(), name.rend());
uint32 length;
if (fread(&length, sizeof(uint32), 1, Stream) != 1)
continue;
calcOffset += 8;
Chunks.push_back(new Chunk(name.c_str(), length, calcOffset + baseOffset, Stream));
calcOffset += length;
// save an extra seek at the end
if ((calcOffset + baseOffset) < Utils::Size(Stream) && calcOffset < maxLength)
fseek(Stream, length, SEEK_CUR);
}
}
int ChunkedData::GetFirstIndex( const std::string& name )
{
for (uint32 i = 0; i < Chunks.size(); ++i)
if (Chunks[i]->Name == name)
return i;
return -1;
}
Chunk* ChunkedData::GetChunkByName( const std::string& name )
{
for (uint32 i = 0; i < Chunks.size(); ++i)
if (Chunks[i]->Name == name)
return Chunks[i];
return NULL;
}
ChunkedData::~ChunkedData()
{
for (std::vector<Chunk*>::iterator itr = Chunks.begin(); itr != Chunks.end(); ++itr)
delete *itr;
Chunks.clear();
if (Stream)
fclose(Stream);
}