mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
FolderInfo.dll: Added support for dynamic Folder= and fixed memory leaks
This commit is contained in:
parent
b670d5efdd
commit
e478768cac
@ -23,9 +23,9 @@
|
||||
|
||||
#define UPDATE_TIME_MIN_MS 10000
|
||||
|
||||
CFolderInfo::CFolderInfo(LPCWSTR path) :
|
||||
CFolderInfo::CFolderInfo(void* ownerSkin) :
|
||||
m_InstanceCount(1),
|
||||
m_Path(path),
|
||||
m_Skin(ownerSkin),
|
||||
m_IncludeSubFolders(false),
|
||||
m_IncludeHiddenFiles(false),
|
||||
m_IncludeSystemFiles(false),
|
||||
@ -160,10 +160,23 @@ void CFolderInfo::CalculateSize()
|
||||
}
|
||||
}
|
||||
|
||||
void CFolderInfo::SetPath(LPCWSTR path)
|
||||
{
|
||||
if (wcscmp(m_Path.c_str(), path) != 0)
|
||||
{
|
||||
m_Path = path;
|
||||
|
||||
// Force update next time
|
||||
m_LastUpdateTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void CFolderInfo::SetRegExpFilter(LPCWSTR filter)
|
||||
{
|
||||
FreePcre();
|
||||
|
||||
if (*filter)
|
||||
{
|
||||
int filterLen = wcslen(filter) + 1;
|
||||
int bufLen = WideCharToMultiByte(CP_UTF8, 0, filter, filterLen, NULL, 0, NULL, NULL);
|
||||
|
||||
@ -175,4 +188,5 @@ void CFolderInfo::SetRegExpFilter(LPCWSTR filter)
|
||||
m_RegExpFilter = pcre_compile(buf, PCRE_UTF8, &error, &erroffset, NULL);
|
||||
|
||||
delete [] buf;
|
||||
}
|
||||
}
|
||||
|
@ -27,21 +27,20 @@
|
||||
class CFolderInfo
|
||||
{
|
||||
public:
|
||||
CFolderInfo(LPCWSTR path);
|
||||
CFolderInfo(void* ownerSkin);
|
||||
~CFolderInfo();
|
||||
|
||||
void AddInstance();
|
||||
void RemoveInstance();
|
||||
|
||||
void* GetSkin() { return m_Skin; }
|
||||
DWORD GetLastUpdateTime() { return m_LastUpdateTime; }
|
||||
|
||||
void SetPath(LPCWSTR path);
|
||||
void SetRegExpFilter(LPCWSTR filter);
|
||||
|
||||
void IncludeSubFolders(bool flag) { m_IncludeSubFolders = flag; }
|
||||
void IncludeHiddenFiles(bool flag) { m_IncludeHiddenFiles = flag; }
|
||||
void IncludeSystemFiles(bool flag) { m_IncludeSystemFiles = flag; }
|
||||
|
||||
LPCWSTR GetPath() { return m_Path.c_str(); }
|
||||
void SetSubFolders(bool flag) { m_IncludeSubFolders = flag; }
|
||||
void SetHiddenFiles(bool flag) { m_IncludeHiddenFiles = flag; }
|
||||
void SetSystemFiles(bool flag) { m_IncludeSystemFiles = flag; }
|
||||
|
||||
UINT64 GetSize() { return m_Size; }
|
||||
int GetFileCount() { return m_FileCount; }
|
||||
@ -55,6 +54,7 @@ private:
|
||||
void CalculateSize();
|
||||
|
||||
UINT m_InstanceCount;
|
||||
void* m_Skin;
|
||||
|
||||
CRawString m_Path;
|
||||
bool m_IncludeSubFolders;
|
||||
|
@ -35,11 +35,13 @@ struct MeasureData
|
||||
LPCWSTR section;
|
||||
CFolderInfo* folder;
|
||||
MeasureType type;
|
||||
bool parent;
|
||||
|
||||
MeasureData(LPCWSTR section) :
|
||||
section(section),
|
||||
folder(),
|
||||
type(MEASURE_FILECOUNT)
|
||||
type(MEASURE_FILECOUNT),
|
||||
parent(false)
|
||||
{
|
||||
}
|
||||
};
|
||||
@ -51,58 +53,41 @@ PLUGIN_EXPORT void Initialize(void** data, void* rm)
|
||||
MeasureData* measure = new MeasureData(RmGetMeasureName(rm));
|
||||
*data = measure;
|
||||
g_Measures.push_back(measure);
|
||||
|
||||
void* skin = RmGetSkin(rm);
|
||||
|
||||
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)
|
||||
{
|
||||
if ((*iter)->folder &&
|
||||
(*iter)->folder->GetSkin() == skin &&
|
||||
wcsncmp(&str[1], (*iter)->section, len - 2) == 0)
|
||||
{
|
||||
measure->folder = (*iter)->folder;
|
||||
measure->folder->AddInstance();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
measure->folder = new CFolderInfo(skin);
|
||||
measure->parent = true;
|
||||
}
|
||||
|
||||
PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
|
||||
{
|
||||
MeasureData* measure = (MeasureData*)data;
|
||||
CFolderInfo* folder = measure->folder;
|
||||
|
||||
LPCWSTR str = RmReadString(rm, L"Folder", L"", FALSE);
|
||||
if (*str == L'[')
|
||||
if (!folder)
|
||||
{
|
||||
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();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (oldFolder)
|
||||
{
|
||||
oldFolder->RemoveInstance();
|
||||
}
|
||||
}
|
||||
else if (*str)
|
||||
{
|
||||
LPCWSTR path = RmPathToAbsolute(rm, str);
|
||||
if (!measure->folder || wcscmp(measure->folder->GetPath(), path) != 0)
|
||||
{
|
||||
if (measure->folder)
|
||||
{
|
||||
measure->folder->RemoveInstance();
|
||||
}
|
||||
|
||||
measure->folder = new CFolderInfo(path);
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
str = RmReadString(rm, L"InfoType", L"");
|
||||
LPCWSTR str = RmReadString(rm, L"InfoType", L"");
|
||||
if (_wcsicmp(str, L"FolderSize") == 0 || _wcsicmp(str, L"FolderSizeStr") == 0)
|
||||
{
|
||||
measure->type = MEASURE_FOLDERSIZE;
|
||||
@ -115,6 +100,19 @@ PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
|
||||
{
|
||||
measure->type = MEASURE_FILECOUNT;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
PLUGIN_EXPORT double Update(void* data)
|
||||
@ -125,7 +123,10 @@ PLUGIN_EXPORT double Update(void* data)
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
if (measure->parent)
|
||||
{
|
||||
measure->folder->Update();
|
||||
}
|
||||
|
||||
switch (measure->type)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user