appwiz.c 33.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * Add/Remove Programs applet
 * Partially based on Wine Uninstaller
 *
 * Copyright 2000 Andreas Mohr
 * Copyright 2004 Hannu Valtonen
 * Copyright 2005 Jonathan Ernst
 * Copyright 2001-2002, 2008 Owen Rudge
 *
 * 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
 *
 */

26 27
#define NONAMELESSUNION

28 29 30 31 32 33 34 35 36 37 38 39 40
#include "config.h"
#include "wine/port.h"

#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <windef.h>
#include <winbase.h>
#include <winuser.h>
#include <wingdi.h>
#include <winreg.h>
#include <shellapi.h>
41
#include <commctrl.h>
42
#include <commdlg.h>
43 44
#include <cpl.h>

45 46 47
#include "wine/unicode.h"
#include "wine/list.h"
#include "wine/debug.h"
48
#include "appwiz.h"
49 50 51 52
#include "res.h"

WINE_DEFAULT_DEBUG_CHANNEL(appwizcpl);

53 54 55
/* define a maximum length for various buffers we use */
#define MAX_STRING_LEN    1024

56 57 58
typedef struct APPINFO
{
    struct list entry;
59 60 61 62
    int id;

    LPWSTR title;
    LPWSTR path;
63
    LPWSTR path_modify;
64 65 66 67 68 69 70 71 72 73 74

    LPWSTR icon;
    int iconIdx;

    LPWSTR publisher;
    LPWSTR version;

    HKEY regroot;
    WCHAR regkey[MAX_STRING_LEN];
} APPINFO;

75
static struct list app_list = LIST_INIT( app_list );
76
HINSTANCE hInst;
77

78 79 80
static WCHAR btnRemove[MAX_STRING_LEN];
static WCHAR btnModifyRemove[MAX_STRING_LEN];

81 82
static const WCHAR openW[] = {'o','p','e','n',0};

83 84 85 86 87 88 89
/* names of registry keys */
static const WCHAR BackSlashW[] = { '\\', 0 };
static const WCHAR DisplayNameW[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
static const WCHAR DisplayIconW[] = {'D','i','s','p','l','a','y','I','c','o','n',0};
static const WCHAR DisplayVersionW[] = {'D','i','s','p','l','a','y','V','e','r',
    's','i','o','n',0};
static const WCHAR PublisherW[] = {'P','u','b','l','i','s','h','e','r',0};
90 91 92 93
static const WCHAR ContactW[] = {'C','o','n','t','a','c','t',0};
static const WCHAR HelpLinkW[] = {'H','e','l','p','L','i','n','k',0};
static const WCHAR HelpTelephoneW[] = {'H','e','l','p','T','e','l','e','p','h',
    'o','n','e',0};
94 95
static const WCHAR ModifyPathW[] = {'M','o','d','i','f','y','P','a','t','h',0};
static const WCHAR NoModifyW[] = {'N','o','M','o','d','i','f','y',0};
96 97 98 99
static const WCHAR ReadmeW[] = {'R','e','a','d','m','e',0};
static const WCHAR URLUpdateInfoW[] = {'U','R','L','U','p','d','a','t','e','I',
    'n','f','o',0};
static const WCHAR CommentsW[] = {'C','o','m','m','e','n','t','s',0};
100 101
static const WCHAR UninstallCommandlineW[] = {'U','n','i','n','s','t','a','l','l',
    'S','t','r','i','n','g',0};
102
static const WCHAR WindowsInstallerW[] = {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
103
static const WCHAR SystemComponentW[] = {'S','y','s','t','e','m','C','o','m','p','o','n','e','n','t',0};
104 105 106 107 108 109 110 111

static const WCHAR PathUninstallW[] = {
        'S','o','f','t','w','a','r','e','\\',
        'M','i','c','r','o','s','o','f','t','\\',
        'W','i','n','d','o','w','s','\\',
        'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
        'U','n','i','n','s','t','a','l','l',0 };

112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
/******************************************************************************
 * Name       : DllMain
 * Description: Entry point for DLL file
 */
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
                    LPVOID lpvReserved)
{
    TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);

    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            hInst = hinstDLL;
            break;
    }
    return TRUE;
}

130 131 132 133 134 135
/******************************************************************************
 * Name       : FreeAppInfo
 * Description: Frees memory used by an AppInfo structure, and any children.
 */
static void FreeAppInfo(APPINFO *info)
{
136 137 138 139 140 141 142
    HeapFree(GetProcessHeap(), 0, info->title);
    HeapFree(GetProcessHeap(), 0, info->path);
    HeapFree(GetProcessHeap(), 0, info->path_modify);
    HeapFree(GetProcessHeap(), 0, info->icon);
    HeapFree(GetProcessHeap(), 0, info->publisher);
    HeapFree(GetProcessHeap(), 0, info->version);
    HeapFree(GetProcessHeap(), 0, info);
143 144 145 146 147 148
}

/******************************************************************************
 * Name       : ReadApplicationsFromRegistry
 * Description: Creates a linked list of uninstallable applications from the
 *              registry.
149
 * Parameters : root    - Which registry root to read from
150 151 152 153
 * Returns    : TRUE if successful, FALSE otherwise
 */
