/** * Returns <code>true</code> if the Windows Trash can be used on the current runtime environment. * * @return <code>true</code> if the Windows Trash can be used on the current runtime environment. */ public static boolean isAvailable() { return OsFamily.WINDOWS.isCurrent() && Shell32.isAvailable(); } }
@Override public boolean empty() { return Shell32.isAvailable() && Shell32.getInstance().SHEmptyRecycleBin(null, null, Shell32API.SHERB_NOCONFIRMATION) == 0; }
/** * Implementation notes: returns the number of items for all Recycle Bins on all drives. This information is not * available on certain versions of Windows such as <i>Windows 2000</i>. */ @Override public int getItemCount() { if(!Shell32.isAvailable()) return -1; Shell32API.SHQUERYRBINFO queryRbInfo = new Shell32API.SHQUERYRBINFO(); // pszRootPath is null to retrieve the information for all Recycle Bins on all drives. Microsoft's documentation // states that this fails on certain versions of Windows such as Windows 2000. If it does, we simply return -1. int ret = Shell32.getInstance().SHQueryRecycleBin( null, queryRbInfo ); return ret==0?(int)queryRbInfo.i64NumItems:-1; }
@Override protected boolean moveToTrash(List<AbstractFile> queuedFiles) { if(!Shell32.isAvailable()) return false; Shell32API.SHFILEOPSTRUCT fileop = new Shell32API.SHFILEOPSTRUCT(); fileop.wFunc = Shell32API.FO_DELETE; fileop.fFlags = Shell32API.FOF_ALLOWUNDO| Shell32API.FOF_NOCONFIRMATION| Shell32API.FOF_SILENT; int nbFiles = queuedFiles.size(); String[] paths = new String[nbFiles]; for(int i=0; i<nbFiles; i++) { // Directories (and regular files) must not end with a trailing slash or the operation will fail. paths[i] = queuedFiles.get(i).getAbsolutePath(false); } // The encodePaths method takes care of encoding the paths in a special way. fileop.pFrom = fileop.encodePaths(paths); return Shell32.getInstance().SHFileOperation(fileop) == 0; } }