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 next message
Zbych is currently offline  Zbych
Messages: 325
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;
}
Re: SysInfo and FileToTrashBin [message #23755 is a reply to message #23753] Thu, 19 November 2009 17:50 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Thank you Zbych

If it is ok (as it seems) I will adopt it Smile

Best regards
Koldo


Best regards
Iñaki
Re: SysInfo and FileToTrashBin [message #23785 is a reply to message #23755] Sun, 22 November 2009 09:07 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello Zbych

Thank you for your help. Your fix is now included.

Now I am reorganizing some packages internally (no change for the user programmer) so the change will be uploaded and public in few weeks.

Best regards
Koldo


Best regards
Iñaki
Re: SysInfo and FileToTrashBin [message #23790 is a reply to message #23785] Sun, 22 November 2009 20:20 Go to previous messageGo to next message
Zbych is currently offline  Zbych
Messages: 325
Registered: July 2009
Senior Member
koldo wrote on Sun, 22 November 2009 09:07

Your fix is now included.
Now I am reorganizing some packages internally


Thank you. Maybe it is good time to remove all mallocs/free from the package (at least replace them with new/delete to ease detection of memory leaks).

Re: SysInfo and FileToTrashBin [message #23791 is a reply to message #23790] Sun, 22 November 2009 21:17 Go to previous message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello Zbych

Good suggestion. No problem as there was only one additional malloc Smile.

Now changed to new/delete (impossible to use static allocation in this case as it is the size of the screen grab in Window_SaveCapture, that depends on the screen size).

Best regards
Koldo


Best regards
Iñaki
Previous Topic: Console Directory Compare
Next Topic: mini bugfix in TabBar
Goto Forum:
  


Current Time: Tue Apr 23 18:03:29 CEST 2024

Total time taken to generate the page: 0.03066 seconds