Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » UppHub » SysInfo and FileToTrashBin
SysInfo and FileToTrashBin [message #23753] Thu, 19 November 2009 15:29 Go to previous message
Zbych is currently offline  Zbych
Messages: 326
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;
}
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Console Directory Compare
Next Topic: mini bugfix in TabBar
Goto Forum:
  


Current Time: Fri May 17 17:53:21 CEST 2024

Total time taken to generate the page: 0.02250 seconds