void versionManager::getMainModuleVersion(VMMAPDEF& mapVersion) { std::string strVersion = ""; TCHAR szBankPath[1000]; _tcscpy_s(szBankPath, getModulePath().c_str()); _tcscat_s(szBankPath, _T("\\MoneyHub.exe")); CFileVersionInfo vinfo; if (vinfo.Create(szBankPath)) { tstring strFileVersion = vinfo.GetFileVersion(); replace(strFileVersion.begin(), strFileVersion.end(), ',', '.'); strFileVersion.erase(remove(strFileVersion.begin(), strFileVersion.end(), ' '), strFileVersion.end()); strVersion = std::string(CT2A(strFileVersion.c_str(), 936)); } else return ; USES_CONVERSION; if(m_bEnName) mapVersion.insert(std::make_pair(L"Main",A2W(strVersion.c_str()) ) ); else { VMMAPDEF::iterator it = m_mapEnChName.find(L"Main"); if( it != m_mapEnChName.end() ) mapVersion.insert(std::make_pair(it->second.c_str(), A2W(strVersion.c_str()) ) ); } }
BOOL CAboutDlg::OnInitDialog() { CDialog::OnInitDialog(); // Initialize version class CFileVersionInfo fv; CString szRes; fv.Create(); // Set the dialog title szRes = "About "; szRes += fv.GetProductName (); this->SetWindowText(szRes); // Get the application version szRes = fv.GetProductVersion(); this->SetDlgItemText (IDC_VERSION, szRes); // Create the copyright line szRes = fv.GetLegalCopyright(); szRes += _T(" "); szRes += fv.GetCompanyName(); this->SetDlgItemText (IDC_COPYRIGHT, szRes); // Set the remaining controls text with the remaining version information this->SetDlgItemText (IDC_APPNAME, fv.GetProductName ()); this->SetDlgItemText (IDC_DESCR, fv.GetFileDescription()); return TRUE; // return TRUE unless you set the focus to a control }
// copy constructor CFileVersionInfo::CFileVersionInfo(const CFileVersionInfo& fvi) { CString strFile = fvi.GetFilename(); if (!strFile.IsEmpty()) { ReadVersionInfo(strFile); } else { m_pVersionInfo = NULL; Clear(); // initialize all to zero } }
/****************************************************************************** GetExeVersion ******************************************************************************/ QString CComponentInfo::GetExeVersion( const QString& sPath) { #ifdef WIN32 CFileVersionInfo fvi; if (!fvi.Create(qPrintable(sPath))) { return ""; } return QString::fromStdString(fvi.GetFileVersion()); #else // !WIN32 Q_UNUSED( sPath ) LOG(2, "GetExeVersion called on non-Windows, returning empty string\n"); return ""; #endif // WIN32 }
LRESULT CAboutDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { m_hBitmapLogo = ::LoadBitmap(_AtlModule.GetResourceInstance(), MAKEINTRESOURCE(IDB_BITMAP_LOGO)); if (m_hBitmapLogo) { GetDlgItem(IDC_STATIC_LOGO).SendMessage(STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)m_hBitmapLogo); BITMAP bmp; GetObject(m_hBitmapLogo, sizeof(BITMAP), &bmp); CRect r, r1; GetDlgItem(IDC_STATIC_NAME).GetWindowRect(r1); ScreenToClient(r1); GetDlgItem(IDC_STATIC_LOGO).GetWindowRect(r); ScreenToClient(r); int Offset = r1.left - r.right - 2; GetWindowRect(r); GetParent().ScreenToClient(r); r.right += Offset; MoveWindow(r); } CFileVersionInfo info; if (info.Open(_AtlModule.GetResourceInstance())) { CString NameProduct; info.QueryStringValue(_T("ProductName"), NameProduct.GetBuffer(255), 255); NameProduct.ReleaseBuffer(); CString VersionNumber; VersionNumber.Format(_T("%s %d.%d.%d.%d"), NameProduct, info.GetProductVersionMajor(), info.GetFileVersionMinor(), info.GetProductVersionBuild(), info.GetProductVersionQFE()); SetDlgItemText(IDC_STATIC_NAME, VersionNumber); info.Close(); } CString Depenednces; Depenednces.LoadString(IDS_DEPENDENCES); SetDlgItemText(IDC_EDIT_DEPENDENCES, Depenednces); m_DonateLink.SubclassWindow(GetDlgItem(IDC_STATIC_DONATE)); m_DonateLink.SetHyperLink(_T("http://salos.narod.ru/eng/donate.html")); bool bREs= m_DonateLink.IsUsingToolTip(); return TRUE; }
void *MuninNodeClient::Entry() { int ret = 0; static const int BUFFER_SIZE = 8096; char buffer[BUFFER_SIZE] = {0}; char hostname[64] = {0}; int len = 0; ret = gethostname(hostname, 64); if (ret) { _Module.LogEvent("Failed to get hostname!"); } ret = _snprintf(buffer, BUFFER_SIZE, "# munin node at %s\n", hostname); // we simply send this string to the client ret = SendLine(buffer); while (!TestDestroy()) { // Now wait for a reply ret = RecvLine(buffer, BUFFER_SIZE); if (ret == -1) { // Recieve error, connection reset? break; } // Remove newlines char *buffer2 = strstr(buffer, "\n"); if (buffer2 != NULL) { *buffer2 = NULL; } buffer2 = strstr(buffer, "\r"); if (buffer2 != NULL) { *buffer2 = NULL; } if (strstr(buffer, "quit") == buffer) { break; } else if (strstr(buffer, "version") == buffer) { // Read in Version Infomation CFileVersionInfo ver; ver.Open(GetModuleHandle(NULL)); ret = _snprintf(buffer, BUFFER_SIZE, "munin node on %s version: Munin Node for Windows %i.%i.%i\n", hostname, ver.GetFileVersionMajor(), ver.GetFileVersionMinor(), ver.GetFileVersionQFE()); ret = SendLine(buffer); } else if (strstr(buffer, "nodes") == buffer) { // This version only supports one node ret = _snprintf(buffer, BUFFER_SIZE, "%s\n.\n", hostname); ret = SendLine(buffer); } else if (strstr(buffer, "list") == buffer) { memset(buffer, 0, BUFFER_SIZE); m_PluginManager->FillPluginList(buffer, BUFFER_SIZE); ret = SendLine(buffer); } else if (strstr(buffer, "config") == buffer) { MuninNodePlugin *plugin = m_PluginManager->LookupPlugin(buffer); if (plugin != NULL) { memset(buffer, 0, BUFFER_SIZE); ret = plugin->GetConfig(buffer, BUFFER_SIZE); if (ret < 0) { ret = SendLine("# Unknown Error\n.\n"); } else { ret = SendLine(buffer); } } else { ret = SendLine("# Unknown service\n.\n"); } } else if (strstr(buffer, "fetch") == buffer) { MuninNodePlugin *plugin = m_PluginManager->LookupPlugin(buffer); if (plugin != NULL) { memset(buffer, 0, BUFFER_SIZE); ret = plugin->GetValues(buffer, BUFFER_SIZE); if (ret < 0) { ret = SendLine("# Unknown Error\n.\n"); } else { ret = SendLine(buffer); } } else { ret = SendLine("# Unknown service\n.\n"); } } else { ret = SendLine("# Unknown command. Try list, nodes, config, fetch, version or quit\n"); } } return 0; }
HRESULT STDAPICALLTYPE DllGetVersion( IN HMODULE hModule, OUT DLLVERSIONINFO* lpDVI ) { if( hModule == NULL || ::IsBadReadPtr( lpDVI, sizeof( DLLVERSIONINFO* ) ) ) { ASSERT_RETURN( S_FALSE ); } CONST DWORD cbSize = lpDVI->cbSize; if( #ifdef DLLVERSIONINFO2 ( #endif cbSize != sizeof( DLLVERSIONINFO ) #ifdef DLLVERSIONINFO2 && cbSize != sizeof( DLLVERSIONINFO2 ) ) #endif || ::IsBadWritePtr( lpDVI, cbSize ) ) { ASSERT_RETURN( S_FALSE ); } ::ZeroMemory( lpDVI, cbSize ); lpDVI->cbSize = cbSize; CFileVersionInfo fvi; if( fvi.Open( hModule ) ) { VS_FIXEDFILEINFO vsffi = fvi.GetVSFFI(); if( vsffi.dwFileType == VFT_DLL || vsffi.dwFileType == VFT_STATIC_LIB ) { switch( vsffi.dwFileOS ) { case VOS__WINDOWS32: case VOS_NT_WINDOWS32: lpDVI->dwPlatformID = DLLVER_PLATFORM_WINDOWS; break; case VOS_NT: lpDVI->dwPlatformID = DLLVER_PLATFORM_NT; break; default: return ( S_FALSE ); } lpDVI->dwMajorVersion = HIWORD( vsffi.dwFileVersionMS ); lpDVI->dwMinorVersion = LOWORD( vsffi.dwFileVersionMS ); lpDVI->dwBuildNumber = HIWORD( vsffi.dwFileVersionLS ); #ifdef DLLVERSIONINFO2 if( cbSize == sizeof( DLLVERSIONINFO2 ) ) { DLLVERSIONINFO2* lpDVI2 = (DLLVERSIONINFO2*)lpDVI; lpDVI2->ullVersion = MAKEDLLVERULL( lpDVI->dwMajorVersion, lpDVI->dwMinorVersion, lpDVI->dwBuildNumber , LOWORD( vsffi.dwFileVersionLS ) ); } #endif return ( S_OK ); } #ifdef _DEBUG else ASSERT( 0 ); #endif fvi.Close(); } return ( S_FALSE ); }
int main(int argc, char* argv[]) { #ifdef _DEBUG // Setup the debug options _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF //Check for memory leaks on app exit );//| _CRTDBG_CHECK_ALWAYS_DF); _CrtSetAllocHook(YourAllocHook); #endif // Read in Version Infomation CFileVersionInfo ver; ver.Open(GetModuleHandle(NULL)); TCHAR displayName[256]; _sntprintf(displayName, 255, _T("Munin Node for Windows %i.%i.%i"), ver.GetFileVersionMajor(), ver.GetFileVersionMinor(), ver.GetFileVersionQFE()); // Load Configuration // Get the executable file path char szConfigFilePath[MAX_PATH]; ::GetModuleFileNameA(NULL, szConfigFilePath, MAX_PATH); PathRemoveFileSpecA(szConfigFilePath); PathAppendA(szConfigFilePath, "\\munin-node.ini"); g_Config.SetPath(szConfigFilePath); g_Config.ReadFile(); // Prepare Service modules _Module.Init(_T("munin-node"), _T("Munin Node for Windows")); _Module.m_bService = TRUE; // Parse arguments if (argc > 1) { char seps[] = "-/"; char *pToken; pToken = strtok(argv[1], seps); while (pToken) { if (!stricmp(pToken, "install")) { return !_Module.Install(); } else if (!stricmp(pToken, "uninstall")) { return !_Module.Uninstall(); } else if (!stricmp(pToken, "quiet")) { FreeConsole(); } else if (!stricmp(pToken, "unattended")) { _Module.SetQuiet(true); } else if (!stricmp(pToken, "run")) { _Module.m_bService = FALSE; } else if (!stricmp(pToken, "help") || !stricmp(pToken, "h") || !stricmp(pToken, "?")) { printf("%s\n", _Module.GetServiceDisplayName()); printf("Usage:\n"); printf(" -install Install the 'Munin Node' service.\n"); printf(" -uninstall Removes the 'Munin Node' service.\n"); printf(" -quiet Close the console window, running in the background.\n"); printf(" -run Run as a normal program, rather than a service.\n"); return 1; } pToken = strtok(NULL, seps); } } _Module.Start(); return 0; }
VOID CFileDefExt::InitOpensWithField(HWND hwndDlg) { WCHAR wszBuf[MAX_PATH] = L""; WCHAR wszPath[MAX_PATH] = L""; DWORD dwSize = sizeof(wszBuf); BOOL bUnknownApp = TRUE; LPCWSTR pwszExt = PathFindExtensionW(m_wszPath); if (RegGetValueW(HKEY_CLASSES_ROOT, pwszExt, L"", RRF_RT_REG_SZ, NULL, wszBuf, &dwSize) == ERROR_SUCCESS) { bUnknownApp = FALSE; StringCbCatW(wszBuf, sizeof(wszBuf), L"\\shell\\open\\command"); dwSize = sizeof(wszPath); if (RegGetValueW(HKEY_CLASSES_ROOT, wszBuf, L"", RRF_RT_REG_SZ, NULL, wszPath, &dwSize) == ERROR_SUCCESS) { /* Get path from command line */ ExpandEnvironmentStringsW(wszPath, wszBuf, _countof(wszBuf)); PathRemoveArgs(wszBuf); PathUnquoteSpacesW(wszBuf); PathSearchAndQualify(wszBuf, wszPath, _countof(wszPath)); HICON hIcon; if (ExtractIconExW(wszPath, 0, NULL, &hIcon, 1)) { HWND hIconCtrl = GetDlgItem(hwndDlg, 14025); HWND hDescrCtrl = GetDlgItem(hwndDlg, 14007); ShowWindow(hIconCtrl, SW_SHOW); RECT rcIcon, rcDescr; GetWindowRect(hIconCtrl, &rcIcon); if (rcIcon.left == rcIcon.right) ERR("Icon control has invalid width: %d-%d\n", rcIcon.left, rcIcon.right); MapWindowPoints(NULL, hwndDlg, (LPPOINT)&rcIcon, 2); GetWindowRect(hDescrCtrl, &rcDescr); MapWindowPoints(NULL, hwndDlg, (LPPOINT)&rcDescr, 2); INT cxOffset = rcIcon.right + 2 - rcDescr.left; SetWindowPos(hDescrCtrl, NULL, rcDescr.left + cxOffset, rcDescr.top, rcDescr.right - rcDescr.left - cxOffset, rcDescr.bottom - rcDescr.top, SWP_NOZORDER); SendMessageW(hIconCtrl, STM_SETICON, (WPARAM)hIcon, 0); } else ERR("Failed to extract icon\n"); if (PathFileExistsW(wszPath)) { /* Get file description */ CFileVersionInfo VerInfo; VerInfo.Load(wszPath); LPCWSTR pwszDescr = VerInfo.GetString(L"FileDescription"); if (pwszDescr) SetDlgItemTextW(hwndDlg, 14007, pwszDescr); else { /* File has no description - display filename */ LPWSTR pwszFilename = PathFindFileNameW(wszPath); PathRemoveExtension(pwszFilename); pwszFilename[0] = towupper(pwszFilename[0]); SetDlgItemTextW(hwndDlg, 14007, pwszFilename); } } else bUnknownApp = TRUE; } else WARN("RegGetValueW %ls failed\n", wszBuf); } else WARN("RegGetValueW %ls failed\n", pwszExt); if (bUnknownApp) { /* Unknown application */ LoadStringW(shell32_hInstance, IDS_UNKNOWN_APP, wszBuf, _countof(wszBuf)); SetDlgItemTextW(hwndDlg, 14007, wszBuf); } }