information.c 10.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * DxDiag information collection
 *
 * 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
 */

21 22 23 24
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <dxdiag.h>

25
#include "wine/debug.h"
26
#include "wine/unicode.h"
27 28 29 30 31

#include "dxdiag_private.h"

WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
static const WCHAR szTimeEnglish[] = {'s','z','T','i','m','e','E','n','g','l','i','s','h',0};
static const WCHAR szTimeLocalized[] = {'s','z','T','i','m','e','L','o','c','a','l','i','z','e','d',0};
static const WCHAR szMachineNameEnglish[] = {'s','z','M','a','c','h','i','n','e','N','a','m','e','E','n','g','l','i','s','h',0};
static const WCHAR szOSExLongEnglish[] = {'s','z','O','S','E','x','L','o','n','g','E','n','g','l','i','s','h',0};
static const WCHAR szOSExLocalized[] = {'s','z','O','S','E','x','L','o','c','a','l','i','z','e','d',0};
static const WCHAR szLanguagesEnglish[] = {'s','z','L','a','n','g','u','a','g','e','s','E','n','g','l','i','s','h',0};
static const WCHAR szLanguagesLocalized[] = {'s','z','L','a','n','g','u','a','g','e','s','L','o','c','a','l','i','z','e','d',0};
static const WCHAR szSystemManufacturerEnglish[] = {'s','z','S','y','s','t','e','m','M','a','n','u','f','a','c','t','u','r','e','r','E','n','g','l','i','s','h',0};
static const WCHAR szSystemModelEnglish[] = {'s','z','S','y','s','t','e','m','M','o','d','e','l','E','n','g','l','i','s','h',0};
static const WCHAR szBIOSEnglish[] = {'s','z','B','I','O','S','E','n','g','l','i','s','h',0};
static const WCHAR szProcessorEnglish[] = {'s','z','P','r','o','c','e','s','s','o','r','E','n','g','l','i','s','h',0};
static const WCHAR szPhysicalMemoryEnglish[] = {'s','z','P','h','y','s','i','c','a','l','M','e','m','o','r','y','E','n','g','l','i','s','h',0};
static const WCHAR szPageFileEnglish[] = {'s','z','P','a','g','e','F','i','l','e','E','n','g','l','i','s','h',0};
static const WCHAR szPageFileLocalized[] = {'s','z','P','a','g','e','F','i','l','e','L','o','c','a','l','i','z','e','d',0};
static const WCHAR szWindowsDir[] = {'s','z','W','i','n','d','o','w','s','D','i','r',0};
static const WCHAR szDirectXVersionLongEnglish[] = {'s','z','D','i','r','e','c','t','X','V','e','r','s','i','o','n','L','o','n','g','E','n','g','l','i','s','h',0};
static const WCHAR szSetupParamEnglish[] = {'s','z','S','e','t','u','p','P','a','r','a','m','E','n','g','l','i','s','h',0};
static const WCHAR szDxDiagVersion[] = {'s','z','D','x','D','i','a','g','V','e','r','s','i','o','n',0};

struct property_list
{
    const WCHAR *property_name;
    WCHAR **output;
};

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
static BOOL property_to_string(IDxDiagContainer *container, const WCHAR *property, WCHAR **output)
{
    VARIANT var;
    HRESULT hr;
    BOOL ret = FALSE;

    VariantInit(&var);

    hr = IDxDiagContainer_GetProp(container, property, &var);
    if (SUCCEEDED(hr))
    {
        if (V_VT(&var) == VT_BSTR)
        {
            WCHAR *bstr = V_BSTR(&var);

            *output = HeapAlloc(GetProcessHeap(), 0, (strlenW(bstr) + 1) * sizeof(WCHAR));
            if (*output)
            {
                strcpyW(*output, bstr);
                ret = TRUE;
            }
        }
    }

    VariantClear(&var);
    return ret;
}

static void free_system_information(struct dxdiag_information *dxdiag_info)
{
    struct system_information *system_info = &dxdiag_info->system_info;
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

    HeapFree(GetProcessHeap(), 0, system_info->szTimeEnglish);
    HeapFree(GetProcessHeap(), 0, system_info->szTimeLocalized);
    HeapFree(GetProcessHeap(), 0, system_info->szMachineNameEnglish);
    HeapFree(GetProcessHeap(), 0, system_info->szOSExLongEnglish);
    HeapFree(GetProcessHeap(), 0, system_info->szOSExLocalized);
    HeapFree(GetProcessHeap(), 0, system_info->szLanguagesEnglish);
    HeapFree(GetProcessHeap(), 0, system_info->szLanguagesLocalized);
    HeapFree(GetProcessHeap(), 0, system_info->szSystemManufacturerEnglish);
    HeapFree(GetProcessHeap(), 0, system_info->szSystemModelEnglish);
    HeapFree(GetProcessHeap(), 0, system_info->szBIOSEnglish);
    HeapFree(GetProcessHeap(), 0, system_info->szProcessorEnglish);
    HeapFree(GetProcessHeap(), 0, system_info->szPhysicalMemoryEnglish);
    HeapFree(GetProcessHeap(), 0, system_info->szPageFileEnglish);
    HeapFree(GetProcessHeap(), 0, system_info->szPageFileLocalized);
    HeapFree(GetProcessHeap(), 0, system_info->szWindowsDir);
    HeapFree(GetProcessHeap(), 0, system_info->szDirectXVersionLongEnglish);
    HeapFree(GetProcessHeap(), 0, system_info->szSetupParamEnglish);
    HeapFree(GetProcessHeap(), 0, system_info->szDxDiagVersion);
107 108
}

