Skip to content

Commit 16a5cd0

Browse files
committed
Bugfixes, improvements
1 parent 9b78147 commit 16a5cd0

File tree

3 files changed

+38
-26
lines changed

3 files changed

+38
-26
lines changed

main.cpp

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,19 @@ MainWindow::~MainWindow() {
6060
delete ui;
6161
}
6262
void 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

230239
void 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

259270
void 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;

main.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Q_OBJECT
4040

4141
QList<QString> get_hashes_from_name(const QString name);
4242
void generate_file_paths();
43-
static void run_copy_thread(QQueue<QPair<QString, QString>> copy_queue);
43+
static void run_copy_thread(MainWindow *w);
4444
static void run_init_thread(MainWindow *w);
4545

4646
static void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
@@ -61,7 +61,8 @@ Q_OBJECT
6161
QSqlDatabase database;
6262
const QString file_database = "database.db";
6363
const QLineEdit *line_edit_search;
64-
QStringList tmp_filter;
64+
QStringList plaintext_backup;
65+
QString html_backup;
6566

6667
QString path_dest = QDir::currentPath();
6768
QFileInfoList file_paths;

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"database-version": 3,
3-
"main-version": 1
3+
"main-version": 4
44
}

0 commit comments

Comments
 (0)