Skip to content

Commit

Permalink
Merge pull request #102 from ansani/85-shareaza-systematically-overwr…
Browse files Browse the repository at this point in the history
…ites-a-file-if-a-file-with-the-same-name-is-received-in-the-same-folder

85 shareaza systematically overwrites a file if a file with the same name is received in the same folder
  • Loading branch information
ansani authored Dec 29, 2022
2 parents 57af11f + d8a68e5 commit bfdf0a2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions shareaza/FragmentedFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,21 @@ DWORD CFragmentedFile::Move(DWORD nIndex, LPCTSTR pszDestination, LPPROGRESS_ROU
strTarget.Format( _T("%s\\%s_%u"), pszDestination, sName, index );
}

// Check if the target file exists
// Try to get the file attributes
WIN32_FILE_ATTRIBUTE_DATA fileAttr;
if (GetFileAttributesEx(strTarget, GetFileExInfoStandard, &fileAttr))
{
// The file exists
CString fileExtension = strTarget.Right(strTarget.GetLength() - strTarget.ReverseFind(_T('.')));
CString fileName = strTarget.Left(strTarget.ReverseFind(_T('.')));
CString currentTimestamp = CTime::GetCurrentTime().Format(_T("%Y%m%d%H%M%S"));
CString newFileName = fileName + _T(" (") + currentTimestamp + _T(")") + fileExtension;
theApp.Message(MSG_DEBUG, _T("File \"%s\" already exists in the destination folder, renaming it to %s"),
(LPCTSTR)strTarget, (LPCTSTR)newFileName);
strTarget = newFileName;
}

// Move/copy file using very long filenames
bSuccess = MoveFileWithProgress( CString( _T("\\\\?\\") ) + sPath,
CString( _T("\\\\?\\") ) + strTarget, lpProgressRoutine, pTask,
Expand Down

0 comments on commit bfdf0a2

Please sign in to comment.