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>
|
2012-03-17 12:27:20 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
2010-11-15 14:38:12 +00:00
|
|
|
#include "FolderInfo.h"
|
2012-03-17 12:27:20 +00:00
|
|
|
#include "../API/RainmeterAPI.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
|
|
|
|
2012-03-17 12:27:20 +00:00
|
|
|
enum MeasureType
|
2010-11-15 14:38:12 +00:00
|
|
|
{
|
2012-03-17 12:27:20 +00:00
|
|
|
MEASURE_FILECOUNT,
|
|
|
|
MEASURE_FOLDERCOUNT,
|
|
|
|
MEASURE_FOLDERSIZE
|
2010-11-15 14:38:12 +00:00
|
|
|
};
|
|
|
|
|
2012-03-17 12:27:20 +00:00
|
|
|
struct MeasureData
|
2010-11-15 14:38:12 +00:00
|
|
|
{
|
2012-03-17 12:27:20 +00:00
|
|
|
LPCWSTR section;
|
|
|
|
CFolderInfo* folder;
|
|
|
|
MeasureType type;
|
|
|
|
|
|
|
|
MeasureData(LPCWSTR section) :
|
|
|
|
section(section),
|
|
|
|
folder(),
|
|
|
|
type(MEASURE_FILECOUNT)
|
2010-11-15 14:38:12 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-03-17 12:27:20 +00:00
|
|
|
std::vector<MeasureData*> g_Measures;
|
2010-11-15 14:38:12 +00:00
|
|
|
|
2012-03-17 12:27:20 +00:00
|
|
|
PLUGIN_EXPORT void Initialize(void** data, void* rm)
|
2010-11-15 14:38:12 +00:00
|
|
|
{
|
2012-03-17 12:27:20 +00:00
|
|
|
MeasureData* measure = new MeasureData(RmGetMeasureName(rm));
|
|
|
|
*data = measure;
|
|
|
|
g_Measures.push_back(measure);
|
2010-11-15 14:38:12 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 12:27:20 +00:00
|
|
|
PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
|
2010-11-15 14:38:12 +00:00
|
|
|
{
|
2012-03-17 12:27:20 +00:00
|
|
|
MeasureData* measure = (MeasureData*)data;
|
2010-11-15 14:38:12 +00:00
|
|
|
|
2012-03-17 12:27:20 +00:00
|
|
|
LPCWSTR str = RmReadString(rm, L"Folder", L"", FALSE);
|
|
|
|
if (*str == L'[')
|
|
|
|
{
|
|
|
|
CFolderInfo* oldFolder = measure->folder;
|
|
|
|
measure->folder = NULL;
|
|
|
|
|
|
|
|
int len = wcslen(str);
|
|
|
|
for (auto iter = g_Measures.cbegin(); iter != g_Measures.cend(); ++iter)
|
|
|
|
{
|
|
|
|
if (wcsncmp(&str[1], (*iter)->section, len - 2) == 0)
|
|
|
|
{
|
|
|
|
measure->folder = (*iter)->folder;
|
|
|
|
measure->folder->AddInstance();
|
|
|
|
}
|
2010-11-15 14:38:12 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 12:27:20 +00:00
|
|
|
if (oldFolder)
|
|
|
|
{
|
|
|
|
oldFolder->RemoveInstance();
|
2010-11-15 14:38:12 +00:00
|
|
|
}
|
2012-03-17 12:27:20 +00:00
|
|
|
}
|
|
|
|
else if (*str)
|
|
|
|
{
|
|
|
|
LPCWSTR path = RmPathToAbsolute(rm, str);
|
|
|
|
if (!measure->folder || wcscmp(measure->folder->GetPath(), path) != 0)
|
|
|
|
{
|
|
|
|
if (measure->folder)
|
|
|
|
{
|
|
|
|
measure->folder->RemoveInstance();
|
|
|
|
}
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2012-03-17 12:27:20 +00:00
|
|
|
measure->folder = new CFolderInfo(path);
|
2010-11-15 14:38:12 +00:00
|
|
|
|
2012-03-17 12:27:20 +00:00
|
|
|
str = RmReadString(rm, L"RegExpFilter", L"");
|
|
|
|
if (*str)
|
|
|
|
{
|
|
|
|
measure->folder->SetRegExpFilter(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
measure->folder->IncludeSubFolders((bool)RmReadInt(rm, L"IncludeSubFolders", 0));
|
|
|
|
measure->folder->IncludeHiddenFiles((bool)RmReadInt(rm, L"IncludeHiddenFiles", 0));
|
|
|
|
measure->folder->IncludeSystemFiles((bool)RmReadInt(rm, L"IncludeSystemFiles", 0));
|
2010-11-15 14:38:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 12:27:20 +00:00
|
|
|
str = RmReadString(rm, L"InfoType", L"");
|
|
|
|
if (_wcsicmp(str, L"FolderSize") == 0 || _wcsicmp(str, L"FolderSizeStr") == 0)
|
|
|
|
{
|
|
|
|
measure->type = MEASURE_FOLDERSIZE;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(str, L"FolderCount") == 0 || _wcsicmp(str, L"FolderCountStr") == 0)
|
|
|
|
{
|
|
|
|
measure->type = MEASURE_FOLDERCOUNT;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(str, L"FileCount") == 0 || _wcsicmp(str, L"FileCountStr") == 0)
|
|
|
|
{
|
|
|
|
measure->type = MEASURE_FILECOUNT;
|
|
|
|
}
|
2010-11-15 14:38:12 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 12:27:20 +00:00
|
|
|
PLUGIN_EXPORT double Update(void* data)
|
2010-11-15 14:38:12 +00:00
|
|
|
{
|
2012-03-17 12:27:20 +00:00
|
|
|
MeasureData* measure = (MeasureData*)data;
|
|
|
|
if (!measure->folder)
|
|
|
|
{
|
|
|
|
return 0.0;
|
2010-11-15 14:38:12 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 12:27:20 +00:00
|
|
|
measure->folder->Update();
|
2010-11-15 14:38:12 +00:00
|
|
|
|
2012-03-17 12:27:20 +00:00
|
|
|
switch (measure->type)
|
2010-11-15 14:38:12 +00:00
|
|
|
{
|
2012-03-17 12:27:20 +00:00
|
|
|
case MEASURE_FOLDERSIZE:
|
|
|
|
return measure->folder->GetSize();
|
2011-09-28 18:28:35 +00:00
|
|
|
|
2012-03-17 12:27:20 +00:00
|
|
|
case MEASURE_FILECOUNT:
|
|
|
|
return measure->folder->GetFileCount();
|
2011-09-28 18:28:35 +00:00
|
|
|
|
2012-03-17 12:27:20 +00:00
|
|
|
case MEASURE_FOLDERCOUNT:
|
|
|
|
return measure->folder->GetFolderCount();
|
2010-11-15 14:38:12 +00:00
|
|
|
}
|
2012-03-17 12:27:20 +00:00
|
|
|
|
|
|
|
return 0.0;
|
2010-11-15 14:38:12 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 12:27:20 +00:00
|
|
|
PLUGIN_EXPORT void Finalize(void* data)
|
2010-11-15 14:38:12 +00:00
|
|
|
{
|
2012-03-17 12:27:20 +00:00
|
|
|
MeasureData* measure = (MeasureData*)data;
|
2010-11-15 14:38:12 +00:00
|
|
|
|
2012-03-17 12:27:20 +00:00
|
|
|
if (measure->folder)
|
|
|
|
{
|
|
|
|
measure->folder->RemoveInstance();
|
2010-11-15 14:38:12 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 12:27:20 +00:00
|
|
|
delete measure;
|
2010-11-15 14:38:12 +00:00
|
|
|
|
2012-03-17 12:27:20 +00:00
|
|
|
std::vector<MeasureData*>::iterator iter = std::find(g_Measures.begin(), g_Measures.end(), measure);
|
|
|
|
g_Measures.erase(iter);
|
2010-11-15 14:38:12 +00:00
|
|
|
}
|