Skip to content

Commit 9ede5d7

Browse files
committed
Fix Copy/move files progress dialog (better)
1 parent 455ae81 commit 9ede5d7

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

src/CmdLineContextMenu.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include <time.h>
6161
#include <iostream>
6262
#include <ShObjIdl_core.h>
63+
#include <future>
6364

6465
#pragma warning(disable : 4996)
6566

@@ -329,10 +330,10 @@ STDMETHODIMP CCmdLineContextMenu::InvokeCommand(LPCMINVOKECOMMANDINFO lpici)
329330
break;
330331

331332
case 31:
332-
CopyFilesHere();
333+
StartCopyFilesHere();
333334
break;
334335
case 32:
335-
MoveFilesHere();
336+
StartMoveFilesHere();
336337
break;
337338

338339
/*
@@ -1681,6 +1682,26 @@ int CCmdLineContextMenu::EmptyFiles()
16811682
return 1;
16821683
}
16831684

1685+
int CCmdLineContextMenu::StartCopyFilesHere()
1686+
{
1687+
std::packaged_task<int()> task([&]() {
1688+
return CopyFilesHere();
1689+
});
1690+
std::future<int> res = task.get_future();
1691+
std::thread(std::move(task)).detach();
1692+
res.wait_for(1s);
1693+
}
1694+
1695+
int CCmdLineContextMenu::StartMoveFilesHere()
1696+
{
1697+
std::packaged_task<int()> task([&]() {
1698+
return MoveFilesHere();
1699+
});
1700+
std::future<int> res = task.get_future();
1701+
std::thread(std::move(task)).detach();
1702+
res.wait_for(1s);
1703+
}
1704+
16841705
void DoWork()
16851706
{
16861707
MSG msg;
@@ -1701,7 +1722,7 @@ int CCmdLineContextMenu::CopyFilesHere()
17011722
if (FAILED(hr)) pProgressDlg = NULL;
17021723
if (pProgressDlg != NULL) {
17031724
pProgressDlg->SetTitle(_T("Copying items..."));
1704-
pProgressDlg->StartProgressDialog(::GetActiveWindow(), NULL, PROGDLG_AUTOTIME | PROGDLG_NOMINIMIZE, NULL);
1725+
pProgressDlg->StartProgressDialog(NULL, NULL, PROGDLG_AUTOTIME, NULL);
17051726
pProgressDlg->SetProgress(lDoneItems, lTotalItems);
17061727
DoWork();
17071728
}
@@ -1838,7 +1859,7 @@ int CCmdLineContextMenu::MoveFilesHere()
18381859
if (FAILED(hr)) pProgressDlg = NULL;
18391860
if (pProgressDlg != NULL) {
18401861
pProgressDlg->SetTitle(_T("Moving items..."));
1841-
pProgressDlg->StartProgressDialog(::GetActiveWindow(), NULL, PROGDLG_AUTOTIME | PROGDLG_NOMINIMIZE, NULL);
1862+
pProgressDlg->StartProgressDialog(NULL, NULL, PROGDLG_AUTOTIME, NULL);
18421863
pProgressDlg->SetProgress(0, lFiles);
18431864
DoWork();
18441865
}

src/CmdLineContextMenu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ END_COM_MAP()
7575
int EditFilename();
7676
int CopyFilesHere();
7777
int MoveFilesHere();
78+
int StartCopyFilesHere();
79+
int StartMoveFilesHere();
7880

7981
typedef std::basic_string<_TCHAR> string;
8082
string m_strFileName;

src/CmdLineExt.rc

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)