#define FO_MASK 0xF
+#define NEW_FILENAME_ON_COPY_TRIES 100
+
static const WCHAR wWildcardFile[] = {'*',0};
static const WCHAR wWildcardChars[] = {'*','?',0};
HeapFree(GetProcessHeap(), 0, flList->feFiles);
}
+static CStringW try_find_new_name(LPCWSTR szDestPath)
+{
+ CStringW mask(szDestPath);
+ CStringW ext(PathFindExtensionW(szDestPath));
+
+ // cut off extension before inserting a "new file" mask
+ if (!ext.IsEmpty())
+ {
+ mask = mask.Left(mask.GetLength() - ext.GetLength());
+ }
+ mask += L" (%d)" + ext;
+
+ CStringW newName;
+
+ // trying to find new file name
+ for (int i = 1; i < NEW_FILENAME_ON_COPY_TRIES; i++)
+ {
+ newName.Format(mask, i);
+
+ if (!PathFileExistsW(newName))
+ {
+ return newName;
+ }
+ }
+
+ return CStringW();
+}
+
static void copy_dir_to_dir(FILE_OPERATION *op, const FILE_ENTRY *feFrom, LPCWSTR szDestPath)
{
WCHAR szFrom[MAX_PATH], szTo[MAX_PATH];
if (!(op->req->fFlags & FOF_NOCONFIRMATION) && PathFileExistsW(szTo))
{
- if (!SHELL_ConfirmDialogW(op->req->hwnd, ASK_OVERWRITE_FOLDER, feFrom->szFilename, op))
+ CStringW newPath;
+ if (lstrcmp(feFrom->szDirectory, szDestPath) == 0 && !(newPath = try_find_new_name(szTo)).IsEmpty())
{
- /* Vista returns an ERROR_CANCELLED even if user pressed "No" */
- if (!op->bManyItems)
- op->bCancelled = TRUE;
- return;
+ StringCchCopyW(szTo, _countof(szTo), newPath);
+ }
+ else
+ {
+ if (!SHELL_ConfirmDialogW(op->req->hwnd, ASK_OVERWRITE_FOLDER, feFrom->szFilename, op))
+ {
+ /* Vista returns an ERROR_CANCELLED even if user pressed "No" */
+ if (!op->bManyItems)
+ op->bCancelled = TRUE;
+ return;
+ }
}
}
{
if (!(op->req->fFlags & FOF_NOCONFIRMATION) && PathFileExistsW(szTo))
{
+ CStringW newPath;
+ if (lstrcmp(szFrom, szTo) == 0 && !(newPath = try_find_new_name(szTo)).IsEmpty())
+ {
+ return SHNotifyCopyFileW(op, szFrom, newPath, FALSE) == 0;
+ }
+
if (!SHELL_ConfirmDialogW(op->req->hwnd, ASK_OVERWRITE_FILE, PathFindFileNameW(szTo), op))
return FALSE;
}