|
|
Home » Developing U++ » UppHub » SysInfo and FileToTrashBin
SysInfo and FileToTrashBin [message #23753] |
Thu, 19 November 2009 15:29  |
Zbych
Messages: 327 Registered: July 2009
|
Senior Member |
|
|
Hello,
I found two bugs in FileToTrashBin in SysInfo package:
1. it allocates memory but it doesn't free it.
2. it uses ascii version of SHFileOperation, so it doesn't work properly with utf-8 strings.
My proposition:
bool FileToTrashBin(const char *path)
{
if (!FileExists(path) && !DirectoryExists(path))
return false;
WString ws(path);
// This string must be double-null terminated.
ws.Cat() << L'\0';
SHFILEOPSTRUCTW fileOp;
fileOp.hwnd = NULL;
fileOp.wFunc = FO_DELETE;
fileOp.pFrom = ~ws;
fileOp.pTo = NULL;
fileOp.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_SILENT;
int ret = SHFileOperationW(&fileOp);
if (0 != ret)
return false;
return true;
}
|
|
|
|
|
|
|
Goto Forum:
Current Time: Wed Apr 30 11:51:52 CEST 2025
Total time taken to generate the page: 0.00514 seconds
|
|
|