Added: Tool logger error logging in build_interface.

--HG--
branch : build_pipeline_v3
hg/feature/build_pipeline_v3
kaetemi 13 years ago
parent a665277784
commit 5454f8a724

@ -30,6 +30,8 @@
#include <vector>
#include <string>
#include "../../pipeline/pipeline_service/tool_logger.h"
// ---------------------------------------------------------------------------
using namespace std;
@ -39,8 +41,9 @@ using namespace NLMISC;
//char sExeDir[MAX_PATH];
std::string sExeDir;
NLMISC::CApplicationContext _ApplicationContext;
PIPELINE::CToolLogger ToolLogger;
void outString (const string &sText)
void outString(const string &sText)
{
std::string sCurDir = CPath::getCurrentPath();
CPath::setCurrentPath(sExeDir.c_str());
@ -197,15 +200,6 @@ int main(int nNbArg, char **ppArgs)
//GetCurrentDirectory (MAX_PATH, sExeDir);
sExeDir = CPath::getCurrentPath();
if (nNbArg < 3)
{
outString ("ERROR : Wrong number of arguments\n");
outString ("USAGE : build_interface [-s<existing_uv_txt_name>] <out_tga_name> <path_maps1> [path_maps2] [path_maps3] ....\n");
outString (" -s : build a subset of an existing interface definition while preserving the existing texture ids,");
outString (" to support freeing up VRAM by switching to the subset without rebuilding the entire interface\n");
return -1;
}
// build as a subset of existing interface
bool buildSubset = false;
string existingUVfilename;
@ -219,7 +213,13 @@ int main(int nNbArg, char **ppArgs)
case 'S':
case 's':
buildSubset = true;
existingUVfilename = string( ppArgs[i]+2 );
existingUVfilename = string(ppArgs[i] + 2);
break;
case 'd':
ToolLogger.initDepend(string(ppArgs[i] + 2));
break;
case 'e':
ToolLogger.initError(string(ppArgs[i] + 2));
break;
default:
break;
@ -229,14 +229,24 @@ int main(int nNbArg, char **ppArgs)
inputDirs.push_back(ppArgs[i]);
}
string fmtName;
uint iNumDirs = (uint)inputDirs.size();
if( iNumDirs )
if (iNumDirs < 2)
{
fmtName = inputDirs.front();
outString ("ERROR : Wrong number of arguments\n");
outString ("USAGE : build_interface [-s<existing_uv_txt_name>] [-d<depend_log_file>] [-e<error_log_file>] <out_tga_name> <path_maps1> [path_maps2] [path_maps3] ....\n");
outString (" -s : build a subset of an existing interface definition while preserving the existing texture ids,");
outString (" to support freeing up VRAM by switching to the subset without rebuilding the entire interface\n");
return -1;
}
std::string tgaName = inputDirs.front();
inputDirs.pop_front();
--iNumDirs;
}
if (tgaName.rfind('.') == string::npos)
tgaName += ".tga";
std::string uvName = tgaName.substr(0, tgaName.rfind('.'));
uvName += ".txt";
vector<string> AllMapNames;
list<string>::iterator it = inputDirs.begin();
list<string>::iterator itEnd = inputDirs.end();
@ -245,7 +255,9 @@ int main(int nNbArg, char **ppArgs)
string sDir = *it++;
if( !CFile::isDirectory(sDir) )
{
outString (string("ERROR : directory ") + sDir + " does not exist\n");
outString(string("ERROR : directory ") + sDir + " does not exist\n");
ToolLogger.writeError(PIPELINE::ERROR, sDir, "Directory does not exist.");
ToolLogger.release();
return -1;
}
CPath::getPathContent(sDir, false, false, true, AllMapNames);
@ -270,6 +282,8 @@ int main(int nNbArg, char **ppArgs)
catch (const NLMISC::Exception &e)
{
outString (string("ERROR :") + e.what());
ToolLogger.writeError(PIPELINE::ERROR, AllMapNames[i], e.what());
ToolLogger.release();
return -1;
}
}
@ -362,12 +376,10 @@ int main(int nNbArg, char **ppArgs)
CPath::setCurrentPath(sExeDir.c_str());
NLMISC::COFile outTga;
if (fmtName.rfind('.') == string::npos)
fmtName += ".tga";
if (outTga.open(fmtName))
if (outTga.open(tgaName))
{
std::string ext;
if (toLower(fmtName).find(".png") != string::npos)
if (toLower(tgaName).find(".png") != string::npos)
{
ext = "png";
GlobalTexture.writePNG (outTga, 32);
@ -379,19 +391,20 @@ int main(int nNbArg, char **ppArgs)
}
outTga.close();
outString (toString("Writing %s file : %s\n", ext.c_str(), fmtName.c_str()));
outString (toString("Writing %s file : %s\n", ext.c_str(), tgaName.c_str()));
}
else
{
outString (string("ERROR: Cannot write tga file : ") + fmtName + "\n");
outString (string("ERROR: Cannot write tga or png file : ") + tgaName + "\n");
ToolLogger.writeError(PIPELINE::ERROR, tgaName, "Cannot write tga or png file.");
ToolLogger.release();
return EXIT_FAILURE;
}
// Write UV text file
if( !buildSubset )
{
fmtName = fmtName.substr(0, fmtName.rfind('.'));
fmtName += ".txt";
FILE *f = fopen (fmtName.c_str(), "wt");
FILE *f = fopen (uvName.c_str(), "wt");
if (f != NULL)
{
for (i = 0; i < mapSize; ++i)
@ -402,11 +415,14 @@ int main(int nNbArg, char **ppArgs)
UVMax[i].U, UVMax[i].V);
}
fclose (f);
outString (string("Writing UV file : ") + fmtName + "\n");
outString (string("Writing UV file : ") + uvName + "\n");
}
else
{
outString (string("ERROR: Cannot write UV file : ") + fmtName + "\n");
outString (string("ERROR: Cannot write UV file : ") + uvName + "\n");
ToolLogger.writeError(PIPELINE::ERROR, uvName, "Cannot write UV file.");
ToolLogger.release();
return EXIT_FAILURE;
}
}
else // build as a subset
@ -417,18 +433,20 @@ int main(int nNbArg, char **ppArgs)
if( (filename == "") || (!iFile.open(filename)) )
{
outString (string("ERROR : could not open file ") + existingUVfilename + "\n");
return -1;
ToolLogger.writeError(PIPELINE::ERROR, existingUVfilename, "Could not open file.");
ToolLogger.release();
return EXIT_FAILURE;
}
// Write subset UV text file
fmtName = fmtName.substr(0, fmtName.rfind('.'));
fmtName += ".txt";
FILE *f = fopen (fmtName.c_str(), "wt");
FILE *f = fopen (uvName.c_str(), "wt");
if (f == NULL)
{
outString (string("ERROR: Cannot write UV file : ") + fmtName + "\n");
outString (string("ERROR: Cannot write UV file : ") + uvName + "\n");
ToolLogger.writeError(PIPELINE::ERROR, uvName, "Cannot write UV file.");
ToolLogger.release();
// fclose (iFile);
return -1;
return EXIT_FAILURE;
}
char bufTmp[256], tgaName[256];
@ -467,8 +485,9 @@ int main(int nNbArg, char **ppArgs)
}
// fclose (iFile);
fclose (f);
outString (string("Writing UV file : ") + fmtName + "\n");
outString (string("Writing UV file : ") + uvName + "\n");
}
return 0;
ToolLogger.release();
return EXIT_SUCCESS;
}

