summaryrefslogtreecommitdiff
path: root/updater/services.cpp
diff options
context:
space:
mode:
author(no author) <(no author)@4f64403b-2f21-0410-a795-97e2b3489a10>2011-03-20 04:25:10 +0000
committer(no author) <(no author)@4f64403b-2f21-0410-a795-97e2b3489a10>2011-03-20 04:25:10 +0000
commite1d43133dc56ded6fce324f5e153b55fbe4a9ce7 (patch)
treeef96da218ae94f7cee50e895b0731b4d4c6b16f9 /updater/services.cpp
parentffc6719a95a520a4d1b0705d48faf3734ae1e9df (diff)
Fixed update detection
git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@590 4f64403b-2f21-0410-a795-97e2b3489a10
Diffstat (limited to 'updater/services.cpp')
-rw-r--r--updater/services.cpp135
1 files changed, 71 insertions, 64 deletions
diff --git a/updater/services.cpp b/updater/services.cpp
index f2b7dac..61e87c3 100644
--- a/updater/services.cpp
+++ b/updater/services.cpp
@@ -18,7 +18,8 @@ int CompareFileNameStruct(const FileNameStruct *p1, const FileNameStruct *p2)
return p1->file_id - p2->file_id;
}
-VOID CALLBACK CheckTimerProcDaily(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) {
+VOID CALLBACK CheckTimerProcDaily(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
+{
if(options.check_daily)
CallService(MS_UPDATE_CHECKFORUPDATES, (WPARAM)(is_idle && options.no_conf_idle), 0);
}
@@ -161,7 +162,8 @@ void RestoreStatus() {
DBDeleteContactSetting(0, MODULE, "SavedGlobalStatus");
}
-bool WriteLastCheckTime() {
+bool WriteLastCheckTime(void)
+{
SYSTEMTIME now;
GetSystemTime(&now);
@@ -172,8 +174,8 @@ bool WriteLastCheckTime() {
return true;
}
-void CheckForUpdatesWorker(void *param) {
-
+void CheckForUpdatesWorker(void *param)
+{
if (checking) return;
/*
// this check doesn't work on some systems - not sure which or why
@@ -395,6 +397,20 @@ void CheckForUpdatesWorker(void *param) {
hNetlibHttp = NULL;
}
+int FindFileInList(const char *name)
+{
+ int res = -1;
+ for (int i=0; i < update_list.getCount(); ++i)
+ {
+ if (strcmp(update_list[i].update.szComponentName, name) == 0)
+ {
+ res = i;
+ break;
+ }
+ }
+ return res;
+}
+
INT_PTR Restart(WPARAM wParam, LPARAM lParam) {
ExternProcess(true);
return 0;
@@ -498,14 +514,18 @@ INT_PTR GetUpdateOptions(WPARAM wParam, LPARAM lParam) {
return found ? 0 : 1;
}
-bool RegisterForFileListing(int file_id, PLUGININFO *pluginInfo, bool auto_register) {
+bool RegisterForFileListing(int file_id, PLUGININFO *pluginInfo, bool auto_register)
+{
return RegisterForFileListing(file_id, pluginInfo->shortName, pluginInfo->version, auto_register, MC_PLUGINS);
}
-bool IsRegistered(int file_id) {
+bool IsRegistered(int file_id)
+{
EnterCriticalSection(&list_cs);
- for (int i=0; i<update_list.getCount(); ++i) {
- if(update_list[i].file_id == file_id) {
+ for (int i=0; i<update_list.getCount(); ++i)
+ {
+ if (update_list[i].file_id == file_id)
+ {
LeaveCriticalSection(&list_cs);
return true; // plugin already registered
}
@@ -515,39 +535,41 @@ bool IsRegistered(int file_id) {
return false;
}
-bool RegisterForFileListing(int file_id, const char *fl_name, DWORD version, bool auto_register, const Category cat) {
+bool RegisterForFileListing(int file_id, const char *fl_name, DWORD version, bool auto_register, const Category cat)
+{
// allow multiple registration of same plugin only if new plugin not automatically registered
// if multiple registration of an auto registered plugin occurs, use newest file id and version
EnterCriticalSection(&list_cs);
- for(int i=0; i<update_list.getCount(); ++i) {
- if(strcmp(update_list[i].update.szComponentName, fl_name) == 0) {
- if(!auto_register) {
- update_list.remove(i);
- break;
- }
- if(update_list[i].auto_register) {
- update_list[i].file_id = file_id; // in case plugin file id changes (i.e. scan from xml data will overwrite settings read from db on startup)
- char version_str[16];
- update_list[i].update.pbVersion = (BYTE *)safe_strdup(CreateVersionString(version, version_str));
- update_list[i].update.cpbVersion = (int)strlen(version_str);
- }
- LeaveCriticalSection(&list_cs);
-
- // plugin already registered - set file id if AUTOREGISTER
- if(update_list[i].update.szUpdateURL && strcmp(update_list[i].update.szUpdateURL, UPDATER_AUTOREGISTER) == 0) {
- update_list[i].file_id = file_id;
- char *buff = (char *)safe_alloc(strlen(MIM_DOWNLOAD_URL_PREFIX) + 9);
- sprintf(buff, MIM_DOWNLOAD_URL_PREFIX "%d", file_id);
- update_list[i].update.szUpdateURL = buff;
- update_list[i].shortName = safe_strdup(update_list[i].update.szComponentName);
-
- if(update_list[i].update.szBetaVersionURL) {
- update_list[i].update_options.fixed = false;
- LoadUpdateOptions(update_list[i].update.szComponentName, &update_list[i].update_options);
- }
+ int i = FindFileInList(fl_name);
+ if (i >= 0 && !auto_register)
+ update_list.remove(i);
+ else if (i >= 0)
+ {
+ if (update_list[i].auto_register)
+ {
+ update_list[i].file_id = file_id; // in case plugin file id changes (i.e. scan from xml data will overwrite settings read from db on startup)
+ char version_str[16];
+ update_list[i].update.pbVersion = (BYTE *)safe_strdup(CreateVersionString(version, version_str));
+ update_list[i].update.cpbVersion = (int)strlen(version_str);
+ }
+ LeaveCriticalSection(&list_cs);
+
+ // plugin already registered - set file id if AUTOREGISTER
+ if (update_list[i].update.szUpdateURL && strcmp(update_list[i].update.szUpdateURL, UPDATER_AUTOREGISTER) == 0)
+ {
+ update_list[i].file_id = file_id;
+ char *buff = (char *)safe_alloc(strlen(MIM_DOWNLOAD_URL_PREFIX) + 9);
+ sprintf(buff, MIM_DOWNLOAD_URL_PREFIX "%d", file_id);
+ update_list[i].update.szUpdateURL = buff;
+ update_list[i].shortName = safe_strdup(update_list[i].update.szComponentName);
+
+ if(update_list[i].update.szBetaVersionURL)
+ {
+ update_list[i].update_options.fixed = false;
+ LoadUpdateOptions(update_list[i].update.szComponentName, &update_list[i].update_options);
}
- return false;
}
+ return false;
}
LeaveCriticalSection(&list_cs);
@@ -652,12 +674,8 @@ INT_PTR Register(WPARAM wParam, LPARAM lParam) {
// remove registered plugin if already there
EnterCriticalSection(&list_cs);
- for(int i=0; i<update_list.getCount(); ++i) {
- if(strcmp(update_list[i].update.szComponentName, update->szComponentName) == 0) {
- update_list.remove(i--);
- break;
- }
- }
+ int i = FindFileInList(update->szComponentName);
+ if (i >= 0) update_list.remove(i);
LeaveCriticalSection(&list_cs);
if(update->szComponentName == 0 || update->pbVersion == 0)
@@ -720,17 +738,13 @@ INT_PTR Register(WPARAM wParam, LPARAM lParam) {
}
INT_PTR RegisterFL(WPARAM wParam, LPARAM lParam) {
- int file_id = (int)wParam;
+ int file_id = (INT_PTR)wParam;
PLUGININFO *pluginInfo = (PLUGININFO *)lParam;
// remove registered plugin if already there
EnterCriticalSection(&list_cs);
- for(int i=0; i<update_list.getCount(); ++i) {
- if(strcmp(update_list[i].update.szComponentName, pluginInfo->shortName) == 0) {
- update_list.remove(i);
- break;
- }
- }
+ int i = FindFileInList(pluginInfo->shortName);
+ if (i >= 0) update_list.remove(i);
LeaveCriticalSection(&list_cs);
RegisterForFileListing(file_id, pluginInfo, false);
@@ -743,12 +757,8 @@ INT_PTR Unregister(WPARAM wParam, LPARAM lParam) {
// remove registered plugin if found
EnterCriticalSection(&list_cs);
- for(int i=0; i<update_list.getCount(); ++i) {
- if(strcmp(update_list[i].update.szComponentName, szComponentName) == 0) {
- update_list.remove(i);
- break;
- }
- }
+ int i = FindFileInList(szComponentName);
+ if (i >= 0) update_list.remove(i);
LeaveCriticalSection(&list_cs);
return 0;
@@ -805,7 +815,8 @@ int ServicesModulesLoaded(WPARAM wParam, LPARAM lParam) {
return 0;
}
-INT_PTR EnableStatusControl(WPARAM wParam, LPARAM lParam) {
+INT_PTR EnableStatusControl(WPARAM wParam, LPARAM lParam)
+{
BOOL enable = (BOOL)wParam;
options.start_offline = (enable == TRUE);
@@ -813,16 +824,12 @@ INT_PTR EnableStatusControl(WPARAM wParam, LPARAM lParam) {
return 0;
}
-INT_PTR IsUpdateSupported(WPARAM wParam, LPARAM lParam) {
+INT_PTR IsUpdateSupported(WPARAM wParam, LPARAM lParam)
+{
char *szComponentName = (char *)lParam;
- bool res = false;
+
EnterCriticalSection(&list_cs);
- for(int i=0; i<update_list.getCount(); ++i) {
- if(strcmp(update_list[i].update.szComponentName, szComponentName) == 0) {
- res = true;
- break;
- }
- }
+ bool res = FindFileInList(szComponentName) >= 0;
LeaveCriticalSection(&list_cs);
return res;