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
|
#define UPDATE_TIME_MIN_MS 10000
|
||||||
|
|
||||||
CFolderInfo::CFolderInfo(LPCWSTR path) :
|
CFolderInfo::CFolderInfo(void* ownerSkin) :
|
||||||
m_InstanceCount(1),
|
m_InstanceCount(1),
|
||||||
m_Path(path),
|
m_Skin(ownerSkin),
|
||||||
m_IncludeSubFolders(false),
|
m_IncludeSubFolders(false),
|
||||||
m_IncludeHiddenFiles(false),
|
m_IncludeHiddenFiles(false),
|
||||||
m_IncludeSystemFiles(false),
|
m_IncludeSystemFiles(false),
|
||||||
@ -160,19 +160,33 @@ 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)
|
void CFolderInfo::SetRegExpFilter(LPCWSTR filter)
|
||||||
{
|
{
|
||||||
FreePcre();
|
FreePcre();
|
||||||
|
|
||||||
int filterLen = wcslen(filter) + 1;
|
if (*filter)
|
||||||
int bufLen = WideCharToMultiByte(CP_UTF8, 0, filter, filterLen, NULL, 0, NULL, NULL);
|
{
|
||||||
|
int filterLen = wcslen(filter) + 1;
|
||||||
|
int bufLen = WideCharToMultiByte(CP_UTF8, 0, filter, filterLen, NULL, 0, NULL, NULL);
|
||||||
|
|
||||||
char* buf = new char[bufLen];
|
char* buf = new char[bufLen];
|
||||||
WideCharToMultiByte(CP_UTF8, 0, filter, filterLen, buf, bufLen, NULL, NULL);
|
WideCharToMultiByte(CP_UTF8, 0, filter, filterLen, buf, bufLen, NULL, NULL);
|
||||||
|
|
||||||
const char* error;
|
const char* error;
|
||||||
int erroffset;
|
int erroffset;
|
||||||
m_RegExpFilter = pcre_compile(buf, PCRE_UTF8, &error, &erroffset, NULL);
|
m_RegExpFilter = pcre_compile(buf, PCRE_UTF8, &error, &erroffset, NULL);
|
||||||
|
|
||||||
delete [] buf;
|
delete [] buf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,21 +27,20 @@
|
|||||||
class CFolderInfo
|
class CFolderInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CFolderInfo(LPCWSTR path);
|
CFolderInfo(void* ownerSkin);
|
||||||
~CFolderInfo();
|
~CFolderInfo();
|
||||||
|
|
||||||
void AddInstance();
|
void AddInstance();
|
||||||
void RemoveInstance();
|
void RemoveInstance();
|
||||||
|
|
||||||
|
void* GetSkin() { return m_Skin; }
|
||||||
DWORD GetLastUpdateTime() { return m_LastUpdateTime; }
|
DWORD GetLastUpdateTime() { return m_LastUpdateTime; }
|
||||||
|
|
||||||
|
void SetPath(LPCWSTR path);
|
||||||
void SetRegExpFilter(LPCWSTR filter);
|
void SetRegExpFilter(LPCWSTR filter);
|
||||||
|
void SetSubFolders(bool flag) { m_IncludeSubFolders = flag; }
|
||||||
void IncludeSubFolders(bool flag) { m_IncludeSubFolders = flag; }
|
void SetHiddenFiles(bool flag) { m_IncludeHiddenFiles = flag; }
|
||||||
void IncludeHiddenFiles(bool flag) { m_IncludeHiddenFiles = flag; }
|
void SetSystemFiles(bool flag) { m_IncludeSystemFiles = flag; }
|
||||||
void IncludeSystemFiles(bool flag) { m_IncludeSystemFiles = flag; }
|
|
||||||
|
|
||||||
LPCWSTR GetPath() { return m_Path.c_str(); }
|
|
||||||
|
|
||||||
UINT64 GetSize() { return m_Size; }
|
UINT64 GetSize() { return m_Size; }
|
||||||
int GetFileCount() { return m_FileCount; }
|
int GetFileCount() { return m_FileCount; }
|
||||||
@ -55,6 +54,7 @@ private:
|
|||||||
void CalculateSize();
|
void CalculateSize();
|
||||||
|
|
||||||
UINT m_InstanceCount;
|
UINT m_InstanceCount;
|
||||||
|
void* m_Skin;
|
||||||
|
|
||||||
CRawString m_Path;
|
CRawString m_Path;
|
||||||
bool m_IncludeSubFolders;
|
bool m_IncludeSubFolders;
|
||||||
|
@ -35,11 +35,13 @@ struct MeasureData
|
|||||||
LPCWSTR section;
|
LPCWSTR section;
|
||||||
CFolderInfo* folder;
|
CFolderInfo* folder;
|
||||||
MeasureType type;
|
MeasureType type;
|
||||||
|
bool parent;
|
||||||
|
|
||||||
MeasureData(LPCWSTR section) :
|
MeasureData(LPCWSTR section) :
|
||||||
section(section),
|
section(section),
|
||||||
folder(),
|
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));
|
MeasureData* measure = new MeasureData(RmGetMeasureName(rm));
|
||||||
*data = measure;
|
*data = measure;
|
||||||
g_Measures.push_back(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)
|
PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
|
||||||
{
|
{
|
||||||
MeasureData* measure = (MeasureData*)data;
|
MeasureData* measure = (MeasureData*)data;
|
||||||
|
CFolderInfo* folder = measure->folder;
|
||||||
|
|
||||||
LPCWSTR str = RmReadString(rm, L"Folder", L"", FALSE);
|
if (!folder)
|
||||||
if (*str == L'[')
|
|
||||||
{
|
{
|
||||||
CFolderInfo* oldFolder = measure->folder;
|
return;
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
if (_wcsicmp(str, L"FolderSize") == 0 || _wcsicmp(str, L"FolderSizeStr") == 0)
|
||||||
{
|
{
|
||||||
measure->type = MEASURE_FOLDERSIZE;
|
measure->type = MEASURE_FOLDERSIZE;
|
||||||
@ -115,6 +100,19 @@ PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
|
|||||||
{
|
{
|
||||||
measure->type = MEASURE_FILECOUNT;
|
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)
|
PLUGIN_EXPORT double Update(void* data)
|
||||||
@ -125,7 +123,10 @@ PLUGIN_EXPORT double Update(void* data)
|
|||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
measure->folder->Update();
|
if (measure->parent)
|
||||||
|
{
|
||||||
|
measure->folder->Update();
|
||||||
|
}
|
||||||
|
|
||||||
switch (measure->type)
|
switch (measure->type)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user