@ -52,7 +52,7 @@ const std::string s_Error = "ERROR";
const std::string s_Warning = "WARNING";
const std::string s_Message = "MESSAGE";
const std::string s_ErrorHeader = "type\tfile\ttime\terror";
const std::string s_ErrorHeader = "type\tpath\ttime\terror";
const std::string s_DependHeader = "output_file\tinput_file";
}
@ -65,10 +65,11 @@ const std::string s_DependHeader = "output_file\tinput_file";
*/
class CToolLogger
{
public:
private:
FILE *m_ErrorLog;
FILE *m_DependLog;
public:
CToolLogger()
{
@ -76,8 +77,7 @@ public:
virtual ~CToolLogger()
{
releaseError();
releaseDepend();
release();
}
void initError(const std::string &errorLog)
@ -101,7 +101,7 @@ public:
fflush(m_DependLog);
}
void writeError(EError type, const std::string &file, const std::string &error)
void writeError(EError type, const std::string &path, const std::string &error)
{
if (m_ErrorLog)
{
@ -109,6 +109,7 @@ public:
}
}
/// inputFile can only be file. May be not-yet-existing file for expected input. Directories are handled on process level.
void writeDepend(const std::string &outputFile, const std::string &inputFile)
{
if (m_DependLog)
@ -117,6 +118,7 @@ public:
fwrite("\t", 1, 1, m_DependLog);
fwrite(inputFile.c_str(), 1, inputFile.length(), m_DependLog);
fwrite("\n", 1, 1, m_DependLog);
fflush(m_DependLog);
}
}
@ -139,6 +141,12 @@ public:
m_DependLog = NULL;
}
}
void release()
{
releaseError();
releaseDepend();
}
}; /* class CToolLogger */
} /* namespace PIPELINE */

Loading…
Cancel
Save