Failure to rename volumes

Found a bug or something that needs fixing?
Post Reply
Edgar5
Posts: 28
Joined: Sun Apr 02, 2017 7:22 am

Failure to rename volumes

Post by Edgar5 » Fri Jan 12, 2018 9:25 am

Assume I have a drive:
D:\
and it has a label:
Data
Assume that I run Explorer++ from a CLI with the switch:
-clear_settings
so that all the settings are reset to factory default. I now run Explorer++ with no switches (either via CLI or by double-clicking on its icon). Explorer++ opens up into its default size and location showing all the existing partitions on the system (A:\, B:\, C:\, D:\ … Z:\). Each partition displays its label which might look something like:
Data (D:\)
(note that Explorer++ has tacked on - in parentheses - the drive letter. Now, try to change the partition's label WITHOUT removing the appended drive letter:
X (D:\)
the rename fails because the code does not strip off that which it tacked on.

In file:
Explorer++\ListViewHandler.cpp
near line number 820, in the function:
BOOL Explorerplusplus::OnListViewEndLabelEdit(LPARAM lParam)
at the beginning of the function, there are a few sanity checks:
/* Did the user cancel the editing? */
if (pItem->pszText == NULL)
return false;
/* Is the new filename empty? */
if (lstrcmp(pItem->pszText, EMPTY_STRING) == 0)
return false;
/* Deny file names ending with a dot
after these sanity checks we can insert an additional sanity check:
/* partition labels have had their drive letter appended for display so they look like:
name (A:)
If the item is a partition, we must strip this " (*:)" drive letter off (if it is still there)*/
std::wstring currentPartition(pItem->pszText), CWD(currentWorkingDirectory);
if ((CWD.compare(L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}") == 0)) {//Looking at "Drives" / "My Computer"
std::wstring aa, bb, cc, dd;
boost::trim(currentPartition);
size_t fullLength = currentPartition.length();
wchar_t a[3] = { currentPartition[fullLength - 4], 0x0 };
wchar_t b[3] = { currentPartition[fullLength - 3], 0x0 };
wchar_t c[3] = { currentPartition[fullLength - 2], 0x0 };
wchar_t d[3] = { currentPartition[fullLength - 1], 0x0 };
aa.assign(a);
bb.assign(b);
cc.assign(c);
dd.assign(d);
if ((aa.compare(L"(") == 0) && (cc.compare(L":") == 0) && (dd.compare(L")") == 0)) {
std::wregex rxPattern;
rxPattern.assign(_T("[A-Z]"), std::regex_constants::icase);
if (std::tr1::regex_match(bb.c_str(), rxPattern)) {
std::wstring volumeLetter, excise;
excise.assign(L"(");
excise.append(bb);
excise.append(L":\\)");
Replace(currentPartition, excise, L"");
boost::trim(currentPartition);
volumeLetter.assign(bb);
volumeLetter.append(L":\\");
returnValue = SetVolumeLabel(volumeLetter.c_str(), currentPartition.c_str());
if (returnValue)
OnRefresh();
return returnValue;
}
}
}
/* The following characters are NOT allowed within a file name:
\/:*?"<>|
See: http://msdn.microsoft.com/en-us/library/aa365247.aspx */
-Edgar5

Post Reply