2010-11-15 14:38:12 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2010 Elestel
|
|
|
|
|
|
|
|
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
|
2012-01-23 06:36:15 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2010-11-15 14:38:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <windows.h>
|
2011-02-03 18:09:24 +00:00
|
|
|
#include "../../Library/Export.h" // Rainmeter's exported functions
|
2010-11-15 14:38:12 +00:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include "FolderInfo.h"
|
|
|
|
|
2011-02-03 18:09:24 +00:00
|
|
|
#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point
|
2011-01-30 09:31:41 +00:00
|
|
|
|
2010-11-15 14:38:12 +00:00
|
|
|
#define UPDATE_TIME_MIN_MS 10000
|
|
|
|
|
|
|
|
using namespace PluginFolderInfo;
|
|
|
|
|
|
|
|
/* 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);
|
2011-07-11 05:35:15 +00:00
|
|
|
__declspec( dllexport ) double Update2(UINT id);
|
2010-11-15 14:38:12 +00:00
|
|
|
__declspec( dllexport ) UINT GetPluginVersion();
|
|
|
|
__declspec( dllexport ) LPCTSTR GetPluginAuthor();
|
|
|
|
}
|
|
|
|
|
|
|
|
enum InfoType
|
|
|
|
{
|
|
|
|
INFOTYPE_FOLDERSIZE,
|
|
|
|
INFOTYPE_FILECOUNT,
|
|
|
|
INFOTYPE_FOLDERCOUNT,
|
|
|
|
|
|
|
|
INFOTYPE_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MeasureInfo
|
|
|
|
{
|
|
|
|
InfoType Type;
|
|
|
|
std::wstring Section;
|
|
|
|
FolderInfo* Folder;
|
|
|
|
|
|
|
|
MeasureInfo(const wchar_t* aSection)
|
|
|
|
{
|
|
|
|
Section = aSection;
|
|
|
|
Type = INFOTYPE_COUNT;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Couple of globals */
|
|
|
|
typedef std::map<UINT, MeasureInfo*> MeasureIdMap; // measure ID -> MeasureInfo
|
|
|
|
static MeasureIdMap sMeasures;
|
|
|
|
typedef std::map<FolderInfo*, UINT> FolderInfoMap; // FolderInfo -> ref count
|
|
|
|
static FolderInfoMap sFolderRefCount;
|
|
|
|
|
|
|
|
static MeasureInfo* GetMeasureInfo(UINT aId)
|
|
|
|
{
|
|
|
|
MeasureIdMap::iterator it = sMeasures.find(aId);
|
|
|
|
if (it != sMeasures.end()) {
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-12-06 07:43:30 +00:00
|
|
|
static FolderInfo* GetFolderInfo(const wchar_t* aPath, const wchar_t* aIniPath)
|
2010-11-15 14:38:12 +00:00
|
|
|
{
|
|
|
|
int pathLen = wcslen(aPath);
|
2011-02-09 05:45:01 +00:00
|
|
|
if (pathLen > 2 && L'[' == aPath[0] && L']' == aPath[pathLen - 1]) {
|
2010-11-15 14:38:12 +00:00
|
|
|
MeasureIdMap::iterator it;
|
|
|
|
for (it = sMeasures.begin(); it != sMeasures.end(); it++) {
|
|
|
|
if (wcsncmp(&aPath[1], it->second->Section.c_str(), pathLen - 2) == 0) {
|
|
|
|
sFolderRefCount[it->second->Folder] = sFolderRefCount[it->second->Folder] + 1;
|
|
|
|
return it->second->Folder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-12-06 07:43:30 +00:00
|
|
|
FolderInfo* folderInfo = new FolderInfo(aPath, aIniPath);
|
2010-11-15 14:38:12 +00:00
|
|
|
sFolderRefCount[folderInfo] = 1;
|
|
|
|
return folderInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
This function is called when the measure is initialized.
|
2011-03-29 19:21:57 +00:00
|
|
|
The function must return the maximum value that can be measured.
|
2010-11-15 14:38:12 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
MeasureInfo* measureInfo = new MeasureInfo(section);
|
|
|
|
|
|
|
|
const wchar_t* strFolder = ReadConfigString(section, L"Folder", L"");
|
2010-12-06 07:43:30 +00:00
|
|
|
measureInfo->Folder = GetFolderInfo(strFolder, iniFile);
|
2010-11-15 14:38:12 +00:00
|
|
|
|
|
|
|
const wchar_t* strInfoType = ReadConfigString(section, L"InfoType", L"");
|
2011-02-09 05:45:01 +00:00
|
|
|
if (_wcsicmp(strInfoType, L"FolderSize") == 0 || _wcsicmp(strInfoType, L"FolderSizeStr") == 0) {
|
|
|
|
measureInfo->Type = INFOTYPE_FOLDERSIZE;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(strInfoType, L"FolderCount") == 0 || _wcsicmp(strInfoType, L"FolderCountStr") == 0) {
|
|
|
|
measureInfo->Type = INFOTYPE_FOLDERCOUNT;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(strInfoType, L"FileCount") == 0 || _wcsicmp(strInfoType, L"FileCountStr") == 0) {
|
|
|
|
measureInfo->Type = INFOTYPE_FILECOUNT;
|
2010-11-15 14:38:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (measureInfo->Folder) {
|
2010-11-15 15:23:32 +00:00
|
|
|
const wchar_t* strRegExpFilter = ReadConfigString(section, L"RegExpFilter", L"");
|
|
|
|
if (strRegExpFilter && wcslen(strRegExpFilter) > 0) {
|
|
|
|
measureInfo->Folder->SetRegExpFilter(strRegExpFilter);
|
2010-11-15 14:38:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const wchar_t* strIncludeSubFolders = ReadConfigString(section, L"IncludeSubFolders", L"");
|
2011-09-28 18:28:35 +00:00
|
|
|
if (wcscmp(strIncludeSubFolders, L"1") == 0) {
|
2010-11-15 14:38:12 +00:00
|
|
|
measureInfo->Folder->IncludeSubFolders(true);
|
|
|
|
}
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2010-11-15 14:38:12 +00:00
|
|
|
const wchar_t* strShowHiddenFiles = ReadConfigString(section, L"IncludeHiddenFiles", L"");
|
2011-09-28 18:28:35 +00:00
|
|
|
if (wcscmp(strShowHiddenFiles, L"1") == 0) {
|
2010-11-15 14:38:12 +00:00
|
|
|
measureInfo->Folder->IncludeHiddenFiles(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
const wchar_t* strShowSystemFiles = ReadConfigString(section, L"IncludeSystemFiles", L"");
|
2011-09-28 18:28:35 +00:00
|
|
|
if (wcscmp(strShowSystemFiles, L"1") == 0) {
|
2010-11-15 14:38:12 +00:00
|
|
|
measureInfo->Folder->IncludeSystemFiles(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
measureInfo->Folder->Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
sMeasures[id] = measureInfo;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
This function is called when new value should be measured.
|
|
|
|
The function returns the new value.
|
|
|
|
*/
|
2011-07-11 05:35:15 +00:00
|
|
|
double Update2(UINT id)
|
2010-11-15 14:38:12 +00:00
|
|
|
{
|
|
|
|
MeasureInfo* measureInfo = sMeasures[id];
|
|
|
|
if (!measureInfo->Folder) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-11 05:35:15 +00:00
|
|
|
DWORD now = GetTickCount();
|
2010-11-15 14:38:12 +00:00
|
|
|
if (now - measureInfo->Folder->GetLastUpdateTime() > UPDATE_TIME_MIN_MS) {
|
|
|
|
measureInfo->Folder->Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (measureInfo->Type)
|
|
|
|
{
|
2011-09-28 18:28:35 +00:00
|
|
|
case INFOTYPE_FOLDERSIZE:
|
|
|
|
return (double)measureInfo->Folder->GetSize();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INFOTYPE_FILECOUNT:
|
|
|
|
return measureInfo->Folder->GetFileCount();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INFOTYPE_FOLDERCOUNT:
|
|
|
|
return measureInfo->Folder->GetFolderCount();
|
|
|
|
break;
|
2010-11-15 14:38:12 +00:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
MeasureIdMap::iterator itm = sMeasures.find(id);
|
|
|
|
if (itm == sMeasures.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MeasureInfo* measureInfo = itm->second;
|
|
|
|
sMeasures.erase(itm);
|
|
|
|
FolderInfoMap::iterator itf = sFolderRefCount.find(measureInfo->Folder);
|
|
|
|
if (itf != sFolderRefCount.end()) {
|
|
|
|
if (1 == itf->second) {
|
|
|
|
delete itf->first;
|
|
|
|
sFolderRefCount.erase(itf);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
itf->second = itf->second - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete measureInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Returns the version number of the plugin. The value
|
|
|
|
can be calculated like this: Major * 1000 + Minor.
|
|
|
|
So, e.g. 2.31 would be 2031.
|
|
|
|
*/
|
|
|
|
UINT GetPluginVersion()
|
|
|
|
{
|
2011-02-09 05:45:01 +00:00
|
|
|
return 0003;
|
2010-11-15 14:38:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Returns the author of the plugin for the about dialog.
|
|
|
|
*/
|
|
|
|
LPCTSTR GetPluginAuthor()
|
|
|
|
{
|
|
|
|
return L"Elestel";
|
|
|
|
}
|