From ddc75d2cc224fd724e0ae218686a474a44e07068 Mon Sep 17 00:00:00 2001 From: Filippo Berto Date: Wed, 15 Mar 2017 09:21:41 +0100 Subject: [PATCH] Authors and credits (partial info) --- CMakeLists.txt | 2 +- Exceptions/AuthorsScreenException.h | 45 ++++++++++++++++++++++++ Graphics/AuthorsScreen/AuthorsScreen.cpp | 15 ++++++++ Graphics/AuthorsScreen/AuthorsScreen.h | 13 +++++++ Graphics/HelpScreen/HelpScreen.cpp | 6 ++-- Graphics/Info/Info.cpp | 9 ++++- Graphics/Info/Info.h | 19 ++++++++++ Graphics/SplashScreen/SplashScreen.cpp | 7 ++-- Graphics/SplashScreen/SplashScreen.h | 1 - InputHandling/InputHandler.cpp | 8 +++++ main.cpp | 2 +- 11 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 Exceptions/AuthorsScreenException.h create mode 100644 Graphics/AuthorsScreen/AuthorsScreen.cpp create mode 100644 Graphics/AuthorsScreen/AuthorsScreen.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6161e7f..67fa918 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ find_package(Boost 1.58.0 COMPONENTS filesystem date_time) if (Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) - set(SOURCE_FILES main.cpp Pin/Pin.h Generator/bertofGenerator/Generator.h Exceptions/NotImplementedException.h Generator/bertofGenerator/Generator.cpp Logger/ScreenLogger/ScreenLogger.h Logger/ScreenLogger/ScreenLogger.cpp Exceptions/InvalidInputException.h Generator/GeneratorInerface.h Logger/Logger.cpp Logger/Logger.h Logger/TextLogger/TextLogger.cpp Logger/TextLogger/TextLogger.h Logger/DoubleLogger/DoubleLogger.cpp Logger/DoubleLogger/DoubleLogger.h Graphics/SplashScreen/SplashScreen.cpp Graphics/SplashScreen/SplashScreen.h InputHandling/InputHandler.cpp InputHandling/InputHandler.h Graphics/HelpScreen/HelpScreen.cpp Graphics/HelpScreen/HelpScreen.h Graphics/Info/Info.cpp Graphics/Info/Info.h Exceptions/HelpScreenException.h) + set(SOURCE_FILES main.cpp Pin/Pin.h Generator/bertofGenerator/Generator.h Exceptions/NotImplementedException.h Generator/bertofGenerator/Generator.cpp Logger/ScreenLogger/ScreenLogger.h Logger/ScreenLogger/ScreenLogger.cpp Exceptions/InvalidInputException.h Generator/GeneratorInerface.h Logger/Logger.cpp Logger/Logger.h Logger/TextLogger/TextLogger.cpp Logger/TextLogger/TextLogger.h Logger/DoubleLogger/DoubleLogger.cpp Logger/DoubleLogger/DoubleLogger.h Graphics/SplashScreen/SplashScreen.cpp Graphics/SplashScreen/SplashScreen.h InputHandling/InputHandler.cpp InputHandling/InputHandler.h Graphics/HelpScreen/HelpScreen.cpp Graphics/HelpScreen/HelpScreen.h Graphics/Info/Info.cpp Graphics/Info/Info.h Exceptions/HelpScreenException.h Exceptions/AuthorsScreenException.h Graphics/AuthorsScreen/AuthorsScreen.cpp Graphics/AuthorsScreen/AuthorsScreen.h) add_executable(WPS_pin_generator ${SOURCE_FILES}) diff --git a/Exceptions/AuthorsScreenException.h b/Exceptions/AuthorsScreenException.h new file mode 100644 index 0000000..d84bfd3 --- /dev/null +++ b/Exceptions/AuthorsScreenException.h @@ -0,0 +1,45 @@ +// +// Created by pily on 15/03/17. +// + +#ifndef WPS_PIN_GENERATOR_AUTHORSCREENEXCEPTION_H +#define WPS_PIN_GENERATOR_AUTHORSCREENEXCEPTION_H + +#include +#include + +class AuthorsScreenException : public std::exception { +public: + /** Constructor (C string) + * @param message C-style string error message. + * The string contents are copied upon construction. + * Hence, responsibility for deleting the char* lies + * with the caller. + */ + explicit AuthorsScreenException(const char *message) : errorMessage_(message) {} + + /** Constructor (C++ STL string) + * @param message The error message. + */ + explicit AuthorsScreenException(const std::string &message = "Authors screen showed") : errorMessage_(message) {} + + /** Destructor + * Virtual to allow subclassing + */ + virtual ~AuthorsScreenException() throw() {} + + /** Returns a pointer to the (constant) error description. + * + * @return + */ + const char *what() const throw() { + return errorMessage_.c_str(); + } + +private: + /** Saved error message + */ + std::string errorMessage_; +}; + +#endif //WPS_PIN_GENERATOR_AUTHORSCREENEXCEPTION_H diff --git a/Graphics/AuthorsScreen/AuthorsScreen.cpp b/Graphics/AuthorsScreen/AuthorsScreen.cpp new file mode 100644 index 0000000..27441b5 --- /dev/null +++ b/Graphics/AuthorsScreen/AuthorsScreen.cpp @@ -0,0 +1,15 @@ +// +// Created by pily on 15/03/17. +// + +#include "AuthorsScreen.h" +#include +#include "../Info/Info.h" +#include "../../lib/rang/include/rang.hpp" + +void AuthorsScreen::printAuthorsScreen() { + + std::cout << rang::style::reset << rang::fg::green << "AUTHORS" << rang::style::reset << std::endl + << Info::getAuthorInfos() + << std::endl; +} diff --git a/Graphics/AuthorsScreen/AuthorsScreen.h b/Graphics/AuthorsScreen/AuthorsScreen.h new file mode 100644 index 0000000..b8ca725 --- /dev/null +++ b/Graphics/AuthorsScreen/AuthorsScreen.h @@ -0,0 +1,13 @@ +// +// Created by pily on 15/03/17. +// + +#ifndef WPS_PIN_GENERATOR_AUTHORSSCREEN_H +#define WPS_PIN_GENERATOR_AUTHORSSCREEN_H + +class AuthorsScreen { +public: + static void printAuthorsScreen(); +}; + +#endif //WPS_PIN_GENERATOR_AUTHORSSCREEN_H diff --git a/Graphics/HelpScreen/HelpScreen.cpp b/Graphics/HelpScreen/HelpScreen.cpp index c4550ff..6cc7bc9 100644 --- a/Graphics/HelpScreen/HelpScreen.cpp +++ b/Graphics/HelpScreen/HelpScreen.cpp @@ -10,8 +10,9 @@ std::string HelpScreen::getHelpScreen() { return - "Version: " + Info::getVersion() + "\n" + - "USAGE:\n" + + "Authors:\t" + Info::getAuthorNames() + "\n" + + "Version:\t" + Info::getVersion() + "\n" + + "USAGE:\t\t" + Info::getExecutableName() + " [options]\n" + "\n" + "OPTIONS:\n" + @@ -19,6 +20,7 @@ std::string HelpScreen::getHelpScreen() { "-g\t\t\t\t\t\tUse the generator algorithm\n" + "-d\t\t\t\t\t\tUse the database\n" + "-h, --help\t\t\t\tPrint this help page\n" + + "--authors\t\tPrint authors credits\n" + "--debug\t\t\t\t\tPrint all th debug info" + "-v, --verbouse\tLog is more verbouse\n" + "--logfile [log.txt]\t\tEnables log to file (default log.txt)\n" + diff --git a/Graphics/Info/Info.cpp b/Graphics/Info/Info.cpp index f186653..65f887d 100644 --- a/Graphics/Info/Info.cpp +++ b/Graphics/Info/Info.cpp @@ -9,9 +9,16 @@ std::string Info::getVersion() { } std::string Info::getProjectName() { - return "WPS-pin-generator"; + return "WPS-pin generator"; } std::string Info::getExecutableName() { return "WPS_pin_generator"; } +std::string Info::getAuthorNames() { + return "bertof"; +} +std::string Info::getAuthorInfos() { + //TODO complete those info + return "bertof\n\tEmail:\tbertof [at] protonmail.com\n\tGitHub:\thttps://github.com/bertof"; +} diff --git a/Graphics/Info/Info.h b/Graphics/Info/Info.h index 677ec06..c272d1b 100644 --- a/Graphics/Info/Info.h +++ b/Graphics/Info/Info.h @@ -7,11 +7,30 @@ #include +/*** Centralized information about this program + */ class Info { public: + /*** Get a string with the version of the program + * @return version string + */ static std::string getVersion(); + /*** Get the full name of the project + * @return project name string + */ static std::string getProjectName(); + /*** Get the executable name + * @return executable name + */ static std::string getExecutableName(); + /*** Get author name + * @return author string + */ + static std::string getAuthorNames(); + /*** Get some info about the author + * @return author info + */ + static std::string getAuthorInfos(); }; #endif //WPS_PIN_GENERATOR_VERSION_H diff --git a/Graphics/SplashScreen/SplashScreen.cpp b/Graphics/SplashScreen/SplashScreen.cpp index 29a8e5b..e62f40d 100644 --- a/Graphics/SplashScreen/SplashScreen.cpp +++ b/Graphics/SplashScreen/SplashScreen.cpp @@ -4,7 +4,10 @@ #include "SplashScreen.h" #include +#include "../../lib/rang/include/rang.hpp" +#include "../Info/Info.h" -std::string SplashScreen::getSplashScreen() { - return "WPS Pin Generator - by Bertof"; +void SplashScreen::printSplashScreen() { + std::cout << rang::style::reset << rang::style::bold << rang::fg::cyan + << Info::getProjectName() << rang::style::reset << std::endl; } diff --git a/Graphics/SplashScreen/SplashScreen.h b/Graphics/SplashScreen/SplashScreen.h index 9c30bef..64fa290 100644 --- a/Graphics/SplashScreen/SplashScreen.h +++ b/Graphics/SplashScreen/SplashScreen.h @@ -10,7 +10,6 @@ class SplashScreen { public: static void printSplashScreen(); - static std::string getSplashScreen(); }; #endif //WPS_PIN_GENERATOR_SPASHSCREEN_H diff --git a/InputHandling/InputHandler.cpp b/InputHandling/InputHandler.cpp index 9aa3e80..4db0ce3 100644 --- a/InputHandling/InputHandler.cpp +++ b/InputHandling/InputHandler.cpp @@ -7,7 +7,9 @@ #include "../Logger/TextLogger/TextLogger.h" #include "../Logger/DoubleLogger/DoubleLogger.h" #include "../Exceptions/InvalidInputException.h" +#include "../Exceptions/AuthorsScreenException.h" #include "../Graphics/HelpScreen/HelpScreen.h" +#include "../Graphics/AuthorsScreen/AuthorsScreen.h" #include "../Generator/GeneratorInerface.h" #include "../Generator/bertofGenerator/Generator.h" @@ -82,6 +84,10 @@ void InputHandler::handle(int argc, char **argv) { else if (args[i] == "--help" || args[i] == "-h") { throw HelpScreenException(); } + // Authors dialog + else if (args[i] == "--authors") { + throw AuthorsScreenException(); + } // BSSID input else if (args[i] == "-b" || args[i] == "--bssid") { @@ -203,6 +209,8 @@ void InputHandler::handle(int argc, char **argv) { } catch (NotImplementedException e) { std::shared_ptr logger(DoubleLogger::getDoubleLogger()); logger->logError(std::string(e.what())); + } catch (AuthorsScreenException e) { + AuthorsScreen::printAuthorsScreen(); } } diff --git a/main.cpp b/main.cpp index b563f8c..9120d85 100644 --- a/main.cpp +++ b/main.cpp @@ -18,7 +18,7 @@ int main(int argc, char *argv[]) { //TODO switch to smart pointers // Spash screen - logger->log(SplashScreen::getSplashScreen()); + SplashScreen::printSplashScreen(); // Handle input InputHandler::handle(argc, argv);