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-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;
|
2012-04-10 15:20:22 +00:00
|
|
|
bool parent;
|
2012-03-17 12:27:20 +00:00
|
|
|
|
|
|
|
MeasureData(LPCWSTR section) :
|
|
|
|
section(section),
|
|
|
|
folder(),
|
2012-04-10 15:20:22 +00:00
|
|
|
type(MEASURE_FILECOUNT),
|
|
|
|
parent(false)
|
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-04-10 15:20:22 +00:00
|
|
|
void* skin = RmGetSkin(rm);
|
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'[')
|
|
|
|
{
|
|
|
|
int len = wcslen(str);
|
|
|
|
for (auto iter = g_Measures.cbegin(); iter != g_Measures.cend(); ++iter)
|
|
|
|
{
|
2012-04-10 15:20:22 +00:00
|
|
|
if ((*iter)->folder &&
|
|
|
|
(*iter)->folder->GetSkin() == skin &&
|
|
|
|
wcsncmp(&str[1], (*iter)->section, len - 2) == 0)
|
2012-03-17 12:27:20 +00:00
|
|
|
{
|
|
|
|
measure->folder = (*iter)->folder;
|
|
|
|
measure->folder->AddInstance();
|
2012-04-10 15:20:22 +00:00
|
|
|
return;
|
2012-03-17 12:27:20 +00:00
|
|
|
}
|
2010-11-15 14:38:12 +00:00
|
|
|
}
|
2012-03-17 12:27:20 +00:00
|
|
|
}
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2012-04-10 15:20:22 +00:00
|
|
|
measure->folder = new CFolderInfo(skin);
|
|
|
|
measure->parent = true;
|
|
|
|
}
|
2010-11-15 14:38:12 +00:00
|
|
|
|
2012-04-10 15:20:22 +00:00
|
|
|
PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
|
|
|
|
{
|
|
|
|
MeasureData* measure = (MeasureData*)data;
|
|
|
|
CFolderInfo* folder = measure->folder;
|
|
|
|
|
|
|
|
if (!folder)
|
|
|
|
{
|
|
|
|
return;
|
2010-11-15 14:38:12 +00:00
|
|
|
}
|
|
|
|
|
2012-04-10 15:20:22 +00:00
|
|
|
LPCWSTR str = RmReadString(rm, L"InfoType", L"");
|
2012-03-17 12:27:20 +00:00
|
|
|
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;
|
|
|
|
}
|
2012-04-10 15:20:22 +00:00
|
|
|
|
|
|
|
if (measure->parent)
|
|
|
|
{
|
|
|
|
str = RmReadPath(rm, L"Folder", L"");
|
|
|
|
folder->SetPath(str);
|
|
|
|
|
|
|
|
str = RmReadString(rm, L"RegExpFilter", L"");
|
|
|
|
folder->SetRegExpFilter(str);
|
|
|
|
|
|
|
|
folder->SetSubFolders(RmReadInt(rm, L"IncludeSubFolders", 0) == 1);
|
|
|
|
folder->SetHiddenFiles(RmReadInt(rm, L"IncludeHiddenFiles", 0) == 1);
|
|
|
|
folder->SetSystemFiles(RmReadInt(rm, L"IncludeSystemFiles", 0) == 1);
|
|
|
|
}
|
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-04-10 15:20:22 +00:00
|
|
|
if (measure->parent)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|