static BOOL ReadApplicationsFromRegistry(HKEY root)
{
154
    HKEY hkeyApp;
155 156
    int i;
    static int id = 0;
157
    DWORD sizeOfSubKeyName, displen, uninstlen;
158
    DWORD dwNoModify, dwType, value, size;
159
    WCHAR subKeyName[256];
160
    WCHAR *command;
161
    APPINFO *info = NULL;
162 163 164 165
    LPWSTR iconPtr;

    sizeOfSubKeyName = sizeof(subKeyName) / sizeof(subKeyName[0]);

166
    for (i = 0; RegEnumKeyExW(root, i, subKeyName, &sizeOfSubKeyName, NULL,
167 168
        NULL, NULL, NULL) != ERROR_NO_MORE_ITEMS; ++i)
    {
169
        RegOpenKeyExW(root, subKeyName, 0, KEY_READ, &hkeyApp);
170 171 172 173 174 175 176 177
        size = sizeof(value);
        if (!RegQueryValueExW(hkeyApp, SystemComponentW, NULL, &dwType, (LPBYTE)&value, &size)
            && dwType == REG_DWORD && value == 1)
        {
            RegCloseKey(hkeyApp);
            sizeOfSubKeyName = sizeof(subKeyName) / sizeof(subKeyName[0]);
            continue;
        }
178 179
        displen = 0;
        uninstlen = 0;
180
        if (!RegQueryValueExW(hkeyApp, DisplayNameW, 0, 0, NULL, &displen))
181
        {
182
            size = sizeof(value);
183
            if (!RegQueryValueExW(hkeyApp, WindowsInstallerW, NULL, &dwType, (LPBYTE)&value, &size)
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
                && dwType == REG_DWORD && value == 1)
            {
                static const WCHAR fmtW[] = {'m','s','i','e','x','e','c',' ','/','x','%','s',0};
                int len = lstrlenW(fmtW) + lstrlenW(subKeyName);

                if (!(command = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)))) goto err;
                wsprintfW(command, fmtW, subKeyName);
            }
            else if (!RegQueryValueExW(hkeyApp, UninstallCommandlineW, 0, 0, NULL, &uninstlen))
            {
                if (!(command = HeapAlloc(GetProcessHeap(), 0, uninstlen))) goto err;
                RegQueryValueExW(hkeyApp, UninstallCommandlineW, 0, 0, (LPBYTE)command, &uninstlen);
            }
            else
            {
                RegCloseKey(hkeyApp);
                sizeOfSubKeyName = sizeof(subKeyName) / sizeof(subKeyName[0]);
                continue;
            }

204 205
            info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct APPINFO));
            if (!info) goto err;
206

207
            info->title = HeapAlloc(GetProcessHeap(), 0, displen);
208

209
            if (!info->title)
210 211
                goto err;

212
            RegQueryValueExW(hkeyApp, DisplayNameW, 0, 0, (LPBYTE)info->title,
213 214 215 216 217 218 219
                &displen);

            /* now get DisplayIcon */
            displen = 0;
            RegQueryValueExW(hkeyApp, DisplayIconW, 0, 0, NULL, &displen);

            if (displen == 0)
220
                info->icon = 0;
221 222
            else
            {
223
                info->icon = HeapAlloc(GetProcessHeap(), 0, displen);
224

225
                if (!info->icon)
226 227
                    goto err;

228
                RegQueryValueExW(hkeyApp, DisplayIconW, 0, 0, (LPBYTE)info->icon,
229 230 231
                    &displen);

                /* separate the index from the icon name, if supplied */
232
                iconPtr = strchrW(info->icon, ',');
233 234 235 236

                if (iconPtr)
                {
                    *iconPtr++ = 0;
237
                    info->iconIdx = atoiW(iconPtr);
238 239 240 241 242 243 244
                }
            }

            /* publisher, version */
            if (RegQueryValueExW(hkeyApp, PublisherW, 0, 0, NULL, &displen) ==
                ERROR_SUCCESS)
            {
245
                info->publisher = HeapAlloc(GetProcessHeap(), 0, displen);
246

247
                if (!info->publisher)
248 249
                    goto err;

250
                RegQueryValueExW(hkeyApp, PublisherW, 0, 0, (LPBYTE)info->publisher,
251 252 253 254 255 256
                    &displen);
            }

            if (RegQueryValueExW(hkeyApp, DisplayVersionW, 0, 0, NULL, &displen) ==
                ERROR_SUCCESS)
            {
257
                info->version = HeapAlloc(GetProcessHeap(), 0, displen);
258

259
                if (!info->version)
260 261
                    goto err;

262
                RegQueryValueExW(hkeyApp, DisplayVersionW, 0, 0, (LPBYTE)info->version,
263 264 265
                    &displen);
            }

266 267 268 269 270 271 272 273 274 275 276
            /* Check if NoModify is set */
            dwType = REG_DWORD;
            dwNoModify = 0;
            displen = sizeof(DWORD);

            if (RegQueryValueExW(hkeyApp, NoModifyW, NULL, &dwType, (LPBYTE)&dwNoModify, &displen)
                != ERROR_SUCCESS)
            {
                dwNoModify = 0;
            }

277
            /* Some installers incorrectly create a REG_SZ instead of a REG_DWORD */
278
            if (dwType == REG_SZ)
279
                dwNoModify = (*(BYTE *)&dwNoModify == '1');
280 281

            /* Fetch the modify path */
282
            if (!dwNoModify)
283
            {
284 285
                size = sizeof(value);
                if (!RegQueryValueExW(hkeyApp, WindowsInstallerW, NULL, &dwType, (LPBYTE)&value, &size)
286 287 288 289
                    && dwType == REG_DWORD && value == 1)
                {
                    static const WCHAR fmtW[] = {'m','s','i','e','x','e','c',' ','/','i','%','s',0};
                    int len = lstrlenW(fmtW) + lstrlenW(subKeyName);
290

291 292
                    if (!(info->path_modify = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)))) goto err;
                    wsprintfW(info->path_modify, fmtW, subKeyName);
293 294 295
                }
                else if (!RegQueryValueExW(hkeyApp, ModifyPathW, 0, 0, NULL, &displen))
                {
296 297
                    if (!(info->path_modify = HeapAlloc(GetProcessHeap(), 0, displen))) goto err;
                    RegQueryValueExW(hkeyApp, ModifyPathW, 0, 0, (LPBYTE)info->path_modify, &displen);
298
                }
299 300
            }

301
            /* registry key */
302
            RegOpenKeyExW(root, NULL, 0, KEY_READ, &info->regroot);
303 304
            lstrcpyW(info->regkey, subKeyName);
            info->path = command;
305

306 307
            info->id = id++;
            list_add_tail( &app_list, &info->entry );
308 309 310 311 312 313
        }

        RegCloseKey(hkeyApp);
        sizeOfSubKeyName = sizeof(subKeyName) / sizeof(subKeyName[0]);
    }

314
    return TRUE;
315 316
err:
    RegCloseKey(hkeyApp);
317
    if (info) FreeAppInfo(info);
318
    HeapFree(GetProcessHeap(), 0, command);
319
    return FALSE;
320 321
}

322 323 324 325 326 327 328 329

/******************************************************************************
 * Name       : AddApplicationsToList
 * Description: Populates the list box with applications.
 * Parameters : hWnd    - Handle of the dialog box
 */
static void AddApplicationsToList(HWND hWnd, HIMAGELIST hList)
{
330
    APPINFO *iter;
331 332 333 334
    LVITEMW lvItem;
    HICON hIcon;
    int index;

335
    LIST_FOR_EACH_ENTRY( iter, &app_list, APPINFO, entry )
336
    {
337 338
        if (!iter->title[0]) continue;

339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
        /* get the icon */
        index = 0;

        if (iter->icon)
        {
            if (ExtractIconExW(iter->icon, iter->iconIdx, NULL, &hIcon, 1) == 1)
            {
                index = ImageList_AddIcon(hList, hIcon);
                DestroyIcon(hIcon);
            }
        }

        lvItem.mask = LVIF_IMAGE | LVIF_TEXT | LVIF_PARAM;
        lvItem.iItem = iter->id;
        lvItem.iSubItem = 0;
        lvItem.pszText = iter->title;
        lvItem.iImage = index;
        lvItem.lParam = iter->id;

        index = ListView_InsertItemW(hWnd, &lvItem);

        /* now add the subitems (columns) */
        ListView_SetItemTextW(hWnd, index, 1, iter->publisher);
        ListView_SetItemTextW(hWnd, index, 2, iter->version);
    }
}

/******************************************************************************
 * Name       : RemoveItemsFromList
 * Description: Clears the application list box.
 * Parameters : hWnd    - Handle of the dialog box
 */
static void RemoveItemsFromList(HWND hWnd)
{
    SendDlgItemMessageW(hWnd, IDL_PROGRAMS, LVM_DELETEALLITEMS, 0, 0);
}

376 377 378 379 380 381
/******************************************************************************
 * Name       : EmptyList
 * Description: Frees memory used by the application linked list.
 */
static inline void EmptyList(void)
{
382 383 384 385 386 387
    APPINFO *info, *next;
    LIST_FOR_EACH_ENTRY_SAFE( info, next, &app_list, APPINFO, entry )
    {
        list_remove( &info->entry );
        FreeAppInfo( info );
    }
388 389
}

390 391 392 393 394 395 396 397
/******************************************************************************
 * Name       : UpdateButtons
 * Description: Enables/disables the Add/Remove button depending on current
 *              selection in list box.
 * Parameters : hWnd    - Handle of the dialog box
 */
static void UpdateButtons(HWND hWnd)
{
398 399
    APPINFO *iter;
    LVITEMW lvItem;
400
    LRESULT selitem = SendDlgItemMessageW(hWnd, IDL_PROGRAMS, LVM_GETNEXTITEM, -1,
401 402 403 404 405 406 407 408 409 410
       LVNI_FOCUSED | LVNI_SELECTED);
    BOOL enable_modify = FALSE;

    if (selitem != -1)
    {
        lvItem.iItem = selitem;
        lvItem.mask = LVIF_PARAM;

        if (SendDlgItemMessageW(hWnd, IDL_PROGRAMS, LVM_GETITEMW, 0, (LPARAM) &lvItem))
        {
411
            LIST_FOR_EACH_ENTRY( iter, &app_list, APPINFO, entry )
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
            {
                if (iter->id == lvItem.lParam)
                {
                    /* Decide whether to display Modify/Remove as one button or two */
                    enable_modify = (iter->path_modify != NULL);

                    /* Update title as appropriate */
                    if (iter->path_modify == NULL)
                        SetWindowTextW(GetDlgItem(hWnd, IDC_ADDREMOVE), btnModifyRemove);
                    else
                        SetWindowTextW(GetDlgItem(hWnd, IDC_ADDREMOVE), btnRemove);

                    break;
                }
            }
        }
    }
429

430 431 432 433
    /* Enable/disable other buttons if necessary */
    EnableWindow(GetDlgItem(hWnd, IDC_ADDREMOVE), (selitem != -1));
    EnableWindow(GetDlgItem(hWnd, IDC_SUPPORT_INFO), (selitem != -1));
    EnableWindow(GetDlgItem(hWnd, IDC_MODIFY), enable_modify);
434 435
}

436 437 438 439 440 441 442
/******************************************************************************
 * Name       : InstallProgram
 * Description: Search for potential Installer and execute it.
 * Parameters : hWnd    - Handle of the dialog box
 */
static void InstallProgram(HWND hWnd)
{
443 444
    static const WCHAR filters[] = {'%','s','%','c','*','i','n','s','t','a','l','*','.','e','x','e',';','*','s','e','t','u','p','*','.','e','x','e',';','*','.','m','s','i','%','c','%','s','%','c','*','.','e','x','e','%','c','%','s','%','c','*','.','*','%','c',0}
;
445 446
    OPENFILENAMEW ofn;
    WCHAR titleW[MAX_STRING_LEN];
447 448 449 450
    WCHAR filter_installs[MAX_STRING_LEN];
    WCHAR filter_programs[MAX_STRING_LEN];
    WCHAR filter_all[MAX_STRING_LEN];
    WCHAR FilterBufferW[MAX_PATH];
451 452 453
    WCHAR FileNameBufferW[MAX_PATH];

    LoadStringW(hInst, IDS_CPL_TITLE, titleW, sizeof(titleW)/sizeof(WCHAR));
454 455 456
    LoadStringW(hInst, IDS_FILTER_INSTALLS, filter_installs, sizeof(filter_installs)/sizeof(WCHAR));
    LoadStringW(hInst, IDS_FILTER_PROGRAMS, filter_programs, sizeof(filter_programs)/sizeof(WCHAR));
    LoadStringW(hInst, IDS_FILTER_ALL, filter_all, sizeof(filter_all)/sizeof(WCHAR));
457

458 459
    snprintfW( FilterBufferW, MAX_PATH, filters, filter_installs, 0, 0,
               filter_programs, 0, 0, filter_all, 0, 0 );
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
    memset(&ofn, 0, sizeof(OPENFILENAMEW));
    ofn.lStructSize = sizeof(OPENFILENAMEW);
    ofn.hwndOwner = hWnd;
    ofn.hInstance = hInst;
    ofn.lpstrFilter = FilterBufferW;
    ofn.nFilterIndex = 0;
    ofn.lpstrFile = FileNameBufferW;
    ofn.nMaxFile = MAX_PATH;
    ofn.lpstrFileTitle = NULL;
    ofn.nMaxFileTitle = 0;
    ofn.lpstrTitle = titleW;
    ofn.Flags = OFN_HIDEREADONLY | OFN_ENABLESIZING;
    FileNameBufferW[0] = 0;

    if (GetOpenFileNameW(&ofn))
    {
        SHELLEXECUTEINFOW sei;
        memset(&sei, 0, sizeof(sei));
        sei.cbSize = sizeof(sei);
        sei.lpVerb = openW;
        sei.nShow = SW_SHOWDEFAULT;
481
        sei.fMask = 0;
482 483 484 485 486 487
        sei.lpFile = ofn.lpstrFile;

        ShellExecuteExW(&sei);
    }
}

488 489 490 491
/******************************************************************************
 * Name       : UninstallProgram
 * Description: Executes the specified program's installer.
 * Parameters : id      - the internal ID of the installer to remove
492
 * Parameters : button  - ID of button pressed (Modify or Remove)
493
 */
