bool CInstallerHandler::DumpSoftware(tagInstaller & itl, LPCTSTR szKey, HKEY hParent) { LRESULT lr; HKEY hKey; LONG size; TCHAR buffer[MAX_PATH]; lr = RegOpenKey(hParent, szKey, &hKey);
if (lr != ERROR_SUCCESS) { logger::record() << "Cannot open key"; return false; }
size = sizeof(buffer); lr = GetValue(hKey, _T("DisplayName"), &buffer[0], &size); if (lr == ERROR_SUCCESS) { if (size > 0) { itl.name = buffer; }
} else { size = sizeof(buffer); lr = GetValue(hKey, _T("QuietDisplayName"), &buffer[0], &size); if (ERROR_SUCCESS == lr && size > 0) { itl.name = buffer; }
}
if (itl.name.empty()) { RegCloseKey(hKey); return false; }
size = sizeof(buffer); lr = GetValue(hKey, _T("SystemComponent"), &buffer[0], &size); if (lr == ERROR_SUCCESS) { if (buffer>0){ return false; }
} size = sizeof(buffer); lr = GetValue(hKey, _T("ParentKeyName"), &buffer[0], &size); if (lr == ERROR_SUCCESS) { if (buffer>0){ return false; }
}
size = sizeof(buffer); lr = GetValue(hKey, _T("InstallLocation"), &buffer[0], &size); if (ERROR_SUCCESS == lr && size > 0) { itl.install_path = buffer; itl.install_path = CStringUtil::StringToUTF8(itl.install_path); } else { lr = GetValue(hKey, _T("DisplayIcon"), &buffer[0], &size); if (ERROR_SUCCESS == lr && size > 0) { itl.install_path = buffer; itl.install_path=StringProcess(itl.install_path); itl.install_path = CStringUtil::StringToUTF8(itl.install_path); } else { lr = GetValue(hKey, _T("UninstallString"), &buffer[0], &size); if (ERROR_SUCCESS == lr && size > 0) { itl.install_path = buffer; itl.install_path = StringProcess(itl.install_path); itl.install_path = CStringUtil::StringToUTF8(itl.install_path); } } }
DWORD dwValue, dwType; DWORD dwBufLen = 255; std::string install_data; if (RegQueryValueEx(hKey, _T("InstallDate"), NULL, &dwType, (LPBYTE)&buffer, &dwBufLen) == ERROR_SUCCESS) { if (dwType == 4){ DWORD dwSize = 0; lr = GetDword(hKey, _T("InstallDate"), dwSize); if (ERROR_SUCCESS == lr){ time_t t = dwSize; auto p = gmtime(&t); char s[80]; strftime(s, 80, "%Y-%m-%d %H:%M:%S", p); itl.install_data = s; } } else{ size = sizeof(buffer); lr = GetValue(hKey, _T("InstallDate"), &buffer[0], &size);
if (ERROR_SUCCESS == lr && size > 0) { itl.install_data = buffer;
if (itl.install_data.length() == 8){ std::string temp = itl.install_data.substr(0, 4); temp.append("-"); temp.append(itl.install_data.substr(4, 2)); temp.append("-"); temp.append(itl.install_data.substr(6, 2)); temp.append(" 00:00:00"); itl.install_data = temp; } else{ itl.install_data = ""; } } else itl.install_data = ""; } }
DWORD dwSize = 0; lr = GetDword(hKey, _T("EstimatedSize"), dwSize); if (ERROR_SUCCESS == lr && size > 0) { auto temp = dwSize / 1024; char buf[64] = {0}; _itoa_s(temp, buf, sizeof(buf), 10); itl.package_size = buf; }
size = sizeof(buffer); lr = GetValue(hKey, _T("DisplayVersion"), &buffer[0], &size); if (ERROR_SUCCESS == lr && size > 0) { itl.version = buffer; }
size = sizeof(buffer); lr = GetValue(hKey, _T("Publisher"), &buffer[0], &size); if (ERROR_SUCCESS == lr && size > 0) {
itl.publisher = buffer; itl.publisher = CStringUtil::StringToUTF8(itl.publisher); }
itl.name = CStringUtil::StringToUTF8(itl.name);
RegCloseKey(hKey);
return true;
}
|