From 14a368553db58f322a6cb1fc0ec5e7ba182d3c46 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 5 Jul 2015 15:35:08 -1000 Subject: [PATCH] LogVisor report additions; Updated RetroCommon --- hecl/driver/ToolHelp.hpp | 4 +-- hecl/driver/ToolInit.hpp | 12 ++++---- hecl/driver/ToolSpec.hpp | 6 ++-- hecl/driver/driver.pro | 14 +++++++-- hecl/driver/main.cpp | 29 +++++++++++------- hecl/extern/LogVisor | 2 +- hecl/extern/RetroCommon | 2 +- hecl/include/HECL/Database.hpp | 16 ++++------ hecl/include/HECL/HECL.hpp | 55 +++++++++------------------------- hecl/lib/HECL.cpp | 5 ++++ hecl/lib/ProjectPath.cpp | 2 +- hecl/lib/database/Project.cpp | 32 +++++++++++++------- hecl/lib/lib.pro | 6 +++- 13 files changed, 94 insertions(+), 91 deletions(-) diff --git a/hecl/driver/ToolHelp.hpp b/hecl/driver/ToolHelp.hpp index 810dec2d6..0c2c836e5 100644 --- a/hecl/driver/ToolHelp.hpp +++ b/hecl/driver/ToolHelp.hpp @@ -15,7 +15,7 @@ public: : ToolBase(info) { 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() @@ -78,7 +78,7 @@ public: helpFunc = ToolHelp::Help; 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; } diff --git a/hecl/driver/ToolInit.hpp b/hecl/driver/ToolInit.hpp index db0fd7b45..a343925c6 100644 --- a/hecl/driver/ToolInit.hpp +++ b/hecl/driver/ToolInit.hpp @@ -20,19 +20,19 @@ public: 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; } 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; } HECL::SystemString testPath = *dir + _S("/.hecl/beacon"); 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; } @@ -48,12 +48,12 @@ public: HECL::Database::Project proj((HECL::ProjectRootPath(*m_dir))); 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; } - 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; } diff --git a/hecl/driver/ToolSpec.hpp b/hecl/driver/ToolSpec.hpp index 42c5be4a5..f0c74f2e0 100644 --- a/hecl/driver/ToolSpec.hpp +++ b/hecl/driver/ToolSpec.hpp @@ -21,7 +21,7 @@ public: return; 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(); HECL::SystemString firstArg = info.args[0]; @@ -37,7 +37,7 @@ public: return; 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; it != info.args.end(); @@ -54,7 +54,7 @@ public: } } 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()); } } diff --git a/hecl/driver/driver.pro b/hecl/driver/driver.pro index 010b7421d..18e0a2c97 100644 --- a/hecl/driver/driver.pro +++ b/hecl/driver/driver.pro @@ -13,11 +13,19 @@ INCLUDEPATH += ../include \ LIBPATH += $$OUT_PWD/../lib \ $$OUT_PWD/../blender \ $$OUT_PWD/../extern/LogVisor \ - $$OUT_PWD/../extern/RetroCommon/NODLib/lib \ $$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 += \ $$PWD/main.cpp diff --git a/hecl/driver/main.cpp b/hecl/driver/main.cpp index e23f4acf5..eac69d640 100644 --- a/hecl/driver/main.cpp +++ b/hecl/driver/main.cpp @@ -49,12 +49,17 @@ static void printHelp(const HECL::SystemChar* pname) } /* 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 regFORCE(_S("-f"), std::regex::ECMAScript|std::regex::optimize); #include "../blender/CBlenderConnection.hpp" +namespace Retro +{ +extern HECL::Database::DataSpecEntry SpecMP1; +} + #if HECL_UCS2 int wmain(int argc, const wchar_t** argv) #else @@ -66,6 +71,8 @@ int main(int argc, const char** argv) if (!strncmp(term, "xterm", 5)) XTERM_COLOR = true; + //fprintf(stderr, "%s\n", Retro::SpecMP1.m_name.c_str()); + //CBlenderConnection bconn(false); //return 0; @@ -166,11 +173,11 @@ int main(int argc, const char** argv) project.reset(new HECL::Database::Project(*rootPath)); info.project = project.get(); } - catch (HECL::Exception& ex) + catch (std::exception&) { LogModule.report(LogVisor::Error, - _S("Unable to open discovered project at '%s':\n%s\n"), - rootPath->getAbsolutePath().c_str(), ex.swhat()); + _S("Unable to open discovered project at '%s'"), + rootPath->getAbsolutePath().c_str()); return -1; } } @@ -202,12 +209,12 @@ int main(int argc, const char** argv) else if (toolName == _S("help")) tool.reset(new ToolHelp(info)); 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"), - toolName.c_str(), ex.swhat()); + LogModule.report(LogVisor::Error, _S("Unable to construct HECL tool '%s'"), + toolName.c_str()); return -1; } @@ -221,10 +228,10 @@ int main(int argc, const char** argv) { retval = tool->run(); } - catch (HECL::Exception& ex) + catch (std::exception&) { - LogModule.report(LogVisor::Error, _S("Error running HECL tool '%s':\n%s\n"), - toolName.c_str(), ex.swhat()); + LogModule.report(LogVisor::Error, _S("Error running HECL tool '%s'"), + toolName.c_str()); return -1; } diff --git a/hecl/extern/LogVisor b/hecl/extern/LogVisor index 47a7a9509..c3dc632dd 160000 --- a/hecl/extern/LogVisor +++ b/hecl/extern/LogVisor @@ -1 +1 @@ -Subproject commit 47a7a95098fe13543450c132cae91a195c06840c +Subproject commit c3dc632dd0f2f750697ccd6ee10898b4f45fb502 diff --git a/hecl/extern/RetroCommon b/hecl/extern/RetroCommon index a0ec6da17..6c0b9785d 160000 --- a/hecl/extern/RetroCommon +++ b/hecl/extern/RetroCommon @@ -1 +1 @@ -Subproject commit a0ec6da17111a416e6eeaf876ce81cbb5216bcb6 +Subproject commit 6c0b9785d0e6826ac4cf874e2544750f8e74cf51 diff --git a/hecl/include/HECL/Database.hpp b/hecl/include/HECL/Database.hpp index ba26befbb..bc882f82f 100644 --- a/hecl/include/HECL/Database.hpp +++ b/hecl/include/HECL/Database.hpp @@ -15,6 +15,7 @@ #include #include +#include #include "HECL.hpp" @@ -24,6 +25,8 @@ namespace Database { class Project; +extern LogVisor::LogModule LogModule; + /** * @brief Nodegraph class for gathering dependency-resolved objects for packaging */ @@ -71,8 +74,8 @@ public: ProjectPath subpath; bool cookedonly; }; - virtual bool canExtract(const ExtractPassInfo& info, SystemString& reasonNo) - {(void)info;reasonNo=_S("not implemented");return false;} + virtual bool canExtract(const ExtractPassInfo& info) + {(void)info;LogModule.report(LogVisor::Error, "not implemented");return false;} virtual void doExtract(const Project& project, const ExtractPassInfo& info) {(void)project;(void)info;} @@ -234,7 +237,6 @@ public: private: ProjectRootPath m_rootPath; CompiledSpecs m_compiledSpecs; - FLogger m_logger; public: Project(const HECL::ProjectRootPath& rootPath); @@ -286,14 +288,6 @@ public: 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 * @param absolute return as absolute-path diff --git a/hecl/include/HECL/HECL.hpp b/hecl/include/HECL/HECL.hpp index edf94ff16..760eec278 100644 --- a/hecl/include/HECL/HECL.hpp +++ b/hecl/include/HECL/HECL.hpp @@ -21,11 +21,15 @@ char* win_realpath(const char* name, char* restrict resolved); #include #include #include +#include +#include #include "../extern/blowfish/blowfish.h" namespace HECL { +extern LogVisor::LogModule LogModule; + #if _WIN32 && UNICODE #define HECL_UCS2 1 #endif @@ -87,31 +91,6 @@ public: #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) { #if _WIN32 @@ -231,29 +210,17 @@ typedef std::match_results SystemRegexMatch; class ProjectRootPath; -/** - * @brief Severity of a log event - */ -enum LogType -{ - LOG_INFO, - LOG_WARN, - LOG_ERROR -}; - -/** - * @brief Logger callback type - */ -typedef std::function FLogger; - /** * @brief FourCC representation used within HECL's database * * 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 * 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 { 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 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);} }; /** diff --git a/hecl/lib/HECL.cpp b/hecl/lib/HECL.cpp index ed6724e20..b15add036 100644 --- a/hecl/lib/HECL.cpp +++ b/hecl/lib/HECL.cpp @@ -1 +1,6 @@ #include "HECL/HECL.hpp" + +namespace HECL +{ +LogVisor::LogModule LogModule("HECL"); +} diff --git a/hecl/lib/ProjectPath.cpp b/hecl/lib/ProjectPath.cpp index 3ec9153e5..6655f55d6 100644 --- a/hecl/lib/ProjectPath.cpp +++ b/hecl/lib/ProjectPath.cpp @@ -120,7 +120,7 @@ Time ProjectPath::getModtime() const return Time(latestTime); } } - throw HECL::Exception(_S("invalid path type")); + LogModule.report(LogVisor::Error, _S("invalid path type for computing modtime")); return Time(); } diff --git a/hecl/lib/database/Project.cpp b/hecl/lib/database/Project.cpp index db76909d0..cdb3c3859 100644 --- a/hecl/lib/database/Project.cpp +++ b/hecl/lib/database/Project.cpp @@ -16,6 +16,8 @@ namespace HECL namespace Database { +LogVisor::LogModule LogModule("HECLDatabase"); + /********************************************** * Project::ConfigFile **********************************************/ @@ -92,7 +94,10 @@ void Project::ConfigFile::addLine(const std::string& line) void Project::ConfigFile::removeLine(const std::string& refLine) { 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(); it != m_lines.end();) @@ -109,7 +114,10 @@ void Project::ConfigFile::removeLine(const std::string& refLine) bool Project::ConfigFile::checkForLine(const std::string& refLine) { 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) { @@ -122,7 +130,10 @@ bool Project::ConfigFile::checkForLine(const std::string& refLine) void Project::ConfigFile::unlockAndDiscard() { 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(); fclose(m_lockedFile); @@ -132,7 +143,10 @@ void Project::ConfigFile::unlockAndDiscard() bool Project::ConfigFile::unlockAndCommit() { 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"); FILE* newFile = HECL::Fopen(newPath.c_str(), _S("w"), LWRITE); @@ -208,17 +222,15 @@ Project::Project(const ProjectRootPath& rootPath) fclose(bf); if (beacon.magic != hecl || SBig(beacon.version) != DATA_VERSION) - throw Exception(_S("incompatible HECL project")); + { + LogModule.report(LogVisor::FatalError, "incompatible project version"); + return; + } /* Compile current dataspec */ rescanDataSpecs(); } -void Project::registerLogger(FLogger logger) -{ - m_logger = logger; -} - bool Project::addPaths(const std::vector& paths) { m_paths.lockAndRead(); diff --git a/hecl/lib/lib.pro b/hecl/lib/lib.pro index c9c20fff8..72240b865 100644 --- a/hecl/lib/lib.pro +++ b/hecl/lib/lib.pro @@ -4,7 +4,11 @@ TARGET = hecl CONFIG -= Qt QT = -INCLUDEPATH += $$PWD ../include ../extern ../extern/Athena/include +INCLUDEPATH += $$PWD \ + ../include \ + ../extern \ + ../extern/Athena/include \ + ../extern/LogVisor/include include (frontend/frontend.pri) include (backend/backend.pri)