Skip to content

Commit bf10c23

Browse files
committed
Check options before reusing saved report
Signed-off-by: Maxime Gervais <gervais.maxime@gmail.com>
1 parent b3790f2 commit bf10c23

5 files changed

Lines changed: 58 additions & 42 deletions

File tree

Source/Common/Core.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ void Core::register_report_xml_to_database(int user, long file, const std::strin
829829
}
830830

831831
//---------------------------------------------------------------------------
832-
void Core::register_report_mediainfo_text_to_database(int user, long file, MediaInfoNameSpace::MediaInfo* curMI)
832+
void Core::register_report_mediainfo_text_to_database(int user, long file, const std::string& options, MediaInfoNameSpace::MediaInfo* curMI)
833833
{
834834
curMI->Option(__T("Details"), __T("0"));
835835
curMI->Option(__T("Inform"), String());
@@ -841,12 +841,12 @@ void Core::register_report_mediainfo_text_to_database(int user, long file, Media
841841
std::string err;
842842
db_mutex.Enter();
843843
get_db()->save_report(user, file, MediaConchLib::report_MediaInfo, MediaConchLib::format_Text,
844-
"", report, mode, mil_version(), err);
844+
options, report, mode, mil_version(), err);
845845
db_mutex.Leave();
846846
}
847847

848848
//---------------------------------------------------------------------------
849-
void Core::register_report_mediainfo_xml_to_database(int user, long file, MediaInfoNameSpace::MediaInfo* curMI)
849+
void Core::register_report_mediainfo_xml_to_database(int user, long file, const std::string& options, MediaInfoNameSpace::MediaInfo* curMI)
850850
{
851851
curMI->Option(__T("Details"), __T("0"));
852852
curMI->Option(__T("Inform"), __T("MIXML"));
@@ -857,12 +857,12 @@ void Core::register_report_mediainfo_xml_to_database(int user, long file, MediaI
857857
std::string err;
858858
db_mutex.Enter();
859859
get_db()->save_report(user, file, MediaConchLib::report_MediaInfo, MediaConchLib::format_Xml,
860-
"", report, mode, mil_version(), err);
860+
options, report, mode, mil_version(), err);
861861
db_mutex.Leave();
862862
}
863863

864864
//---------------------------------------------------------------------------
865-
void Core::register_report_micromediatrace_xml_to_database(int user, long file, MediaInfoNameSpace::MediaInfo* curMI)
865+
void Core::register_report_micromediatrace_xml_to_database(int user, long file, const std::string& options, MediaInfoNameSpace::MediaInfo* curMI)
866866
{
867867
curMI->Option(__T("Details"), __T("1"));
868868
curMI->Option(__T("Inform"), __T("MICRO_XML"));
@@ -892,7 +892,7 @@ void Core::register_report_micromediatrace_xml_to_database(int user, long file,
892892
std::string err;
893893
db_mutex.Enter();
894894
get_db()->save_report(user, file, MediaConchLib::report_MicroMediaTrace, MediaConchLib::format_Xml,
895-
"", report, mode, mil_version(), err);
895+
options, report, mode, mil_version(), err);
896896
db_mutex.Leave();
897897
}
898898

@@ -914,29 +914,30 @@ void Core::register_reports_to_database(int user, long file, const std::string&
914914
register_report_xml_to_database(user, file, report, report_kind, options);
915915

916916
//MI and MT
917-
register_reports_to_database(user, file, curMI);
917+
register_reports_to_database(user, file, options, curMI);
918918
}
919919

920920
//---------------------------------------------------------------------------
921-
void Core::register_reports_to_database(int user, long file, MediaInfoNameSpace::MediaInfo* curMI)
921+
void Core::register_reports_to_database(int user, long file, const std::string& options,
922+
MediaInfoNameSpace::MediaInfo* curMI)
922923
{
923924
// MediaInfo
924-
register_report_mediainfo_text_to_database(user, file, curMI);
925-
register_report_mediainfo_xml_to_database(user, file, curMI);
925+
register_report_mediainfo_text_to_database(user, file, options, curMI);
926+
register_report_mediainfo_xml_to_database(user, file, options, curMI);
926927

927928
// MicroMediaTrace
928-
register_report_micromediatrace_xml_to_database(user, file, curMI);
929+
register_report_micromediatrace_xml_to_database(user, file, options, curMI);
929930
}
930931

