From a656c5d4c9aea7a3f391c7fae2ba14a8600ce835 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 3 Jul 2015 20:02:12 -1000 Subject: [PATCH] Integrated LogVisor for error gathering --- .gitmodules | 3 +++ LogVisor | 1 + NODLib.pro | 4 ++-- driver/driver.pro | 13 ++++++++++--- driver/main.cpp | 4 ++++ include/NOD/Util.hpp | 4 ++++ lib/DiscIOISO.cpp | 8 ++++---- lib/DiscIOWBFS.cpp | 8 ++++---- lib/NOD.cpp | 11 +++++++---- lib/lib.pro | 6 +++++- main.cpp | 35 ----------------------------------- 11 files changed, 44 insertions(+), 53 deletions(-) create mode 100644 .gitmodules create mode 160000 LogVisor delete mode 100644 main.cpp diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..0afc36e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "LogVisor"] + path = LogVisor + url = https://github.com/RetroView/LogVisor.git diff --git a/LogVisor b/LogVisor new file mode 160000 index 0000000..33f2f7b --- /dev/null +++ b/LogVisor @@ -0,0 +1 @@ +Subproject commit 33f2f7b279991a7be81310024636f43ecbf5ed24 diff --git a/NODLib.pro b/NODLib.pro index 536a556..a37dcb1 100644 --- a/NODLib.pro +++ b/NODLib.pro @@ -6,8 +6,8 @@ CONFIG -= app_bundle CONFIG -= qt QT = -SUBDIRS += lib driver -driver.depends += lib +SUBDIRS += LogVisor lib driver +driver.depends += LogVisor lib HEADERS += \ include/NOD/Util.hpp \ diff --git a/driver/driver.pro b/driver/driver.pro index 5c22a88..8a1f7c5 100644 --- a/driver/driver.pro +++ b/driver/driver.pro @@ -7,8 +7,15 @@ CONFIG -= app_bundle CONFIG -= qt QT = -INCLUDEPATH += ../include -QMAKE_LFLAGS += -maes -LIBS += -L$$OUT_PWD/../lib -lNOD +isEmpty(LOGVISOR_INCLUDE) { + LOGVISOR_INCLUDE = ../LogVisor/include +} +INCLUDEPATH += ../include $$LOGVISOR_INCLUDE +isEmpty(LOGVISOR_LIBS) { + LOGVISOR_LIBS = -L$$OUT_PWD/../LogVisor -lLogVisor +} +LIBS += -L$$OUT_PWD/../lib -lNOD $$LOGVISOR_LIBS -lpthread + +QMAKE_LFLAGS += -maes SOURCES += main.cpp diff --git a/driver/main.cpp b/driver/main.cpp index bccbcc9..5139711 100644 --- a/driver/main.cpp +++ b/driver/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "NOD/NOD.hpp" static void printHelp() @@ -25,6 +26,9 @@ int main(int argc, char* argv[]) return -1; } + /* Enable logging to console */ + LogVisor::RegisterConsoleLogger(); + const NOD::SystemChar* inDir = nullptr; const NOD::SystemChar* outDir = _S("."); bool force = false; diff --git a/include/NOD/Util.hpp b/include/NOD/Util.hpp index 128e352..46127d6 100644 --- a/include/NOD/Util.hpp +++ b/include/NOD/Util.hpp @@ -3,10 +3,14 @@ #include #include +#include namespace NOD { +/* Log Module */ +extern LogVisor::LogModule LogModule; + /* filesystem char type */ #if _WIN32 && UNICODE #include diff --git a/lib/DiscIOISO.cpp b/lib/DiscIOISO.cpp index 107bde5..2a8dac4 100644 --- a/lib/DiscIOISO.cpp +++ b/lib/DiscIOISO.cpp @@ -36,9 +36,9 @@ public: if (!fp) { #if NOD_UCS2 - fwprintf(stderr, L"Unable to open '%s' for reading\n", filepath.c_str()); + LogModule.report(LogVisor::Error, L"Unable to open '%s' for reading\n", filepath.c_str()); #else - fprintf(stderr, "Unable to open '%s' for reading\n", filepath.c_str()); + LogModule.report(LogVisor::Error, "Unable to open '%s' for reading\n", filepath.c_str()); #endif return std::unique_ptr(); } @@ -67,9 +67,9 @@ public: if (!fp) { #if NOD_UCS2 - fwprintf(stderr, L"Unable to open '%s' for writing\n", filepath.c_str()); + LogModule.report(LogVisor::Error, L"Unable to open '%s' for writing\n", filepath.c_str()); #else - fprintf(stderr, "Unable to open '%s' for writing\n", filepath.c_str()); + LogModule.report(LogVisor::Error, "Unable to open '%s' for writing\n", filepath.c_str()); #endif return std::unique_ptr(); } diff --git a/lib/DiscIOWBFS.cpp b/lib/DiscIOWBFS.cpp index f44691e..3e63ec9 100644 --- a/lib/DiscIOWBFS.cpp +++ b/lib/DiscIOWBFS.cpp @@ -36,9 +36,9 @@ public: if (!fp) { #if NOD_UCS2 - fwprintf(stderr, L"Unable to open '%s' for reading\n", filepath.c_str()); + LogModule.report(LogVisor::Error, L"Unable to open '%s' for reading\n", filepath.c_str()); #else - fprintf(stderr, "Unable to open '%s' for reading\n", filepath.c_str()); + LogModule.report(LogVisor::Error, "Unable to open '%s' for reading\n", filepath.c_str()); #endif return std::unique_ptr(); } @@ -67,9 +67,9 @@ public: if (!fp) { #if NOD_UCS2 - fwprintf(stderr, L"Unable to open '%s' for writing\n", filepath.c_str()); + LogModule.report(LogVisor::Error, L"Unable to open '%s' for writing\n", filepath.c_str()); #else - fprintf(stderr, "Unable to open '%s' for writing\n", filepath.c_str()); + LogModule.report(LogVisor::Error, "Unable to open '%s' for writing\n", filepath.c_str()); #endif return std::unique_ptr(); } diff --git a/lib/NOD.cpp b/lib/NOD.cpp index 7b3bd47..3ab40c5 100644 --- a/lib/NOD.cpp +++ b/lib/NOD.cpp @@ -4,6 +4,9 @@ namespace NOD { + +LogVisor::LogModule LogModule("NODLib"); + std::unique_ptr NewDiscIOISO(const SystemChar* path); std::unique_ptr NewDiscIOWBFS(const SystemChar* path); @@ -18,9 +21,9 @@ std::unique_ptr OpenDiscFromImage(const SystemChar* path, bool& isWii) if (!fp) { #if NOD_UCS2 - fwprintf(stderr, L"Unable to open '%s'\n", path); + LogModule.report(LogVisor::Error, L"Unable to open '%s'\n", path); #else - fprintf(stderr, "Unable to open '%s'\n", path); + LogModule.report(LogVisor::Error, "Unable to open '%s'\n", path); #endif return std::unique_ptr(); } @@ -63,9 +66,9 @@ std::unique_ptr OpenDiscFromImage(const SystemChar* path, bool& isWii) if (!discIO) { #if NOD_UCS2 - fwprintf(stderr, L"'%s' is not a valid image\n", path); + LogModule.report(LogVisor::Error, L"'%s' is not a valid image\n", path); #else - fprintf(stderr, "'%s' is not a valid image\n", path); + LogModule.report(LogVisor::Error, "'%s' is not a valid image\n", path); #endif return std::unique_ptr(); } diff --git a/lib/lib.pro b/lib/lib.pro index 54abc6b..6992271 100644 --- a/lib/lib.pro +++ b/lib/lib.pro @@ -6,7 +6,11 @@ QT = TARGET = NOD QMAKE_CXXFLAGS += -maes -INCLUDEPATH += ../include ../../../LogVisor/include + +isEmpty(LOGVISOR_INCLUDE) { + LOGVISOR_INCLUDE = ../LogVisor/include +} +INCLUDEPATH += ../include $$LOGVISOR_INCLUDE SOURCES += \ FileIOFILE.cpp \ diff --git a/main.cpp b/main.cpp deleted file mode 100644 index b1abde8..0000000 --- a/main.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include "NODLib.hpp" - -int main(int argc, char* argv[]) -{ - if (argc < 2) - { - fprintf(stderr, "Usage: nodlib \n"); - return -1; - } - - std::unique_ptr disc = NOD::OpenDiscFromImage(argv[1]); - if (!disc) - return -1; - - const NOD::DiscBase::IPartition* dataPart = disc->getDataPartition(); - if (dataPart) - { - for (const NOD::DiscBase::IPartition::Node& node : dataPart->getFSTRoot()) - { - if (node.getKind() == NOD::DiscBase::IPartition::Node::NODE_FILE) - printf("FILE: %s\n", node.getName().c_str()); - else if (node.getKind() == NOD::DiscBase::IPartition::Node::NODE_DIRECTORY) - { - printf("DIR: %s\n", node.getName().c_str()); - for (const NOD::DiscBase::IPartition::Node& subnode : node) - printf("SUBFILE: %s\n", subnode.getName().c_str()); - } - } - } - - return 0; -} -