3030// added drop handler for copy/move items to target folder
3131// Version 1.8.1 (c) 2023 thomas694
3232// fixed deleting empty subfolders
33+ // Version 1.8.2 (c) 2024 thomas694
34+ // fixed copy/move files progress dialog
3335//
3436// DFTContextMenuHandler is free software: you can redistribute it and/or modify
3537// it under the terms of the GNU General Public License as published by
@@ -140,7 +142,7 @@ STDMETHODIMP CCmdLineContextMenu::QueryContextMenu(HMENU hmenu,
140142 InsertMenu (hPopup, 6 , MF_BYPOSITION, uID++, _T (" Remove group names (...-name.mp3)" ));
141143 InsertMenu (hPopup, 7 , MF_BYPOSITION, uID++, _T (" Rename extension..." ));
142144 InsertMenu (hPopup, 8 , MF_BYPOSITION, uID++, _T (" Append extension (.mp -> .mp3)..." ));
143- InsertMenu (hPopup, 9 , MF_BYPOSITION, uID++, _T (" Remove n chars from filename..." ));
145+ InsertMenu (hPopup, 9 , MF_BYPOSITION, uID++, _T (" Remove n characters from filename..." ));
144146 InsertMenu (hPopup, 10 , MF_BYPOSITION, uID++, _T (" Set file date/time..." ));
145147 InsertMenu (hPopup, 11 , MF_BYPOSITION, uID++, _T (" Append to filename..." ));
146148 InsertMenu (hPopup, 12 , MF_BYPOSITION, uID++, _T (" Insert before filename..." ));
@@ -418,7 +420,7 @@ STDMETHODIMP CCmdLineContextMenu::GetCommandString(UINT_PTR idCmd,
418420 hr = S_OK;
419421 break ;
420422 case 8 :
421- wcsncpy ((LPWSTR)pszName, OLESTR (" Remove n chars from filename" ), cchMax);
423+ wcsncpy ((LPWSTR)pszName, OLESTR (" Remove n characters from filename" ), cchMax);
422424 ((LPWSTR)pszName)[cchMax - 1 ] = OLESTR (' \0 ' );
423425 hr = S_OK;
424426 break ;
@@ -513,7 +515,7 @@ STDMETHODIMP CCmdLineContextMenu::GetCommandString(UINT_PTR idCmd,
513515 hr = S_OK;
514516 break ;
515517 case 8 :
516- strncpy ((LPSTR)pszName, " Remove n chars from filename" , cchMax);
518+ strncpy ((LPSTR)pszName, " Remove n characters from filename" , cchMax);
517519 ((LPSTR)pszName)[cchMax - 1 ] = ' \0 ' ;
518520 hr = S_OK;
519521 break ;
@@ -1055,7 +1057,7 @@ int CCmdLineContextMenu::RemoveFromFilename()
10551057 bAsked = true ;
10561058 // get new extension
10571059 string sText = _T (" 0" );
1058- string sTitle = _T (" Remove n chars (-n from start)" );
1060+ string sTitle = _T (" Remove n characters (-n from start)" );
10591061 CCmdLinePromptDlg dlg (sText , sTitle , false );
10601062 if (dlg.DoModal () == IDOK) {
10611063 lHowManyCharacters = _ttol (dlg.strExtension .data ());
@@ -1679,52 +1681,73 @@ int CCmdLineContextMenu::EmptyFiles()
16791681 return 1 ;
16801682}
16811683
1684+ void DoWork ()
1685+ {
1686+ MSG msg;
1687+ if (PeekMessage (&msg, NULL , 0 , 0 , 1 )) {
1688+ TranslateMessage (&msg);
1689+ DispatchMessageW (&msg);
1690+ }
1691+ }
1692+
16821693int CCmdLineContextMenu::CopyFilesHere ()
16831694{
1684- size_t lFiles;
1685- lFiles = m_strFilenames.size ();
1695+ size_t lTotalItems, lFiles;
1696+ lTotalItems = lFiles = m_strFilenames.size ();
1697+ size_t lDoneItems = 0 ;
16861698
16871699 IProgressDialog* pProgressDlg;
16881700 HRESULT hr = CoCreateInstance (CLSID_ProgressDialog, NULL , CLSCTX_INPROC_SERVER, IID_PPV_ARGS (&pProgressDlg));
16891701 if (FAILED (hr)) pProgressDlg = NULL ;
16901702 if (pProgressDlg != NULL ) {
16911703 pProgressDlg->SetTitle (_T (" Copying items..." ));
1692- pProgressDlg->StartProgressDialog (::GetActiveWindow (), NULL , PROGDLG_AUTOTIME, NULL );
1693- pProgressDlg->SetProgress (0 , lFiles);
1704+ pProgressDlg->StartProgressDialog (::GetActiveWindow (), NULL , PROGDLG_AUTOTIME | PROGDLG_NOMINIMIZE, NULL );
1705+ pProgressDlg->SetProgress (lDoneItems, lTotalItems);
1706+ DoWork ();
16941707 }
16951708
16961709 int i;
16971710 for (i = 0 ; i < lFiles; i++) {
1698- if (pProgressDlg->HasUserCancelled ())
1699- break ;
1700- if (pProgressDlg != NULL ) pProgressDlg->SetProgress (i + 1 , lFiles);
1701-
17021711 // split into components
17031712 TCHAR sDrive [_MAX_DRIVE];
17041713 TCHAR sDir [MAX_PATH_EX];
17051714 TCHAR sName [_MAX_FNAME];
17061715 TCHAR sExt [_MAX_EXT];
17071716 _tsplitpath (m_strFilenames[i].data (), sDrive , sDir , sName , sExt );
17081717
1718+ if (pProgressDlg != NULL ) {
1719+ if (pProgressDlg->HasUserCancelled ())
1720+ break ;
1721+ lDoneItems++;
1722+ pProgressDlg->SetProgress (lDoneItems, lTotalItems);
1723+ DoWork ();
1724+ string sItem = _T (" " );
1725+ sItem .append (sName ).append (sExt );
1726+ pProgressDlg->SetLine (2 , sItem .data (), true , NULL );
1727+ }
1728+
17091729 string sNewFilename = _T (" " );
17101730 sNewFilename .append (m_szFolderDroppedIn).append (_T (" \\ " )).append (sName ).append (sExt );
17111731 if (sNewFilename .rfind (_T (" \\\\ ?\\ " ), 0 ) != 0 )
17121732 sNewFilename = _T (" \\\\ ?\\ " ) + sNewFilename ;
17131733
17141734 if (PathIsDirectory (m_strFilenames[i].data ())) {
1715- CopyDirectory (m_strFilenames[i].data (), sNewFilename );
1735+ CopyDirectory (m_strFilenames[i].data (), sNewFilename , pProgressDlg, &lDoneItems, &lTotalItems );
17161736
17171737 } else {
17181738 bool ret = CopyFile (m_strFilenames[i].data (), sNewFilename .c_str (), true );
17191739 }
17201740 }
17211741
1722- if (pProgressDlg != NULL ) pProgressDlg->StopProgressDialog ();
1723-
1742+ if (pProgressDlg != NULL ) {
1743+ pProgressDlg->StopProgressDialog ();
1744+ pProgressDlg->Release ();
1745+ }
1746+
17241747 return 1 ;
17251748}
17261749
1727- int CCmdLineContextMenu::CopyDirectory (string sourceDir, string destDir)
1750+ int CCmdLineContextMenu::CopyDirectory (string sourceDir, string destDir, IProgressDialog* pProgressDlg, size_t * currentItems, size_t * totalItems )
17281751{
17291752 string strSource;
17301753 string strDest;
@@ -1736,6 +1759,23 @@ int CCmdLineContextMenu::CopyDirectory(string sourceDir, string destDir)
17361759 return ::GetLastError ();
17371760
17381761 string searchFolder = sourceDir + _T (" \\ *" );
1762+
1763+ if (pProgressDlg != NULL ) {
1764+ hFind = ::FindFirstFile (searchFolder.c_str (), &fd);
1765+ if (hFind != INVALID_HANDLE_VALUE)
1766+ {
1767+ do
1768+ {
1769+ if (_tcscmp (fd.cFileName , _T (" ." )) == 0 || _tcscmp (fd.cFileName , _T (" .." )) == 0 ) { continue ; }
1770+ (*totalItems)++;
1771+ } while (!pProgressDlg->HasUserCancelled () && ::FindNextFile (hFind, &fd) == TRUE );
1772+ ::FindClose (hFind);
1773+ hFind = NULL ;
1774+ }
1775+ if (pProgressDlg->HasUserCancelled ())
1776+ return -1 ;
1777+ }
1778+
17391779 hFind = ::FindFirstFile (searchFolder.c_str (), &fd);
17401780 if (hFind != INVALID_HANDLE_VALUE)
17411781 {
@@ -1752,11 +1792,20 @@ int CCmdLineContextMenu::CopyDirectory(string sourceDir, string destDir)
17521792 if (strDest.rfind (_T (" \\\\ ?\\ " ), 0 ) != 0 )
17531793 strDest = _T (" \\\\ ?\\ " ) + strDest;
17541794
1795+ (*currentItems)++;
1796+ if (pProgressDlg != NULL ) {
1797+ if (pProgressDlg->HasUserCancelled ())
1798+ break ;
1799+ pProgressDlg->SetProgress (*currentItems, *totalItems);
1800+ DoWork ();
1801+ }
1802+
17551803 if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
17561804 {
17571805 // Copy subdirectory
1758- if (CopyDirectory (strSource, strDest))
1759- return 0 ;
1806+ int ret = CopyDirectory (strSource, strDest, pProgressDlg, currentItems, totalItems);
1807+ if (ret < 0 )
1808+ return ret;
17601809 }
17611810 else
17621811 {
@@ -1768,6 +1817,9 @@ int CCmdLineContextMenu::CopyDirectory(string sourceDir, string destDir)
17681817
17691818 ::FindClose (hFind);
17701819
1820+ if (pProgressDlg != NULL && pProgressDlg->HasUserCancelled ())
1821+ return -1 ;
1822+
17711823 DWORD dwError = ::GetLastError ();
17721824 if (dwError != ERROR_NO_MORE_FILES)
17731825 return dwError;
@@ -1786,23 +1838,30 @@ int CCmdLineContextMenu::MoveFilesHere()
17861838 if (FAILED (hr)) pProgressDlg = NULL ;
17871839 if (pProgressDlg != NULL ) {
17881840 pProgressDlg->SetTitle (_T (" Moving items..." ));
1789- pProgressDlg->StartProgressDialog (::GetActiveWindow (), NULL , PROGDLG_AUTOTIME, NULL );
1841+ pProgressDlg->StartProgressDialog (::GetActiveWindow (), NULL , PROGDLG_AUTOTIME | PROGDLG_NOMINIMIZE , NULL );
17901842 pProgressDlg->SetProgress (0 , lFiles);
1843+ DoWork ();
17911844 }
17921845
17931846 int i;
17941847 for (i = 0 ; i < lFiles; i++) {
1795- if (pProgressDlg->HasUserCancelled ())
1796- break ;
1797- if (pProgressDlg != NULL ) pProgressDlg->SetProgress (i + 1 , lFiles);
1798-
17991848 // split into components
18001849 TCHAR sDrive [_MAX_DRIVE];
18011850 TCHAR sDir [MAX_PATH_EX];
18021851 TCHAR sName [_MAX_FNAME];
18031852 TCHAR sExt [_MAX_EXT];
18041853 _tsplitpath (m_strFilenames[i].data (), sDrive , sDir , sName , sExt );
18051854
1855+ if (pProgressDlg != NULL ) {
1856+ if (pProgressDlg->HasUserCancelled ())
1857+ break ;
1858+ pProgressDlg->SetProgress (i + 1 , lFiles);
1859+ DoWork ();
1860+ string sItem = _T (" " );
1861+ sItem .append (sName ).append (sExt );
1862+ pProgressDlg->SetLine (2 , sItem .data (), true , NULL );
1863+ }
1864+
18061865 string sNewFilename = _T (" " );
18071866 sNewFilename .append (m_szFolderDroppedIn).append (_T (" \\ " )).append (sName ).append (sExt );
18081867 if (sNewFilename .rfind (_T (" \\\\ ?\\ " ), 0 ) != 0 )
@@ -1811,7 +1870,10 @@ int CCmdLineContextMenu::MoveFilesHere()
18111870 bool ret = MoveFile (m_strFilenames[i].data (), sNewFilename .c_str ());
18121871 }
18131872
1814- if (pProgressDlg != NULL ) pProgressDlg->StopProgressDialog ();
1873+ if (pProgressDlg != NULL ) {
1874+ pProgressDlg->StopProgressDialog ();
1875+ pProgressDlg->Release ();
1876+ }
18151877
18161878 return 1 ;
18171879}
0 commit comments