cryptui: Implement browsing for input file in CryptUIWizImport.
authorJuan Lang <juan.lang@gmail.com>
Tue, 23 Dec 2008 03:08:31 +0000 (19:08 -0800)
committerAlexandre Julliard <julliard@winehq.org>
Tue, 23 Dec 2008 18:54:25 +0000 (19:54 +0100)
dlls/cryptui/Makefile.in
dlls/cryptui/cryptui_En.rc
dlls/cryptui/cryptuires.h
dlls/cryptui/main.c

index e268be61cf75724f762d8bc9cb0ff37f2eb4a238..d70d0ea685777564090b40ed0442e9500274cac4 100644 (file)
@@ -3,7 +3,7 @@ TOPOBJDIR = ../..
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = cryptui.dll
-IMPORTS   = uuid crypt32 ole32 comctl32 user32 gdi32 kernel32
+IMPORTS   = uuid crypt32 ole32 comctl32 comdlg32 user32 gdi32 kernel32
 DELAYIMPORTS = wintrust urlmon
 IMPORTLIB = cryptui
 
index aa86409a3e8491a4deae13b26bc376e0430e05cd..470eb1f36a45d324e8926c948f1b0fcb2f58e146 100644 (file)
@@ -69,6 +69,13 @@ STRINGTABLE DISCARDABLE
     IDS_IMPORT_FILE_SUBTITLE "Specify the file you want to import."
     IDS_IMPORT_STORE_TITLE "Certificate Store"
     IDS_IMPORT_STORE_SUBTITLE "Certificate stores are collections of certificates, certificate revocation lists, and certificate trust lists."
+    IDS_IMPORT_FILTER_CERT "X.509 Certificate (*.cer; *.crt)"
+    IDS_IMPORT_FILTER_PFX "Personal Information Exchange (*.pfx; *.p12)"
+    IDS_IMPORT_FILTER_CRL "Certificate Revocation List (*.crl)"
+    IDS_IMPORT_FILTER_CTL "Certificate Trust List (*.stl)"
+    IDS_IMPORT_FILTER_SERIALIZED_STORE "Microsoft Serialized Certificate Store (*.sst)"
+    IDS_IMPORT_FILTER_CMS "CMS/PKCS #7 Messages (*.spc; *.p7b)"
+    IDS_IMPORT_FILTER_ALL "All Files (*.*)"
     IDS_PURPOSE_SERVER_AUTH "Ensures the identify of a remote computer"
     IDS_PURPOSE_CLIENT_AUTH "Proves your identity to a remote computer"
     IDS_PURPOSE_CODE_SIGNING "Ensures software came from software publisher\nProtects software from alteration after publication"
@@ -209,7 +216,8 @@ IDD_IMPORT_WELCOME DIALOG DISCARDABLE 0,0,317,143
 CAPTION "Certificate Import Wizard"
 FONT 8, "MS Shell Dlg"
 BEGIN
-  LTEXT "Welcome to the Certificate Import Wizard", IDC_IMPORT_TITLE, 115,1,195,24
+  LTEXT "Welcome to the Certificate Import Wizard", IDC_IMPORT_TITLE,
+    115,1,195,24
   LTEXT "This wizard helps you import certificates, certificate revocation lists, and certificate trust lists from a file to a certificate store.",
     stc1, 115,33,195,16
   LTEXT "A certificate can be used to identify you or the computer with which you are communicating.  It can also be used for authentication, and to sign messages.  Certificate stores are collections of certificates, certificate revocation lists, and certificate trust lists.",
@@ -251,7 +259,8 @@ IDD_IMPORT_FINISH DIALOG DISCARDABLE 0,0,317,143
 CAPTION "Certificate Import Wizard"
 FONT 8, "MS Shell Dlg"
 BEGIN
-  LTEXT "Completing the Certificate Import Wizard", IDC_IMPORT_TITLE, 115,1,195,24
+  LTEXT "Completing the Certificate Import Wizard", IDC_IMPORT_TITLE,
+    115,1,195,24
   LTEXT "You have successfully completed the Certificate Import Wizard.",
     stc1, 115,33,195,24
   LTEXT "You have specified the following settings:",
