Error 403 from Google Calendar? Upgrade to the new Google Calendar support. See here for details. close
Welcome, Guest
Please Login or Register.    Lost Password?

Rough Code for a Recycle Bin Plugin
(1 viewing) (1) Guest
Go to bottomPage: 12
TOPIC: Rough Code for a Recycle Bin Plugin
#9155
Rough Code for a Recycle Bin Plugin 5 Years, 8 Months ago  
Something I've seen in most full featured desktop enhancement suites, but which seems to be lacking in Rainmeter, is full control/replacement of the recycle bin. I banged out a little code to create a plugin for this functionality, but I don't have a compiler on this machine, or the time to debug it right now...

maybe someone else can finish this off for me and get it into the codebase on google...

Code:


/*
  Copyright (C) 2005 Kimmo Pekkola, 2009 Greg Schoppe

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#pragma warning(disable: 4786)
#pragma warning(disable: 4996)

#include 
#include  
#include 
#include 
#include 
#include 
#include 
#include "..\..\Library\Export.h"       // Rainmeter's exported functions

/* The exported functions */
extern "C"
{
__declspec( dllexport ) UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id);
__declspec( dllexport ) void Finalize(HMODULE instance, UINT id);
__declspec( dllexport ) double Update2(UINT id);
__declspec( dllexport ) UINT GetPluginVersion();
__declspec( dllexport ) LPCTSTR GetPluginAuthor();
__declspec( dllexport ) void BinBang(LPCTSTR args, UINT id);
}

const int NUMRECYCLE  = 1;
const int SIZERECYCLE = 2;

static std::map g_Values;

/*
  This function is called when the measure is initialized.
  The function must return the maximum value that can be measured.
  The return value can also be 0, which means that Rainmeter will
  track the maximum value automatically. The parameters for this
  function are:

  instance  The instance of this DLL
  iniFile   The name of the ini-file (usually Rainmeter.ini)
  section   The name of the section in the ini-file for this measure
  id        The identifier for the measure. This is used to identify the measures that use the same plugin.
*/
UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
{
        int dataType = 0;  // 1 for numRecycled, 2 for sizeRecycled
        
        /* Read our own settings from the ini-file */
        LPCTSTR data = ReadConfigString(section, L"numRecycled", NULL);
        if (data)
        {
                dataType = NUMRECYCLE;
        }

        data = ReadConfigString(section, L"sizeRecycled", NULL);
        if (data)
        {
                dataType = SIZERECYCLE;
        }

        g_Values[id] = dataType;

        return 0;
}

/*
This function is called when new value should be measured.
The function returns the new value.
*/
double Update2(UINT id)
{
        int dataType = g_Values[id];
        
        SHQUERYRBINFO RecycleBinInfo = { 0 };  
RecycleBinInfo.cbSize = sizeof( RecycleBinInfo ); // Tell size of structure  
VERIFY( SHQueryRecycleBin( _T( "C:" ), NULL ) == S_OK ); // Get recycle bin info  
        
        
        if (dataType == NUMRECYCLE)
        {
return (RecycleBinInfo.i64Size / 1048576; // size in megabytes
        }
        else if (dataType == SIZERECYCLE)
        {
return RecycleBinInfo.i64NumItems; // number of items in bin
        }
        return 0;
}

/*
  If the measure needs to free resources before quitting.
  The plugin can export Finalize function, which is called
  when Rainmeter quits (or refreshes).
*/
void Finalize(HMODULE instance, UINT id)
{
        std::map::iterator i1 = g_Values.find(id);
        if (i1 != g_Values.end())
        {
                g_Values.erase(i1);
        }
}

UINT GetPluginVersion()
{
        return 1000;
}

LPCTSTR GetPluginAuthor()
{
        return L"gschoppe (gschoppe@gmail.com)";
}

void BinBang(LPCTSTR args, UINT id)
{
        std::wstring bang = args;

if (wcsicmp(bang.c_str(), L"EmptyBin"«») == 0)
{ //Empty the Recycle Bin
SHEmptyRecycleBin( NULL, NULL, NULL );
}
else
{
if (wcsicmp(bang.c_str(), L"EmptyBinSilent"«») == 0)
{ //Empty the Recycle Bin (no prompt)
SHEmptyRecycleBin( NULL, NULL,
                   SHERB_NOCONFIRMATION |
                   SHERB_NOPROGRESSUI   |
                   SHERB_NOSOUND );
}
else
{ //Open the Recycle Bin folder
system("explorer.exe /N,::{645FF040-5081-101B-9F08-00AA002F954E}"«»);
}
}
}



There are a few known issues:

1) currently, it only handles the C:/ recycle bin for querying and emptying... I believe replacing that parameter with null will fix that, but I'm not certain

