Skip to content

Commit

Permalink
fix regression - Stopping verify/save can abort()
Browse files Browse the repository at this point in the history
  • Loading branch information
gurnec committed Aug 26, 2016
1 parent c77a856 commit 3c6693a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
18 changes: 12 additions & 6 deletions HashSave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ VOID __fastcall HashSaveWorkerMain( PHASHSAVECONTEXT phsctx )
dwStarted = GetTickCount();
#endif

class CanceledException {};

// concurrency::parallel_for_each(vecpItems.cbegin(), vecpItems.cend(), ...
auto per_file_worker = [&](PHASHSAVEITEM pItem)
{
Expand All @@ -201,7 +203,7 @@ VOID __fastcall HashSaveWorkerMain( PHASHSAVECONTEXT phsctx )
// Allocate a read buffer (one buffer is cached per worker thread by Alloc/Free)
pbBuffer = (PBYTE)concurrency::Alloc(READ_BUFFER_SIZE);
if (pbBuffer == NULL)
return;
throw CanceledException();
}
#endif

Expand Down Expand Up @@ -229,7 +231,7 @@ VOID __fastcall HashSaveWorkerMain( PHASHSAVECONTEXT phsctx )
if (phsctx->status == PAUSED)
WaitForSingleObject(phsctx->hUnpauseEvent, INFINITE);
if (phsctx->status == CANCEL_REQUESTED)
return;
throw CanceledException();

// Write the data
HashCalcWriteResult(phsctx, pItem);
Expand All @@ -240,12 +242,16 @@ VOID __fastcall HashSaveWorkerMain( PHASHSAVECONTEXT phsctx )
};
#pragma warning(pop)

try
{
#ifdef USE_PPL
if (bMultithreaded)
concurrency::parallel_for_each(vecpItems.cbegin(), vecpItems.cend(), per_file_worker);
else
if (bMultithreaded)
concurrency::parallel_for_each(vecpItems.cbegin(), vecpItems.cend(), per_file_worker);
else
#endif
std::for_each(vecpItems.cbegin(), vecpItems.cend(), per_file_worker);
std::for_each(vecpItems.cbegin(), vecpItems.cend(), per_file_worker);
}
catch (CanceledException) {} // ignore cancellation requests

#ifdef _TIMED
if (phsctx->cTotal > 1 && phsctx->status != CANCEL_REQUESTED)
Expand Down
23 changes: 14 additions & 9 deletions HashVerify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,8 @@ VOID __fastcall HashVerifyWorkerMain( PHASHVERIFYCONTEXT phvctx )
// sound notification of completion when appropriate
phvctx->dwStarted = GetTickCount();

class CanceledException {};

// concurrency::parallel_for_each(phvctx->index, phvctx->index + phvctx->cTotal, ...
auto per_file_worker = [&](PHASHVERIFYITEM pItem)
{
Expand All @@ -543,7 +545,7 @@ VOID __fastcall HashVerifyWorkerMain( PHASHVERIFYCONTEXT phvctx )
// Allocate a read buffer (one buffer is cached per worker thread by Alloc/Free)
pbBuffer = (PBYTE)concurrency::Alloc(READ_BUFFER_SIZE);
if (pbBuffer == NULL)
return;
throw CanceledException();
}
else
#endif
Expand Down Expand Up @@ -594,7 +596,7 @@ VOID __fastcall HashVerifyWorkerMain( PHASHVERIFYCONTEXT phvctx )
if (phvctx->status == PAUSED)
WaitForSingleObject(phvctx->hUnpauseEvent, INFINITE);
if (phvctx->status == CANCEL_REQUESTED)
return;
throw CanceledException();

// Part 3: Do something with the results
if (whres.dwFlags)
Expand Down Expand Up @@ -643,18 +645,21 @@ VOID __fastcall HashVerifyWorkerMain( PHASHVERIFYCONTEXT phvctx )
PostMessage(phvctx->hWnd, HM_WORKERTHREAD_UPDATE, (WPARAM)phvctx, (LPARAM)pItem);
};

try
{
#ifdef USE_PPL
if (bMultithreaded)
concurrency::parallel_for_each(phvctx->index, phvctx->index + phvctx->cTotal, per_file_worker);
else
#endif
std::for_each(phvctx->index, phvctx->index + phvctx->cTotal, per_file_worker);
}
catch (CanceledException) {} // ignore cancellation requests

if (bMultithreaded)
{
concurrency::parallel_for_each(phvctx->index, phvctx->index + phvctx->cTotal, per_file_worker);
DeleteCriticalSection(&updateCritSec);
}
else
#endif
{
std::for_each(phvctx->index, phvctx->index + phvctx->cTotal, per_file_worker);
VirtualFree(pbTheBuffer, 0, MEM_RELEASE);
}

// Play a sound to signal the normal, successful termination of operations,
// but exempt operations that were nearly instantaneous
Expand Down
8 changes: 4 additions & 4 deletions installer/HashCheck.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Unicode true

Name "HashCheck"
OutFile "HashCheckSetup-v2.4.0.37-beta.exe"
OutFile "HashCheckSetup-v2.4.0.38-beta.exe"

RequestExecutionLevel admin
ManifestSupportedOS all
Expand Down Expand Up @@ -53,15 +53,15 @@ FunctionEnd
!insertmacro MUI_LANGUAGE "Ukrainian"
!insertmacro MUI_LANGUAGE "Catalan"

VIProductVersion "2.4.0.37-beta"
VIProductVersion "2.4.0.38-beta"
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "HashCheck Shell Extension"
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductVersion" "2.4.0.37-beta"
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductVersion" "2.4.0.38-beta"
VIAddVersionKey /LANG=${LANG_ENGLISH} "Comments" "Installer distributed from https://github.com/gurnec/HashCheck/releases"
VIAddVersionKey /LANG=${LANG_ENGLISH} "CompanyName" ""
VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalTrademarks" ""
VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "Copyright © Kai Liu, Christopher Gurnee, Tim Schlueter, et al. All rights reserved."
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "Installer (x86/x64) from https://github.com/gurnec/HashCheck/releases"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "2.4.0.37-beta"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "2.4.0.38-beta"

; With solid compression, files that are required before the
; actual installation should be stored first in the data block,
Expand Down
4 changes: 2 additions & 2 deletions version.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#define HASHCHECK_NAME_STR "HashCheck Shell Extension"

// Full version: MUST be in the form of major,minor,revision,build
#define HASHCHECK_VERSION_FULL 2,4,0,37
#define HASHCHECK_VERSION_FULL 2,4,0,38

// String version: May be any suitable string
#define HASHCHECK_VERSION_STR "2.4.0.37-beta"
#define HASHCHECK_VERSION_STR "2.4.0.38-beta"

#ifdef _USRDLL
// PE version: MUST be in the form of major.minor
Expand Down

0 comments on commit 3c6693a

Please sign in to comment.