index 0fffb83d652432ffa40a1bde2cda0f5e5b3fd679..9abfe4956f77584fb78830815211eefc501c4256 100644 (file)
 #define IDS_IMPORT_FILE_SUBTITLE 1046
 #define IDS_IMPORT_STORE_TITLE 1047
 #define IDS_IMPORT_STORE_SUBTITLE 1048
+#define IDS_IMPORT_FILTER_CERT 1049
+#define IDS_IMPORT_FILTER_PFX 1050
+#define IDS_IMPORT_FILTER_CRL 1051
+#define IDS_IMPORT_FILTER_CTL 1052
+#define IDS_IMPORT_FILTER_SERIALIZED_STORE 1053
+#define IDS_IMPORT_FILTER_CMS 1054
+#define IDS_IMPORT_FILTER_ALL 1055
 
 #define IDS_PURPOSE_SERVER_AUTH 1100
 #define IDS_PURPOSE_CLIENT_AUTH 1101
index c7f8286cd3f46573fbca48bdce761f3311d1c638..074d8bec2241b5609f6996ddd6e2d09b88f1e60e 100644 (file)
@@ -32,6 +32,7 @@
 #include "richedit.h"
 #include "ole2.h"
 #include "richole.h"
+#include "commdlg.h"
 #include "commctrl.h"
 #include "cryptuiapi.h"
 #include "cryptuires.h"
@@ -3695,13 +3696,95 @@ static LRESULT CALLBACK import_welcome_dlg_proc(HWND hwnd, UINT msg, WPARAM wp,
     return ret;
 }
 