109
static inline void fill_system_property_list(struct dxdiag_information *dxdiag_info, struct property_list *list)
110
{
111
    struct system_information *system_info = &dxdiag_info->system_info;
112

113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
    list[0].property_name = szTimeEnglish;
    list[0].output = &system_info->szTimeEnglish;
    list[1].property_name = szTimeLocalized;
    list[1].output = &system_info->szTimeLocalized;
    list[2].property_name = szMachineNameEnglish;
    list[2].output = &system_info->szMachineNameEnglish;
    list[3].property_name = szOSExLongEnglish;
    list[3].output = &system_info->szOSExLongEnglish;
    list[4].property_name = szOSExLocalized;
    list[4].output = &system_info->szOSExLocalized;
    list[5].property_name = szLanguagesEnglish;
    list[5].output = &system_info->szLanguagesEnglish;
    list[6].property_name = szLanguagesLocalized;
    list[6].output = &system_info->szLanguagesLocalized;
    list[7].property_name = szSystemManufacturerEnglish;
    list[7].output = &system_info->szSystemManufacturerEnglish;
    list[8].property_name = szSystemModelEnglish;
    list[8].output = &system_info->szSystemModelEnglish;
    list[9].property_name = szBIOSEnglish;
    list[9].output = &system_info->szBIOSEnglish;
    list[10].property_name = szProcessorEnglish;
    list[10].output = &system_info->szProcessorEnglish;
    list[11].property_name = szPhysicalMemoryEnglish;
    list[11].output = &system_info->szPhysicalMemoryEnglish;
    list[12].property_name = szPageFileEnglish;
    list[12].output = &system_info->szPageFileEnglish;
    list[13].property_name = szPageFileLocalized;
    list[13].output = &system_info->szPageFileLocalized;
    list[14].property_name = szWindowsDir;
    list[14].output = &system_info->szWindowsDir;
    list[15].property_name = szDirectXVersionLongEnglish;
    list[15].output = &system_info->szDirectXVersionLongEnglish;
    list[16].property_name = szSetupParamEnglish;
    list[16].output = &system_info->szSetupParamEnglish;
    list[17].property_name = szDxDiagVersion;
    list[17].output = &system_info->szDxDiagVersion;
}

static BOOL fill_system_information(IDxDiagContainer *container, struct dxdiag_information *dxdiag_info)
{
153 154
    struct system_information *system_info = &dxdiag_info->system_info;
    size_t i;
155 156 157
    struct property_list property_list[18];

    fill_system_property_list(dxdiag_info, property_list);
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188

    for (i = 0; i < sizeof(property_list)/sizeof(property_list[0]); i++)
    {
        if (!property_to_string(container, property_list[i].property_name, property_list[i].output))
        {
            WINE_ERR("Failed to retrieve property %s\n", wine_dbgstr_w(property_list[i].property_name));
            return FALSE;
        }
    }

#ifdef _WIN64
    system_info->win64 = TRUE;
#else
    system_info->win64 = FALSE;
#endif

    return TRUE;
}

static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};

static const struct information_fillers
{
    const WCHAR *child_container_name;
    BOOL (*fill_function)(IDxDiagContainer *, struct dxdiag_information *);
    void (*free_function)(struct dxdiag_information *);
} filler_list[] =
{
    {DxDiag_SystemInfo, fill_system_information, free_system_information},
};

189 190
void free_dxdiag_information(struct dxdiag_information *system_info)
{
191 192 193 194 195 196 197 198 199
    size_t i;

    if (!system_info)
        return;

    for (i = 0; i < sizeof(filler_list)/sizeof(filler_list[0]); i++)
        filler_list[i].free_function(system_info);

    HeapFree(GetProcessHeap(), 0, system_info);
200 201 202 203
}

struct dxdiag_information *collect_dxdiag_information(BOOL whql_check)
{
204 205 206
    IDxDiagProvider *pddp = NULL;
    IDxDiagContainer *root = NULL;
    struct dxdiag_information *ret = NULL;
207
    DXDIAG_INIT_PARAMS params = {sizeof(DXDIAG_INIT_PARAMS), DXDIAG_DX9_SDK_VERSION};
208 209 210 211 212 213 214 215 216 217 218 219
    HRESULT hr;
    size_t i;

    /* Initialize the DxDiag COM instances. */
    hr = CoCreateInstance(&CLSID_DxDiagProvider, NULL, CLSCTX_INPROC_SERVER,
                          &IID_IDxDiagProvider, (void **)&pddp);
    if (FAILED(hr))
    {
        WINE_ERR("IDxDiagProvider instance creation failed with 0x%08x\n", hr);
        goto error;
    }

220
    params.bAllowWHQLChecks = whql_check;
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
    hr = IDxDiagProvider_Initialize(pddp, &params);
    if (FAILED(hr))
        goto error;

    hr = IDxDiagProvider_GetRootContainer(pddp, &root);
    if (FAILED(hr))
        goto error;

    ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
    if (!ret)
        goto error;

    for (i = 0; i < sizeof(filler_list)/sizeof(filler_list[0]); i++)
    {
        IDxDiagContainer *child;
        BOOL success;

        hr = IDxDiagContainer_GetChildContainer(root, filler_list[i].child_container_name, &child);
        if (FAILED(hr))
            goto error;

        success = filler_list[i].fill_function(child, ret);
        IDxDiagContainer_Release(child);
        if (!success)
            goto error;
    }

    IDxDiagContainer_Release(root);
    IDxDiagProvider_Release(pddp);
    return ret;

error:
    free_dxdiag_information(ret);
    if (root) IDxDiagContainer_Release(root);
    if (pddp) IDxDiagProvider_Release(pddp);
256 257
    return NULL;
}