494
static void UninstallProgram(int id, DWORD button)
495 496 497 498 499 500 501 502 503 504 505
{
    APPINFO *iter;
    STARTUPINFOW si;
    PROCESS_INFORMATION info;
    WCHAR errormsg[MAX_STRING_LEN];
    WCHAR sUninstallFailed[MAX_STRING_LEN];
    BOOL res;

    LoadStringW(hInst, IDS_UNINSTALL_FAILED, sUninstallFailed,
        sizeof(sUninstallFailed) / sizeof(sUninstallFailed[0]));

506
    LIST_FOR_EACH_ENTRY( iter, &app_list, APPINFO, entry )
507 508 509 510 511 512 513 514 515
    {
        if (iter->id == id)
        {
            TRACE("Uninstalling %s (%s)\n", wine_dbgstr_w(iter->title),
                wine_dbgstr_w(iter->path));

            memset(&si, 0, sizeof(STARTUPINFOW));
            si.cb = sizeof(STARTUPINFOW);
            si.wShowWindow = SW_NORMAL;
516 517 518

            res = CreateProcessW(NULL, (button == IDC_MODIFY) ? iter->path_modify : iter->path,
                NULL, NULL, FALSE, 0, NULL, NULL, &si, &info);
519 520 521

            if (res)
            {
522 523
                CloseHandle(info.hThread);

524 525
                /* wait for the process to exit */
                WaitForSingleObject(info.hProcess, INFINITE);
526
                CloseHandle(info.hProcess);
527 528 529 530 531 532 533 534 535
            }
            else
            {
                wsprintfW(errormsg, sUninstallFailed, iter->path);

                if (MessageBoxW(0, errormsg, iter->title, MB_YESNO |
                    MB_ICONQUESTION) == IDYES)
                {
                    /* delete the application's uninstall entry */
536 537
                    RegDeleteKeyW(iter->regroot, iter->regkey);
                    RegCloseKey(iter->regroot);
538 539 540 541 542 543 544 545
                }
            }

            break;
        }
    }
}

546 547 548 549 550 551 552 553 554 555 556
/**********************************************************************************
 * Name       : SetInfoDialogText
 * Description: Sets the text of a label in a window, based upon a registry entry
 *              or string passed to the function.
 * Parameters : hKey         - registry entry to read from, NULL if not reading
 *                             from registry
 *              lpKeyName    - key to read from, or string to check if hKey is NULL
 *              lpAltMessage - alternative message if entry not found
 *              hWnd         - handle of dialog box
 *              iDlgItem     - ID of label in dialog box
 */
557
static void SetInfoDialogText(HKEY hKey, LPCWSTR lpKeyName, LPCWSTR lpAltMessage,
558 559 560 561 562 563 564 565 566 567 568
  HWND hWnd, int iDlgItem)
{
    WCHAR buf[MAX_STRING_LEN];
    DWORD buflen;
    HWND hWndDlgItem;

    hWndDlgItem = GetDlgItem(hWnd, iDlgItem);

    /* if hKey is null, lpKeyName contains the string we want to check */
    if (hKey == NULL)
    {
569
        if (lpKeyName && lpKeyName[0])
570 571 572 573 574 575 576 577 578
            SetWindowTextW(hWndDlgItem, lpKeyName);
        else
            SetWindowTextW(hWndDlgItem, lpAltMessage);
    }
    else
    {
        buflen = MAX_STRING_LEN;

        if ((RegQueryValueExW(hKey, lpKeyName, 0, 0, (LPBYTE) buf, &buflen) ==
579
           ERROR_SUCCESS) && buf[0])
580 581 582 583 584 585
            SetWindowTextW(hWndDlgItem, buf);
        else
            SetWindowTextW(hWndDlgItem, lpAltMessage);
    }
}

586 587 588 589 590 591 592
/******************************************************************************
 * Name       : SupportInfoDlgProc
 * Description: Callback procedure for support info dialog
 * Parameters : hWnd    - hWnd of the window
 *              msg     - reason for calling function
 *              wParam  - additional parameter
 *              lParam  - additional parameter
593
 * Returns    : Depends on the message
594
 */