931932
//---------------------------------------------------------------------------
932-
void Core::register_reports_to_database(int user, long file)
933+
void Core::register_reports_to_database(int user, long file, const std::string& options)
933934
{
934935
// MediaInfo
935-
register_report_mediainfo_text_to_database(user, file, MI);
936-
register_report_mediainfo_xml_to_database(user, file, MI);
936+
register_report_mediainfo_text_to_database(user, file, options, MI);
937+
register_report_mediainfo_xml_to_database(user, file, options, MI);
937938

938939
// MicroMediaTrace
939-
register_report_micromediatrace_xml_to_database(user, file, MI);
940+
register_report_micromediatrace_xml_to_database(user, file, options, MI);
940941
}
941942

942943
//---------------------------------------------------------------------------

Source/Common/Core.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ class Core
178178
// Report Database access
179179
//***************************************************************************
180180
void set_file_analyzed_to_database(int user, long id);
181-
void register_reports_to_database(int user, long file, MediaInfoNameSpace::MediaInfo* MI);
181+
void register_reports_to_database(int user, long file, const std::string& options,
182+
MediaInfoNameSpace::MediaInfo* MI);
182183
void register_reports_to_database(int user, long file, const std::string& report,
183184
MediaConchLib::report report_kind, const std::string& options,
184185
MediaInfoNameSpace::MediaInfo* curMI);
@@ -245,12 +246,12 @@ class Core
245246
std::string get_last_modification_file(const std::string& file);
246247
bool file_is_existing(const std::string& filename);
247248

248-
void register_reports_to_database(int user, long file);
249+
void register_reports_to_database(int user, long file, const std::string& options);
249250
void register_report_xml_to_database(int user, long file, const std::string& report,
250251
MediaConchLib::report report_kind, const std::string& options);
251-
void register_report_mediainfo_text_to_database(int user, long file, MediaInfoNameSpace::MediaInfo* MI);
252-
void register_report_mediainfo_xml_to_database(int user, long file, MediaInfoNameSpace::MediaInfo* MI);
253-
void register_report_micromediatrace_xml_to_database(int user, long file, MediaInfoNameSpace::MediaInfo* MI);
252+
void register_report_mediainfo_text_to_database(int user, long file, const std::string& options, MediaInfoNameSpace::MediaInfo* MI);
253+
void register_report_mediainfo_xml_to_database(int user, long file,const std::string& options, MediaInfoNameSpace::MediaInfo* MI);
254+
void register_report_micromediatrace_xml_to_database(int user, long file,const std::string& options, MediaInfoNameSpace::MediaInfo* MI);
254255

255256
std::string get_config_file();
256257
std::string get_database_path();

