Owen Rudge : appwiz.cpl: Add uninstall routine for applications.

Alexandre Julliard julliard at winehq.org
Fri Jul 25 08:13:54 CDT 2008


Module: wine
Branch: master
Commit: eece76b8b33e355341f84c5f13d442529b9c31ab
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=eece76b8b33e355341f84c5f13d442529b9c31ab

Author: Owen Rudge <owen at owenrudge.net>
Date:   Mon Jul 21 19:42:38 2008 +0100

appwiz.cpl: Add uninstall routine for applications.

---

 dlls/appwiz.cpl/En.rc    |    2 +
 dlls/appwiz.cpl/appwiz.c |   81 ++++++++++++++++++++++++++++++++++++++++++++++
 dlls/appwiz.cpl/res.h    |    1 +
 3 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/dlls/appwiz.cpl/En.rc b/dlls/appwiz.cpl/En.rc
index 1abc788..fde9fa1 100644
--- a/dlls/appwiz.cpl/En.rc
+++ b/dlls/appwiz.cpl/En.rc
@@ -27,6 +27,8 @@ STRINGTABLE
    IDS_CPL_DESC, "Allows you to install new software, or remove existing software from your computer."
    IDS_TAB1_TITLE, "Applications"
 
+   IDS_UNINSTALL_FAILED, "Unable to execute the uninstaller, '%s'. Do you want to remove the uninstall entry for this program from the registry?"
+
    IDS_COLUMN_NAME, "Name"
    IDS_COLUMN_PUBLISHER, "Publisher"
    IDS_COLUMN_VERSION, "Version"
diff --git a/dlls/appwiz.cpl/appwiz.c b/dlls/appwiz.cpl/appwiz.c
index 445e5ba..fa4d573 100644
--- a/dlls/appwiz.cpl/appwiz.c
+++ b/dlls/appwiz.cpl/appwiz.c
@@ -371,6 +371,61 @@ static void UpdateButtons(HWND hWnd)
     EnableWindow(GetDlgItem(hWnd, IDC_SUPPORT_INFO), sel);
 }
 
+/******************************************************************************
+ * Name       : UninstallProgram
+ * Description: Executes the specified program's installer.
+ * Parameters : id      - the internal ID of the installer to remove
+ */
+static void UninstallProgram(int id)
+{
+    APPINFO *iter;
+    STARTUPINFOW si;
+    PROCESS_INFORMATION info;
+    WCHAR errormsg[MAX_STRING_LEN];
+    WCHAR sUninstallFailed[MAX_STRING_LEN];
+    HKEY hkey;
+    BOOL res;
+
+    LoadStringW(hInst, IDS_UNINSTALL_FAILED, sUninstallFailed,
+        sizeof(sUninstallFailed) / sizeof(sUninstallFailed[0]));
+
+    for (iter = AppInfo; iter; iter = iter->next)
+    {
+        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;
+            res = CreateProcessW(NULL, iter->path, NULL, NULL, FALSE, 0, NULL,
+                NULL, &si, &info);
+
+            if (res)
+            {
+                /* wait for the process to exit */
+                WaitForSingleObject(info.hProcess, INFINITE);
+            }
+            else
+            {
+                wsprintfW(errormsg, sUninstallFailed, iter->path);
+
+                if (MessageBoxW(0, errormsg, iter->title, MB_YESNO |
+                    MB_ICONQUESTION) == IDYES)
+                {
+                    /* delete the application's uninstall entry */
+                    RegOpenKeyExW(iter->regroot, PathUninstallW, 0, KEY_READ, &hkey);
+                    RegDeleteKeyW(hkey, iter->regkey);
+                    RegCloseKey(hkey);
+                }
+            }
+
+            break;
+        }
+    }
+}
+
 /* Definition of column headers for AddListViewColumns function */
 typedef struct AppWizColumn {
    int width;
@@ -494,8 +549,10 @@ static HIMAGELIST ResetApplicationList(BOOL bFirstRun, HWND hWnd, HIMAGELIST hIm
  */
 static BOOL CALLBACK MainDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
+    int selitem;
     static HIMAGELIST hImageList;
     LPNMHDR nmh;
+    LVITEMW lvItem;
 
     switch(msg)
     {
@@ -531,6 +588,30 @@ static BOOL CALLBACK MainDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPar
             }
 
             return TRUE;
+
+        case WM_COMMAND:
+            switch (LOWORD(wParam))
+            {
+                case IDC_ADDREMOVE:
+                    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))
+                            UninstallProgram(lvItem.lParam);
+                    }
+
+                    hImageList = ResetApplicationList(FALSE, hWnd, hImageList);
+
+                    break;
+            }
+
+            return TRUE;
     }
 
     return FALSE;
diff --git a/dlls/appwiz.cpl/res.h b/dlls/appwiz.cpl/res.h
index 64b4a5b..2aff5ca 100644
--- a/dlls/appwiz.cpl/res.h
+++ b/dlls/appwiz.cpl/res.h
@@ -38,6 +38,7 @@
 #define IDS_CPL_TITLE          1
 #define IDS_CPL_DESC           2
 #define IDS_TAB1_TITLE         3
+#define IDS_UNINSTALL_FAILED   4
 #define IDS_COLUMN_NAME        6
 #define IDS_COLUMN_PUBLISHER   7
 #define IDS_COLUMN_VERSION     8




More information about the wine-cvs mailing list