595
static INT_PTR CALLBACK SupportInfoDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
596 597
{
    APPINFO *iter;
598
    HKEY hkey;
599 600
    WCHAR oldtitle[MAX_STRING_LEN];
    WCHAR buf[MAX_STRING_LEN];
601 602
    WCHAR key[MAX_STRING_LEN];
    WCHAR notfound[MAX_STRING_LEN];
603 604 605 606

    switch(msg)
    {
        case WM_INITDIALOG:
607
            LIST_FOR_EACH_ENTRY( iter, &app_list, APPINFO, entry )
608 609 610
            {
                if (iter->id == (int) lParam)
                {
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
                    lstrcpyW(key, PathUninstallW);
                    lstrcatW(key, BackSlashW);
                    lstrcatW(key, iter->regkey);

                    /* check the application's registry entries */
                    RegOpenKeyExW(iter->regroot, key, 0, KEY_READ, &hkey);

                    /* Load our "not specified" string */
                    LoadStringW(hInst, IDS_NOT_SPECIFIED, notfound,
                        sizeof(notfound) / sizeof(notfound[0]));

                    /* Update the data for items already read into the structure */
                    SetInfoDialogText(NULL, iter->publisher, notfound, hWnd,
                        IDC_INFO_PUBLISHER);
                    SetInfoDialogText(NULL, iter->version, notfound, hWnd,
                        IDC_INFO_VERSION);

                    /* And now update the data for those items in the registry */
629
                    SetInfoDialogText(hkey, ContactW, notfound, hWnd,
630
                        IDC_INFO_CONTACT);
631
                    SetInfoDialogText(hkey, HelpLinkW, notfound, hWnd,
632
                        IDC_INFO_SUPPORT);
633
                    SetInfoDialogText(hkey, HelpTelephoneW, notfound, hWnd,
634
                        IDC_INFO_PHONE);
635
                    SetInfoDialogText(hkey, ReadmeW, notfound, hWnd,
636
                        IDC_INFO_README);
637
                    SetInfoDialogText(hkey, URLUpdateInfoW, notfound, hWnd,
638
                        IDC_INFO_UPDATES);
639
                    SetInfoDialogText(hkey, CommentsW, notfound, hWnd,
640 641
                        IDC_INFO_COMMENTS);

642 643 644 645 646 647 648 649
                    /* Update the main label with the app name */
                    if (GetWindowTextW(GetDlgItem(hWnd, IDC_INFO_LABEL), oldtitle,
                        MAX_STRING_LEN) != 0)
                    {
                        wsprintfW(buf, oldtitle, iter->title);
                        SetWindowTextW(GetDlgItem(hWnd, IDC_INFO_LABEL), buf);
                    }

650 651
                    RegCloseKey(hkey);

652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
                    break;
                }
            }

            return TRUE;

        case WM_DESTROY:
            return 0;

        case WM_COMMAND:
            switch (LOWORD(wParam))
            {
                case IDOK:
                    EndDialog(hWnd, TRUE);
                    break;

            }

            return TRUE;
    }

    return FALSE;
}

/******************************************************************************
 * Name       : SupportInfo
 * Description: Displays the Support Information dialog
 * Parameters : hWnd    - Handle of the main dialog
 *              id      - ID of the application to display information for
 */
static void SupportInfo(HWND hWnd, int id)
{
684
    DialogBoxParamW(hInst, MAKEINTRESOURCEW(IDD_INFO), hWnd, SupportInfoDlgProc, id);
685 686
}

687 688 689 690 691 692 693
/* Definition of column headers for AddListViewColumns function */
typedef struct AppWizColumn {
   int width;
   int fmt;
   int title;
} AppWizColumn;

694
static const AppWizColumn columns[] = {
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
    {200, LVCFMT_LEFT, IDS_COLUMN_NAME},
    {150, LVCFMT_LEFT, IDS_COLUMN_PUBLISHER},
    {100, LVCFMT_LEFT, IDS_COLUMN_VERSION},
};

/******************************************************************************
 * Name       : AddListViewColumns
 * Description: Adds column headers to the list view control.
 * Parameters : hWnd    - Handle of the list view control.
 * Returns    : TRUE if completed successfully, FALSE otherwise.
 */
static BOOL AddListViewColumns(HWND hWnd)
{
    WCHAR buf[MAX_STRING_LEN];
    LVCOLUMNW lvc;
710
    UINT i;
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732

    lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;

    /* Add the columns */
    for (i = 0; i < sizeof(columns) / sizeof(columns[0]); i++)
    {
        lvc.iSubItem = i;
        lvc.pszText = buf;

        /* set width and format */
        lvc.cx = columns[i].width;
        lvc.fmt = columns[i].fmt;

        LoadStringW(hInst, columns[i].title, buf, sizeof(buf) / sizeof(buf[0]));

        if (ListView_InsertColumnW(hWnd, i, &lvc) == -1)
            return FALSE;
    }

    return TRUE;
}

733 734 735 736 737 738 739 740 741 742 743 744
/******************************************************************************
 * Name       : AddListViewImageList
 * Description: Creates an ImageList for the list view control.
 * Parameters : hWnd    - Handle of the list view control.
 * Returns    : Handle of the image list.
 */
static HIMAGELIST AddListViewImageList(HWND hWnd)
{
    HIMAGELIST hSmall;
    HICON hDefaultIcon;

    hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
745
                              ILC_COLOR32 | ILC_MASK, 1, 1);
746 747 748 749 750 751

    /* Add default icon to image list */
    hDefaultIcon = LoadIconW(hInst, MAKEINTRESOURCEW(ICO_MAIN));
    ImageList_AddIcon(hSmall, hDefaultIcon);
    DestroyIcon(hDefaultIcon);

752
    SendMessageW(hWnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)hSmall);
753 754 755 756

    return hSmall;
}

757 758 759 760 761 762 763 764 765 766
/******************************************************************************
 * Name       : ResetApplicationList
 * Description: Empties the app list, if need be, and recreates it.
 * Parameters : bFirstRun  - TRUE if this is the first time this is run, FALSE otherwise
 *              hWnd       - handle of the dialog box
 *              hImageList - handle of the image list
 * Returns    : New handle of the image list.
 */