Source/Common/SQLLiteReport.cpp

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,9 @@ long SQLLiteReport::get_file_id(int user, const std::string& filename, const std
379379
create << "SELECT " << key << " FROM MEDIACONCH_FILE";
380380
create << " WHERE FILENAME = ?";
381381
create << " AND USER = ?";
382-
create << " AND OPTIONS = ?";
383-
if (file_last_modification.size())
382+
if (!options.empty())
383+
create << " AND OPTIONS = ?";
384+
if (!file_last_modification.empty())
384385
create << " AND FILE_LAST_MODIFICATION = ?";
385386
create << ";";
386387
query = create.str();
@@ -402,16 +403,19 @@ long SQLLiteReport::get_file_id(int user, const std::string& filename, const std
402403
return -1;
403404
}
404405

405-
ret = sqlite3_bind_text(stmt, 3, options.c_str(), options.size(), SQLITE_STATIC);
406-
if (ret != SQLITE_OK)
406+
if (!options.empty())
407407
{
408-
err = get_sqlite_error(ret);
409-
return -1;
408+
ret = sqlite3_bind_text(stmt, 3, options.c_str(), options.size(), SQLITE_STATIC);
409+
if (ret != SQLITE_OK)
410+
{
411+
err = get_sqlite_error(ret);
412+
return -1;
413+
}
410414
}
411415

412-
if (file_last_modification.size())
416+
if (!file_last_modification.empty())
413417
{
414-
ret = sqlite3_bind_blob(stmt, 4, file_last_modification.c_str(), file_last_modification.length(), SQLITE_STATIC);
418+
ret = sqlite3_bind_blob(stmt, options.empty() ? 3 : 4, file_last_modification.c_str(), file_last_modification.length(), SQLITE_STATIC);
415419
if (ret != SQLITE_OK)
416420
{
417421
err = get_sqlite_error(ret);
@@ -1133,7 +1137,9 @@ int SQLLiteReport::get_report(int user, long file_id, MediaConchLib::report repo
11331137
create << "FILE_ID = ? ";
11341138
create << "AND TOOL = ? ";
11351139
create << "AND FORMAT = ?";
1136-
create << "AND OPTIONS = ?;";
1140+
if (!options.empty())
1141+
create << " AND OPTIONS = ?";
1142+
create << ";";
11371143
query = create.str();
11381144

11391145
if (prepare_v2(query, err) < 0)
@@ -1160,11 +1166,14 @@ int SQLLiteReport::get_report(int user, long file_id, MediaConchLib::report repo
11601166
return -1;
11611167
}
11621168

1163-
ret = sqlite3_bind_text(stmt, 4, options.c_str(), options.size(), SQLITE_STATIC);
1164-
if (ret != SQLITE_OK)
1169+
if (!options.empty())
11651170
{
1166-
err = get_sqlite_error(ret);
1167-
return -1;
1171+
ret = sqlite3_bind_text(stmt, 4, options.c_str(), options.size(), SQLITE_STATIC);
1172+
if (ret != SQLITE_OK)
1173+
{
1174+
err = get_sqlite_error(ret);
1175+
return -1;
1176+
}
11681177
}
11691178

11701179
if (execute() < 0 || !reports.size())
@@ -1215,8 +1224,10 @@ int SQLLiteReport::report_is_registered(int user, long file_id, MediaConchLib::r
12151224
create << "SELECT " << key << " FROM MEDIACONCH_REPORT WHERE ";
12161225
create << "FILE_ID = ? ";
12171226
create << "AND TOOL = ? ";
1218-
create << "AND FORMAT = ? ";
1219-
create << "AND OPTIONS = ?;";
1227+
create << "AND FORMAT = ?";
1228+
if (!options.empty())
1229+
create << " AND OPTIONS = ?";
1230+
create << ";";
12201231
query = create.str();
12211232

12221233
if (prepare_v2(query, err) < 0)
@@ -1243,11 +1254,14 @@ int SQLLiteReport::report_is_registered(int user, long file_id, MediaConchLib::r
12431254
return -1;
12441255
}
12451256

1246-
ret = sqlite3_bind_text(stmt, 4, options.c_str(), options.size(), SQLITE_STATIC);
1247-
if (ret != SQLITE_OK)
1257+
if (!options.empty())
12481258
{
1249-
err = get_sqlite_error(ret);
1250-
return -1;
1259+
ret = sqlite3_bind_text(stmt, 4, options.c_str(), options.size(), SQLITE_STATIC);
1260+
if (ret != SQLITE_OK)
1261+
{
1262+
err = get_sqlite_error(ret);
1263+
return -1;
1264+
}
12511265
}
12521266

12531267
if (execute())

Source/Common/Scheduler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ namespace MediaConch {
124124

125125
CS.Enter();
126126
if (!el->errored())
127-
core->register_reports_to_database(el->user, el->file_id, MI);
127+
core->register_reports_to_database(el->user, el->file_id, Core::serialize_string_from_options_vec(el->options), MI);
128128
else
129129
{
130130
std::string err;
@@ -302,7 +302,7 @@ namespace MediaConch {
302302
MediaConchLib::report report_kind = ((PluginFormat*)p)->get_report_kind();
303303

304304
CS.Enter();
305-
core->register_reports_to_database(el->user, el->file_id, report, report_kind, "", MI);
305+
core->register_reports_to_database(el->user, el->file_id, report, report_kind, Core::serialize_string_from_options_vec(el->options), MI);
306306
remove_element(el);
307307
CS.Leave();
308308
run_element();

Source/GUI/Qt/mainwindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ int MainWindow::analyze(const std::vector<std::string>& files, bool with_fixer,
14231423

14241424
for (size_t i = 0; i + 1 < opt.size();)
14251425
{
1426-
if (opt[i] != "File_TryToFix" && opt[i] != "file_parsespeed")
1426+
if (!(with_fixer && (opt[i] == "File_TryToFix" || opt[i] == "file_parsespeed")))
14271427
options.push_back(std::make_pair(opt[i], opt[i + 1]));
14281428
i += 2;
14291429
}

0 commit comments

Comments
 (0)