From 8f5a7b54eb953bbfc877ec915e26b3a95ec28d00 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@4f64403b-2f21-0410-a795-97e2b3489a10> Date: Sun, 21 Feb 2010 23:00:56 +0000 Subject: New updater with 3x reduced footprint and fully W7 and x64 compatible git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@476 4f64403b-2f21-0410-a795-97e2b3489a10 --- updater/services.cpp | 223 ++++++++++++++++++++++++++------------------------- 1 file changed, 112 insertions(+), 111 deletions(-) (limited to 'updater/services.cpp') diff --git a/updater/services.cpp b/updater/services.cpp index c0a7fae..4b232b1 100644 --- a/updater/services.cpp +++ b/updater/services.cpp @@ -12,19 +12,21 @@ HANDLE hStartupDone = 0; bool checking = false; -HANDLE hUpdateThread = 0; - #define NUM_SERVICES 13 HANDLE hService[NUM_SERVICES] = {0}; +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) { if(options.check_daily) CallService(MS_UPDATE_CHECKFORUPDATES, (WPARAM)(is_idle && options.no_conf_idle), 0); } - // returns true if any downloaded dll is active -bool DownloadUpdates(UpdateList *todo, FilenameMap *map, bool dlls_only) { +bool DownloadUpdates(UpdateList &todo, FilenameMap *map, bool dlls_only) { bool dll_enabled_or_langpack = false; @@ -42,19 +44,18 @@ bool DownloadUpdates(UpdateList *todo, FilenameMap *map, bool dlls_only) { } - int count = todo->size(), index = 0; TCHAR msg[512]; TCHAR *temp_str; bool a_download_succeeded = false; - for(todo->reset(); todo->current(); todo->next(), index++) { + for (int index = 0; index < todo.getCount(); index++) { // remember if the user has decided not to install this version char stored_setting[256]; - mir_snprintf(stored_setting, 256, "DisabledVer%s", todo->current()->update.szComponentName); + mir_snprintf(stored_setting, SIZEOF(stored_setting), "DisabledVer%s", todo[index].update.szComponentName); DBVARIANT dbv; - bool download = todo->current()->update_options.enabled; + bool download = todo[index].update_options.enabled; if(!DBGetContactSetting(0, "Updater", stored_setting, &dbv)) { - if(dbv.pszVal && strcmp(dbv.pszVal, todo->current()->newVersion) == 0) + if(dbv.pszVal && strcmp(dbv.pszVal, todo[index].newVersion) == 0) download = false; else DBDeleteContactSetting(0, "Updater", stored_setting); @@ -62,36 +63,37 @@ bool DownloadUpdates(UpdateList *todo, FilenameMap *map, bool dlls_only) { } if(download) { - _stprintf(msg, TranslateT("Downloading plugin: %s"), TranslateTS(temp_str = GetTString(todo->current()->update.szComponentName))); + mir_sntprintf(msg, SIZEOF(msg), TranslateT("Downloading plugin: %s"), TranslateTS(temp_str = GetTString(todo[index].update.szComponentName))); free(temp_str); } else { - _stprintf(msg, TranslateT("Skipping plugin: %s"), TranslateTS(temp_str = GetTString(todo->current()->update.szComponentName))); + mir_sntprintf(msg, SIZEOF(msg), TranslateT("Skipping plugin: %s"), TranslateTS(temp_str = GetTString(todo[index].update.szComponentName))); free(temp_str); } if(!use_popup) { PostMessage(hwndProgress, WMU_SETMESSAGE, (WPARAM)msg, 0); - PostMessage(hwndProgress, WMU_SETPROGRESS, (WPARAM)(int)(index * 100.0 / count), 0); + PostMessage(hwndProgress, WMU_SETPROGRESS, (WPARAM)(int)(index * 100.0 / todo.getCount()), 0); } //else if(hwndPop) // disabled - just annoying //ChangePopupText(hwndPop, msg); if(download) { bool got_file = false; - if(todo->current()->update_options.use_beta) { + if(todo[index].update_options.use_beta) { // download from i->update.szBetaUpdateURL to temp folder - got_file = GetFile(todo->current()->update.szBetaUpdateURL, options.temp_folder, todo->current()->update.szComponentName, todo->current()->newVersion, dlls_only); + got_file = GetFile(todo[index].update.szBetaUpdateURL, options.temp_folder, todo[index].update.szComponentName, todo[index].newVersion, dlls_only); } else { - got_file = GetFile(todo->current()->update.szUpdateURL, options.temp_folder, todo->current()->update.szComponentName, todo->current()->newVersion, dlls_only); + got_file = GetFile(todo[index].update.szUpdateURL, options.temp_folder, todo[index].update.szComponentName, todo[index].newVersion, dlls_only); } if(got_file) { a_download_succeeded = true; - if(todo->current()->file_id != -1) { - if(todo->current()->cat == MC_PLUGINS) - dll_enabled_or_langpack |= RearrangeDlls(todo->current()->shortName, (*map)[todo->current()->file_id]); - else if(todo->current()->cat == MC_LOCALIZATION) { - RearrangeLangpacks(todo->current()->shortName, (*map)[todo->current()->file_id]); + if(todo[index].file_id != -1) { + FileNameStruct* fns = map->find((FileNameStruct*)&todo[index].file_id); + if(todo[index].cat == MC_PLUGINS) + dll_enabled_or_langpack |= RearrangeDlls(todo[index].shortName, fns->list); + else if(todo[index].cat == MC_LOCALIZATION) { + RearrangeLangpacks(todo[index].shortName, fns->list); dll_enabled_or_langpack = true; } } else { @@ -113,22 +115,22 @@ bool DownloadUpdates(UpdateList *todo, FilenameMap *map, bool dlls_only) { if(hwndPop) SendMessage(hwndPop, WMU_CLOSEPOP, 0, 0); if(!a_download_succeeded) { - for(todo->reset(); todo->current(); todo->next()) - free(todo->current()->newVersion); - todo->clear(); + for(int i = 0; i < todo.getCount(); ++i) + free(todo[i].newVersion); + todo.destroy(); } return dll_enabled_or_langpack; } -void __stdcall sttNotifyStartup( DWORD_PTR dwParam ) { +void __stdcall sttNotifyStartup( void* dwParam ) { NotifyEventHooks(hStartupDone, 0, 0); } void RestoreStatus() { //NotifyEventHooks(hStartupDone, 0, 0); // do this in a seperate thread, in case we're called from an event hook to prevent double-lock on core hook critical section (csHooks) - QueueUserAPC(sttNotifyStartup, mainThread, 0); + CallFunctionAsync(sttNotifyStartup, NULL); if(options.start_offline) { // restore global status - only works on startup since we remove the SavedGlobalStatus parameter @@ -155,10 +157,9 @@ bool WriteLastCheckTime() { return true; } -//DWORD CALLBACK CheckForUpdatesWorker(LPVOID param) { -unsigned int CALLBACK CheckForUpdatesWorker(void *param) { +void CheckForUpdatesWorker(void *param) { - if(checking) return 1; + if (checking) return; /* // this check doesn't work on some systems - not sure which or why if(!(GetSystemMetrics(SM_NETWORK) & 1)) { @@ -181,7 +182,7 @@ unsigned int CALLBACK CheckForUpdatesWorker(void *param) { bool use_popup = options.popup_notify && ArePopupsEnabled(); - FilenameMap fn_map; + FilenameMap fn_map(5, CompareFileNameStruct); if(use_popup) { ShowPopup(0, TranslateT("Checking for Updates"), _T(""), POPFLAG_SAVEHWND, -1); @@ -196,7 +197,8 @@ unsigned int CALLBACK CheckForUpdatesWorker(void *param) { EnterCriticalSection(&list_cs); - if(options.use_xml_backend) { + if(options.use_xml_backend) + { if(UpdateXMLData(MC_PLUGINS)) {// prevent double error messages (in some cases) // iterate through the registered plugins if(!use_popup) PostMessage(hwndProgress, WMU_SETMESSAGE, (WPARAM)TranslateT("Scanning plugins folder"), 0); @@ -217,18 +219,18 @@ unsigned int CALLBACK CheckForUpdatesWorker(void *param) { UpdateList update_list2(update_list); LeaveCriticalSection(&list_cs); - int count = update_list2.size(), index = 0; + int count = update_list2.getCount(), index = 0; TCHAR msg[512]; TCHAR *temp_str; UpdateList todo; - for(update_list2.reset(); update_list2.current(); update_list2.next(), index++) { - if(update_list2.current()->update_options.enabled) { - _stprintf(msg, TranslateT("Checking plugin: %s"), TranslateTS(temp_str = GetTString(update_list2.current()->update.szComponentName))); + for(index = 0; index < count; index++) { + if(update_list2[index].update_options.enabled) { + mir_sntprintf(msg, SIZEOF(msg), TranslateT("Checking plugin: %s"), TranslateTS(temp_str = GetTString(update_list2[index].update.szComponentName))); free(temp_str); } else { - _stprintf(msg, TranslateT("Skipping plugin: %s"), TranslateTS(temp_str = GetTString(update_list2.current()->update.szComponentName))); + mir_sntprintf(msg, SIZEOF(msg), TranslateT("Skipping plugin: %s"), TranslateTS(temp_str = GetTString(update_list2[index].update.szComponentName))); free(temp_str); } @@ -238,13 +240,13 @@ unsigned int CALLBACK CheckForUpdatesWorker(void *param) { } //else if(hwndPop) // disabled - just annoying //ChangePopupText(hwndPop, msg); - if(update_list2.current()->update_options.enabled) { + if(update_list2[index].update_options.enabled) { char *nv; bool beta; - if(nv = UpdateRequired(update_list2.current(), &beta)) { - todo.push_back(*update_list2.current()); - todo.back().newVersion = nv; - todo.back().update_options.use_beta = beta; + if(nv = UpdateRequired(update_list2[index], &beta)) { + todo.insert(new UpdateInternal(update_list2[index])); + todo[todo.getCount()-1].newVersion = nv; + todo[todo.getCount()-1].update_options.use_beta = beta; } } if(use_popup == false && hwndProgress == 0) { @@ -263,7 +265,7 @@ unsigned int CALLBACK CheckForUpdatesWorker(void *param) { bool restore_status = true; - if(todo.size()) { + if(todo.getCount()) { int cd_ret = CD_OK; if(confirm) { if(use_popup) { @@ -275,10 +277,12 @@ unsigned int CALLBACK CheckForUpdatesWorker(void *param) { } else { if(hwndOptions) PostMessage(hwndOptions, WMU_DONECHECKING, 0, 0); RestoreStatus(); - for(todo.reset(); todo.current(); todo.next()) - free(todo.current()->newVersion); + for(int i=0; inewVersion); + for(int i=0; inewVersion); + for(int i=0; iupdate.szComponentName, &(update_list.current()->update_options), lParam); + for(int i=0; iupdate.szComponentName, szComponentName) == 0 - || _tcscmp(TranslateTS(temp1 = GetTString(update_list.current()->update.szComponentName)), (TCHAR *)szComponentName) == 0) // when set via options, szComponentName is translated and potentially already converted to unicode + for (int i=0; iupdate_options = *uo; - SaveUpdateOptions(update_list.current()->update.szComponentName, &update_list.current()->update_options); - if(update_list.current()->file_id == -1 && !uo->use_beta) { - update_list.current()->file_id = CheckForFileID(update_list.current()->update.szUpdateURL, update_list.current()->update.szVersionURL, update_list.current()->update.szComponentName); + update_list[i].update_options = *uo; + SaveUpdateOptions(update_list[i].update.szComponentName, &update_list[i].update_options); + if(update_list[i].file_id == -1 && !uo->use_beta) { + update_list[i].file_id = CheckForFileID(update_list[i].update.szUpdateURL, update_list[i].update.szVersionURL, update_list[i].update.szComponentName); } break; } @@ -441,12 +445,12 @@ INT_PTR GetUpdateOptions(WPARAM wParam, LPARAM lParam) { bool found = false; EnterCriticalSection(&list_cs); - for(update_list.reset(); update_list.current(); update_list.next()) { - if(strcmp(update_list.current()->update.szComponentName, szComponentName) == 0 - || _tcscmp(TranslateTS(temp1 = GetTString(update_list.current()->update.szComponentName)), (TCHAR *)szComponentName) == 0) // when set via options, szComponentName is translated and potentially already converted to unicode + for (int i=0; iupdate_options; + *uo = update_list[i].update_options; break; } } @@ -463,8 +467,8 @@ bool RegisterForFileListing(int file_id, PLUGININFO *pluginInfo, bool auto_regis bool IsRegistered(int file_id) { EnterCriticalSection(&list_cs); - for(update_list.reset(); update_list.current(); update_list.next()) { - if(update_list.current()->file_id == file_id) { + for (int i=0; iupdate.szComponentName, fl_name) == 0) { + for(int i=0; iauto_register) { - update_list.current()->file_id = file_id; // in case plugin file id changes (i.e. scan from xml data will overwrite settings read from db on startup) + 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.current()->update.pbVersion = (BYTE *)safe_strdup(CreateVersionString(version, version_str)); - update_list.current()->update.cpbVersion = strlen(version_str); + 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.current()->update.szUpdateURL && strcmp(update_list.current()->update.szUpdateURL, UPDATER_AUTOREGISTER) == 0) { - update_list.current()->file_id = file_id; + 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.current()->update.szUpdateURL = buff; - update_list.current()->shortName = safe_strdup(update_list.current()->update.szComponentName); + update_list[i].update.szUpdateURL = buff; + update_list[i].shortName = safe_strdup(update_list[i].update.szComponentName); - if(update_list.current()->update.szBetaVersionURL) { - update_list.current()->update_options.fixed = false; - LoadUpdateOptions(update_list.current()->update.szComponentName, &update_list.current()->update_options); + 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; @@ -519,7 +523,7 @@ bool RegisterForFileListing(int file_id, const char *fl_name, DWORD version, boo update_internal.update.szComponentName = safe_strdup(fl_name); update_internal.update.pbVersion = (BYTE *)safe_strdup(CreateVersionString(version, version_str)); - update_internal.update.cpbVersion = strlen(version_str); + update_internal.update.cpbVersion = (int)strlen(version_str); buff = (char *)safe_alloc(strlen(MIM_DOWNLOAD_URL_PREFIX) + 9); sprintf(buff, MIM_DOWNLOAD_URL_PREFIX "%d", file_id); @@ -529,7 +533,7 @@ bool RegisterForFileListing(int file_id, const char *fl_name, DWORD version, boo buff = (char *)safe_alloc(strlen("class=\"fileNameHeader\">") + strlen(fl_name) + 2); sprintf(buff, "class=\"fileNameHeader\">%s ", fl_name); update_internal.update.pbVersionPrefix = (BYTE *)buff; - update_internal.update.cpbVersionPrefix = strlen(buff); + update_internal.update.cpbVersionPrefix = (int)strlen(buff); buff = (char *)safe_alloc(strlen(MIM_VIEW_URL_PREFIX) + 9); sprintf(buff, MIM_VIEW_URL_PREFIX "%d", file_id); @@ -545,7 +549,7 @@ bool RegisterForFileListing(int file_id, const char *fl_name, DWORD version, boo LoadUpdateOptions(update_internal.update.szComponentName, &update_internal.update_options); EnterCriticalSection(&list_cs); - update_list.push_back(update_internal); + update_list.insert(new UpdateInternal(update_internal)); LeaveCriticalSection(&list_cs); return true; @@ -611,9 +615,9 @@ INT_PTR Register(WPARAM wParam, LPARAM lParam) { // remove registered plugin if already there EnterCriticalSection(&list_cs); - for(update_list.reset(); update_list.current(); update_list.next()) { - if(strcmp(update_list.current()->update.szComponentName, update->szComponentName) == 0) { - update_list.erase(); + for(int i=0; iszComponentName) == 0) { + update_list.remove(i--); break; } } @@ -643,7 +647,7 @@ INT_PTR Register(WPARAM wParam, LPARAM lParam) { char *buff = (char *)safe_alloc(strlen("class=\"fileNameHeader\">") + strlen(update->szComponentName) + 2); sprintf(buff, "class=\"fileNameHeader\">%s ", update->szComponentName); update_internal.update.pbVersionPrefix = (BYTE *)buff; - update_internal.update.cpbVersionPrefix = strlen(buff); + update_internal.update.cpbVersionPrefix = (int)strlen(buff); update_internal.shortName = safe_strdup(update->szComponentName); } else { @@ -668,7 +672,7 @@ INT_PTR Register(WPARAM wParam, LPARAM lParam) { LoadUpdateOptions(update_internal.update.szComponentName, &update_internal.update_options); EnterCriticalSection(&list_cs); - update_list.push_back(update_internal); + update_list.insert(new UpdateInternal(update_internal)); LeaveCriticalSection(&list_cs); //if(strcmp(update_internal.update.szComponentName, "My Details") == 0) { @@ -684,9 +688,9 @@ INT_PTR RegisterFL(WPARAM wParam, LPARAM lParam) { // remove registered plugin if already there EnterCriticalSection(&list_cs); - for(update_list.reset(); update_list.current(); update_list.next()) { - if(strcmp(update_list.current()->update.szComponentName, pluginInfo->shortName) == 0) { - update_list.erase(); + for(int i=0; ishortName) == 0) { + update_list.remove(i); break; } } @@ -702,9 +706,9 @@ INT_PTR Unregister(WPARAM wParam, LPARAM lParam) { // remove registered plugin if found EnterCriticalSection(&list_cs); - for(update_list.reset(); update_list.current(); update_list.next()) { - if(strcmp(update_list.current()->update.szComponentName, szComponentName) == 0) { - update_list.erase(); + for(int i=0; iupdate.szComponentName, szComponentName) == 0) { - return TRUE; + for(int i=0; i