void CBase_SampleChart::OnExportData() { CString file = _T("C:/Points.csv"); CFileDialog mFileDlg(FALSE,_T("csv"),_T("Points"),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,_T("csv文件|*.csv||"),this); DWORD dwVersion = GetVersion(); DWORD dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); DWORD dwWindowsMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); if (dwVersion < 0x80000000) mFileDlg.m_ofn.lStructSize=88;//显示新的文件对话框 else mFileDlg.m_ofn.lStructSize=76;//显示老的文件对话框 mFileDlg.m_ofn.lpstrTitle= _T("保存到文件"); if(mFileDlg.DoModal() !=IDOK ) return; file = mFileDlg.GetPathName(); CString strSep = _T(","); CFile f; BOOL ret = f.Open(file,CFile::modeCreate | CFile::modeReadWrite); if(!ret) { MessageBox(_T("打开文件失败,可能是文件为只读属性或被占用")); return; } CString line(_T("时间")); // CArray<CChartSerie*, CChartSerie*> series; series.Add(m_pcCurveMain); unsigned maxCount = 0; CChartSerie* pSerieOfMaxCount = NULL; for(int i=0; i<=series.GetUpperBound(); ++i) { CChartSerie* pS = series.GetAt(i); unsigned c = pS->GetPointsCount(); if(c > maxCount) { maxCount = c; pSerieOfMaxCount = pS; } line = line + strSep + pS->GetName().c_str(); } //标题列 { TWen_USES_CONVERSION; LPCSTR s=TWen_CT2A(line + _T("\r\n")); f.Write(s,strlen(s)); } for(size_t i=0; i<maxCount; i++) { line.Format(_T("%.15f"), pSerieOfMaxCount->m_vPoints.m_pPoints[i].x); for(int j=0; j<=series.GetUpperBound(); ++j) { CChartSerie* pS = GetSerieByIndex(j); unsigned c = pS->GetPointsCount(); CString v; if(c > i) v.Format(_T("%.15f"), pS->m_vPoints.m_pPoints[i].y); line = line + strSep + v; } { TWen_USES_CONVERSION; LPCSTR s=TWen_CT2A(line + _T("\r\n")); f.Write(s,strlen(s)); } } f.Close(); MessageBox(_T("数据已保存到文件[")+file+_T("]")); }
void WindowsPlatform::syncFolderAdded(QString syncPath, QString syncName) { if (syncPath.startsWith(QString::fromAscii("\\\\?\\"))) { syncPath = syncPath.mid(4); } if (!syncPath.size()) { return; } QDir syncDir(syncPath); if (!syncDir.exists()) { return; } DWORD dwVersion = GetVersion(); DWORD dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); int iconIndex = (dwMajorVersion<6) ? 2 : 3; QString infoTip = QCoreApplication::translate("WindowsPlatform", "MEGA synced folder"); SHFOLDERCUSTOMSETTINGS fcs = {0}; fcs.dwSize = sizeof(SHFOLDERCUSTOMSETTINGS); fcs.dwMask = FCSM_ICONFILE | FCSM_INFOTIP; fcs.pszIconFile = (LPWSTR)MegaApplication::applicationFilePath().utf16(); fcs.iIconIndex = iconIndex; fcs.pszInfoTip = (LPWSTR)infoTip.utf16(); SHGetSetFolderCustomSettings(&fcs, (LPCWSTR)syncPath.utf16(), FCS_FORCEWRITE); WCHAR path[MAX_PATH]; HRESULT res = SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, path); if (res != S_OK) { return; } QString linksPath = QString::fromWCharArray(path); linksPath += QString::fromAscii("\\Links"); QFileInfo info(linksPath); if (!info.isDir()) { return; } QString linkPath = linksPath + QString::fromAscii("\\") + syncName + QString::fromAscii(".lnk"); if (QFile(linkPath).exists()) { return; } WCHAR wDescription[]=L"MEGAsync synchronized folder"; linkPath = QDir::toNativeSeparators(linkPath); WCHAR *wLinkPath = (WCHAR *)linkPath.utf16(); syncPath = QDir::toNativeSeparators(syncPath); WCHAR *wSyncPath = (WCHAR *)syncPath.utf16(); QString exec = MegaApplication::applicationFilePath(); exec = QDir::toNativeSeparators(exec); WCHAR *wExecPath = (WCHAR *)exec.utf16(); res = CreateLink(wSyncPath, wLinkPath, wDescription, wExecPath); SHChangeNotify(SHCNE_CREATE, SHCNF_PATH | SHCNF_FLUSHNOWAIT, wLinkPath, NULL); WCHAR *wLinksPath = (WCHAR *)linksPath.utf16(); SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_PATH | SHCNF_FLUSHNOWAIT, wLinksPath, NULL); SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH | SHCNF_FLUSHNOWAIT, syncPath.utf16(), NULL); }
//------------------------------------------------------------------------------------------------- void FMain() { if (const HWND hWnd = FindWindowW(g_wGuidClass, nullptr)) PostMessageW(hWnd, WM_CLOSE, 0, 0); if (SUCCEEDED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED))) { IMMDeviceEnumerator *immDeviceEnumerator; if (CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), reinterpret_cast<LPVOID*>(&immDeviceEnumerator)) == S_OK) { IMMDevice *immDeviceDefault; if (immDeviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &immDeviceDefault) == S_OK) { wchar_t *wIdDefaultOld; HRESULT hr = immDeviceDefault->GetId(&wIdDefaultOld); immDeviceDefault->Release(); if (hr == S_OK) { IMMDeviceCollection *immDeviceCollection; hr = immDeviceEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &immDeviceCollection); immDeviceEnumerator->Release(); if (hr == S_OK) { UINT iCount; if (immDeviceCollection->GetCount(&iCount) == S_OK) { bool bFail = true; for (UINT i = 0; i < iCount; ++i) { IMMDevice *immDevice; if (immDeviceCollection->Item(i, &immDevice) == S_OK) { wchar_t *wIdEnum; hr = immDevice->GetId(&wIdEnum); immDevice->Release(); if (hr == S_OK) { if (FCompareMemoryW(wIdDefaultOld, wIdEnum)) { bFail = false; if (++i >= iCount) i = 0; hr = immDeviceCollection->Item(i, &immDevice); immDeviceCollection->Release(); if (hr == S_OK) { wchar_t *wIdDefaultNew; if (immDevice->GetId(&wIdDefaultNew) == S_OK) { IPropertyStore *ipStore; hr = immDevice->OpenPropertyStore(STGM_READ, &ipStore); immDevice->Release(); if (hr == S_OK) { PROPVARIANT propFriendlyName; PropVariantInitFix(&propFriendlyName); PROPERTYKEY propKeyFriendlyName; propKeyFriendlyName.fmtid.Data1 = 0xA45C254E; propKeyFriendlyName.fmtid.Data2 = 0xDF1C; propKeyFriendlyName.fmtid.Data3 = 0x4EFD; FCopyMemory(propKeyFriendlyName.fmtid.Data4); propKeyFriendlyName.pid = 14; hr = ipStore->GetValue(propKeyFriendlyName, &propFriendlyName); ipStore->Release(); if (SUCCEEDED(hr)) { IPolicyConfig *pPolicyConfig; if (CoCreateInstance(__uuidof(CPolicyConfigClient), nullptr, CLSCTX_ALL, (GetVersion() & 0xFF) >= 10 ? __uuidof(IPolicyConfigWin10) : __uuidof(IPolicyConfig), reinterpret_cast<LPVOID*>(&pPolicyConfig)) == S_OK) { hr = pPolicyConfig->SetDefaultEndpoint(wIdDefaultNew, eConsole); if (hr == S_OK) { pPolicyConfig->SetDefaultEndpoint(wIdDefaultNew, eMultimedia); pPolicyConfig->SetDefaultEndpoint(wIdDefaultNew, eCommunications); } pPolicyConfig->Release(); if (hr == S_OK) { WNDCLASSEX wndCl; wndCl.cbSize = sizeof(WNDCLASSEX); wndCl.style = 0; wndCl.lpfnWndProc = WindowProc; wndCl.cbClsExtra = 0; wndCl.cbWndExtra = 0; wndCl.hInstance = GetModuleHandleW(nullptr); wndCl.hIcon = nullptr; wndCl.hCursor = nullptr; wndCl.hbrBackground = nullptr; wndCl.lpszMenuName = nullptr; wndCl.lpszClassName = g_wGuidClass; wndCl.hIconSm = nullptr; if (RegisterClassExW(&wndCl)) { if (CreateWindowExW(WS_EX_NOACTIVATE | WS_EX_LAYERED | WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST, g_wGuidClass, nullptr, WS_POPUP | WS_VISIBLE | WS_MAXIMIZE, 0, 0, 0, 0, nullptr, nullptr, wndCl.hInstance, propFriendlyName.pwszVal)) { MSG msg; while (GetMessageW(&msg, nullptr, 0, 0) > 0) DispatchMessageW(&msg); } UnregisterClassW(g_wGuidClass, wndCl.hInstance); } } } } PropVariantClear(&propFriendlyName); } CoTaskMemFree(wIdDefaultNew); } else immDevice->Release(); } break; } CoTaskMemFree(wIdEnum); } } } if (bFail) immDeviceCollection->Release(); } else immDeviceCollection->Release(); } CoTaskMemFree(wIdDefaultOld); } else immDeviceEnumerator->Release(); } else immDeviceEnumerator->Release(); } CoUninitialize(); } }
// // Installs the BK initial loader and a payload driver depending on current architecture. // WINERROR SetupBk( BOOL IsExe, // specify TRUE if the function called from an EXE file. It will enable UAC elevation and self-delete. BOOL bReboot // specify TRUE if reboot needed after install ) { WINERROR Status; CHAR VersionHi, VersionLo; BOOL Elevated = TRUE; ULONG OsVersion, PayloadSize, BootSize; PCHAR MutexName = NULL, KeyName = NULL, Payload = NULL, BootLoader = NULL; HKEY hKey; HANDLE hMutex = 0; do // not a loop { // Generating pseudo-random program key name if (!GetProgramKeyName(&KeyName, &MutexName)) { DbgPrint("BKSETUP: Failed generating program key and mutex name.\n"); Status = ERROR_NOT_ENOUGH_MEMORY; break; } // Checking if the application already running if (!(hMutex = CreateMutex(NULL, TRUE, MutexName)) || ((Status = GetLastError()) == ERROR_ALREADY_EXISTS)) { DbgPrint("BKSETUP: An other copy of the program already running.\n"); Status = ERROR_SERVICE_ALREADY_RUNNING; break; } // Checking if we were already installed if (RegOpenKey(HKEY_LOCAL_MACHINE, KeyName, &hKey) == NO_ERROR) { RegCloseKey(hKey); DbgPrint("BKSETUP: Already installed.\n"); Status = ERROR_ALREADY_EXISTS; break; } OsVersion = GetVersion(); VersionHi = LOBYTE(LOWORD(OsVersion)); VersionLo = HIBYTE(LOWORD(OsVersion)); // Checking if current OS supported if ((VersionHi == 5 && VersionLo == 0) || VersionHi < 5 || VersionHi > 6) { Status = ERROR_OLD_WIN_VERSION; DbgPrint("BKSETUP: OS not supported.\n"); break; } // Running as separate executable if (VersionHi == 6) { // For Vista and higher: // Checking for UAC elevated token HANDLE hToken; ULONG bSize; Elevated = FALSE; if (OpenProcessToken(GetCurrentProcess(), READ_CONTROL | TOKEN_QUERY, &hToken)) { GetTokenInformation(hToken, 20, &Elevated, sizeof(BOOL), &bSize); CloseHandle(hToken); } } // if (VersionHi >= 6) if (!Elevated) { // Running with low integrity access token if (IsExe) { // Releasing program mutex CloseHandle(hMutex); hMutex = 0; // Requesting elevation RequestUac(); } Status = ERROR_ACCESS_DENIED; DbgPrint("BKSETUP: Not enough privileges to complete installation.\n"); break; } // if (!Elevated) // Unpacking joined module depending on current OS architecture if (!GetJoinedData(g_CurrentModuleBase, &Payload, &PayloadSize, IsProcessWow64(g_CurrentProcessId), 0, TARGET_FLAG_DRV)) { Status = ERROR_FILE_NOT_FOUND; DbgPrint("BKSETUP: No joined payload found.\n"); break; } // Unpacking joined initial loader if (!GetJoinedData(g_CurrentModuleBase, &BootLoader, &BootSize, FALSE, 0, TARGET_FLAG_BINARY)) { Status = ERROR_FILE_NOT_FOUND; DbgPrint("BKSETUP: No joined BK loader found.\n"); break; } // Installing the boot loader Status = BkSetupWithPayload(BootLoader, BootSize, Payload, PayloadSize); vFree(BootLoader); if (Status != NO_ERROR) { DbgPrint("BKSETUP: Installation failed because of unknown reason.\n"); break; } // Creating program key to mark that we were installed if (RegCreateKey(HKEY_LOCAL_MACHINE, KeyName, &hKey) == NO_ERROR) RegCloseKey(hKey); Status = NO_ERROR; DbgPrint("BKSETUP: Successfully installed.\n"); } while(FALSE); if (hMutex) CloseHandle(hMutex); if (Payload) vFree(Payload); if (KeyName) vFree(KeyName); if (MutexName) vFree(MutexName); if (IsExe) DoSelfDelete(); if (Status == NO_ERROR && bReboot) { // One second timeout to let the Self Delete BAT-file initialize, then reboot. Sleep(1000); Reboot(); } return(Status); }
// // FUNCTION: About(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for "About" dialog box // This version allows greater flexibility over the contents of the 'About' box, // by pulling out values from the 'Version' resource. // // MESSAGES: // // WM_INITDIALOG - initialize dialog box // WM_COMMAND - Input received // // LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static HFONT hfontDlg; // Font for dialog text static HFONT hFinePrint; // Font for 'fine print' in dialog DWORD dwVerInfoSize; // Size of version information block LPSTR lpVersion; // String pointer to 'version' text DWORD dwVerHnd=0; // An 'ignored' parameter, always '0' UINT uVersionLen; BOOL bRetCode; int i; char szFullPath[256]; char szResult[256]; char szGetName[256]; DWORD dwVersion; char szVersion[40]; DWORD dwResult; switch (message) { case WM_INITDIALOG: // hide window while it's being constructed ShowWindow (hDlg, SW_HIDE); // crate and load the fonts to be used for the text hfontDlg = CreateFont(14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, VARIABLE_PITCH | FF_SWISS, ""); hFinePrint = CreateFont(11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, VARIABLE_PITCH | FF_SWISS, ""); // position the window in the center of the parent CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); // get the .exe path GetModuleFileName ((HINSTANCE)(GetWindowLongPtr(hDlg, GWLP_HINSTANCE)), szFullPath, sizeof(szFullPath)); // Now lets dive in and pull out the version information: dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd); if (dwVerInfoSize) { LPSTR lpstrVffInfo; HANDLE hMem; hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize); lpstrVffInfo = GlobalLock(hMem); GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpstrVffInfo); // The below 'hex' value looks a little confusing, but // essentially what it is, is the hexidecimal representation // of a couple different values that represent the language // and character set that we are wanting string values for. // 040904E4 is a very common one, because it means: // US English, Windows MultiLingual characterset // Or to pull it all apart: // 04------ = SUBLANG_ENGLISH_USA // --09---- = LANG_ENGLISH // --11---- = LANG_JAPANESE // ----04E4 = 1252 = Codepage for Windows:Multilingual _snprintf_s(szGetName, 256, _TRUNCATE, "%sProductName", GetStringRes(IDS_VER_INFO_LANG)); // Set the title of the dialog: bRetCode = VerQueryValue((LPVOID)lpstrVffInfo, (LPSTR)szGetName, (LPVOID)&lpVersion, (UINT *)&uVersionLen); // Notice order of version and string... _snprintf_s(szResult, 256, _TRUNCATE, "About %s", lpVersion); // set dialog caption SetWindowText (hDlg, szResult); // Walk through the dialog items that we want to replace: for (i = DLG_VERFIRST; i <= DLG_VERLAST; i++) { GetDlgItemText(hDlg, i, szResult, sizeof(szResult)); _snprintf_s(szGetName, 256, _TRUNCATE, "%s%s", GetStringRes(IDS_VER_INFO_LANG), szResult); uVersionLen = 0; lpVersion = NULL; bRetCode = VerQueryValue((LPVOID)lpstrVffInfo, (LPSTR)szGetName, (LPVOID)&lpVersion, (UINT *)&uVersionLen); if ( bRetCode && uVersionLen && lpVersion) { // Replace dialog item text with version info strncpy_s(szResult, 256, lpVersion, _TRUNCATE); SetDlgItemText(hDlg, i, szResult); } else { dwResult = GetLastError(); _snprintf_s(szResult, 256, _TRUNCATE, GetStringRes(IDS_VERSION_ERROR), dwResult); SetDlgItemText (hDlg, i, szResult); } SendMessage (GetDlgItem (hDlg, i), WM_SETFONT, (UINT_PTR)((i==DLG_VERLAST)?hFinePrint:hfontDlg), TRUE); } // for (i = DLG_VERFIRST; i <= DLG_VERLAST; i++) GlobalUnlock(hMem); GlobalFree(hMem); } else { // No version information available. } // if (dwVerInfoSize) SendMessage (GetDlgItem (hDlg, IDC_LABEL), WM_SETFONT, (WPARAM)hfontDlg,(LPARAM)TRUE); // We are using GetVersion rather then GetVersionEx // because earlier versions of Windows NT and Win32s // didn't include GetVersionEx: dwVersion = GetVersion(); if (dwVersion < 0x80000000) { // Windows NT _snprintf_s(szVersion, 40, _TRUNCATE, "Microsoft Windows NT %u.%u (Build: %u)", (DWORD)(LOBYTE(LOWORD(dwVersion))), (DWORD)(HIBYTE(LOWORD(dwVersion))), (DWORD)(HIWORD(dwVersion)) ); } else if (LOBYTE(LOWORD(dwVersion))<4) { // Win32s _snprintf_s(szVersion, 40, _TRUNCATE, "Microsoft Win32s %u.%u (Build: %u)", (DWORD)(LOBYTE(LOWORD(dwVersion))), (DWORD)(HIBYTE(LOWORD(dwVersion))), (DWORD)(HIWORD(dwVersion) & ~0x8000) ); } else { // Windows 95 _snprintf_s(szVersion, 40, _TRUNCATE, "Microsoft Windows 95 %u.%u", (DWORD)(LOBYTE(LOWORD(dwVersion))), (DWORD)(HIBYTE(LOWORD(dwVersion))) ); } SetWindowText (GetDlgItem(hDlg, IDC_OSVERSION), szVersion); // now display the finished product ShowWindow (hDlg, SW_SHOW); return (TRUE); case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, TRUE); DeleteObject (hfontDlg); DeleteObject (hFinePrint); return (TRUE); } break; } return FALSE; }
void OPENSSL_showfatal (const char *fmta,...) { va_list ap; TCHAR buf[256]; const TCHAR *fmt; #ifdef STD_ERROR_HANDLE /* what a dirty trick! */ HANDLE h; if ((h=GetStdHandle(STD_ERROR_HANDLE)) != NULL && GetFileType(h)!=FILE_TYPE_UNKNOWN) { /* must be console application */ va_start (ap,fmta); vfprintf (stderr,fmta,ap); va_end (ap); return; } #endif if (sizeof(TCHAR)==sizeof(char)) fmt=(const TCHAR *)fmta; else do { int keepgoing; size_t len_0=strlen(fmta)+1,i; WCHAR *fmtw; fmtw = (WCHAR *)alloca(len_0*sizeof(WCHAR)); if (fmtw == NULL) { fmt=(const TCHAR *)L"no stack?"; break; } #ifndef OPENSSL_NO_MULTIBYTE if (!MultiByteToWideChar(CP_ACP,0,fmta,len_0,fmtw,len_0)) #endif for (i=0; i<len_0; i++) fmtw[i]=(WCHAR)fmta[i]; for (i=0; i<len_0; i++) { if (fmtw[i]==L'%') do { keepgoing=0; switch (fmtw[i+1]) { case L'0': case L'1': case L'2': case L'3': case L'4': case L'5': case L'6': case L'7': case L'8': case L'9': case L'.': case L'*': case L'-': i++; keepgoing=1; break; case L's': fmtw[i+1]=L'S'; break; case L'S': fmtw[i+1]=L's'; break; case L'c': fmtw[i+1]=L'C'; break; case L'C': fmtw[i+1]=L'c'; break; } } while (keepgoing); } fmt = (const TCHAR *)fmtw; } while (0); va_start (ap,fmta); _vsntprintf (buf,sizeof(buf)/sizeof(TCHAR)-1,fmt,ap); buf [sizeof(buf)/sizeof(TCHAR)-1] = _T('\0'); va_end (ap); #if defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0333 /* this -------------v--- guards NT-specific calls */ if (GetVersion() < 0x80000000 && OPENSSL_isservice() > 0) { HANDLE h = RegisterEventSource(0,_T("OPENSSL")); const TCHAR *pmsg=buf; ReportEvent(h,EVENTLOG_ERROR_TYPE,0,0,0,1,0,&pmsg,0); DeregisterEventSource(h); } else #endif MessageBox (NULL,buf,_T("OpenSSL: FATAL"),MB_OK|MB_ICONSTOP); }
AXIS2_EXTERN axis2_char_t* AXIS2_CALL service_admin_util_get_uname(axutil_env_t *env,char mode) { char *unameval; char tmp_uname[256]; #ifdef WIN32 DWORD dwBuild=0; DWORD dwVersion = GetVersion(); DWORD dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); DWORD dwWindowsMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1; TCHAR ComputerName[MAX_COMPUTERNAME_LENGTH + 1]; SYSTEM_INFO SysInfo; GetComputerName(ComputerName, &dwSize); GetSystemInfo(&SysInfo); if (mode == 's') { if (dwVersion < 0x80000000) { unameval = "Windows NT"; } else { unameval = "Windows 9x"; } } else if (mode == 'r') { snprintf(tmp_uname, sizeof(tmp_uname), "%d.%d", dwWindowsMajorVersion, dwWindowsMinorVersion); unameval = tmp_uname; } else if (mode == 'n') { unameval = ComputerName; } else if (mode == 'v') { dwBuild = (DWORD)(HIWORD(dwVersion)); snprintf(tmp_uname, sizeof(tmp_uname), "build %d", dwBuild); unameval = tmp_uname; } else if (mode == 'm') { switch (SysInfo.wProcessorArchitecture) { case PROCESSOR_ARCHITECTURE_INTEL : snprintf(tmp_uname, sizeof(tmp_uname), "i%d", SysInfo.dwProcessorType); unameval = tmp_uname; break; case PROCESSOR_ARCHITECTURE_MIPS : snprintf(tmp_uname, sizeof(tmp_uname), "MIPS R%d000", SysInfo.wProcessorLevel); unameval = tmp_uname; break; case PROCESSOR_ARCHITECTURE_ALPHA : snprintf(tmp_uname, sizeof(tmp_uname), "Alpha %d", SysInfo.wProcessorLevel); unameval = tmp_uname; break; case PROCESSOR_ARCHITECTURE_PPC : snprintf(tmp_uname, sizeof(tmp_uname), "PPC 6%02d", SysInfo.wProcessorLevel); unameval = tmp_uname; break; case PROCESSOR_ARCHITECTURE_IA64 : unameval = "IA64"; break; #if defined(PROCESSOR_ARCHITECTURE_IA32_ON_WIN64) case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 : unameval = "IA32"; break; #endif #if defined(PROCESSOR_ARCHITECTURE_AMD64) case PROCESSOR_ARCHITECTURE_AMD64 : unameval = "AMD64"; break; #endif case PROCESSOR_ARCHITECTURE_UNKNOWN : default : unameval = "Unknown"; break; } } else { /* assume mode == 'a' */ /* Get build numbers for Windows NT or Win95 */ if (dwVersion < 0x80000000){ dwBuild = (DWORD)(HIWORD(dwVersion)); snprintf(tmp_uname, sizeof(tmp_uname), "%s %d.%d build %d", "Windows NT", dwWindowsMajorVersion, dwWindowsMinorVersion, dwBuild); } else { snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %d.%d", "Windows 9x", dwWindowsMajorVersion, dwWindowsMinorVersion); } unameval = tmp_uname; } #else #ifdef HAVE_SYS_UTSNAME_H struct utsname buf; if (uname((struct utsname *)&buf) == -1) { unameval = "Linux"; } else { if (mode == 's') { unameval = buf.sysname; } else if (mode == 'r') { unameval = buf.release; } else if (mode == 'n') { unameval = buf.nodename; } else if (mode == 'v') { unameval = buf.version; } else if (mode == 'm') { unameval = buf.machine; } else { /* assume mode == 'a' */ snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %s %s %s", buf.sysname, buf.nodename, buf.release, buf.version, buf.machine); unameval = tmp_uname; } } #endif #endif return axutil_strdup(env,unameval); }
static int Win32_GetVersion(Jim_Interp *interp, int objc, Jim_Obj * const *objv) { Jim_SetResult(interp, Jim_NewIntObj(interp, GetVersion())); return JIM_OK; }
static void test_GetRandomRgn(void) { HWND hwnd = CreateWindowExA(0,"BUTTON","test",WS_VISIBLE|WS_POPUP,0,0,100,100,GetDesktopWindow(),0,0,0); HDC hdc; HRGN hrgn = CreateRectRgn(0, 0, 0, 0); int ret; RECT rc, rc2; RECT ret_rc, window_rc; ok( hwnd != 0, "CreateWindow failed\n" ); SetRect(&window_rc, 400, 300, 500, 400); SetWindowPos(hwnd, HWND_TOPMOST, window_rc.left, window_rc.top, window_rc.right - window_rc.left, window_rc.bottom - window_rc.top, 0 ); hdc = GetDC(hwnd); ret = GetRandomRgn(hdc, hrgn, 1); ok(ret == 0, "GetRandomRgn rets %d\n", ret); ret = GetRandomRgn(hdc, hrgn, 2); ok(ret == 0, "GetRandomRgn rets %d\n", ret); ret = GetRandomRgn(hdc, hrgn, 3); ok(ret == 0, "GetRandomRgn rets %d\n", ret); /* Set a clip region */ SetRect(&rc, 20, 20, 80, 80); IntersectClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom); ret = GetRandomRgn(hdc, hrgn, 1); ok(ret != 0, "GetRandomRgn rets %d\n", ret); GetRgnBox(hrgn, &ret_rc); ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %s\n", wine_dbgstr_rect(&ret_rc)); ret = GetRandomRgn(hdc, hrgn, 2); ok(ret == 0, "GetRandomRgn rets %d\n", ret); ret = GetRandomRgn(hdc, hrgn, 3); ok(ret != 0, "GetRandomRgn rets %d\n", ret); GetRgnBox(hrgn, &ret_rc); ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %s\n", wine_dbgstr_rect(&ret_rc)); /* Move the clip to the meta and clear the clip */ SetMetaRgn(hdc); ret = GetRandomRgn(hdc, hrgn, 1); ok(ret == 0, "GetRandomRgn rets %d\n", ret); ret = GetRandomRgn(hdc, hrgn, 2); ok(ret != 0, "GetRandomRgn rets %d\n", ret); GetRgnBox(hrgn, &ret_rc); ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %s\n", wine_dbgstr_rect(&ret_rc)); ret = GetRandomRgn(hdc, hrgn, 3); ok(ret != 0, "GetRandomRgn rets %d\n", ret); GetRgnBox(hrgn, &ret_rc); ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %s\n", wine_dbgstr_rect(&ret_rc)); /* Set a new clip (still got the meta) */ SetRect(&rc2, 10, 30, 70, 90); IntersectClipRect(hdc, rc2.left, rc2.top, rc2.right, rc2.bottom); ret = GetRandomRgn(hdc, hrgn, 1); ok(ret != 0, "GetRandomRgn rets %d\n", ret); GetRgnBox(hrgn, &ret_rc); ok(EqualRect(&rc2, &ret_rc), "GetRandomRgn %s\n", wine_dbgstr_rect(&ret_rc)); ret = GetRandomRgn(hdc, hrgn, 2); ok(ret != 0, "GetRandomRgn rets %d\n", ret); GetRgnBox(hrgn, &ret_rc); ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %s\n", wine_dbgstr_rect(&ret_rc)); IntersectRect(&rc2, &rc, &rc2); ret = GetRandomRgn(hdc, hrgn, 3); ok(ret != 0, "GetRandomRgn rets %d\n", ret); GetRgnBox(hrgn, &ret_rc); ok(EqualRect(&rc2, &ret_rc), "GetRandomRgn %s\n", wine_dbgstr_rect(&ret_rc)); ret = GetRandomRgn(hdc, hrgn, SYSRGN); ok(ret != 0, "GetRandomRgn rets %d\n", ret); GetRgnBox(hrgn, &ret_rc); if(GetVersion() & 0x80000000) OffsetRect(&window_rc, -window_rc.left, -window_rc.top); /* the window may be partially obscured so the region may be smaller */ IntersectRect( &window_rc, &ret_rc, &ret_rc ); ok(EqualRect(&window_rc, &ret_rc), "GetRandomRgn %s\n", wine_dbgstr_rect(&ret_rc)); DeleteObject(hrgn); ReleaseDC(hwnd, hdc); DestroyWindow(hwnd); }
static void TestSuite_PrintJsonHeader (TestSuite *suite, /* IN */ FILE *stream) /* IN */ { #ifdef _WIN32 # define INFO_BUFFER_SIZE 32767 SYSTEM_INFO si; DWORD version = 0; DWORD major_version = 0; DWORD minor_version = 0; DWORD build = 0; GetSystemInfo(&si); version = GetVersion(); major_version = (DWORD)(LOBYTE(LOWORD(version))); minor_version = (DWORD)(HIBYTE(LOWORD(version))); if (version < 0x80000000) { build = (DWORD)(HIWORD(version)); } fprintf (stream, "{\n" " \"host\": {\n" " \"sysname\": \"Windows\",\n" " \"release\": \"%ld.%ld (%ld)\",\n" " \"machine\": \"%ld\",\n" " \"memory\": {\n" " \"pagesize\": %ld,\n" " \"npages\": %d\n" " }\n" " },\n" " \"options\": {\n" " \"parallel\": \"%s\",\n" " \"fork\": \"%s\"\n" " },\n" " \"tests\": [\n", major_version, minor_version, build, si.dwProcessorType, si.dwPageSize, 0, (suite->flags & TEST_NOTHREADS) ? "false" : "true", (suite->flags & TEST_NOFORK) ? "false" : "true"); #else struct utsname u; uint64_t pagesize; uint64_t npages = 0; ASSERT (suite); if (uname (&u) == -1) { perror ("uname()"); return; } pagesize = sysconf (_SC_PAGE_SIZE); # if defined(_SC_PHYS_PAGES) npages = sysconf (_SC_PHYS_PAGES); # endif fprintf (stream, "{\n" " \"host\": {\n" " \"sysname\": \"%s\",\n" " \"release\": \"%s\",\n" " \"machine\": \"%s\",\n" " \"memory\": {\n" " \"pagesize\": %"PRIu64",\n" " \"npages\": %"PRIu64"\n" " }\n" " },\n" " \"options\": {\n" " \"parallel\": \"%s\",\n" " \"fork\": \"%s\"\n" " },\n" " \"tests\": [\n", u.sysname, u.release, u.machine, pagesize, npages, (suite->flags & TEST_NOTHREADS) ? "false" : "true", (suite->flags & TEST_NOFORK) ? "false" : "true"); #endif fflush (stream); }
static void MBInit( void ) /************************/ { #if defined( __NT__ ) && !defined( __UNIX__ ) int countRange, countVal; CPINFO cpInfo; BOOL rc; #elif defined __OS2__ || defined __OS2_PM__ int countRange, countVal; COUNTRYCODE countryInfo; CHAR leadBytes[12]; #ifdef _M_I86 USHORT rc; #else APIRET rc; #endif #elif defined( __WINDOWS__ ) || defined( __UNIX__ ) int countVal; DWORD version; #endif memset( __CharLenTable, 1, sizeof( __CharLenTable ) ); /* zero table to start */ #if defined( __NT__) && !defined( __UNIX__ ) /*** Initialize the __CharLenTable values ***/ rc = GetCPInfo( CP_OEMCP, &cpInfo ); /* get code page info */ if( rc == FALSE ) return; for( countRange=0; !(cpInfo.LeadByte[countRange]==0x00 && cpInfo.LeadByte[countRange+1]==0x00); countRange+=2 ) { for( countVal=cpInfo.LeadByte[countRange]; countVal<=cpInfo.LeadByte[countRange+1]; countVal++) { __CharLenTable[countVal] = 2; IsDBCS = TRUE; } } #elif defined __OS2__ || defined __OS2_PM__ /*** Initialize the __CharLenTable values ***/ countryInfo.country = 0; /* default country */ countryInfo.codepage = 0; /* specified code page */ #ifdef _M_I86 rc = DosGetDBCSEv( 12, &countryInfo, leadBytes ); #else rc = DosQueryDBCSEnv( 12, &countryInfo, leadBytes ); #endif if( rc != 0 ) return; for( countRange=0; !(leadBytes[countRange]==0x00 && leadBytes[countRange+1]==0x00); countRange+=2 ) { for( countVal=leadBytes[countRange]; countVal<=leadBytes[countRange+1]; countVal++) { __CharLenTable[countVal] = 2; IsDBCS = TRUE; } } #elif defined( __WINDOWS__ ) || defined( __UNIX__ ) /*** Initialize the __CharLenTable values ***/ version = GetVersion(); if( LOWORD(version) < ((10<<8)+3) ) return; /* 3.1+ needed */ for( countVal=0; countVal<256; countVal++ ) { if( IsDBCSLeadByte( (BYTE)countVal ) ) { __CharLenTable[countVal] = 2; IsDBCS = TRUE; } } #endif }
const wchar_t* GameObjectComponent::GetVersionString() { return GetVersion().AsWString().c_str(); }
LONG WINAPI HandleUnknownException(struct _EXCEPTION_POINTERS *ExceptionInfo) { WCHAR registerInfo[220]; WCHAR filepath[MAX_PATH] = {0}; WCHAR file[MAX_PATH] = {0}; WCHAR message[MAX_PATH + 200 + _countof(registerInfo)]; WCHAR osInfo[100]; DWORD_PTR baseAddress = 0; DWORD_PTR address = (DWORD_PTR)ExceptionInfo->ExceptionRecord->ExceptionAddress; wcscpy_s(filepath, L"unknown"); wcscpy_s(file, L"unknown"); if (GetMappedFileNameW(GetCurrentProcess(), (LPVOID)address, filepath, _countof(filepath)) > 0) { WCHAR *temp = wcsrchr(filepath, '\\'); if (temp) { temp++; wcscpy_s(file, temp); } } swprintf_s(osInfo, _countof(osInfo), TEXT("Exception! Please report it! OS: %X"), GetVersion()); DWORD_PTR moduleBase = (DWORD_PTR)GetModuleHandleW(file); swprintf_s(message, _countof(message), TEXT("ExceptionCode %08X\r\nExceptionFlags %08X\r\nNumberParameters %08X\r\nExceptionAddress VA ")TEXT(PRINTF_DWORD_PTR_FULL_S)TEXT(" - Base ")TEXT(PRINTF_DWORD_PTR_FULL_S)TEXT("\r\nExceptionAddress module %s\r\n\r\n"), ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionInfo->ExceptionRecord->ExceptionFlags, ExceptionInfo->ExceptionRecord->NumberParameters, address, moduleBase, file); #ifdef _WIN64 swprintf_s(registerInfo, _countof(registerInfo),TEXT("rax=0x%p, rbx=0x%p, rdx=0x%p, rcx=0x%p, rsi=0x%p, rdi=0x%p, rbp=0x%p, rsp=0x%p, rip=0x%p"), ExceptionInfo->ContextRecord->Rax, ExceptionInfo->ContextRecord->Rbx, ExceptionInfo->ContextRecord->Rdx, ExceptionInfo->ContextRecord->Rcx, ExceptionInfo->ContextRecord->Rsi, ExceptionInfo->ContextRecord->Rdi, ExceptionInfo->ContextRecord->Rbp, ExceptionInfo->ContextRecord->Rsp, ExceptionInfo->ContextRecord->Rip ); #else swprintf_s(registerInfo, _countof(registerInfo),TEXT("eax=0x%p, ebx=0x%p, edx=0x%p, ecx=0x%p, esi=0x%p, edi=0x%p, ebp=0x%p, esp=0x%p, eip=0x%p"), ExceptionInfo->ContextRecord->Eax, ExceptionInfo->ContextRecord->Ebx, ExceptionInfo->ContextRecord->Edx, ExceptionInfo->ContextRecord->Ecx, ExceptionInfo->ContextRecord->Esi, ExceptionInfo->ContextRecord->Edi, ExceptionInfo->ContextRecord->Ebp, ExceptionInfo->ContextRecord->Esp, ExceptionInfo->ContextRecord->Eip ); #endif wcscat_s(message, _countof(message), registerInfo); MessageBox(0, message, osInfo, MB_ICONERROR); return EXCEPTION_CONTINUE_SEARCH; }
/************************************************************************* * ScrollDC (X11DRV.@) */ BOOL CDECL X11DRV_ScrollDC( HDC hdc, INT dx, INT dy, const RECT *lprcScroll, const RECT *lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate ) { RECT rcSrc, rcClip, offset; INT dxdev, dydev, res; HRGN DstRgn, clipRgn, visrgn; INT code = X11DRV_START_EXPOSURES; TRACE("dx,dy %d,%d rcScroll %s rcClip %s hrgnUpdate %p lprcUpdate %p\n", dx, dy, wine_dbgstr_rect(lprcScroll), wine_dbgstr_rect(lprcClip), hrgnUpdate, lprcUpdate); /* enable X-exposure events */ if (hrgnUpdate || lprcUpdate) ExtEscape( hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL ); /* get the visible region */ visrgn=CreateRectRgn( 0, 0, 0, 0); GetRandomRgn( hdc, visrgn, SYSRGN); if( !(GetVersion() & 0x80000000)) { /* Window NT/2k/XP */ POINT org; GetDCOrgEx(hdc, &org); OffsetRgn( visrgn, -org.x, -org.y); } /* intersect with the clipping Region if the DC has one */ clipRgn = CreateRectRgn( 0, 0, 0, 0); if (GetClipRgn( hdc, clipRgn) != 1) { DeleteObject(clipRgn); clipRgn=NULL; } else CombineRgn( visrgn, visrgn, clipRgn, RGN_AND); /* only those pixels in the scroll rectangle that remain in the clipping * rect are scrolled. */ if( lprcClip) rcClip = *lprcClip; else GetClipBox( hdc, &rcClip); rcSrc = rcClip; OffsetRect( &rcClip, -dx, -dy); IntersectRect( &rcSrc, &rcSrc, &rcClip); /* if an scroll rectangle is specified, only the pixels within that * rectangle are scrolled */ if( lprcScroll) IntersectRect( &rcSrc, &rcSrc, lprcScroll); /* now convert to device coordinates */ LPtoDP(hdc, (LPPOINT)&rcSrc, 2); TRACE("source rect: %s\n", wine_dbgstr_rect(&rcSrc)); /* also dx and dy */ SetRect(&offset, 0, 0, dx, dy); LPtoDP(hdc, (LPPOINT)&offset, 2); dxdev = offset.right - offset.left; dydev = offset.bottom - offset.top; /* now intersect with the visible region to get the pixels that will * actually scroll */ DstRgn = CreateRectRgnIndirect( &rcSrc); res = CombineRgn( DstRgn, DstRgn, visrgn, RGN_AND); /* and translate, giving the destination region */ OffsetRgn( DstRgn, dxdev, dydev); if( TRACE_ON( scroll)) dump_region( "Destination scroll region: ", DstRgn); /* if there are any, do it */ if( res > NULLREGION) { RECT rect ; /* clip to the destination region, so we can BitBlt with a simple * bounding rectangle */ if( clipRgn) ExtSelectClipRgn( hdc, DstRgn, RGN_AND); else SelectClipRgn( hdc, DstRgn); GetRgnBox( DstRgn, &rect); DPtoLP(hdc, (LPPOINT)&rect, 2); TRACE("destination rect: %s\n", wine_dbgstr_rect(&rect)); BitBlt( hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, hdc, rect.left - dx, rect.top - dy, SRCCOPY); } /* compute the update areas. This is the combined clip rectangle * minus the scrolled region, and intersected with the visible * region. */ if (hrgnUpdate || lprcUpdate) { HRGN hrgn = hrgnUpdate; HRGN ExpRgn = 0; /* collect all the exposures */ code = X11DRV_END_EXPOSURES; ExtEscape( hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, sizeof(ExpRgn), (LPSTR)&ExpRgn ); /* Intersect clip and scroll rectangles, allowing NULL values */ if( lprcScroll) if( lprcClip) IntersectRect( &rcClip, lprcClip, lprcScroll); else rcClip = *lprcScroll; else if( lprcClip) rcClip = *lprcClip; else GetClipBox( hdc, &rcClip); /* Convert the combined clip rectangle to device coordinates */ LPtoDP(hdc, (LPPOINT)&rcClip, 2); if( hrgn ) SetRectRgn( hrgn, rcClip.left, rcClip.top, rcClip.right, rcClip.bottom); else hrgn = CreateRectRgnIndirect( &rcClip); CombineRgn( hrgn, hrgn, visrgn, RGN_AND); CombineRgn( hrgn, hrgn, DstRgn, RGN_DIFF); /* add the exposures to this */ if( ExpRgn) { if( TRACE_ON( scroll)) dump_region( "Expose region: ", ExpRgn); CombineRgn( hrgn, hrgn, ExpRgn, RGN_OR); DeleteObject( ExpRgn); } if( TRACE_ON( scroll)) dump_region( "Update region: ", hrgn); if( lprcUpdate) { GetRgnBox( hrgn, lprcUpdate ); /* Put the lprcUpdate in logical coordinates */ DPtoLP( hdc, (LPPOINT)lprcUpdate, 2 ); TRACE("returning lprcUpdate %s\n", wine_dbgstr_rect(lprcUpdate)); } if( !hrgnUpdate) DeleteObject( hrgn); } /* restore original clipping region */ SelectClipRgn( hdc, clipRgn); DeleteObject( visrgn); DeleteObject( DstRgn); if( clipRgn) DeleteObject( clipRgn); return TRUE; }
bool Surface::resetSwapChain(int backbufferWidth, int backbufferHeight) { IDirect3DDevice9 *device = mDisplay->getDevice(); if (device == NULL) { return false; } // Evict all non-render target textures to system memory and release all resources // before reallocating them to free up as much video memory as possible. device->EvictManagedResources(); release(); D3DPRESENT_PARAMETERS presentParameters = {0}; HRESULT result; bool useFlipEx = (LOWORD(GetVersion()) >= 0x61) && mDisplay->isD3d9ExDevice(); // FlipEx causes unseemly stretching when resizing windows AND when one // draws outside of the WM_PAINT callback. While this is seldom a problem in // single process applications, it is particuarly noticeable in multiprocess // applications. Therefore, if the creator process of our window is not in // the current process, disable use of FlipEx. DWORD windowPID; GetWindowThreadProcessId(mWindow, &windowPID); if(windowPID != GetCurrentProcessId()) useFlipEx = false; presentParameters.AutoDepthStencilFormat = mConfig->mDepthStencilFormat; // We set BackBufferCount = 1 even when we use D3DSWAPEFFECT_FLIPEX. // We do this because DirectX docs are a bit vague whether to set this to 1 // or 2. The runtime seems to accept 1, so we speculate that either it is // forcing it to 2 without telling us, or better, doing something smart // behind the scenes knowing that we don't need more. presentParameters.BackBufferCount = 1; presentParameters.BackBufferFormat = mConfig->mRenderTargetFormat; presentParameters.EnableAutoDepthStencil = FALSE; presentParameters.Flags = 0; presentParameters.hDeviceWindow = getWindowHandle(); presentParameters.MultiSampleQuality = 0; // FIXME: Unimplemented presentParameters.MultiSampleType = D3DMULTISAMPLE_NONE; // FIXME: Unimplemented presentParameters.PresentationInterval = mPresentInterval; // Use flipEx on Win7 or greater. if(useFlipEx) presentParameters.SwapEffect = D3DSWAPEFFECT_FLIPEX; else presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD; presentParameters.Windowed = TRUE; presentParameters.BackBufferWidth = backbufferWidth; presentParameters.BackBufferHeight = backbufferHeight; if (mWindow) { result = device->CreateAdditionalSwapChain(&presentParameters, &mSwapChain); } else { HANDLE *pShareHandle = NULL; if (mDisplay->isD3d9ExDevice()) { pShareHandle = &mShareHandle; } result = device->CreateTexture(presentParameters.BackBufferWidth, presentParameters.BackBufferHeight, 1, D3DUSAGE_RENDERTARGET, presentParameters.BackBufferFormat, D3DPOOL_DEFAULT, &mOffscreenTexture, pShareHandle); } if (FAILED(result)) { ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); ERR("Could not create additional swap chains or offscreen surfaces: %08lX", result); release(); return error(EGL_BAD_ALLOC, false); } if (mConfig->mDepthStencilFormat != D3DFMT_UNKNOWN) { result = device->CreateDepthStencilSurface(presentParameters.BackBufferWidth, presentParameters.BackBufferHeight, presentParameters.AutoDepthStencilFormat, presentParameters.MultiSampleType, presentParameters.MultiSampleQuality, FALSE, &mDepthStencil, NULL); } if (FAILED(result)) { ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); ERR("Could not create depthstencil surface for new swap chain: %08lX", result); release(); return error(EGL_BAD_ALLOC, false); } if (mWindow) { mSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &mRenderTarget); InvalidateRect(mWindow, NULL, FALSE); } else { mOffscreenTexture->GetSurfaceLevel(0, &mRenderTarget); } mWidth = presentParameters.BackBufferWidth; mHeight = presentParameters.BackBufferHeight; mPresentIntervalDirty = false; return true; }
int CMainFrame::GetAdapterList() { #define ADAPTER_LENGTH (10000) DWORD dwVersion, dwWindowsMajorVersion, dwAdapterLength = ADAPTER_LENGTH; int iAdapterNum = 0; // unicode strings (winnt) WCHAR AdapterName[ADAPTER_LENGTH]; // string that contains a list of the network adapters WCHAR *temp; // ascii strings (win95) char AdapterNamea[ADAPTER_LENGTH]; // string that contains a list of the network adapters char *tempa; /* DWORD dwIP, dwMask; BOOL bIpMask; char szAdapterNameIPMask[512]; */ /* the data returned by PacketGetAdapterNames is different in Win95 and in WinNT. We have to check the os on which we are running */ dwVersion = GetVersion(); dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); if (!(dwVersion >= 0x80000000 && dwWindowsMajorVersion >= 4)) { // Windows NT //#pragma warning( disable : 4133 ) PacketGetAdapterNames((char *)AdapterName, &dwAdapterLength); //#pragma warning( default : 4133 ) temp = AdapterName; while (*temp != 0) { // bIpMask = PacketGetNetInfo((char *)temp, &dwIP, &dwMask); if (0 == WideCharToMultiByte(CP_ACP, 0, temp, wcslen(temp), AdapterNamea, 512, NULL, NULL)) { TRACE("Error converting to ANSI: %u\n", GetLastError()); } /*if (bIpMask) { sprintf(&AdapterNamea[wcslen(temp)], " (ip:%u.%u.%u.%u mask:%u.%u.%u.%u)", (BYTE)(dwIP >> 24), (BYTE)(dwIP >> 16), (BYTE)(dwIP >> 8), (BYTE)(dwIP), (BYTE)(dwMask >> 24), (BYTE)(dwMask >> 16), (BYTE)(dwMask >> 8), (BYTE)(dwMask)); } else AdapterNamea[wcslen(temp)] = 0;*/ AdapterNamea[wcslen(temp)] = 0; m_wndAdapter.AddString(AdapterNamea); temp += wcslen(temp); temp++; iAdapterNum++; } } else { // windows 9x PacketGetAdapterNames(AdapterNamea, &dwAdapterLength); tempa = AdapterNamea; while (*tempa != 0) { m_wndAdapter.AddString(tempa); tempa += strlen(tempa); tempa++; iAdapterNum++; } } // Find the longest string in the combo box. CString str; CSize sz; int dx = 0; CDC* pDC = m_wndAdapter.GetDC(); for (int i=0;i < m_wndAdapter.GetCount(); i++) { m_wndAdapter.GetLBText( i, str ); sz = pDC->GetTextExtent(str); if (sz.cx > dx) dx = sz.cx; } m_wndAdapter.ReleaseDC(pDC); // Adjust the width for the vertical scroll bar and the left and right border. dx += ::GetSystemMetrics(SM_CXVSCROLL) + 2 * ::GetSystemMetrics(SM_CXEDGE); // Set the width of the list box so that every item is completely visible. m_wndAdapter.SetDroppedWidth(dx); return iAdapterNum; #undef ADAPTER_LENGTH }
LICE_IBitmap *LICE_LoadPNG(const char *filename, LICE_IBitmap *bmp) { FILE *fp = NULL; #if defined(_WIN32) && !defined(WDL_NO_SUPPORT_UTF8) #ifdef WDL_SUPPORT_WIN9X if (GetVersion()<0x80000000) #endif { WCHAR wf[2048]; if (MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,filename,-1,wf,2048)) fp = _wfopen(wf,L"rb"); } #endif if (!fp) fp = fopen(filename,"rb"); if (!fp) return 0; png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if(!png_ptr) { fclose(fp); return 0; } png_infop info_ptr = png_create_info_struct(png_ptr); if(!info_ptr) { png_destroy_read_struct(&png_ptr, NULL, NULL); fclose(fp); return 0; } if (setjmp(png_jmpbuf(png_ptr))) { png_destroy_read_struct(&png_ptr, &info_ptr, NULL); fclose(fp); return 0; } png_init_io(png_ptr, fp); png_read_info(png_ptr, info_ptr); unsigned int width, height; int bit_depth, color_type, interlace_type, compression_type, filter_method; png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method); //convert whatever it is to RGBA if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_palette_to_rgb(png_ptr); if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr); if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { png_set_tRNS_to_alpha(png_ptr); color_type |= PNG_COLOR_MASK_ALPHA; } if (bit_depth == 16) png_set_strip_16(png_ptr); if (bit_depth < 8) png_set_packing(png_ptr); if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png_ptr); if (color_type & PNG_COLOR_MASK_ALPHA) png_set_swap_alpha(png_ptr); else png_set_filler(png_ptr, 0xff, PNG_FILLER_BEFORE); LICE_IBitmap *delbmp = NULL; if (bmp) bmp->resize(width,height); else delbmp = bmp = new WDL_NEW LICE_MemBitmap(width,height); if (!bmp || bmp->getWidth() != (int)width || bmp->getHeight() != (int)height) { delete delbmp; png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); fclose(fp); return 0; } unsigned char **row_pointers=(unsigned char **)malloc(height*sizeof(unsigned char *));; LICE_pixel *srcptr = bmp->getBits(); int dsrcptr=bmp->getRowSpan(); if (bmp->isFlipped()) { srcptr += dsrcptr*(bmp->getHeight()-1); dsrcptr=-dsrcptr; } unsigned int i; for(i=0;i<height;i++) { row_pointers[i]=(unsigned char *)srcptr; srcptr+=dsrcptr; } png_read_image(png_ptr, row_pointers); png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); fclose(fp); #if !(LICE_PIXEL_A == 0 && LICE_PIXEL_R == 1 && LICE_PIXEL_G == 2 && LICE_PIXEL_B == 3) for(i=0;i<height;i++) { unsigned char *bp = row_pointers[i]; int j=width; while (j-->0) { unsigned char a = bp[0]; unsigned char r = bp[1]; unsigned char g = bp[2]; unsigned char b = bp[3]; ((LICE_pixel*)bp)[0] = LICE_RGBA(r,g,b,a); bp+=4; } } #endif free(row_pointers); return bmp; }
BOOL IsWin395OrHigher( void ) { WORD wVer; wVer = LOWORD( GetVersion() ); wVer = ( ( ( WORD )LOBYTE( wVer ) ) << 8 ) | ( WORD )HIBYTE( wVer ); return ( wVer >= 0x035F ); // 5F = 95 dec }
static void frontend_win32_get_os(char *s, size_t len, int *major, int *minor) { uint32_t version = GetVersion(); *major = (DWORD)(LOBYTE(LOWORD(version))); *minor = (DWORD)(HIBYTE(LOWORD(version))); switch (*major) { case 10: strlcpy(s, "Windows 10", len); break; case 6: switch (*minor) { case 3: strlcpy(s, "Windows 8.1", len); break; case 2: strlcpy(s, "Windows 8", len); break; case 1: strlcpy(s, "Windows 7/2008 R2", len); break; case 0: strlcpy(s, "Windows Vista/2008", len); break; default: break; } break; case 5: switch (*minor) { case 2: strlcpy(s, "Windows 2003", len); break; case 1: strlcpy(s, "Windows XP", len); break; case 0: strlcpy(s, "Windows 2000", len); break; } break; case 4: switch (*minor) { case 0: strlcpy(s, "Windows NT 4.0", len); break; case 90: strlcpy(s, "Windows ME", len); break; case 10: strlcpy(s, "Windows 98", len); break; } break; default: break; } }
static int open_s(stream_t *stream,int mode, void* opts, int* file_format) { struct stream_priv_s* p = opts; int ret,ret2,f,sect,tmp; mp_vcd_priv_t* vcd; #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) int bsize = VCD_SECTOR_SIZE; #endif #if defined(__MINGW32__) || defined(__CYGWIN__) HANDLE hd; char device[] = "\\\\.\\?:"; #endif #if defined(__OS2__) char device[] = "X:"; HFILE hcd; ULONG ulAction; ULONG rc; #endif if(mode != STREAM_READ #if defined(__MINGW32__) || defined(__CYGWIN__) || GetVersion() > 0x80000000 // Win9x #endif ) { m_struct_free(&stream_opts,opts); return STREAM_UNSUPPORTED; } if (!p->device) { if(cdrom_device) p->device = strdup(cdrom_device); else p->device = strdup(DEFAULT_CDROM_DEVICE); } #if defined(__MINGW32__) || defined(__CYGWIN__) device[4] = p->device[0]; /* open() can't be used for devices so do it the complicated way */ hd = CreateFile(device, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); f = _open_osfhandle((long)hd, _O_RDONLY); #elif defined(__OS2__) device[0] = p->device[0]; rc = DosOpen(device, &hcd, &ulAction, 0, FILE_NORMAL, OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW, OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE | OPEN_FLAGS_DASD, NULL); f = rc ? -1 : hcd; #else f=open(p->device,O_RDONLY); #endif if(f<0){ mp_tmsg(MSGT_OPEN,MSGL_ERR,"CD-ROM Device '%s' not found.\n",p->device); m_struct_free(&stream_opts,opts); return STREAM_ERROR; } vcd = vcd_read_toc(f); if(!vcd) { mp_msg(MSGT_OPEN,MSGL_ERR,"Failed to get cd toc\n"); close(f); m_struct_free(&stream_opts,opts); return STREAM_ERROR; } ret2=vcd_get_track_end(vcd,p->track); if(ret2<0){ mp_msg(MSGT_OPEN, MSGL_ERR, "%s (get)\n", mp_gtext("Error selecting VCD track.")); close(f); free(vcd); m_struct_free(&stream_opts,opts); return STREAM_ERROR; } ret=vcd_seek_to_track(vcd,p->track); if(ret<0){ mp_msg(MSGT_OPEN, MSGL_ERR, "%s (seek)\n", mp_gtext("Error selecting VCD track.")); close(f); free(vcd); m_struct_free(&stream_opts,opts); return STREAM_ERROR; } /* search forward up to at most 3 seconds to skip leading margin */ sect = ret / VCD_SECTOR_DATA; for (tmp = sect; tmp < sect + 3 * 75; tmp++) { char mem[VCD_SECTOR_DATA]; //since MPEG packs are block-aligned we stop discarding sectors if they are non-null if (vcd_read(vcd, mem) != VCD_SECTOR_DATA || mem[2] || mem[3]) break; } mp_msg(MSGT_OPEN, MSGL_DBG2, "%d leading sectors skipped\n", tmp - sect); vcd_set_msf(vcd, tmp); ret = tmp * VCD_SECTOR_DATA; mp_msg(MSGT_OPEN,MSGL_V,"VCD start byte position: 0x%X end: 0x%X\n",ret,ret2); #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) { mp_msg(MSGT_OPEN,MSGL_WARN,"Error in CDRIOCSETBLOCKSIZE"); } #endif stream->fd = f; stream->type = STREAMTYPE_VCD; stream->sector_size = VCD_SECTOR_DATA; stream->start_pos=ret; stream->end_pos=ret2; stream->priv = vcd; stream->fill_buffer = fill_buffer; stream->seek = seek; stream->close = close_s; *file_format = DEMUXER_TYPE_MPEG_PS; m_struct_free(&stream_opts,opts); return STREAM_OK; }
int main(int argc, char **argv) { int i; HINSTANCE hPacket; DWORD dwVersion, dwMajorVersion; char AdapterInfo[NIC_BUFFER_SIZE] = { '\0','\0' }; unsigned long AdapterLength = NIC_BUFFER_SIZE; LPWSTR wstrName; LPSTR strName, strDesc; int nAdapterCount; PCHAR dllVersion; PCHAR testString; int nDLLMajorVersion, nDLLMinorVersion; // Attemp to load the WinpCap packet library hPacket = LoadLibrary("PACKET.DLL"); if(hPacket) { // Now look up the address PacketGetAdapterNames = (BOOLEAN (*)(PTSTR, PULONG))GetProcAddress(hPacket, "PacketGetAdapterNames"); PacketGetVersion = (PCHAR (*)())GetProcAddress(hPacket, "PacketGetVersion"); } else { printf("Could not load WinPCap driver!\n"); printf ("You can download them for free from\n"); printf ("http://www.winpcap.org/\n"); myexit(1); } dwVersion = GetVersion(); dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); // Get DLL Version and Tokenize dllVersion = PacketGetVersion(); nDLLMajorVersion = -1; nDLLMinorVersion = -1; for ( testString = strtok(dllVersion, ", "); testString != NULL; testString = strtok(NULL, ", ") ) { // If Single Character, Convert if ( strlen( testString ) == 1 ) { // Check Major First if ( nDLLMajorVersion == -1 ) { nDLLMajorVersion = atoi(testString); } else if ( nDLLMinorVersion == -1 ) { nDLLMinorVersion = atoi(testString); } } } // Get out blob of adapter info PacketGetAdapterNames(AdapterInfo,&AdapterLength); // If this is Windows NT ... And DLL Returns UNICODE if(!(dwVersion >= 0x80000000 && dwMajorVersion >= 4) && !(nDLLMajorVersion >= 3 && nDLLMinorVersion >= 1)) { wstrName=(LPWSTR)AdapterInfo; // Obtain Names nAdapterCount = 0; while ((*wstrName)) { // store pointer to name niNT[nAdapterCount].wstrName=wstrName; wstrName += lstrlenW(wstrName) +1; nAdapterCount++; } strDesc = (LPSTR)++wstrName; // Obtain descriptions .... for(i=0;i<nAdapterCount;i++) { // store pointer to description niNT[i].strDesc=strDesc; strDesc += lstrlen(strDesc) +1; // ... and display adapter info printf("\n%d: %s\n",i+1,niNT[i].strDesc); wprintf(L" Device: %s",niNT[i].wstrName); } if(i) { printf("\n\nExample config for bochsrc:\n"); wprintf(L"ne2k: ioaddr=0x300, irq=3, mac=b0:c4:20:00:00:00, ethmod=win32, ethdev=%s",niNT[0].wstrName); printf("\n"); } } else { // Windows 9x strName=(LPSTR)AdapterInfo; // Obtain Names nAdapterCount = 0; while ((*strName)) { // store pointer to name ni9X[nAdapterCount].strName=strName; strName += lstrlen(strName) +1; nAdapterCount++; } strDesc = (LPSTR)++strName; // Obtain descriptions .... for(i=0;i<nAdapterCount;i++) { // store pointer to description ni9X[i].strDesc=strDesc; strDesc += lstrlen(strDesc) +1; // ... and display adapter info printf("\n%d: %s\n",i+1,ni9X[i].strDesc); printf(" Device: %s",ni9X[i].strName); } if(i) { printf("\n\nExample config for bochsrc:\n"); printf("ne2k: ioaddr=0x300, irq=3, mac=b0:c4:20:00:00:00, ethmod=win32, ethdev=%s",ni9X[0].strName); printf("\n"); } printf("\n"); } myexit (0); return 0; /* shut up stupid compilers */ }
/* * funkcja callback obs³uguj¹ca stronê z opcjami tab 2 */ INT_PTR CALLBACK DlgProcOpts_Tab2(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { static HANDLE hItemAll; switch ( msg ) { case WM_INITDIALOG: { TranslateDialogDefault(hwndDlg); mirfoxMiranda.getMirfoxData().setTab2OptionsState(MFENUM_OPTIONS_INIT); //load icons HIMAGELIST hIml; int smCx = GetSystemMetrics(SM_CXSMICON); int smCy = GetSystemMetrics(SM_CYSMICON); hIml = ImageList_Create(smCx,smCy,((LOBYTE(LOWORD(GetVersion()))>=5 && LOWORD(GetVersion())!=5) ? ILC_COLOR32 : ILC_COLOR16) | ILC_MASK, 4, 4); //load icons (direct) icoHandle_ICON_OFF = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON_OFF)); icoHandle_ICON_FF = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON_FF)); //TODO load icons (icolib) - no need to use DestroyIcon //HICON icoHandle_ICON_OFF = (HICON)CallService(MS_SKIN2_GETICONBYHANDLE, 0, (LPARAM)mirfoxData.icoHandle_ICON_OFF); //HICON icoHandle_ICON_FF = (HICON)CallService(MS_SKIN2_GETICONBYHANDLE, 0, (LPARAM)mirfoxData.icoHandle_ICON_FF); //add icons to ImageList list ImageList_AddIcon(hIml, icoHandle_ICON_OFF); ImageList_AddIcon(hIml, icoHandle_ICON_FF); SendDlgItemMessage(hwndDlg, IDC2_CONTACTS_LIST, CLM_SETEXTRAIMAGELIST, 0, (LPARAM)hIml); //m_clc.h //list params init resetListOptions(GetDlgItem(hwndDlg, IDC2_CONTACTS_LIST)); SendDlgItemMessage(hwndDlg, IDC2_CONTACTS_LIST, CLM_SETEXTRACOLUMNS, 1, 0); //add 'All contacts' list record { CLCINFOITEM cii = {0}; cii.cbSize = sizeof(cii); cii.flags = CLCIIF_GROUPFONT; cii.pszText =TranslateT("** All contacts **"); hItemAll = (HANDLE)SendDlgItemMessage(hwndDlg, IDC2_CONTACTS_LIST, CLM_ADDINFOITEM, 0, (LPARAM)&cii); } //set contacts and groups icons setListContactIcons(GetDlgItem(hwndDlg, IDC2_CONTACTS_LIST)); setListGroupIcons(GetDlgItem(hwndDlg, IDC2_CONTACTS_LIST), (HANDLE)SendDlgItemMessage(hwndDlg, IDC2_CONTACTS_LIST, CLM_GETNEXTITEM, CLGN_ROOT, 0), hItemAll, NULL); mirfoxMiranda.getMirfoxData().setTab2OptionsState(MFENUM_OPTIONS_WORK); return FALSE; } case WM_SETFOCUS: SetFocus(GetDlgItem(hwndDlg, IDC2_CONTACTS_LIST)); break; case WM_NOTIFY: if (mirfoxMiranda.getMirfoxData().getTab2OptionsState() != MFENUM_OPTIONS_WORK){ break; //options not inited yet } switch(((LPNMHDR)lParam)->idFrom) { case IDC2_CONTACTS_LIST: switch (((LPNMHDR)lParam)->code){ case CLN_NEWCONTACT: case CLN_LISTREBUILT: setListContactIcons(GetDlgItem(hwndDlg, IDC2_CONTACTS_LIST)); //fall through case CLN_CONTACTMOVED: setListGroupIcons(GetDlgItem(hwndDlg, IDC2_CONTACTS_LIST), (HANDLE)SendDlgItemMessage(hwndDlg, IDC2_CONTACTS_LIST, CLM_GETNEXTITEM, CLGN_ROOT, 0), hItemAll, NULL); break; case CLN_OPTIONSCHANGED: resetListOptions(GetDlgItem(hwndDlg, IDC2_CONTACTS_LIST)); break; case NM_CLICK: { NMCLISTCONTROL *nm=(NMCLISTCONTROL*)lParam; // Make sure we have an extra column if (nm->iColumn == -1){ break; } // Find clicked item DWORD hitFlags; HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC2_CONTACTS_LIST, CLM_HITTEST, (WPARAM)&hitFlags, MAKELPARAM(nm->pt.x, nm->pt.y)); // Nothing was clicked if (hItem == NULL){ break; } // It was not a visbility icon if (!(hitFlags & CLCHT_ONITEMEXTRA)){ break; } // Get image in clicked column (0=off, 1=on) int iImage = SendDlgItemMessage(hwndDlg, IDC2_CONTACTS_LIST, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(nm->iColumn, 0)); if (iImage == 0){ iImage=nm->iColumn + 1; } else { if (iImage == 1){ iImage = 0; } } // Get item type (contact, group, etc...) int itemType = SendDlgItemMessage(hwndDlg, IDC2_CONTACTS_LIST, CLM_GETITEMTYPE, (WPARAM)hItem, 0); // Update list if (itemType == CLCIT_CONTACT) { // A contact SendDlgItemMessage(hwndDlg, IDC2_CONTACTS_LIST, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(nm->iColumn, iImage)); } else if (itemType == CLCIT_INFO) { // All Contacts setAllChildIcons(GetDlgItem(hwndDlg, IDC2_CONTACTS_LIST), hItem, nm->iColumn, iImage); } else if (itemType == CLCIT_GROUP) { // A group hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC2_CONTACTS_LIST, CLM_GETNEXTITEM, CLGN_CHILD, (LPARAM)hItem); if (hItem) { setAllChildIcons(GetDlgItem(hwndDlg, IDC2_CONTACTS_LIST), hItem, nm->iColumn, iImage); } } // Update the all/none icons setListGroupIcons(GetDlgItem(hwndDlg, IDC2_CONTACTS_LIST), (HANDLE)SendDlgItemMessage(hwndDlg, IDC2_CONTACTS_LIST, CLM_GETNEXTITEM, CLGN_ROOT, 0), hItemAll, NULL); // Activate Apply button SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; }//end case NM_CLICK }//end switch break; case 0: switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: { for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)){ HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC2_CONTACTS_LIST, CLM_FINDCONTACT, hContact, 0); if(hItem) { int iImage = SendDlgItemMessage(hwndDlg, IDC2_CONTACTS_LIST, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(0,0)); MFENUM_MIRANDACONTACT_STATE contactState; if (iImage == 0xFF){ //TODO impossible?? } else { if (iImage == 1){ contactState = MFENUM_MIRANDACONTACT_STATE_ON; } else { contactState = MFENUM_MIRANDACONTACT_STATE_OFF; } } //save to mirfoxData int result = mirfoxMiranda.getMirfoxData().updateMirandaContactState(hContact, contactState); if (result != 0){ //todo errors handling } //save to db 1 - on, 2 - off if (contactState == MFENUM_MIRANDACONTACT_STATE_OFF){ db_set_b(hContact, PLUGIN_DB_ID, "state", 2); } else { db_set_b(hContact, PLUGIN_DB_ID, "state", 1); } }//TODO else { ... (and at others if(hItem)) //TODO contacts witch are not ay mirfoxData but on list //( check hash concat(all id) on mirfoxData and on list, if doesn't match - refresh mirfoxData //same for protocols //for now it schould be ok } //TODO contacts at MirfoxData but not on list now return TRUE; } } break; } break; case WM_DESTROY: { HIMAGELIST hIml=(HIMAGELIST)SendDlgItemMessage(hwndDlg, IDC2_CONTACTS_LIST, CLM_GETEXTRAIMAGELIST, 0, 0); //m_clc.h ImageList_Destroy(hIml); // use DestroyIcon only witchout icolib DestroyIcon(icoHandle_ICON_OFF); icoHandle_ICON_OFF = NULL; DestroyIcon(icoHandle_ICON_FF); icoHandle_ICON_FF = NULL; break; } }//end switch return 0; }
static void readscreen(void) { #if !defined(OPENSSL_SYS_WINCE) && !defined(OPENSSL_SYS_WIN32_CYGWIN) HDC hScrDC; /* screen DC */ HDC hMemDC; /* memory DC */ HBITMAP hBitmap; /* handle for our bitmap */ HBITMAP hOldBitmap; /* handle for previous bitmap */ BITMAP bm; /* bitmap properties */ unsigned int size; /* size of bitmap */ char *bmbits; /* contents of bitmap */ int w; /* screen width */ int h; /* screen height */ int y; /* y-coordinate of screen lines to grab */ int n = 16; /* number of screen lines to grab at a time */ if (GetVersion() >= 0x80000000 || !OPENSSL_isservice()) return; /* Create a screen DC and a memory DC compatible to screen DC */ hScrDC = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL); hMemDC = CreateCompatibleDC(hScrDC); /* Get screen resolution */ w = GetDeviceCaps(hScrDC, HORZRES); h = GetDeviceCaps(hScrDC, VERTRES); /* Create a bitmap compatible with the screen DC */ hBitmap = CreateCompatibleBitmap(hScrDC, w, n); /* Select new bitmap into memory DC */ hOldBitmap = SelectObject(hMemDC, hBitmap); /* Get bitmap properties */ GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm); size = (unsigned int)bm.bmWidthBytes * bm.bmHeight * bm.bmPlanes; bmbits = OPENSSL_malloc(size); if (bmbits) { /* Now go through the whole screen, repeatedly grabbing n lines */ for (y = 0; y < h-n; y += n) { unsigned char md[MD_DIGEST_LENGTH]; /* Bitblt screen DC to memory DC */ BitBlt(hMemDC, 0, 0, w, n, hScrDC, 0, y, SRCCOPY); /* Copy bitmap bits from memory DC to bmbits */ GetBitmapBits(hBitmap, size, bmbits); /* Get the hash of the bitmap */ MD(bmbits,size,md); /* Seed the random generator with the hash value */ RAND_add(md, MD_DIGEST_LENGTH, 0); } OPENSSL_free(bmbits); } /* Select old bitmap back into memory DC */ hBitmap = SelectObject(hMemDC, hOldBitmap); /* Clean up */ DeleteObject(hBitmap); DeleteDC(hMemDC); DeleteDC(hScrDC); #endif /* !OPENSSL_SYS_WINCE */ }
void Next2Friends::SaveApplicationData() { Utils::StorageSetData(GetClsID(), GetVersion(), (void *)applicationData, sizeof(ApplicationData)); }
void I_PreInitGraphics(void) { int p; char *video_driver = strdup(sdl_videodriver); // Initialize SDL unsigned int flags = 0; if (!(M_CheckParm("-nodraw") && M_CheckParm("-nosound"))) flags = SDL_INIT_VIDEO; #ifdef PRBOOM_DEBUG flags |= SDL_INIT_NOPARACHUTE; #endif // e6y: Forcing "directx" video driver for Win9x. // The "windib" video driver is the default for SDL > 1.2.9, // to prevent problems with certain laptops, 64-bit Windows, and Windows Vista. // The DirectX driver is still available, and can be selected by setting // the environment variable SDL_VIDEODRIVER to "directx". if ((p = M_CheckParm("-videodriver")) && (p < myargc - 1)) { free(video_driver); video_driver = strdup(myargv[p + 1]); } if (strcasecmp(video_driver, "default")) { // videodriver != default char buf[80]; strcpy(buf, "SDL_VIDEODRIVER="); strncat(buf, video_driver, sizeof(buf) - sizeof(buf[0]) - strlen(buf)); putenv(buf); } else { // videodriver == default #ifdef _WIN32 if ((int)GetVersion() < 0 && V_GetMode() != VID_MODEGL ) // win9x { free(video_driver); video_driver = strdup("directx"); putenv("SDL_VIDEODRIVER=directx"); } #endif } p = SDL_Init(flags); if (p < 0 && strcasecmp(video_driver, "default")) { static const union { const char *c; char *s; } u = { "SDL_VIDEODRIVER=" }; //e6y: wrong videodriver? lprintf(LO_ERROR, "Could not initialize SDL with SDL_VIDEODRIVER=%s [%s]\n", video_driver, SDL_GetError()); putenv(u.s); p = SDL_Init(flags); } free(video_driver); if (p < 0) { I_Error("Could not initialize SDL [%s]", SDL_GetError()); } atexit(I_ShutdownSDL); }
DWORD main( int argc, char *argv[], char *envp[] ) { int i; HANDLE hMod,x; CHAR Buff[256]; PCHAR s; FARPROC f; DWORD Version; HANDLE Handle; DWORD rc; STARTUPINFO StartupInfo; GetStartupInfo(&StartupInfo); printf("Title %s\n",StartupInfo.lpTitle); printf( "TBASE: Entering Test Program\n" ); assert(GetModuleFileName(0,Buff,256) < 255); printf("Image Name %s\n",Buff); #if 0 printf( "argc: %ld\n", argc ); for (i=0; i<argc; i++) { printf( "argv[ %3ld ]: '%s'\n", i, argv[ i ] ); } for (i=0; envp[ i ]; i++) { printf( "envp[ %3ld ]: %s\n", i, envp[ i ] ); } DbgBreakPoint(); s = "ync ""Yes or No"""; printf( "Invoking: '%s'\nResult: %d\n", s, system(s) ); TestEnvironment(); for (i=1; i<=256; i++) { rc = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY, NULL, i, NULL, sizeof( Buff ), (va_list *)Inserts ); if (rc != 0) { rc = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY, NULL, i, Buff, rc, (va_list *)Inserts ); if (rc != 0) { cprintf( "SYS%05u: %s\r\n", i, Buff ); } } } Handle = CreateFile( "\\config.sys", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL ); if (Handle != INVALID_HANDLE_VALUE) { printf( "CreateFile successful, handle = %lX\n", Handle ); } else { printf( "CreateFile failed\n" ); } rc = SetFilePointer(Handle, 0, NULL, FILE_END); if (rc != -1) { printf( "File size = %ld\n", rc ); } else { printf( "SetFilePointer failed\n" ); } Version = GetVersion(); assert( (Version & 0x0000ffff) == 4); assert( (Version >> 16) == 0); #endif hMod = LoadLibrary("dbgdll"); assert(hMod); assert(hMod == GetModuleHandle("dbgdll")); hMod = LoadLibrary("c:\\nt\\dll\\csr.dll"); assert(hMod); assert(GetModuleFileName(hMod,Buff,256) == strlen("c:\\nt\\dll\\csr.dll")+1); assert(_strcmpi(Buff,"c:\\nt\\dll\\csr.dll") == 0 ); hMod = LoadLibrary("nt\\dll\\csrrtl.dll"); assert(hMod); x = LoadLibrary("csrrtl"); assert( x && x == hMod); assert(FreeLibrary(x)); assert(FreeLibrary(x)); hMod = GetModuleHandle("csrrtl"); assert(hMod == NULL); x = LoadLibrary("csrrtl"); assert( x ); assert(FreeLibrary(x)); hMod = LoadLibrary("kernel32"); assert(hMod); f = GetProcAddress(hMod,"GetProcAddress"); assert(f); assert(f == (f)(hMod,"GetProcAddress")); assert(f == MakeProcInstance(f,hMod)); FreeProcInstance(f); DebugBreak(); assert(FreeLibrary(hMod)); // hMod = LoadLibrary("baddll"); // assert(!hMod); printf( "TBASE: Exiting Test Program\n" ); return 0; }
void PopupManager::Show(const tstring &aMsg, const tstring &aTitle, int Icon, HICON /*hIcon*/, bool force) { if(!activated) return; if (!AirUtil::getAway() && SETTING(POPUP_AWAY) && !force) return; if(!MainFrame::getMainFrame()->getAppMinimized() && SETTING(POPUP_MINIMIZED) && !force) { return; } tstring msg = aMsg; if(int(aMsg.length()) > SETTING(MAX_MSG_LENGTH)) { msg = aMsg.substr(0, (SETTING(MAX_MSG_LENGTH) - 3)); msg += _T("..."); } if(SETTING(POPUP_TYPE) == BALLOON) { NOTIFYICONDATA m_nid; m_nid.cbSize = sizeof(NOTIFYICONDATA); m_nid.hWnd = MainFrame::getMainFrame()->m_hWnd; m_nid.uID = 0; m_nid.uFlags = NIF_INFO; m_nid.uTimeout = (SETTING(POPUP_TIME) * 1000); m_nid.dwInfoFlags = Icon; _tcscpy(m_nid.szInfo, msg.c_str()); _tcscpy(m_nid.szInfoTitle, aTitle.c_str()); Shell_NotifyIcon(NIM_MODIFY, &m_nid); return; } if(PopupImage != SETTING(POPUPFILE) || popuptype != SETTING(POPUP_TYPE)) { PopupImage = SETTING(POPUPFILE); popuptype = SETTING(POPUP_TYPE); hBitmap = (HBITMAP)::LoadImage(NULL, (Text::toT(PopupImage).c_str()), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); if(hBitmap != NULL && SETTING(POPUP_TYPE) == CUSTOM) { BITMAP bm; GetObject(hBitmap,sizeof(bm),&bm); height = (uint16_t)bm.bmHeight; width = (uint16_t)bm.bmWidth; } else if(SETTING(POPUP_TYPE) != CUSTOM) { height = 90; width = 200; } } CRect rcDesktop; //get desktop rect so we know where to place the popup ::SystemParametersInfo(SPI_GETWORKAREA,0,&rcDesktop,0); int screenHeight = rcDesktop.bottom; int screenWidth = rcDesktop.right; //if we have popups all the way up to the top of the screen do not create a new one if( (offset + height) > screenHeight) return; //get the handle of the window that has focus HWND gotFocus = ::SetFocus(WinUtil::mainWnd); //compute the window position CRect rc(screenWidth - width , screenHeight - height - offset, screenWidth, screenHeight - offset); //Create a new popup PopupWnd *p = new PopupWnd(msg, aTitle, rc, id++, hBitmap); p->height = height; // save the height, for removal if(SETTING(POPUP_TYPE) != CUSTOM) { if(LOBYTE(LOWORD(GetVersion())) >= 5) { p->SetWindowLong(GWL_EXSTYLE, p->GetWindowLong(GWL_EXSTYLE) | WS_EX_LAYERED | WS_EX_TRANSPARENT); typedef bool (CALLBACK* LPFUNC)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags); LPFUNC _d_SetLayeredWindowAttributes = (LPFUNC)GetProcAddress(LoadLibrary(_T("user32")), "SetLayeredWindowAttributes"); _d_SetLayeredWindowAttributes(p->m_hWnd, 0, 200, LWA_ALPHA); } }
/* * AccLoadProg - create a new process for debugging */ trap_retval ReqProg_load( void ) { char *parm; char *src; char *dst; char *endsrc; char exe_name[PATH_MAX]; char ch; BOOL rc; int len; MYCONTEXT con; thread_info *ti; HANDLE handle; prog_load_req *acc; prog_load_ret *ret; header_info hi; WORD stack; WORD version; DWORD pid; DWORD pid_started; DWORD cr_flags; char *buff; size_t nBuffRequired; char *dll_name; char *service_name; char *dll_destination; char *service_parm; acc = GetInPtr( 0 ); ret = GetOutPtr( 0 ); parm = GetInPtr( sizeof( *acc ) ); /* * reset status variables */ LastExceptionCode = -1; DebugString = NULL; DebugeeEnded = FALSE; RemoveAllThreads(); FreeLibList(); DidWaitForDebugEvent = FALSE; DebugeePid = 0; DebugeeTid = 0; SupportingExactBreakpoints = 0; /* * check if pid is specified */ ParseServiceStuff( parm, &dll_name, &service_name, &dll_destination, &service_parm ); pid = 0; src = parm; /* // Just to be really safe! */ nBuffRequired = GetTotalSize() + PATH_MAX + 16; buff = LocalAlloc( LMEM_FIXED, nBuffRequired ); if( buff == NULL ) { ret->err = ERROR_NOT_ENOUGH_MEMORY; return( sizeof( *ret ) ); } if( *src == '#' ) { src++; pid = strtoul( src, &endsrc, 16 ); if( pid == 0 ) { pid = -1; } strcpy( buff, endsrc ); } else { while( isdigit( *src ) ) { src++; } if( *src == 0 && src != parm ) { pid = atoi( parm ); } } /* * get program to debug. If the user has specified a pid, then * skip directly to doing a DebugActiveProcess */ IsWOW = FALSE; #if !defined( MD_x64 ) IsDOS = FALSE; #endif if( pid == 0 ) { ret->err = FindProgFile( parm, exe_name, NtExtList ); if( ret->err != 0 ) { goto error_exit; } /* * Get type of application */ handle = CreateFile( (LPTSTR)exe_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0 ); if( handle == INVALID_HANDLE_VALUE ) { ret->err = GetLastError(); goto error_exit; } GetFullPathName( exe_name, MAX_PATH, CurrEXEName, NULL ); /* * get the parm list */ if( strchr( CurrEXEName, ' ' ) != NULL ) { strcpy( buff, "\"" ); strcat( buff, CurrEXEName ); strcat( buff, "\"" ); } else { strcpy( buff, CurrEXEName ); } dst = &buff[strlen( buff )]; src = parm; while( *src != 0 ) { ++src; } // parm layout // <--parameters-->0<--program_name-->0<--arguments-->0 // for( len = GetTotalSize() - sizeof( *acc ) - (src - parm) - 1; len > 0; --len ) { ch = *src; if( ch == 0 ) { ch = ' '; } *dst = ch; ++dst; ++src; } *dst = 0; cr_flags = DEBUG_ONLY_THIS_PROCESS; if( !GetEXEHeader( handle, &hi, &stack ) ) { ret->err = GetLastError(); CloseHandle( handle ); goto error_exit; } if( hi.sig == EXE_PE ) { if( IS_PE64( hi.u.peh ) ) { DebugeeSubsystem = PE64( hi.u.peh ).subsystem; } else { DebugeeSubsystem = PE32( hi.u.peh ).subsystem; #if defined( MD_x64 ) IsWOW = TRUE; #endif } if( DebugeeSubsystem == SS_WINDOWS_CHAR ) { cr_flags |= CREATE_NEW_CONSOLE; } #if !defined( MD_x64 ) } else if( hi.sig == EXE_NE ) { IsWOW = TRUE; /* * find out the pid of WOW, if it is already running. */ pVDMEnumProcessWOW( EnumWOWProcessFunc, (LPARAM)&pid ); if( pid != 0 ) { version = LOWORD( GetVersion() ); if( LOBYTE( version ) == 3 && HIBYTE( version ) < 50 ) { int kill = MessageBox( NULL, TRP_NT_wow_warning, TRP_The_WATCOM_Debugger, MB_APPLMODAL + MB_YESNO ); if( kill == IDYES ) { DWORD axs = PROCESS_TERMINATE+STANDARD_RIGHTS_REQUIRED; HANDLE hprocess = OpenProcess( axs, FALSE, pid ); if( hprocess != 0 && TerminateProcess( hprocess, 0 ) ) { CloseHandle( hprocess ); pid = 0; } } } else { cr_flags |= CREATE_SEPARATE_WOW_VDM; pid = 0; // always start a new VDM. } } if( pid != 0 ) { ret->err = GetLastError(); CloseHandle( handle ); goto error_exit; } } else { IsDOS = TRUE; #endif } CloseHandle( handle ); } /* * start the debugee */ pid_started = pid; if( *dll_name ) { strcat( buff, LOAD_PROG_STR_DELIM ); strcat( buff, LOAD_PROG_STR_DLLNAME ); strcat( buff, dll_name ); } if( *service_name ) { strcat( buff, LOAD_PROG_STR_DELIM ); strcat( buff, LOAD_PROG_STR_SERVICE ); strcat( buff, service_name ); } if( *dll_destination ) { strcat( buff, LOAD_PROG_STR_DELIM ); strcat( buff, LOAD_PROG_STR_COPYDIR ); strcat( buff, dll_destination ); } if( *service_parm ) { strcat( buff, LOAD_PROG_STR_DELIM ); strcat( buff, LOAD_PROG_STR_SERVICEPARM ); strcat( buff, service_parm ); } ret->err = StartControlThread( buff, &pid_started, cr_flags ); if( ret->err != 0 ) { goto error_exit; } /* * CREATE_PROCESS_DEBUG_EVENT will always be the first debug event. * If it is not, then something is horribly wrong. */ rc = MyWaitForDebugEvent(); if( !rc || ( DebugEvent.dwDebugEventCode != CREATE_PROCESS_DEBUG_EVENT ) || ( DebugEvent.dwProcessId != pid_started ) ) { ret->err = GetLastError(); goto error_exit; } ProcessInfo.pid = DebugEvent.dwProcessId; ProcessInfo.process_handle = DebugEvent.u.CreateProcessInfo.hProcess; ProcessInfo.base_addr = DebugEvent.u.CreateProcessInfo.lpBaseOfImage; AddProcess( &hi ); AddThread( DebugEvent.dwThreadId, DebugEvent.u.CreateProcessInfo.hThread, DebugEvent.u.CreateProcessInfo.lpStartAddress ); DebugeePid = DebugEvent.dwProcessId; DebugeeTid = DebugEvent.dwThreadId; LastDebugEventTid = DebugEvent.dwThreadId; #if defined( MD_x86 ) #ifdef WOW if( IsWOW ) { ret->flags = LD_FLAG_IS_PROT; ret->err = 0; ret->task_id = DebugeePid; /* * we use our own CS and DS as the Flat CS and DS, for lack * of anything better */ FlatDS = GetDS(); FlatCS = GetCS(); if( !executeUntilVDMStart() ) { ret->err = GetLastError(); goto error_exit; } if( pid ) { addAllWOWModules(); } else { addKERNEL(); } /* * we save the starting CS:IP of the WOW app, since we will use * it to force execution of code later */ ti = FindThread( DebugeeTid ); MyGetThreadContext( ti, &con ); WOWAppInfo.segment = ( WORD ) con.SegCs; WOWAppInfo.offset = ( WORD ) con.Eip; con.SegSs = con.SegDs; // Wow lies about the stack segment. Reset it con.Esp = stack; MySetThreadContext( ti, &con ); } else if( IsDOS ) { // TODO! Clean up this code ret->flags = 0; //LD_FLAG_IS_PROT; ret->err = 0; ret->task_id = DebugeePid; /* * we use our own CS and DS as the Flat CS and DS, for lack * of anything better */ FlatDS = GetDS(); FlatCS = GetCS(); if( !executeUntilVDMStart() ) { ret->err = GetLastError(); goto error_exit; } #if 0 if( pid ) { addAllWOWModules(); } else { addKERNEL(); } #endif /* * we save the starting CS:IP of the WOW app, since we will use * it to force execution of code later */ ti = FindThread( DebugeeTid ); MyGetThreadContext( ti, &con ); WOWAppInfo.segment = ( WORD )con.SegCs; WOWAppInfo.offset = ( WORD )con.Eip; con.SegSs = con.SegDs; // Wow lies about the stack segment. Reset it con.Esp = stack; MySetThreadContext( ti, &con ); } else { #else { #endif #else { #endif LPVOID base; if( pid == 0 ) { base = (LPVOID)DebugEvent.u.CreateProcessInfo.lpStartAddress; } else { base = 0; } ret->flags = LD_FLAG_IS_PROT; ret->err = 0; ret->task_id = DebugeePid; if( executeUntilStart( pid != 0 ) ) { LPVOID old; /* * make the application load our DLL, so that we can have it * run code out of it. One small note: this will not work right * if the app does not load our DLL at the same address the * debugger loaded it at!!! */ ti = FindThread( DebugeeTid ); MyGetThreadContext( ti, &con ); old = (LPVOID)AdjustIP( &con, 0 ); if( base != 0 ) { SetIP( &con, base ); } MySetThreadContext( ti, &con ); SetIP( &con, old ); MySetThreadContext( ti, &con ); } ti = FindThread( DebugeeTid ); MyGetThreadContext( ti, &con ); #if defined( MD_x86 ) FlatCS = con.SegCs; FlatDS = con.SegDs; #endif ret->flags |= LD_FLAG_IS_BIG; } ret->flags |= LD_FLAG_HAVE_RUNTIME_DLLS; if( pid != 0 ) { ret->flags |= LD_FLAG_IS_STARTED; } ret->mod_handle = 0; error_exit: if( buff != NULL ) { LocalFree( buff ); } return( sizeof( *ret ) ); } trap_retval ReqProg_kill( void ) { prog_kill_ret *ret; ret = GetOutPtr( 0 ); ret->err = 0; DelProcess( TRUE ); StopControlThread(); return( sizeof( *ret ) ); }
/** * @brief Takes a JsonDocument object and parses it as a Jplace document into a PlacementMap object. * * Returns true iff successful. */ bool JplaceProcessor::FromDocument (const JsonDocument& doc, PlacementMap& placements) { placements.clear(); // check if the version is correct JsonValue* val = doc.Get("version"); if (!val) { LOG_WARN << "Jplace document does not contain a valid version number at key 'version'." << "Now continuing to parse in the hope that it still works."; } if (!CheckVersion(val->ToString())) { LOG_WARN << "Jplace document has version '" << val->ToString() << "', however this parser " << "is written for version " << GetVersion() << " of the Jplace format. " << "Now continuing to parse in the hope that it still works."; } // find and process the reference tree val = doc.Get("tree"); if (!val || !val->IsString() || !NewickProcessor::FromString(val->ToString(), placements.tree)) { LOG_WARN << "Jplace document does not contain a valid Newick tree at key 'tree'."; return false; } // create a map from edge nums to the actual edge pointers, for later use when processing // the pqueries. we do not use PlacementMap::EdgeNumMap() here, because we need to do extra // checking for validity first! std::unordered_map<int, PlacementTree::EdgeType*> edge_num_map; for ( PlacementTree::ConstIteratorEdges it = placements.tree.BeginEdges(); it != placements.tree.EndEdges(); ++it ) { PlacementTree::EdgeType* edge = *it; if (edge_num_map.count(edge->edge_num) > 0) { LOG_WARN << "Jplace document contains a tree where the edge num tag '" << edge->edge_num << "' is used more than once."; return false; } edge_num_map.emplace(edge->edge_num, edge); } // get the field names and store them in array fields val = doc.Get("fields"); if (!val || !val->IsArray()) { LOG_WARN << "Jplace document does not contain field names at key 'fields'."; return false; } JsonValueArray* fields_arr = JsonValueToArray(val); std::vector<std::string> fields; bool has_edge_num = false; for (JsonValue* fields_val : *fields_arr) { if (!fields_val->IsString()) { LOG_WARN << "Jplace document contains a value of type '" << fields_val->TypeToString() << "' instead of a string with a field name at key 'fields'."; return false; } // check field validity std::string field = fields_val->ToString(); if (field == "edge_num" || field == "likelihood" || field == "like_weight_ratio" || field == "distal_length" || field == "pendant_length" || field == "parsimony" ) { for (std::string fn : fields) { if (fn == field) { LOG_WARN << "Jplace document contains field name '" << field << "' more than " << "once at key 'fields'."; return false; } } fields.push_back(field); } else { LOG_WARN << "Jplace document contains a field name '" << field << "' " << "at key 'fields', which is not used by this parser and thus skipped."; } has_edge_num |= (field == "edge_num"); } if (!has_edge_num) { LOG_WARN << "Jplace document does not contain necessary field 'edge_num' at key 'fields'."; return false; } // find and process the pqueries val = doc.Get("placements"); if (!val || !val->IsArray()) { LOG_WARN << "Jplace document does not contain pqueries at key 'placements'."; return false; } JsonValueArray* placements_arr = JsonValueToArray(val); for (JsonValue* pqry_val : *placements_arr) { if (!pqry_val->IsObject()) { LOG_WARN << "Jplace document contains a value of type '" << pqry_val->TypeToString() << "' instead of an object with a pquery at key 'placements'."; return false; } JsonValueObject* pqry_obj = JsonValueToObject(pqry_val); if (!pqry_obj->Has("p") || !pqry_obj->Get("p")->IsArray()) { LOG_WARN << "Jplace document contains a pquery at key 'placements' that does not " << "contain an array of placements at sub-key 'p'."; return false; } // create new pquery Pquery* pqry = new Pquery(); // process the placements and store them in the pquery JsonValueArray* pqry_p_arr = JsonValueToArray(pqry_obj->Get("p")); for (JsonValue* pqry_p_val : *pqry_p_arr) { if (!pqry_p_val->IsArray()) { LOG_WARN << "Jplace document contains a pquery with invalid placement at key 'p'."; return false; } JsonValueArray* pqry_fields = JsonValueToArray(pqry_p_val); if (pqry_fields->size() != fields.size()) { LOG_WARN << "Jplace document contains a placement fields array with different size " << "than the fields name array."; return false; } // process all fields of the placement PqueryPlacement* pqry_place = new PqueryPlacement(); for (size_t i = 0; i < pqry_fields->size(); ++i) { // up to version 3 of the jplace specification, the p-fields in a jplace document // only contain numbers (float or int),so we can do this check here once for all // fields, instead of repetition for everyfield. if in the future there are fields // with non-number type, this check has to go into the single field assignments. if (!pqry_fields->at(i)->IsNumber()) { LOG_WARN << "Jplace document contains pquery where field " << fields[i] << " is of type '" << pqry_fields->at(i)->TypeToString() << "' instead of a number."; return false; } // switch on the field name to set the correct value double pqry_place_val = JsonValueToNumber(pqry_fields->at(i))->value; if (fields[i] == "edge_num") { pqry_place->edge_num = pqry_place_val; if (edge_num_map.count(pqry_place_val) == 0) { LOG_WARN << "Jplace document contains a pquery where field 'edge_num' " << "has value '" << pqry_place_val << "', which is not marked " << "in the given tree as an edge num."; return false; } pqry_place->edge = edge_num_map.at(pqry_place_val); pqry_place->edge->placements.push_back(pqry_place); } else if (fields[i] == "likelihood") { pqry_place->likelihood = pqry_place_val; } else if (fields[i] == "like_weight_ratio") { pqry_place->like_weight_ratio = pqry_place_val; } else if (fields[i] == "distal_length") { // the jplace format uses distal length, but we use proximal, // so we need to convert here. pqry_place->proximal_length = pqry_place->edge->branch_length - pqry_place_val; } else if (fields[i] == "pendant_length") { pqry_place->pendant_length = pqry_place_val; } else if (fields[i] == "parsimony") { pqry_place->parsimony = pqry_place_val; } } pqry_place->pquery = pqry; pqry->placements.push_back(pqry_place); } // check name/named multiplicity validity if (pqry_obj->Has("n") && pqry_obj->Has("nm")) { LOG_WARN << "Jplace document contains a pquery with both an 'n' and an 'nm' key."; return false; } if (!pqry_obj->Has("n") && !pqry_obj->Has("nm")) { LOG_WARN << "Jplace document contains a pquery with neither an 'n' nor an 'nm' key."; return false; } // process names if (pqry_obj->Has("n")) { if (!pqry_obj->Get("n")->IsArray()) { LOG_WARN << "Jplace document contains a pquery with key 'n' that is not array."; return false; } JsonValueArray* pqry_n_arr = JsonValueToArray(pqry_obj->Get("n")); for (JsonValue* pqry_n_val : *pqry_n_arr) { if (!pqry_n_val->IsString()) { LOG_WARN << "Jplace document contains a pquery where key 'n' has a " << "non-string field."; return false; } PqueryName* pqry_name = new PqueryName(); pqry_name->name = pqry_n_val->ToString(); pqry_name->multiplicity = 0.0; pqry_name->pquery = pqry; pqry->names.push_back(pqry_name); } } // process named multiplicities if (pqry_obj->Has("nm")) { if (!pqry_obj->Get("nm")->IsArray()) { LOG_WARN << "Jplace document contains a pquery with key 'nm' that is not array."; return false; } JsonValueArray* pqry_nm_arr = JsonValueToArray(pqry_obj->Get("nm")); for (JsonValue* pqry_nm_val : *pqry_nm_arr) { if (!pqry_nm_val->IsArray()) { LOG_WARN << "Jplace document contains a pquery where key 'nm' has a " << "non-array field."; return false; } JsonValueArray * pqry_nm_val_arr = JsonValueToArray(pqry_nm_val); if (pqry_nm_val_arr->size() != 2) { LOG_WARN << "Jplace document contains a pquery where key 'nm' has an array " << "field with size != 2 (one for the name, one for the multiplicity)."; return false; } if (!pqry_nm_val_arr->at(0)->IsString()) { LOG_WARN << "Jplace document contains a pquery where key 'nm' has an array " << "whose first value is not a string for the name."; return false; } if (!pqry_nm_val_arr->at(1)->IsNumber()) { LOG_WARN << "Jplace document contains a pquery where key 'nm' has an array " << "whose second value is not a number for the multiplicity."; return false; } PqueryName* pqry_name = new PqueryName(); pqry_name->name = pqry_nm_val_arr->at(0)->ToString(); pqry_name->multiplicity = JsonValueToNumber(pqry_nm_val_arr->at(1))->value; if (pqry_name->multiplicity < 0.0) { LOG_WARN << "Jplace document contains pquery with negative multiplicity at " << "name '" << pqry_name->name << "'."; } pqry_name->pquery = pqry; pqry->names.push_back(pqry_name); } } // finally, add the pquery to the placements object placements.pqueries.push_back(pqry); } // check if there is metadata val = doc.Get("metadata"); if (val && val->IsObject()) { JsonValueObject* meta_obj = JsonValueToObject(val); for (JsonValueObject::ObjectPair meta_pair : *meta_obj) { placements.metadata[meta_pair.first] = meta_pair.second->ToString(); } } return true; }
CString GetHddDriveInfo() { int index=0; float fTotalSize=0; HANDLE hDevice; CString Result; CString HardDisk; DWORD junk; DISK_GEOMETRY pdg; BOOL bWin9X = FALSE; if (GetVersion() >= 0x80000000) { bWin9X = TRUE; } HardDisk.Format("\\\\.\\PhysicalDrive%d",index); hDevice=CreateFile(HardDisk,0,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL); if (hDevice==INVALID_HANDLE_VALUE) Result=="Error: Can not Query Hard Disk Drives."; while (hDevice!=INVALID_HANDLE_VALUE) { BOOL bResult=DeviceIoControl(hDevice,IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL,0, &pdg,sizeof(DISK_GEOMETRY), &junk, (LPOVERLAPPED) NULL); if (bResult) { CString Temp; Temp.Format("Hard Disk Drive %d : ",index+1); Result+=Temp; double DiskSize=pdg.Cylinders.QuadPart * pdg.TracksPerCylinder * pdg.SectorsPerTrack * pdg.BytesPerSector/1024/1024/1024.0; Temp.Format("%.2f GB\n", DiskSize); Result+=Temp; // fTotalSize += atof(Temp); } CloseHandle(hDevice); index++; HardDisk.Format("\\\\.\\PhysicalDrive%d",index); hDevice=CreateFile(HardDisk,0,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL); } double dTotalSize = 0, dTotalFree = 0; ULARGE_INTEGER AvailableToCaller, Disk, Free; for (int iCounter=0; iCounter < MAX_OF_HARD_DISKS; iCounter++) { if (GetDriveType(HardDiskLetters[iCounter])==DRIVE_FIXED) { if (GetDiskFreeSpaceEx(HardDiskLetters[iCounter],&AvailableToCaller,&Disk,&Free)) { CString Temp; // Temp.Format("*** Hard Disk: (%s) ***\r\n",HardDiskLetters[iCounter]); // Result+=Temp; // Temp.Format("Total size: %I64d (MB)\r\n",Disk.QuadPart/1024/1024); // Result+=Temp; // ULONGLONG Used=Disk.QuadPart-Free.QuadPart; // Temp.Format("Used: %I64d (MB)\r\n",Used/1024/1024); // Result+=Temp; // Temp.Format("Free: %I64d (MB)\r\n\r\n",Free.QuadPart/1024/1024); // Result+=Temp; dTotalSize += (INT64)(Disk.QuadPart); dTotalFree += (INT64)(Free.QuadPart); if (bWin9X) { Temp.Format("Hard Disk Drive %d : %.2f GB\n", iCounter+1, dTotalSize/1024/1024/1024.0); Result += Temp; } } } } dTotalSize = dTotalSize/1024/1024/1024.0; dTotalFree = dTotalFree/1024/1024/1024.0; // CString Temp; // Temp.Format("Number of Hard Disk Drives: %d\n",index); CString strTotalSize, strTotalFree; strTotalSize.Format("%.2f Gigabytes Usable Hard Drive Capacity\n", dTotalSize/*fTotalSize*/); strTotalFree.Format("%.2f Gigabytes Hard Drive Free Space\n", dTotalFree); Result=strTotalSize+strTotalFree+Result; return Result + "\n"; }