static HIMAGELIST ResetApplicationList(BOOL bFirstRun, HWND hWnd, HIMAGELIST hImageList)
{
767
    static const BOOL is_64bit = sizeof(void *) > sizeof(int);
768
    HWND hWndListView;
769
    HKEY hkey;
770 771 772 773 774 775 776 777 778

    hWndListView = GetDlgItem(hWnd, IDL_PROGRAMS);

    /* if first run, create the image list and add the listview columns */
    if (bFirstRun)
    {
        if (!AddListViewColumns(hWndListView))
            return NULL;
    }
779 780
    else /* we need to remove the existing things first */
    {
781
        RemoveItemsFromList(hWnd);
782
        ImageList_Destroy(hImageList);
783 784 785 786

        /* reset the list, since it's probably changed if the uninstallation was
           successful */
        EmptyList();
787 788 789 790
    }

    /* now create the image list and add the applications to the listview */
    hImageList = AddListViewImageList(hWndListView);
791

792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807
    if (!RegOpenKeyExW(HKEY_LOCAL_MACHINE, PathUninstallW, 0, KEY_READ, &hkey))
    {
        ReadApplicationsFromRegistry(hkey);
        RegCloseKey(hkey);
    }
    if (is_64bit &&
        !RegOpenKeyExW(HKEY_LOCAL_MACHINE, PathUninstallW, 0, KEY_READ|KEY_WOW64_32KEY, &hkey))
    {
        ReadApplicationsFromRegistry(hkey);
        RegCloseKey(hkey);
    }
    if (!RegOpenKeyExW(HKEY_CURRENT_USER, PathUninstallW, 0, KEY_READ, &hkey))
    {
        ReadApplicationsFromRegistry(hkey);
        RegCloseKey(hkey);
    }
808

809
    AddApplicationsToList(hWndListView, hImageList);
810 811
    UpdateButtons(hWnd);

812 813 814
    return(hImageList);
}

815 816 817 818 819 820 821
/******************************************************************************
 * Name       : MainDlgProc
 * Description: Callback procedure for main tab
 * Parameters : hWnd    - hWnd of the window
 *              msg     - reason for calling function
 *              wParam  - additional parameter
 *              lParam  - additional parameter
822
 * Returns    : Depends on the message
823
 */
824
static INT_PTR CALLBACK MainDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
825
{
826
    int selitem;
827
    static HIMAGELIST hImageList;
828
    LPNMHDR nmh;
829
    LVITEMW lvItem;
830 831 832 833

    switch(msg)
    {
        case WM_INITDIALOG:
834 835 836
            SendDlgItemMessageW(hWnd, IDL_PROGRAMS, LVM_SETEXTENDEDLISTVIEWSTYLE,
                LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);

837 838
            hImageList = ResetApplicationList(TRUE, hWnd, hImageList);

839 840 841
            if (!hImageList)
                return FALSE;

842
            return TRUE;
843 844

        case WM_DESTROY:
845
            RemoveItemsFromList(hWnd);
846 847
            ImageList_Destroy(hImageList);

848 849
            EmptyList();

850
            return 0;
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866

        case WM_NOTIFY:
            nmh = (LPNMHDR) lParam;

            switch (nmh->idFrom)
            {
                case IDL_PROGRAMS:
                    switch (nmh->code)
                    {
                        case LVN_ITEMCHANGED:
                            UpdateButtons(hWnd);
                            break;
                    }
                    break;
            }

867 868 869 870 871
            return TRUE;

        case WM_COMMAND:
            switch (LOWORD(wParam))
            {
872 873 874 875
                case IDC_INSTALL:
                    InstallProgram(hWnd);
                    break;

876
                case IDC_ADDREMOVE:
877
                case IDC_MODIFY:
878 879 880 881 882 883 884 885 886 887
                    selitem = SendDlgItemMessageW(hWnd, IDL_PROGRAMS,
                        LVM_GETNEXTITEM, -1, LVNI_FOCUSED|LVNI_SELECTED);

                    if (selitem != -1)
                    {
                        lvItem.iItem = selitem;
                        lvItem.mask = LVIF_PARAM;

                        if (SendDlgItemMessageW(hWnd, IDL_PROGRAMS, LVM_GETITEMW,
                          0, (LPARAM) &lvItem))
888
                            UninstallProgram(lvItem.lParam, LOWORD(wParam));
889 890 891 892
                    }

                    hImageList = ResetApplicationList(FALSE, hWnd, hImageList);

893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908
                    break;

                case IDC_SUPPORT_INFO:
                    selitem = SendDlgItemMessageW(hWnd, IDL_PROGRAMS,
                        LVM_GETNEXTITEM, -1, LVNI_FOCUSED | LVNI_SELECTED);

                    if (selitem != -1)
                    {
                        lvItem.iItem = selitem;
                        lvItem.mask = LVIF_PARAM;

                        if (SendDlgItemMessageW(hWnd, IDL_PROGRAMS, LVM_GETITEMW,
                          0, (LPARAM) &lvItem))
                            SupportInfo(hWnd, lvItem.lParam);
                    }

909 910 911
                    break;
            }

912
            return TRUE;
913 914
    }

915 916 917
    return FALSE;
}

