summaryrefslogtreecommitdiff
path: root/plugins/BasicHistory
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-01-08 11:32:03 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-01-08 11:32:03 +0000
commitd0218e1e5f874668e28366fe043d3c30f8238aa3 (patch)
tree804971acf25de104772773ccada13f6d23a3b192 /plugins/BasicHistory
parentb17ba2cace1782778de0a2bea8b2b96bb1dba157 (diff)
minus another critical section
git-svn-id: http://svn.miranda-ng.org/main/trunk@11793 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/BasicHistory')
-rw-r--r--plugins/BasicHistory/src/BasicHistory.cpp8
-rw-r--r--plugins/BasicHistory/src/EventList.cpp72
-rw-r--r--plugins/BasicHistory/src/EventList.h3
3 files changed, 34 insertions, 49 deletions
diff --git a/plugins/BasicHistory/src/BasicHistory.cpp b/plugins/BasicHistory/src/BasicHistory.cpp
index f625f727ea..687f416fe8 100644
--- a/plugins/BasicHistory/src/BasicHistory.cpp
+++ b/plugins/BasicHistory/src/BasicHistory.cpp
@@ -59,7 +59,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
return TRUE;
}
-TIME_API tmi = {0};
+TIME_API tmi = { 0 };
int hLangpack = 0;
extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
@@ -234,8 +234,8 @@ int ModulesLoaded(WPARAM wParam, LPARAM lParam)
else Options::instance->ftpExePathDef = ftpExe;
}
- TCHAR* log = _T("%miranda_logpath%\\BasicHistory\\ftplog.txt");
- TCHAR* logAbsolute = Utils_ReplaceVarsT(log);
+ TCHAR *log = _T("%miranda_logpath%\\BasicHistory\\ftplog.txt");
+ TCHAR *logAbsolute = Utils_ReplaceVarsT(log);
Options::instance->ftpLogPath = logAbsolute;
mir_free(logAbsolute);
Options::instance->Load();
@@ -294,8 +294,6 @@ extern "C" int __declspec(dllexport) Unload(void)
DestroyCursor(hCurSplitNS);
DestroyCursor(hCurSplitWE);
- EventList::Deinit();
-
if (Options::instance != NULL) {
Options::instance->Unload();
delete Options::instance;
diff --git a/plugins/BasicHistory/src/EventList.cpp b/plugins/BasicHistory/src/EventList.cpp
index c10b883001..a70772e3d9 100644
--- a/plugins/BasicHistory/src/EventList.cpp
+++ b/plugins/BasicHistory/src/EventList.cpp
@@ -24,6 +24,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
extern int iconsNum;
+static mir_cs csEventList;
+
bool DeleteDirectory(LPCTSTR lpszDir, bool noRecycleBin = true);
std::wstring GetName(const std::wstring &path);
@@ -236,18 +238,16 @@ void EventList::RefreshEventList()
if (useImportedMessages) {
std::vector<IImport::ExternalMessage> messages;
-
- EnterCriticalSection(&criticalSection);
- std::map<MCONTACT, EventList::ImportDiscData>::iterator it = contactFileMap.find(hContact);
- if (it != contactFileMap.end()) {
- ExportManager imp(hWnd, hContact, 1);
- imp.SetAutoImport(it->second.file);
- if (!imp.Import(it->second.type, messages, NULL))
- messages.clear();
+ {
+ mir_cslock lck(csEventList);
+ std::map<MCONTACT, EventList::ImportDiscData>::iterator it = contactFileMap.find(hContact);
+ if (it != contactFileMap.end()) {
+ ExportManager imp(hWnd, hContact, 1);
+ imp.SetAutoImport(it->second.file);
+ if (!imp.Import(it->second.type, messages, NULL))
+ messages.clear();
+ }
}
-
- LeaveCriticalSection(&criticalSection);
-
ImportMessages(messages);
}
@@ -306,17 +306,17 @@ bool EventList::SearchInContact(MCONTACT hContact, TCHAR *strFind, ComparatorInt
if (useImportedMessages) {
std::vector<IImport::ExternalMessage> messages;
-
- EnterCriticalSection(&criticalSection);
- std::map<MCONTACT, EventList::ImportDiscData>::iterator it = contactFileMap.find(hContact);
- if (it != contactFileMap.end()) {
- ExportManager imp(hWnd, hContact, 1);
- imp.SetAutoImport(it->second.file);
- if (!imp.Import(it->second.type, messages, NULL))
- messages.clear();
+ {
+ mir_cslock lck(csEventList);
+ std::map<MCONTACT, EventList::ImportDiscData>::iterator it = contactFileMap.find(hContact);
+ if (it != contactFileMap.end()) {
+ ExportManager imp(hWnd, hContact, 1);
+ imp.SetAutoImport(it->second.file);
+ if (!imp.Import(it->second.type, messages, NULL))
+ messages.clear();
+ }
}
- LeaveCriticalSection(&criticalSection);
for (int i = 0; i < (int)importedMessages.size(); ++i)
if (compFun->Compare((importedMessages[i].flags & DBEF_SENT) != 0, importedMessages[i].message, strFind))
return true;
@@ -612,13 +612,11 @@ HICON EventList::GetEventCoreIcon(const EventIndex& ev)
{
if (ev.isExternal)
return NULL;
- HICON ico;
- ico = (HICON)CallService(MS_DB_EVENT_GETICON, LR_SHARED, (LPARAM)&gdbei);
+
+ HICON ico = (HICON)CallService(MS_DB_EVENT_GETICON, LR_SHARED, (LPARAM)&gdbei);
HICON icoMsg = LoadSkinnedIcon(SKINICON_EVENT_MESSAGE);
if (icoMsg == ico)
- {
return NULL;
- }
return ico;
}
@@ -639,13 +637,13 @@ void EventList::RebuildGroup(int selected)
eventList[selected].insert(eventList[selected].begin(), newGroup.begin(), newGroup.end());
}
-CRITICAL_SECTION EventList::criticalSection;
std::map<MCONTACT, EventList::ImportDiscData> EventList::contactFileMap;
std::wstring EventList::contactFileDir;
void EventList::AddImporter(MCONTACT hContact, IImport::ImportType type, const std::wstring& file)
{
- EnterCriticalSection(&criticalSection);
+ mir_cslock lck(csEventList);
+
TCHAR buf[32];
mir_sntprintf(buf, SIZEOF(buf), _T("%016llx"), (unsigned long long int)hContact);
ImportDiscData data;
@@ -653,12 +651,10 @@ void EventList::AddImporter(MCONTACT hContact, IImport::ImportType type, const s
data.type = type;
CopyFile(file.c_str(), data.file.c_str(), FALSE);
contactFileMap[hContact] = data;
- LeaveCriticalSection(&criticalSection);
}
void EventList::Init()
{
- InitializeCriticalSection(&EventList::criticalSection);
TCHAR temp[MAX_PATH];
temp[0] = 0;
GetTempPath(MAX_PATH, temp);
@@ -668,43 +664,35 @@ void EventList::Init()
CreateDirectory(contactFileDir.c_str(), NULL);
}
-void EventList::Deinit()
-{
- DeleteCriticalSection(&EventList::criticalSection);
-}
-
int EventList::GetContactMessageNumber(MCONTACT hContact)
{
int count = db_event_count(hContact);
- EnterCriticalSection(&criticalSection);
+
+ mir_cslock lck(csEventList);
std::map<MCONTACT, EventList::ImportDiscData>::iterator it = contactFileMap.find(hContact);
if (it != contactFileMap.end())
++count;
-
- LeaveCriticalSection(&criticalSection);
return count;
}
bool EventList::IsImportedHistory(MCONTACT hContact)
{
bool count = false;
- EnterCriticalSection(&criticalSection);
+
+ mir_cslock lck(csEventList);
std::map<MCONTACT, EventList::ImportDiscData>::iterator it = contactFileMap.find(hContact);
if (it != contactFileMap.end())
count = true;
-
- LeaveCriticalSection(&criticalSection);
return count;
}
void EventList::DeleteImporter(MCONTACT hContact)
{
- EnterCriticalSection(&criticalSection);
+ mir_cslock lck(csEventList);
+
std::map<MCONTACT, EventList::ImportDiscData>::iterator it = contactFileMap.find(hContact);
if (it != contactFileMap.end()) {
DeleteFile(it->second.file.c_str());
contactFileMap.erase(it);
}
-
- LeaveCriticalSection(&criticalSection);
}
diff --git a/plugins/BasicHistory/src/EventList.h b/plugins/BasicHistory/src/EventList.h
index d2640a185e..a4f5dd885d 100644
--- a/plugins/BasicHistory/src/EventList.h
+++ b/plugins/BasicHistory/src/EventList.h
@@ -45,6 +45,7 @@ public:
};
bool isExternal;
};
+
private:
std::map<int, bool> filterMap;
bool onlyInFilter;
@@ -53,7 +54,6 @@ private:
std::wstring filterName;
std::vector<IImport::ExternalMessage> importedMessages;
DWORD goldBlobSize;
- static CRITICAL_SECTION criticalSection;
struct EventTempIndex
{
@@ -111,7 +111,6 @@ public:
bool useImportedMessages;
static void Init();
- static void Deinit();
void SetDefFilter(int filter);
int GetFilterNr();
std::wstring GetFilterName();