/[openpgpmdrv]/trunk/OpenPGPminidriverTest/PublicDataOperations.cpp
ViewVC logotype

Contents of /trunk/OpenPGPminidriverTest/PublicDataOperations.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (show annotations)
Thu Mar 11 20:32:26 2010 UTC (15 years, 1 month ago) by vletoux
File size: 3756 byte(s)
improvement of the quality of the project.
More test for the qualification of the driver success but not all ...

1 /* OpenPGP Smart Card Mini Driver
2 Copyright (C) 2009 Vincent Le Toux
3
4 This library is Free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License version 2.1 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Lesser General Public License for more details.
12
13 You should have received a copy of the GNU Lesser General Public
14 License along with this library; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18 #include <windows.h>
19 #include <tchar.h>
20 #include <stdio.h>
21 #include <cardmod.h>
22 #include "global.h"
23 #include "dialog.h"
24
25
26 DWORD ListFiles(HWND hWnd, PSTR szDirectory)
27 {
28 DWORD dwReturn = 0, dwSize;
29 LPSTR pszFiles = NULL;
30
31 dwSize = 0;
32 dwReturn = pCardData->pfnCardEnumFiles(pCardData, szDirectory, &pszFiles, &dwSize, 0);
33 if (!dwReturn)
34 {
35 LPSTR szCurrentFile = pszFiles;
36 while (szCurrentFile[0] != 0)
37 {
38 CHAR szText[256];
39 if (szDirectory)
40 {
41 sprintf_s(szText, ARRAYSIZE(szText),"%s\\%s",szDirectory, szCurrentFile);
42 }
43 else
44 {
45 sprintf_s(szText, ARRAYSIZE(szText),"%s",szCurrentFile);
46 }
47 SendDlgItemMessageA(hWnd,IDC_FILES,LB_ADDSTRING,0,(LPARAM)szText);
48 if (_stricmp(szCurrentFile,"cardapps") == 0)
49 {
50 PBYTE pbData = NULL;
51 dwSize = 0;
52 dwReturn = pCardData->pfnCardReadFile(pCardData, szDirectory, szCurrentFile, 0, &pbData, &dwSize);
53 if (dwReturn == 0)
54 {
55 CHAR szDirectory[9];
56 for (DWORD dwI = 0; dwI < dwSize; dwI+=8)
57 {
58 memcpy(szDirectory, pbData + dwI, 8);
59 szDirectory[8] = 0;
60 ListFiles(hWnd, szDirectory);
61 }
62
63 pCardData->pfnCspFree(pbData);
64 }
65 }
66
67 szCurrentFile = szCurrentFile + strlen(szCurrentFile)+1;
68 }
69 pCardData->pfnCspFree(pszFiles);
70 }
71 return dwReturn;
72 }
73
74 DWORD ListFiles(HWND hWnd)
75 {
76 if (!pCardData)
77 {
78 return SCARD_E_COMM_DATA_LOST;
79 }
80 SendMessage(GetDlgItem(hWnd, IDC_FILES),LB_RESETCONTENT,0,0);
81 return ListFiles(hWnd, NULL);
82 }
83
84 DWORD ViewFile(HWND hWnd)
85 {
86 CHAR szFileName[256];
87 PSTR szFile, szDirectory;
88 DWORD dwReturn;
89 PBYTE pbData = NULL;
90 DWORD dwSize;
91 TCHAR szData[10];
92 __try
93 {
94 // clear text
95 SendMessage( GetDlgItem(hWnd, IDC_CONTENT), WM_SETTEXT,0,(LPARAM) "");
96
97 DWORD iItem = (DWORD)SendMessage(GetDlgItem(hWnd, IDC_FILES),LB_GETCURSEL,0,0);
98 if (iItem == LB_ERR)
99 {
100 dwReturn = SCARD_E_COMM_DATA_LOST;
101 __leave;
102 }
103 if (!pCardData)
104 {
105 dwReturn = SCARD_E_COMM_DATA_LOST;
106 __leave;
107 }
108 SendMessageA( GetDlgItem(hWnd,IDC_FILES), LB_GETTEXT,iItem,(LPARAM)szFileName);
109 szFile = strchr(szFileName,'\\');
110 if (szFile)
111 {
112 *szFile = 0;
113 szFile++;
114 szDirectory = szFileName;
115 }
116 else
117 {
118 szDirectory = NULL;
119 szFile = szFileName;
120 }
121 dwReturn = pCardData->pfnCardReadFile(pCardData,szDirectory,szFile, 0, &pbData, &dwSize);
122 if (dwReturn)
123 {
124 __leave;
125 }
126 for(DWORD dwI = 0; dwI < dwSize; dwI++)
127 {
128 _stprintf_s(szData,ARRAYSIZE(szData),TEXT("%02X "),pbData[dwI]);
129 SendMessage( // returns LRESULT in lResult
130 GetDlgItem(hWnd, IDC_CONTENT), // (HWND) handle to destination control
131 EM_REPLACESEL, // (UINT) message ID
132 FALSE, // = () wParam;
133 (LPARAM)szData // = (LPARAM)(LPCTSTR) lParam;
134 );
135
136 }
137 }
138 __finally
139 {
140 if (pbData)
141 pCardData->pfnCspFree(pbData);
142 }
143 return 0;
144 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26