918 919 920 921 922 923 924 925 926 927 928
static int CALLBACK propsheet_callback( HWND hwnd, UINT msg, LPARAM lparam )
{
    switch (msg)
    {
    case PSCB_INITIALIZED:
        SendMessageW( hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIconW( hInst, MAKEINTRESOURCEW(ICO_MAIN) ));
        break;
    }
    return 0;
}

929 930 931 932 933 934 935 936 937 938 939 940 941 942
/******************************************************************************
 * Name       : StartApplet
 * Description: Main routine for applet
 * Parameters : hWnd    - hWnd of the Control Panel
 */
static void StartApplet(HWND hWnd)
{
    PROPSHEETPAGEW psp;
    PROPSHEETHEADERW psh;
    WCHAR tab_title[MAX_STRING_LEN], app_title[MAX_STRING_LEN];

    /* Load the strings we will use */
    LoadStringW(hInst, IDS_TAB1_TITLE, tab_title, sizeof(tab_title) / sizeof(tab_title[0]));
    LoadStringW(hInst, IDS_CPL_TITLE, app_title, sizeof(app_title) / sizeof(app_title[0]));
943 944
    LoadStringW(hInst, IDS_REMOVE, btnRemove, sizeof(btnRemove) / sizeof(btnRemove[0]));
    LoadStringW(hInst, IDS_MODIFY_REMOVE, btnModifyRemove, sizeof(btnModifyRemove) / sizeof(btnModifyRemove[0]));
945 946 947 948 949

    /* Fill out the PROPSHEETPAGE */
    psp.dwSize = sizeof (PROPSHEETPAGEW);
    psp.dwFlags = PSP_USETITLE;
    psp.hInstance = hInst;
950 951
    psp.u.pszTemplate = MAKEINTRESOURCEW (IDD_MAIN);
    psp.u2.pszIcon = NULL;
952
    psp.pfnDlgProc = MainDlgProc;
953 954 955 956 957
    psp.pszTitle = tab_title;
    psp.lParam = 0;

    /* Fill out the PROPSHEETHEADER */
    psh.dwSize = sizeof (PROPSHEETHEADERW);
958
    psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK;
959 960
    psh.hwndParent = hWnd;
    psh.hInstance = hInst;
961
    psh.u.pszIcon = MAKEINTRESOURCEW(ICO_MAIN);
962 963
    psh.pszCaption = app_title;
    psh.nPages = 1;
964
    psh.u3.ppsp = &psp;
965
    psh.pfnCallback = propsheet_callback;
966
    psh.u2.nStartPage = 0;
967 968 969 970 971

    /* Display the property sheet */
    PropertySheetW (&psh);
}

972 973 974
static LONG start_params(const WCHAR *params)
{
    static const WCHAR install_geckoW[] = {'i','n','s','t','a','l','l','_','g','e','c','k','o',0};
975
    static const WCHAR install_monoW[] = {'i','n','s','t','a','l','l','_','m','o','n','o',0};
976

977 978 979
    if(!params)
        return FALSE;

980
    if(!strcmpW(params, install_geckoW)) {
981
        install_addon(ADDON_GECKO);
982 983 984
        return TRUE;
    }

985 986 987 988 989
    if(!strcmpW(params, install_monoW)) {
        install_addon(ADDON_MONO);
        return TRUE;
    }

990 991 992 993
    WARN("unknown param %s\n", debugstr_w(params));
    return FALSE;
}

994 995 996 997 998 999 1000
/******************************************************************************
 * Name       : CPlApplet
 * Description: Entry point for Control Panel applets
 * Parameters : hwndCPL - hWnd of the Control Panel
 *              message - reason for calling function
 *              lParam1 - additional parameter
 *              lParam2 - additional parameter
1001
 * Returns    : Depends on the message
1002 1003 1004
 */
LONG CALLBACK CPlApplet(HWND hwndCPL, UINT message, LPARAM lParam1, LPARAM lParam2)
{
1005 1006
    INITCOMMONCONTROLSEX iccEx;

1007 1008 1009
    switch (message)
    {
        case CPL_INIT:
1010
            iccEx.dwSize = sizeof(iccEx);
1011
            iccEx.dwICC = ICC_LISTVIEW_CLASSES | ICC_TAB_CLASSES | ICC_LINK_CLASS;
1012 1013 1014

            InitCommonControlsEx(&iccEx);

1015 1016 1017 1018 1019
            return TRUE;

        case CPL_GETCOUNT:
            return 1;

1020 1021 1022
        case CPL_STARTWPARMSW:
            return start_params((const WCHAR *)lParam2);

1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033
        case CPL_INQUIRE:
        {
            CPLINFO *appletInfo = (CPLINFO *) lParam2;

            appletInfo->idIcon = ICO_MAIN;
            appletInfo->idName = IDS_CPL_TITLE;
            appletInfo->idInfo = IDS_CPL_DESC;
            appletInfo->lData = 0;

            break;
        }
1034 1035 1036 1037

        case CPL_DBLCLK:
            StartApplet(hwndCPL);
            break;
1038 1039 1040 1041
    }

    return FALSE;
}