2011-06-14 13:01:37 +00:00
|
|
|
/*
|
|
|
|
* DxDiag file information output
|
|
|
|
*
|
|
|
|
* Copyright 2011 Andrew Nguyen
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2011-06-14 13:02:18 +00:00
|
|
|
#define COBJMACROS
|
|
|
|
#include <initguid.h>
|
2011-06-14 13:02:12 +00:00
|
|
|
#include <windows.h>
|
2011-06-14 13:02:18 +00:00
|
|
|
#include <msxml2.h>
|
2011-06-14 13:01:37 +00:00
|
|
|
#include <assert.h>
|
2011-06-14 13:02:12 +00:00
|
|
|
#include <stdio.h>
|
2011-06-14 13:01:37 +00:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "dxdiag_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
|
|
|
|
|
2011-06-14 13:02:12 +00:00
|
|
|
static char output_buffer[1024];
|
|
|
|
static const char crlf[2] = "\r\n";
|
|
|
|
|
2011-06-15 12:11:11 +00:00
|
|
|
struct text_information_field
|
|
|
|
{
|
|
|
|
const char *field_name;
|
|
|
|
const WCHAR *value;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct xml_information_field
|
|
|
|
{
|
|
|
|
const WCHAR *tag_name;
|
|
|
|
const WCHAR *value;
|
|
|
|
};
|
|
|
|
|
2011-06-14 13:02:12 +00:00
|
|
|
static BOOL output_text_header(HANDLE hFile, const char *caption)
|
|
|
|
{
|
|
|
|
DWORD len = strlen(caption);
|
|
|
|
DWORD total_len = 3 * (len + sizeof(crlf));
|
|
|
|
char *ptr = output_buffer;
|
2014-07-12 08:40:12 +00:00
|
|
|
DWORD bytes_written;
|
2011-06-14 13:02:12 +00:00
|
|
|
|
|
|
|
assert(total_len <= sizeof(output_buffer));
|
|
|
|
|
|
|
|
memset(ptr, '-', len);
|
|
|
|
ptr += len;
|
|
|
|
|
|
|
|
memcpy(ptr, crlf, sizeof(crlf));
|
|
|
|
ptr += sizeof(crlf);
|
|
|
|
|
|
|
|
memcpy(ptr, caption, len);
|
|
|
|
ptr += len;
|
|
|
|
|
|
|
|
memcpy(ptr, crlf, sizeof(crlf));
|
|
|
|
ptr += sizeof(crlf);
|
|
|
|
|
|
|
|
memset(ptr, '-', len);
|
|
|
|
ptr += len;
|
|
|
|
|
|
|
|
memcpy(ptr, crlf, sizeof(crlf));
|
|
|
|
|
2014-07-12 08:40:12 +00:00
|
|
|
return WriteFile(hFile, output_buffer, total_len, &bytes_written, NULL);
|
2011-06-14 13:02:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL output_text_field(HANDLE hFile, const char *field_name, DWORD field_width, const WCHAR *value)
|
|
|
|
{
|
2019-04-29 09:52:43 +00:00
|
|
|
DWORD value_lenW = lstrlenW(value);
|
2011-06-14 13:02:12 +00:00
|
|
|
DWORD value_lenA = WideCharToMultiByte(CP_ACP, 0, value, value_lenW, NULL, 0, NULL, NULL);
|
|
|
|
DWORD total_len = field_width + sizeof(": ") - 1 + value_lenA + sizeof(crlf);
|
|
|
|
char sprintf_fmt[1 + 10 + 3 + 1];
|
|
|
|
char *ptr = output_buffer;
|
2014-07-12 08:40:12 +00:00
|
|
|
DWORD bytes_written;
|
2011-06-14 13:02:12 +00:00
|
|
|
|
|
|
|
assert(total_len <= sizeof(output_buffer));
|
|
|
|
|
2022-02-04 08:56:19 +00:00
|
|
|
sprintf(sprintf_fmt, "%%%lus: ", field_width);
|
2011-06-14 13:02:12 +00:00
|
|
|
ptr += sprintf(ptr, sprintf_fmt, field_name);
|
|
|
|
|
|
|
|
ptr += WideCharToMultiByte(CP_ACP, 0, value, value_lenW, ptr, value_lenA, NULL, NULL);
|
|
|
|
memcpy(ptr, crlf, sizeof(crlf));
|
|
|
|
|
2014-07-12 08:40:12 +00:00
|
|
|
return WriteFile(hFile, output_buffer, total_len, &bytes_written, NULL);
|
2011-06-14 13:02:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL output_crlf(HANDLE hFile)
|
|
|
|
{
|
2014-07-12 08:40:12 +00:00
|
|
|
DWORD bytes_written;
|
|
|
|
return WriteFile(hFile, crlf, sizeof(crlf), &bytes_written, NULL);
|
2011-06-14 13:02:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-15 12:11:11 +00:00
|
|
|
static inline void fill_system_text_output_table(struct dxdiag_information *dxdiag_info, struct text_information_field *fields)
|
|
|
|
{
|
|
|
|
fields[0].field_name = "Time of this report";
|
|
|
|
fields[0].value = dxdiag_info->system_info.szTimeEnglish;
|
|
|
|
fields[1].field_name = "Machine name";
|
|
|
|
fields[1].value = dxdiag_info->system_info.szMachineNameEnglish;
|
|
|
|
fields[2].field_name = "Operating System";
|
|
|
|
fields[2].value = dxdiag_info->system_info.szOSExLongEnglish;
|
|
|
|
fields[3].field_name = "Language";
|
|
|
|
fields[3].value = dxdiag_info->system_info.szLanguagesEnglish;
|
|
|
|
fields[4].field_name = "System Manufacturer";
|
|
|
|
fields[4].value = dxdiag_info->system_info.szSystemManufacturerEnglish;
|
|
|
|
fields[5].field_name = "System Model";
|
|
|
|
fields[5].value = dxdiag_info->system_info.szSystemModelEnglish;
|
|
|
|
fields[6].field_name = "BIOS";
|
|
|
|
fields[6].value = dxdiag_info->system_info.szBIOSEnglish;
|
|
|
|
fields[7].field_name = "Processor";
|
|
|
|
fields[7].value = dxdiag_info->system_info.szProcessorEnglish;
|
|
|
|
fields[8].field_name = "Memory";
|
|
|
|
fields[8].value = dxdiag_info->system_info.szPhysicalMemoryEnglish;
|
|
|
|
fields[9].field_name = "Page File";
|
|
|
|
fields[9].value = dxdiag_info->system_info.szPageFileEnglish;
|
|
|
|
fields[10].field_name = "Windows Dir";
|
|
|
|
fields[10].value = dxdiag_info->system_info.szWindowsDir;
|
|
|
|
fields[11].field_name = "DirectX Version";
|
|
|
|
fields[11].value = dxdiag_info->system_info.szDirectXVersionLongEnglish;
|
|
|
|
fields[12].field_name = "DX Setup Parameters";
|
|
|
|
fields[12].value = dxdiag_info->system_info.szSetupParamEnglish;
|
|
|
|
fields[13].field_name = "DxDiag Version";
|
|
|
|
fields[13].value = dxdiag_info->system_info.szDxDiagVersion;
|
|
|
|
}
|
|
|
|
|
2011-06-14 13:02:12 +00:00
|
|
|
static BOOL output_text_information(struct dxdiag_information *dxdiag_info, const WCHAR *filename)
|
|
|
|
{
|
2011-06-15 12:11:11 +00:00
|
|
|
struct information_block
|
2011-06-14 13:02:12 +00:00
|
|
|
{
|
|
|
|
const char *caption;
|
2011-06-15 12:11:11 +00:00
|
|
|
const size_t field_width;
|
|
|
|
struct text_information_field fields[50];
|
2011-06-14 13:02:12 +00:00
|
|
|
} output_table[] =
|
|
|
|
{
|
2011-06-15 12:11:11 +00:00
|
|
|
{"System Information", 19},
|
2011-06-14 13:02:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
HANDLE hFile;
|
|
|
|
size_t i;
|
|
|
|
|
2011-06-15 12:11:11 +00:00
|
|
|
fill_system_text_output_table(dxdiag_info, output_table[0].fields);
|
|
|
|
|
2011-06-14 13:02:12 +00:00
|
|
|
hFile = CreateFileW(filename, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2022-02-04 08:56:19 +00:00
|
|
|
WINE_ERR("File creation failed, last error %lu\n", GetLastError());
|
2011-06-14 13:02:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-08-21 21:10:19 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(output_table); i++)
|
2011-06-14 13:02:12 +00:00
|
|
|
{
|
2011-06-15 12:11:11 +00:00
|
|
|
const struct text_information_field *fields = output_table[i].fields;
|
2011-06-14 13:02:12 +00:00
|
|
|
unsigned int j;
|
|
|
|
|
|
|
|
output_text_header(hFile, output_table[i].caption);
|
|
|
|
for (j = 0; fields[j].field_name; j++)
|
|
|
|
output_text_field(hFile, fields[j].field_name, output_table[i].field_width, fields[j].value);
|
|
|
|
output_crlf(hFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(hFile);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-06-14 13:02:18 +00:00
|
|
|
static IXMLDOMElement *xml_create_element(IXMLDOMDocument *xmldoc, const WCHAR *name)
|
|
|
|
{
|
|
|
|
BSTR bstr = SysAllocString(name);
|
|
|
|
IXMLDOMElement *ret;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!bstr)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
hr = IXMLDOMDocument_createElement(xmldoc, bstr, &ret);
|
|
|
|
SysFreeString(bstr);
|
|
|
|
|
|
|
|
return SUCCEEDED(hr) ? ret : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT xml_put_element_text(IXMLDOMElement *element, const WCHAR *text)
|
|
|
|
{
|
|
|
|
BSTR bstr = SysAllocString(text);
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!bstr)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
hr = IXMLDOMElement_put_text(element, bstr);
|
|
|
|
SysFreeString(bstr);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT save_xml_document(IXMLDOMDocument *xmldoc, const WCHAR *filename)
|
|
|
|
{
|
|
|
|
BSTR bstr = SysAllocString(filename);
|
|
|
|
VARIANT destVar;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!bstr)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
V_VT(&destVar) = VT_BSTR;
|
|
|
|
V_BSTR(&destVar) = bstr;
|
|
|
|
|
|
|
|
hr = IXMLDOMDocument_save(xmldoc, destVar);
|
|
|
|
VariantClear(&destVar);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-06-15 12:11:11 +00:00
|
|
|
static inline void fill_system_xml_output_table(struct dxdiag_information *dxdiag_info, struct xml_information_field *fields)
|
2011-06-14 13:02:12 +00:00
|
|
|
{
|
2020-10-05 21:22:50 +00:00
|
|
|
fields[0].tag_name = L"Time";
|
2011-06-15 12:11:11 +00:00
|
|
|
fields[0].value = dxdiag_info->system_info.szTimeEnglish;
|
2020-10-05 21:22:50 +00:00
|
|
|
fields[1].tag_name = L"MachineName";
|
2011-06-15 12:11:11 +00:00
|
|
|
fields[1].value = dxdiag_info->system_info.szMachineNameEnglish;
|
2020-10-05 21:22:50 +00:00
|
|
|
fields[2].tag_name = L"OperatingSystem";
|
2011-06-15 12:11:11 +00:00
|
|
|
fields[2].value = dxdiag_info->system_info.szOSExLongEnglish;
|
2020-10-05 21:22:50 +00:00
|
|
|
fields[3].tag_name = L"Language";
|
2011-06-15 12:11:11 +00:00
|
|
|
fields[3].value = dxdiag_info->system_info.szLanguagesEnglish;
|
2020-10-05 21:22:50 +00:00
|
|
|
fields[4].tag_name = L"SystemManufacturer";
|
2011-06-15 12:11:11 +00:00
|
|
|
fields[4].value = dxdiag_info->system_info.szSystemManufacturerEnglish;
|
2020-10-05 21:22:50 +00:00
|
|
|
fields[5].tag_name = L"SystemModel";
|
2011-06-15 12:11:11 +00:00
|
|
|
fields[5].value = dxdiag_info->system_info.szSystemModelEnglish;
|
2020-10-05 21:22:50 +00:00
|
|
|
fields[6].tag_name = L"BIOS";
|
2011-06-15 12:11:11 +00:00
|
|
|
fields[6].value = dxdiag_info->system_info.szBIOSEnglish;
|
2020-10-05 21:22:50 +00:00
|
|
|
fields[7].tag_name = L"Processor";
|
2011-06-15 12:11:11 +00:00
|
|
|
fields[7].value = dxdiag_info->system_info.szProcessorEnglish;
|
2020-10-05 21:22:50 +00:00
|
|
|
fields[8].tag_name = L"Memory";
|
2011-06-15 12:11:11 +00:00
|
|
|
fields[8].value = dxdiag_info->system_info.szPhysicalMemoryEnglish;
|
2020-10-05 21:22:50 +00:00
|
|
|
fields[9].tag_name = L"PageFile";
|
2011-06-15 12:11:11 +00:00
|
|
|
fields[9].value = dxdiag_info->system_info.szPageFileEnglish;
|
2020-10-05 21:22:50 +00:00
|
|
|
fields[10].tag_name = L"WindowsDir";
|
2011-06-15 12:11:11 +00:00
|
|
|
fields[10].value = dxdiag_info->system_info.szWindowsDir;
|
2020-10-05 21:22:50 +00:00
|
|
|
fields[11].tag_name = L"DirectXVersion";
|
2011-06-15 12:11:11 +00:00
|
|
|
fields[11].value = dxdiag_info->system_info.szDirectXVersionLongEnglish;
|
2020-10-05 21:22:50 +00:00
|
|
|
fields[12].tag_name = L"DXSetupParameters";
|
2011-06-15 12:11:11 +00:00
|
|
|
fields[12].value = dxdiag_info->system_info.szSetupParamEnglish;
|
2020-10-05 21:22:50 +00:00
|
|
|
fields[13].tag_name = L"DxDiagVersion";
|
2011-06-15 12:11:11 +00:00
|
|
|
fields[13].value = dxdiag_info->system_info.szDxDiagVersion;
|
2020-10-05 21:22:50 +00:00
|
|
|
fields[14].tag_name = L"DxDiagUnicode";
|
|
|
|
fields[14].value = L"1";
|
|
|
|
fields[15].tag_name = L"DxDiag64Bit";
|
|
|
|
fields[15].value = dxdiag_info->system_info.win64 ? L"1" : L"0";
|
2011-06-15 12:11:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL output_xml_information(struct dxdiag_information *dxdiag_info, const WCHAR *filename)
|
|
|
|
{
|
|
|
|
struct information_block
|
2011-06-14 13:02:18 +00:00
|
|
|
{
|
|
|
|
const WCHAR *tag_name;
|
2011-06-15 12:11:11 +00:00
|
|
|
struct xml_information_field fields[50];
|
2011-06-14 13:02:18 +00:00
|
|
|
} output_table[] =
|
|
|
|
{
|
2020-10-05 21:22:50 +00:00
|
|
|
{L"SystemInformation"},
|
2011-06-14 13:02:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
IXMLDOMDocument *xmldoc = NULL;
|
|
|
|
IXMLDOMElement *dxdiag_element = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
size_t i;
|
|
|
|
|
2011-06-15 12:11:11 +00:00
|
|
|
fill_system_xml_output_table(dxdiag_info, output_table[0].fields);
|
|
|
|
|
2011-06-14 13:02:18 +00:00
|
|
|
hr = CoCreateInstance(&CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IXMLDOMDocument, (void **)&xmldoc);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-04 08:56:19 +00:00
|
|
|
WINE_ERR("IXMLDOMDocument instance creation failed with 0x%08lx\n", hr);
|
2011-06-14 13:02:18 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2020-10-05 21:22:50 +00:00
|
|
|
if (!(dxdiag_element = xml_create_element(xmldoc, L"DxDiag")))
|
2011-06-14 13:02:18 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
hr = IXMLDOMDocument_appendChild(xmldoc, (IXMLDOMNode *)dxdiag_element, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto error;
|
|
|
|
|
2018-08-21 21:10:19 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(output_table); i++)
|
2011-06-14 13:02:18 +00:00
|
|
|
{
|
|
|
|
IXMLDOMElement *info_element = xml_create_element(xmldoc, output_table[i].tag_name);
|
2011-06-15 12:11:11 +00:00
|
|
|
const struct xml_information_field *fields = output_table[i].fields;
|
2011-06-14 13:02:18 +00:00
|
|
|
unsigned int j = 0;
|
|
|
|
|
|
|
|
if (!info_element)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
hr = IXMLDOMElement_appendChild(dxdiag_element, (IXMLDOMNode *)info_element, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IXMLDOMElement_Release(info_element);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; fields[j].tag_name; j++)
|
|
|
|
{
|
|
|
|
IXMLDOMElement *field_element = xml_create_element(xmldoc, fields[j].tag_name);
|
|
|
|
|
|
|
|
if (!field_element)
|
|
|
|
{
|
|
|
|
IXMLDOMElement_Release(info_element);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = xml_put_element_text(field_element, fields[j].value);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IXMLDOMElement_Release(field_element);
|
|
|
|
IXMLDOMElement_Release(info_element);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IXMLDOMElement_appendChild(info_element, (IXMLDOMNode *)field_element, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IXMLDOMElement_Release(field_element);
|
|
|
|
IXMLDOMElement_Release(info_element);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
IXMLDOMElement_Release(field_element);
|
|
|
|
}
|
|
|
|
|
|
|
|
IXMLDOMElement_Release(info_element);
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = save_xml_document(xmldoc, filename);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
IXMLDOMElement_Release(dxdiag_element);
|
|
|
|
IXMLDOMDocument_Release(xmldoc);
|
|
|
|
return TRUE;
|
|
|
|
error:
|
|
|
|
if (dxdiag_element) IXMLDOMElement_Release(dxdiag_element);
|
|
|
|
if (xmldoc) IXMLDOMDocument_Release(xmldoc);
|
2011-06-14 13:02:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-06-14 13:01:37 +00:00
|
|
|
static struct output_backend
|
|
|
|
{
|
|
|
|
const WCHAR filename_ext[5];
|
2011-06-14 13:02:12 +00:00
|
|
|
BOOL (*output_handler)(struct dxdiag_information *, const WCHAR *filename);
|
2011-06-14 13:01:37 +00:00
|
|
|
} output_backends[] =
|
|
|
|
{
|
|
|
|
/* OUTPUT_TEXT */
|
|
|
|
{
|
2020-10-05 21:22:50 +00:00
|
|
|
L".txt", output_text_information,
|
2011-06-14 13:01:37 +00:00
|
|
|
},
|
|
|
|
/* OUTPUT_XML */
|
|
|
|
{
|
2020-10-05 21:22:50 +00:00
|
|
|
L".xml", output_xml_information,
|
2011-06-14 13:01:37 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const WCHAR *get_output_extension(enum output_type type)
|
|
|
|
{
|
2018-08-21 21:10:19 +00:00
|
|
|
assert(type > OUTPUT_NONE && type <= ARRAY_SIZE(output_backends));
|
2011-06-14 13:01:37 +00:00
|
|
|
|
|
|
|
return output_backends[type - 1].filename_ext;
|
|
|
|
}
|
|
|
|
|
2011-06-14 13:01:51 +00:00
|
|
|
BOOL output_dxdiag_information(struct dxdiag_information *dxdiag_info, const WCHAR *filename, enum output_type type)
|
2011-06-14 13:01:37 +00:00
|
|
|
{
|
2018-08-21 21:10:19 +00:00
|
|
|
assert(type > OUTPUT_NONE && type <= ARRAY_SIZE(output_backends));
|
2011-06-14 13:02:12 +00:00
|
|
|
|
|
|
|
return output_backends[type - 1].output_handler(dxdiag_info, filename);
|
2011-06-14 13:01:37 +00:00
|
|
|
}
|