mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Reintegrated 2.3 branch into trunk
This commit is contained in:
@ -1,10 +1,5 @@
|
||||
// Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
|
||||
#include <windows.h>
|
||||
#include "../../Version.h"
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
#include "windows.h"
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@ -18,7 +13,7 @@ VS_VERSION_INFO VERSIONINFO
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS VS_FF_DEBUG
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS VOS_NT_WINDOWS32
|
||||
FILETYPE VFT_DLL
|
||||
@ -28,11 +23,9 @@ BEGIN
|
||||
BEGIN
|
||||
BLOCK "040904E4"
|
||||
BEGIN
|
||||
VALUE "FileDescription", "RecycleManager Plugin for Rainmeter"
|
||||
VALUE "FileVersion", "1.0.0.0"
|
||||
VALUE "InternalName", "PluginRecycleManager"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2010 - gschoppe"
|
||||
VALUE "OriginalFilename", "PluginRecycleManager.dll"
|
||||
VALUE "LegalCopyright", "<22> 2010 - gschoppe"
|
||||
VALUE "OriginalFilename", "RecycleManager.dll"
|
||||
VALUE "ProductName", "Rainmeter"
|
||||
#ifdef _WIN64
|
||||
VALUE "ProductVersion", STRPRODUCTVER " (64-bit)"
|
||||
|
@ -73,10 +73,10 @@
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)TestBench\x32\$(Configuration)\Plugins\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\x32\$(Configuration)\</IntDir>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</LinkIncremental>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)TestBench\x64\$(Configuration)\Plugins\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.\x64\$(Configuration)\</IntDir>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</LinkIncremental>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
|
||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">RecycleManager</TargetName>
|
||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">RecycleManager</TargetName>
|
||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">RecycleManager</TargetName>
|
||||
|
@ -18,25 +18,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include "../../Library/RawString.h"
|
||||
#include "../../Library/Export.h" // Rainmeter's exported functions
|
||||
|
||||
#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point
|
||||
|
||||
/* 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 ExecuteBang(LPCTSTR args, UINT id);
|
||||
}
|
||||
|
||||
// System resources that can be counted
|
||||
enum MEASURETYPE
|
||||
{
|
||||
@ -44,96 +30,61 @@ enum MEASURETYPE
|
||||
SIZERECYCLE
|
||||
};
|
||||
|
||||
static std::map<UINT, MEASURETYPE> g_Values;
|
||||
static std::map<UINT, std::wstring> g_DriveList;
|
||||
|
||||
/*
|
||||
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)
|
||||
struct MeasureData
|
||||
{
|
||||
MEASURETYPE dataType = NUMRECYCLE;
|
||||
MEASURETYPE type;
|
||||
CRawString drives;
|
||||
|
||||
/* Read our own settings from the ini-file */
|
||||
LPCTSTR type = ReadConfigString(section, L"RecycleType", L"COUNT");
|
||||
if (type)
|
||||
{
|
||||
if (_wcsicmp(L"COUNT", type) == 0)
|
||||
{
|
||||
dataType = NUMRECYCLE;
|
||||
}
|
||||
else if (_wcsicmp(L"SIZE", type) == 0)
|
||||
{
|
||||
dataType = SIZERECYCLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wstring error = L"RecycleManager.dll: RecycleType=";
|
||||
error += type;
|
||||
error += L" is not valid in [";
|
||||
error += section;
|
||||
error += L"]";
|
||||
LSLog(LOG_ERROR, NULL, error.c_str());
|
||||
}
|
||||
}
|
||||
MeasureData() : type(NUMRECYCLE) {}
|
||||
};
|
||||
|
||||
g_Values[id] = dataType;
|
||||
|
||||
LPCTSTR drives = ReadConfigString(section, L"Drives", L"");
|
||||
g_DriveList[id] = (drives && *drives) ? drives : L"ALL";
|
||||
|
||||
return 0;
|
||||
PLUGIN_EXPORT void Initialize(void** data)
|
||||
{
|
||||
MeasureData* measure = new MeasureData;
|
||||
*data = measure;
|
||||
}
|
||||
|
||||
void Tokenize(const std::wstring& str, std::vector<std::wstring>& tokens, const std::wstring& delimiters = L"|")
|
||||
PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
|
||||
{
|
||||
// Skip delimiters at beginning.
|
||||
std::wstring::size_type lastPos = str.find_first_not_of(delimiters, 0);
|
||||
// Find first "non-delimiter".
|
||||
std::wstring::size_type pos = str.find_first_of(delimiters, lastPos);
|
||||
MeasureData* measure = (MeasureData*)data;
|
||||
|
||||
while (std::wstring::npos != pos || std::wstring::npos != lastPos)
|
||||
LPCWSTR value = RmReadString(rm, L"RecycleType", L"COUNT");
|
||||
if (_wcsicmp(L"COUNT", value) == 0)
|
||||
{
|
||||
// Found a token, add it to the vector.
|
||||
tokens.push_back(str.substr(lastPos, pos - lastPos));
|
||||
// Skip delimiters. Note the "not_of"
|
||||
lastPos = str.find_first_not_of(delimiters, pos);
|
||||
// Find next "non-delimiter"
|
||||
pos = str.find_first_of(delimiters, lastPos);
|
||||
measure->type = NUMRECYCLE;
|
||||
}
|
||||
else if (_wcsicmp(L"SIZE", value) == 0)
|
||||
{
|
||||
measure->type = SIZERECYCLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
WCHAR buffer[256];
|
||||
_snwprintf_s(buffer, _TRUNCATE, L"RecycleManager.dll: RecycleType=%s is not valid in [%s]", value, RmGetMeasureName(rm));
|
||||
RmLog(LOG_ERROR, buffer);
|
||||
}
|
||||
|
||||
value = RmReadString(rm, L"Drives", L"ALL");
|
||||
measure->drives = (_wcsicmp(value, L"ALL") == 0) ? NULL : value;
|
||||
}
|
||||
|
||||
/*
|
||||
This function is called when new value should be measured.
|
||||
The function returns the new value.
|
||||
*/
|
||||
double Update2(UINT id)
|
||||
PLUGIN_EXPORT double Update(void* data)
|
||||
{
|
||||
MeasureData* measure = (MeasureData*)data;
|
||||
double retVal = 0;
|
||||
MEASURETYPE dataType = g_Values[id];
|
||||
const std::wstring& driveSet = g_DriveList[id];
|
||||
|
||||
SHQUERYRBINFO rbi = {0};
|
||||
rbi.cbSize = sizeof(SHQUERYRBINFO);
|
||||
|
||||
if (_wcsicmp(driveSet.c_str(), L"ALL") == 0)
|
||||
if (measure->drives.empty())
|
||||
{
|
||||
if (SHQueryRecycleBin(NULL, &rbi) == S_OK)
|
||||
{
|
||||
if (dataType == SIZERECYCLE)
|
||||
if (measure->type == SIZERECYCLE)
|
||||
{
|
||||
retVal = (double)rbi.i64Size; // size in bytes
|
||||
}
|
||||
else if (dataType == NUMRECYCLE)
|
||||
else if (measure->type == NUMRECYCLE)
|
||||
{
|
||||
retVal = (double)rbi.i64NumItems; // number of items in bin
|
||||
}
|
||||
@ -141,100 +92,70 @@ double Update2(UINT id)
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<std::wstring> tokens;
|
||||
Tokenize(driveSet, tokens);
|
||||
|
||||
for (int i = 0, isize = (int)tokens.size(); i < isize; i++)
|
||||
WCHAR* drives = _wcsdup(measure->drives.c_str());
|
||||
WCHAR* token = wcstok(drives, L"|");
|
||||
while (token)
|
||||
{
|
||||
if (SHQueryRecycleBin(tokens[i].c_str(), &rbi) == S_OK)
|
||||
if (SHQueryRecycleBin(token, &rbi) == S_OK)
|
||||
{
|
||||
if (dataType == SIZERECYCLE)
|
||||
if (measure->type == SIZERECYCLE)
|
||||
{
|
||||
retVal += (double)rbi.i64Size; // size in bytes
|
||||
}
|
||||
else if (dataType == NUMRECYCLE)
|
||||
else if (measure->type == NUMRECYCLE)
|
||||
{
|
||||
retVal += (double)rbi.i64NumItems; // number of items in bin
|
||||
}
|
||||
}
|
||||
|
||||
token = wcstok(NULL, L"|");
|
||||
}
|
||||
free(drives);
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/*
|
||||
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)
|
||||
PLUGIN_EXPORT void Finalize(void* data)
|
||||
{
|
||||
std::map<UINT, MEASURETYPE>::iterator i1 = g_Values.find(id);
|
||||
if (i1 != g_Values.end())
|
||||
MeasureData* measure = (MeasureData*)data;
|
||||
delete measure;
|
||||
}
|
||||
|
||||
PLUGIN_EXPORT void ExecuteBang(void* data, LPCWSTR args)
|
||||
{
|
||||
MeasureData* measure = (MeasureData*)data;
|
||||
|
||||
auto emptyBin = [&](DWORD flags)
|
||||
{
|
||||
g_Values.erase(i1);
|
||||
}
|
||||
}
|
||||
|
||||
UINT GetPluginVersion()
|
||||
{
|
||||
return 1000;
|
||||
}
|
||||
|
||||
LPCTSTR GetPluginAuthor()
|
||||
{
|
||||
return L"gschoppe (gschoppe@gmail.com)";
|
||||
}
|
||||
|
||||
void ExecuteBang(LPCTSTR args, UINT id)
|
||||
{
|
||||
const std::wstring& driveSet = g_DriveList[id];
|
||||
if (_wcsicmp(args, L"EmptyBin") == 0)
|
||||
{
|
||||
// Empty the Recycle Bin
|
||||
if (_wcsicmp(driveSet.c_str(), L"ALL") == 0)
|
||||
if (measure->drives.empty())
|
||||
{
|
||||
SHEmptyRecycleBin( NULL, NULL, NULL );
|
||||
SHEmptyRecycleBin(NULL, NULL, flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<std::wstring> tokens;
|
||||
Tokenize(driveSet, tokens);
|
||||
|
||||
for (int i = 0, isize = (int)tokens.size(); i < isize; i++)
|
||||
WCHAR* drives = _wcsdup(measure->drives.c_str());
|
||||
WCHAR* token = wcstok(drives, L"|");
|
||||
while (token)
|
||||
{
|
||||
SHEmptyRecycleBin( NULL, tokens[i].c_str(), NULL ); // empty bin
|
||||
SHEmptyRecycleBin(NULL, token, flags);
|
||||
token = wcstok(NULL, L"|");
|
||||
}
|
||||
free(drives);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
};
|
||||
|
||||
if (_wcsicmp(args, L"EmptyBin") == 0)
|
||||
{
|
||||
if (_wcsicmp(args, L"EmptyBinSilent") == 0)
|
||||
{
|
||||
// Empty the Recycle Bin (no prompt)
|
||||
if (_wcsicmp(driveSet.c_str(), L"ALL") == 0)
|
||||
{
|
||||
SHEmptyRecycleBin( NULL, NULL, SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI | SHERB_NOSOUND );
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<std::wstring> tokens;
|
||||
Tokenize(driveSet, tokens);
|
||||
|
||||
for (int i = 0, isize = (int)tokens.size(); i < isize; i++)
|
||||
{
|
||||
SHEmptyRecycleBin( NULL, tokens[i].c_str(), SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI | SHERB_NOSOUND ); // empty bin
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (_wcsicmp(args, L"OpenBin") == 0)
|
||||
{
|
||||
// Open the Recycle Bin folder
|
||||
ShellExecute(NULL, L"open", L"explorer.exe", L"/N,::{645FF040-5081-101B-9F08-00AA002F954E}", NULL, SW_SHOW);
|
||||
return;
|
||||
}
|
||||
emptyBin(0);
|
||||
}
|
||||
else if (_wcsicmp(args, L"EmptyBinSilent") == 0)
|
||||
{
|
||||
emptyBin(SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI | SHERB_NOSOUND);
|
||||
}
|
||||
else if (_wcsicmp(args, L"OpenBin") == 0)
|
||||
{
|
||||
// Open the Recycle Bin folder
|
||||
ShellExecute(NULL, L"open", L"explorer.exe", L"/N,::{645FF040-5081-101B-9F08-00AA002F954E}", NULL, SW_SHOW);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user