From e8cdc4e41af364ec4c51a3448743d0ae7d8869c0 Mon Sep 17 00:00:00 2001 From: modeco80 Date: Tue, 22 Aug 2023 19:43:17 -0400 Subject: [PATCH] clean up code a bit more --- src/worker.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/worker.cpp b/src/worker.cpp index 4d14ac0..eaa0d75 100644 --- a/src/worker.cpp +++ b/src/worker.cpp @@ -25,6 +25,8 @@ namespace swbf { std::uint32_t codeHash; bool done = false; + /// The matched codes for this thread. + /// All threads need to be summed up to get the whole list. std::vector matches; void DisplayProgress() { @@ -96,10 +98,9 @@ namespace swbf { while(true) { hash = swbf::SwsfScramble(test_buffer); - // There was a match! + // found a match if(hash == options.targetHash) DisplayData().matches.push_back(test_buffer); - //swbf::fprint(stderr, "match: {} ({:08x})\n", test_buffer, hash); CopyDisplayData(); @@ -138,10 +139,15 @@ namespace swbf { pool.join(); // just in case! - // build the matches file - fprint(stdout, "Writing matches file..."); + fprint(stdout, "\nDone, writing matches file...\n"); std::ofstream ofs("matches.txt"); + if(!ofs) { + fprint(stderr, "Could not open matches file for writing. Unfortunately, there's not much I can do about that.\n"); + std::exit(1); + } + + // write the matches file if(options.exact) fprint(ofs, "Matches for hash {:8x} for length {}:\n", options.targetHash, options.startLength, options.endLength); else @@ -154,6 +160,8 @@ namespace swbf { td.matches.clear(); } + + infoData.clear(); } } // namespace swbf