PowerToys/src/modules/powerrename/lib/PowerRenameItem.cpp

350 lines
9.3 KiB
C++
Raw Normal View History

#include "pch.h"
#include "PowerRenameItem.h"
int CPowerRenameItem::s_id = 0;
IFACEMETHODIMP_(ULONG)
CPowerRenameItem::AddRef()
{
return InterlockedIncrement(&m_refCount);
}
IFACEMETHODIMP_(ULONG)
CPowerRenameItem::Release()
{
long refCount = InterlockedDecrement(&m_refCount);
if (refCount == 0)
{
delete this;
}
return refCount;
}
IFACEMETHODIMP CPowerRenameItem::QueryInterface(_In_ REFIID riid, _Outptr_ void** ppv)
{
static const QITAB qit[] = {
QITABENT(CPowerRenameItem, IPowerRenameItem),
QITABENT(CPowerRenameItem, IPowerRenameItemFactory),
{ 0 }
};
return QISearch(this, qit, riid, ppv);
}
IFACEMETHODIMP CPowerRenameItem::PutPath(_In_opt_ PCWSTR newPath)
{
CSRWSharedAutoLock lock(&m_lock);
CoTaskMemFree(m_path);
m_path = nullptr;
HRESULT hr = S_OK;
if (newPath != nullptr)
{
hr = SHStrDup(newPath, &m_path);
}
return hr;
}
IFACEMETHODIMP CPowerRenameItem::GetPath(_Outptr_ PWSTR* path)
{
*path = nullptr;
CSRWSharedAutoLock lock(&m_lock);
HRESULT hr = E_FAIL;
if (m_path)
{
hr = SHStrDup(m_path, path);
}
return hr;
}
[PowerRename] Add ModificationTime and AccessTime support when renaming with $YY-$MM-$DD patterns (#39653) <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request 1. Add new configuration to control this behaviour. By default, set to creation time to align with previous version 2. Add UI in PowerRename's MainWindow 3. Implement the logic ![image](https://github.com/user-attachments/assets/fde6731b-73f9-453f-8b68-6ce66589f44a) Original discussion here: https://github.com/microsoft/PowerToys/pull/38186 <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] **Closes:** #36040 - [x] **Communication:** I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [x] **Localization:** All end user facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed --------- Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com> Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
2025-05-30 13:07:20 +08:00
IFACEMETHODIMP CPowerRenameItem::GetTime(_In_ DWORD flags, _Outptr_ SYSTEMTIME* time)
{
CSRWSharedAutoLock lock(&m_lock);
HRESULT hr = E_FAIL;
[PowerRename] Add ModificationTime and AccessTime support when renaming with $YY-$MM-$DD patterns (#39653) <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request 1. Add new configuration to control this behaviour. By default, set to creation time to align with previous version 2. Add UI in PowerRename's MainWindow 3. Implement the logic ![image](https://github.com/user-attachments/assets/fde6731b-73f9-453f-8b68-6ce66589f44a) Original discussion here: https://github.com/microsoft/PowerToys/pull/38186 <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] **Closes:** #36040 - [x] **Communication:** I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [x] **Localization:** All end user facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed --------- Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com> Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
2025-05-30 13:07:20 +08:00
PowerRenameFlags parsedTimeType;
[PowerRename] Add ModificationTime and AccessTime support when renaming with $YY-$MM-$DD patterns (#39653) <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request 1. Add new configuration to control this behaviour. By default, set to creation time to align with previous version 2. Add UI in PowerRename's MainWindow 3. Implement the logic ![image](https://github.com/user-attachments/assets/fde6731b-73f9-453f-8b68-6ce66589f44a) Original discussion here: https://github.com/microsoft/PowerToys/pull/38186 <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] **Closes:** #36040 - [x] **Communication:** I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [x] **Localization:** All end user facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed --------- Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com> Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
2025-05-30 13:07:20 +08:00
// Get Time by PowerRenameFlags
if (flags & PowerRenameFlags::ModificationTime)
{
parsedTimeType = PowerRenameFlags::ModificationTime;
}
else if (flags & PowerRenameFlags::AccessTime)
{
parsedTimeType = PowerRenameFlags::AccessTime;
}
else
{
// Default to modification time if no specific flag is set
parsedTimeType = PowerRenameFlags::CreationTime;
}
if (m_isTimeParsed && parsedTimeType == m_parsedTimeType)
{
hr = S_OK;
}
else
{
HANDLE hFile = CreateFileW(m_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
[PowerRename] Add ModificationTime and AccessTime support when renaming with $YY-$MM-$DD patterns (#39653) <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request 1. Add new configuration to control this behaviour. By default, set to creation time to align with previous version 2. Add UI in PowerRename's MainWindow 3. Implement the logic ![image](https://github.com/user-attachments/assets/fde6731b-73f9-453f-8b68-6ce66589f44a) Original discussion here: https://github.com/microsoft/PowerToys/pull/38186 <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] **Closes:** #36040 - [x] **Communication:** I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [x] **Localization:** All end user facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed --------- Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com> Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
2025-05-30 13:07:20 +08:00
FILETIME FileTime;
bool success = false;
// Get Time by PowerRenameFlags
switch (parsedTimeType)
{
case PowerRenameFlags::CreationTime:
success = GetFileTime(hFile, &FileTime, NULL, NULL);
break;
case PowerRenameFlags::ModificationTime:
success = GetFileTime(hFile, NULL, NULL, &FileTime);
break;
case PowerRenameFlags::AccessTime:
success = GetFileTime(hFile, NULL, &FileTime, NULL);
break;
default:
// Default to modification time if no specific flag is set
success = GetFileTime(hFile, NULL, NULL, &FileTime);
break;
}
if (success)
{
SYSTEMTIME SystemTime, LocalTime;
[PowerRename] Add ModificationTime and AccessTime support when renaming with $YY-$MM-$DD patterns (#39653) <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request 1. Add new configuration to control this behaviour. By default, set to creation time to align with previous version 2. Add UI in PowerRename's MainWindow 3. Implement the logic ![image](https://github.com/user-attachments/assets/fde6731b-73f9-453f-8b68-6ce66589f44a) Original discussion here: https://github.com/microsoft/PowerToys/pull/38186 <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] **Closes:** #36040 - [x] **Communication:** I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [x] **Localization:** All end user facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed --------- Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com> Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
2025-05-30 13:07:20 +08:00
if (FileTimeToSystemTime(&FileTime, &SystemTime))
{
if (SystemTimeToTzSpecificLocalTime(NULL, &SystemTime, &LocalTime))
{
m_time = LocalTime;
m_isTimeParsed = true;
[PowerRename] Add ModificationTime and AccessTime support when renaming with $YY-$MM-$DD patterns (#39653) <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request 1. Add new configuration to control this behaviour. By default, set to creation time to align with previous version 2. Add UI in PowerRename's MainWindow 3. Implement the logic ![image](https://github.com/user-attachments/assets/fde6731b-73f9-453f-8b68-6ce66589f44a) Original discussion here: https://github.com/microsoft/PowerToys/pull/38186 <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] **Closes:** #36040 - [x] **Communication:** I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [x] **Localization:** All end user facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed --------- Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com> Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
2025-05-30 13:07:20 +08:00
m_parsedTimeType = parsedTimeType;
hr = S_OK;
}
}
}
}
[PowerRename] Add ModificationTime and AccessTime support when renaming with $YY-$MM-$DD patterns (#39653) <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request 1. Add new configuration to control this behaviour. By default, set to creation time to align with previous version 2. Add UI in PowerRename's MainWindow 3. Implement the logic ![image](https://github.com/user-attachments/assets/fde6731b-73f9-453f-8b68-6ce66589f44a) Original discussion here: https://github.com/microsoft/PowerToys/pull/38186 <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] **Closes:** #36040 - [x] **Communication:** I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [x] **Localization:** All end user facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed --------- Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com> Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
2025-05-30 13:07:20 +08:00
CloseHandle(hFile);
}
*time = m_time;
return hr;
}
IFACEMETHODIMP CPowerRenameItem::GetShellItem(_Outptr_ IShellItem** ppsi)
{
return SHCreateItemFromParsingName(m_path, nullptr, IID_PPV_ARGS(ppsi));
}
IFACEMETHODIMP CPowerRenameItem::PutOriginalName(_In_opt_ PCWSTR originalName)
{
CSRWSharedAutoLock lock(&m_lock);
CoTaskMemFree(m_originalName);
m_originalName = nullptr;
HRESULT hr = S_OK;
if (originalName != nullptr)
{
hr = SHStrDup(originalName, &m_originalName);
}
return hr;
}
IFACEMETHODIMP CPowerRenameItem::GetOriginalName(_Outptr_ PWSTR* originalName)
{
CSRWSharedAutoLock lock(&m_lock);
HRESULT hr = E_FAIL;
if (m_originalName)
{
hr = SHStrDup(m_originalName, originalName);
}
return hr;
}
IFACEMETHODIMP CPowerRenameItem::PutNewName(_In_opt_ PCWSTR newName)
{
CSRWSharedAutoLock lock(&m_lock);
CoTaskMemFree(m_newName);
m_newName = nullptr;
HRESULT hr = S_OK;
if (newName != nullptr)
{
hr = SHStrDup(newName, &m_newName);
}
return hr;
}
IFACEMETHODIMP CPowerRenameItem::GetNewName(_Outptr_ PWSTR* newName)
{
CSRWSharedAutoLock lock(&m_lock);
HRESULT hr = S_OK;
if (m_newName)
{
hr = SHStrDup(m_newName, newName);
}
return hr;
}
IFACEMETHODIMP CPowerRenameItem::GetIsFolder(_Out_ bool* isFolder)
{
CSRWSharedAutoLock lock(&m_lock);
*isFolder = m_isFolder;
return S_OK;
}
IFACEMETHODIMP CPowerRenameItem::GetIsSubFolderContent(_Out_ bool* isSubFolderContent)
{
CSRWSharedAutoLock lock(&m_lock);
*isSubFolderContent = m_depth > 0;
return S_OK;
}
IFACEMETHODIMP CPowerRenameItem::GetSelected(_Out_ bool* selected)
{
CSRWSharedAutoLock lock(&m_lock);
*selected = m_selected;
return S_OK;
}
IFACEMETHODIMP CPowerRenameItem::PutSelected(_In_ bool selected)
{
CSRWSharedAutoLock lock(&m_lock);
m_selected = selected;
return S_OK;
}
IFACEMETHODIMP CPowerRenameItem::GetId(_Out_ int* id)
{
CSRWSharedAutoLock lock(&m_lock);
*id = m_id;
return S_OK;
}
IFACEMETHODIMP CPowerRenameItem::GetDepth(_Out_ UINT* depth)
{
*depth = m_depth;
return S_OK;
}
IFACEMETHODIMP CPowerRenameItem::PutDepth(_In_ int depth)
{
m_depth = depth;
return S_OK;
}
IFACEMETHODIMP CPowerRenameItem::GetStatus(_Out_ PowerRenameItemRenameStatus* status)
{
*status = m_status;
return S_OK;
}
IFACEMETHODIMP CPowerRenameItem::PutStatus(_In_ PowerRenameItemRenameStatus status)
{
m_status = status;
return S_OK;
}
IFACEMETHODIMP CPowerRenameItem::ShouldRenameItem(_In_ DWORD flags, _Out_ bool* shouldRename)
{
// Should we perform a rename on this item given its
// state and the options that were set?
bool hasChanged = m_newName != nullptr && (lstrcmp(m_originalName, m_newName) != 0) && (lstrcmp(L"", m_newName) != 0);
bool excludeBecauseFolder = (m_isFolder && (flags & PowerRenameFlags::ExcludeFolders));
bool excludeBecauseFile = (!m_isFolder && (flags & PowerRenameFlags::ExcludeFiles));
bool excludeBecauseSubFolderContent = (m_depth > 0 && (flags & PowerRenameFlags::ExcludeSubfolders));
*shouldRename = (m_selected && m_canRename && hasChanged && !excludeBecauseFile &&
!excludeBecauseFolder && !excludeBecauseSubFolderContent && m_status == PowerRenameItemRenameStatus::ShouldRename);
return S_OK;
}
IFACEMETHODIMP CPowerRenameItem::IsItemVisible(_In_ DWORD filter, _In_ DWORD flags, _Out_ bool* isItemVisible)
{
switch (filter)
{
case PowerRenameFilters::None:
*isItemVisible = true;
break;
case PowerRenameFilters::Selected:
GetSelected(isItemVisible);
break;
case PowerRenameFilters::FlagsApplicable:
*isItemVisible = !((m_isFolder && (flags & PowerRenameFlags::ExcludeFolders)) ||
(!m_isFolder && (flags & PowerRenameFlags::ExcludeFiles)) ||
(m_depth > 0 && (flags & PowerRenameFlags::ExcludeSubfolders)));
break;
case PowerRenameFilters::ShouldRename:
ShouldRenameItem(flags, isItemVisible);
break;
}
return S_OK;
}
IFACEMETHODIMP CPowerRenameItem::Reset()
{
CSRWSharedAutoLock lock(&m_lock);
CoTaskMemFree(m_newName);
m_newName = nullptr;
return S_OK;
}
HRESULT CPowerRenameItem::s_CreateInstance(_In_opt_ IShellItem* psi, _In_ REFIID iid, _Outptr_ void** resultInterface)
{
*resultInterface = nullptr;
CPowerRenameItem* newRenameItem = new CPowerRenameItem();
HRESULT hr = E_OUTOFMEMORY;
if (newRenameItem)
{
hr = S_OK;
if (psi != nullptr)
{
hr = newRenameItem->_Init(psi);
}
if (SUCCEEDED(hr))
{
hr = newRenameItem->QueryInterface(iid, resultInterface);
}
newRenameItem->Release();
}
return hr;
}
CPowerRenameItem::CPowerRenameItem() :
m_refCount(1),
m_id(++s_id)
{
}
CPowerRenameItem::~CPowerRenameItem()
{
CoTaskMemFree(m_path);
CoTaskMemFree(m_newName);
CoTaskMemFree(m_originalName);
}
HRESULT CPowerRenameItem::_Init(_In_ IShellItem* psi)
{
// Get the full filesystem path from the shell item
HRESULT hr = psi->GetDisplayName(SIGDN_FILESYSPATH, &m_path);
if (SUCCEEDED(hr))
{
hr = SHStrDup(PathFindFileName(m_path), &m_originalName);
if (SUCCEEDED(hr))
{
// Check if we are a folder now so we can check this attribute quickly later
// Also check if the shell allows us to rename the item.
SFGAOF att = 0;
hr = psi->GetAttributes(SFGAO_STREAM | SFGAO_FOLDER | SFGAO_CANRENAME, &att);
if (SUCCEEDED(hr))
{
// Some items can be both folders and streams (ex: zip folders).
m_isFolder = (att & SFGAO_FOLDER) && !(att & SFGAO_STREAM);
// The shell lets us know if an item should not be renamed
Updates for check-spelling v0.0.25 (#40386) ## Summary of the Pull Request - #39572 updated check-spelling but ignored: > 🐣 Breaking Changes [Code Scanning action requires a Code Scanning Ruleset](https://github.com/check-spelling/check-spelling/wiki/Breaking-Change:-Code-Scanning-action-requires-a-Code-Scanning-Ruleset) If you use SARIF reporting, then instead of the workflow yielding an ❌ when it fails, it will rely on [github-advanced-security 🤖](https://github.com/apps/github-advanced-security) to report the failure. You will need to adjust your checks for PRs. This means that check-spelling hasn't been properly doing its job 😦. I'm sorry, I should have pushed a thing to this repo earlier,... Anyway, as with most refreshes, this comes with a number of fixes, some are fixes for typos that snuck in before the 0.0.25 upgrade, some are for things that snuck in after, some are based on new rules in spell-check-this, and some are hand written patterns based on running through this repository a few times. About the 🐣 **breaking change**: someone needs to create a ruleset for this repository (see [Code Scanning action requires a Code Scanning Ruleset: Sample ruleset ](https://github.com/check-spelling/check-spelling/wiki/Breaking-Change:-Code-Scanning-action-requires-a-Code-Scanning-Ruleset#sample-ruleset)). The alternative to adding a ruleset is to change the condition to not use sarif for this repository. In general, I think the github integration from sarif is prettier/more helpful, so I think that it's the better choice. You can see an example of it working in: - https://github.com/check-spelling-sandbox/PowerToys/pull/23 --------- Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com> Co-authored-by: Mike Griese <migrie@microsoft.com> Co-authored-by: Dustin L. Howett <dustin@howett.net>
2025-07-08 18:16:52 -04:00
// (ex: user profile director, windows dir, etc.).
m_canRename = (att & SFGAO_CANRENAME);
}
}
}
return hr;
}