forked from len0rd/rockbox
MTP:
* Add Win32 progress callback reporting support git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18355 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
e320446f0e
commit
79177edfb2
6 changed files with 178 additions and 95 deletions
Binary file not shown.
|
@ -10,6 +10,8 @@
|
|||
#define MTP_DLL_API __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
__declspec(dllexport) bool send_fw(LPWSTR file, int filesize);
|
||||
extern "C"
|
||||
{
|
||||
__declspec(dllexport) bool send_fw(LPWSTR file, int filesize, void (*callback)(unsigned int progress, unsigned int max));
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,26 @@
|
|||
#include "sac.h"
|
||||
#include "scclient.h"
|
||||
|
||||
class CProgressHelper :
|
||||
public IWMDMProgress
|
||||
{
|
||||
void (*m_callback)(unsigned int progress, unsigned int max);
|
||||
DWORD m_max_ticks;
|
||||
DWORD m_cur_ticks;
|
||||
DWORD m_counter;
|
||||
|
||||
public:
|
||||
CProgressHelper( void (*callback)(unsigned int progress, unsigned int max) );
|
||||
~CProgressHelper();
|
||||
STDMETHOD(Begin)( DWORD dwEstimatedTicks );
|
||||
STDMETHOD(Progress)( DWORD dwTranspiredTicks );
|
||||
STDMETHOD(End)();
|
||||
|
||||
STDMETHOD(QueryInterface) ( REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject );
|
||||
STDMETHOD_(ULONG, AddRef)( void );
|
||||
STDMETHOD_(ULONG, Release)( void );
|
||||
};
|
||||
|
||||
/*
|
||||
* Compilation requirements:
|
||||
*
|
||||
|
@ -21,7 +41,7 @@
|
|||
*
|
||||
*/
|
||||
extern "C" {
|
||||
__declspec(dllexport) bool send_fw(LPWSTR file, int filesize)
|
||||
__declspec(dllexport) bool send_fw(LPWSTR file, int filesize, void (*callback)(unsigned int progress, unsigned int max))
|
||||
{
|
||||
bool return_value = false;
|
||||
HRESULT hr;
|
||||
|
@ -67,14 +87,6 @@ __declspec(dllexport) bool send_fw(LPWSTR file, int filesize)
|
|||
hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched);
|
||||
while (SUCCEEDED(hr) && (hr != S_FALSE))
|
||||
{
|
||||
#if 0
|
||||
/* output device name */
|
||||
wchar_t pwsString[256];
|
||||
hr = pIDevice->GetName(pwsString, 256);
|
||||
if SUCCEEDED(hr)
|
||||
wprintf(L"Found device %s\n", pwsString);
|
||||
#endif
|
||||
|
||||
/* get storage info */
|
||||
DWORD tempDW;
|
||||
pIDevice->GetType(&tempDW);
|
||||
|
@ -113,14 +125,15 @@ __declspec(dllexport) bool send_fw(LPWSTR file, int filesize)
|
|||
if (SUCCEEDED(hr))
|
||||
{
|
||||
IWMDMStorage *pNewObject = NULL;
|
||||
CProgressHelper *progress = new CProgressHelper(callback);
|
||||
|
||||
hr = pIWMDMStorageControl->Insert3(
|
||||
WMDM_MODE_BLOCK | WMDM_CONTENT_FILE,
|
||||
WMDM_MODE_BLOCK | WMDM_CONTENT_FILE | WMDM_MODE_PROGRESS,
|
||||
0,
|
||||
file,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
(callback == NULL ? NULL : (IWMDMProgress*)progress),
|
||||
pIWMDMMetaData,
|
||||
NULL,
|
||||
(IWMDMStorage **)&pNewObject);
|
||||
|
@ -159,3 +172,64 @@ __declspec(dllexport) bool send_fw(LPWSTR file, int filesize)
|
|||
return return_value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CProgressHelper::CProgressHelper( void (*callback)(unsigned int progress, unsigned int max) )
|
||||
{
|
||||
m_cur_ticks = 0;
|
||||
m_max_ticks = 0;
|
||||
m_counter = 0;
|
||||
|
||||
m_callback = callback;
|
||||
}
|
||||
|
||||
CProgressHelper::~CProgressHelper()
|
||||
{
|
||||
}
|
||||
|
||||
HRESULT CProgressHelper::Begin( DWORD dwEstimatedTicks )
|
||||
{
|
||||
m_max_ticks = dwEstimatedTicks;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CProgressHelper::Progress( DWORD dwTranspiredTicks )
|
||||
{
|
||||
m_cur_ticks = dwTranspiredTicks;
|
||||
|
||||
if(m_callback != NULL)
|
||||
m_callback(m_cur_ticks, max(m_max_ticks, m_cur_ticks));
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CProgressHelper::End()
|
||||
{
|
||||
m_cur_ticks = m_max_ticks;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CProgressHelper::QueryInterface( REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject )
|
||||
{
|
||||
if(riid == IID_IWMDMProgress || riid == IID_IUnknown)
|
||||
{
|
||||
*ppvObject = this;
|
||||
return S_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ppvObject = NULL;
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
}
|
||||
|
||||
ULONG CProgressHelper::AddRef()
|
||||
{
|
||||
return m_counter++;
|
||||
}
|
||||
ULONG CProgressHelper::Release()
|
||||
{
|
||||
return m_counter--;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include <wchar.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
extern __declspec(dllimport) bool send_fw(LPWSTR file, int filesize);
|
||||
extern __declspec(dllimport) bool send_fw(LPWSTR file, int filesize, void (*callback)(unsigned int progress, unsigned int max));
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
|
@ -51,6 +51,13 @@ int filesize(char* filename)
|
|||
return tmp;
|
||||
}
|
||||
|
||||
void callback(unsigned int progress, unsigned int max)
|
||||
{
|
||||
unsigned int normalized = progress*1000/max;
|
||||
printf("Progress: %d.%d%%\r", normalized/10, normalized%10);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
|
@ -69,7 +76,7 @@ int main(int argc, char **argv)
|
|||
|
||||
fprintf(stdout, "Sending firmware...\n");
|
||||
|
||||
if(send_fw(tmp, filesize(argv[1])))
|
||||
if(send_fw(tmp, filesize(argv[1]), &callback))
|
||||
fprintf(stdout, "Firmware sent successfully!\n");
|
||||
else
|
||||
fprintf(stdout, "Error occured during sending!\n");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue