LogVisor report additions; Updated RetroCommon

This commit is contained in:
Jack Andersen 2015-07-05 15:35:08 -10:00
parent cd0b2f0926
commit 14a368553d
13 changed files with 94 additions and 91 deletions

View File

@ -15,7 +15,7 @@ public:
: ToolBase(info) : ToolBase(info)
{ {
if (m_info.args.empty()) if (m_info.args.empty())
throw HECL::Exception(_S("help requires a tool name argument")); LogModule.report(LogVisor::FatalError, "help requires a tool name argument");
} }
~ToolHelp() ~ToolHelp()
@ -78,7 +78,7 @@ public:
helpFunc = ToolHelp::Help; helpFunc = ToolHelp::Help;
else else
{ {
throw HECL::Exception(_S("unrecognized tool '") + toolName + _S("' - can't help")); LogModule.report(LogVisor::FatalError, _S("unrecognized tool '%s' - can't help"), toolName.c_str());
return; return;
} }

View File

@ -20,19 +20,19 @@ public:
if (HECL::Stat(dir->c_str(), &theStat)) if (HECL::Stat(dir->c_str(), &theStat))
{ {
throw HECL::Exception(_S("unable to stat '") + *dir + _S("'")); LogModule.report(LogVisor::FatalError, _S("unable to stat '%s'"), dir->c_str());
return; return;
} }
if (!S_ISDIR(theStat.st_mode)) if (!S_ISDIR(theStat.st_mode))
{ {
throw HECL::Exception(_S("'") + *dir + _S("' is not a directory")); LogModule.report(LogVisor::FatalError, _S("'%s' is not a directory"), dir->c_str());
return; return;
} }
HECL::SystemString testPath = *dir + _S("/.hecl/beacon"); HECL::SystemString testPath = *dir + _S("/.hecl/beacon");
if (!HECL::Stat(testPath.c_str(), &theStat)) if (!HECL::Stat(testPath.c_str(), &theStat))
{ {
throw HECL::Exception(_S("project already exists at '") + *dir + _S("'")); LogModule.report(LogVisor::FatalError, _S("project already exists at '%s'"), dir->c_str());
return; return;
} }
@ -48,12 +48,12 @@ public:
HECL::Database::Project proj((HECL::ProjectRootPath(*m_dir))); HECL::Database::Project proj((HECL::ProjectRootPath(*m_dir)));
proj.enableDataSpecs({_S("hecl-little")}); proj.enableDataSpecs({_S("hecl-little")});
} }
catch (HECL::Exception& e) catch (std::exception& e)
{ {
LogModule.report(LogVisor::Error, _S("unable to init project: '%s'\n"), e.swhat()); LogModule.report(LogVisor::Error, "unable to init project");
return -1; return -1;
} }
LogModule.report(LogVisor::Info, _S("initialized project at '%s/.hecl'\n"), m_dir->c_str()); LogModule.report(LogVisor::Info, _S("initialized project at '%s/.hecl'"), m_dir->c_str());
return 0; return 0;
} }

View File

@ -21,7 +21,7 @@ public:
return; return;
if (!info.project) if (!info.project)
throw HECL::Exception(_S("hecl spec must be ran within a project directory")); LogModule.report(LogVisor::FatalError, "hecl spec must be ran within a project directory");
const auto& specs = info.project->getDataSpecs(); const auto& specs = info.project->getDataSpecs();
HECL::SystemString firstArg = info.args[0]; HECL::SystemString firstArg = info.args[0];
@ -37,7 +37,7 @@ public:
return; return;
if (info.args.size() < 2) if (info.args.size() < 2)
throw HECL::Exception(_S("Speclist argument required")); LogModule.report(LogVisor::FatalError, "Speclist argument required");
for (auto it = info.args.begin()+1; for (auto it = info.args.begin()+1;
it != info.args.end(); it != info.args.end();
@ -54,7 +54,7 @@ public:
} }
} }
if (!found) if (!found)
throw HECL::Exception(_S("'") + *it + _S("' is not found in the dataspec registry")); LogModule.report(LogVisor::FatalError, _S("'%s' is not found in the dataspec registry"), it->c_str());
} }
} }

View File

@ -13,11 +13,19 @@ INCLUDEPATH += ../include \
LIBPATH += $$OUT_PWD/../lib \ LIBPATH += $$OUT_PWD/../lib \
$$OUT_PWD/../blender \ $$OUT_PWD/../blender \
$$OUT_PWD/../extern/LogVisor \ $$OUT_PWD/../extern/LogVisor \
$$OUT_PWD/../extern/RetroCommon/NODLib/lib \
$$OUT_PWD/../extern/blowfish \ $$OUT_PWD/../extern/blowfish \
$$OUT_PWD/../extern/libpng $$OUT_PWD/../extern/libpng \
$$OUT_PWD/../extern/Athena/lib \
$$OUT_PWD/../extern/RetroCommon/DataSpec \
$$OUT_PWD/../extern/RetroCommon/NODLib/lib
LIBS += -lhecl -lhecl-blender -lblowfish -lNOD -lLogVisor -lpng -lpthread LIBS += -lhecl -lhecl-blender -lblowfish -lpng -lpthread
LIBS += -Wl,--whole-archive -lRetroDataSpec -Wl,--no-whole-archive -lNOD -lLogVisor
CONFIG(debug, debug|release) {
LIBS += -lAthena-d
} else {
LIBS += -lAthena
}
SOURCES += \ SOURCES += \
$$PWD/main.cpp $$PWD/main.cpp

View File

@ -49,12 +49,17 @@ static void printHelp(const HECL::SystemChar* pname)
} }
/* Regex patterns */ /* Regex patterns */
static const HECL::SystemRegex regOPEN(_S("-o([^\"]*|\\S*))"), std::regex::ECMAScript|std::regex::optimize); static const HECL::SystemRegex regOPEN(_S("-o([^\"]*|\\S*)"), std::regex::ECMAScript|std::regex::optimize);
static const HECL::SystemRegex regVERBOSE(_S("-v(v*)"), std::regex::ECMAScript|std::regex::optimize); static const HECL::SystemRegex regVERBOSE(_S("-v(v*)"), std::regex::ECMAScript|std::regex::optimize);
static const HECL::SystemRegex regFORCE(_S("-f"), std::regex::ECMAScript|std::regex::optimize); static const HECL::SystemRegex regFORCE(_S("-f"), std::regex::ECMAScript|std::regex::optimize);
#include "../blender/CBlenderConnection.hpp" #include "../blender/CBlenderConnection.hpp"
namespace Retro
{
extern HECL::Database::DataSpecEntry SpecMP1;
}
#if HECL_UCS2 #if HECL_UCS2
int wmain(int argc, const wchar_t** argv) int wmain(int argc, const wchar_t** argv)
#else #else
@ -66,6 +71,8 @@ int main(int argc, const char** argv)
if (!strncmp(term, "xterm", 5)) if (!strncmp(term, "xterm", 5))
XTERM_COLOR = true; XTERM_COLOR = true;
//fprintf(stderr, "%s\n", Retro::SpecMP1.m_name.c_str());
//CBlenderConnection bconn(false); //CBlenderConnection bconn(false);
//return 0; //return 0;
@ -166,11 +173,11 @@ int main(int argc, const char** argv)
project.reset(new HECL::Database::Project(*rootPath)); project.reset(new HECL::Database::Project(*rootPath));
info.project = project.get(); info.project = project.get();
} }
catch (HECL::Exception& ex) catch (std::exception&)
{ {
LogModule.report(LogVisor::Error, LogModule.report(LogVisor::Error,
_S("Unable to open discovered project at '%s':\n%s\n"), _S("Unable to open discovered project at '%s'"),
rootPath->getAbsolutePath().c_str(), ex.swhat()); rootPath->getAbsolutePath().c_str());
return -1; return -1;
} }
} }
@ -202,12 +209,12 @@ int main(int argc, const char** argv)
else if (toolName == _S("help")) else if (toolName == _S("help"))
tool.reset(new ToolHelp(info)); tool.reset(new ToolHelp(info));
else else
throw HECL::Exception(_S("unrecognized tool '") + toolName + _S("'")); LogModule.report(LogVisor::FatalError, _S("unrecognized tool '%s'"), toolName.c_str());
} }
catch (HECL::Exception& ex) catch (std::exception&)
{ {
LogModule.report(LogVisor::Error, _S("Unable to construct HECL tool '%s':\n%s\n"), LogModule.report(LogVisor::Error, _S("Unable to construct HECL tool '%s'"),
toolName.c_str(), ex.swhat()); toolName.c_str());
return -1; return -1;
} }
@ -221,10 +228,10 @@ int main(int argc, const char** argv)
{ {
retval = tool->run(); retval = tool->run();
} }
catch (HECL::Exception& ex) catch (std::exception&)
{ {
LogModule.report(LogVisor::Error, _S("Error running HECL tool '%s':\n%s\n"), LogModule.report(LogVisor::Error, _S("Error running HECL tool '%s'"),
toolName.c_str(), ex.swhat()); toolName.c_str());
return -1; return -1;
} }

