From 5d2bb16e92ee8ba88660f2fdd47d479033f47cfb Mon Sep 17 00:00:00 2001 From: Christian Gaarden Gaardmark Date: Mon, 21 Oct 2024 03:51:14 -0700 Subject: [PATCH] [New+]When new folder name collides, create copy instead of creating inside existing (#35464) * Fixed target folder path when source is a folder --- .../NewShellExtensionContextMenu/new_utilities.h | 6 ++++++ .../shell_context_sub_menu_item.cpp | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/modules/NewPlus/NewShellExtensionContextMenu/new_utilities.h b/src/modules/NewPlus/NewShellExtensionContextMenu/new_utilities.h index 55bafb8b56..7ae46635a8 100644 --- a/src/modules/NewPlus/NewShellExtensionContextMenu/new_utilities.h +++ b/src/modules/NewPlus/NewShellExtensionContextMenu/new_utilities.h @@ -50,6 +50,12 @@ namespace newplus::utilities return false; } + inline bool is_directory(const std::filesystem::path path) + { + const auto entry = std::filesystem::directory_entry(path); + return entry.is_directory(); + } + inline bool wstring_same_when_comparing_ignore_case(std::wstring stringA, std::wstring stringB) { transform(stringA.begin(), stringA.end(), stringA.begin(), towupper); diff --git a/src/modules/NewPlus/NewShellExtensionContextMenu/shell_context_sub_menu_item.cpp b/src/modules/NewPlus/NewShellExtensionContextMenu/shell_context_sub_menu_item.cpp index bdae885009..99378f468a 100644 --- a/src/modules/NewPlus/NewShellExtensionContextMenu/shell_context_sub_menu_item.cpp +++ b/src/modules/NewPlus/NewShellExtensionContextMenu/shell_context_sub_menu_item.cpp @@ -70,9 +70,13 @@ IFACEMETHODIMP shell_context_sub_menu_item::Invoke(_In_opt_ IShellItemArray*, _I // Determine initial filename std::filesystem::path source_fullpath = template_entry->path; - std::filesystem::path target_fullpath = std::wstring(target_path_name) - + L"\\" - + this->template_entry->get_target_filename(!utilities::get_newplus_setting_hide_starting_digits()); + std::filesystem::path target_fullpath = std::wstring(target_path_name); + + // Only append name to target if source is not a directory + if (!utilities::is_directory(target_fullpath)) + { + target_fullpath.append(this->template_entry->get_target_filename(!utilities::get_newplus_setting_hide_starting_digits())); + } // Copy file and determine final filename std::filesystem::path target_final_fullpath = this->template_entry->copy_object_to(GetActiveWindow(), target_fullpath);