// Ryzom - MMORPG Framework
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
#include "reference_builder.h"
#include "pds_table_buffer.h"
//#include "pd_string_manager.h"
#include
#include
#include
using namespace std;
using namespace NLMISC;
/*
* Constructor
*/
CReferenceBuilder::CReferenceBuilder()
{
}
/*
* Build a new reference from a older reference
* Apply delta changes so new reference is clean
*/
bool CReferenceBuilder::build(CRefIndex& previous, CRefIndex& next)
{
return build(previous.getRootPath(),
previous.getPath(),
next.getPath(),
previous.getRootPath()+"hours",
previous.getRootPath()+"minutes",
previous.getRootPath()+"seconds",
previous.getRootPath()+"logs",
previous.Timestamp.toString(),
next.Timestamp.toString());
}
/*
* Build a new reference from a older reference
* Apply delta changes so new reference is clean
*/
bool CReferenceBuilder::build( const std::string& rootRefPath,
const std::string& previousReferencePath,
const std::string& nextReferencePath,
const std::string& hoursUpdatePath,
const std::string& minutesUpdatePath,
const std::string& secondsUpdatePath,
const std::string& logPath,
const std::string& mintimestamp,
const std::string& maxtimestamp,
volatile bool* stopAsked)
{
if (!internalBuild( rootRefPath,
previousReferencePath,
nextReferencePath,
hoursUpdatePath,
minutesUpdatePath,
secondsUpdatePath,
logPath,
mintimestamp,
maxtimestamp,
stopAsked))
{
// clean up if failed...
// delete all files generated in the next reference path
vector files;
NLMISC::CPath::getPathContent(nextReferencePath, false, false, true, files);
uint i;
for (i=0; i files;
NLMISC::CPath::getPathContent(previous, false, false, true, files);
for (i=0; i updateList;
if (!buildUpdateList(updateList, hourspath) ||
!buildUpdateList(updateList, minutespath) ||
!buildUpdateList(updateList, secondspath))
{
nlwarning("CReferenceBuilder::build(): failed to build update list for new reference '%s'", next.c_str());
return false;
}
// first apply hours, then minutes and eventually seconds delta updates
if (!updateReference(updateList, minstamp, maxstamp, rootRefPath, next))
{
nlwarning("CReferenceBuilder::build(): failed to build next reference '%s'", next.c_str());
return false;
}
// buildStringManagerRef(previousReferencePath, nextReferencePath,
// logPath,
// minstamp, maxstamp);
return true;
}
/*
* Apply delta
*/
bool CReferenceBuilder::updateReference(std::vector& updateList,
const CTimestamp& baseTimestamp,
const CTimestamp& endTimestamp,
const string& refRootPath,
const string& refPath,
volatile bool* stopAsked)
{
if (updateList.empty())
return true;
uint i, j;
for (i=0; i= endTimestamp)
continue;
if (!tableBuffer.applyDeltaChanges(update.Filename))
{
nlwarning("CReferenceBuilder::updateReference(): failed to apply delta file '%s'", update.Filename.c_str());
return false;
}
PDS_LOG_DEBUG(1)("CReferenceBuilder::updateReference(): updated reference with file '%s'", update.Filename.c_str());
}
}
return true;
}
/*
* Build update list
*/
bool CReferenceBuilder::buildUpdateList(std::vector& updateList, const std::string& filePath)
{
vector fileList;
NLMISC::CPath::getPathContent(filePath, false, false, true, fileList);
if (fileList.empty())
return true;
// sort table by id first then date
sort(fileList.begin(), fileList.end());
uint i;
for (i=0; i= update.StartTime && starttime < update.EndTime) ||
(endtime > update.StartTime && endtime <= update.EndTime))
{
insert = false;
break;
}
}
if (!insert)
continue;
CUpdateFile update;
update.StartTime = starttime;
update.EndTime = endtime;
update.Filename = fileList[i];
list.insert(it, update);
}
return true;
}
/* Build string manager reference
*
*/
//bool CReferenceBuilder::buildStringManagerRef(const std::string& previousReferencePath,
// const std::string& nextReferencePath,
// const std::string& logPath,
// const CTimestamp& baseTimestamp,
// const CTimestamp& endTimestamp)
//{
// RY_PDS::CPDStringManager sm;
//
// if (!sm.load(previousReferencePath))
// {
// nlwarning("CReferenceBuilder::build(): failed to load previous reference string manager");
// return false;
// }
//
// vector filelist;
// NLMISC::CPath::getPathContent(logPath, false, false, true, filelist);
//
// vector updateList;
//
// uint i;
// for (i=0; i= baseTimestamp && stamp <= endTimestamp)
// {
// updateList.push_back(filelist[i]);
// }
// }
//
// sort(updateList.begin(), updateList.end());
//
// for (i=0; i