From bf10c23c9bad384dcd42cbbad46375718844d1ff Mon Sep 17 00:00:00 2001 From: Maxime Gervais Date: Mon, 6 Jul 2026 01:21:04 +0200 Subject: [PATCH] Check options before reusing saved report Signed-off-by: Maxime Gervais --- Source/Common/Core.cpp | 31 ++++++++++---------- Source/Common/Core.h | 11 +++---- Source/Common/SQLLiteReport.cpp | 52 +++++++++++++++++++++------------ Source/Common/Scheduler.cpp | 4 +-- Source/GUI/Qt/mainwindow.cpp | 2 +- 5 files changed, 58 insertions(+), 42 deletions(-) diff --git a/Source/Common/Core.cpp b/Source/Common/Core.cpp index 3b3977b7..7b242f57 100644 --- a/Source/Common/Core.cpp +++ b/Source/Common/Core.cpp @@ -829,7 +829,7 @@ void Core::register_report_xml_to_database(int user, long file, const std::strin } //--------------------------------------------------------------------------- -void Core::register_report_mediainfo_text_to_database(int user, long file, MediaInfoNameSpace::MediaInfo* curMI) +void Core::register_report_mediainfo_text_to_database(int user, long file, const std::string& options, MediaInfoNameSpace::MediaInfo* curMI) { curMI->Option(__T("Details"), __T("0")); curMI->Option(__T("Inform"), String()); @@ -841,12 +841,12 @@ void Core::register_report_mediainfo_text_to_database(int user, long file, Media std::string err; db_mutex.Enter(); get_db()->save_report(user, file, MediaConchLib::report_MediaInfo, MediaConchLib::format_Text, - "", report, mode, mil_version(), err); + options, report, mode, mil_version(), err); db_mutex.Leave(); } //--------------------------------------------------------------------------- -void Core::register_report_mediainfo_xml_to_database(int user, long file, MediaInfoNameSpace::MediaInfo* curMI) +void Core::register_report_mediainfo_xml_to_database(int user, long file, const std::string& options, MediaInfoNameSpace::MediaInfo* curMI) { curMI->Option(__T("Details"), __T("0")); curMI->Option(__T("Inform"), __T("MIXML")); @@ -857,12 +857,12 @@ void Core::register_report_mediainfo_xml_to_database(int user, long file, MediaI std::string err; db_mutex.Enter(); get_db()->save_report(user, file, MediaConchLib::report_MediaInfo, MediaConchLib::format_Xml, - "", report, mode, mil_version(), err); + options, report, mode, mil_version(), err); db_mutex.Leave(); } //--------------------------------------------------------------------------- -void Core::register_report_micromediatrace_xml_to_database(int user, long file, MediaInfoNameSpace::MediaInfo* curMI) +void Core::register_report_micromediatrace_xml_to_database(int user, long file, const std::string& options, MediaInfoNameSpace::MediaInfo* curMI) { curMI->Option(__T("Details"), __T("1")); curMI->Option(__T("Inform"), __T("MICRO_XML")); @@ -892,7 +892,7 @@ void Core::register_report_micromediatrace_xml_to_database(int user, long file, std::string err; db_mutex.Enter(); get_db()->save_report(user, file, MediaConchLib::report_MicroMediaTrace, MediaConchLib::format_Xml, - "", report, mode, mil_version(), err); + options, report, mode, mil_version(), err); db_mutex.Leave(); } @@ -914,29 +914,30 @@ void Core::register_reports_to_database(int user, long file, const std::string& register_report_xml_to_database(user, file, report, report_kind, options); //MI and MT - register_reports_to_database(user, file, curMI); + register_reports_to_database(user, file, options, curMI); } //--------------------------------------------------------------------------- -void Core::register_reports_to_database(int user, long file, MediaInfoNameSpace::MediaInfo* curMI) +void Core::register_reports_to_database(int user, long file, const std::string& options, + MediaInfoNameSpace::MediaInfo* curMI) { // MediaInfo - register_report_mediainfo_text_to_database(user, file, curMI); - register_report_mediainfo_xml_to_database(user, file, curMI); + register_report_mediainfo_text_to_database(user, file, options, curMI); + register_report_mediainfo_xml_to_database(user, file, options, curMI); // MicroMediaTrace - register_report_micromediatrace_xml_to_database(user, file, curMI); + register_report_micromediatrace_xml_to_database(user, file, options, curMI); } //--------------------------------------------------------------------------- -void Core::register_reports_to_database(int user, long file) +void Core::register_reports_to_database(int user, long file, const std::string& options) { // MediaInfo - register_report_mediainfo_text_to_database(user, file, MI); - register_report_mediainfo_xml_to_database(user, file, MI); + register_report_mediainfo_text_to_database(user, file, options, MI); + register_report_mediainfo_xml_to_database(user, file, options, MI); // MicroMediaTrace - register_report_micromediatrace_xml_to_database(user, file, MI); + register_report_micromediatrace_xml_to_database(user, file, options, MI); } //--------------------------------------------------------------------------- diff --git a/Source/Common/Core.h b/Source/Common/Core.h index 546a17f0..db6ac1bd 100644 --- a/Source/Common/Core.h +++ b/Source/Common/Core.h @@ -178,7 +178,8 @@ class Core // Report Database access //*************************************************************************** void set_file_analyzed_to_database(int user, long id); - void register_reports_to_database(int user, long file, MediaInfoNameSpace::MediaInfo* MI); + void register_reports_to_database(int user, long file, const std::string& options, + MediaInfoNameSpace::MediaInfo* MI); void register_reports_to_database(int user, long file, const std::string& report, MediaConchLib::report report_kind, const std::string& options, MediaInfoNameSpace::MediaInfo* curMI); @@ -245,12 +246,12 @@ class Core std::string get_last_modification_file(const std::string& file); bool file_is_existing(const std::string& filename); - void register_reports_to_database(int user, long file); + void register_reports_to_database(int user, long file, const std::string& options); void register_report_xml_to_database(int user, long file, const std::string& report, MediaConchLib::report report_kind, const std::string& options); - void register_report_mediainfo_text_to_database(int user, long file, MediaInfoNameSpace::MediaInfo* MI); - void register_report_mediainfo_xml_to_database(int user, long file, MediaInfoNameSpace::MediaInfo* MI); - void register_report_micromediatrace_xml_to_database(int user, long file, MediaInfoNameSpace::MediaInfo* MI); + void register_report_mediainfo_text_to_database(int user, long file, const std::string& options, MediaInfoNameSpace::MediaInfo* MI); + void register_report_mediainfo_xml_to_database(int user, long file,const std::string& options, MediaInfoNameSpace::MediaInfo* MI); + void register_report_micromediatrace_xml_to_database(int user, long file,const std::string& options, MediaInfoNameSpace::MediaInfo* MI); std::string get_config_file(); std::string get_database_path(); diff --git a/Source/Common/SQLLiteReport.cpp b/Source/Common/SQLLiteReport.cpp index efde3dd5..53d1d9e5 100644 --- a/Source/Common/SQLLiteReport.cpp +++ b/Source/Common/SQLLiteReport.cpp @@ -379,8 +379,9 @@ long SQLLiteReport::get_file_id(int user, const std::string& filename, const std create << "SELECT " << key << " FROM MEDIACONCH_FILE"; create << " WHERE FILENAME = ?"; create << " AND USER = ?"; - create << " AND OPTIONS = ?"; - if (file_last_modification.size()) + if (!options.empty()) + create << " AND OPTIONS = ?"; + if (!file_last_modification.empty()) create << " AND FILE_LAST_MODIFICATION = ?"; create << ";"; query = create.str(); @@ -402,16 +403,19 @@ long SQLLiteReport::get_file_id(int user, const std::string& filename, const std return -1; } - ret = sqlite3_bind_text(stmt, 3, options.c_str(), options.size(), SQLITE_STATIC); - if (ret != SQLITE_OK) + if (!options.empty()) { - err = get_sqlite_error(ret); - return -1; + ret = sqlite3_bind_text(stmt, 3, options.c_str(), options.size(), SQLITE_STATIC); + if (ret != SQLITE_OK) + { + err = get_sqlite_error(ret); + return -1; + } } - if (file_last_modification.size()) + if (!file_last_modification.empty()) { - ret = sqlite3_bind_blob(stmt, 4, file_last_modification.c_str(), file_last_modification.length(), SQLITE_STATIC); + ret = sqlite3_bind_blob(stmt, options.empty() ? 3 : 4, file_last_modification.c_str(), file_last_modification.length(), SQLITE_STATIC); if (ret != SQLITE_OK) { err = get_sqlite_error(ret); @@ -1133,7 +1137,9 @@ int SQLLiteReport::get_report(int user, long file_id, MediaConchLib::report repo create << "FILE_ID = ? "; create << "AND TOOL = ? "; create << "AND FORMAT = ?"; - create << "AND OPTIONS = ?;"; + if (!options.empty()) + create << " AND OPTIONS = ?"; + create << ";"; query = create.str(); if (prepare_v2(query, err) < 0) @@ -1160,11 +1166,14 @@ int SQLLiteReport::get_report(int user, long file_id, MediaConchLib::report repo return -1; } - ret = sqlite3_bind_text(stmt, 4, options.c_str(), options.size(), SQLITE_STATIC); - if (ret != SQLITE_OK) + if (!options.empty()) { - err = get_sqlite_error(ret); - return -1; + ret = sqlite3_bind_text(stmt, 4, options.c_str(), options.size(), SQLITE_STATIC); + if (ret != SQLITE_OK) + { + err = get_sqlite_error(ret); + return -1; + } } if (execute() < 0 || !reports.size()) @@ -1215,8 +1224,10 @@ int SQLLiteReport::report_is_registered(int user, long file_id, MediaConchLib::r create << "SELECT " << key << " FROM MEDIACONCH_REPORT WHERE "; create << "FILE_ID = ? "; create << "AND TOOL = ? "; - create << "AND FORMAT = ? "; - create << "AND OPTIONS = ?;"; + create << "AND FORMAT = ?"; + if (!options.empty()) + create << " AND OPTIONS = ?"; + create << ";"; query = create.str(); if (prepare_v2(query, err) < 0) @@ -1243,11 +1254,14 @@ int SQLLiteReport::report_is_registered(int user, long file_id, MediaConchLib::r return -1; } - ret = sqlite3_bind_text(stmt, 4, options.c_str(), options.size(), SQLITE_STATIC); - if (ret != SQLITE_OK) + if (!options.empty()) { - err = get_sqlite_error(ret); - return -1; + ret = sqlite3_bind_text(stmt, 4, options.c_str(), options.size(), SQLITE_STATIC); + if (ret != SQLITE_OK) + { + err = get_sqlite_error(ret); + return -1; + } } if (execute()) diff --git a/Source/Common/Scheduler.cpp b/Source/Common/Scheduler.cpp index 6a557fe0..ec81ae13 100644 --- a/Source/Common/Scheduler.cpp +++ b/Source/Common/Scheduler.cpp @@ -124,7 +124,7 @@ namespace MediaConch { CS.Enter(); if (!el->errored()) - core->register_reports_to_database(el->user, el->file_id, MI); + core->register_reports_to_database(el->user, el->file_id, Core::serialize_string_from_options_vec(el->options), MI); else { std::string err; @@ -302,7 +302,7 @@ namespace MediaConch { MediaConchLib::report report_kind = ((PluginFormat*)p)->get_report_kind(); CS.Enter(); - core->register_reports_to_database(el->user, el->file_id, report, report_kind, "", MI); + core->register_reports_to_database(el->user, el->file_id, report, report_kind, Core::serialize_string_from_options_vec(el->options), MI); remove_element(el); CS.Leave(); run_element(); diff --git a/Source/GUI/Qt/mainwindow.cpp b/Source/GUI/Qt/mainwindow.cpp index c9e333d4..8f313b0e 100644 --- a/Source/GUI/Qt/mainwindow.cpp +++ b/Source/GUI/Qt/mainwindow.cpp @@ -1423,7 +1423,7 @@ int MainWindow::analyze(const std::vector& files, bool with_fixer, for (size_t i = 0; i + 1 < opt.size();) { - if (opt[i] != "File_TryToFix" && opt[i] != "file_parsespeed") + if (!(with_fixer && (opt[i] == "File_TryToFix" || opt[i] == "file_parsespeed"))) options.push_back(std::make_pair(opt[i], opt[i + 1])); i += 2; }