void DlgDownloadProc() { CallFunctionAsync(CreateDownloadDialog, 0); if (!DownloadFile(pFileUrl->tszDownloadURL, pFileUrl->tszDiskPath)) { Title = TranslateT("Pack Updater"); Text = TranslateT("An error occurred while downloading the update."); if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1) && db_get_b(NULL, MODNAME, "Popups1", DEFAULT_POPUP_ENABLED)) { Number = 1; show_popup(0, Title, Text, Number, 0); } else if (db_get_b(NULL, MODNAME, "Popups1M", DEFAULT_MESSAGE_ENABLED)) MessageBox(NULL, Text, Title, MB_ICONSTOP); } CallFunctionAsync(DestroyDownloadDialog, 0); }
INT_PTR Meta_ContactMenuFunc(WPARAM hMeta, LPARAM lParam) { DBCachedContact *cc = CheckMeta(hMeta); if (cc == NULL) return 0; MCONTACT hContact = Meta_GetContactHandle(cc, (int)lParam); if (options.menu_function == FT_MSG) { // open message window if protocol supports message sending or chat, else simulate double click char *proto = GetContactProto(hContact); if (proto) { INT_PTR caps = CallProtoService(proto, PS_GETCAPS, PFLAGNUM_1, 0); if ((caps & PF1_IMSEND) || (caps & PF1_CHAT)) { // set default contact for sending/status and open message window Meta_SetSrmmSub(hMeta, hContact); db_mc_setDefaultNum(hMeta, lParam, false); CallService(MS_MSG_SENDMESSAGET, hMeta, 0); } else // protocol does not support messaging - simulate double click CallService(MS_CLIST_CONTACTDOUBLECLICKED, hContact, 0); } else // protocol does not support messaging - simulate double click CallService(MS_CLIST_CONTACTDOUBLECLICKED, hContact, 0); } else if (options.menu_function == FT_MENU) // show contact's context menu CallFunctionAsync(sttMenuThread, (void*)hContact); else if (options.menu_function == FT_INFO) // show user info for subcontact CallService(MS_USERINFO_SHOWDIALOG, hContact, 0); return 0; }
static void ReloadOptions(void *hWnd) { while (IsWindow((HWND)hWnd)) Sleep(50); CallFunctionAsync(OpenOptions, 0); }
static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_COMMAND: if (HIWORD(wParam) == STN_CLICKED) { SESSION_INFO *si = (SESSION_INFO*)PUGetPluginData(hWnd); CallFunctionAsync(ShowRoomFromPopup, si); PUDeletePopup(hWnd); return TRUE; } break; case WM_CONTEXTMENU: SESSION_INFO *si = (SESSION_INFO*)PUGetPluginData(hWnd); if (si->hContact) if (CallService(MS_CLIST_GETEVENT, (WPARAM)si->hContact, 0)) CallService(MS_CLIST_REMOVEEVENT, (WPARAM)si->hContact, (LPARAM)GC_FAKE_EVENT); if (si->hWnd && KillTimer(si->hWnd, TIMERID_FLASHWND)) FlashWindow(si->hWnd, FALSE); PUDeletePopup(hWnd); break; } return DefWindowProc(hWnd, message, wParam, lParam); }
/* Conference handlers */ void ext_yahoo_got_conf_invite(int id, const char *me, const char *who, const char *room, const char *msg, YList *members) { char z[1024]; mir_snprintf(z, Translate("[miranda] Got conference invite to room: %s with msg: %s"), room ? room : "", msg ? msg : ""); LOG(("[ext_yahoo_got_conf_invite] %s", z)); CYahooProto* ppro = getProtoById(id); if (!ppro) return; bool freeList = true; CYahooProto::ChatRoom *cm = ppro->m_chatrooms.find((CYahooProto::ChatRoom*)&room); if (!cm) { if (mir_strcmp(who, me)) { cm = new CYahooProto::ChatRoom(room, members); ppro->m_chatrooms.insert(cm); InviteChatReqParam* req = new InviteChatReqParam(room, who, msg, ppro); CallFunctionAsync(ConferenceRequestCB, req); freeList = false; } else { cm = new CYahooProto::ChatRoom(room, NULL); ppro->m_chatrooms.insert(cm); ppro->ChatStart(room); yahoo_conference_logon(id, NULL, members, room); } } if (freeList) { for (YList *l = members; l; l = l->next) free(l->data); y_list_free(members); } }
static void GetList(void *) { TCHAR tszTempPath[MAX_PATH]; DWORD dwLen = GetTempPath(_countof(tszTempPath), tszTempPath); if (tszTempPath[dwLen-1] == '\\') tszTempPath[dwLen-1] = 0; ptrT updateUrl( GetDefaultUrl()), baseUrl; SERVLIST hashes(50, CompareHashes); if (!ParseHashes(updateUrl, baseUrl, hashes)) { hListThread = NULL; return; } FILELIST *UpdateFiles = new FILELIST(20); VARST dirname(_T("%miranda_path%")); for (int i=0; i < hashes.getCount(); i++) { ServListEntry &hash = hashes[i]; TCHAR tszPath[MAX_PATH]; mir_sntprintf(tszPath, _countof(tszPath), _T("%s\\%s"), dirname, hash.m_name); if (GetFileAttributes(tszPath) == INVALID_FILE_ATTRIBUTES) { FILEINFO *FileInfo = new FILEINFO; FileInfo->bDeleteOnly = FALSE; // copy the relative old name _tcsncpy(FileInfo->tszOldName, hash.m_name, _countof(FileInfo->tszOldName)); _tcsncpy(FileInfo->tszNewName, hash.m_name, _countof(FileInfo->tszNewName)); TCHAR tszFileName[MAX_PATH]; _tcsncpy(tszFileName, _tcsrchr(tszPath, L'\\') + 1, _countof(tszFileName)); TCHAR *tp = _tcschr(tszFileName, L'.'); *tp = 0; TCHAR tszRelFileName[MAX_PATH]; _tcsncpy(tszRelFileName, hash.m_name, MAX_PATH); tp = _tcsrchr(tszRelFileName, L'.'); if (tp) *tp = 0; tp = _tcschr(tszRelFileName, L'\\'); if (tp) tp++; else tp = tszRelFileName; _tcslwr(tp); mir_sntprintf(FileInfo->File.tszDiskPath, _countof(FileInfo->File.tszDiskPath), _T("%s\\Temp\\%s.zip"), tszRoot, tszFileName); mir_sntprintf(FileInfo->File.tszDownloadURL, _countof(FileInfo->File.tszDownloadURL), _T("%s/%s.zip"), baseUrl, tszRelFileName); for (tp = _tcschr(FileInfo->File.tszDownloadURL, '\\'); tp != 0; tp = _tcschr(tp, '\\')) *tp++ = '/'; FileInfo->File.CRCsum = hash.m_crc; // Deselect all plugins by default FileInfo->bEnabled = false; UpdateFiles->insert(FileInfo); } } // Show dialog if (UpdateFiles->getCount() == 0) { ShowPopup(TranslateT("Plugin Updater"), TranslateT("List is empty."), POPUP_TYPE_INFO); delete UpdateFiles; } else CallFunctionAsync(LaunchListDialog, UpdateFiles); hListThread = NULL; }
// always gets called in main message loop static void CALLBACK BufferedProcTimer(HWND hwnd,UINT msg,UINT_PTR idTimer,DWORD currentTick) { struct BufferedCallData *buf; UINT uElapsed,uElapseNext=USER_TIMER_MAXIMUM; BUFFEREDPROC pfnBuffProc; LPARAM lParam; #ifdef _DEBUG char szDbgLine[256]; const char *pszProcName; #endif for(int i=0; i < nCallListCount; ++i) { /* find elapsed procs */ uElapsed=currentTick-callList[i].startTick; /* wraparound works */ if ((uElapsed+USER_TIMER_MINIMUM)>=callList[i].uElapse) { /* call elapsed proc */ pfnBuffProc=callList[i].pfnBuffProc; lParam=callList[i].lParam; #ifdef _DEBUG pszProcName=callList[i].pszProcName; #endif /* resize storage array */ if ((i+1)<nCallListCount) memmove(&callList[i],&callList[i+1],((nCallListCount-i-1)*sizeof(struct BufferedCallData))); --nCallListCount; --i; /* reiterate current */ if (nCallListCount) { buf=(struct BufferedCallData*)mir_realloc(callList,nCallListCount*sizeof(struct BufferedCallData)); if (buf != NULL) callList=buf; } else { mir_free(callList); callList=NULL; } #ifdef _DEBUG mir_snprintf(szDbgLine,SIZEOF(szDbgLine),"buffered call: %s(0x%X)\n",pszProcName,lParam); /* all ascii */ OutputDebugStringA(szDbgLine); #endif CallFunctionAsync((void (CALLBACK *)(void*))pfnBuffProc,(void*)lParam); /* compatible */ } /* find next timer delay */ else if ((callList[i].uElapse-uElapsed)<uElapseNext) uElapseNext=callList[i].uElapse-uElapsed; } /* set next timer */ if (nCallListCount) { #ifdef _DEBUG mir_snprintf(szDbgLine,SIZEOF(szDbgLine),"next buffered timeout: %ums\n",uElapseNext); /* all ascii */ OutputDebugStringA(szDbgLine); #endif idBufferedTimer=SetTimer(hwnd,idBufferedTimer,uElapseNext,BufferedProcTimer); /* will be reset */ } else { KillTimer(hwnd,idTimer); idBufferedTimer=0; #ifdef _DEBUG OutputDebugStringA("empty buffered queue\n"); #endif } }
void CVkProto::OnLoggedIn() { m_bOnline = true; SetServerStatus(m_iDesiredStatus); // initialize online timer CallFunctionAsync(VKSetTimer, this); }
static void __inline ShutdownAndStopWatcher(void) { HANDLE hDoneEvent = CreateEvent(NULL, FALSE, FALSE, NULL); CallFunctionAsync(MainThreadMapping, &hDoneEvent); if (hDoneEvent != NULL) { WaitForSingleObject(hDoneEvent, INFINITE); CloseHandle(hDoneEvent); } }
static void ApplyDownloads(void *param) { HWND hDlg = (HWND)param; ////////////////////////////////////////////////////////////////////////////////////// // if we need to escalate priviledges, launch a atub if (!PrepareEscalation()) { PostMessage(hDlg, WM_CLOSE, 0, 0); return; } ////////////////////////////////////////////////////////////////////////////////////// // ok, let's unpack all zips AutoHandle pipe(hPipe); HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES); OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA); //create needed folders after escalating priviledges. Folders creates when we actually install updates TCHAR tszFileTemp[MAX_PATH], tszFileBack[MAX_PATH]; mir_sntprintf(tszFileBack, _countof(tszFileBack), _T("%s\\Backups"), tszRoot); SafeCreateDirectory(tszFileBack); mir_sntprintf(tszFileTemp, _countof(tszFileTemp), _T("%s\\Temp"), tszRoot); SafeCreateDirectory(tszFileTemp); VARST tszMirandaPath(_T("%miranda_path%")); HANDLE nlc = NULL; for (int i=0; i < todo.getCount(); ++i) { ListView_EnsureVisible(hwndList, i, FALSE); if (todo[i].bEnabled) { // download update ListView_SetItemText(hwndList, i, 1, TranslateT("Downloading...")); if (DownloadFile(&todo[i].File, nlc)) { ListView_SetItemText(hwndList, i, 1, TranslateT("Succeeded.")); if (unzip(todo[i].File.tszDiskPath, tszMirandaPath, tszFileBack,false)) SafeDeleteFile(todo[i].File.tszDiskPath); // remove .zip after successful update } else ListView_SetItemText(hwndList, i, 1, TranslateT("Failed!")); } else ListView_SetItemText(hwndList, i, 1, TranslateT("Skipped.")); } Netlib_CloseHandle(nlc); ShowPopup(TranslateT("Plugin Updater"), TranslateT("Download complete"), POPUP_TYPE_INFO); int rc = MessageBox(hDlg, TranslateT("Download complete. Do you want to go to plugins option page?"), TranslateT("Plugin Updater"), MB_YESNO | MB_ICONQUESTION); if (rc == IDYES) CallFunctionAsync(OpenPluginOptions, 0); PostMessage(hDlg, WM_CLOSE, 0, 0); }
void SmileyType::RemoveObject(ISmileyBase *pObject) { int idx = m_arSmileys.getIndex(pObject); if (idx == -1) return; m_arSmileys.remove(idx); if (m_arSmileys.getCount() == 0) CallFunctionAsync(sttStopTimer, this); }
int CDropbox::OnFileDialogSuccessed(WPARAM, LPARAM lParam) { HWND hwnd = (HWND)lParam; if (hTransferWindow == hwnd) { CallFunctionAsync(EnableTabSrmmButtonSync, (void*)hTransferContact); hTransferWindow = 0; } return 0; }
void SmileyType::AddObject(ISmileyBase *pObject) { if (m_arSmileys.getCount() == 0) { if (m_xepimg == NULL) m_xepimg = AddCacheImage(m_filepath, m_index); CallFunctionAsync(sttStartTimer, this); } m_arSmileys.insert(pObject); }
void CVkProto::OnLoggedIn() { debugLogA("CVkProto::OnLoggedIn"); m_bOnline = true; SetServerStatus(m_iDesiredStatus); // initialize online timer CallFunctionAsync(VKSetTimer, this); db_unset(NULL, m_szModuleName, "LastNewsReqTime"); db_unset(NULL, m_szModuleName, "LastNotificationsReqTime"); }
void CSametimeProto::showPopup(const TCHAR* msg, SametimePopupEnum flag) { if (Miranda_Terminated()) return; PopupData *puData = (PopupData*)mir_calloc(sizeof(PopupData)); puData->flag = flag; puData->title = mir_tstrdup(m_tszUserName); puData->text = mir_tstrdup(msg); puData->proto = this; CallFunctionAsync(sttMainThreadCallback, puData); }
void GGPROTO::showpopup(const TCHAR* nickname, const TCHAR* msg, int flags) { if (Miranda_Terminated()) return; PopupData *puData = (PopupData*)mir_calloc(sizeof(PopupData)); puData->flags = flags; puData->title = mir_tstrdup(nickname); puData->text = mir_tstrdup(msg); puData->gg = this; CallFunctionAsync(sttMainThreadCallback, puData); }
void CMsnProto::MSN_ShowPopup(const TCHAR* nickname, const TCHAR* msg, int flags, const char* url, MCONTACT hContact) { if (Miranda_Terminated()) return; PopupData *pud = (PopupData*)mir_calloc(sizeof(PopupData)); pud->flags = flags; pud->url = mir_strdup(url); pud->title = mir_tstrdup(nickname); pud->text = mir_tstrdup(msg); pud->proto = this; CallFunctionAsync(sttMainThreadCallback, pud); }
void gg_showpopup(GGPROTO* gg, const char* nickname, const char* msg, int flags) { PopupData* puData; if (Miranda_Terminated()) return; puData = (PopupData*)mir_alloc(sizeof(PopupData)); puData->flags = flags; puData->title = mir_strdup(nickname); puData->text = mir_strdup(msg); puData->gg = gg; CallFunctionAsync(sttMainThreadCallback, puData); }
void CVkProto::OnLoggedOut() { m_bOnline = false; if (m_pollingConn) CallService(MS_NETLIB_SHUTDOWN, (WPARAM)m_pollingConn, 0); ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, ID_STATUS_OFFLINE); m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; CallFunctionAsync(VKUnsetTimer, this); SetAllContactStatuses(ID_STATUS_OFFLINE); m_chats.destroy(); }
static LRESULT CALLBACK PopupDlgProcRestart(HWND hPopup, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_CONTEXTMENU: PUDeletePopup(hPopup); break; case WM_COMMAND: PUDeletePopup(hPopup); CallFunctionAsync(RestartPrompt, 0); break; } return DefWindowProc(hPopup, uMsg, wParam, lParam); }
void CJabberProto::OnIqResultMucGetJidList( HXML iqNode, JABBER_MUC_JIDLIST_TYPE listType ) { const TCHAR* type; JABBER_MUC_JIDLIST_INFO *jidListInfo; if (( type = xmlGetAttrValue( iqNode, _T("type"))) == NULL ) return; if ( !lstrcmp( type, _T("result" ))) { if (( jidListInfo = new JABBER_MUC_JIDLIST_INFO ) != NULL ) { jidListInfo->type = listType; jidListInfo->ppro = this; jidListInfo->roomJid = NULL; // Set in the dialog procedure if (( jidListInfo->iqNode = xi.copyNode( iqNode )) != NULL ) CallFunctionAsync( JabberMucJidListCreateDialogApcProc, jidListInfo ); else mir_free( jidListInfo ); } } }
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) CallFunctionAsync(sttNotifyStartup, NULL); if(options.start_offline) { // restore global status - only works on startup since we remove the SavedGlobalStatus parameter WORD clist_status = DBGetContactSettingWord(0, "CList", "Status", ID_STATUS_OFFLINE), saved_global_status = DBGetContactSettingWord(0, MODULE, "SavedGlobalStatus", clist_status); if(clist_status == ID_STATUS_OFFLINE && saved_global_status != clist_status) { #ifdef DEBUG_POPUPS PUShowMessage("Updater: restoring status", SM_NOTIFY); #endif CallService(MS_CLIST_SETSTATUSMODE, (WPARAM)saved_global_status, 0); } } DBDeleteContactSetting(0, MODULE, "SavedGlobalStatus"); }
void LoadSmiley(void) { if (m_img != NULL) return; m_img = m_sml->CreateCachedImage(); if (m_img && m_img->IsAnimated() && opt.AnimateDlg) { m_nFramePosition = 0; m_img->SelectFrame(m_nFramePosition); long frtm = m_img->GetFrameDelay(); m_counter = frtm / 10 + ((frtm % 10) >= 5); regAniSmileys.insert(this); if (timerId == 0) { timerId = 0xffffffff; CallFunctionAsync(sttMainThreadCallback, NULL); } } else m_nFramePosition = m_sml->GetStaticFrame(); }
ImageBase* AddCacheImage(const CMString& file, int index) { CMString tmpfile(file); tmpfile.AppendFormat(_T("#%d"), index); unsigned id = mir_hash(tmpfile.c_str(), tmpfile.GetLength() * sizeof(TCHAR)); WaitForSingleObject(g_hMutexIm, 3000); ImageBase srch(id); ImageBase *img = g_imagecache.find(&srch); if (img == NULL) { int ind = file.ReverseFind('.'); if (ind == -1) return NULL; CMString ext = file.Mid(ind+1); ext.MakeLower(); if (ext == _T("dll") || ext == _T("exe")) img = opt.HQScaling ? (ImageBase*)new ImageType(id, file, index, icoDll) : (ImageBase*)new IconType(id, file, index, icoDll); else if (ext == _T("ico")) img = opt.HQScaling ? (ImageBase*)new ImageType(id, file, 0, icoFile) : (ImageBase*)new IconType(id, file, 0, icoFile); else if (ext == _T("icl")) img = opt.HQScaling ? (ImageBase*)new ImageType(id, file, index, icoIcl) : (ImageBase*)new IconType(id, file, index, icoIcl); else if (ext == _T("gif")) img = new ImageType(id, file, NULL); else if (fei == NULL || ext == _T("tif") || ext == _T("tiff")) img = new ImageType(id, file, NULL); else img = opt.HQScaling ? (ImageBase*)new ImageType(id, file, NULL) : (ImageBase*)new ImageFType(id, file); g_imagecache.insert(img); if (timerId == 0) { timerId = 0xffffffff; CallFunctionAsync(sttMainThreadCallback, NULL); } } else img->AddRef(); ReleaseMutex(g_hMutexIm); return img; }
static int SyncCallAPCProxy(PSYNCCALLBACKPROC pfnProc, WPARAM wParam, LPARAM lParam) { if (pfnProc == NULL) return 0; if (GetCurrentThreadId() == g_dwMainThreadID) return pfnProc(wParam, lParam); SYNCCALLITEM item; item.wParam = wParam; item.lParam = lParam; item.pfnProc = pfnProc; item.nResult = 0; item.hDoneEvent = CreateEvent(NULL, FALSE, FALSE, NULL); CallFunctionAsync(_SyncCallerUserAPCProc, &item); WaitForSingleObject(item.hDoneEvent, INFINITE); CloseHandle(item.hDoneEvent); return item.nResult; }
void CVkProto::OnLoggedOut() { debugLogA("CVkProto::OnLoggedOut"); m_bOnline = false; if (m_pollingConn) CallService(MS_NETLIB_SHUTDOWN, (WPARAM)m_pollingConn); ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, ID_STATUS_OFFLINE); m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; bool bOnline = false; { mir_cslock lck(csInstances); for (int i = 0; i < vk_Instances.getCount(); i++) bOnline = bOnline || vk_Instances[i]->IsOnline(); } if (!bOnline) CallFunctionAsync(VKUnsetTimer, this); SetAllContactStatuses(ID_STATUS_OFFLINE); m_chats.destroy(); }
static void ApplyUpdates(void *param) { HWND hDlg = (HWND)param; OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA); if (todo.getCount() == 0) { return; } // 1) If we need to escalate priviledges, launch a stub if (!PrepareEscalation()) { PostMessage(hDlg, WM_CLOSE, 0, 0); return; } AutoHandle pipe(hPipe); HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES); //create needed folders after escalating priviledges. Folders creates when we actually install updates TCHAR tszFileTemp[MAX_PATH], tszFileBack[MAX_PATH]; mir_sntprintf(tszFileBack, SIZEOF(tszFileBack), _T("%s\\Backups"), tszRoot); SafeCreateDirectory(tszFileBack); mir_sntprintf(tszFileTemp, SIZEOF(tszFileTemp), _T("%s\\Temp"), tszRoot); SafeCreateDirectory(tszFileTemp); // 2) Download all plugins HANDLE nlc = NULL; for (int i=0; i < todo.getCount(); i++) { ListView_EnsureVisible(hwndList, i, FALSE); if (!todo[i].bEnabled) { SetStringText(hwndList, i, TranslateT("Skipped.")); } else if (todo[i].bDeleteOnly) { SetStringText(hwndList, i, TranslateT("Will be deleted!")); } else { // download update SetStringText(hwndList, i, TranslateT("Downloading...")); FILEURL *pFileUrl = &todo[i].File; if (!DownloadFile(pFileUrl, nlc)) { SetStringText(hwndList, i, TranslateT("Failed!")); // interrupt update as we require all components to be updated Netlib_CloseHandle(nlc); PostMessage(hDlg, UM_ERROR, 0, 0); SkinPlaySound("updatefailed"); return; } SetStringText(hwndList, i, TranslateT("Succeeded.")); } } Netlib_CloseHandle(nlc); // 3) Unpack all zips VARST tszMirandaPath(_T("%miranda_path%")); for (int i = 0; i < todo.getCount(); i++) { FILEINFO& p = todo[i]; if (p.bEnabled) { if (p.bDeleteOnly) { // we need only to backup the old file TCHAR *ptszRelPath = p.tszNewName + _tcslen(tszMirandaPath) + 1, tszBackFile[MAX_PATH]; mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, ptszRelPath); BackupFile(p.tszNewName, tszBackFile); } else { // if file name differs, we also need to backup the old file here // otherwise it would be replaced by unzip if ( _tcsicmp(p.tszOldName, p.tszNewName)) { TCHAR tszSrcPath[MAX_PATH], tszBackFile[MAX_PATH]; mir_sntprintf(tszSrcPath, SIZEOF(tszSrcPath), _T("%s\\%s"), tszMirandaPath, p.tszOldName); mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, p.tszOldName); BackupFile(tszSrcPath, tszBackFile); } if ( unzip(p.File.tszDiskPath, tszMirandaPath, tszFileBack,true)) SafeDeleteFile(p.File.tszDiskPath); // remove .zip after successful update } } } SkinPlaySound("updatecompleted"); #if MIRANDA_VER < 0x0A00 // 4) Change title of clist ptrT title = db_get_tsa(NULL, "CList", "TitleText"); if (!_tcsicmp(title, _T("Miranda IM"))) db_set_ts(NULL, "CList", "TitleText", _T("Miranda NG")); #endif opts.bForceRedownload = false; db_unset(NULL, MODNAME, DB_SETTING_REDOWNLOAD); db_set_b(NULL, MODNAME, DB_SETTING_RESTART_COUNT, 5); // 5) Prepare Restart int rc = MessageBox(hDlg, TranslateT("Update complete. Press Yes to restart Miranda now or No to postpone a restart until the exit."), TranslateT("Plugin Updater"), MB_YESNO | MB_ICONQUESTION); PostMessage(hDlg, WM_CLOSE, 0, 0); if (rc == IDYES) #if MIRANDA_VER >= 0x0A00 CallServiceSync(MS_SYSTEM_RESTART, db_get_b(NULL, MODNAME, "RestartCurrentProfile", 1) ? 1 : 0, 0); #else CallFunctionAsync(RestartMe, 0); #endif }
static void DlgUpdateSilent(void *lParam) { OBJLIST<FILEINFO> &UpdateFiles = *(OBJLIST<FILEINFO> *)lParam; if (UpdateFiles.getCount() == 0) { delete &UpdateFiles; return; } // 1) If we need to escalate priviledges, launch a stub if (!PrepareEscalation()) { delete &UpdateFiles; return; } AutoHandle pipe(hPipe); //create needed folders after escalating priviledges. Folders creates when we actually install updates TCHAR tszFileTemp[MAX_PATH], tszFileBack[MAX_PATH]; mir_sntprintf(tszFileBack, SIZEOF(tszFileBack), _T("%s\\Backups"), tszRoot); SafeCreateDirectory(tszFileBack); mir_sntprintf(tszFileTemp, SIZEOF(tszFileTemp), _T("%s\\Temp"), tszRoot); SafeCreateDirectory(tszFileTemp); // 2) Download all plugins HANDLE nlc = NULL; // Count all updates that have been enabled int count = 0; for (int i = 0; i < UpdateFiles.getCount(); i++) { if (UpdateFiles[i].bEnabled && !UpdateFiles[i].bDeleteOnly) { // download update FILEURL *pFileUrl = &UpdateFiles[i].File; if (!DownloadFile(pFileUrl, nlc)) { // interrupt update as we require all components to be updated Netlib_CloseHandle(nlc); SkinPlaySound("updatefailed"); delete &UpdateFiles; return; } count++; } } Netlib_CloseHandle(nlc); // All available updates have been disabled if (count == 0) { delete &UpdateFiles; return; } // 3) Unpack all zips VARST tszMirandaPath(_T("%miranda_path%")); for (int i = 0; i < UpdateFiles.getCount(); i++) { FILEINFO& p = UpdateFiles[i]; if (p.bEnabled) { if (p.bDeleteOnly) { // we need only to backup the old file TCHAR *ptszRelPath = p.tszNewName + _tcslen(tszMirandaPath) + 1, tszBackFile[MAX_PATH]; mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, ptszRelPath); BackupFile(p.tszNewName, tszBackFile); } else { // if file name differs, we also need to backup the old file here // otherwise it would be replaced by unzip if (_tcsicmp(p.tszOldName, p.tszNewName)) { TCHAR tszSrcPath[MAX_PATH], tszBackFile[MAX_PATH]; mir_sntprintf(tszSrcPath, SIZEOF(tszSrcPath), _T("%s\\%s"), tszMirandaPath, p.tszOldName); mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, p.tszOldName); BackupFile(tszSrcPath, tszBackFile); } // remove .zip after successful update if (unzip(p.File.tszDiskPath, tszMirandaPath, tszFileBack, true)) SafeDeleteFile(p.File.tszDiskPath); } } } delete &UpdateFiles; SkinPlaySound("updatecompleted"); #if MIRANDA_VER < 0x0A00 // 4) Change title of clist ptrT title = db_get_tsa(NULL, "CList", "TitleText"); if (!_tcsicmp(title, _T("Miranda IM"))) db_set_ts(NULL, "CList", "TitleText", _T("Miranda NG")); #endif opts.bForceRedownload = false; db_unset(NULL, MODNAME, DB_SETTING_REDOWNLOAD); db_set_b(NULL, MODNAME, DB_SETTING_RESTART_COUNT, 5); db_set_b(NULL, MODNAME, DB_SETTING_NEED_RESTART, 1); // 5) Prepare Restart TCHAR tszTitle[100]; mir_sntprintf(tszTitle, SIZEOF(tszTitle), TranslateT("%d component(s) was updated"), count); if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1)) { ShowPopup(tszTitle,TranslateT("You need to restart your Miranda to apply installed updates."),POPUP_TYPE_MSG); } else { bool notified = false; if (ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) { MIRANDASYSTRAYNOTIFY err; err.szProto = MODULEA; err.cbSize = sizeof(err); err.dwInfoFlags = NIIF_INTERN_UNICODE | NIIF_INFO; err.tszInfoTitle = tszTitle; err.tszInfo = TranslateT("You need to restart your Miranda to apply installed updates."); err.uTimeout = 30000; notified = !CallService(MS_CLIST_SYSTRAY_NOTIFY, 0, (LPARAM)&err); } if (!notified) { // Error, let's try to show MessageBox as last way to inform user about successful update TCHAR tszText[200]; mir_sntprintf(tszText, SIZEOF(tszText), _T("%s\n\n%s"), TranslateT("You need to restart your Miranda to apply installed updates."), TranslateT("Would you like to restart it now?")); if (MessageBox(NULL, tszText, tszTitle, MB_ICONINFORMATION | MB_YESNO) == IDYES) #if MIRANDA_VER >= 0x0A00 CallServiceSync(MS_SYSTEM_RESTART, db_get_b(NULL, MODNAME, "RestartCurrentProfile", 1) ? 1 : 0, 0); #else CallFunctionAsync(RestartMe, 0); #endif } } }
static void __cdecl GuiOutThread(LPVOID di) { GCHOOK* gch = (GCHOOK*)di; CallFunctionAsync(OnHook, (void*)gch); }
static void TSAPI Chat_OpenPopup(SESSION_INFO *si, HWND hwndPopup) { CallFunctionAsync(ShowRoomFromPopup, si); PUDeletePopup(hwndPopup); }