Skip to content

Commit 7bfd86b

Browse files
committed
Fix Problem moving items across volumes
1 parent c6d7ff2 commit 7bfd86b

4 files changed

Lines changed: 71 additions & 2 deletions

File tree

src/CmdLineContextMenu.cpp

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
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+
18561887
int 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) {

src/CmdLineContextMenu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ END_COM_MAP()
9191
StringArray GetSubfolders(string folder);
9292
bool IsEmptyDirectory(string folder);
9393
int CopyDirectory(string sourceDir, string destDir, IProgressDialog* pProgressDlg, size_t* currentFiles, size_t* totalFiles);
94+
BOOL RemoveDirectory(string strDir);
9495

9596
string m_strBaseFolder;
9697
StringArray m_lstFolders;

src/CmdLineExt.rc

-18 Bytes
Binary file not shown.

src/app.manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
22
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
3-
<assemblyIdentity type='win32' name='DFTContextMenuHandler' version='1.8.2.0' processorArchitecture="amd64" />
3+
<assemblyIdentity type='win32' name='DFTContextMenuHandler' version='1.8.3.0' processorArchitecture="amd64" />
44
<asmv3:application>
55
<asmv3:windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
66
<ws2:longPathAware>true</ws2:longPathAware>

0 commit comments

Comments
 (0)