Skip to content

Commit 4bd58f9

Browse files
committed
Replaced async with thread for mingw support
1 parent 486ff1b commit 4bd58f9

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/core/hexeditor.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@ vector<Match *> HexEditor::findPatterns() {
241241
}
242242
}
243243

244+
void HexEditor::initCompare() {
245+
this->fileCompared = false;
246+
}
247+
248+
bool HexEditor::hasCompared() {
249+
return this->fileCompared;
250+
}
251+
244252
vector<pair<unsigned long, uint8_t>> HexEditor::compareTo(HexEditor &hexEditor) {
245253
vector<pair<unsigned long, uint8_t>> diff_bytes;
246254

@@ -254,8 +262,8 @@ vector<pair<unsigned long, uint8_t>> HexEditor::compareTo(HexEditor &hexEditor)
254262
if (this->getCurrentData()[i] != byte_new) {
255263
diff_bytes.push_back(pair<unsigned long, uint8_t>(i, byte_new));
256264
}
257-
this->bytesRead = i;
258265
}
266+
this->fileCompared = true;
259267

260268
return diff_bytes;
261269
}

src/core/hexeditor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class HexEditor
2828
atomic<unsigned long> bytesRead;
2929
atomic<unsigned long> bytesSaved;
3030
atomic<bool> fileSaved;
31+
atomic<bool> fileCompared;
3132
HexEditor();
3233
HexEditor(string path);
3334
~HexEditor();
@@ -44,6 +45,8 @@ class HexEditor
4445
string getCurrentPath();
4546
vector<Match *> findPatterns();
4647
vector<pair<unsigned long, uint8_t>> compareTo(HexEditor &hexEditor);
48+
void initCompare();
49+
bool hasCompared();
4750

4851
private:
4952
PatternMatching *patternMatching;

src/fhex.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -835,26 +835,28 @@ void Fhex::compare(QString filename) {
835835
this->progressBar->setValue(0);
836836
this->statusBar.setText("Comparing file.. please wait");
837837

838-
future<vector<pair<unsigned long, uint8_t>>> fut_res = async([this, filename]()
838+
vector<pair<unsigned long, uint8_t>> res;
839+
this->hexEditor->initCompare();
840+
std::thread th([this, filename, &res]()
839841
{
840842
HexEditor newHexEditor;
841843
newHexEditor.loadFileAsync(filename.toStdString());
842844
while(!newHexEditor.isFileLoaded()) {
843845
std::this_thread::sleep_for(std::chrono::milliseconds(100));
844846
}
845-
return this->hexEditor->compareTo(newHexEditor);
847+
res = this->hexEditor->compareTo(newHexEditor);
846848
});
847849

848-
while (fut_res.wait_for(std::chrono::milliseconds(100)) != std::future_status::ready) {
850+
while (!this->hexEditor->hasCompared()) {
849851
int val = (this->hexEditor->bytesRead * 100) / this->hexEditor->loadedFileSize;
850852
this->progressBar->setValue(val);
851853
this->repaint();
852854
this->app->processEvents();
853855
}
856+
th.join();
854857

855858
this->progressBar->setVisible(false);
856859

857-
vector<pair<unsigned long, uint8_t>> res = fut_res.get();
858860
unsigned long changes = res.size();
859861
unsigned long start_offset = 0;
860862
unsigned long offset = 0;

0 commit comments

Comments
 (0)