Skip to content

Commit

Permalink
Fix Copy/move files progress dialog (better)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas694 committed Feb 26, 2024
1 parent 455ae81 commit 9ede5d7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/CmdLineContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include <time.h>
#include <iostream>
#include <ShObjIdl_core.h>
#include <future>

#pragma warning(disable : 4996)

Expand Down Expand Up @@ -329,10 +330,10 @@ STDMETHODIMP CCmdLineContextMenu::InvokeCommand(LPCMINVOKECOMMANDINFO lpici)
break;

case 31:
CopyFilesHere();
StartCopyFilesHere();
break;
case 32:
MoveFilesHere();
StartMoveFilesHere();
break;

/*
Expand Down Expand Up @@ -1681,6 +1682,26 @@ int CCmdLineContextMenu::EmptyFiles()
return 1;
}

int CCmdLineContextMenu::StartCopyFilesHere()
{
std::packaged_task<int()> task([&]() {
return CopyFilesHere();
});
std::future<int> res = task.get_future();
std::thread(std::move(task)).detach();
res.wait_for(1s);
}

int CCmdLineContextMenu::StartMoveFilesHere()
{
std::packaged_task<int()> task([&]() {
return MoveFilesHere();
});
std::future<int> res = task.get_future();
std::thread(std::move(task)).detach();
res.wait_for(1s);
}

void DoWork()
{
MSG msg;
Expand All @@ -1701,7 +1722,7 @@ int CCmdLineContextMenu::CopyFilesHere()
if (FAILED(hr)) pProgressDlg = NULL;
if (pProgressDlg != NULL) {
pProgressDlg->SetTitle(_T("Copying items..."));
pProgressDlg->StartProgressDialog(::GetActiveWindow(), NULL, PROGDLG_AUTOTIME | PROGDLG_NOMINIMIZE, NULL);
pProgressDlg->StartProgressDialog(NULL, NULL, PROGDLG_AUTOTIME, NULL);
pProgressDlg->SetProgress(lDoneItems, lTotalItems);
DoWork();
}
Expand Down Expand Up @@ -1838,7 +1859,7 @@ int CCmdLineContextMenu::MoveFilesHere()
if (FAILED(hr)) pProgressDlg = NULL;
if (pProgressDlg != NULL) {
pProgressDlg->SetTitle(_T("Moving items..."));
pProgressDlg->StartProgressDialog(::GetActiveWindow(), NULL, PROGDLG_AUTOTIME | PROGDLG_NOMINIMIZE, NULL);
pProgressDlg->StartProgressDialog(NULL, NULL, PROGDLG_AUTOTIME, NULL);
pProgressDlg->SetProgress(0, lFiles);
DoWork();
}
Expand Down
2 changes: 2 additions & 0 deletions src/CmdLineContextMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ END_COM_MAP()
int EditFilename();
int CopyFilesHere();
int MoveFilesHere();
int StartCopyFilesHere();
int StartMoveFilesHere();

typedef std::basic_string<_TCHAR> string;
string m_strFileName;
Expand Down
Binary file modified src/CmdLineExt.rc
Binary file not shown.

0 comments on commit 9ede5d7

Please sign in to comment.