2) I'm implicitly casting from Long Long to double with the recycle bin query's return statement... I don't remember if c++ can do that

3) Very little error checking and logging



I hope this is useful to someone who can complete it and add it to the codebase.
gschoppe
Fresh Boarder
Posts: 7
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#9160
Re:Rough Code for a Recycle Bin Plugin 5 Years, 8 Months ago  
it appears that my code didn't copy perfectly, leaving out the includes, and perhaps other things... here's the cpp file
File Attachment:
File Name: RecycleManager.zip
File Size: 1963
gschoppe
Fresh Boarder
Posts: 7
graphgraph
User Offline Click here to see the profile of this user
Last Edit: 2009/03/06 16:39 By gschoppe.
The administrator has disabled public write access.
 
#9194
Re:Rough Code for a Recycle Bin Plugin 5 Years, 8 Months ago  
Thanks. I added the code (with some modifications) to the svn and compiled a new version of Rainmeter.
Rainy
Moderator
Posts: 6041
graph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#9200
Re:Rough Code for a Recycle Bin Plugin 5 Years, 8 Months ago  
awesome... I've been wanting to have this functionality for years!! I'm just ecstatic that it made it in!!

--------------------------------------------

one more question, is there a way to trigger an event when a file/folder is dragged onto a widget that takes the file path as a parameter? It would complete the recycle bin replacement, as well as enhance functions like WinAmp controls and allow for simple batch/vbs-like operations to be front-ended by Rainmeter...

I'd be glad to look into it, if it's not a current feature, or currently in development.

---------------------------------------------

also, on regarding the driveLetter issue for getting bin info, the bug that causes a null string to fail only effects ME and 2000 ... I don't know if support for them is mission critical. If not, line 98 should read:

SHQueryRecycleBin( NULL, &RecycleBinInfo ); // Get recycle bin info

otherwise, you only get info for the C: drive's bin...



alternatively, there could be two variants of the plugin one for ME/2000 and one for all other windows versions,

or an internal OS check,

or the code could check for all mounted drive letters and sum the results...

you might have better ideas, but these struck me right off.
gschoppe
Fresh Boarder
Posts: 7
graphgraph
User Offline Click here to see the profile of this user
Last Edit: 2009/03/08 17:04 By gschoppe.
The administrator has disabled public write access.
 
#9233
Re:Rough Code for a Recycle Bin Plugin 5 Years, 8 Months ago  
Dropping files isn't supported at the moment but it's probably doable. Also the bang to empty the recycle bin doesn't work yet since it's not possible to register new !bangs from the plugins.

There are OS version checks in other part of the application too so that's probably the easiest way to fix the drive issue.
Rainy
Moderator
Posts: 6041
graph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#9300
Re:Rough Code for a Recycle Bin Plugin 5 Years, 8 Months ago  
So, what can we do with this recycle plugin? Can we have it display an image dependent on how many files are in the bin? Empty, 10 Files, 30 Files.
dragonmage
Junior Boarder
Posts: 20
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
Go to topPage: 12
get the latest posts directly to your desktop