@ -1 +1 @@
Subproject commit 47a7a95098fe13543450c132cae91a195c06840c Subproject commit c3dc632dd0f2f750697ccd6ee10898b4f45fb502

@ -1 +1 @@
Subproject commit a0ec6da17111a416e6eeaf876ce81cbb5216bcb6 Subproject commit 6c0b9785d0e6826ac4cf874e2544750f8e74cf51

View File

@ -15,6 +15,7 @@
#include <stdint.h> #include <stdint.h>
#include <Athena/IStreamReader.hpp> #include <Athena/IStreamReader.hpp>
#include <LogVisor/LogVisor.hpp>
#include "HECL.hpp" #include "HECL.hpp"
@ -24,6 +25,8 @@ namespace Database
{ {
class Project; class Project;
extern LogVisor::LogModule LogModule;
/** /**
* @brief Nodegraph class for gathering dependency-resolved objects for packaging * @brief Nodegraph class for gathering dependency-resolved objects for packaging
*/ */
@ -71,8 +74,8 @@ public:
ProjectPath subpath; ProjectPath subpath;
bool cookedonly; bool cookedonly;
}; };
virtual bool canExtract(const ExtractPassInfo& info, SystemString& reasonNo) virtual bool canExtract(const ExtractPassInfo& info)
{(void)info;reasonNo=_S("not implemented");return false;} {(void)info;LogModule.report(LogVisor::Error, "not implemented");return false;}
virtual void doExtract(const Project& project, const ExtractPassInfo& info) virtual void doExtract(const Project& project, const ExtractPassInfo& info)
{(void)project;(void)info;} {(void)project;(void)info;}
@ -234,7 +237,6 @@ public:
private: private:
ProjectRootPath m_rootPath; ProjectRootPath m_rootPath;
CompiledSpecs m_compiledSpecs; CompiledSpecs m_compiledSpecs;
FLogger m_logger;
public: public:
Project(const HECL::ProjectRootPath& rootPath); Project(const HECL::ProjectRootPath& rootPath);
@ -286,14 +288,6 @@ public:
C_HEAVY C_HEAVY
}; };
/**
* @brief Register an optional callback to report log-messages using
* @param logger logger-callback
*
* If this method is never called, all project operations will run silently.
*/
void registerLogger(HECL::FLogger logger);
/** /**
* @brief Get the path of the project's root-directory * @brief Get the path of the project's root-directory
* @param absolute return as absolute-path * @param absolute return as absolute-path

View File

@ -21,11 +21,15 @@ char* win_realpath(const char* name, char* restrict resolved);
#include <string> #include <string>
#include <algorithm> #include <algorithm>
#include <regex> #include <regex>
#include <LogVisor/LogVisor.hpp>
#include <Athena/DNA.hpp>
#include "../extern/blowfish/blowfish.h" #include "../extern/blowfish/blowfish.h"
namespace HECL namespace HECL
{ {
extern LogVisor::LogModule LogModule;
#if _WIN32 && UNICODE #if _WIN32 && UNICODE
#define HECL_UCS2 1 #define HECL_UCS2 1
#endif #endif
@ -87,31 +91,6 @@ public:
#endif #endif
#endif #endif
class Exception : public std::exception
{
SystemString m_what;
#if HECL_UCS2
std::string m_utf8what;
#endif
public:
Exception(const SystemString& what) noexcept
: m_what(what)
{
#if HECL_UCS2
m_utf8what = WideToUTF8(what);
#endif
}
const char* what() const noexcept
{
#if HECL_UCS2
return m_utf8what.c_str();
#else
return m_what.c_str();
#endif
}
inline const SystemChar* swhat() const noexcept {return m_what.c_str();}
};
static inline void MakeDir(const SystemString& dir) static inline void MakeDir(const SystemString& dir)
{ {
#if _WIN32 #if _WIN32
@ -231,29 +210,17 @@ typedef std::match_results<SystemString::const_iterator> SystemRegexMatch;
class ProjectRootPath; class ProjectRootPath;
/**
* @brief Severity of a log event
*/
enum LogType
{
LOG_INFO,
LOG_WARN,
LOG_ERROR
};
/**
* @brief Logger callback type
*/
typedef std::function<void(LogType, std::string&)> FLogger;
/** /**
* @brief FourCC representation used within HECL's database * @brief FourCC representation used within HECL's database
* *
* FourCCs are efficient, mnemonic four-char-sequences used to represent types * FourCCs are efficient, mnemonic four-char-sequences used to represent types
* while fitting comfortably in a 32-bit word. HECL uses a four-char array * while fitting comfortably in a 32-bit word. HECL uses a four-char array
* to remain endian-independent. * to remain endian-independent.
*
* This class also functions as a read/write Athena DNA type,
* for easy initialization of FourCCs in DNA data records.
*/ */
class FourCC final class FourCC final : public Athena::io::DNA<Athena::BigEndian>
{ {
union union
{ {
@ -270,6 +237,12 @@ public:
inline bool operator==(const char* other) const {return num == *(uint32_t*)other;} inline bool operator==(const char* other) const {return num == *(uint32_t*)other;}
inline bool operator!=(const char* other) const {return num != *(uint32_t*)other;} inline bool operator!=(const char* other) const {return num != *(uint32_t*)other;}
inline std::string toString() const {return std::string(fcc, 4);} inline std::string toString() const {return std::string(fcc, 4);}
Delete expl;
inline void read(Athena::io::IStreamReader& reader)
{reader.readUBytesToBuf(fcc, 4);}
inline void write(Athena::io::IStreamWriter& writer) const
{writer.writeUBytes((atUint8*)fcc, 4);}
}; };
/** /**

View File

@ -1 +1,6 @@
#include "HECL/HECL.hpp" #include "HECL/HECL.hpp"
namespace HECL
{
LogVisor::LogModule LogModule("HECL");
}

View File

@ -120,7 +120,7 @@ Time ProjectPath::getModtime() const
return Time(latestTime); return Time(latestTime);
} }
} }
throw HECL::Exception(_S("invalid path type")); LogModule.report(LogVisor::Error, _S("invalid path type for computing modtime"));
return Time(); return Time();
} }

View File

@ -16,6 +16,8 @@ namespace HECL
namespace Database namespace Database
{ {
LogVisor::LogModule LogModule("HECLDatabase");
/********************************************** /**********************************************
* Project::ConfigFile * Project::ConfigFile
**********************************************/ **********************************************/
@ -92,7 +94,10 @@ void Project::ConfigFile::addLine(const std::string& line)
void Project::ConfigFile::removeLine(const std::string& refLine) void Project::ConfigFile::removeLine(const std::string& refLine)
{ {
if (!m_lockedFile) if (!m_lockedFile)
throw HECL::Exception(_S("Project::ConfigFile::lockAndRead not yet called")); {
LogModule.reportSource(LogVisor::FatalError, __FILE__, __LINE__, "Project::ConfigFile::lockAndRead not yet called");
return;
}
for (auto it = m_lines.begin(); for (auto it = m_lines.begin();
it != m_lines.end();) it != m_lines.end();)
@ -109,7 +114,10 @@ void Project::ConfigFile::removeLine(const std::string& refLine)
bool Project::ConfigFile::checkForLine(const std::string& refLine) bool Project::ConfigFile::checkForLine(const std::string& refLine)
{ {
if (!m_lockedFile) if (!m_lockedFile)
throw HECL::Exception(_S("Project::ConfigFile::lockAndRead not yet called")); {
LogModule.reportSource(LogVisor::FatalError, __FILE__, __LINE__, "Project::ConfigFile::lockAndRead not yet called");
return false;
}
for (const std::string& line : m_lines) for (const std::string& line : m_lines)
{ {
@ -122,7 +130,10 @@ bool Project::ConfigFile::checkForLine(const std::string& refLine)
void Project::ConfigFile::unlockAndDiscard() void Project::ConfigFile::unlockAndDiscard()
{ {
if (!m_lockedFile) if (!m_lockedFile)
throw HECL::Exception(_S("Project::ConfigFile::lockAndRead not yet called")); {
LogModule.reportSource(LogVisor::FatalError, __FILE__, __LINE__, "Project::ConfigFile::lockAndRead not yet called");
return;
}
m_lines.clear(); m_lines.clear();
fclose(m_lockedFile); fclose(m_lockedFile);
@ -132,7 +143,10 @@ void Project::ConfigFile::unlockAndDiscard()
bool Project::ConfigFile::unlockAndCommit() bool Project::ConfigFile::unlockAndCommit()
{ {
if (!m_lockedFile) if (!m_lockedFile)
throw HECL::Exception(_S("Project::ConfigFile::lockAndRead not yet called")); {
LogModule.reportSource(LogVisor::FatalError, __FILE__, __LINE__, "Project::ConfigFile::lockAndRead not yet called");
return false;
}
SystemString newPath = m_filepath + _S(".part"); SystemString newPath = m_filepath + _S(".part");
FILE* newFile = HECL::Fopen(newPath.c_str(), _S("w"), LWRITE); FILE* newFile = HECL::Fopen(newPath.c_str(), _S("w"), LWRITE);
@ -208,17 +222,15 @@ Project::Project(const ProjectRootPath& rootPath)
fclose(bf); fclose(bf);
if (beacon.magic != hecl || if (beacon.magic != hecl ||
SBig(beacon.version) != DATA_VERSION) SBig(beacon.version) != DATA_VERSION)
throw Exception(_S("incompatible HECL project")); {
LogModule.report(LogVisor::FatalError, "incompatible project version");
return;
}
/* Compile current dataspec */ /* Compile current dataspec */
rescanDataSpecs(); rescanDataSpecs();
} }
void Project::registerLogger(FLogger logger)
{
m_logger = logger;
}
bool Project::addPaths(const std::vector<ProjectPath>& paths) bool Project::addPaths(const std::vector<ProjectPath>& paths)
{ {
m_paths.lockAndRead(); m_paths.lockAndRead();

View File

@ -4,7 +4,11 @@ TARGET = hecl
CONFIG -= Qt CONFIG -= Qt
QT = QT =
INCLUDEPATH += $$PWD ../include ../extern ../extern/Athena/include INCLUDEPATH += $$PWD \
../include \
../extern \
../extern/Athena/include \
../extern/LogVisor/include
include (frontend/frontend.pri) include (frontend/frontend.pri)
include (backend/backend.pri) include (backend/backend.pri)