summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurus Cuelenaere <mcuelenaere@gmail.com>2008-08-27 23:07:08 +0000
committerMaurus Cuelenaere <mcuelenaere@gmail.com>2008-08-27 23:07:08 +0000
commit79177edfb2bb5e934c1630d723a0032c995942d7 (patch)
tree608f77faf1b21a5cddb1d6eb4b8b6d2f1a061262
parente320446f0e74fcc6c5a216e20d3cd499a70658b3 (diff)
downloadrockbox-79177edfb2bb5e934c1630d723a0032c995942d7.tar.gz
rockbox-79177edfb2bb5e934c1630d723a0032c995942d7.zip
MTP:
* Add Win32 progress callback reporting support git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18355 a1c6a512-1295-4272-9138-f99709370657
-rwxr-xr-xutils/MTP/MTP_DLL.dllbin90112 -> 90112 bytes
-rw-r--r--utils/MTP/MTP_DLL/MTP_DLL.cpp2
-rw-r--r--utils/MTP/MTP_DLL/MTP_DLL.h6
-rw-r--r--utils/MTP/MTP_DLL/sendfirm_win.cpp244
-rw-r--r--utils/MTP/MTP_DLL/stdafx.h18
-rw-r--r--utils/MTP/sendfirm_win.c17
6 files changed, 185 insertions, 102 deletions
diff --git a/utils/MTP/MTP_DLL.dll b/utils/MTP/MTP_DLL.dll
index 3f9b6c7a50..448dff430a 100755
--- a/utils/MTP/MTP_DLL.dll
+++ b/utils/MTP/MTP_DLL.dll
Binary files differ
diff --git a/utils/MTP/MTP_DLL/MTP_DLL.cpp b/utils/MTP/MTP_DLL/MTP_DLL.cpp
index 8d8e2502c9..ffd314a697 100644
--- a/utils/MTP/MTP_DLL/MTP_DLL.cpp
+++ b/utils/MTP/MTP_DLL/MTP_DLL.cpp
@@ -12,7 +12,7 @@
12BOOL APIENTRY DllMain( HMODULE hModule, 12BOOL APIENTRY DllMain( HMODULE hModule,
13 DWORD ul_reason_for_call, 13 DWORD ul_reason_for_call,
14 LPVOID lpReserved 14 LPVOID lpReserved
15 ) 15 )
16{ 16{
17 return TRUE; 17 return TRUE;
18} 18}
diff --git a/utils/MTP/MTP_DLL/MTP_DLL.h b/utils/MTP/MTP_DLL/MTP_DLL.h
index 45352830a3..ad99014bc2 100644
--- a/utils/MTP/MTP_DLL/MTP_DLL.h
+++ b/utils/MTP/MTP_DLL/MTP_DLL.h
@@ -10,6 +10,8 @@
10#define MTP_DLL_API __declspec(dllimport) 10#define MTP_DLL_API __declspec(dllimport)
11#endif 11#endif
12 12
13extern "C" { 13extern "C"
14__declspec(dllexport) bool send_fw(LPWSTR file, int filesize); 14{
15__declspec(dllexport) bool send_fw(LPWSTR file, int filesize, void (*callback)(unsigned int progress, unsigned int max));
15} 16}
17
diff --git a/utils/MTP/MTP_DLL/sendfirm_win.cpp b/utils/MTP/MTP_DLL/sendfirm_win.cpp
index e895c024fd..0861b345b0 100644
--- a/utils/MTP/MTP_DLL/sendfirm_win.cpp
+++ b/utils/MTP/MTP_DLL/sendfirm_win.cpp
@@ -11,6 +11,26 @@
11#include "sac.h" 11#include "sac.h"
12#include "scclient.h" 12#include "scclient.h"
13 13
14class CProgressHelper :
15 public IWMDMProgress
16{
17 void (*m_callback)(unsigned int progress, unsigned int max);
18 DWORD m_max_ticks;
19 DWORD m_cur_ticks;
20 DWORD m_counter;
21
22public:
23 CProgressHelper( void (*callback)(unsigned int progress, unsigned int max) );
24 ~CProgressHelper();
25 STDMETHOD(Begin)( DWORD dwEstimatedTicks );
26 STDMETHOD(Progress)( DWORD dwTranspiredTicks );
27 STDMETHOD(End)();
28
29 STDMETHOD(QueryInterface) ( REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject );
30 STDMETHOD_(ULONG, AddRef)( void );
31 STDMETHOD_(ULONG, Release)( void );
32};
33
14/* 34/*
15 * Compilation requirements: 35 * Compilation requirements:
16 * 36 *
@@ -21,74 +41,66 @@
21 * 41 *
22 */ 42 */
23extern "C" { 43extern "C" {
24__declspec(dllexport) bool send_fw(LPWSTR file, int filesize) 44__declspec(dllexport) bool send_fw(LPWSTR file, int filesize, void (*callback)(unsigned int progress, unsigned int max))
25{ 45{
26 bool return_value = false; 46 bool return_value = false;
27 HRESULT hr; 47 HRESULT hr;
28 IComponentAuthenticate* pICompAuth; 48 IComponentAuthenticate* pICompAuth;
29 CSecureChannelClient *m_pSacClient = new CSecureChannelClient; 49 CSecureChannelClient *m_pSacClient = new CSecureChannelClient;
30 IWMDeviceManager3* m_pIdvMgr = NULL; 50 IWMDeviceManager3* m_pIdvMgr = NULL;
31 51
32 /* these are generic keys */ 52 /* these are generic keys */
33 BYTE abPVK[] = {0x00}; 53 BYTE abPVK[] = {0x00};
34 BYTE abCert[] = {0x00}; 54 BYTE abCert[] = {0x00};
35 55
36 CoInitialize(NULL); 56 CoInitialize(NULL);
37 57
38 /* get an authentication interface */ 58 /* get an authentication interface */
39 hr = CoCreateInstance(CLSID_MediaDevMgr, NULL, CLSCTX_ALL ,IID_IComponentAuthenticate, (void **)&pICompAuth); 59 hr = CoCreateInstance(CLSID_MediaDevMgr, NULL, CLSCTX_ALL ,IID_IComponentAuthenticate, (void **)&pICompAuth);
40 if SUCCEEDED(hr) 60 if SUCCEEDED(hr)
41 { 61 {
42 /* create a secure channel client certificate */ 62 /* create a secure channel client certificate */
43 hr = m_pSacClient->SetCertificate(SAC_CERT_V1, (BYTE*) abCert, sizeof(abCert), (BYTE*) abPVK, sizeof(abPVK)); 63 hr = m_pSacClient->SetCertificate(SAC_CERT_V1, (BYTE*) abCert, sizeof(abCert), (BYTE*) abPVK, sizeof(abPVK));
44 if SUCCEEDED(hr) 64 if SUCCEEDED(hr)
45 { 65 {
46 /* bind the authentication interface to the secure channel client */ 66 /* bind the authentication interface to the secure channel client */
47 m_pSacClient->SetInterface(pICompAuth); 67 m_pSacClient->SetInterface(pICompAuth);
48 68
49 /* trigger communication */ 69 /* trigger communication */
50 hr = m_pSacClient->Authenticate(SAC_PROTOCOL_V1); 70 hr = m_pSacClient->Authenticate(SAC_PROTOCOL_V1);
51 if SUCCEEDED(hr) 71 if SUCCEEDED(hr)
52 { 72 {
53 /* get main interface to media device manager */ 73 /* get main interface to media device manager */
54 hr = pICompAuth->QueryInterface(IID_IWMDeviceManager2, (void**)&m_pIdvMgr); 74 hr = pICompAuth->QueryInterface(IID_IWMDeviceManager2, (void**)&m_pIdvMgr);
55 if SUCCEEDED(hr) 75 if SUCCEEDED(hr)
56 { 76 {
57 /* enumerate devices... */ 77 /* enumerate devices... */
58 IWMDMEnumDevice *pIEnumDev; 78 IWMDMEnumDevice *pIEnumDev;
59 hr = m_pIdvMgr->EnumDevices2(&pIEnumDev); 79 hr = m_pIdvMgr->EnumDevices2(&pIEnumDev);
60 if SUCCEEDED(hr) 80 if SUCCEEDED(hr)
61 { 81 {
62 hr = pIEnumDev->Reset(); /* Next will now return the first device */ 82 hr = pIEnumDev->Reset(); /* Next will now return the first device */
63 if SUCCEEDED(hr) 83 if SUCCEEDED(hr)
64 { 84 {
65 IWMDMDevice3* pIDevice; 85 IWMDMDevice3* pIDevice;
66 unsigned long ulNumFetched; 86 unsigned long ulNumFetched;
67 hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched); 87 hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched);
68 while (SUCCEEDED(hr) && (hr != S_FALSE)) 88 while (SUCCEEDED(hr) && (hr != S_FALSE))
69 { 89 {
70#if 0 90 /* get storage info */
71 /* output device name */ 91 DWORD tempDW;
72 wchar_t pwsString[256]; 92 pIDevice->GetType(&tempDW);
73 hr = pIDevice->GetName(pwsString, 256); 93 if (tempDW & WMDM_DEVICE_TYPE_STORAGE)
74 if SUCCEEDED(hr)
75 wprintf(L"Found device %s\n", pwsString);
76#endif
77
78 /* get storage info */
79 DWORD tempDW;
80 pIDevice->GetType(&tempDW);
81 if (tempDW & WMDM_DEVICE_TYPE_STORAGE)
82 { 94 {
83 IWMDMEnumStorage *pIEnumStorage = NULL; 95 IWMDMEnumStorage *pIEnumStorage = NULL;
84 IWMDMStorage *pIStorage = NULL; 96 IWMDMStorage *pIStorage = NULL;
85 IWMDMStorage3 *pIFileStorage = NULL; 97 IWMDMStorage3 *pIFileStorage = NULL;
86 hr = pIDevice->EnumStorage(&pIEnumStorage); 98 hr = pIDevice->EnumStorage(&pIEnumStorage);
87 if SUCCEEDED(hr) 99 if SUCCEEDED(hr)
88 { 100 {
89 pIEnumStorage->Reset(); 101 pIEnumStorage->Reset();
90 hr = pIEnumStorage->Next(1, (IWMDMStorage **)&pIStorage, &ulNumFetched); 102 hr = pIEnumStorage->Next(1, (IWMDMStorage **)&pIStorage, &ulNumFetched);
91 while (SUCCEEDED(hr) && (hr != S_FALSE)) 103 while (SUCCEEDED(hr) && (hr != S_FALSE))
92 { 104 {
93 IWMDMStorage3 *pNewStorage; 105 IWMDMStorage3 *pNewStorage;
94 hr = pIStorage->QueryInterface(IID_IWMDMStorage3, (void **)&pNewStorage); 106 hr = pIStorage->QueryInterface(IID_IWMDMStorage3, (void **)&pNewStorage);
@@ -113,14 +125,15 @@ __declspec(dllexport) bool send_fw(LPWSTR file, int filesize)
113 if (SUCCEEDED(hr)) 125 if (SUCCEEDED(hr))
114 { 126 {
115 IWMDMStorage *pNewObject = NULL; 127 IWMDMStorage *pNewObject = NULL;
128 CProgressHelper *progress = new CProgressHelper(callback);
116 129
117 hr = pIWMDMStorageControl->Insert3( 130 hr = pIWMDMStorageControl->Insert3(
118 WMDM_MODE_BLOCK | WMDM_CONTENT_FILE, 131 WMDM_MODE_BLOCK | WMDM_CONTENT_FILE | WMDM_MODE_PROGRESS,
119 0, 132 0,
120 file, 133 file,
121 NULL, 134 NULL,
122 NULL, 135 NULL,
123 NULL, 136 (callback == NULL ? NULL : (IWMDMProgress*)progress),
124 pIWMDMMetaData, 137 pIWMDMMetaData,
125 NULL, 138 NULL,
126 (IWMDMStorage **)&pNewObject); 139 (IWMDMStorage **)&pNewObject);
@@ -135,27 +148,88 @@ __declspec(dllexport) bool send_fw(LPWSTR file, int filesize)
135 } 148 }
136 } 149 }
137 } 150 }
138 } 151 }
139 } 152 }
140 pIEnumStorage->Release(); 153 pIEnumStorage->Release();
141 } 154 }
142 155
143 /* move to next device */ 156 /* move to next device */
144 if(!return_value) 157 if(!return_value)
145 hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched); 158 hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched);
146 } 159 }
147 pIEnumDev->Release(); 160 pIEnumDev->Release();
148 } 161 }
149 m_pIdvMgr->Release(); 162 m_pIdvMgr->Release();
150 } 163 }
151 pICompAuth->Release(); 164 pICompAuth->Release();
152 } 165 }
153 } 166 }
154 } 167 }
155 } 168 }
156 169
157 CoUninitialize(); 170 CoUninitialize();
158 171
159 return return_value; 172 return return_value;
173}
174}
175
176
177CProgressHelper::CProgressHelper( void (*callback)(unsigned int progress, unsigned int max) )
178{
179 m_cur_ticks = 0;
180 m_max_ticks = 0;
181 m_counter = 0;
182
183 m_callback = callback;
184}
185
186CProgressHelper::~CProgressHelper()
187{
160} 188}
189
190HRESULT CProgressHelper::Begin( DWORD dwEstimatedTicks )
191{
192 m_max_ticks = dwEstimatedTicks;
193
194 return S_OK;
195}
196
197HRESULT CProgressHelper::Progress( DWORD dwTranspiredTicks )
198{
199 m_cur_ticks = dwTranspiredTicks;
200
201 if(m_callback != NULL)
202 m_callback(m_cur_ticks, max(m_max_ticks, m_cur_ticks));
203
204 return S_OK;
205}
206
207HRESULT CProgressHelper::End()
208{
209 m_cur_ticks = m_max_ticks;
210
211 return S_OK;
212}
213
214HRESULT CProgressHelper::QueryInterface( REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject )
215{
216 if(riid == IID_IWMDMProgress || riid == IID_IUnknown)
217 {
218 *ppvObject = this;
219 return S_OK;
220 }
221 else
222 {
223 *ppvObject = NULL;
224 return E_NOINTERFACE;
225 }
226}
227
228ULONG CProgressHelper::AddRef()
229{
230 return m_counter++;
231}
232ULONG CProgressHelper::Release()
233{
234 return m_counter--;
161} 235}
diff --git a/utils/MTP/MTP_DLL/stdafx.h b/utils/MTP/MTP_DLL/stdafx.h
index a13982c634..1734058361 100644
--- a/utils/MTP/MTP_DLL/stdafx.h
+++ b/utils/MTP/MTP_DLL/stdafx.h
@@ -7,23 +7,23 @@
7 7
8// Modify the following defines if you have to target a platform prior to the ones specified below. 8// Modify the following defines if you have to target a platform prior to the ones specified below.
9// Refer to MSDN for the latest info on corresponding values for different platforms. 9// Refer to MSDN for the latest info on corresponding values for different platforms.
10#ifndef WINVER // Allow use of features specific to Windows XP or later. 10#ifndef WINVER // Allow use of features specific to Windows XP or later.
11#define WINVER 0x0501 // Change this to the appropriate value to target other versions of Windows. 11#define WINVER 0x0501 // Change this to the appropriate value to target other versions of Windows.
12#endif 12#endif
13 13
14#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later. 14#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
15#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows. 15#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
16#endif 16#endif
17 17
18#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later. 18#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
19#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. 19#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
20#endif 20#endif
21 21
22#ifndef _WIN32_IE // Allow use of features specific to IE 6.0 or later. 22#ifndef _WIN32_IE // Allow use of features specific to IE 6.0 or later.
23#define _WIN32_IE 0x0600 // Change this to the appropriate value to target other versions of IE. 23#define _WIN32_IE 0x0600 // Change this to the appropriate value to target other versions of IE.
24#endif 24#endif
25 25
26#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 26#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
27// Windows Header Files: 27// Windows Header Files:
28#include <windows.h> 28#include <windows.h>
29 29
diff --git a/utils/MTP/sendfirm_win.c b/utils/MTP/sendfirm_win.c
index e605d47d0c..c16a7ab68b 100644
--- a/utils/MTP/sendfirm_win.c
+++ b/utils/MTP/sendfirm_win.c
@@ -28,7 +28,7 @@
28#include <wchar.h> 28#include <wchar.h>
29#include <stdbool.h> 29#include <stdbool.h>
30 30
31extern __declspec(dllimport) bool send_fw(LPWSTR file, int filesize); 31extern __declspec(dllimport) bool send_fw(LPWSTR file, int filesize, void (*callback)(unsigned int progress, unsigned int max));
32 32
33void usage(void) 33void usage(void)
34{ 34{
@@ -37,9 +37,9 @@ void usage(void)
37 37
38int filesize(char* filename) 38int filesize(char* filename)
39{ 39{
40 FILE* fd; 40 FILE* fd;
41 int tmp; 41 int tmp;
42 fd = fopen(filename, "r"); 42 fd = fopen(filename, "r");
43 if(fd == NULL) 43 if(fd == NULL)
44 { 44 {
45 fprintf(stderr, "Error while opening %s!\n", filename); 45 fprintf(stderr, "Error while opening %s!\n", filename);
@@ -47,10 +47,17 @@ int filesize(char* filename)
47 } 47 }
48 fseek(fd, 0, SEEK_END); 48 fseek(fd, 0, SEEK_END);
49 tmp = ftell(fd); 49 tmp = ftell(fd);
50 fclose(fd); 50 fclose(fd);
51 return tmp; 51 return tmp;
52} 52}
53 53
54void callback(unsigned int progress, unsigned int max)
55{
56 unsigned int normalized = progress*1000/max;
57 printf("Progress: %d.%d%%\r", normalized/10, normalized%10);
58 fflush(stdout);
59}
60
54int main(int argc, char **argv) 61int main(int argc, char **argv)
55{ 62{
56 if (argc < 2) 63 if (argc < 2)
@@ -69,7 +76,7 @@ int main(int argc, char **argv)
69 76
70 fprintf(stdout, "Sending firmware...\n"); 77 fprintf(stdout, "Sending firmware...\n");
71 78
72 if(send_fw(tmp, filesize(argv[1]))) 79 if(send_fw(tmp, filesize(argv[1]), &callback))
73 fprintf(stdout, "Firmware sent successfully!\n"); 80 fprintf(stdout, "Firmware sent successfully!\n");
74 else 81 else
75 fprintf(stdout, "Error occured during sending!\n"); 82 fprintf(stdout, "Error occured during sending!\n");