3232// fixed deleting empty subfolders
3333// Version 1.8.2 (c) 2024 thomas694
3434// fixed copy/move files progress dialog
35+ // Version 1.8.3 (c) 2024 thomas694
36+ // fixed problem moving items across volumes
3537//
3638// DFTContextMenuHandler is free software: you can redistribute it and/or modify
3739// it under the terms of the GNU General Public License as published by
@@ -1853,6 +1855,35 @@ int CCmdLineContextMenu::CopyDirectory(string sourceDir, string destDir, IProgre
18531855 return 0 ;
18541856}
18551857
1858+ BOOL CCmdLineContextMenu::RemoveDirectory (string strDirectory)
1859+ {
1860+ WIN32_FIND_DATA fdFile = {};
1861+
1862+ string strSearchItems = strDirectory + _T (" \\ *.*" );
1863+ HANDLE hFind = ::FindFirstFile (strSearchItems.c_str (), &fdFile);
1864+ if (hFind == INVALID_HANDLE_VALUE) {
1865+ return FALSE ;
1866+ }
1867+
1868+ do {
1869+ string strDelete = strDirectory + _T (" \\ " ) + fdFile.cFileName ;
1870+
1871+ if ((fdFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 ) {
1872+ if (_tcscmp (fdFile.cFileName , _T (" ." )) == 0 || _tcscmp (fdFile.cFileName , _T (" .." )) == 0 )
1873+ continue ;
1874+ CCmdLineContextMenu::RemoveDirectory (strDelete);
1875+ }
1876+ else {
1877+ ::DeleteFile (strDelete.c_str());
1878+ }
1879+ } while (::FindNextFile (hFind, &fdFile) == TRUE );
1880+
1881+ ::FindClose (hFind);
1882+ ::RemoveDirectory (strDirectory.c_str());
1883+
1884+ return TRUE ;
1885+ }
1886+
18561887int CCmdLineContextMenu::MoveFilesHere (StringArray strFilenames, string szFolderDroppedIn)
18571888{
18581889 size_t lFiles;
@@ -1868,6 +1899,19 @@ int CCmdLineContextMenu::MoveFilesHere(StringArray strFilenames, string szFolder
18681899 DoWork ();
18691900 }
18701901
1902+ bool isSameVolume = true ;
1903+ if (lFiles > 0 ) {
1904+ HANDLE hFile = CreateFile (strFilenames[0 ].c_str (), GENERIC_READ, FILE_SHARE_READ, NULL , OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
1905+ BY_HANDLE_FILE_INFORMATION fileInfo = {};
1906+ BOOL ret = GetFileInformationByHandle (hFile, &fileInfo);
1907+ HANDLE hFile2 = CreateFile (szFolderDroppedIn.c_str (), GENERIC_READ, FILE_SHARE_READ, NULL , OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
1908+ BY_HANDLE_FILE_INFORMATION fileInfo2 = {};
1909+ ret = GetFileInformationByHandle (hFile2, &fileInfo2);
1910+ isSameVolume = fileInfo.dwVolumeSerialNumber == fileInfo2.dwVolumeSerialNumber ;
1911+ CloseHandle (hFile);
1912+ CloseHandle (hFile2);
1913+ }
1914+
18711915 int i;
18721916 for (i = 0 ; i < lFiles; i++) {
18731917 // split into components
@@ -1887,12 +1931,36 @@ int CCmdLineContextMenu::MoveFilesHere(StringArray strFilenames, string szFolder
18871931 pProgressDlg->SetLine (2 , sItem .data (), true , NULL );
18881932 }
18891933
1934+ string sOldFilename = strFilenames[i].data ();
1935+ if (sOldFilename .rfind (_T (" \\\\ ?\\ " ), 0 ) != 0 )
1936+ sOldFilename = _T (" \\\\ ?\\ " ) + sOldFilename ;
18901937 string sNewFilename = _T (" " );
18911938 sNewFilename .append (szFolderDroppedIn).append (_T (" \\ " )).append (sName ).append (sExt );
18921939 if (sNewFilename .rfind (_T (" \\\\ ?\\ " ), 0 ) != 0 )
18931940 sNewFilename = _T (" \\\\ ?\\ " ) + sNewFilename ;
18941941
1895- bool ret = MoveFile (m_strFilenames[i].data (), sNewFilename .c_str ());
1942+ bool ret;
1943+ if (isSameVolume) {
1944+ ret = MoveFile (sOldFilename .c_str (), sNewFilename .c_str ());
1945+ if (!ret)
1946+ break ;
1947+ /*
1948+ if (ret == false) {
1949+ DWORD error = ::GetLastError();
1950+ std::string sMessage = std::system_category().message(error);
1951+ string message = string(sMessage.begin(), sMessage.end());
1952+ MessageBox(NULL, message.c_str(), _T("Error"), 0);
1953+ }
1954+ */
1955+ }
1956+ else {
1957+ size_t dummy;
1958+ int result = CopyDirectory (sOldFilename , sNewFilename , NULL , &dummy, &dummy);
1959+ if (result == 0 )
1960+ CCmdLineContextMenu::RemoveDirectory (sOldFilename .c_str ());
1961+ else
1962+ break ;
1963+ }
18961964 }
18971965
18981966 if (pProgressDlg != NULL ) {
0 commit comments