BOOL GetVolumeCaps( char *rootpath, /* filepath, or NULL */ char *name, /* filename associated with rootpath */ PVOLUMECAPS VolumeCaps /* result structure describing capabilities */ ) { char TempRootPath[MAX_PATH + 1]; DWORD cchTempRootPath = 0; BOOL bSuccess = TRUE; /* assume success until told otherwise */ if(!bInitialized) if(!Initialize()) return FALSE; /* process the input path to produce a consistent path suitable for compare operations and also suitable for certain picky Win32 API that don't like forward slashes */ if(rootpath != NULL && rootpath[0] != '\0') { DWORD i; cchTempRootPath = lstrlenA(rootpath); if(cchTempRootPath > MAX_PATH) return FALSE; /* copy input, converting forward slashes to back slashes as we go */ for(i = 0 ; i <= cchTempRootPath ; i++) { if(rootpath[i] == '/') TempRootPath[i] = '\\'; else TempRootPath[i] = rootpath[i]; } /* check for UNC and Null terminate or append trailing \ as appropriate */ /* possible valid UNCs we are passed follow: \\machine\foo\bar (path is \\machine\foo\) \\machine\foo (path is \\machine\foo\) \\machine\foo\ \\.\c$\ (FIXFIX: Win32API doesn't like this - GetComputerName()) LATERLATER: handling mounted DFS drives in the future will require slightly different logic which isn't available today. This is required because directories can point at different servers which have differing capabilities. */ if(TempRootPath[0] == '\\' && TempRootPath[1] == '\\') { DWORD slash = 0; for(i = 2 ; i < cchTempRootPath ; i++) { if(TempRootPath[i] == '\\') { slash++; if(slash == 2) { i++; TempRootPath[i] = '\0'; cchTempRootPath = i; break; } } } /* if there was only one slash found, just tack another onto the end */ if(slash == 1 && TempRootPath[cchTempRootPath] != '\\') { TempRootPath[cchTempRootPath] = TempRootPath[0]; /* '\\' */ TempRootPath[cchTempRootPath+1] = '\0'; cchTempRootPath++; } } else { if(TempRootPath[1] == ':') { /* drive letter specified, truncate to root */ TempRootPath[2] = '\\'; TempRootPath[3] = '\0'; cchTempRootPath = 3; } else { /* must be file on current drive */ TempRootPath[0] = '\0'; cchTempRootPath = 0; } } } /* if path != NULL */ /* grab lock protecting cached entry */ EnterCriticalSection( &VolumeCapsLock ); if(!g_VolumeCaps.bValid || lstrcmpiA(g_VolumeCaps.RootPath, TempRootPath) != 0) { /* no match found, build up new entry */ DWORD dwFileSystemFlags; DWORD dwRemotePrivileges = 0; BOOL bRemote = FALSE; /* release lock during expensive operations */ LeaveCriticalSection( &VolumeCapsLock ); bSuccess = GetVolumeInformationA( (TempRootPath[0] == '\0') ? NULL : TempRootPath, NULL, 0, NULL, NULL, &dwFileSystemFlags, NULL, 0); /* only if target volume supports Acls, and we were told to use privileges do we need to go out and test for the remote case */ if(bSuccess && (dwFileSystemFlags & FS_PERSISTENT_ACLS) && VolumeCaps->bUsePrivileges) { if(GetDriveTypeA( (TempRootPath[0] == '\0') ? NULL : TempRootPath ) == DRIVE_REMOTE) { bRemote = TRUE; /* make a determination about our remote capabilities */ GetRemotePrivilegesSet(name, &dwRemotePrivileges); } } /* always take the lock again, since we release it below */ EnterCriticalSection( &VolumeCapsLock ); /* replace the existing data if successful */ if(bSuccess) { lstrcpynA(g_VolumeCaps.RootPath, TempRootPath, cchTempRootPath+1); g_VolumeCaps.dwFileSystemFlags = dwFileSystemFlags; g_VolumeCaps.bRemote = bRemote; g_VolumeCaps.dwRemotePrivileges = dwRemotePrivileges; g_VolumeCaps.bValid = TRUE; } } if(bSuccess) { /* copy input elements */ g_VolumeCaps.bUsePrivileges = VolumeCaps->bUsePrivileges; g_VolumeCaps.dwFileAttributes = VolumeCaps->dwFileAttributes; /* give caller results */ memcpy(VolumeCaps, &g_VolumeCaps, sizeof(VOLUMECAPS)); } else { g_VolumeCaps.bValid = FALSE; } LeaveCriticalSection( &VolumeCapsLock ); /* release lock */ return bSuccess; }
void PaintClc(HWND hwnd, struct ClcData *dat, HDC hdc, RECT * rcPaint) { HDC hdcMem; RECT clRect; int y, indent, index, fontHeight; struct ClcGroup *group; HFONT hOldFont; DWORD style = GetWindowLong(hwnd, GWL_STYLE); int status = GetGeneralisedStatus(); int grey = 0, groupCountsFontTopShift; HBRUSH hBrushAlternateGrey = NULL; // yes I know about GetSysColorBrush() COLORREF tmpbkcolour = style & CLS_CONTACTLIST ? (dat->useWindowsColours ? GetSysColor(COLOR_3DFACE) : dat->bkColour) : dat->bkColour; if (dat->greyoutFlags & pcli->pfnClcStatusToPf2(status) || style & WS_DISABLED) grey = 1; else if (GetFocus() != hwnd && dat->greyoutFlags & GREYF_UNFOCUS) grey = 1; GetClientRect(hwnd, &clRect); if (rcPaint == NULL) rcPaint = &clRect; if (IsRectEmpty(rcPaint)) return; y = -dat->yScroll; hdcMem = CreateCompatibleDC(hdc); HBITMAP hBmpOsb = CreateBitmap(clRect.right, clRect.bottom, 1, GetDeviceCaps(hdc, BITSPIXEL), NULL); HBITMAP hOldBitmap = (HBITMAP)SelectObject(hdcMem, hBmpOsb); { TEXTMETRIC tm; hOldFont = (HFONT)SelectObject(hdcMem, dat->fontInfo[FONTID_GROUPS].hFont); GetTextMetrics(hdcMem, &tm); groupCountsFontTopShift = tm.tmAscent; SelectObject(hdcMem, dat->fontInfo[FONTID_GROUPCOUNTS].hFont); GetTextMetrics(hdcMem, &tm); groupCountsFontTopShift -= tm.tmAscent; } if (style & CLS_GREYALTERNATE) hBrushAlternateGrey = CreateSolidBrush(GetNearestColor(hdcMem, RGB(GetRValue(tmpbkcolour) - 10, GetGValue(tmpbkcolour) - 10, GetBValue(tmpbkcolour) - 10))); ChangeToFont(hdcMem, dat, FONTID_CONTACTS, &fontHeight); SetBkMode(hdcMem, TRANSPARENT); { HBRUSH hBrush; hBrush = CreateSolidBrush(tmpbkcolour); FillRect(hdcMem, rcPaint, hBrush); DeleteObject(hBrush); if (dat->hBmpBackground) { BITMAP bmp; HDC hdcBmp; int x, y; int maxx, maxy; int destw, desth; // XXX: Halftone isnt supported on 9x, however the scretch problems dont happen on 98. SetStretchBltMode(hdcMem, HALFTONE); GetObject(dat->hBmpBackground, sizeof(bmp), &bmp); hdcBmp = CreateCompatibleDC(hdcMem); SelectObject(hdcBmp, dat->hBmpBackground); y = dat->backgroundBmpUse & CLBF_SCROLL ? -dat->yScroll : 0; maxx = dat->backgroundBmpUse & CLBF_TILEH ? clRect.right : 1; maxy = dat->backgroundBmpUse & CLBF_TILEV ? maxy = rcPaint->bottom : y + 1; switch (dat->backgroundBmpUse & CLBM_TYPE) { case CLB_STRETCH: if (dat->backgroundBmpUse & CLBF_PROPORTIONAL) { if (clRect.right * bmp.bmHeight < clRect.bottom * bmp.bmWidth) { desth = clRect.bottom; destw = desth * bmp.bmWidth / bmp.bmHeight; } else { destw = clRect.right; desth = destw * bmp.bmHeight / bmp.bmWidth; } } else { destw = clRect.right; desth = clRect.bottom; } break; case CLB_STRETCHH: if (dat->backgroundBmpUse & CLBF_PROPORTIONAL) { destw = clRect.right; desth = destw * bmp.bmHeight / bmp.bmWidth; } else { destw = clRect.right; desth = bmp.bmHeight; } break; case CLB_STRETCHV: if (dat->backgroundBmpUse & CLBF_PROPORTIONAL) { desth = clRect.bottom; destw = desth * bmp.bmWidth / bmp.bmHeight; } else { destw = bmp.bmWidth; desth = clRect.bottom; } break; default: //clb_topleft destw = bmp.bmWidth; desth = bmp.bmHeight; break; } for (; y < maxy; y += desth) { if (y < rcPaint->top - desth) continue; for (x = 0; x < maxx; x += destw) StretchBlt(hdcMem, x, y, destw, desth, hdcBmp, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY); } DeleteDC(hdcBmp); } } group = &dat->list; group->scanIndex = 0; indent = 0; for (index = 0; y < rcPaint->bottom;) { if (group->scanIndex == group->cl.count) { group = group->parent; indent--; if (group == NULL) break; group->scanIndex++; continue; } if (y > rcPaint->top - dat->rowHeight) { int iImage = -1; int selected = index == dat->selection && (dat->showSelAlways || dat->exStyle & CLS_EX_SHOWSELALWAYS || GetFocus() == hwnd) && group->cl.items[group->scanIndex]->type != CLCIT_DIVIDER; int hottrack = dat->exStyle & CLS_EX_TRACKSELECT && group->cl.items[group->scanIndex]->type != CLCIT_DIVIDER && dat->iHotTrack == index; SIZE textSize, countsSize, spaceSize; int width, checkboxWidth; char *szCounts; //alternating grey if (style & CLS_GREYALTERNATE && index & 1) { RECT rc; rc.top = y; rc.bottom = rc.top + dat->rowHeight; rc.left = 0; rc.right = clRect.right; FillRect(hdcMem, &rc, hBrushAlternateGrey); } //setup if (group->cl.items[group->scanIndex]->type == CLCIT_GROUP) ChangeToFont(hdcMem, dat, FONTID_GROUPS, &fontHeight); else if (group->cl.items[group->scanIndex]->type == CLCIT_INFO) { if (group->cl.items[group->scanIndex]->flags & CLCIIF_GROUPFONT) ChangeToFont(hdcMem, dat, FONTID_GROUPS, &fontHeight); else ChangeToFont(hdcMem, dat, FONTID_CONTACTS, &fontHeight); } else if (group->cl.items[group->scanIndex]->type == CLCIT_DIVIDER) ChangeToFont(hdcMem, dat, FONTID_DIVIDERS, &fontHeight); else if (group->cl.items[group->scanIndex]->type == CLCIT_CONTACT && group->cl.items[group->scanIndex]->flags & CONTACTF_NOTONLIST) ChangeToFont(hdcMem, dat, FONTID_NOTONLIST, &fontHeight); else if (group->cl.items[group->scanIndex]->type == CLCIT_CONTACT && ((group->cl.items[group->scanIndex]->flags & CONTACTF_INVISTO && GetRealStatus(group->cl.items[group->scanIndex], status) != ID_STATUS_INVISIBLE) || (group->cl.items[group->scanIndex]->flags & CONTACTF_VISTO && GetRealStatus(group->cl.items[group->scanIndex], status) == ID_STATUS_INVISIBLE) ) ) { // the contact is in the always visible list and the proto is invisible // the contact is in the always invisible and the proto is in any other mode ChangeToFont(hdcMem, dat, group->cl.items[group->scanIndex]->flags & CONTACTF_ONLINE ? FONTID_INVIS : FONTID_OFFINVIS, &fontHeight); } else if (group->cl.items[group->scanIndex]->type == CLCIT_CONTACT && !(group->cl.items[group->scanIndex]->flags & CONTACTF_ONLINE)) ChangeToFont(hdcMem, dat, FONTID_OFFLINE, &fontHeight); else ChangeToFont(hdcMem, dat, FONTID_CONTACTS, &fontHeight); GetTextExtentPoint32(hdcMem, group->cl.items[group->scanIndex]->szText, lstrlen(group->cl.items[group->scanIndex]->szText), &textSize); width = textSize.cx; if (group->cl.items[group->scanIndex]->type == CLCIT_GROUP) { szCounts = pcli->pfnGetGroupCountsText(dat, group->cl.items[group->scanIndex]); if (szCounts[0]) { GetTextExtentPoint32A(hdcMem, " ", 1, &spaceSize); ChangeToFont(hdcMem, dat, FONTID_GROUPCOUNTS, &fontHeight); GetTextExtentPoint32A(hdcMem, szCounts, lstrlenA(szCounts), &countsSize); width += spaceSize.cx + countsSize.cx; } } if ((style & CLS_CHECKBOXES && group->cl.items[group->scanIndex]->type == CLCIT_CONTACT) || (style & CLS_GROUPCHECKBOXES && group->cl.items[group->scanIndex]->type == CLCIT_GROUP) || (group->cl.items[group->scanIndex]->type == CLCIT_INFO && group->cl.items[group->scanIndex]->flags & CLCIIF_CHECKBOX)) checkboxWidth = dat->checkboxSize + 2; else checkboxWidth = 0; //background if (selected) { int x = dat->leftMargin + indent * dat->groupIndent + checkboxWidth + dat->iconXSpace - 2; ImageList_DrawEx(dat->himlHighlight, 0, hdcMem, x, y, min(width + 5, clRect.right - x), dat->rowHeight, CLR_NONE, CLR_NONE, dat->exStyle & CLS_EX_NOTRANSLUCENTSEL ? ILD_NORMAL : ILD_BLEND25); SetTextColor(hdcMem, dat->selTextColour); } else if (hottrack) SetHotTrackColour(hdcMem, dat); //checkboxes if (checkboxWidth) { RECT rc; HANDLE hTheme = OpenThemeData(hwnd, L"BUTTON"); rc.left = dat->leftMargin + indent * dat->groupIndent; rc.right = rc.left + dat->checkboxSize; rc.top = y + ((dat->rowHeight - dat->checkboxSize) >> 1); rc.bottom = rc.top + dat->checkboxSize; DrawThemeBackground(hTheme, hdcMem, BP_CHECKBOX, group->cl.items[group->scanIndex]->flags & CONTACTF_CHECKED ? (hottrack ? CBS_CHECKEDHOT : CBS_CHECKEDNORMAL) : (hottrack ? CBS_UNCHECKEDHOT : CBS_UNCHECKEDNORMAL), &rc, &rc); CloseThemeData(hTheme); } //icon if (group->cl.items[group->scanIndex]->type == CLCIT_GROUP) iImage = group->cl.items[group->scanIndex]->group->expanded ? IMAGE_GROUPOPEN : IMAGE_GROUPSHUT; else if (group->cl.items[group->scanIndex]->type == CLCIT_CONTACT) iImage = group->cl.items[group->scanIndex]->iImage; if (iImage != -1) { /*COLORREF colourFg=dat->selBkColour; int mode=ILD_NORMAL; if(selected) mode=ILD_SELECTED; else if(hottrack) {mode=ILD_FOCUS; colourFg=dat->hotTextColour;} else if(group->cl.items[group->scanIndex]->type==CLCIT_CONTACT && group->cl.items[group->scanIndex]->flags&CONTACTF_NOTONLIST) {colourFg=dat->fontInfo[FONTID_NOTONLIST].colour; mode=ILD_BLEND50;} ImageList_DrawEx(himlCListClc,iImage,hdcMem,dat->leftMargin+indent*dat->groupIndent+checkboxWidth,y+((dat->rowHeight-16)>>1),0,0,CLR_NONE,colourFg,mode); */ // this doesnt use CLS_CONTACTLIST since the colour prolly wont match anyway COLORREF colourFg = dat->selBkColour; int mode = ILD_NORMAL; if (hottrack) { colourFg = dat->hotTextColour; } else if (group->cl.items[group->scanIndex]->type == CLCIT_CONTACT && group->cl.items[group->scanIndex]->flags & CONTACTF_NOTONLIST) { colourFg = dat->fontInfo[FONTID_NOTONLIST].colour; mode = ILD_BLEND50; } if (group->cl.items[group->scanIndex]->type == CLCIT_CONTACT && dat->showIdle && (group->cl.items[group->scanIndex]->flags & CONTACTF_IDLE) && GetRealStatus(group->cl.items[group->scanIndex], ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) mode = ILD_SELECTED; ImageList_DrawEx(himlCListClc, iImage, hdcMem, dat->leftMargin + indent * dat->groupIndent + checkboxWidth, y + ((dat->rowHeight - 16) >> 1), 0, 0, CLR_NONE, colourFg, mode); } //text if (group->cl.items[group->scanIndex]->type == CLCIT_DIVIDER) { RECT rc; rc.top = y + (dat->rowHeight >> 1); rc.bottom = rc.top + 2; rc.left = dat->leftMargin + indent * dat->groupIndent; rc.right = rc.left + ((clRect.right - rc.left - textSize.cx) >> 1) - 3; DrawEdge(hdcMem, &rc, BDR_SUNKENOUTER, BF_RECT); TextOut(hdcMem, rc.right + 3, y + ((dat->rowHeight - fontHeight) >> 1), group->cl.items[group->scanIndex]->szText, lstrlen(group->cl.items[group->scanIndex]->szText)); rc.left = rc.right + 6 + textSize.cx; rc.right = clRect.right; DrawEdge(hdcMem, &rc, BDR_SUNKENOUTER, BF_RECT); }
/*********************************************************************** * register_coclasses */ static HRESULT register_coclasses(struct regsvr_coclass const *list) { LONG res = ERROR_SUCCESS; HKEY coclass_key; res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL); if (res != ERROR_SUCCESS) goto error_return; for (; res == ERROR_SUCCESS && list->clsid; ++list) { WCHAR buf[39]; HKEY clsid_key; StringFromGUID2(list->clsid, buf, 39); res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL); if (res != ERROR_SUCCESS) goto error_close_coclass_key; if (list->name) { res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ, (CONST BYTE*)(list->name), strlen(list->name) + 1); if (res != ERROR_SUCCESS) goto error_close_clsid_key; } if (list->ips) { res = register_key_defvalueA(clsid_key, ips_keyname, list->ips); if (res != ERROR_SUCCESS) goto error_close_clsid_key; } if (list->ips32) { HKEY ips32_key; res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &ips32_key, NULL); if (res != ERROR_SUCCESS) goto error_close_clsid_key; res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ, (CONST BYTE*)list->ips32, lstrlenA(list->ips32) + 1); if (res == ERROR_SUCCESS && list->ips32_tmodel) res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ, (CONST BYTE*)list->ips32_tmodel, strlen(list->ips32_tmodel) + 1); RegCloseKey(ips32_key); if (res != ERROR_SUCCESS) goto error_close_clsid_key; } if (list->clsid_str) { res = register_key_defvalueA(clsid_key, clsid_keyname, list->clsid_str); if (res != ERROR_SUCCESS) goto error_close_clsid_key; } if (list->progid) { HKEY progid_key; res = register_key_defvalueA(clsid_key, progid_keyname, list->progid); if (res != ERROR_SUCCESS) goto error_close_clsid_key; res = RegCreateKeyExA(HKEY_CLASSES_ROOT, list->progid, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &progid_key, NULL); if (res != ERROR_SUCCESS) goto error_close_clsid_key; res = register_key_defvalueW(progid_key, clsid_keyname, buf); RegCloseKey(progid_key); if (res != ERROR_SUCCESS) goto error_close_clsid_key; } error_close_clsid_key: RegCloseKey(clsid_key); } error_close_coclass_key: RegCloseKey(coclass_key); error_return: return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK; }
static void test_VerQueryValueA(void) { static const char * const value_name[] = { "Product", "CompanyName", "FileDescription", "Internal", "ProductVersion", "InternalName", "File", "LegalCopyright", "FileVersion", "Legal", "OriginalFilename", "ProductName", "Company", "Original" }; char *ver, *p; UINT len, ret, translation, i; char buf[MAX_PATH]; ret = GetModuleFileNameA(NULL, buf, sizeof(buf)); assert(ret); SetLastError(0xdeadbeef); len = GetFileVersionInfoSizeA(buf, NULL); ok(len, "GetFileVersionInfoSizeA(%s) error %u\n", buf, GetLastError()); ver = HeapAlloc(GetProcessHeap(), 0, len); assert(ver); SetLastError(0xdeadbeef); ret = GetFileVersionInfoA(buf, 0, len, ver); ok(ret, "GetFileVersionInfoA error %u\n", GetLastError()); p = (char *)0xdeadbeef; len = 0xdeadbeef; SetLastError(0xdeadbeef); ret = VerQueryValueA(ver, "\\VarFileInfo\\Translation", (LPVOID*)&p, &len); ok(ret, "VerQueryValue error %u\n", GetLastError()); ok(len == 4, "VerQueryValue returned %u, expected 4\n", len); translation = *(UINT *)p; translation = MAKELONG(HIWORD(translation), LOWORD(translation)); p = (char *)0xdeadbeef; len = 0xdeadbeef; SetLastError(0xdeadbeef); ret = VerQueryValueA(ver, "String", (LPVOID*)&p, &len); ok(!ret, "VerQueryValue should fail\n"); ok(GetLastError() == ERROR_RESOURCE_TYPE_NOT_FOUND || GetLastError() == 0xdeadbeef /* NT4, W2K */, "VerQueryValue returned %u\n", GetLastError()); ok(p == (char *)0xdeadbeef, "expected 0xdeadbeef got %p\n", p); ok(len == 0, "expected 0 got %x\n", len); p = (char *)0xdeadbeef; len = 0xdeadbeef; SetLastError(0xdeadbeef); ret = VerQueryValueA(ver, "StringFileInfo", (LPVOID*)&p, &len); ok(ret, "VerQueryValue error %u\n", GetLastError()); ok(len == 0, "VerQueryValue returned %u, expected 0\n", len); ok(p != (char *)0xdeadbeef, "not expected 0xdeadbeef\n"); p = (char *)0xdeadbeef; len = 0xdeadbeef; SetLastError(0xdeadbeef); ret = VerQueryValueA(ver, "\\StringFileInfo", (LPVOID*)&p, &len); ok(ret, "VerQueryValue error %u\n", GetLastError()); ok(len == 0, "VerQueryValue returned %u, expected 0\n", len); ok(p != (char *)0xdeadbeef, "not expected 0xdeadbeef\n"); p = (char *)0xdeadbeef; len = 0xdeadbeef; SetLastError(0xdeadbeef); ret = VerQueryValueA(ver, "\\\\StringFileInfo", (LPVOID*)&p, &len); ok(ret, "VerQueryValue error %u\n", GetLastError()); ok(len == 0, "VerQueryValue returned %u, expected 0\n", len); ok(p != (char *)0xdeadbeef, "not expected 0xdeadbeef\n"); p = (char *)0xdeadbeef; len = 0xdeadbeef; SetLastError(0xdeadbeef); ret = VerQueryValueA(ver, "\\StringFileInfo\\\\", (LPVOID*)&p, &len); ok(ret, "VerQueryValue error %u\n", GetLastError()); ok(len == 0, "VerQueryValue returned %u, expected 0\n", len); ok(p != (char *)0xdeadbeef, "not expected 0xdeadbeef\n"); sprintf(buf, "\\StringFileInfo\\%08x", translation); p = (char *)0xdeadbeef; len = 0xdeadbeef; SetLastError(0xdeadbeef); ret = VerQueryValueA(ver, buf, (LPVOID*)&p, &len); ok(ret, "VerQueryValue error %u\n", GetLastError()); ok(len == 0, "VerQueryValue returned %u, expected 0\n", len); ok(p != (char *)0xdeadbeef, "not expected 0xdeadbeef\n"); for (i = 0; i < ARRAY_SIZE(value_name); i++) { sprintf(buf, "\\StringFileInfo\\%08x\\%s", translation, value_name[i]); p = (char *)0xdeadbeef; len = 0xdeadbeef; SetLastError(0xdeadbeef); ret = VerQueryValueA(ver, buf, (LPVOID*)&p, &len); ok(ret, "VerQueryValueA(%s) error %u\n", buf, GetLastError()); ok(len == strlen(value_name[i]) + 1, "VerQueryValue returned %u\n", len); ok(!strcmp(value_name[i], p), "expected \"%s\", got \"%s\"\n", value_name[i], p); /* test partial value names */ len = lstrlenA(buf); buf[len - 2] = 0; p = (char *)0xdeadbeef; len = 0xdeadbeef; SetLastError(0xdeadbeef); ret = VerQueryValueA(ver, buf, (LPVOID*)&p, &len); ok(!ret, "VerQueryValueA(%s) succeeded\n", buf); ok(GetLastError() == ERROR_RESOURCE_TYPE_NOT_FOUND || GetLastError() == 0xdeadbeef /* NT4, W2K */, "VerQueryValue returned %u\n", GetLastError()); ok(p == (char *)0xdeadbeef, "expected 0xdeadbeef got %p\n", p); ok(len == 0, "expected 0 or 0xbeef, got %x\n", len); } HeapFree(GetProcessHeap(), 0, ver); }
/*********************************************************************** * lstrlen (KERNEL.90) */ INT16 WINAPI lstrlen16( LPCSTR str ) { return (INT16)lstrlenA( str ); }
static void testGetModuleFileName(const char* name) { HMODULE hMod; char bufA[MAX_PATH]; WCHAR bufW[MAX_PATH]; DWORD len1A, len1W = 0, len2A, len2W = 0; hMod = (name) ? GetModuleHandleA(name) : NULL; /* first test, with enough space in buffer */ memset(bufA, '-', sizeof(bufA)); SetLastError(0xdeadbeef); len1A = GetModuleFileNameA(hMod, bufA, sizeof(bufA)); ok(GetLastError() == ERROR_SUCCESS || broken(GetLastError() == 0xdeadbeef), /* <= XP SP3 */ "LastError was not reset: %u\n", GetLastError()); ok(len1A > 0, "Getting module filename for handle %p\n", hMod); if (is_unicode_enabled) { memset(bufW, '-', sizeof(bufW)); SetLastError(0xdeadbeef); len1W = GetModuleFileNameW(hMod, bufW, sizeof(bufW) / sizeof(WCHAR)); ok(GetLastError() == ERROR_SUCCESS || broken(GetLastError() == 0xdeadbeef), /* <= XP SP3 */ "LastError was not reset: %u\n", GetLastError()); ok(len1W > 0, "Getting module filename for handle %p\n", hMod); } ok(len1A == strlen(bufA), "Unexpected length of GetModuleFilenameA (%d/%d)\n", len1A, lstrlenA(bufA)); if (is_unicode_enabled) { ok(len1W == lstrlenW(bufW), "Unexpected length of GetModuleFilenameW (%d/%d)\n", len1W, lstrlenW(bufW)); ok(cmpStrAW(bufA, bufW, len1A, len1W), "Comparing GetModuleFilenameAW results\n"); } /* second test with a buffer too small */ memset(bufA, '-', sizeof(bufA)); len2A = GetModuleFileNameA(hMod, bufA, len1A / 2); ok(len2A > 0, "Getting module filename for handle %p\n", hMod); if (is_unicode_enabled) { memset(bufW, '-', sizeof(bufW)); len2W = GetModuleFileNameW(hMod, bufW, len1W / 2); ok(len2W > 0, "Getting module filename for handle %p\n", hMod); ok(cmpStrAW(bufA, bufW, len2A, len2W), "Comparing GetModuleFilenameAW results with buffer too small\n" ); ok(len1W / 2 == len2W, "Correct length in GetModuleFilenameW with buffer too small (%d/%d)\n", len1W / 2, len2W); } ok(len1A / 2 == len2A || len1A / 2 == len2A + 1, /* Win9x */ "Correct length in GetModuleFilenameA with buffer too small (%d/%d)\n", len1A / 2, len2A); }
extern "C" int __declspec(dllexport) CListInitialise(PLUGINLINK * link) { int rc = 0; DBVARIANT dbv; int i; char szProfilePath[MAX_PATH]; pluginLink = link; #ifdef _DEBUG _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); #endif mir_getMMI(&mmi); mir_getLI(&li); mir_getTMI(&tmi); mir_getLP( &pluginInfo ); API::onInit(); LoadCLCButtonModule(); RegisterCLUIFrameClasses(); ZeroMemory((void*) &cfg::dat, sizeof(cfg::dat)); int iCount = CallService(MS_DB_CONTACT_GETCOUNT, 0, 0); iCount += 20; if( iCount < 300 ) iCount = 300; cfg::eCache = reinterpret_cast<TExtraCache *>(malloc(sizeof(TExtraCache) * iCount)); ZeroMemory(cfg::eCache, sizeof(struct TExtraCache) * iCount); cfg::nextCacheEntry = 0; cfg::maxCacheEntry = iCount; cfg::init(); cfg::dat.toolbarVisibility = cfg::getDword("CLUI", "TBVisibility", DEFAULT_TB_VISIBILITY); cfg::dat.hMenuButtons = GetSubMenu(LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_CONTEXT)), 3); cfg::dat.hMenuNotify = CreatePopupMenu(); cfg::dat.wNextMenuID = 1; cfg::dat.sortTimer = cfg::getDword("CLC", "SortTimer", 150); cfg::dat.szNoEvents = TranslateTS(szNoevents); cfg::dat.avatarBorder = (COLORREF)cfg::getDword("CLC", "avatarborder", 0); cfg::dat.avatarRadius = (COLORREF)cfg::getDword("CLC", "avatarradius", 4); cfg::dat.hBrushAvatarBorder = CreateSolidBrush(cfg::dat.avatarBorder); cfg::dat.avatarSize = cfg::getWord("CList", "AvatarSize", 24); cfg::dat.dualRowMode = cfg::getByte("CLC", "DualRowMode", 0); cfg::dat.avatarPadding = cfg::getByte("CList", "AvatarPadding", 0); cfg::dat.isTransparent = cfg::getByte("CList", "Transparent", 0); cfg::dat.alpha = cfg::getByte("CList", "Alpha", SETTING_ALPHA_DEFAULT); cfg::dat.autoalpha = cfg::getByte("CList", "AutoAlpha", SETTING_ALPHA_DEFAULT); cfg::dat.fadeinout = cfg::getByte("CLUI", "FadeInOut", 0); cfg::dat.autosize = cfg::getByte("CLUI", "AutoSize", 0); cfg::dat.dwExtraImageMask = cfg::getDword("CLUI", "ximgmask", 0); cfg::dat.bNoOfflineAvatars = cfg::getByte("CList", "NoOfflineAV", 1); cfg::dat.bFullTransparent = cfg::getByte("CLUI", "fulltransparent", 0); cfg::dat.bDblClkAvatars = cfg::getByte("CLC", "dblclkav", 0); cfg::dat.bEqualSections = cfg::getByte("CLUI", "EqualSections", 0); cfg::dat.bCenterStatusIcons = cfg::getByte("CLC", "si_centered", 1); cfg::dat.boldHideOffline = -1; cfg::dat.bSecIMAvail = ServiceExists("SecureIM/IsContactSecured") ? 1 : 0; cfg::dat.bNoTrayTips = cfg::getByte("CList", "NoTrayTips", 0); cfg::dat.bShowLocalTime = cfg::getByte("CLC", "ShowLocalTime", 1); cfg::dat.bShowLocalTimeSelective = cfg::getByte("CLC", "SelectiveLocalTime", 1); cfg::dat.bDontSeparateOffline = cfg::getByte("CList", "DontSeparateOffline", 0); cfg::dat.bShowXStatusOnSbar = cfg::getByte("CLUI", "xstatus_sbar", 0); cfg::dat.bLayeredHack = cfg::getByte("CLUI", "layeredhack", 1); cfg::dat.bFirstRun = cfg::getByte("CLUI", "firstrun", 1); cfg::dat.langPackCP = CallService(MS_LANGPACK_GETCODEPAGE, 0, 0); cfg::dat.realTimeSaving = cfg::getByte("CLUI", "save_pos_always", 0); DWORD sortOrder = cfg::getDword("CList", "SortOrder", SORTBY_NAME); cfg::dat.sortOrder[0] = LOBYTE(LOWORD(sortOrder)); cfg::dat.sortOrder[1] = HIBYTE(LOWORD(sortOrder)); cfg::dat.sortOrder[2] = LOBYTE(HIWORD(sortOrder)); if(cfg::dat.bFirstRun) cfg::writeByte("CLUI", "firstrun", 0); if(!cfg::getString(NULL, "CLUI", "exIconOrder", &dbv)) { if(lstrlenA(dbv.pszVal) < EXICON_COUNT) { for(i = 1; i <= EXICON_COUNT; i++) cfg::dat.exIconOrder[i - 1] = i; } else { for(i = 0; i < EXICON_COUNT; i++) if(dbv.pszVal[i] < EXICON_COUNT+1 && dbv.pszVal[i] >0) cfg::dat.exIconOrder[i] = dbv.pszVal[i]; else cfg::dat.exIconOrder[i] = i+1; } DBFreeVariant(&dbv); } else { for(i = 1; i <= EXICON_COUNT; i++) cfg::dat.exIconOrder[i - 1] = i; } ReloadThemedOptions(); FLT_ReadOptions(); Reload3dBevelColors(); himlExtraImages = ImageList_Create(16, 16, ILC_MASK | (IsWinVerXPPlus() ? ILC_COLOR32 : ILC_COLOR16), 30, 2); ImageList_SetIconSize(himlExtraImages, cfg::dat.exIconScale, cfg::dat.exIconScale); cfg::dat.dwFlags = cfg::getDword("CLUI", "Frameflags", CLUI_FRAME_SHOWTOPBUTTONS | CLUI_FRAME_STATUSICONS | CLUI_FRAME_SHOWBOTTOMBUTTONS | CLUI_FRAME_BUTTONSFLAT | CLUI_FRAME_CLISTSUNKEN); cfg::dat.dwFlags |= (cfg::getByte("CLUI", "ShowSBar", 1) ? CLUI_FRAME_SBARSHOW : 0); cfg::dat.soundsOff = cfg::getByte("CLUI", "NoSounds", 0); CallService(MS_DB_GETPROFILEPATH, MAX_PATH, (LPARAM)szProfilePath); #if defined(_UNICODE) MultiByteToWideChar(CP_ACP, 0, szProfilePath, MAX_PATH, cfg::dat.tszProfilePath, MAX_PATH); cfg::dat.tszProfilePath[MAX_PATH - 1] = 0; #else mir_sntprintf(cfg::dat.tszProfilePath, MAX_PATH, "%s", szProfilePath); #endif _tcslwr(cfg::dat.tszProfilePath); if(cfg::getByte("Skin", "UseSound", 0) != cfg::dat.soundsOff) cfg::writeByte("Skin", "UseSound", (BYTE)(cfg::dat.soundsOff ? 0 : 1)); // get the clist interface pcli = ( CLIST_INTERFACE* )CallService(MS_CLIST_RETRIEVE_INTERFACE, 0, (LPARAM)g_hInst); if ( (INT_PTR)pcli == CALLSERVICE_NOTFOUND ) { LBL_Error: MessageBoxA( NULL, "This plugin requires Miranda IM 0.8.0.9 or later", "Fatal error", MB_OK ); return 1; } if ( pcli->version < 6 ) // don't join it with the previous if() goto LBL_Error; pcli->pfnBuildGroupPopupMenu = BuildGroupPopupMenu; pcli->pfnCluiProtocolStatusChanged = CluiProtocolStatusChanged; pcli->pfnCompareContacts = CompareContacts; pcli->pfnCreateClcContact = CreateClcContact; pcli->pfnCreateEvent = fnCreateEvent; pcli->pfnDocking_ProcessWindowMessage = Docking_ProcessWindowMessage; pcli->pfnGetDefaultFontSetting = GetDefaultFontSetting; pcli->pfnGetRowBottomY = RowHeight::getItemBottomY; pcli->pfnGetRowHeight = RowHeight::getHeight; pcli->pfnGetRowTopY = RowHeight::getItemTopY; pcli->pfnGetRowTotalHeight = RowHeight::getTotalHeight; pcli->pfnGetWindowVisibleState = GetWindowVisibleState; pcli->pfnHitTest = HitTest; pcli->pfnLoadContactTree = LoadContactTree; pcli->pfnOnCreateClc = LoadCLUIModule; pcli->pfnPaintClc = PaintClc; pcli->pfnRebuildEntireList = RebuildEntireList; pcli->pfnRowHitTest = RowHeight::hitTest; pcli->pfnScrollTo = ScrollTo; pcli->pfnTrayIconUpdateBase = TrayIconUpdateBase; pcli->pfnSetHideOffline = SetHideOffline; pcli->pfnShowHide = ShowHide; saveAddContactToGroup = pcli->pfnAddContactToGroup; pcli->pfnAddContactToGroup = AddContactToGroup; saveRemoveItemFromGroup = pcli->pfnRemoveItemFromGroup; pcli->pfnRemoveItemFromGroup = RemoveItemFromGroup; saveAddEvent = pcli->pfnAddEvent; pcli->pfnAddEvent = AddEvent; saveRemoveEvent = pcli->pfnRemoveEvent; pcli->pfnRemoveEvent = RemoveEvent; saveAddGroup = pcli->pfnAddGroup; pcli->pfnAddGroup = AddGroup; saveAddInfoItemToGroup = pcli->pfnAddInfoItemToGroup; pcli->pfnAddInfoItemToGroup = AddInfoItemToGroup; saveContactListControlWndProc = pcli->pfnContactListControlWndProc; pcli->pfnContactListControlWndProc = ContactListControlWndProc; saveContactListWndProc = pcli->pfnContactListWndProc; pcli->pfnContactListWndProc = ContactListWndProc; saveIconFromStatusMode = pcli->pfnIconFromStatusMode; pcli->pfnIconFromStatusMode = fnIconFromStatusMode; saveLoadClcOptions = pcli->pfnLoadClcOptions; pcli->pfnLoadClcOptions = LoadClcOptions; saveProcessExternalMessages = pcli->pfnProcessExternalMessages; pcli->pfnProcessExternalMessages = ProcessExternalMessages; saveRecalcScrollBar = pcli->pfnRecalcScrollBar; pcli->pfnRecalcScrollBar = RecalcScrollBar; saveTrayIconProcessMessage = pcli->pfnTrayIconProcessMessage; pcli->pfnTrayIconProcessMessage = TrayIconProcessMessage; rc = LoadContactListModule(); if (rc == 0) rc = LoadCLCModule(); HookEvent(ME_SYSTEM_MODULESLOADED, systemModulesLoaded); return rc; }
/** * This just adds the message to the database for later delivery and * adds the contact to the list of contacts that have queued messages * * @param iJobIndex int: index of the send job * dat: Message window data * fAddHeader: add the "message was sent delayed" header (default = true) * hContact : contact to which the job should be added (default = hOwner of the send job) * * @return the index on success, -1 on failure */ int SendQueue::doSendLater(int iJobIndex, TWindowData *dat, HANDLE hContact, bool fIsSendLater) { bool fAvail = sendLater->isAvail(); const TCHAR *szNote = 0; if(fIsSendLater && dat) { if(fAvail) szNote = CTranslator::get(CTranslator::GEN_SQ_QUEUED_MESSAGE); else szNote = CTranslator::get(CTranslator::GEN_SQ_QUEUING_NOT_AVAIL); char *utfText = M->utf8_encodeT(szNote); DBEVENTINFO dbei; dbei.cbSize = sizeof(dbei); dbei.eventType = EVENTTYPE_MESSAGE; dbei.flags = DBEF_SENT | DBEF_UTF; dbei.szModule = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) dat->hContact, 0); dbei.timestamp = time(NULL); dbei.cbBlob = lstrlenA(utfText) + 1; dbei.pBlob = (PBYTE) utfText; StreamInEvents(dat->hwnd, 0, 1, 1, &dbei); if (dat->hDbEventFirst == NULL) SendMessage(dat->hwnd, DM_REMAKELOG, 0, 0); dat->cache->saveHistory(0, 0); EnableSendButton(dat, FALSE); if (dat->pContainer->hwndActive == dat->hwnd) UpdateReadChars(dat); SendDlgItemMessage(dat->hwnd, IDC_SAVE, BM_SETIMAGE, IMAGE_ICON, (LPARAM) PluginConfig.g_buttonBarIcons[ICON_BUTTON_CANCEL]); SendDlgItemMessage(dat->hwnd, IDC_SAVE, BUTTONADDTOOLTIP, (WPARAM)pszIDCSAVE_close, 0); dat->dwFlags &= ~MWF_SAVEBTN_SAV; mir_free(utfText); if(!fAvail) return(0); } if(iJobIndex >= 0 && iJobIndex < NR_SENDJOBS) { SendJob* job = &m_jobs[iJobIndex]; char szKeyName[20]; TCHAR tszTimestamp[30], tszHeader[150]; time_t now = time(0); if(fIsSendLater) { TCHAR *formatTime = _T("%Y.%m.%d - %H:%M"); _tcsftime(tszTimestamp, 30, formatTime, _localtime32((__time32_t *)&now)); tszTimestamp[29] = 0; mir_snprintf(szKeyName, 20, "S%d", now); mir_sntprintf(tszHeader, safe_sizeof(tszHeader), CTranslator::get(CTranslator::GEN_SQ_SENDLATER_HEADER), tszTimestamp); } else mir_sntprintf(tszHeader, safe_sizeof(tszHeader), _T("M%d|"), time(0)); if(job->dwFlags & PREF_UTF || !(job->dwFlags & PREF_UNICODE)) { char *utf_header = M->utf8_encodeT(tszHeader); UINT required = lstrlenA(utf_header) + lstrlenA(job->sendBuffer) + 10; char *tszMsg = reinterpret_cast<char *>(mir_alloc(required)); if(fIsSendLater) { mir_snprintf(tszMsg, required, "%s%s", job->sendBuffer, utf_header); DBWriteContactSettingString(hContact ? hContact : job->hOwner, "SendLater", szKeyName, tszMsg); } else { mir_snprintf(tszMsg, required, "%s%s", utf_header, job->sendBuffer); sendLater->addJob(tszMsg, (LPARAM)hContact); } mir_free(utf_header); mir_free(tszMsg); } else if(job->dwFlags & PREF_UNICODE) { int iLen = lstrlenA(job->sendBuffer); wchar_t *wszMsg = (wchar_t *)&job->sendBuffer[iLen + 1]; UINT required = sizeof(TCHAR) * (lstrlen(tszHeader) + lstrlenW(wszMsg) + 10); TCHAR *tszMsg = reinterpret_cast<TCHAR *>(mir_alloc(required)); if(fIsSendLater) mir_sntprintf(tszMsg, required, _T("%s%s"), wszMsg, tszHeader); else mir_sntprintf(tszMsg, required, _T("%s%s"), tszHeader, wszMsg); char *utf = M->utf8_encodeT(tszMsg); if(fIsSendLater) DBWriteContactSettingString(hContact ? hContact : job->hOwner, "SendLater", szKeyName, utf); else sendLater->addJob(utf, (LPARAM)hContact); mir_free(utf); mir_free(tszMsg); } if(fIsSendLater) { int iCount = M->GetDword(hContact ? hContact : job->hOwner, "SendLater", "count", 0); iCount++; M->WriteDword(hContact ? hContact : job->hOwner, "SendLater", "count", iCount); sendLater->addContact(hContact ? hContact : job->hOwner); } return(iJobIndex); } return(-1); }
BOOL EncodeMessage(PCRYPT_DATA_BLOB pEncodedBlob, LPWSTR pwszSignerName) { /*--------------------------------------------------------------- Declare and initialize variables. This includes getting a pointer to the message content. This sample creates the message content and gets a pointer to it. In most situations, the content will exist somewhere, and a pointer to it will get passed to the application. ---------------------------------------------------------------*/ HCERTSTORE hSystemStoreHandle; CRYPT_SIGN_MESSAGE_PARA SignMessagePara; //--------------------------------------------------------------- // The message to be signed and encoded. BYTE* pbContent = (BYTE*) "The quick brown fox jumped over " \ "the lazy dog."; /*--------------------------------------------------------------- The length of the message. This must be one more than the value returned by strlen() to include the terminal NULL character. ---------------------------------------------------------------*/ DWORD cbContent = lstrlenA((char *) pbContent) + 1; //--------------------------------------------------------------- // Arrays to hold the message to be signed and its length. const BYTE *rgpbToBeSigned[1] ; DWORD rgcbToBeSigned[1]; //--------------------------------------------------------------- // The signer's certificate. PCCERT_CONTEXT pSignerCert; //--------------------------------------------------------------- // Buffer to hold the name of the subject of a certificate. wchar_t pszNameString[MAX_NAME]; //--------------------------------------------------------------- // The following variables are used only in the decoding phase. DWORD cbData = sizeof(DWORD); //--------------------------------------------------------------- // Begin processing. Display the original message. rgpbToBeSigned[0] = pbContent; rgcbToBeSigned[0] = cbContent; printf("The original message = \n%s\n\n", rgpbToBeSigned[0]); //--------------------------------------------------------------- // Open a certificate store. if(hSystemStoreHandle = CertOpenStore( CERT_STORE_PROV_SYSTEM, 0, NULL, CERT_SYSTEM_STORE_CURRENT_USER, CERTIFICATE_STORE_NAME)) { printf("The certificate store is open. \n"); } else { MyHandleError( "Error Getting Store Handle"); } /*--------------------------------------------------------------- Find a certificate in the store. This certificate will be used to sign the message. To sign the message, the certificate must have a private key accessible. ---------------------------------------------------------------*/ if(pSignerCert = CertFindCertificateInStore( hSystemStoreHandle, MY_ENCODING_TYPE, 0, CERT_FIND_SUBJECT_STR, pwszSignerName, NULL)) { //----------------------------------------------------------- // Get and print the name of the subject of the certificate. if(CertGetNameString( pSignerCert, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL, pszNameString, MAX_NAME) > 1) { wprintf(L"The message signer is %s \n",pszNameString); } else { MyHandleError("Getting the name of the signer " \ "failed.\n"); } } else { MyHandleError("Signer certificate not found."); } /*--------------------------------------------------------------- Initialize the CRYPT_SIGN_MESSAGE_PARA structure. First, use memset to set all members to zero or NULL. Then set the values of all members that must be nonzero. ---------------------------------------------------------------*/ memset(&SignMessagePara, 0, sizeof(CRYPT_SIGN_MESSAGE_PARA)); SignMessagePara.cbSize = sizeof(CRYPT_SIGN_MESSAGE_PARA); SignMessagePara.HashAlgorithm.pszObjId = szOID_RSA_MD2; SignMessagePara.pSigningCert = pSignerCert; SignMessagePara.dwMsgEncodingType = MY_ENCODING_TYPE; SignMessagePara.cMsgCert = 1; SignMessagePara.rgpMsgCert = &pSignerCert; /*--------------------------------------------------------------- In two steps, sign and encode the message. First, get the number of bytes required for the buffer to hold the signed and encoded message. ---------------------------------------------------------------*/ if( CryptSignMessage( &SignMessagePara, FALSE, 1, rgpbToBeSigned, rgcbToBeSigned, NULL, &pEncodedBlob->cbData)) { printf("The needed length is %d \n", pEncodedBlob->cbData); } else { MyHandleError("Getting the length failed.\n"); } //--------------------------------------------------------------- // Allocate memory for the required buffer. pEncodedBlob->pbData = (BYTE *)malloc(pEncodedBlob->cbData); if(!pEncodedBlob->pbData) { MyHandleError("Memory allocation failed."); } //--------------------------------------------------------------- // Call CryptSignMessage a second time to // copy the signed and encoded message to the buffer. if( CryptSignMessage( &SignMessagePara, FALSE, 1, rgpbToBeSigned, rgcbToBeSigned, pEncodedBlob->pbData, &pEncodedBlob->cbData)) { printf("Signing worked \n"); } else { MyHandleError("Signing failed.\n"); } //--------------------------------------------------------------- // Clean up after signing and encoding. if(pSignerCert) { CertFreeCertificateContext(pSignerCert); } if(hSystemStoreHandle) { CertCloseStore(hSystemStoreHandle, CERT_CLOSE_STORE_FORCE_FLAG); } return TRUE; }
void SendQueue::recallFailed(const TWindowData *dat, int iEntry) const { int iLen = GetWindowTextLengthA(GetDlgItem(dat->hwnd, IDC_MESSAGE)); if(dat) { NotifyDeliveryFailure(dat); if (iLen == 0) { // message area is empty, so we can recall the failed message... SETTEXTEX stx = {ST_DEFAULT, 1200}; if (m_jobs[iEntry].dwFlags & PREF_UNICODE) SendDlgItemMessage(dat->hwnd, IDC_MESSAGE, EM_SETTEXTEX, (WPARAM)&stx, (LPARAM)&m_jobs[iEntry].sendBuffer[lstrlenA(m_jobs[iEntry].sendBuffer) + 1]); else { stx.codepage = (m_jobs[iEntry].dwFlags & PREF_UTF) ? CP_UTF8 : CP_ACP; SendDlgItemMessage(dat->hwnd, IDC_MESSAGE, EM_SETTEXTEX, (WPARAM)&stx, (LPARAM)m_jobs[iEntry].sendBuffer); } UpdateSaveAndSendButton(const_cast<TWindowData *>(dat)); SendDlgItemMessage(dat->hwnd, IDC_MESSAGE, EM_SETSEL, (WPARAM) - 1, (LPARAM) - 1); } } }
int SendQueue::ackMessage(TWindowData *dat, WPARAM wParam, LPARAM lParam) { ACKDATA *ack = (ACKDATA *) lParam; DBEVENTINFO dbei = { 0}; HANDLE hNewEvent; int iFound = SendQueue::NR_SENDJOBS, iNextFailed; TContainerData *m_pContainer = 0; if (dat) m_pContainer = dat->pContainer; iFound = (int)(LOWORD(wParam)); //i = (int)(HIWORD(wParam)); if (m_jobs[iFound].iStatus == SQ_ERROR) { // received ack for a job which is already in error state... if (dat) { // window still open if (dat->iCurrentQueueError == iFound) { dat->iCurrentQueueError = -1; showErrorControls(dat, FALSE); } } /* * we must discard this job, because there is no message window open to handle the * error properly. But we display a tray notification to inform the user about the problem. */ else goto inform_and_discard; } // failed acks are only handled when the window is still open. with no window open, they will be *silently* discarded if (ack->result == ACKRESULT_FAILED) { if (dat) { /* * "hard" errors are handled differently in multisend. There is no option to retry - once failed, they * are discarded and the user is notified with a small log message. */ if (!nen_options.iNoSounds && !(m_pContainer->dwFlags & CNT_NOSOUND)) SkinPlaySound("SendError"); TCHAR *szAckMsg = mir_a2t((char *)ack->lParam); mir_sntprintf(m_jobs[iFound].szErrorMsg, safe_sizeof(m_jobs[iFound].szErrorMsg), CTranslator::get(CTranslator::GEN_MSG_DELIVERYFAILURE), szAckMsg); m_jobs[iFound].iStatus = SQ_ERROR; mir_free(szAckMsg); KillTimer(dat->hwnd, TIMERID_MSGSEND + iFound); if (!(dat->dwFlags & MWF_ERRORSTATE)) handleError(dat, iFound); return 0; } else { inform_and_discard: _DebugPopup(m_jobs[iFound].hOwner, CTranslator::get(CTranslator::GEN_SQ_DELIVERYFAILEDLATE)); clearJob(iFound); return 0; } } dbei.cbSize = sizeof(dbei); dbei.eventType = EVENTTYPE_MESSAGE; dbei.flags = DBEF_SENT; dbei.szModule = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) m_jobs[iFound].hOwner, 0); dbei.timestamp = time(NULL); dbei.cbBlob = lstrlenA(m_jobs[iFound].sendBuffer) + 1; if (dat) dat->cache->updateStats(TSessionStats::BYTES_SENT, dbei.cbBlob - 1); else { CContactCache *c = CContactCache::getContactCache(m_jobs[iFound].hOwner); if(c) c->updateStats(TSessionStats::BYTES_SENT, dbei.cbBlob - 1); } if (m_jobs[iFound].dwFlags & PREF_UNICODE) dbei.cbBlob *= sizeof(TCHAR) + 1; if (m_jobs[iFound].dwFlags & PREF_RTL) dbei.flags |= DBEF_RTL; if (m_jobs[iFound].dwFlags & PREF_UTF) dbei.flags |= DBEF_UTF; dbei.pBlob = (PBYTE) m_jobs[iFound].sendBuffer; hNewEvent = (HANDLE) CallService(MS_DB_EVENT_ADD, (WPARAM) m_jobs[iFound].hOwner, (LPARAM) & dbei); if (m_pContainer) { if (!nen_options.iNoSounds && !(m_pContainer->dwFlags & CNT_NOSOUND)) SkinPlaySound("SendMsg"); } if (dat && (m_jobs[iFound].hOwner == dat->hContact)) { if (dat->hDbEventFirst == NULL) { dat->hDbEventFirst = hNewEvent; SendMessage(dat->hwnd, DM_REMAKELOG, 0, 0); } } m_jobs[iFound].hSendId = NULL; m_jobs[iFound].iAcksNeeded--; if (m_jobs[iFound].iAcksNeeded == 0) { // everything sent //if (m_jobs[iFound].hOwner != 0 && dat) // EnableSending(dat, TRUE); clearJob(iFound); if (dat) { KillTimer(dat->hwnd, TIMERID_MSGSEND + iFound); dat->iOpenJobs--; } m_currentIndex--; } if (dat) { checkQueue(dat); if ((iNextFailed = findNextFailed(dat)) >= 0 && !(dat->dwFlags & MWF_ERRORSTATE)) handleError(dat, iNextFailed); //MAD: close on send mode else { if (M->GetByte("AutoClose", 0)) { if(M->GetByte("adv_AutoClose_2", 0)) SendMessage(dat->hwnd, WM_CLOSE, 0, 1); else SendMessage(dat->pContainer->hwnd, WM_CLOSE, 0, 0); } } //MAD_ } return 0; }
static void DoSplitSendA(LPVOID param) { struct SendJob *job = sendQueue->getJobByIndex((int)param); int id; BOOL fFirstSend = FALSE; char *szBegin, *szTemp, *szSaved, savedChar; int iLen, iCur = 0, iSavedCur = 0, i; BOOL fSplitting = TRUE; char *svcName; HANDLE hContact = job->hOwner; DWORD dwFlags = job->dwFlags; int chunkSize = job->chunkSize; svcName = pss_msg; iLen = lstrlenA(job->sendBuffer); szTemp = (char *)mir_alloc(iLen + 1); CopyMemory(szTemp, job->sendBuffer, iLen + 1); szBegin = szTemp; do { iCur += chunkSize; if (iCur > iLen) fSplitting = FALSE; if (fSplitting) { i = 0; szSaved = &szBegin[iCur]; iSavedCur = iCur; while (iCur) { if (szBegin[iCur] == ' ') { szSaved = &szBegin[iCur]; break; } if (i == SPLIT_WORD_CUTOFF) { iCur = iSavedCur; szSaved = &szBegin[iCur]; break; } i++; iCur--; } savedChar = *szSaved; *szSaved = 0; id = SendChunkA(szTemp, hContact, PSS_MESSAGE, dwFlags); if (!fFirstSend) { job->hSendId = (HANDLE)id; fFirstSend = TRUE; PostMessage(PluginConfig.g_hwndHotkeyHandler, DM_SPLITSENDACK, (WPARAM)param, 0); } *szSaved = savedChar; szTemp = szSaved; if (savedChar == ' ') { szTemp++; iCur++; } } else { id = SendChunkA(szTemp, hContact, PSS_MESSAGE, dwFlags); if (!fFirstSend) { job->hSendId = (HANDLE)id; fFirstSend = TRUE; PostMessage(PluginConfig.g_hwndHotkeyHandler, DM_SPLITSENDACK, (WPARAM)param, 0); } } Sleep(500L); } while (fSplitting); mir_free(szBegin); }
static void DoSplitSendW(LPVOID param) { struct SendJob *job = sendQueue->getJobByIndex((int)param); int id; BOOL fFirstSend = FALSE; WCHAR *wszBegin, *wszTemp, *wszSaved, savedChar; int iLen, iCur = 0, iSavedCur = 0, i; BOOL fSplitting = TRUE; char szServiceName[100], *svcName; HANDLE hContact = job->hOwner; DWORD dwFlags = job->dwFlags; int chunkSize = job->chunkSize / 2; char *szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0); if (szProto == NULL) svcName = pss_msg; else { _snprintf(szServiceName, sizeof(szServiceName), "%s%sW", szProto, PSS_MESSAGE); if (ServiceExists(szServiceName)) svcName = pss_msgw; else svcName = pss_msg; } iLen = lstrlenA(job->sendBuffer); wszBegin = (WCHAR *) & job->sendBuffer[iLen + 1]; wszTemp = (WCHAR *)mir_alloc(sizeof(WCHAR) * (lstrlenW(wszBegin) + 1)); CopyMemory(wszTemp, wszBegin, sizeof(WCHAR) * (lstrlenW(wszBegin) + 1)); wszBegin = wszTemp; do { iCur += chunkSize; if (iCur > iLen) fSplitting = FALSE; /* * try to "word wrap" the chunks - split on word boundaries (space characters), if possible. * SPLIT_WORD_CUTOFF = max length of unbreakable words, longer words may be split. */ if (fSplitting) { i = 0; wszSaved = &wszBegin[iCur]; iSavedCur = iCur; while (iCur) { if (wszBegin[iCur] == (TCHAR)' ') { wszSaved = &wszBegin[iCur]; break; } if (i == SPLIT_WORD_CUTOFF) { // no space found backwards, restore old split position iCur = iSavedCur; wszSaved = &wszBegin[iCur]; break; } i++; iCur--; } savedChar = *wszSaved; *wszSaved = 0; id = SendChunkW(wszTemp, hContact, svcName, dwFlags); if (!fFirstSend) { job->hSendId = (HANDLE)id; fFirstSend = TRUE; PostMessage(PluginConfig.g_hwndHotkeyHandler, DM_SPLITSENDACK, (WPARAM)param, 0); } *wszSaved = savedChar; wszTemp = wszSaved; if (savedChar == (TCHAR)' ') { wszTemp++; iCur++; } } else { id = SendChunkW(wszTemp, hContact, svcName, dwFlags); if (!fFirstSend) { job->hSendId = (HANDLE)id; fFirstSend = TRUE; PostMessage(PluginConfig.g_hwndHotkeyHandler, DM_SPLITSENDACK, (WPARAM)param, 0); } } Sleep(500L); } while (fSplitting); mir_free(wszBegin); }
//BGI 使用0xA表示换行 string WINAPI GetString(PBYTE BufferStart, ULONG& Offset) { ULONG Value = *(PULONG)(BufferStart + Offset); Offset += 4; WCHAR WideString[1500] = { 0 }; CHAR UTF8Name[2000] = { 0 }; ScriptHeader* Header = (ScriptHeader*)BufferStart; ULONG HeaderSize = Header->HeaderSize - sizeof(ULONG) + sizeof(ScriptHeader); MultiByteToWideChar(GBKMode ? 936 : 932, 0, (CHAR*)(BufferStart + Value + HeaderSize), lstrlenA((CHAR*)(BufferStart + Value + HeaderSize)), WideString, 1500); WideCharToMultiByte(CP_UTF8, 0, WideString, lstrlenW(WideString), UTF8Name, 2000, nullptr, nullptr); #ifndef DUMP_TEXT_ONLY return FixString("\"" + string(UTF8Name) + "\""); #else return FixString(string(UTF8Name)); #endif }
__declspec(dllexport) bool TITCALL ExporterBuildExportTable(ULONG_PTR StorePlace, ULONG_PTR FileMapVA) { unsigned int i = NULL; unsigned int j = NULL; LPVOID expBuildExportDataOld; PIMAGE_DOS_HEADER DOSHeader; PIMAGE_NT_HEADERS32 PEHeader32; PIMAGE_NT_HEADERS64 PEHeader64; LPVOID expBuildExportData; DynBuf expBuildExportDyn; LPVOID expBuildExportDataCWP; DWORD StorePlaceRVA = (DWORD)ConvertFileOffsetToVA(FileMapVA, StorePlace, false); ULONG_PTR TempULONG; DWORD TempDWORD; BOOL FileIs64 = false; if(expTableDataCWP != NULL) { expBuildExportData = expBuildExportDyn.Allocate(ExporterEstimatedSize()); expBuildExportDataCWP = (LPVOID)((ULONG_PTR)expBuildExportData + sizeof IMAGE_EXPORT_DIRECTORY); expExportData.NumberOfNames = expExportNumber; expExportData.NumberOfFunctions = expExportNumber; for(i = 0; i < expExportNumber; i++) { for(j = 0; j < expExportNumber; j++) { if(lstrcmpiA((PCHAR)expNamePointers[i], (PCHAR)expNamePointers[j]) < NULL) { TempULONG = expNamePointers[j]; expNamePointers[j] = expNamePointers[i]; expNamePointers[i] = TempULONG; TempDWORD = expExportAddress[j]; expExportAddress[j] = expExportAddress[i]; expExportAddress[i] = TempDWORD; } } } if(expNamePresent) { expExportData.Name = StorePlaceRVA + (DWORD)((ULONG_PTR)expBuildExportDataCWP - (ULONG_PTR)expBuildExportData); RtlMoveMemory(expBuildExportDataCWP, (LPVOID)expTableData, lstrlenA((PCHAR)expTableData)); expBuildExportDataCWP = (LPVOID)((ULONG_PTR)expBuildExportDataCWP + lstrlenA((PCHAR)expTableData) + 2); } for(i = 0; i < expExportNumber; i++) { RtlMoveMemory(expBuildExportDataCWP, (LPVOID)expNamePointers[i], lstrlenA((PCHAR)expNamePointers[i])); expBuildExportDataOld = expBuildExportDataCWP; expBuildExportDataCWP = (LPVOID)((ULONG_PTR)expBuildExportDataCWP + lstrlenA((PCHAR)expNamePointers[i]) + 2); expSortedNamePointers[i] = (DWORD)((ULONG_PTR)expBuildExportDataOld - (ULONG_PTR)expBuildExportData) + StorePlaceRVA; } expExportData.AddressOfFunctions = StorePlaceRVA + (DWORD)((ULONG_PTR)expBuildExportDataCWP - (ULONG_PTR)expBuildExportData); RtlMoveMemory(expBuildExportDataCWP, &expExportAddress, 4 * expExportNumber); expBuildExportDataCWP = (LPVOID)((ULONG_PTR)expBuildExportDataCWP + 4 * expExportNumber); expExportData.AddressOfNames = StorePlaceRVA + (DWORD)((ULONG_PTR)expBuildExportDataCWP - (ULONG_PTR)expBuildExportData); RtlMoveMemory(expBuildExportDataCWP, &expSortedNamePointers, 4 * expExportNumber); expBuildExportDataCWP = (LPVOID)((ULONG_PTR)expBuildExportDataCWP + 4 * expExportNumber); expExportData.AddressOfNameOrdinals = StorePlaceRVA + (DWORD)((ULONG_PTR)expBuildExportDataCWP - (ULONG_PTR)expBuildExportData); RtlMoveMemory(expBuildExportDataCWP, &expOrdinals, 2 * expExportNumber); expBuildExportDataCWP = (LPVOID)((ULONG_PTR)expBuildExportDataCWP + 2 * expExportNumber); RtlMoveMemory(expBuildExportData, &expExportData, sizeof IMAGE_EXPORT_DIRECTORY); RtlMoveMemory((LPVOID)StorePlace, expBuildExportData, (DWORD)((ULONG_PTR)expBuildExportDataCWP - (ULONG_PTR)expBuildExportData)); if(FileMapVA != NULL) { DOSHeader = (PIMAGE_DOS_HEADER)FileMapVA; if(EngineValidateHeader(FileMapVA, NULL, NULL, DOSHeader, true)) { PEHeader32 = (PIMAGE_NT_HEADERS32)((ULONG_PTR)DOSHeader + DOSHeader->e_lfanew); PEHeader64 = (PIMAGE_NT_HEADERS64)((ULONG_PTR)DOSHeader + DOSHeader->e_lfanew); if(PEHeader32->OptionalHeader.Magic == 0x10B) { FileIs64 = false; } else if(PEHeader32->OptionalHeader.Magic == 0x20B) { FileIs64 = true; } else { return false; } if(!FileIs64) { PEHeader32->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress = (DWORD)StorePlaceRVA; PEHeader32->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size = (DWORD)((ULONG_PTR)expBuildExportDataCWP - (ULONG_PTR)expBuildExportData); } else { PEHeader64->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress = (DWORD)StorePlaceRVA; PEHeader64->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size = (DWORD)((ULONG_PTR)expBuildExportDataCWP - (ULONG_PTR)expBuildExportData); } } } ExporterCleanup(); return true; } return false; }
static void test_SetupCopyOEMInf(void) { CHAR toolong[MAX_PATH * 2]; CHAR path[MAX_PATH], dest[MAX_PATH]; CHAR tmpfile[MAX_PATH], dest_save[MAX_PATH]; LPSTR inf = NULL; DWORD size; BOOL res; /* try NULL SourceInfFileName */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(NULL, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); ok(res == FALSE, "Expected FALSE, got %d\n", res); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); /* try empty SourceInfFileName */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA("", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); ok(res == FALSE, "Expected FALSE, got %d\n", res); ok(GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_BAD_PATHNAME || /* Win98 */ GetLastError() == ERROR_INVALID_PARAMETER, /* Vista, W2K8 */ "Unexpected error : %d\n", GetLastError()); /* try a relative nonexistent SourceInfFileName */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA("nonexistent", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); ok(res == FALSE, "Expected FALSE, got %d\n", res); ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); /* try an absolute nonexistent SourceInfFileName */ strcpy(path, CURR_DIR); strcat(path, "\\nonexistent"); SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(path, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); ok(res == FALSE, "Expected FALSE, got %d\n", res); ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); /* try a long SourceInfFileName */ memset(toolong, 'a', MAX_PATH * 2); toolong[MAX_PATH * 2 - 1] = '\0'; SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(toolong, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); ok(res == FALSE, "Expected FALSE, got %d\n", res); ok(GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_FILENAME_EXCED_RANGE, /* Win98 */ "Expected ERROR_FILE_NOT_FOUND or ERROR_FILENAME_EXCED_RANGE, got %d\n", GetLastError()); get_temp_filename(tmpfile); create_inf_file(tmpfile); /* try a relative SourceInfFileName */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(tmpfile, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); ok(res == FALSE || broken(res == TRUE), /* Win98 */ "Expected FALSE, got %d\n", res); if (GetLastError() == ERROR_WRONG_INF_TYPE || GetLastError() == ERROR_UNSUPPORTED_TYPE /* Win7 */) { /* FIXME: * Vista needs a [Manufacturer] entry in the inf file. Doing this will give some * popups during the installation though as it also needs a catalog file (signed?). */ win_skip("Needs a different inf file on Vista+\n"); DeleteFileA(tmpfile); return; } ok(GetLastError() == ERROR_FILE_NOT_FOUND || broken(GetLastError() == ERROR_SUCCESS), /* Win98 */ "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); ok(file_exists(tmpfile), "Expected tmpfile to exist\n"); /* try SP_COPY_REPLACEONLY, dest does not exist */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL); ok(res == FALSE, "Expected FALSE, got %d\n", res); ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); ok(file_exists(tmpfile), "Expected source inf to exist\n"); /* try an absolute SourceInfFileName, without DestinationInfFileName */ strcpy(path, CURR_DIR); strcat(path, "\\"); strcat(path, tmpfile); SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, NULL, 0, NULL, NULL); ok(res == TRUE, "Expected TRUE, got %d\n", res); ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); ok(file_exists(path), "Expected source inf to exist\n"); /* try SP_COPY_REPLACEONLY, dest exists */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL); ok(res == TRUE, "Expected TRUE, got %d\n", res); ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); ok(file_exists(path), "Expected source inf to exist\n"); /* try SP_COPY_NOOVERWRITE */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); ok(res == FALSE, "Expected FALSE, got %d\n", res); ok(GetLastError() == ERROR_FILE_EXISTS, "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError()); /* get the DestinationInfFileName */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, NULL, NULL); ok(res == TRUE, "Expected TRUE, got %d\n", res); ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); ok(strlen(dest) != 0, "Expected a non-zero length string\n"); ok(file_exists(dest), "Expected destination inf to exist\n"); ok(check_format(dest, NULL), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest); ok(file_exists(path), "Expected source inf to exist\n"); strcpy(dest_save, dest); DeleteFileA(dest_save); /* get the DestinationInfFileName, DestinationInfFileNameSize is too small * - inf is still copied */ strcpy(dest, "aaa"); size = 0; SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, 5, &size, NULL); ok(res == FALSE, "Expected FALSE, got %d\n", res); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError()); ok(file_exists(path), "Expected source inf to exist\n"); ok(file_exists(dest_save), "Expected dest inf to exist\n"); ok(!strcmp(dest, "aaa"), "Expected dest to be unchanged\n"); ok(size == strlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n"); /* get the DestinationInfFileName and DestinationInfFileNameSize */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, NULL); ok(res == TRUE, "Expected TRUE, got %d\n", res); ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); ok(lstrlenA(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlenA(dest), size); ok(file_exists(dest), "Expected destination inf to exist\n"); ok(check_format(dest, NULL), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest); ok(file_exists(path), "Expected source inf to exist\n"); ok(size == lstrlenA(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n"); test_original_file_name(strrchr(path, '\\') + 1, dest); /* get the DestinationInfFileName, DestinationInfFileNameSize, and DestinationInfFileNameComponent */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, &inf); ok(res == TRUE, "Expected TRUE, got %d\n", res); ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); ok(lstrlenA(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlenA(dest), size); ok(file_exists(dest), "Expected destination inf to exist\n"); ok((inf && inf[0] != 0) || broken(!inf), /* Win98 */ "Expected inf to point to the filename\n"); ok(check_format(dest, inf), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest); ok(file_exists(path), "Expected source inf to exist\n"); ok(size == lstrlenA(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n"); /* try SP_COPY_DELETESOURCE */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_DELETESOURCE, NULL, 0, NULL, NULL); ok(res == TRUE, "Expected TRUE, got %d\n", res); ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); ok(!file_exists(path), "Expected source inf to not exist\n"); if (pSetupUninstallOEMInfA) { char pnf[MAX_PATH]; char *pnffile; char *destfile = strrchr(dest, '\\') + 1; strcpy(pnf, dest); *(strrchr(pnf, '.') + 1) = 'p'; pnffile = strrchr(pnf, '\\') + 1; SetLastError(0xdeadbeef); res = pSetupUninstallOEMInfA(destfile, 0, NULL); if(!res) res = pSetupUninstallOEMInfA(pnffile, 0, NULL); ok(res, "Failed to uninstall '%s'/'%s' : %d\n", destfile, pnffile, GetLastError()); todo_wine ok(!file_exists(dest), "Expected inf '%s' to not exist\n", dest); if(file_exists(dest)) { SetLastError(0xdeadbeef); res = DeleteFileA(dest); ok(res, "Failed to delete file '%s' : %d\n", dest, GetLastError()); } ok(!file_exists(pnf), "Expected pnf '%s' to not exist\n", pnf); if(file_exists(pnf)) { SetLastError(0xdeadbeef); res = DeleteFileA(pnf); ok(res, "Failed to delete file '%s' : %d\n", pnf, GetLastError()); } } else { /* Win9x/WinMe */ SetLastError(0xdeadbeef); res = DeleteFileA(dest); ok(res, "Failed to delete file '%s' : %d\n", dest, GetLastError()); /* On WinMe we also need to remove the .pnf file */ *(strrchr(dest, '.') + 1) = 'p'; DeleteFileA(dest); } }
static void testLoadLibraryEx(void) { CHAR path[MAX_PATH]; HMODULE hmodule; HANDLE hfile; BOOL ret; hfile = CreateFileA("testfile.dll", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); ok(hfile != INVALID_HANDLE_VALUE, "Expected a valid file handle\n"); /* NULL lpFileName */ if (is_unicode_enabled) { SetLastError(0xdeadbeef); hmodule = LoadLibraryExA(NULL, NULL, 0); ok(hmodule == 0, "Expected 0, got %p\n", hmodule); ok(GetLastError() == ERROR_MOD_NOT_FOUND || GetLastError() == ERROR_INVALID_PARAMETER, /* win9x */ "Expected ERROR_MOD_NOT_FOUND or ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); } else win_skip("NULL filename crashes on WinMe\n"); /* empty lpFileName */ SetLastError(0xdeadbeef); hmodule = LoadLibraryExA("", NULL, 0); ok(hmodule == 0, "Expected 0, got %p\n", hmodule); ok(GetLastError() == ERROR_MOD_NOT_FOUND || GetLastError() == ERROR_DLL_NOT_FOUND /* win9x */ || GetLastError() == ERROR_INVALID_PARAMETER /* win8 */, "Expected ERROR_MOD_NOT_FOUND or ERROR_DLL_NOT_FOUND, got %d\n", GetLastError()); /* hFile is non-NULL */ SetLastError(0xdeadbeef); hmodule = LoadLibraryExA("testfile.dll", hfile, 0); ok(hmodule == 0, "Expected 0, got %p\n", hmodule); todo_wine { ok(GetLastError() == ERROR_SHARING_VIOLATION || GetLastError() == ERROR_INVALID_PARAMETER || /* win2k3 */ GetLastError() == ERROR_FILE_NOT_FOUND, /* win9x */ "Unexpected last error, got %d\n", GetLastError()); } SetLastError(0xdeadbeef); hmodule = LoadLibraryExA("testfile.dll", (HANDLE)0xdeadbeef, 0); ok(hmodule == 0, "Expected 0, got %p\n", hmodule); todo_wine { ok(GetLastError() == ERROR_SHARING_VIOLATION || GetLastError() == ERROR_INVALID_PARAMETER || /* win2k3 */ GetLastError() == ERROR_FILE_NOT_FOUND, /* win9x */ "Unexpected last error, got %d\n", GetLastError()); } /* try to open a file that is locked */ SetLastError(0xdeadbeef); hmodule = LoadLibraryExA("testfile.dll", NULL, 0); ok(hmodule == 0, "Expected 0, got %p\n", hmodule); todo_wine { ok(GetLastError() == ERROR_SHARING_VIOLATION || GetLastError() == ERROR_FILE_NOT_FOUND, /* win9x */ "Expected ERROR_SHARING_VIOLATION or ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); } /* lpFileName does not matter */ if (is_unicode_enabled) { SetLastError(0xdeadbeef); hmodule = LoadLibraryExA(NULL, hfile, 0); ok(hmodule == 0, "Expected 0, got %p\n", hmodule); ok(GetLastError() == ERROR_MOD_NOT_FOUND || GetLastError() == ERROR_INVALID_PARAMETER, /* win2k3 */ "Expected ERROR_MOD_NOT_FOUND or ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); } CloseHandle(hfile); /* load empty file */ SetLastError(0xdeadbeef); hmodule = LoadLibraryExA("testfile.dll", NULL, LOAD_LIBRARY_AS_DATAFILE); ok(hmodule == 0, "Expected 0, got %p\n", hmodule); todo_wine { ok(GetLastError() == ERROR_FILE_INVALID || GetLastError() == ERROR_BAD_FORMAT, /* win9x */ "Expected ERROR_FILE_INVALID or ERROR_BAD_FORMAT, got %d\n", GetLastError()); } DeleteFileA("testfile.dll"); GetSystemDirectoryA(path, MAX_PATH); if (path[lstrlenA(path) - 1] != '\\') lstrcatA(path, "\\"); lstrcatA(path, "kernel32.dll"); /* load kernel32.dll with an absolute path */ SetLastError(0xdeadbeef); hmodule = LoadLibraryExA(path, NULL, LOAD_LIBRARY_AS_DATAFILE); ok(hmodule != 0, "Expected valid module handle\n"); ok(GetLastError() == 0xdeadbeef || GetLastError() == ERROR_SUCCESS, /* win9x */ "Expected 0xdeadbeef or ERROR_SUCCESS, got %d\n", GetLastError()); /* try invalid file handle */ SetLastError(0xdeadbeef); hmodule = LoadLibraryExA(path, (HANDLE)0xdeadbeef, 0); if (!hmodule) /* succeeds on xp and older */ ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError()); FreeLibrary(hmodule); /* load kernel32.dll with no path */ SetLastError(0xdeadbeef); hmodule = LoadLibraryExA("kernel32.dll", NULL, LOAD_LIBRARY_AS_DATAFILE); ok(hmodule != 0, "Expected valid module handle\n"); ok(GetLastError() == 0xdeadbeef || GetLastError() == ERROR_SUCCESS, /* win9x */ "Expected 0xdeadbeef or ERROR_SUCCESS, got %d\n", GetLastError()); FreeLibrary(hmodule); GetCurrentDirectoryA(MAX_PATH, path); if (path[lstrlenA(path) - 1] != '\\') lstrcatA(path, "\\"); lstrcatA(path, "kernel32.dll"); /* load kernel32.dll with an absolute path that does not exist */ SetLastError(0xdeadbeef); hmodule = LoadLibraryExA(path, NULL, LOAD_LIBRARY_AS_DATAFILE); todo_wine { ok(hmodule == 0, "Expected 0, got %p\n", hmodule); } ok(GetLastError() == ERROR_FILE_NOT_FOUND || broken(GetLastError() == ERROR_INVALID_HANDLE), /* nt4 */ "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); /* Free the loaded dll when it's the first time this dll is loaded in process - First time should pass, second fail */ SetLastError(0xdeadbeef); hmodule = LoadLibraryExA("comctl32.dll", NULL, LOAD_LIBRARY_AS_DATAFILE); ok(hmodule != 0, "Expected valid module handle\n"); SetLastError(0xdeadbeef); ret = FreeLibrary(hmodule); ok(ret, "Expected to be able to free the module, failed with %d\n", GetLastError()); SetLastError(0xdeadbeef); ret = FreeLibrary(hmodule); ok(!ret, "Unexpected ability to free the module, failed with %d\n", GetLastError()); /* load with full path, name without extension */ GetSystemDirectoryA(path, MAX_PATH); if (path[lstrlenA(path) - 1] != '\\') lstrcatA(path, "\\"); lstrcatA(path, "kernel32"); hmodule = LoadLibraryExA(path, NULL, 0); ok(hmodule != NULL, "got %p\n", hmodule); FreeLibrary(hmodule); /* same with alterate search path */ hmodule = LoadLibraryExA(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); ok(hmodule != NULL, "got %p\n", hmodule); FreeLibrary(hmodule); }
static void test_SetupGetFileCompressionInfoEx(void) { BOOL ret; DWORD required_len, source_size, target_size; char source[MAX_PATH], temp[MAX_PATH], name[MAX_PATH]; UINT type; GetTempPathA(sizeof(temp), temp); GetTempFileNameA(temp, "doc", 0, source); ret = pSetupGetFileCompressionInfoExA(NULL, NULL, 0, NULL, NULL, NULL, NULL); ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n"); ret = pSetupGetFileCompressionInfoExA(source, NULL, 0, NULL, NULL, NULL, NULL); ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n"); ret = pSetupGetFileCompressionInfoExA(source, NULL, 0, &required_len, NULL, NULL, NULL); ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n"); ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1); create_source_file(source, comp_lzx, sizeof(comp_lzx)); ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type); ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret); ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source); ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1); ok(source_size == sizeof(comp_lzx), "got %d\n", source_size); ok(target_size == sizeof(uncompressed), "got %d\n", target_size); ok(type == FILE_COMPRESSION_WINLZA, "got %d, expected FILE_COMPRESSION_WINLZA\n", type); DeleteFileA(source); create_source_file(source, comp_zip, sizeof(comp_zip)); ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type); ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret); ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source); ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1); ok(source_size == sizeof(comp_zip), "got %d\n", source_size); ok(target_size == sizeof(comp_zip), "got %d\n", target_size); ok(type == FILE_COMPRESSION_NONE, "got %d, expected FILE_COMPRESSION_NONE\n", type); DeleteFileA(source); create_source_file(source, comp_cab_lzx, sizeof(comp_cab_lzx)); ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type); ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret); ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source); ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1); ok(source_size == sizeof(comp_cab_lzx), "got %d\n", source_size); ok(target_size == sizeof(uncompressed), "got %d\n", target_size); ok(type == FILE_COMPRESSION_MSZIP, "got %d, expected FILE_COMPRESSION_MSZIP\n", type); DeleteFileA(source); create_source_file(source, comp_cab_zip, sizeof(comp_cab_zip)); ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type); ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret); ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source); ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1); ok(source_size == sizeof(comp_cab_zip), "got %d\n", source_size); ok(target_size == sizeof(uncompressed), "got %d\n", target_size); ok(type == FILE_COMPRESSION_MSZIP, "got %d, expected FILE_COMPRESSION_MSZIP\n", type); DeleteFileA(source); }
static void test_legacy_filter_registration(void) { IFilterMapper2 *pMapper2 = NULL; IFilterMapper *pMapper = NULL; HRESULT hr; static const WCHAR wszFilterName[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', 0 }; static const CHAR szFilterName[] = "Testfilter"; static const WCHAR wszPinName[] = {'P', 'i', 'n', '1', 0 }; CLSID clsidFilter; CHAR szRegKey[MAX_PATH]; static const CHAR szClsid[] = "CLSID"; WCHAR wszGuidstring[MAX_PATH]; CHAR szGuidstring[MAX_PATH]; LONG lRet; HKEY hKey = NULL; IEnumMoniker *pEnum = NULL; BOOL found; IEnumRegFilters *pRegEnum = NULL; /* Test if legacy filter registration scheme works (filter is added to HKCR\Filter). IFilterMapper_RegisterFilter * registers in this way. Filters so registered must then be accessible through both IFilterMapper_EnumMatchingFilters * and IFilterMapper2_EnumMatchingFilters. */ hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pMapper2); ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr); if (FAILED(hr)) goto out; hr = IFilterMapper2_QueryInterface(pMapper2, &IID_IFilterMapper, (void **)&pMapper); ok(hr == S_OK, "IFilterMapper2_QueryInterface failed with %x\n", hr); if (FAILED(hr)) goto out; /* Register a test filter. */ hr = CoCreateGuid(&clsidFilter); ok(hr == S_OK, "CoCreateGuid failed with %x\n", hr); lRet = StringFromGUID2(&clsidFilter, wszGuidstring, MAX_PATH); ok(lRet > 0, "StringFromGUID2 failed\n"); if (!lRet) goto out; WideCharToMultiByte(CP_ACP, 0, wszGuidstring, -1, szGuidstring, MAX_PATH, 0, 0); lstrcpyA(szRegKey, szClsid); lstrcatA(szRegKey, "\\"); lstrcatA(szRegKey, szGuidstring); /* Register---- functions need a filter class key to write pin and pin media type data to. Create a bogus * class key for it. */ lRet = RegCreateKeyExA(HKEY_CLASSES_ROOT, szRegKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL); if (lRet == ERROR_ACCESS_DENIED) skip("Not authorized to register filters\n"); else { ok(lRet == ERROR_SUCCESS, "RegCreateKeyExA failed with %x\n", HRESULT_FROM_WIN32(lRet)); /* Set default value - this is interpreted as "friendly name" later. */ lRet = RegSetValueExA(hKey, NULL, 0, REG_SZ, (LPBYTE)szFilterName, lstrlenA(szFilterName) + 1); ok(lRet == ERROR_SUCCESS, "RegSetValueExA failed with %x\n", HRESULT_FROM_WIN32(lRet)); if (hKey) RegCloseKey(hKey); hKey = NULL; hr = IFilterMapper_RegisterFilter(pMapper, clsidFilter, wszFilterName, MERIT_UNLIKELY); ok(hr == S_OK, "IFilterMapper_RegisterFilter failed with %x\n", hr); hr = IFilterMapper_RegisterPin(pMapper, clsidFilter, wszPinName, TRUE, FALSE, FALSE, FALSE, GUID_NULL, NULL); ok(hr == S_OK, "IFilterMapper_RegisterPin failed with %x\n", hr); hr = IFilterMapper_RegisterPinType(pMapper, clsidFilter, wszPinName, GUID_NULL, GUID_NULL); ok(hr == S_OK, "IFilterMapper_RegisterPinType failed with %x\n", hr); hr = IFilterMapper2_EnumMatchingFilters(pMapper2, &pEnum, 0, TRUE, MERIT_UNLIKELY, TRUE, 0, NULL, NULL, &GUID_NULL, FALSE, FALSE, 0, NULL, NULL, &GUID_NULL); ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr); if (SUCCEEDED(hr) && pEnum) { found = enum_find_filter(wszFilterName, pEnum); ok(found, "IFilterMapper2_EnumMatchingFilters failed to return the test filter\n"); } if (pEnum) IEnumMoniker_Release(pEnum); pEnum = NULL; found = FALSE; hr = IFilterMapper_EnumMatchingFilters(pMapper, &pRegEnum, MERIT_UNLIKELY, TRUE, GUID_NULL, GUID_NULL, FALSE, FALSE, GUID_NULL, GUID_NULL); ok(hr == S_OK, "IFilterMapper_EnumMatchingFilters failed with %x\n", hr); if (SUCCEEDED(hr) && pRegEnum) { ULONG cFetched; REGFILTER *prgf; while(!found && IEnumRegFilters_Next(pRegEnum, 1, &prgf, &cFetched) == S_OK) { CHAR val[512]; WideCharToMultiByte(CP_ACP, 0, prgf->Name, -1, val, sizeof(val), 0, 0); if (!lstrcmpA(val, szFilterName)) found = TRUE; CoTaskMemFree(prgf); } IEnumRegFilters_Release(pRegEnum); } ok(found, "IFilterMapper_EnumMatchingFilters failed to return the test filter\n"); hr = IFilterMapper_UnregisterFilter(pMapper, clsidFilter); ok(hr == S_OK, "FilterMapper_UnregisterFilter failed with %x\n", hr); lRet = RegOpenKeyExA(HKEY_CLASSES_ROOT, szClsid, 0, KEY_WRITE | DELETE, &hKey); ok(lRet == ERROR_SUCCESS, "RegOpenKeyExA failed with %x\n", HRESULT_FROM_WIN32(lRet)); lRet = RegDeleteKeyA(hKey, szGuidstring); ok(lRet == ERROR_SUCCESS, "RegDeleteKeyA failed with %x\n", HRESULT_FROM_WIN32(lRet)); } if (hKey) RegCloseKey(hKey); hKey = NULL; out: if (pMapper) IFilterMapper_Release(pMapper); if (pMapper2) IFilterMapper2_Release(pMapper2); }
__declspec(dllexport) void download (HWND parent, int string_size, TCHAR *variables, stack_t **stacktop) { char buf[1024]; char url[1024]; TCHAR filenameT[1024]; static char proxy[1024]; BOOL bSuccess=FALSE; int timeout_ms=30000; int getieproxy=1; int manualproxy=0; int translation_version; const char *error=NULL; // translation version 2 & 1 static char szDownloading[1024]; // "Downloading %s" static char szConnecting[1024]; // "Connecting ..." static char szSecond[1024]; // " (1 second remaining)" for v2 // "second" for v1 static char szMinute[1024]; // " (1 minute remaining)" for v2 // "minute" for v1 static char szHour[1024]; // " (1 hour remaining)" for v2 // "hour" for v1 static char szProgress[1024]; // "%skB (%d%%) of %skB at %u.%01ukB/s" for v2 // "%dkB (%d%%) of %dkB at %d.%01dkB/s" for v1 // translation version 2 only static char szSeconds[1024]; // " (%u seconds remaining)" static char szMinutes[1024]; // " (%u minutes remaining)" static char szHours[1024]; // " (%u hours remaining)" // translation version 1 only static char szPlural[1024]; // "s"; static char szRemaining[1024]; // " (%d %s%s remaining)"; EXDLL_INIT(); PopStringA(url); if (!lstrcmpiA(url, "/TRANSLATE2")) { PopStringA(szDownloading); PopStringA(szConnecting); PopStringA(szSecond); PopStringA(szMinute); PopStringA(szHour); PopStringA(szSeconds); PopStringA(szMinutes); PopStringA(szHours); PopStringA(szProgress); PopStringA(url); translation_version=2; } else if (!lstrcmpiA(url, "/TRANSLATE")) { PopStringA(szDownloading); PopStringA(szConnecting); PopStringA(szSecond); PopStringA(szMinute); PopStringA(szHour); PopStringA(szPlural); PopStringA(szProgress); PopStringA(szRemaining); PopStringA(url); translation_version=1; } else { lstrcpyA(szDownloading, "Downloading %s"); lstrcpyA(szConnecting, "Connecting ..."); lstrcpyA(szSecond, " (1 second remaining)"); lstrcpyA(szMinute, " (1 minute remaining)"); lstrcpyA(szHour, " (1 hour remaining)"); lstrcpyA(szSeconds, " (%u seconds remaining)"); lstrcpyA(szMinutes, " (%u minutes remaining)"); lstrcpyA(szHours, " (%u hours remaining)"); lstrcpyA(szProgress, "%skB (%d%%) of %skB at %u.%01ukB/s"); translation_version=2; } lstrcpynA(buf, url, 10); if (!lstrcmpiA(buf, "/TIMEOUT=")) { timeout_ms=my_atoi(url+9); PopStringA(url); } if (!lstrcmpiA(url, "/PROXY")) { getieproxy=0; manualproxy=1; PopStringA(proxy); PopStringA(url); } if (!lstrcmpiA(url, "/NOIEPROXY")) { getieproxy=0; PopStringA(url); } popstring(filenameT); static char main_buf[8192]; char *filenameA; #ifdef _UNICODE filenameA = main_buf; wsprintfA(filenameA, "%S", filenameT); #else filenameA = filenameT; #endif HANDLE hFile = CreateFile(filenameT,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL); if (hFile == INVALID_HANDLE_VALUE) { wsprintfA(buf, "Unable to open %s", filenameA); error = buf; } else { if (parent) { uMsgCreate = RegisterWindowMessage(_T("nsisdl create")); lpWndProcOld = (WNDPROC)SetWindowLongPtr(parent,GWLP_WNDPROC,(LONG_PTR)ParentWndProc); SendMessage(parent, uMsgCreate, TRUE, (LPARAM) parent); // set initial text char *p = filenameA; while (*p) p++; while (*p !='\\' && p != filenameA) p = CharPrevA(filenameA, p); wsprintfA(buf, szDownloading, p != filenameA ? p + 1 : p); SetDlgItemTextA(childwnd, 1006, buf); SetWindowTextA(g_hwndStatic, szConnecting); } { WSADATA wsaData; WSAStartup(MAKEWORD(1, 1), &wsaData); JNL_HTTPGet *get = 0; char *buf = main_buf, *p = NULL; HKEY hKey; if (getieproxy && RegOpenKeyExA(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",0,KEY_READ,&hKey) == ERROR_SUCCESS) { DWORD l = 4; DWORD t; DWORD v; if (RegQueryValueExA(hKey,"ProxyEnable",NULL,&t,(unsigned char*)&v,&l) == ERROR_SUCCESS && t == REG_DWORD && v) { l=8192; if (RegQueryValueExA(hKey,"ProxyServer",NULL,&t,(unsigned char *)buf,&l ) == ERROR_SUCCESS && t == REG_SZ) { p=strstr(buf,"http="); if (!p) p=buf; else { p+=5; } char *tp=strstr(p,";"); if (tp) *tp=0; char *p2=strstr(p,"="); if (p2) p=0; // we found the wrong proxy } } buf[8192-1]=0; RegCloseKey(hKey); } if (manualproxy == 1) { p = proxy; } DWORD start_time=GetTickCount(); get=new JNL_HTTPGet(JNL_CONNECTION_AUTODNS,16384,(p&&p[0])?p:NULL); int st; int has_printed_headers = 0; __int64 cl = 0; int len; __int64 sofar = 0; DWORD last_recv_time=start_time; get->addheader ("User-Agent: NSISDL/1.2 (Mozilla)"); get->addheader ("Accept: */*"); get->connect (url); while (1) { if (g_cancelled) error = "cancel"; if (error) { if (parent) { SendMessage(parent, uMsgCreate, FALSE, (LPARAM) parent); SetWindowLongPtr(parent, GWLP_WNDPROC, (LONG_PTR)lpWndProcOld); } break; } st = get->run (); if (st == -1) { lstrcpynA(url, get->geterrorstr(), sizeof(url)); error = url; } else if (st == 1) { if (sofar < cl || get->get_status () != 2) error="download incomplete"; else { bSuccess=TRUE; error = "success"; } } else { if (get->get_status () == 0) { // progressFunc ("Connecting ...", 0); if (last_recv_time+timeout_ms < GetTickCount()) error = "Timed out on connecting."; else Sleep(10); // don't busy-loop while connecting } else if (get->get_status () == 1) { progress_callback("Reading headers", 0); if (last_recv_time+timeout_ms < GetTickCount()) error = "Timed out on getting headers."; else Sleep(10); // don't busy-loop while reading headers } else if (get->get_status () == 2) { if (! has_printed_headers) { has_printed_headers = 1; last_recv_time=GetTickCount(); cl = get->content_length (); if (cl == 0) error = "Server did not specify content length."; else if (g_hwndProgressBar) { SendMessage(g_hwndProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0, 30000)); g_file_size = cl; } } int data_downloaded = 0; while ((len = get->bytes_available ()) > 0) { data_downloaded++; if (len > 8192) len = 8192; len = get->get_bytes (buf, len); if (len > 0) { last_recv_time=GetTickCount(); DWORD dw; WriteFile(hFile,buf,len,&dw,NULL); sofar += len; int time_sofar=(GetTickCount()-start_time)/1000; int bps = (int)(sofar/(time_sofar?time_sofar:1)); int remain = MulDiv64(time_sofar, cl, sofar) - time_sofar; if (translation_version == 2) { char *rtext=remain==1?szSecond:szSeconds;; if (remain >= 60) { remain/=60; rtext=remain==1?szMinute:szMinutes; if (remain >= 60) { remain/=60; rtext=remain==1?szHour:szHours; } } char sofar_str[128]; char cl_str[128]; myitoa64(sofar/1024, sofar_str); myitoa64(cl/1024, cl_str); wsprintfA (buf, szProgress, //%skB (%d%%) of %skB @ %u.%01ukB/s sofar_str, MulDiv64(100, sofar, cl), cl_str, bps/1024,((bps*10)/1024)%10 ); if (remain) wsprintfA(buf+lstrlenA(buf),rtext, remain ); } else if (translation_version == 1) { char *rtext=szSecond; if (remain >= 60) { remain/=60; rtext=szMinute; if (remain >= 60) { remain/=60; rtext=szHour; } } wsprintfA (buf, szProgress, //%dkB (%d%%) of %dkB @ %d.%01dkB/s int(sofar/1024), MulDiv64(100, sofar, cl), int(cl/1024), bps/1024,((bps*10)/1024)%10 ); if (remain) wsprintfA(buf+lstrlenA(buf),szRemaining, remain, rtext, remain==1?"":szPlural ); } progress_callback(buf, sofar); } else { if (sofar < cl) error = "Server aborted."; } } if (GetTickCount() > last_recv_time+timeout_ms) { if (sofar != cl) { error = "Downloading timed out."; } else { // workaround for bug #1713562 // buggy servers that wait for the client to close the connection. // another solution would be manually stopping when cl == sofar, // but then buggy servers that return wrong content-length will fail. bSuccess = TRUE; error = "success"; } } else if (!data_downloaded) Sleep(10); } else { error = "Bad response status."; } } } // Clean up the connection then release winsock if (get) delete get; WSACleanup(); } CloseHandle(hFile); } if (g_cancelled || !bSuccess) { DeleteFile(filenameT); } PushStringA(error); }
bool CPluginAnsi::UpdateConEmuTabsApi(int windowCount) { if (!InfoA || gbIgnoreUpdateTabs) return false; bool lbCh = false, lbDummy = false; WindowInfo WInfo; WCHAR* pszName = gszDir1; pszName[0] = 0; //(WCHAR*)calloc(CONEMUTABMAX, sizeof(WCHAR)); int tabCount = 0; bool lbActiveFound = false; for (int i = 0; i < windowCount; i++) { WInfo.Pos = i; _ASSERTE(GetCurrentThreadId() == gnMainThreadId); InfoA->AdvControl(InfoA->ModuleNumber, ACTL_GETSHORTWINDOWINFO, (void*)&WInfo); if (WInfo.Type == WTYPE_EDITOR || WInfo.Type == WTYPE_VIEWER || WInfo.Type == WTYPE_PANELS) { InfoA->AdvControl(InfoA->ModuleNumber, ACTL_GETWINDOWINFO, (void*)&WInfo); if (WInfo.Type == WTYPE_EDITOR || WInfo.Type == WTYPE_VIEWER || WInfo.Type == WTYPE_PANELS) { #ifdef SHOW_DEBUG_EVENTS char szDbg[255]; wsprintfA(szDbg, "Window %i (Type=%i, Modified=%i)\n", i, WInfo.Type, WInfo.Modified); OutputDebugStringA(szDbg); #endif if (WInfo.Current) lbActiveFound = true; MultiByteToWideChar(CP_OEMCP, 0, WInfo.Name, lstrlenA(WInfo.Name)+1, pszName, CONEMUTABMAX); TODO("Определение ИД редактора/вьювера"); lbCh |= AddTab(tabCount, -1, false/*losingFocus*/, false/*editorSave*/, WInfo.Type, pszName, /*editorSave ? pszFileName :*/ NULL, WInfo.Current, WInfo.Modified, 0, 0); //if (WInfo.Type == WTYPE_EDITOR && WInfo.Current) //2009-08-17 // lastModifiedStateW = WInfo.Modified; } } } // Скорее всего это модальный редактор (или вьювер?) if (!lbActiveFound) { WInfo.Pos = -1; _ASSERTE(GetCurrentThreadId() == gnMainThreadId); InfoA->AdvControl(InfoA->ModuleNumber, ACTL_GETSHORTWINDOWINFO, (void*)&WInfo); if (WInfo.Type == WTYPE_EDITOR || WInfo.Type == WTYPE_VIEWER) { WInfo.Pos = -1; InfoA->AdvControl(InfoA->ModuleNumber, ACTL_GETWINDOWINFO, (void*)&WInfo); if (WInfo.Type == WTYPE_EDITOR || WInfo.Type == WTYPE_VIEWER) { tabCount = 0; MultiByteToWideChar(CP_OEMCP, 0, WInfo.Name, lstrlenA(WInfo.Name)+1, pszName, CONEMUTABMAX); TODO("Определение ИД редактора/вьювера"); lbCh |= AddTab(tabCount, -1, false/*losingFocus*/, false/*editorSave*/, WInfo.Type, pszName, /*editorSave ? pszFileName :*/ NULL, WInfo.Current, WInfo.Modified, 0, 0); } } else if (WInfo.Type == WTYPE_PANELS) { gpTabs->Tabs.CurrentType = gnCurrentWindowType = WInfo.Type; } } // 101224 - сразу запомнить количество! AddTabFinish(tabCount); return lbCh; }
NetworkClient::NetworkClient(void) { #ifndef IU_CLI _mutex.acquire(); #endif if(!_curl_init) { enableResponseCodeChecking_ = true; curl_global_init(CURL_GLOBAL_ALL); curl_version_info_data * infoData = curl_version_info(CURLVERSION_NOW); _is_openssl = strstr(infoData->ssl_version, "WinSSL")!=infoData->ssl_version; #ifdef WIN32 GetModuleFileNameA(0, CertFileName, 1023); int i, len = lstrlenA(CertFileName); for(i=len; i>=0; i--) { if(CertFileName[i] == '\\') { CertFileName[i+1] = 0; break; } } strcat(CertFileName, "curl-ca-bundle.crt"); #endif atexit(&curl_cleanup); _curl_init = true; } #ifndef IU_CLI _mutex.release(); #endif m_hOutFile = 0; chunkOffset_ = -1; chunkSize_ = -1; chunk_ = 0; m_CurrentFileSize = -1; m_uploadingFile = NULL; *m_errorBuffer = 0; m_progressCallbackFunc = NULL; curl_handle = curl_easy_init(); // Initializing libcurl m_bodyFuncData.funcType = funcTypeBody; m_bodyFuncData.nmanager = this; m_UploadBufferSize = 65536; m_headerFuncData.funcType = funcTypeHeader; m_headerFuncData.nmanager = this; m_nUploadDataOffset = 0; treatErrorsAsWarnings_ = false; curl_easy_setopt(curl_handle, CURLOPT_COOKIELIST, ""); setUserAgent("Mozilla/5.0"); curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, private_static_writer); curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, &m_bodyFuncData); curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, &m_headerFuncData); curl_easy_setopt(curl_handle, CURLOPT_ERRORBUFFER, m_errorBuffer); curl_easy_setopt(curl_handle, CURLOPT_PROGRESSFUNCTION, &ProgressFunc); curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 0L); curl_easy_setopt(curl_handle, CURLOPT_PROGRESSDATA, this); curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl_handle, CURLOPT_ENCODING, ""); curl_easy_setopt(curl_handle, CURLOPT_SOCKOPTFUNCTION, &set_sockopts); curl_easy_setopt(curl_handle, CURLOPT_SOCKOPTDATA, this); #ifdef _WIN32 curl_easy_setopt(curl_handle, CURLOPT_CAINFO, CertFileName); #endif curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 1L); curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 2L); //curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L); //curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0L); //We want the referrer field set automatically when following locations curl_easy_setopt(curl_handle, CURLOPT_AUTOREFERER, 1L); curl_easy_setopt(curl_handle, CURLOPT_BUFFERSIZE, 32768L); curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 0L); }
int ModernDrawStatusBarWorker(HWND hWnd, HDC hDC) { int iconHeight = GetSystemMetrics(SM_CYSMICON)+2; int i; // Count visible protos RECT rc; GetClientRect(hWnd, &rc); if (g_CluiData.fDisableSkinEngine) { if (g_StatusBarData.bkUseWinColors && xpt_IsThemed(g_StatusBarData.hTheme)) xpt_DrawTheme(g_StatusBarData.hTheme, hWnd, hDC, 0, 0, &rc, &rc); else DrawBackGround(hWnd, hDC, g_StatusBarData.hBmpBackground, g_StatusBarData.bkColour, g_StatusBarData.backgroundBmpUse); } else SkinDrawGlyph(hDC, &rc, &rc, "Main,ID=StatusBar"); //TBD g_StatusBarData.nProtosPerLine = db_get_b(NULL,"CLUI","StatusBarProtosPerLine",SETTING_PROTOSPERLINE_DEFAULT); HFONT hOldFont = g_clcPainter.ChangeToFont(hDC,NULL,FONTID_STATUSBAR_PROTONAME,NULL); SIZE textSize = {0}; GetTextExtentPoint32A(hDC, " ", 1, &textSize); int spaceWidth = textSize.cx; int textY = rc.top+((rc.bottom-rc.top-textSize.cy)>>1); int iconY = rc.top+((rc.bottom-rc.top-GetSystemMetrics(SM_CXSMICON))>>1); ProtosData.destroy(); int protoCount; PROTOACCOUNT **accs; ProtoEnumAccounts( &protoCount, &accs ); if (protoCount == 0) return 0; for (int j = 0; j < protoCount; j++) { int i = pcli->pfnGetAccountIndexByPos(j); if (i == -1 || !pcli->pfnGetProtocolVisibility(accs[i]->szModuleName)) continue; char buf[256]; mir_snprintf(buf, SIZEOF(buf), "SBarAccountIsCustom_%s", accs[i]->szModuleName); ProtoItemData *p = new ProtoItemData; if (g_StatusBarData.perProtoConfig && db_get_b(NULL, "CLUI", buf, SETTING_SBARACCOUNTISCUSTOM_DEFAULT)) { mir_snprintf(buf, SIZEOF(buf), "HideAccount_%s", accs[i]->szModuleName); if ( db_get_b(NULL, "CLUI", buf, SETTING_SBARHIDEACCOUNT_DEFAULT)) continue; mir_snprintf(buf, SIZEOF(buf), "SBarShow_%s", accs[i]->szModuleName); BYTE showOps = db_get_b(NULL,"CLUI", buf, SETTING_SBARSHOW_DEFAULT); p->showProtoIcon = showOps & 1; p->showProtoName = showOps & 2; p->showStatusName = showOps & 4; mir_snprintf(buf, SIZEOF(buf), "ShowXStatus_%s", accs[i]->szModuleName); p->xStatusMode = db_get_b(NULL,"CLUI", buf, SETTING_SBARSHOW_DEFAULT); mir_snprintf(buf, SIZEOF(buf), "UseConnectingIcon_%s", accs[i]->szModuleName); p->connectingIcon = db_get_b(NULL,"CLUI", buf, SETTING_USECONNECTINGICON_DEFAULT); mir_snprintf(buf, SIZEOF(buf), "ShowUnreadEmails_%s", accs[i]->szModuleName); p->showProtoEmails = db_get_b(NULL,"CLUI", buf, SETTING_SHOWUNREADEMAILS_DEFAULT); mir_snprintf(buf, SIZEOF(buf), "SBarRightClk_%s", accs[i]->szModuleName); p->SBarRightClk = db_get_b(NULL,"CLUI", buf, SETTING_SBARRIGHTCLK_DEFAULT); mir_snprintf(buf, SIZEOF(buf), "PaddingLeft_%s", accs[i]->szModuleName); p->PaddingLeft = db_get_dw(NULL,"CLUI", buf, SETTING_PADDINGLEFT_DEFAULT); mir_snprintf(buf, SIZEOF(buf), "PaddingRight_%s", accs[i]->szModuleName); p->PaddingRight = db_get_dw(NULL,"CLUI", buf, SETTING_PADDINGRIGHT_DEFAULT); } else { p->showProtoIcon = g_StatusBarData.showProtoIcon; p->showProtoName = g_StatusBarData.showProtoName; p->showStatusName = g_StatusBarData.showStatusName; p->xStatusMode = g_StatusBarData.xStatusMode; p->connectingIcon = g_StatusBarData.connectingIcon; p->showProtoEmails = g_StatusBarData.showProtoEmails; p->SBarRightClk = 0; p->PaddingLeft = 0; p->PaddingRight = 0; } p->ProtoStatus = CallProtoService(accs[i]->szModuleName,PS_GETSTATUS, 0, 0); if (p->ProtoStatus > ID_STATUS_OFFLINE) { if (p->showProtoEmails == 1 && ProtoServiceExists(accs[i]->szModuleName, PS_GETUNREADEMAILCOUNT)) { char buf[40]; mir_snprintf(buf, SIZEOF(buf),"[%d]", (int)ProtoCallService(accs[i]->szModuleName, PS_GETUNREADEMAILCOUNT, 0, 0)); p->ProtoEMailCount = mir_strdup(buf); } } p->ProtoHumanName = mir_tstrdup(accs[i]->tszAccountName); p->AccountName = mir_strdup(accs[i]->szModuleName); p->ProtoName = mir_strdup(accs[i]->szProtoName); p->ProtoStatusText = mir_tstrdup(pcli->pfnGetStatusModeDescription(p->ProtoStatus, 0)); p->ProtoPos = ProtosData.getCount(); p->isDimmed = 0; if (g_CluiData.bFilterEffective & CLVM_FILTER_PROTOS) { char szTemp[2048]; mir_snprintf(szTemp, SIZEOF(szTemp), "%s|", p->AccountName ); p->isDimmed = strstr(g_CluiData.protoFilter, szTemp) ? 0 : 1; } ProtosData.insert(p); } if ( ProtosData.getCount() == 0) return 0; //START MULTILINE HERE int orig_protoCount = protoCount; int orig_visProtoCount = ProtosData.getCount(); int protosperline = 0; if (g_StatusBarData.nProtosPerLine) protosperline = g_StatusBarData.nProtosPerLine; else if (orig_visProtoCount) protosperline = orig_visProtoCount; else if (protoCount) { protosperline = protoCount; orig_visProtoCount = protoCount; } else { protosperline = 1; orig_visProtoCount = 1; } protosperline = min(protosperline,orig_visProtoCount); int linecount = protosperline ? (orig_visProtoCount+(protosperline-1))/protosperline : 1; //divide with rounding to up for (int line = 0; line < linecount; line++) { int rowheight = max(textSize.cy+2, iconHeight); protoCount = min(protosperline,(orig_protoCount-line*protosperline)); int visProtoCount = min(protosperline,(orig_visProtoCount-line*protosperline)); GetClientRect(hWnd,&rc); rc.top += g_StatusBarData.rectBorders.top; rc.bottom -= g_StatusBarData.rectBorders.bottom; int aligndx = 0, maxwidth = 0, xstatus = 0, SumWidth = 0; int height = (rowheight*linecount); if (height > (rc.bottom - rc.top)) { rowheight = (rc.bottom - rc.top) / linecount; height = (rowheight*linecount); } int rowsdy = ((rc.bottom-rc.top)-height)/2; if (rowheight*(line)+rowsdy < rc.top-rowheight) continue; if (rowheight*(line+1)+rowsdy>rc.bottom+rowheight) break; if (g_StatusBarData.VAlign == 0) { //top rc.bottom = rc.top+rowheight*(line+1); rc.top = rc.top+rowheight*line+1; } else if (g_StatusBarData.VAlign == 1) { //center rc.bottom = rc.top+rowsdy+rowheight*(line+1); rc.top = rc.top+rowsdy+rowheight*line+1; } else if (g_StatusBarData.VAlign == 2) { //bottom rc.top = rc.bottom - (rowheight*(linecount - line)); rc.bottom = rc.bottom - (rowheight*(linecount - line - 1)+1); } textY = rc.top + (((rc.bottom-rc.top) - textSize.cy)/2); iconY = rc.top + (((rc.bottom-rc.top) - iconHeight)/2); //Code for each line DWORD sw; int rectwidth = rc.right - rc.left - g_StatusBarData.rectBorders.left - g_StatusBarData.rectBorders.right; if (visProtoCount > 1) sw = (rectwidth - (g_StatusBarData.extraspace*(visProtoCount-1))) / visProtoCount; else sw = rectwidth; int *ProtoWidth = (int*)mir_alloc(sizeof(int)*visProtoCount); for (i=0; i < visProtoCount; i++) { ProtoItemData &p = ProtosData[line*protosperline + i]; DWORD w = p.PaddingLeft; w += p.PaddingRight; if (p.showProtoIcon) { w += GetSystemMetrics(SM_CXSMICON)+1; p.extraIcon = NULL; if ((p.xStatusMode & 8) && p.ProtoStatus > ID_STATUS_OFFLINE) { TCHAR str[512]; CUSTOM_STATUS cs = { sizeof(cs) }; cs.flags = CSSF_MASK_NAME | CSSF_TCHAR; cs.ptszName = str; if ( CallProtoService(p.AccountName, PS_GETCUSTOMSTATUSEX, 0, (LPARAM)&cs) == 0) p.ProtoXStatus = mir_tstrdup(str); } if ((p.xStatusMode & 3)) { if (p.ProtoStatus > ID_STATUS_OFFLINE) { if ( ProtoServiceExists(p.AccountName, PS_GETCUSTOMSTATUSICON)) p.extraIcon = (HICON)ProtoCallService(p.AccountName, PS_GETCUSTOMSTATUSICON, 0, 0); if (p.extraIcon && (p.xStatusMode & 3) == 3) w += GetSystemMetrics(SM_CXSMICON)+1; } } } SIZE textSize; if (p.showProtoName) { GetTextExtentPoint32(hDC, p.ProtoHumanName, lstrlen(p.ProtoHumanName), &textSize); w += textSize.cx + 3 + spaceWidth; } if (p.showProtoEmails && p.ProtoEMailCount) { GetTextExtentPoint32A(hDC, p.ProtoEMailCount, lstrlenA(p.ProtoEMailCount), &textSize); w += textSize.cx + 3 + spaceWidth; } if (p.showStatusName) { GetTextExtentPoint32(hDC, p.ProtoStatusText, lstrlen(p.ProtoStatusText), &textSize); w += textSize.cx + 3 + spaceWidth; } if ((p.xStatusMode & 8) && p.ProtoXStatus) { GetTextExtentPoint32(hDC, p.ProtoXStatus, lstrlen(p.ProtoXStatus), &textSize); w += textSize.cx + 3 + spaceWidth; } if (p.showProtoName || (p.showProtoEmails && p.ProtoEMailCount) || p.showStatusName || ((p.xStatusMode & 8) && p.ProtoXStatus)) w -= spaceWidth; p.fullWidth = w; if (g_StatusBarData.sameWidth) { ProtoWidth[i] = sw; SumWidth += w; } else { ProtoWidth[i] = w; SumWidth += w; } } // Reposition rects for (i=0; i < visProtoCount; i++) if (ProtoWidth[i] > maxwidth) maxwidth = ProtoWidth[i]; if (g_StatusBarData.sameWidth) { for (i=0; i < visProtoCount; i++) ProtoWidth[i] = maxwidth; SumWidth = maxwidth * visProtoCount; } SumWidth += (visProtoCount-1) * (g_StatusBarData.extraspace+1); if (SumWidth > rectwidth) { float f = (float)rectwidth/SumWidth; SumWidth = 0; for (i=0; i < visProtoCount; i++) { ProtoWidth[i] = (int)((float)ProtoWidth[i]*f); SumWidth += ProtoWidth[i]; } SumWidth += (visProtoCount-1)*(g_StatusBarData.extraspace+1); } if (g_StatusBarData.Align == 1) //center aligndx = (rectwidth-SumWidth)>>1; else if (g_StatusBarData.Align == 2) //right aligndx = (rectwidth-SumWidth); // Draw in rects RECT r = rc; r.left += g_StatusBarData.rectBorders.left+aligndx; for (i=0; i < visProtoCount; i++) { ProtoItemData& p = ProtosData[line*protosperline + i]; HRGN rgn; HICON hIcon = NULL; HICON hxIcon = NULL; BOOL NeedDestroy = FALSE; int x = r.left; x += p.PaddingLeft; r.right = r.left+ProtoWidth[i]; if (p.showProtoIcon) { if (p.ProtoStatus > ID_STATUS_OFFLINE && (p.xStatusMode & 3) > 0) { if ( ProtoServiceExists(p.AccountName, PS_GETCUSTOMSTATUSICON)) { hxIcon = p.extraIcon; if (hxIcon) { if ((p.xStatusMode & 3) == 2) { hIcon = GetMainStatusOverlay(p.ProtoStatus); NeedDestroy = TRUE; } else if ((p.xStatusMode & 3) == 1) { hIcon = hxIcon; NeedDestroy = TRUE; hxIcon = NULL; } } } } if (hIcon == NULL && (hxIcon == NULL || ((p.xStatusMode & 3) == 3))) { if ((p.connectingIcon == 1) && p.ProtoStatus >= ID_STATUS_CONNECTING && p.ProtoStatus <= ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES) { hIcon = (HICON)CLUI_GetConnectingIconService((WPARAM)p.AccountName,0); if (hIcon) NeedDestroy = TRUE; else hIcon = LoadSkinnedProtoIcon(p.AccountName,p.ProtoStatus); } else hIcon = LoadSkinnedProtoIcon(p.AccountName,p.ProtoStatus); } rgn = CreateRectRgn(r.left,r.top,r.right,r.bottom); if (g_StatusBarData.sameWidth) { int fw = p.fullWidth; int rw = r.right-r.left; if (g_StatusBarData.Align == 1) x = r.left+((rw-fw)/2); else if (g_StatusBarData.Align == 2) x = r.left+((rw-fw)); else x = r.left; } SelectClipRgn(hDC,rgn); p.DoubleIcons = FALSE; DWORD dim = p.isDimmed ? (( 64 << 24 ) | 0x80 ) : 0; if ((p.xStatusMode&3) == 3) { if (hIcon) mod_DrawIconEx_helper(hDC,x,iconY,hIcon,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL|dim ); if (hxIcon) { mod_DrawIconEx_helper(hDC,x+GetSystemMetrics(SM_CXSMICON)+1,iconY,hxIcon,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON), 0, NULL,DI_NORMAL|dim); x += GetSystemMetrics(SM_CXSMICON)+1; } p.DoubleIcons = hIcon && hxIcon; } else { if (hxIcon) mod_DrawIconEx_helper(hDC,x,iconY,hxIcon,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON), 0, NULL,DI_NORMAL|dim); if (hIcon) mod_DrawIconEx_helper(hDC,x,iconY,hIcon,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON), 0, NULL,DI_NORMAL| ((hxIcon && (p.xStatusMode&4))?(192 << 24):0 ) | dim ); } if (hxIcon || hIcon) { /* TODO g_StatusBarData.bDrawLockOverlay options to draw locked proto*/ if ( db_get_b(NULL, p.AccountName,"LockMainStatus", 0)) { HICON hLockOverlay = LoadSkinnedIcon(SKINICON_OTHER_STATUS_LOCKED); if (hLockOverlay != NULL) { mod_DrawIconEx_helper(hDC, x, iconY, hLockOverlay, GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON), 0, NULL,DI_NORMAL | dim); Skin_ReleaseIcon(hLockOverlay); } } } if (hxIcon) DestroyIcon_protect(hxIcon); if (NeedDestroy) DestroyIcon_protect(hIcon); else Skin_ReleaseIcon(hIcon); x += GetSystemMetrics(SM_CXSMICON)+1; } if (p.showProtoName) { SIZE textSize; RECT rt = r; rt.left = x+(spaceWidth>>1); rt.top = textY; ske_DrawText(hDC, p.ProtoHumanName, lstrlen(p.ProtoHumanName), &rt, 0); if ((p.showProtoEmails && p.ProtoEMailCount != NULL) || p.showStatusName || ((p.xStatusMode & 8) && p.ProtoXStatus)) { GetTextExtentPoint32(hDC, p.ProtoHumanName, lstrlen(p.ProtoHumanName), &textSize); x += textSize.cx + 3; } } if (p.showProtoEmails && p.ProtoEMailCount != NULL) { SIZE textSize; RECT rt = r; rt.left = x+(spaceWidth>>1); rt.top = textY; ske_DrawTextA(hDC, p.ProtoEMailCount, lstrlenA(p.ProtoEMailCount), &rt, 0); if (p.showStatusName || ((p.xStatusMode & 8) && p.ProtoXStatus)) { GetTextExtentPoint32A(hDC,p.ProtoEMailCount,lstrlenA(p.ProtoEMailCount),&textSize); x += textSize.cx+3; } }
static void test_GetPrivateProfileString(const char *content, const char *descript) { DWORD ret, len; CHAR buf[MAX_PATH]; CHAR def_val[MAX_PATH]; CHAR path[MAX_PATH]; CHAR windir[MAX_PATH]; /* NT series crashes on r/o empty strings, so pass an r/w empty string and check for modification */ CHAR emptystr[MAX_PATH] = ""; LPSTR tempfile; static const char filename[] = ".\\winetest.ini"; trace("test_GetPrivateProfileStringA: %s\n", descript); if(!lstrcmpA(descript, "CR only")) { SetLastError(0xdeadbeef); ret = GetPrivateProfileStringW(NULL, NULL, NULL, NULL, 0, NULL); if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) { win_skip("Win9x and WinME don't handle 'CR only' correctly\n"); return; } } create_test_file(filename, content, lstrlenA(content)); /* Run this test series with caching. Wine won't cache profile files younger than 2.1 seconds. */ Sleep(2500); /* lpAppName is NULL */ memset(buf, 0xc, sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA(NULL, "name1", "default", buf, MAX_PATH, filename); ok(ret == 18 || broken(ret == 19), /* Win9x and WinME */ "Expected 18, got %d\n", ret); len = lstrlenA("section1") + sizeof(CHAR) + lstrlenA("section2") + 2 * sizeof(CHAR); ok(!memcmp(buf, "section1\0section2\0\0", len), "Expected \"section1\\0section2\\0\\0\", got \"%s\"\n", buf); /* lpAppName is empty */ memset(buf, 0xc, sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA(emptystr, "name1", "default", buf, MAX_PATH, filename); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "default"), "Expected \"default\", got \"%s\"\n", buf); ok(emptystr_ok(emptystr), "AppName modified\n"); /* lpAppName is missing */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("notasection", "name1", "default", buf, MAX_PATH, filename); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "default"), "Expected \"default\", got \"%s\"\n", buf); /* lpAppName is empty, lpDefault is NULL */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA(emptystr, "name1", NULL, buf, MAX_PATH, filename); ok(ret == 0, "Expected 0, got %d\n", ret); ok(!lstrcmpA(buf, "") || broken(!lstrcmpA(buf, "kumquat")), /* Win9x, WinME */ "Expected \"\", got \"%s\"\n", buf); ok(emptystr_ok(emptystr), "AppName modified\n"); /* lpAppName is empty, lpDefault is empty */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA(emptystr, "name1", "", buf, MAX_PATH, filename); ok(ret == 0, "Expected 0, got %d\n", ret); ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf); ok(emptystr_ok(emptystr), "AppName modified\n"); /* lpAppName is empty, lpDefault has trailing blank characters */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); /* lpDefault must be writable (trailing blanks are removed inplace in win9x) */ lstrcpyA(def_val, "default "); ret = GetPrivateProfileStringA(emptystr, "name1", def_val, buf, MAX_PATH, filename); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "default"), "Expected \"default\", got \"%s\"\n", buf); ok(emptystr_ok(emptystr), "AppName modified\n"); /* lpAppName is empty, many blank characters in lpDefault */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); /* lpDefault must be writable (trailing blanks are removed inplace in win9x) */ lstrcpyA(def_val, "one two "); ret = GetPrivateProfileStringA(emptystr, "name1", def_val, buf, MAX_PATH, filename); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "one two"), "Expected \"one two\", got \"%s\"\n", buf); ok(emptystr_ok(emptystr), "AppName modified\n"); /* lpAppName is empty, blank character but not trailing in lpDefault */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA(emptystr, "name1", "one two", buf, MAX_PATH, filename); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "one two"), "Expected \"one two\", got \"%s\"\n", buf); ok(emptystr_ok(emptystr), "AppName modified\n"); /* lpKeyName is NULL */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", NULL, "default", buf, MAX_PATH, filename); ok(ret == 18, "Expected 18, got %d\n", ret); ok(!memcmp(buf, "name1\0name2\0name4\0", ret + 1), "Expected \"name1\\0name2\\0name4\\0\", got \"%s\"\n", buf); /* lpKeyName is empty */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", emptystr, "default", buf, MAX_PATH, filename); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "default"), "Expected \"default\", got \"%s\"\n", buf); ok(emptystr_ok(emptystr), "KeyName modified\n"); /* lpKeyName is missing */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "notakey", "default", buf, MAX_PATH, filename); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "default"), "Expected \"default\", got \"%s\"\n", buf); /* lpKeyName is empty, lpDefault is NULL */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", emptystr, NULL, buf, MAX_PATH, filename); ok(ret == 0, "Expected 0, got %d\n", ret); ok(!lstrcmpA(buf, "") || broken(!lstrcmpA(buf, "kumquat")), /* Win9x, WinME */ "Expected \"\", got \"%s\"\n", buf); ok(emptystr_ok(emptystr), "KeyName modified\n"); /* lpKeyName is empty, lpDefault is empty */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", emptystr, "", buf, MAX_PATH, filename); ok(ret == 0, "Expected 0, got %d\n", ret); ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf); ok(emptystr_ok(emptystr), "KeyName modified\n"); /* lpKeyName is empty, lpDefault has trailing blank characters */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); /* lpDefault must be writable (trailing blanks are removed inplace in win9x) */ lstrcpyA(def_val, "default "); ret = GetPrivateProfileStringA("section1", emptystr, def_val, buf, MAX_PATH, filename); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "default"), "Expected \"default\", got \"%s\"\n", buf); ok(emptystr_ok(emptystr), "KeyName modified\n"); if (0) /* crashes */ { /* lpReturnedString is NULL */ ret = GetPrivateProfileStringA("section1", "name1", "default", NULL, MAX_PATH, filename); } /* lpFileName is NULL */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "name1", "default", buf, MAX_PATH, NULL); ok(ret == 7 || broken(ret == 0), /* Win9x, WinME */ "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "default") || broken(!lstrcmpA(buf, "kumquat")), /* Win9x, WinME */ "Expected \"default\", got \"%s\"\n", buf); /* lpFileName is empty */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "name1", "default", buf, MAX_PATH, ""); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "default"), "Expected \"default\", got \"%s\"\n", buf); /* lpFileName is nonexistent */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "name1", "default", buf, MAX_PATH, "nonexistent"); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "default"), "Expected \"default\", got \"%s\"\n", buf); /* nSize is 0 */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "name1", "default", buf, 0, filename); ok(ret == 0, "Expected 0, got %d\n", ret); ok(!lstrcmpA(buf, "kumquat"), "Expected buf to be unchanged, got \"%s\"\n", buf); /* nSize is exact size of output */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "name1", "default", buf, 4, filename); ok(ret == 3, "Expected 3, got %d\n", ret); ok(!lstrcmpA(buf, "val"), "Expected \"val\", got \"%s\"\n", buf); /* nSize has room for NULL terminator */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "name1", "default", buf, 5, filename); ok(ret == 4, "Expected 4, got %d\n", ret); ok(!lstrcmpA(buf, "val1"), "Expected \"val1\", got \"%s\"\n", buf); /* output is 1 character */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "name4", "default", buf, MAX_PATH, filename); ok(ret == 1, "Expected 1, got %d\n", ret); ok(!lstrcmpA(buf, "a"), "Expected \"a\", got \"%s\"\n", buf); /* output is 1 character, no room for NULL terminator */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "name4", "default", buf, 1, filename); ok(ret == 0, "Expected 0, got %d\n", ret); ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf); /* lpAppName is NULL, not enough room for final section name */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA(NULL, "name1", "default", buf, 16, filename); ok(ret == 14, "Expected 14, got %d\n", ret); len = lstrlenA("section1") + 2 * sizeof(CHAR); todo_wine ok(!memcmp(buf, "section1\0secti\0\0", ret + 2) || broken(!memcmp(buf, "section1\0\0", len)), /* Win9x, WinME */ "Expected \"section1\\0secti\\0\\0\", got \"%s\"\n", buf); /* lpKeyName is NULL, not enough room for final key name */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", NULL, "default", buf, 16, filename); ok(ret == 14, "Expected 14, got %d\n", ret); todo_wine ok(!memcmp(buf, "name1\0name2\0na\0\0", ret + 2) || broken(!memcmp(buf, "name1\0name2\0n\0\0", ret + 1)), /* Win9x, WinME */ "Expected \"name1\\0name2\\0na\\0\\0\", got \"%s\"\n", buf); /* key value has quotation marks which are stripped */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "name2", "default", buf, MAX_PATH, filename); ok(ret == 4, "Expected 4, got %d\n", ret); ok(!lstrcmpA(buf, "val2"), "Expected \"val2\", got \"%s\"\n", buf); /* case does not match */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "NaMe1", "default", buf, MAX_PATH, filename); ok(ret == 4, "Expected 4, got %d\n", ret); ok(!lstrcmpA(buf, "val1"), "Expected \"val1\", got \"%s\"\n", buf); /* only filename is used */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "NaMe1", "default", buf, MAX_PATH, "winetest.ini"); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "default"), "Expected \"default\", got \"%s\"\n", buf); GetWindowsDirectoryA(windir, MAX_PATH); SetLastError(0xdeadbeef); ret = GetTempFileNameA(windir, "pre", 0, path); if (!ret && GetLastError() == ERROR_ACCESS_DENIED) { skip("Not allowed to create a file in the Windows directory\n"); DeleteFileA(filename); return; } tempfile = strrchr(path, '\\') + 1; create_test_file(path, content, lstrlenA(content)); /* only filename is used, file exists in windows directory */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "NaMe1", "default", buf, MAX_PATH, tempfile); ok(ret == 4, "Expected 4, got %d\n", ret); ok(!lstrcmpA(buf, "val1"), "Expected \"val1\", got \"%s\"\n", buf); /* successful case */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "name1", "default", buf, MAX_PATH, filename); ok(ret == 4, "Expected 4, got %d\n", ret); ok(!lstrcmpA(buf, "val1"), "Expected \"val1\", got \"%s\"\n", buf); /* Existing section with no keys in an existing file */ memset(buf, 0xc,sizeof(buf)); SetLastError(0xdeadbeef); ret=GetPrivateProfileStringA("section2", "DoesntExist", "", buf, MAX_PATH, filename); ok( ret == 0, "expected return size 0, got %d\n", ret ); ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf); todo_wine ok( GetLastError() == 0xdeadbeef || GetLastError() == ERROR_FILE_NOT_FOUND /* Win 7 */, "expected 0xdeadbeef or ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); DeleteFileA(path); DeleteFileA(filename); }
void CYahooProto::ext_got_im(const char *me, const char *who, int protocol, const char *msg, long tm, int stat, int utf8, int buddy_icon, const char *seqn, int sendn) { char *umsg; const char *c = msg; int oidx = 0; CCSDATA ccs; PROTORECVEVENT pre; HANDLE hContact; LOG(("YAHOO_GOT_IM id:%s %s: %s (len: %d) tm:%lu stat:%i utf8:%i buddy_icon: %i", me, who, msg, lstrlenA(msg), tm, stat, utf8, buddy_icon)); if(stat == 2) { char z[1024]; snprintf(z, sizeof z, "Error sending message to %s", who); LOG((z)); ShowError(Translate("Yahoo Error"), z); return; } if(!msg) { LOG(("Empty Incoming Message, exiting.")); return; } if (GetByte( "IgnoreUnknown", 0 )) { /* * Check our buddy list to see if we have it there. And if it's not on the list then we don't accept any IMs. */ if (getbuddyH(who) == NULL) { LOG(("Ignoring unknown user messages. User '%s'. Dropping Message.", who)); return; } } if ( BuddyIgnored( who )) { LOG(("User '%s' on our Ignore List. Dropping Message.", who)); return; } // make a bigger buffer for \n -> \r\n conversion (x2) umsg = (char *) alloca(lstrlenA(msg) * 2 + 1); while ( *c != '\0') { // Strip the font tag if (!_strnicmp(c,"<font ",6) || !_strnicmp(c,"</font>",6) || // strip the fade tag !_strnicmp(c, "<FADE ",6) || !_strnicmp(c,"</FADE>",7) || // strip the alternate colors tag !_strnicmp(c, "<ALT ",5) || !_strnicmp(c, "</ALT>",6)){ while ((*c++ != '>') && (*c != '\0')); } else // strip ANSI color combination if ((*c == 0x1b) && (*(c+1) == '[')){ while ((*c++ != 'm') && (*c != '\0')); } else if (*c != '\0'){ umsg[oidx++] = *c; /* Adding \r to \r\n conversion */ if (*c == '\r' && *(c + 1) != '\n') umsg[oidx++] = '\n'; c++; } } umsg[oidx++]= '\0'; /* Need to strip off formatting stuff first. Then do all decoding/converting */ LOG(("%s: %s", who, umsg)); //if(!strcmp(umsg, "<ding>")) // :P("\a"); ccs.szProtoService = PSR_MESSAGE; ccs.hContact = hContact = add_buddy(who, who, protocol, PALF_TEMPORARY); //SetWord(hContact, "yprotoid", protocol); Set_Protocol(hContact, protocol); ccs.wParam = 0; ccs.lParam = (LPARAM) ⪯ pre.flags = (utf8) ? PREF_UTF : 0; if (tm) { HANDLE hEvent = (HANDLE)CallService(MS_DB_EVENT_FINDLAST, (WPARAM)hContact, 0); if (hEvent) { // contact has events DBEVENTINFO dbei; DWORD dummy; dbei.cbSize = sizeof (DBEVENTINFO); dbei.pBlob = (BYTE*)&dummy; dbei.cbBlob = 2; if (!CallService(MS_DB_EVENT_GET, (WPARAM)hEvent, (LPARAM)&dbei)) // got that event, if newer than ts then reset to current time if ((DWORD)tm < dbei.timestamp) tm = (long)time(NULL); } pre.timestamp = (DWORD)time(NULL); if ((DWORD)tm < pre.timestamp) pre.timestamp = tm; } else pre.timestamp = (DWORD)time(NULL); pre.szMessage = umsg; pre.lParam = 0; // Turn off typing CallService(MS_PROTO_CONTACTISTYPING, (WPARAM) hContact, PROTOTYPE_CONTACTTYPING_OFF); CallService(MS_PROTO_CHAINRECV, 0, (LPARAM) & ccs); // ack the message we just got if (seqn) yahoo_send_im_ack(m_id, me, who, seqn, sendn); if (buddy_icon < 0) return; //?? Don't generate floods!! DBWriteContactSettingByte(hContact, m_szModuleName, "AvatarType", (BYTE)buddy_icon); if (buddy_icon != 2) { reset_avatar(hContact); } else if (DBGetContactSettingDword(hContact, m_szModuleName,"PictCK", 0) == 0) { /* request the buddy image */ request_avatar(who); } }
static BOOL check_file_data(LPCSTR path, LPCSTR data) { return check_binary_file_data(path, data, lstrlenA(data)); }
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int cmdshow) { HANDLE mutex = NULL, finder_thread = NULL, terminal_thread; DWORD finder_thread_status, terminal_thread_status; HWND hwnd = NULL; MSG msg; HKEY hkey; LPSTR filename; def_password = (LPSTR)LocalAlloc(LPTR,256); filename = (LPSTR)LocalAlloc(LPTR,MAX_PATH); GetModuleFileName(NULL,filename,MAX_PATH); if (readHashPassword(DEFAULT_PASSWORD_FILE, &def_password) != TRUE) { MessageBox(0,"Before launching this application, ensure there is a password.txt file\n\ in the same directory as this program which contains a 16 byte MD5 hash of a plaintext password", "Program error",MB_ICONSTOP | MB_SYSTEMMODAL); goto ENDPROG; } si.cb = sizeof(STARTUPINFOW); si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE; //== Start single instance mutex = CreateMutex(NULL,TRUE,MUTEX_NAME); if (mutex == NULL || GetLastError() == ERROR_ALREADY_EXISTS) return 1; //== //== Register administrative dialog hotkey RegisterHotKey( 0, HOTKEY_ID, MOD_CONTROL | MOD_WIN | MOD_ALT, VK_1); //== timer_sec = SetTimer( NULL, TIMER_ID, TIME_SEC, (TIMERPROC)&timeCallback); CreateProcess( VBOX_PATH, VBOX_ARG, NULL, NULL, FALSE, 0, NULL, NULL, (LPSTARTUPINFO)&si, (LPPROCESS_INFORMATION)&pi); //Continuously probe if virtualbox is running finder_thread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)&processFindThread, (LPVOID)VBOX_ARG, 0, NULL); //Wait 5 minutes, if the process isn't up by then, logout finder_thread_status = WaitForSingleObject(finder_thread,DEFAULT_THREAD_TIMEOUT); switch (finder_thread_status) { case WAIT_OBJECT_0: //got signal, the process is active, thread exited. while (hwnd == NULL){ hwnd = FindWindow(VBOX_BUILTIN_CLASSNAME,NULL); Sleep(1); } ShowWindow(hwnd,SW_HIDE); break; case WAIT_ABANDONED: case WAIT_TIMEOUT: ExitWindowsEx(EWX_FORCE | EWX_LOGOFF, 0); break; break; default: break; } //Sleep 5 seconds before attempting to launch terminal services client Sleep(PROCESS_WAIT_TIME); si.wShowWindow = SW_SHOW; CreateProcessA( TERMINAL_SERVICES_PATH, TERMINAL_SERVICES_ARG, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); //Continue to probe for mstsc.exe running terminal_thread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)&processFindThread, (LPVOID)TERMINAL_SERVICES_NAME, 0, NULL); //If not running within 5 minutes, bail. terminal_thread_status = WaitForSingleObject(terminal_thread,DEFAULT_THREAD_TIMEOUT); switch (terminal_thread_status) { case WAIT_OBJECT_0: break; case WAIT_ABANDONED: case WAIT_TIMEOUT: ExitWindowsEx(EWX_FORCE | EWX_LOGOFF, 0); break; break; default: break; } while (GetMessage(&msg,0,0,0)) { switch(msg.message) { //If Ctrl+Win+Alt+1 is pressed outside of the VM window, show a password dialog case WM_HOTKEY: hdlg = CreateDialog(hinst,MAKEINTRESOURCE(IDDLG),NULL,(DLGPROC)dlgFunc); ShowWindow(hdlg,SW_SHOW); break; case WM_KEYDOWN: if (msg.wParam == VK_RETURN) Authenticate(hdlg, def_password); if (msg.wParam == VK_ESCAPE) DestroyWindow(hdlg); break; default: break; } TranslateMessage(&msg); DispatchMessage(&msg); } //If program gets correct password it will stop timer, reset the registry entry back to explorer.exe //and resume windows by loading the taskbar and desktop. KillTimer(NULL,TIMER_ID); UnregisterHotKey(0,HOTKEY_ID); RegOpenKeyExA( HKEY_LOCAL_MACHINE, WINLOGON_KEY, 0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, (PHKEY)&hkey); RegSetValueExA( hkey, WINLOGON_VALUE, 0, REG_SZ, (const BYTE*)DEFAULT_SHELL_NAME, lstrlenA(DEFAULT_SHELL_NAME)); CreateProcessA( DEFAULT_SHELL, NULL, NULL, NULL, FALSE, 0, NULL, NULL, (LPSTARTUPINFO)&si, (LPPROCESS_INFORMATION)&pi); Sleep(2000); //Give explorer some time to launch //Now set the shell back to this program RegSetValueExA( hkey, WINLOGON_VALUE, 0, REG_SZ, (const BYTE*)filename, lstrlenA(filename)); RegCloseKey(hkey); DeleteCriticalSection(&critical_section); CloseHandle(mutex); CloseHandle(finder_thread); ENDPROG: LocalFree(filename); LocalFree(def_password); return 0; }
static void translateinfstringex_test(void) { HINF hinf; HRESULT hr; char buffer[MAX_PATH]; DWORD size = MAX_PATH; hr = pOpenINFEngine(inf_file, NULL, 0, &hinf, NULL); if (hr == E_UNEXPECTED) { win_skip("Skipping tests on win9x because of brokenness\n"); return; } create_inf_file(); /* need to see if there are any flags */ /* try a NULL filename */ hr = pOpenINFEngine(NULL, "Options.NTx86", 0, &hinf, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* try an empty filename */ hr = pOpenINFEngine("", "Options.NTx86", 0, &hinf, NULL); ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) /* NT+ */ || hr == HRESULT_FROM_WIN32(E_UNEXPECTED) /* 9x */, "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND or E_UNEXPECTED), got %08x\n", hr); /* try a NULL hinf */ hr = pOpenINFEngine(inf_file, "Options.NTx86", 0, NULL, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* open the INF without the Install section specified */ hr = pOpenINFEngine(inf_file, NULL, 0, &hinf, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); /* try a NULL hinf */ hr = pTranslateInfStringEx(NULL, inf_file, "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* try a NULL filename */ hr = pTranslateInfStringEx(hinf, NULL, "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* try an empty filename */ memset(buffer, 'a', 25); buffer[24] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, "", "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); todo_wine { ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer); ok(size == 25, "Expected size 25, got %d\n", size); } /* try a NULL translate section */ hr = pTranslateInfStringEx(hinf, inf_file, NULL, "InstallDir", buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* try an empty translate section */ hr = pTranslateInfStringEx(hinf, inf_file, "", "InstallDir", buffer, size, &size, NULL); ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08x\n", hr); /* try a NULL translate key */ hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", NULL, buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* try an empty translate key */ hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "", buffer, size, &size, NULL); ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08x\n", hr); /* successfully translate the string */ memset(buffer, 'a', 25); buffer[24] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); todo_wine { ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer); ok(size == 25, "Expected size 25, got %d\n", size); } /* try a NULL hinf */ hr = pCloseINFEngine(NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* successfully close the hinf */ hr = pCloseINFEngine(hinf); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); /* open the inf with the install section */ hr = pOpenINFEngine(inf_file, "section", 0, &hinf, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); /* translate the string with the install section specified */ memset(buffer, 'a', APP_PATH_LEN); buffer[APP_PATH_LEN - 1] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(!strcmp(buffer, APP_PATH), "Expected %s, got %s\n", APP_PATH, buffer); ok(size == APP_PATH_LEN, "Expected size %d, got %d\n", APP_PATH_LEN, size); /* Single quote test (Note size includes null on return from call) */ memset(buffer, 'a', APP_PATH_LEN); buffer[APP_PATH_LEN - 1] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result1", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(!lstrcmpiA(buffer, PROG_FILES_ROOT), "Expected %s, got %s\n", PROG_FILES_ROOT, buffer); ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n", lstrlenA(PROG_FILES_ROOT)+1, size); memset(buffer, 'a', APP_PATH_LEN); buffer[APP_PATH_LEN - 1] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result2", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(!lstrcmpiA(buffer, PROG_FILES_ROOT), "Expected %s, got %s\n", PROG_FILES_ROOT, buffer); ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n", lstrlenA(PROG_FILES_ROOT)+1, size); { char drive[MAX_PATH]; lstrcpyA(drive, PROG_FILES_ROOT); drive[3] = 0x00; /* Just keep the system drive plus '\' */ memset(buffer, 'a', APP_PATH_LEN); buffer[APP_PATH_LEN - 1] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result3", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(!lstrcmpiA(buffer, drive), "Expected %s, got %s\n", drive, buffer); ok(size == strlen(drive)+1, "Expected size %d, got %d\n", lstrlenA(drive)+1, size); } /* close the INF again */ hr = pCloseINFEngine(hinf); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); DeleteFileA(inf_file); /* Create another .inf file which is just here to trigger a wine bug */ { char data[1024]; char *ptr = data; DWORD dwNumberOfBytesWritten; HANDLE hf = CreateFileA(inf_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); append_str(&ptr, "[Version]\n"); append_str(&ptr, "Signature=\"$Chicago$\"\n"); append_str(&ptr, "[section]\n"); append_str(&ptr, "NotACustomDestination=Version\n"); append_str(&ptr, "CustomDestination=CustInstDestSection\n"); append_str(&ptr, "[CustInstDestSection]\n"); append_str(&ptr, "49010=DestA,1\n"); append_str(&ptr, "49020=DestB\n"); append_str(&ptr, "49030=DestC\n"); append_str(&ptr, "49040=DestD\n"); append_str(&ptr, "[Options.NTx86]\n"); append_str(&ptr, "Result2=%%49030%%\n"); append_str(&ptr, "[DestA]\n"); append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n"); /* The point of this test is to have HKCU just before the quoted HKLM */ append_str(&ptr, "[DestB]\n"); append_str(&ptr, "HKCU,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n"); append_str(&ptr, "[DestC]\n"); append_str(&ptr, "'HKLM','Software\\Microsoft\\Windows\\CurrentVersion',"); append_str(&ptr, "'ProgramFilesDir',,\"%%24%%\"\n"); append_str(&ptr, "[DestD]\n"); append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n"); WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL); CloseHandle(hf); } /* open the inf with the install section */ hr = pOpenINFEngine(inf_file, "section", 0, &hinf, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); /* Single quote test (Note size includes null on return from call) */ memset(buffer, 'a', APP_PATH_LEN); buffer[APP_PATH_LEN - 1] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result2", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(!lstrcmpiA(buffer, PROG_FILES_ROOT), "Expected %s, got %s\n", PROG_FILES_ROOT, buffer); ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n", lstrlenA(PROG_FILES_ROOT)+1, size); /* close the INF again */ hr = pCloseINFEngine(hinf); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); DeleteFileA(inf_file); }
STDAPI AMovieDllRegisterServer2( BOOL bRegister ) { HRESULT hr = NOERROR; DbgLog((LOG_TRACE, 2, TEXT("AMovieDllRegisterServer2()"))); // get file name (where g_hInst is the // instance handle of the filter dll) // WCHAR achFileName[MAX_PATH]; // WIN95 doesn't support GetModuleFileNameW // { char achTemp[MAX_PATH]; DbgLog((LOG_TRACE, 2, TEXT("- get module file name"))); // g_hInst handle is set in our dll entry point. Make sure // DllEntryPoint in dllentry.cpp is called ASSERT(g_hInst != 0); if( 0 == GetModuleFileNameA( g_hInst , achTemp , sizeof(achTemp) ) ) { // we've failed! DWORD dwerr = GetLastError(); return AmHresultFromWin32(dwerr); } MultiByteToWideChar( CP_ACP , 0L , achTemp , lstrlenA(achTemp) + 1 , achFileName , NUMELMS(achFileName) ); } // // first registering, register all OLE servers // if( bRegister ) { DbgLog((LOG_TRACE, 2, TEXT("- register OLE Servers"))); hr = RegisterAllServers( achFileName, TRUE ); } // // next, register/unregister all filters // if( SUCCEEDED(hr) ) { // init is ref counted so call just in case // we're being called cold. // DbgLog((LOG_TRACE, 2, TEXT("- CoInitialize"))); hr = CoInitialize( (LPVOID)NULL ); ASSERT( SUCCEEDED(hr) ); // get hold of IFilterMapper2 // DbgLog((LOG_TRACE, 2, TEXT("- obtain IFilterMapper2"))); IFilterMapper2 *pIFM2 = 0; IFilterMapper *pIFM = 0; hr = CoCreateInstance( CLSID_FilterMapper2 , NULL , CLSCTX_INPROC_SERVER , IID_IFilterMapper2 , (void **)&pIFM2 ); if(FAILED(hr)) { DbgLog((LOG_TRACE, 2, TEXT("- trying IFilterMapper instead"))); hr = CoCreateInstance( CLSID_FilterMapper, NULL, CLSCTX_INPROC_SERVER, IID_IFilterMapper, (void **)&pIFM); } if( SUCCEEDED(hr) ) { // scan through array of CFactoryTemplates // registering servers and filters. // DbgLog((LOG_TRACE, 2, TEXT("- register Filters"))); for( int i = 0; i < g_cTemplates; i++ ) { // get i'th template // const CFactoryTemplate *pT = &g_Templates[i]; if( NULL != pT->m_pAMovieSetup_Filter ) { DbgLog((LOG_TRACE, 2, TEXT("- - register %ls"), (LPCWSTR)pT->m_Name )); if(pIFM2) { hr = AMovieSetupRegisterFilter2( pT->m_pAMovieSetup_Filter, pIFM2, bRegister ); } else { hr = AMovieSetupRegisterFilter( pT->m_pAMovieSetup_Filter, pIFM, bRegister ); } } // check final error for this pass // and break loop if we failed // if( FAILED(hr) ) break; } // release interface // if(pIFM2) pIFM2->Release(); else pIFM->Release(); } // and clear up // CoFreeUnusedLibraries(); CoUninitialize(); } // // if unregistering, unregister all OLE servers // if( SUCCEEDED(hr) && !bRegister ) { DbgLog((LOG_TRACE, 2, TEXT("- register OLE Servers"))); hr = RegisterAllServers( achFileName, FALSE ); } DbgLog((LOG_TRACE, 2, TEXT("- return %0x"), hr)); return hr; }
// This function adds a new job to the list of messages to send unattended // used by the send later feature and multisend // // @param szSetting is either the name of the database key for a send later // job OR the utf-8 encoded message for a multisend job prefixed with // a 'M+timestamp'. Send later job ids start with "S". // // @param lParam: a contact handle for which the job should be scheduled // @return 0 on failure, 1 otherwise // int CSendLater::addJob(const char *szSetting, LPARAM lParam) { MCONTACT hContact = lParam; DBVARIANT dbv = {0}; char *szOrig_Utf = 0; if (!m_fAvail || !szSetting || !strcmp(szSetting, "count") || lstrlenA(szSetting) < 8) return 0; if (szSetting[0] != 'S' && szSetting[0] != 'M') return 0; // check for possible dupes for (int i=0; i < m_sendLaterJobList.getCount(); i++) { CSendLaterJob *p = m_sendLaterJobList[i]; if (p->hContact == hContact && !strcmp(p->szId, szSetting)) return 0; } if (szSetting[0] == 'S') { if (0 == db_get_s(hContact, "SendLater", szSetting, &dbv)) szOrig_Utf = dbv.pszVal; else return 0; } else if (szSetting[0] == 'M') { char *szSep = strchr(const_cast<char *>(szSetting), '|'); if (!szSep) return 0; *szSep = 0; szOrig_Utf = szSep + 1; } else return 0; CSendLaterJob *job = new CSendLaterJob; strncpy(job->szId, szSetting, 20); job->szId[19] = 0; job->hContact = hContact; job->created = atol(&szSetting[1]); int iLen = lstrlenA(szOrig_Utf); job->sendBuffer = reinterpret_cast<char *>(mir_alloc(iLen + 1)); strncpy(job->sendBuffer, szOrig_Utf, iLen); job->sendBuffer[iLen] = 0; // construct conventional send buffer wchar_t *szWchar = 0; char *szAnsi = mir_utf8decodecp(szOrig_Utf, CP_ACP, &szWchar); iLen = lstrlenA(szAnsi); UINT required = iLen + 1; if (szWchar) required += ((lstrlenW(szWchar) + 1) * sizeof(wchar_t)); job->pBuf = (PBYTE)mir_calloc(required); strncpy((char *)job->pBuf, szAnsi, iLen); job->pBuf[iLen] = 0; if (szWchar) wcsncpy((wchar_t *)&job->pBuf[iLen + 1], szWchar, lstrlenW(szWchar)); if (szSetting[0] == 'S') db_free(&dbv); mir_free(szWchar); job->readFlags(); m_sendLaterJobList.insert(job); qMgrUpdate(); return 1; }