diff --git a/.gitignore b/.gitignore index 728045d..9f21b35 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ run .idea -cmake-build-* \ No newline at end of file +cmake-build-* +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b75839..3f1beb4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,20 +30,12 @@ endif() # Add sources for CLI executable list( APPEND ${PROJECT_NAME}_SOURCES "${CMAKE_CURRENT_LIST_DIR}/src/main.cpp" - "${CMAKE_CURRENT_LIST_DIR}/src/output/Output.cpp" - "${CMAKE_CURRENT_LIST_DIR}/src/output/Output.hpp" - "${CMAKE_CURRENT_LIST_DIR}/src/output/CsvOutput.cpp" - "${CMAKE_CURRENT_LIST_DIR}/src/output/CsvOutput.hpp" - "${CMAKE_CURRENT_LIST_DIR}/src/output/JsonOutput.cpp" - "${CMAKE_CURRENT_LIST_DIR}/src/output/JsonOutput.hpp" - "${CMAKE_CURRENT_LIST_DIR}/src/output/SimpleOutput.cpp" - "${CMAKE_CURRENT_LIST_DIR}/src/output/SimpleOutput.hpp" - "${CMAKE_CURRENT_LIST_DIR}/src/output/RsvOutput.cpp" - "${CMAKE_CURRENT_LIST_DIR}/src/output/RsvOutput.hpp" "${CMAKE_CURRENT_LIST_DIR}/src/create.cpp" "${CMAKE_CURRENT_LIST_DIR}/src/create.hpp" "${CMAKE_CURRENT_LIST_DIR}/src/verify.cpp" "${CMAKE_CURRENT_LIST_DIR}/src/verify.hpp" + "${CMAKE_CURRENT_LIST_DIR}/src/log.cpp" + "${CMAKE_CURRENT_LIST_DIR}/src/log.hpp" ) # Create CLI executable diff --git a/src/create.cpp b/src/create.cpp index 0e60526..4b740c8 100644 --- a/src/create.cpp +++ b/src/create.cpp @@ -2,8 +2,6 @@ // Created by ENDERZOMBI102 on 15/10/2023. // #include -#include -#include #include #include #include @@ -12,44 +10,45 @@ #include #include "create.hpp" +#include "log.hpp" -auto create( std::string_view root_, std::string_view indexLocation, const std::vector& excluded, bool overwrite, const Output* out ) noexcept -> int { +auto create( std::string_view root_, std::string_view indexLocation, const std::vector& excluded, bool overwrite ) noexcept -> int { const std::filesystem::path root{ root_ }; const std::filesystem::path indexPath{ root / indexLocation }; if ( std::filesystem::exists( indexPath ) ) { if (! overwrite ) { - out->write( OutputKind::Error, fmt::format( "Index file `{}` already exist, do you want to overwite it? (y/N)", indexPath.string() ) ); + Log_Error( "Index file `{}` already exist, do you want to overwite it? (y/N)", indexPath.string() ); std::string input; std::cin >> input; if ( input != "y" ) { - out->write( OutputKind::Info, "Aborting." ); + Log_Info( "Aborting." ); return 1; } } else { - out->write( OutputKind::Warn, fmt::format( "Index file `{}` already exist, will be overwritten.", indexPath.string() ) ); + Log_Warn( "Index file `{}` already exist, will be overwritten.", indexPath.string() ); } } auto start{ std::chrono::high_resolution_clock::now() }; - out->write( OutputKind::Info, fmt::format( "Creating index file at `{}`", indexPath.string() ) ); + Log_Info( "Creating index file at `{}`", indexPath.string() ); // open index file with a writer stream std::ofstream writer{ indexPath, std::ios_base::out | std::ios_base::trunc }; if (! writer.good() ) { - out->write( OutputKind::Error, fmt::format( "Failed to open index file for writing: N/D" ) ); + Log_Error( "Failed to open index file for writing: N/D" ); return 1; } - out->write( OutputKind::Info, "Compiling exclusion regexes..." ); + Log_Info( "Compiling exclusion regexes..." ); // allocate all at once std::vector exclusionREs{}; exclusionREs.reserve( excluded.size() ); for ( const auto& exclusion : excluded ) { exclusionREs.emplace_back( exclusion, std::regex::ECMAScript | std::regex::icase | std::regex::optimize ); } - out->write( OutputKind::Info, fmt::format( "Done in {}", std::chrono::duration_cast( std::chrono::high_resolution_clock::now() - start ) ) ); + Log_Info( "Done in {}", std::chrono::duration_cast( std::chrono::high_resolution_clock::now() - start ) ); unsigned count{ 0 }; unsigned errors{ 0 }; @@ -83,7 +82,7 @@ auto create( std::string_view root_, std::string_view indexLocation, const std:: fopen_s( &file, path.c_str(), "rb" ); #endif if (! file ) { - out->write( OutputKind::Error, fmt::format( "Failed to open file: {}", path ) ); + Log_Error( "Failed to open file: {}", path ); continue; } @@ -106,20 +105,12 @@ auto create( std::string_view root_, std::string_view indexLocation, const std:: // write out entry writer << fmt::format( "{}\xFF{}\xFF{}\xFF{}\xFF\xFD", pathRel, size, sha256er.getHash(), crc32er.getHash() ); - out->write( OutputKind::Info, fmt::format( "Processed file `{}`", path ) ); + Log_Info( "Processed file `{}`", path ); count += 1; } auto end{ std::chrono::high_resolution_clock::now() }; - out->write( - OutputKind::Info, - fmt::format( - "Finished processing {} files in {}! (with {} errors)", - count, - std::chrono::duration_cast( end - start ), - errors - ) - ); + Log_Info( "Finished processing {} files in {}! (with {} errors)", count, std::chrono::duration_cast( end - start ), errors ); return 0; } diff --git a/src/create.hpp b/src/create.hpp index 7a7b08e..06680cd 100644 --- a/src/create.hpp +++ b/src/create.hpp @@ -6,7 +6,4 @@ #include #include -#include "output/Output.hpp" - - -auto create( std::string_view root, std::string_view indexLocation, const std::vector& excluded, bool overwrite, const Output* out ) noexcept -> int; +auto create( std::string_view root, std::string_view indexLocation, const std::vector& excluded, bool overwrite ) noexcept -> int; diff --git a/src/log.cpp b/src/log.cpp new file mode 100644 index 0000000..d71fb71 --- /dev/null +++ b/src/log.cpp @@ -0,0 +1,41 @@ +#include "log.hpp" +#include + +bool g_bUIReportMode = false; + +void Log_Message( LogSeverity severity, const std::string_view message ) +{ + // Don't log in report only mode! + const char* prefixes[] = { + "Info", + "Warn", + "Error", + }; + const char* prefix = prefixes[(int)severity]; + + if ( g_bUIReportMode ) + { + // Print for UI to read + const auto line{ fmt::format( R"("message","{}","{}",,)", prefix, message ) }; + std::printf( "%s\n", line.c_str() ); + } + else + { + // Standard print + std::cout << prefix << ": " << message << "\n"; + } +} + +void Log_Report( const std::string_view file, const std::string_view message, const std::string_view got, const std::string_view expected ) +{ + if ( g_bUIReportMode ) + { + const auto line{ fmt::format( R"("report","{}","{}","{}","{}")", file, message, got, expected ) }; + std::printf( "%s\n", line.c_str() ); + } + else + { + const auto line{ fmt::format( "In file `{}`: {}", file, message ) }; + std::fprintf( stderr, "%s\n", line.c_str() ); + } +} diff --git a/src/log.hpp b/src/log.hpp new file mode 100644 index 0000000..d280b71 --- /dev/null +++ b/src/log.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include +#include + +enum class LogSeverity +{ + Info, + Warn, + Error, +}; + +// Base logging function +void Log_Message( LogSeverity severity, const std::string_view message ); + +// Report +extern bool g_bUIReportMode; +void Log_Report( const std::string_view file, const std::string_view message, const std::string_view got, const std::string_view expected ); + +// Logging helpers +template +inline void Log_Info( const fmt::format_string fmt, Ts&&... args ) +{ + Log_Message( LogSeverity::Info, fmt::format( fmt, std::forward( args )... ) ); +} + +template +inline void Log_Warn( const fmt::format_string fmt, Ts&&... args ) +{ + Log_Message( LogSeverity::Warn, fmt::format( fmt, std::forward( args )... ) ); +} + +template +inline void Log_Error( const fmt::format_string fmt, Ts&&... args ) +{ + Log_Message( LogSeverity::Error, fmt::format( fmt, std::forward(args)... ) ); +} + diff --git a/src/main.cpp b/src/main.cpp index 1b09c08..79f743d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,15 +6,10 @@ #include #include #include -#include #include "create.hpp" -#include "output/CsvOutput.hpp" -#include "output/RsvOutput.hpp" -#include "output/JsonOutput.hpp" -#include "output/Output.hpp" -#include "output/SimpleOutput.hpp" #include "verify.hpp" +#include "log.hpp" // the index file is encoded as `Rows-of-String-Values` // correct the index path with os @@ -44,9 +39,7 @@ auto main( int argc, char* argv[] ) -> int { std::string root{}; std::vector excludes{}; std::string indexLocation{}; - std::string format{}; bool overwrite{ false }; - bool tee{ false }; const auto programFile{ std::filesystem::path( argv[ 0 ] ).filename() }; argumentum::argument_parser parser{}; @@ -74,67 +67,24 @@ auto main( int argc, char* argv[] ) -> int { .metavar( "index-loc" ) .maxargs( 1 ) .absent( INDEX_PATH ); - params.add_parameter( format, "--format", "-f" ) - .help( "Output format. [simple, json, csv] default: `simple`" ) - .metavar( "format" ) - .choices( { "simple", "json", "csv", "rsv" } ) - .maxargs( 1 ) - .absent( "simple" ); params.add_parameter( overwrite, "--overwrite" ) .help( "Do not ask for confirmation for overwriting an existing index." ) .metavar( "overwrite" ); - params.add_parameter( tee, "--tee" ) - .help( "Also write the program's output to `$workDir/verifier.log`." ) - .metavar( "tee" ) - .absent( false ); + params.add_parameter( g_bUIReportMode, "--ui-report" ) + .help( "Use UI report mode logging." ) + .metavar( "ui-report" ); if (! parser.parse_args( argc, argv, 1 ) ) { return 1; } - std::unique_ptr output; - switch ( format.at(0) ) { - case 's': - output = std::make_unique(); - break; - case 'j': - output = std::make_unique(); - break; - case 'c': - output = std::make_unique(); - break; - case 'r': - output = std::make_unique(); - break; - default: - fmt::println( stderr, "Invalid `--format` argument: `{}`", format ); - return 1; - } int ret; - // `tee`, can be useful to track down a failure - FILE* file{ nullptr }; - if ( tee ) { -#ifndef _WIN32 - file = std::fopen( "./verifier.log", "w" ); -#else - fopen_s( &file, "./verifier.log", "w" ); -#endif - } - - output->init( file ); // `$basename started at $time` message { auto now{ std::time( nullptr ) }; -#ifndef _WIN32 - auto local{ std::localtime( &now ) }; - const auto line = fmt::format( "`{}` started at {:02d}:{:02d}:{:02d}", programFile.string(), local->tm_hour, local->tm_min, local->tm_sec ); -#else - tm local{}; - localtime_s( &local, &now ); - const auto line = fmt::format( "`{}` started at {:02d}:{:02d}:{:02d}", programFile.string(), local.tm_hour, local.tm_min, local.tm_sec ); -#endif - output->write( OutputKind::Info, line ); + tm* local = std::localtime( &now ); + Log_Info( "`{}` started at {:02d}:{:02d}:{:02d}", programFile.string(), local->tm_hour, local->tm_min, local->tm_sec ); } if ( newIndex ) { // stuff we ignore during the building of the index, the "standard" useless stuff is hardcoded @@ -143,18 +93,15 @@ auto main( int argc, char* argv[] ) -> int { excludes.emplace_back( ".*\\.vmx" ); excludes.emplace_back( ".*\\.log" ); excludes.emplace_back( ".*verifier_index\\.rsv" ); - ret = create( root, indexLocation, excludes, overwrite, output.get() ); + ret = create( root, indexLocation, excludes, overwrite ); } else { - // warn about stuff which shouldn't be here, don't use the `output::report` as this is a negligible user error if ( overwrite ) - fmt::println( stderr, "WARN: current action doesn't support `--overwrite`, please remove it." ); + Log_Error( "current action doesn't support `--overwrite`, please remove it." ); if (! excludes.empty() ) - fmt::println( stderr, "WARN: current action doesn't support `--exclude`, please remove it." ); + Log_Error( "current action doesn't support `--exclude`, please remove it." ); - ret = verify( root, indexLocation, output.get() ); + ret = verify( root, indexLocation ); } - if ( file ) - fclose( file ); return ret; } diff --git a/src/output/CsvOutput.cpp b/src/output/CsvOutput.cpp deleted file mode 100644 index f4971cc..0000000 --- a/src/output/CsvOutput.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// -// Created by ENDERZOMBI102 on 14/10/2023. -// -#include -#include - -#include "CsvOutput.hpp" - -auto CsvOutput::init( FILE* teeFile ) -> void { - Output::init( teeFile ); - fmt::println( "type,context,message,got?,expected?" ); - if ( this->teeFile ) - fmt::println( this->teeFile, "type,context,message,got?,expected?\n" ); -} - -auto CsvOutput::write( OutputKind kind, std::string_view message ) const -> void { - const auto line{ fmt::format( R"("message","{}","{}",,)", toString( kind ), message ) }; - std::printf( "%s\n", line.c_str() ); - if ( this->teeFile ) - std::fprintf( this->teeFile, "%s\n", line.c_str() ); -} - -auto CsvOutput::report( std::string_view file, std::string_view message, std::string_view got, std::string_view expected ) const -> void { - const auto line{ fmt::format( R"("report","{}","{}","{}","{}")", file, message, got, expected ) }; - std::printf( "%s\n", line.c_str() ); - if ( this->teeFile ) - std::fprintf( this->teeFile, "%s\n", line.c_str() ); -} diff --git a/src/output/CsvOutput.hpp b/src/output/CsvOutput.hpp deleted file mode 100644 index 2e58f9e..0000000 --- a/src/output/CsvOutput.hpp +++ /dev/null @@ -1,17 +0,0 @@ -// -// Created by ENDERZOMBI102 on 14/10/2023. -// -#pragma once - -#include "Output.hpp" - -class CsvOutput : public Output { -public: - CsvOutput() = default; - CsvOutput( const CsvOutput& ) = delete; - CsvOutput operator=( const CsvOutput& ) = delete; -public: - auto init( FILE* teeFile ) -> void override; - auto write( OutputKind kind, std::string_view message ) const -> void override; - auto report( std::string_view file, std::string_view message, std::string_view got, std::string_view expected ) const -> void override; -}; diff --git a/src/output/JsonOutput.cpp b/src/output/JsonOutput.cpp deleted file mode 100644 index 637b00e..0000000 --- a/src/output/JsonOutput.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// -// Created by ENDERZOMBI102 on 14/10/2023. -// -#include -#include - -#include "JsonOutput.hpp" - -auto JsonOutput::write( const OutputKind kind, const std::string_view message ) const -> void { - const auto line{ fmt::format( R"({{"type":"message","kind":"{}","message":"{}"}})", toString( kind ), message ) }; - - std::printf( "%s\n", line.c_str() ); - if ( this->teeFile ) - std::fprintf( this->teeFile, "%s\n", line.c_str() ); -} - -auto JsonOutput::report( const std::string_view file, const std::string_view message, const std::string_view got, const std::string_view expected ) const -> void { - const auto line{ fmt::format( R"({{"type":"report","file":"{}","message":"{}","got":"{}","expected":"{}"}})", file, message, got, expected ) }; - - std::printf( "%s\n", line.c_str() ); - if ( this->teeFile ) - std::fprintf( this->teeFile, "%s\n", line.c_str() ); -} diff --git a/src/output/JsonOutput.hpp b/src/output/JsonOutput.hpp deleted file mode 100644 index 9844588..0000000 --- a/src/output/JsonOutput.hpp +++ /dev/null @@ -1,16 +0,0 @@ -// -// Created by ENDERZOMBI102 on 14/10/2023. -// -#pragma once - -#include "Output.hpp" - -class JsonOutput : public Output { -public: - JsonOutput() = default; - JsonOutput( const JsonOutput& ) = delete; - JsonOutput operator=( const JsonOutput& ) = delete; -public: - auto write( OutputKind kind, std::string_view message ) const -> void override; - auto report( std::string_view file, std::string_view message, std::string_view got, std::string_view expected ) const -> void override; -}; diff --git a/src/output/Output.cpp b/src/output/Output.cpp deleted file mode 100644 index 636ed05..0000000 --- a/src/output/Output.cpp +++ /dev/null @@ -1,14 +0,0 @@ -// -// Created by ENDERZOMBI102 on 15/10/2023. -// -#include "Output.hpp" - - -auto toString( const OutputKind kind ) -> std::string_view { - switch ( kind ) { - case OutputKind::Info: return "info"; - case OutputKind::Warn: return "warn"; - case OutputKind::Error: return "error"; - } - return {}; -} diff --git a/src/output/Output.hpp b/src/output/Output.hpp deleted file mode 100644 index 3365569..0000000 --- a/src/output/Output.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// -// Created by ENDERZOMBI102 on 14/10/2023. -// -#pragma once - -#include - -enum class OutputKind { - Info, - Warn, - Error -}; - -auto toString( OutputKind kind ) -> std::string_view; - -class Output { -public: - virtual ~Output() = default; - virtual auto init( FILE* teeFile_ ) -> void { - this->teeFile = teeFile_; - } - virtual auto write( OutputKind kind, std::string_view message ) const -> void = 0; - virtual auto report( std::string_view file, std::string_view message, std::string_view got, std::string_view expected ) const -> void = 0; -protected: - FILE* teeFile{ nullptr }; -}; diff --git a/src/output/RsvOutput.cpp b/src/output/RsvOutput.cpp deleted file mode 100644 index 42722f9..0000000 --- a/src/output/RsvOutput.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// -// Created by ENDERZOMBI102 on 1/29/24. -// -#include -#include - -#include "RsvOutput.hpp" - - -auto RsvOutput::init( FILE* teeFile ) -> void { - Output::init( teeFile ); - fmt::println( "type\xFF" "context\xFFmessage\xFFgot?\xFF" "expected?\xFF\xFD" ); - if ( this->teeFile ) - fmt::println( this->teeFile, "type\xFF" "context\xFFmessage\xFFgot?\xFF" "expected?\xFF\xFD" ); -} - -auto RsvOutput::write( OutputKind kind, std::string_view message ) const -> void { - const auto line{ fmt::format( "message\xFF{}\xFF{}\xFF\xFE\xFF\xFE\xFF\xFD", toString( kind ), message ) }; - std::printf( "%s", line.c_str() ); - if ( this->teeFile ) - std::fprintf( this->teeFile, "%s", line.c_str() ); -} - -auto RsvOutput::report( std::string_view file, std::string_view message, std::string_view got, std::string_view expected ) const -> void { - const auto line{ fmt::format( "report\xFF{}\xFF{}\xFF{}\xFF{}\xFF\xFD", file, message, got, expected ) }; - std::printf( "%s", line.c_str() ); - if ( this->teeFile ) - std::fprintf( this->teeFile, "%s", line.c_str() ); -} \ No newline at end of file diff --git a/src/output/RsvOutput.hpp b/src/output/RsvOutput.hpp deleted file mode 100644 index 1eb912a..0000000 --- a/src/output/RsvOutput.hpp +++ /dev/null @@ -1,17 +0,0 @@ -// -// Created by ENDERZOMBI102 on 1/29/24. -// -#pragma once - -#include "Output.hpp" - -class RsvOutput : public Output { -public: - RsvOutput() = default; - RsvOutput( const RsvOutput& ) = delete; - RsvOutput operator=( const RsvOutput& ) = delete; -public: - auto init( FILE* teeFile ) -> void override; - auto write( OutputKind kind, std::string_view message ) const -> void override; - auto report( std::string_view file, std::string_view message, std::string_view got, std::string_view expected ) const -> void override; -}; diff --git a/src/output/SimpleOutput.cpp b/src/output/SimpleOutput.cpp deleted file mode 100644 index d0bfa8f..0000000 --- a/src/output/SimpleOutput.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// -// Created by ENDERZOMBI102 on 14/10/2023. -// -#include -#include - -#include "SimpleOutput.hpp" - -auto SimpleOutput::write( const OutputKind kind, const std::string_view message ) const -> void { - std::string line; - FILE* where; - switch ( kind ) { - case OutputKind::Info: - line = fmt::format( "Info: {}", message ); - where = stdout; - break; - case OutputKind::Warn: - line = fmt::format( "Warn: {}", message ); - where = stderr; - break; - case OutputKind::Error: - line = fmt::format( "Error: {}", message ); - where = stderr; - break; - } - - std::fprintf( where, "%s\n", line.c_str() ); - if ( this->teeFile ) - std::fprintf( this->teeFile, "%s\n", line.c_str() ); -} - -auto SimpleOutput::report( const std::string_view file, const std::string_view message, const std::string_view got, const std::string_view expected ) const -> void { - const auto line{ fmt::format( "In file `{}`: {}", file, message ) }; - - std::fprintf( stderr, "%s\n", line.c_str() ); - if ( this->teeFile ) - std::fprintf( this->teeFile, "%s\n", line.c_str() ); -} diff --git a/src/output/SimpleOutput.hpp b/src/output/SimpleOutput.hpp deleted file mode 100644 index c770dae..0000000 --- a/src/output/SimpleOutput.hpp +++ /dev/null @@ -1,16 +0,0 @@ -// -// Created by ENDERZOMBI102 on 14/10/2023. -// -#pragma once - -#include "Output.hpp" - -class SimpleOutput : public Output { -public: - SimpleOutput() = default; - SimpleOutput( const SimpleOutput& ) = delete; - SimpleOutput operator=( const SimpleOutput& ) = delete; -public: - auto write( OutputKind kind, std::string_view message ) const -> void override; - auto report( std::string_view file, std::string_view message, std::string_view got, std::string_view expected ) const -> void override; -}; diff --git a/src/verify.cpp b/src/verify.cpp index 02ef290..16046f5 100644 --- a/src/verify.cpp +++ b/src/verify.cpp @@ -2,33 +2,32 @@ // Created by ENDERZOMBI102 on 15/10/2023. // #include -#include -#include #include #include #include #include #include "verify.hpp" +#include "log.hpp" static auto splitString( const std::string& string, const std::string& delim ) -> std::vector; -auto verify( std::string_view root_, std::string_view indexLocation, const Output* out ) -> int { +auto verify( std::string_view root_, std::string_view indexLocation ) -> int { const std::filesystem::path root{ root_ }; const std::filesystem::path indexPath{ root / indexLocation }; if (! std::filesystem::exists( indexPath ) ) { - out->write( OutputKind::Error, fmt::format( "Index file `{}` does not exist.", indexPath.string() ) ); + Log_Error( "Index file `{}` does not exist.", indexPath.string() ); return 1; } - out->write( OutputKind::Info, fmt::format( "Using index file at `{}`", indexPath.string() ) ); + Log_Info( "Using index file at `{}`", indexPath.string() ); // open index file, if the file didn't exist, we wouldn't be here std::ifstream indexStream{ indexPath, std::ios_base::in }; if (! indexStream.good() ) { - out->write( OutputKind::Error, fmt::format( "Failed to open index file for reading: N/D" ) ); + Log_Error( "Failed to open index file for reading: N/D" ); return 1; } @@ -59,7 +58,7 @@ auto verify( std::string_view root_, std::string_view indexLocation, const Outpu const auto path = root / pathRel; if (! std::filesystem::exists( path ) ) { - out->report( pathRel, "Entry doesn't exist on disk.", "nul", "nul" ); + Log_Report( pathRel, "Entry doesn't exist on disk.", "nul", "nul" ); errors += 1; continue; } @@ -74,7 +73,7 @@ auto verify( std::string_view root_, std::string_view indexLocation, const Outpu fopen_s( &file, path.string().c_str(), "rb" ); #endif if (! file ) { - out->write( OutputKind::Error, fmt::format( "Failed to open file: {}", path.string() ) ); + Log_Error( "Failed to open file: {}", path.string() ); continue; } @@ -82,8 +81,8 @@ auto verify( std::string_view root_, std::string_view indexLocation, const Outpu auto length{ std::ftell( file ) }; if ( length != expectedSize ) { - out->report( pathRel, "Sizes don't match.", std::to_string( length ), split[ 3 ] ); - out->write( OutputKind::Info, fmt::format( "Processed entry `{}`", pathRel ) ); + Log_Report( pathRel, "Sizes don't match.", std::to_string( length ), split[ 3 ] ); + Log_Info( "Processed entry `{}`", pathRel ); entries += 1; errors += 1; continue; @@ -100,30 +99,22 @@ auto verify( std::string_view root_, std::string_view indexLocation, const Outpu } if ( sha256er.getHash() != expectedSha256 ) { - out->report( pathRel, "Content sha256 doesn't match.", sha256er.getHash(), expectedSha256 ); + Log_Report( pathRel, "Content sha256 doesn't match.", sha256er.getHash(), expectedSha256 ); errors += 1; } if ( crc32er.getHash() != expectedCrc32 ) { - out->report( pathRel, "Content crc32 doesn't match.", sha256er.getHash(), expectedSha256 ); + Log_Report( pathRel, "Content crc32 doesn't match.", sha256er.getHash(), expectedSha256 ); errors += 1; } - out->write( OutputKind::Info, fmt::format( "Processed entry `{}`", pathRel ) ); + Log_Info( "Processed entry `{}`", pathRel ); entries += 1; } std::fclose( file ); auto end{ std::chrono::high_resolution_clock::now() }; - out->write( - OutputKind::Info, - fmt::format( - "Verified {} files in {} with {} errors!", - entries, - std::chrono::duration_cast( end - start ), - errors - ) - ); + Log_Info( "Verified {} files in {} with {} errors!", entries, std::chrono::duration_cast( end - start ), errors ); return 0; } diff --git a/src/verify.hpp b/src/verify.hpp index ee1b15e..3519b09 100644 --- a/src/verify.hpp +++ b/src/verify.hpp @@ -6,7 +6,4 @@ #include #include -#include "output/Output.hpp" - - -auto verify( std::string_view root, std::string_view indexLocation, const Output* out ) -> int; +auto verify( std::string_view root, std::string_view indexLocation ) -> int; diff --git a/ui/src/MainWindow.cpp b/ui/src/MainWindow.cpp index b154f3d..651e551 100644 --- a/ui/src/MainWindow.cpp +++ b/ui/src/MainWindow.cpp @@ -140,7 +140,7 @@ void MainWindow::onGenerateManifest( bool checked ) { proc->setProgram( getVerifierPath() ); // Setup arguments - QStringList arguments{ "--new-index", "-f", "csv", "--root", this->projectPath->text() }; + QStringList arguments{ "--new-index", "--ui-report", "--root", this->projectPath->text() }; if ( this->manifestPath->text() != "default" ) arguments.append( { "-i", this->manifestPath->text() } ); proc->setArguments( arguments ); @@ -201,7 +201,7 @@ void MainWindow::onVerifyFiles( bool checked ) { proc->setProgram( getVerifierPath() ); // Setup arguments - QStringList arguments{ "-f", "csv", "--root", this->projectPath->text() }; + QStringList arguments{ "--ui-report", "--root", this->projectPath->text() }; if ( this->manifestPath->text() != "default" ) arguments.append( { "-i", this->manifestPath->text() } ); proc->setArguments( arguments );