@@ -60,18 +60,19 @@ MainWindow::~MainWindow() {
6060 delete ui;
6161}
6262void MainWindow::on_line_edit_text_edited (const QString &str) {
63- if (tmp_filter.isEmpty ()) { // backup the old content of text edit right
64- tmp_filter = ui->text_edit_right ->toPlainText ().split (" \n " );
63+ if (plaintext_backup.isEmpty ()) { // backup the old content of text edit right
64+ html_backup = ui->text_edit_right ->toHtml ();
65+ plaintext_backup = ui->text_edit_right ->toPlainText ().split (" \n " );
6566 }
6667
6768 if (!str.isEmpty ()) { // if line edit is empty, we reset right pane
6869 QStringList res;
69- for (QString s : tmp_filter )
70+ for (QString s : plaintext_backup )
7071 if (s.contains (str, Qt::CaseInsensitive))
7172 res += s;
7273 ui->text_edit_right ->setText (res.join (" \n " ));
7374 } else {
74- ui->text_edit_right ->setText (tmp_filter. join ( " \n " ) );
75+ ui->text_edit_right ->setText (html_backup );
7576 }
7677}
7778
@@ -99,7 +100,7 @@ void MainWindow::on_file_chooser_src_clicked() {
99100 }
100101
101102 ui->text_edit_right ->clear ();
102- tmp_filter .clear ();
103+ plaintext_backup .clear ();
103104 ui->text_edit_left ->setText (res);
104105 ui->text_edit_left ->setReadOnly (true );
105106 ui->option_copy ->setEnabled (true );
@@ -179,28 +180,33 @@ void MainWindow::on_button_go_clicked() {
179180 }
180181
181182 qDebug (" Checking duplicates..." );
183+ bool from_name;
182184 for (const QFileInfo &entry : file_paths) { // iterate over the selected files
183185 QRegularExpressionMatch match = regex_hash.match (entry.fileName ());
184186
185187 // check presence of hash in filename
186188 QList<QString> hashes;
187189 if (match.hasMatch ()) {
188190 hashes.append (match.captured (0 ));
189- qDebug (" Found matching hash" );
190- names_mode = false ;
191+ qDebug (" Found matching hash for %s " , match. captured ( 0 ). toStdString (). c_str () );
192+ from_name = false ;
191193 } else if (names_mode) {
192- for (QString hash : get_hashes_from_name (entry.fileName ())) {
193- hashes.append (hash_from_int (hash));
194+ QList<QString> h = get_hashes_from_name (entry.baseName ());
195+ if (!h.isEmpty ()) {
196+ for (QString hash : h) {
197+ hashes.append (hash_from_int (hash));
198+ }
199+ qDebug (" Found %d matching hashes for name %s" , hashes.size (), entry.fileName ().toStdString ().c_str ());
200+ from_name = true ;
194201 }
195- qDebug (" Found %d matching hashes" , hashes.size ());
196202 }
197203
198204 QList<QList<QVariant>> search_results;
199205 for (QString hash : hashes) {
200206 search_results = get_duplicates_from_hash (hash);
201207
202208 if (!search_results.isEmpty ()) {
203- ts << hash << (names_mode ? " <font color=\" orange\" >(from name)</font><br>" : " <br>" );
209+ ts << hash << (from_name ? " <font color=\" orange\" >(from name)</font><br>" : " <br>" );
204210 for (QList<QVariant> search : search_results) {
205211 QString crc = search[0 ].toString ();
206212 QString name = search[1 ].toString ();
@@ -221,39 +227,44 @@ void MainWindow::on_button_go_clicked() {
221227 }
222228
223229 if (copy_mode) {
224- thread_copy = std::thread (run_copy_thread, copy_queue );
230+ thread_copy = std::thread (run_copy_thread, this );
225231 }
226232
227233 ui->text_edit_right ->setText (result);
234+ if (thread_copy.joinable ()) {
235+ thread_copy.join ();
236+ }
228237}
229238
230239void MainWindow::on_button_clear_clicked () {
231240 qDebug (" Clearing data" );
232241 ui->text_edit_right ->clear ();
233- tmp_filter .clear ();
242+ plaintext_backup .clear ();
234243 ui->text_edit_left ->clear ();
235244 ui->text_edit_left ->setReadOnly (false );
236245 ui->option_copy ->setEnabled (false );
237246 ui->file_chooser_dst ->setEnabled (false );
238247 file_paths.clear ();
239248}
240249
241- void MainWindow::run_copy_thread (QQueue<QPair<QString, QString>> files) {
250+ void MainWindow::run_copy_thread (MainWindow *w) {
251+ w->ui ->button_go ->setEnabled (false );
242252 QPair<QString, QString> file;
243- while (!files .isEmpty ()) {
244- file = files .dequeue ();
245- qDebug ( " Copying %s to %s " , file. first . toStdString (). c_str (), file. second . toStdString (). c_str ());
253+ while (!w-> copy_queue .isEmpty ()) {
254+ file = w-> copy_queue .dequeue ();
255+
246256
247257 if (QFile (file.second ).exists () && QFile (file.second ).size () < QFile (file.first ).size ()) {
248- qDebug (" Destination already exists. Overwriting with larger file." );
258+ qDebug (" Destination already exists, but this file is larger." );
259+ qDebug (" Copying %s to %s" , file.first .toStdString ().c_str (), file.second .toStdString ().c_str ());
249260 QFile::remove (file.second );
250261 QFile::copy (file.first , file.second );
251262 } else if (!QFile (file.second ).exists ()) {
263+ qDebug (" Copying %s to %s" , file.first .toStdString ().c_str (), file.second .toStdString ().c_str ());
252264 QFile::copy (file.first , file.second );
253- } else {
254- qDebug (" Abort copy." );
255265 }
256266 }
267+ w->ui ->button_go ->setEnabled (true );
257268}
258269
259270void MainWindow::run_init_thread (MainWindow *w) {
@@ -299,10 +310,10 @@ void MainWindow::run_init_thread(MainWindow *w) {
299310
300311 // auto update executable
301312 if (local_main_version < remote_main_version) {
302- qCritical (" Texture Mapper is outdated, updating from %s..." , url_executable.arg (remote_db_version ).toStdString ().c_str ());
313+ qCritical (" Texture Mapper is outdated, updating from %s..." , url_executable.arg (remote_main_version ).toStdString ().c_str ());
303314
304315 QNetworkAccessManager manager;
305- QNetworkRequest req (QUrl (url_executable.arg (remote_db_version )));
316+ QNetworkRequest req (QUrl (url_executable.arg (remote_main_version )));
306317 req.setAttribute (QNetworkRequest::FollowRedirectsAttribute, true );
307318 QNetworkReply *response_exec = manager.get (req);
308319
@@ -329,7 +340,7 @@ void MainWindow::run_init_thread(MainWindow *w) {
329340 }
330341 }
331342 } else {
332- qDebug (" We are running the latest available version of the tools " );
343+ qDebug (" Running the latest available version of the tool " );
333344 }
334345
335346 QJsonObject new_json;
0 commit comments