// 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 "nel/misc/types_nl.h"
#include "nel/misc/config_file.h"
#include "nel/misc/sheet_id.h"
#include "nel/misc/path.h"
#include "nel/misc/diff_tool.h"
#include "nel/misc/algo.h"
#include "nel/georges/u_form.h"
#include "nel/georges/u_form_elm.h"
#include "nel/georges/load_form.h"
#include "nel/ligo/ligo_config.h"
#include "nel/ligo/primitive.h"
#include "nel/ligo/primitive_utils.h"
using namespace std;
using namespace NLMISC;
using namespace NLLIGO;
using namespace STRING_MANAGER;
static CLigoConfig LigoConfig;
static bool RemoveOlds = false;
// ***************************************************************************
/*
* Interface to build the whole list of words (key id) for a specific worksheet
*/
struct IWordListBuilder
{
virtual bool buildWordList(std::vector &allWords, string workSheetFileName) =0;
};
// ***************************************************************************
/*
* Specialisation of IWordListBuilder to list sheets in a directory
*/
struct CSheetWordListBuilder : public IWordListBuilder
{
string SheetExt;
string SheetPath;
virtual bool buildWordList(std::vector &allWords, string workSheetFileName)
{
SheetExt= toLower(SheetExt);
// verify the directory is correct
if(!CFile::isDirectory(SheetPath))
{
nlwarning("Error: Directory '%s' not found. '%s' Aborted", SheetPath.c_str(), workSheetFileName.c_str());
return false;
}
// list all files.
std::vector allFiles;
allFiles.reserve(100000);
CPath::getPathContent(SheetPath, true, false, true, allFiles, NULL);
// Keep only the extension we want, and remove "_" (parent)
allWords.clear();
allWords.reserve(allFiles.size());
for(uint i=0;i PrimFilter;
virtual bool buildWordList(std::vector &allWords, string workSheetFileName)
{
// verify the directory is correct
if(!CFile::isDirectory(PrimPath))
{
nlwarning("Error: Directory '%s' not found. '%s' Aborted", PrimPath.c_str(), workSheetFileName.c_str());
return false;
}
// list all files.
std::vector allFiles;
allFiles.reserve(100000);
CPath::getPathContent(PrimPath, true, false, true, allFiles, NULL);
// parse all primitive that match the filter
allWords.clear();
allWords.reserve(100000);
// to avoid duplicate
set allWordSet;
for(uint i=0;i setPlace;
TPrimitiveSet placeRes;
setPlace.buildSet(PrimDoc.RootNode, predCont, placeRes);
// for all found
for (uint placeId= 0; placeId < placeRes.size(); ++placeId)
{
string primName;
if(placeRes[placeId]->getPropertyByName(listProp[cid], primName) && !primName.empty())
{
primName= toLower(primName);
// avoid duplicate
if(allWordSet.insert(primName).second)
{
allWords.push_back(primName);
}
}
}
}
}
return true;
}
};
// ***************************************************************************
void extractNewWords(string workSheetFileName, string columnId, IWordListBuilder &wordListBuilder)
{
uint i;
// **** Load the excel sheet
// load
TWorksheet workSheet;
if(!loadExcelSheet(workSheetFileName, workSheet, true))
{
nlwarning("Error reading '%s'. Aborted", workSheetFileName.c_str());
return;
}
// get the key column index
uint keyColIndex = 0;
if(!workSheet.findCol(columnId, keyColIndex))
{
nlwarning("Error: Don't find the column '%s'. '%s' Aborted", columnId.c_str(), workSheetFileName.c_str());
return;
}
// get the name column index
uint nameColIndex = 0;
if(!workSheet.findCol(ucstring("name"), nameColIndex))
{
nlwarning("Error: Don't find the column 'name'. '%s' Aborted", workSheetFileName.c_str());
return;
}
// Make a copy of this worksheet, with strlwr on the key
// Yoyo: I prefer not modify the original worksheet (don't know what bad side effect it can have....)
TWorksheet workSheetLwr= workSheet;
for(i=0;i allWords;
if(!wordListBuilder.buildWordList(allWords, workSheetFileName))
return;
// **** Append new one to the worksheet
uint nbAdd= 0;
for(i=0;i")+keyName);
// add to the workSheet
workSheet.resize(workSheet.size()+1);
workSheet.setData(rowIdx, keyColIndex, keyName);
workSheet.setData(rowIdx, nameColIndex, string("")+keyName);
nbAdd++;
}
}
// **** Remove no more present ones (and log)
uint nbRemove= 0;
if(RemoveOlds)
{
// Build as a set
std::set allWordSet;
for(i=0;idisplayRawNL("'%s': '%s' entry erased at line '%d'.", workSheetFileName.c_str(),
keyStr.c_str(), i);
}
}
// resize to correct new size
tmpCopy.resize(dstRowId);
tmpCopyLwr.resize(dstRowId);
// copy back
workSheet= tmpCopy;
workSheetLwr= tmpCopyLwr;
}
// **** Save
if(nbAdd==0 && nbRemove==0)
{
if(RemoveOlds)
NLMISC::InfoLog->displayRawNL("'%s': No deprecated entry found.", workSheetFileName.c_str());
NLMISC::InfoLog->displayRawNL("'%s': No new entry found.", workSheetFileName.c_str());
// Don't save
}
else
{
if(RemoveOlds)
NLMISC::InfoLog->displayRawNL("'%s': %d deprecated entry erased.", workSheetFileName.c_str(), nbRemove);
NLMISC::InfoLog->displayRawNL("'%s': %d new entry found.", workSheetFileName.c_str(), nbAdd);
// Save the not lowered worksheet
ucstring s = prepareExcelSheet(workSheet);
try
{
CI18N::writeTextFile(workSheetFileName.c_str(), s);
}
catch (const Exception &e)
{
nlwarning("cannot save file: '%s'. Reason: %s", workSheetFileName.c_str(), e.what());
}
}
}
// ***************************************************************************
int extractNewSheetNames(int argc, char *argv[])
{
// **** read the parameters
for (int i=2; iaddNegativeFilter("numCol changed to");
NLMISC::InfoLog->addNegativeFilter("CPath::addSearchPath");
// **** read the configuration file
CConfigFile cf;
cf.load("bin/translation_tools.cfg");
CConfigFile::CVar &paths = cf.getVar("Paths");
CConfigFile::CVar &pathNoRecurse= cf.getVar("PathsNoRecurse");
CConfigFile::CVar &ligoClassFile= cf.getVar("LigoClassFile");
CConfigFile::CVar &leveldesignDataPathVar = cf.getVar("LeveldesignDataPath");
// parse path
for (uint i=0; i