FolderInfo.dll now returns size in bytes. If using InfoType=FolderSizeStr (which until now autoscaled the value internally), AutoScale=1 should be added to the meter(s). While this does change behaviour, it allows for the use of Scale, NumOfDecimals, etc. that weren't possible prior to this change (without an extra Calc measure).

This commit is contained in:
Birunthan Mohanathas 2011-02-09 05:45:01 +00:00
parent 6bd209ffa3
commit cde1e517ac
2 changed files with 12 additions and 81 deletions

View File

@ -33,7 +33,6 @@ extern "C"
{ {
__declspec( dllexport ) UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id); __declspec( dllexport ) UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id);
__declspec( dllexport ) void Finalize(HMODULE instance, UINT id); __declspec( dllexport ) void Finalize(HMODULE instance, UINT id);
__declspec( dllexport ) LPCTSTR GetString(UINT id, UINT flags);
__declspec( dllexport ) UINT Update(UINT id); __declspec( dllexport ) UINT Update(UINT id);
__declspec( dllexport ) UINT GetPluginVersion(); __declspec( dllexport ) UINT GetPluginVersion();
__declspec( dllexport ) LPCTSTR GetPluginAuthor(); __declspec( dllexport ) LPCTSTR GetPluginAuthor();
@ -41,12 +40,6 @@ extern "C"
enum InfoType enum InfoType
{ {
// folder info (string)
INFOTYPE_FOLDERSIZESTR,
INFOTYPE_FILECOUNTSTR,
INFOTYPE_FOLDERCOUNTSTR,
// folder info (int)
INFOTYPE_FOLDERSIZE, INFOTYPE_FOLDERSIZE,
INFOTYPE_FILECOUNT, INFOTYPE_FILECOUNT,
INFOTYPE_FOLDERCOUNT, INFOTYPE_FOLDERCOUNT,
@ -54,19 +47,6 @@ enum InfoType
INFOTYPE_COUNT INFOTYPE_COUNT
}; };
const static wchar_t* InfoTypeName[INFOTYPE_COUNT] =
{
// folder info (string)
L"FolderSizeStr", // FIELD_FOLDERSIZESTR
L"FileCountStr", // FIELD_FILECOUNTSTR
L"FolderCountStr", // FIELD_FOLDERCOUNTSTR
// folder info (int)
L"FolderSize", // FIELD_FOLDERSIZE
L"FileCount", // FIELD_FILECOUNT
L"FolderCount", // FIELD_FOLDERCOUNT
};
struct MeasureInfo struct MeasureInfo
{ {
InfoType Type; InfoType Type;
@ -99,7 +79,7 @@ static MeasureInfo* GetMeasureInfo(UINT aId)
static FolderInfo* GetFolderInfo(const wchar_t* aPath, const wchar_t* aIniPath) static FolderInfo* GetFolderInfo(const wchar_t* aPath, const wchar_t* aIniPath)
{ {
int pathLen = wcslen(aPath); int pathLen = wcslen(aPath);
if(pathLen > 2 && L'[' == aPath[0] && L']' == aPath[pathLen - 1]) { if (pathLen > 2 && L'[' == aPath[0] && L']' == aPath[pathLen - 1]) {
MeasureIdMap::iterator it; MeasureIdMap::iterator it;
for (it = sMeasures.begin(); it != sMeasures.end(); it++) { for (it = sMeasures.begin(); it != sMeasures.end(); it++) {
if (wcsncmp(&aPath[1], it->second->Section.c_str(), pathLen - 2) == 0) { if (wcsncmp(&aPath[1], it->second->Section.c_str(), pathLen - 2) == 0) {
@ -139,10 +119,14 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
measureInfo->Folder = GetFolderInfo(strFolder, iniFile); measureInfo->Folder = GetFolderInfo(strFolder, iniFile);
const wchar_t* strInfoType = ReadConfigString(section, L"InfoType", L""); const wchar_t* strInfoType = ReadConfigString(section, L"InfoType", L"");
for (int i = 0; i < INFOTYPE_COUNT; i++) { if (_wcsicmp(strInfoType, L"FolderSize") == 0 || _wcsicmp(strInfoType, L"FolderSizeStr") == 0) {
if (_wcsicmp(strInfoType, InfoTypeName[i]) == 0) { measureInfo->Type = INFOTYPE_FOLDERSIZE;
measureInfo->Type = (InfoType)i; }
} 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;
} }
if (measureInfo->Folder) { if (measureInfo->Folder) {
@ -174,59 +158,6 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
return 0; return 0;
} }
static void FormatSize(wchar_t* buffer, size_t bufferSize, UINT64 size)
{
if ((size >> 40) > 0) {
wsprintf(buffer, L"%d.%02d T", (int)(size >> 40), (int)(( size << 24 >> 54 ) / 10.24));
}
else if ((size >> 30) > 0) {
wsprintf(buffer, L"%d.%02d G", (int)(size >> 30), (int)(( size << 34 >> 54 ) / 10.24));
}
else if ((size >> 20) > 0) {
wsprintf(buffer, L"%d.%02d M", (int)(size >> 20), (int)(( size << 44 >> 54 ) / 10.24));
}
else if ((size >> 10) > 0) {
wsprintf(buffer, L"%d.%02d k", (int)(size >> 10), (int)(( size << 54 >> 54 ) / 10.24));
}
else {
wsprintf(buffer, L"%ld ", size);
}
}
/*
This function is called when the value should be
returned as a string.
*/
LPCTSTR GetString(UINT id, UINT flags)
{
static wchar_t buffer[MAX_PATH];
buffer[0] = 0;
MeasureInfo* measureInfo = sMeasures[id];
if (!measureInfo->Folder) {
return buffer;
}
int now = GetTickCount();
if (now - measureInfo->Folder->GetLastUpdateTime() > UPDATE_TIME_MIN_MS) {
measureInfo->Folder->Update();
}
switch (measureInfo->Type)
{
case INFOTYPE_FOLDERSIZESTR:
FormatSize(buffer, MAX_PATH, measureInfo->Folder->GetSize());
break;
case INFOTYPE_FILECOUNTSTR:
wsprintf(buffer, L"%d", measureInfo->Folder->GetFileCount());
break;
case INFOTYPE_FOLDERCOUNTSTR:
wsprintf(buffer, L"%d", measureInfo->Folder->GetFolderCount());
break;
}
return buffer;
}
/* /*
This function is called when new value should be measured. This function is called when new value should be measured.
The function returns the new value. The function returns the new value.
@ -292,7 +223,7 @@ void Finalize(HMODULE instance, UINT id)
*/ */
UINT GetPluginVersion() UINT GetPluginVersion()
{ {
return 0002; return 0003;
} }
/* /*

View File

@ -12,7 +12,7 @@
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,2,0,0 FILEVERSION 0,3,0,0
PRODUCTVERSION PRODUCTVER PRODUCTVERSION PRODUCTVER
FILEFLAGSMASK 0x17L FILEFLAGSMASK 0x17L
#ifdef _DEBUG #ifdef _DEBUG
@ -29,7 +29,7 @@ BEGIN
BLOCK "040904E4" BLOCK "040904E4"
BEGIN BEGIN
VALUE "FileDescription", "FolderInfo Plugin for Rainmeter" VALUE "FileDescription", "FolderInfo Plugin for Rainmeter"
VALUE "FileVersion", "0.2.0.0" VALUE "FileVersion", "0.3.0.0"
VALUE "InternalName", "FolderInfo" VALUE "InternalName", "FolderInfo"
VALUE "LegalCopyright", "Copyright (C) 2010 - Elestel" VALUE "LegalCopyright", "Copyright (C) 2010 - Elestel"
VALUE "OriginalFilename", "FolderInfo.dll" VALUE "OriginalFilename", "FolderInfo.dll"