+static const WCHAR filter_cert[] = { '*','.','c','e','r',';','*','.',
+ 'c','r','t',0 };
+static const WCHAR filter_pfx[] = { '*','.','p','f','x',';','*','.',
+ 'p','1','2',0 };
+static const WCHAR filter_crl[] = { '*','.','c','r','l',0 };
+static const WCHAR filter_ctl[] = { '*','.','s','t','l',0 };
+static const WCHAR filter_serialized_store[] = { '*','.','s','s','t',0 };
+static const WCHAR filter_cms[] = { '*','.','s','p','c',';','*','.',
+ 'p','7','b',0 };
+static const WCHAR filter_all[] = { '*','.','*',0 };
+
+struct StringToFilter
+{
+    int     id;
+    DWORD   allowFlags;
+    LPCWSTR filter;
+} import_filters[] = {
+ { IDS_IMPORT_FILTER_CERT, CRYPTUI_WIZ_IMPORT_ALLOW_CERT, filter_cert },
+ { IDS_IMPORT_FILTER_PFX, 0, filter_pfx },
+ { IDS_IMPORT_FILTER_CRL, CRYPTUI_WIZ_IMPORT_ALLOW_CRL, filter_crl },
+ { IDS_IMPORT_FILTER_CTL, CRYPTUI_WIZ_IMPORT_ALLOW_CTL, filter_ctl },
+ { IDS_IMPORT_FILTER_SERIALIZED_STORE, 0, filter_serialized_store },
+ { IDS_IMPORT_FILTER_CMS, 0, filter_cms },
+ { IDS_IMPORT_FILTER_ALL, 0, filter_all },
+};
+
+static WCHAR *make_import_file_filter(DWORD dwFlags)
+{
+    DWORD i;
+    int len, totalLen = 2;
+    LPWSTR filter = NULL, str;
+
+    for (i = 0; i < sizeof(import_filters) / sizeof(import_filters[0]); i++)
+    {
+        if (!import_filters[i].allowFlags || !dwFlags ||
+         (dwFlags & import_filters[i].allowFlags))
+        {
+            len = LoadStringW(hInstance, import_filters[i].id, (LPWSTR)&str, 0);
+            totalLen += len + strlenW(import_filters[i].filter) + 2;
+        }
+    }
+    filter = HeapAlloc(GetProcessHeap(), 0, totalLen * sizeof(WCHAR));
+    if (filter)
+    {
+        LPWSTR ptr;
+
+        ptr = filter;
+        for (i = 0; i < sizeof(import_filters) / sizeof(import_filters[0]); i++)
+        {
+            if (!import_filters[i].allowFlags || !dwFlags ||
+             (dwFlags & import_filters[i].allowFlags))
+            {
+                len = LoadStringW(hInstance, import_filters[i].id,
+                 (LPWSTR)&str, 0);
+                memcpy(ptr, str, len * sizeof(WCHAR));
+                ptr += len;
+                *ptr++ = 0;
+                strcpyW(ptr, import_filters[i].filter);
+                ptr += strlenW(import_filters[i].filter) + 1;
+            }
+        }
+        *ptr++ = 0;
+    }
+    return filter;
+}
+
+struct ImportWizData
+{
+    DWORD dwFlags;
+    PCCRYPTUI_WIZ_IMPORT_SRC_INFO pImportSrc;
+    HCERTSTORE hDestCertStore;
+};
+
 static LRESULT CALLBACK import_file_dlg_proc(HWND hwnd, UINT msg, WPARAM wp,
  LPARAM lp)
 {
     LRESULT ret = 0;
+    struct ImportWizData *data;
 
     switch (msg)
     {
+    case WM_INITDIALOG:
+    {
+        PROPSHEETPAGEW *page = (PROPSHEETPAGEW *)lp;
+
+        data = (struct ImportWizData *)page->lParam;
+        SetWindowLongPtrW(hwnd, DWLP_USER, (LPARAM)data);
+        break;
+    }
     case WM_NOTIFY:
     {
         NMHDR *hdr = (NMHDR *)lp;
@@ -3716,6 +3799,30 @@ static LRESULT CALLBACK import_file_dlg_proc(HWND hwnd, UINT msg, WPARAM wp,
         }
         break;
     }
+    case WM_COMMAND:
+        switch (wp)
+        {
+        case IDC_IMPORT_BROWSE_FILE:
+        {
+            OPENFILENAMEW ofn;
+            WCHAR fileBuf[MAX_PATH];
+
+            data = (struct ImportWizData *)GetWindowLongPtrW(hwnd, DWLP_USER);
+            memset(&ofn, 0, sizeof(ofn));
+            ofn.lStructSize = sizeof(ofn);
+            ofn.hwndOwner = hwnd;
+            ofn.lpstrFilter = make_import_file_filter(data->dwFlags);
+            ofn.lpstrFile = fileBuf;
+            ofn.nMaxFile = sizeof(fileBuf) / sizeof(fileBuf[0]);
+            fileBuf[0] = 0;
+            if (GetOpenFileNameW(&ofn))
+                SendMessageW(GetDlgItem(hwnd, IDC_IMPORT_FILENAME), WM_SETTEXT,
+                 0, (LPARAM)ofn.lpstrFile);
+            HeapFree(GetProcessHeap(), 0, (LPWSTR)ofn.lpstrFilter);
+            break;
+        }
+        }
+        break;
     }
     return ret;
 }
@@ -3776,6 +3883,7 @@ static BOOL show_import_ui(DWORD dwFlags, HWND hwndParent,
 {
     PROPSHEETHEADERW hdr;
     PROPSHEETPAGEW pages[4];
+    struct ImportWizData data = { dwFlags, pImportSrc, hDestCertStore };
 
     FIXME("\n");
 
@@ -3794,6 +3902,7 @@ static BOOL show_import_ui(DWORD dwFlags, HWND hwndParent,
     pages[1].dwFlags = PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
     pages[1].pszHeaderTitle = MAKEINTRESOURCEW(IDS_IMPORT_FILE_TITLE);
     pages[1].pszHeaderSubTitle = MAKEINTRESOURCEW(IDS_IMPORT_FILE_SUBTITLE);
+    pages[1].lParam = (LPARAM)&data;
 
     pages[2].dwSize = sizeof(pages[2]);
     pages[2].hInstance = hInstance;