Initial community commit

This commit is contained in:
Jef
2024-09-24 14:54:57 +02:00
parent 537bcbc862
commit 20d28e80a5
16810 changed files with 4640254 additions and 2 deletions

View File

@ -0,0 +1,76 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_COMMON_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_COMMON_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#ifndef LONGX86
#ifdef _WIN64
#define LONGX86 LONG_PTR
#else /*_WIN64*/
#define LONGX86 LONG
#endif /*_WIN64*/
#endif // LONGX86
#define CSTR_INVARIANT MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT)
#ifdef __cplusplus
#define SENDMSG(__hwnd, __msgId, __wParam, __lParam) ::SendMessageW((__hwnd), (__msgId), (__wParam), (__lParam))
#else
#define SENDMSG(__hwnd, __msgId, __wParam, __lParam) SendMessageW((__hwnd), (__msgId), (__wParam), (__lParam))
#endif // __cplusplus
#define SENDMLIPC(__hwndML, __ipcMsgId, __param) SENDMSG((__hwndML), WM_ML_IPC, (WPARAM)(__param), (LPARAM)(__ipcMsgId))
#define SENDWAIPC(__hwndWA, __ipcMsgId, __param) SENDMSG((__hwndWA), WM_WA_IPC, (WPARAM)(__param), (LPARAM)(__ipcMsgId))
#define SENDCMD(__hwnd, __ctrlId, __eventId, __hctrl) (SENDMSG((__hwnd), WM_COMMAND, MAKEWPARAM(__ctrlId, __eventId), (LPARAM)(__hctrl)))
#define DIALOG_RESULT(__hwnd, __result) { SetWindowLongPtrW((__hwnd), DWLP_MSGRESULT, ((LONGX86)(LONG_PTR)(__result))); return TRUE; }
#ifndef GetWindowStyle
#define GetWindowStyle(__hwnd) ((UINT)GetWindowLongPtr((__hwnd), GWL_STYLE))
#endif //GetWindowStyle
#ifndef SetWindowStyle
#define SetWindowStyle(__hwnd, __style) (SetWindowLongPtr((__hwnd), GWL_STYLE, (__style)))
#endif //SetWindowStyle
#ifndef GetWindowStyleEx
#define GetWindowStyleEx(__hwnd) ((UINT)GetWindowLongPtr((__hwnd), GWL_EXSTYLE))
#endif // GetWindowStyleEx
#ifndef SetWindowStyleEx
#define SetWindowStyleEx(__hwnd, __style) (SetWindowLongPtr((__hwnd), GWL_EXSTYLE, (__style)))
#endif //SetWindowStyle
#ifndef RECTWIDTH
#define RECTWIDTH(__r) ((__r).right - (__r).left)
#endif
#ifndef RECTHEIGHT
#define RECTHEIGHT(__r) ((__r).bottom - (__r).top)
#endif
#undef CLAMP
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
#ifndef ARRAYSIZE
#define ARRAYSIZE(_a) (sizeof(_a)/sizeof((_a)[0]))
#endif
#ifndef ABS
#define ABS(x) (((x) > 0) ? (x) : (-x))
#endif
#ifndef MIN
#define MIN(v1, v2) (((v1) < (v2)) ? (v1) : (v2))
#endif
#ifndef MAX
#define MAX(v1, v2) (((v1) > (v2)) ? (v1) : (v2))
#endif
#endif //_NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_COMMON_HEADER

View File

@ -0,0 +1,871 @@
#include "main.h"
#include "./device.h"
#include <strsafe.h>
Device::Device()
: ref(1), name(NULL), type(NULL), connection(NULL), displayName(NULL),
totalSpace(0), usedSpace(0), attached(FALSE), hidden(FALSE),
connected(FALSE), activity(NULL), model(NULL), status(NULL)
{
InitializeCriticalSection(&lock);
if (NULL == WASABI_API_DEVICES ||
FAILED(WASABI_API_DEVICES->CreateDeviceEventManager(&eventManager)))
{
eventManager = NULL;
}
if (NULL == WASABI_API_DEVICES ||
FAILED(WASABI_API_DEVICES->CreateIconStore(&iconStore)))
{
iconStore = NULL;
}
if (NULL == WASABI_API_DEVICES ||
FAILED(WASABI_API_DEVICES->CreateSupportedCommandStore(&commands)))
{
commands = NULL;
}
}
Device::~Device()
{
DeviceActivity *activityCopy;
Lock();
if (NULL != activity)
{
activity->SetUser(NULL);
activityCopy = activity;
activityCopy->AddRef();
}
else
activityCopy = NULL;
AnsiString_Free(name);
AnsiString_Free(type);
AnsiString_Free(connection);
String_Free(displayName);
String_Free(model);
String_Free(status);
if (NULL != commands)
commands->Release();
if (NULL != iconStore)
iconStore->Release();
if (NULL != eventManager)
eventManager->Release();
Unlock();
if (NULL != activityCopy)
{
activityCopy->Stop();
activityCopy->Release();
}
DeleteCriticalSection(&lock);
}
HRESULT Device::CreateInstance(const char *name, const char *type, const char *connection, Device**instance)
{
Device *self;
if (NULL == instance)
return E_POINTER;
*instance = NULL;
self = new Device();
if (NULL == self)
return E_OUTOFMEMORY;
self->name = AnsiString_Duplicate(name);
self->type = AnsiString_Duplicate(type);
self->connection = AnsiString_Duplicate(connection);
*instance = self;
return S_OK;
}
size_t Device::AddRef()
{
return InterlockedIncrement((LONG*)&ref);
}
size_t Device::Release()
{
if (0 == ref)
return ref;
LONG r = InterlockedDecrement((LONG*)&ref);
if (0 == r)
delete(this);
return r;
}
int Device::QueryInterface(GUID interface_guid, void **object)
{
if (NULL == object)
return E_POINTER;
if (IsEqualIID(interface_guid, IFC_Device))
*object = static_cast<ifc_device*>(this);
else
{
*object = NULL;
return E_NOINTERFACE;
}
if (NULL == *object)
return E_UNEXPECTED;
AddRef();
return S_OK;
}
void Device::Lock()
{
EnterCriticalSection(&lock);
}
void Device::Unlock()
{
LeaveCriticalSection(&lock);
}
const char *Device::GetName()
{
return name;
}
const char *Device::GetType()
{
return type;
}
const char *Device::GetConnection()
{
return connection;
}
HRESULT Device::GetIcon(wchar_t *buffer, size_t bufferSize, int width, int height)
{
if (NULL == buffer)
return E_POINTER;
if (NULL == iconStore)
return E_UNEXPECTED;
return iconStore->Get(buffer, bufferSize, width, height);
}
HRESULT Device::GetDisplayName(wchar_t *buffer, size_t bufferSize)
{
HRESULT hr;
if (NULL == buffer)
return E_POINTER;
Lock();
if (0 == String_CopyTo(buffer, displayName, bufferSize) &&
FALSE == IS_STRING_EMPTY(displayName))
{
hr = E_FAIL;
}
else
hr = S_OK;
Unlock();
return hr;
}
BOOL Device::GetHidden()
{
return hidden;
}
HRESULT Device::GetTotalSpace(uint64_t *size)
{
if (NULL == size)
return E_POINTER;
Lock();
*size = totalSpace;
Unlock();
return S_OK;
}
HRESULT Device::GetUsedSpace(uint64_t *size)
{
if (NULL == size)
return E_POINTER;
Lock();
*size = usedSpace;
Unlock();
return S_OK;
}
BOOL Device::GetAttached()
{
return attached;
}
HRESULT Device::Attach(HWND hostWindow)
{
HRESULT hr;
Lock();
if (FALSE != attached)
hr = S_FALSE;
else
{
attached = TRUE;
hr = S_OK;
}
Unlock();
if (S_OK == hr && NULL != eventManager)
eventManager->Notify_AttachmentChanged(this, attached);
return hr;
}
HRESULT Device::Detach(HWND hostWindow)
{
HRESULT hr;
Lock();
if (FALSE == attached)
hr = S_FALSE;
else
{
attached = FALSE;
hr = S_OK;
}
Unlock();
if (S_OK == hr && NULL != eventManager)
eventManager->Notify_AttachmentChanged(this, attached);
return hr;
}
HRESULT Device::EnumerateCommands(ifc_devicesupportedcommandenum **enumerator, DeviceCommandContext context)
{
if (NULL == commands)
return E_UNEXPECTED;
return commands->Enumerate(enumerator);
}
HRESULT Device::SendCommand(const char *command, HWND hostWindow, ULONG_PTR param)
{
const wchar_t *commandName;
wchar_t message[1024];
if (NULL == command)
return E_POINTER;
if (CSTR_EQUAL == CompareStringA(CSTR_INVARIANT, NORM_IGNORECASE, command, -1, "sync", -1))
{
StartSyncActivity(hostWindow);
return S_OK;
}
else if (CSTR_EQUAL == CompareStringA(CSTR_INVARIANT, NORM_IGNORECASE, command, -1, "eject", -1))
commandName = L"Eject";
else if (CSTR_EQUAL == CompareStringA(CSTR_INVARIANT, NORM_IGNORECASE, command, -1, "detach", -1))
{
Detach(hostWindow);
return S_OK;
}
else if (CSTR_EQUAL == CompareStringA(CSTR_INVARIANT, NORM_IGNORECASE, command, -1, "settings", -1))
commandName = L"Settings";
else
return E_NOTIMPL;
StringCchPrintf(message, ARRAYSIZE(message), L"%s command received", commandName);
MessageBox(hostWindow, message, L"Device command test", MB_OK | MB_ICONINFORMATION);
return S_OK;
}
HRESULT Device::GetCommandFlags(const char *command, DeviceCommandFlags *flags)
{
if (NULL == commands)
return E_UNEXPECTED;
return commands->GetFlags(command, flags);
}
HRESULT Device::GetActivity(ifc_deviceactivity **activityOut)
{
HRESULT hr;
if (NULL == activityOut)
return E_POINTER;
Lock();
*activityOut = activity;
if (NULL != activity)
{
activity->AddRef();
hr = S_OK;
}
else
hr = S_FALSE;
Unlock();
return hr;
}
HRESULT Device::Advise(ifc_deviceevent *handler)
{
if (NULL == eventManager)
return E_UNEXPECTED;
return eventManager->Advise(handler);
}
HRESULT Device::Unadvise(ifc_deviceevent *handler)
{
if (NULL == eventManager)
return E_UNEXPECTED;
return eventManager->Unadvise(handler);
}
HWND Device::CreateView(HWND parentWindow)
{
return DeviceView_CreateWindow(parentWindow, this);
}
void Device::SetNavigationItem(void *navigationItem)
{
}
HRESULT Device::GetModel(wchar_t *buffer, size_t bufferSize)
{
HRESULT hr;
if (NULL == buffer)
return E_POINTER;
Lock();
if (0 == String_CopyTo(buffer, model, bufferSize) &&
FALSE == IS_STRING_EMPTY(model))
{
hr = E_FAIL;
}
else
hr = S_OK;
Unlock();
return hr;
}
HRESULT Device::GetStatus(wchar_t *buffer, size_t bufferSize)
{
HRESULT hr;
if (NULL == buffer)
return E_POINTER;
Lock();
if (0 == String_CopyTo(buffer, status, bufferSize) &&
FALSE == IS_STRING_EMPTY(status))
{
hr = E_FAIL;
}
else
hr = S_OK;
Unlock();
return hr;
}
HRESULT Device::SetConnection(const char *con)
{
Lock();
AnsiString_Free(connection);
connection = AnsiString_Duplicate(con);
Unlock();
return S_OK;
}
HRESULT Device::SetDisplayName(const wchar_t *name)
{
HRESULT hr;
Lock();
if (NULL == name && NULL == displayName)
hr = S_FALSE;
else
{
if (NULL != displayName &&
CSTR_EQUAL == CompareString(LOCALE_USER_DEFAULT, 0, name, -1, displayName, -1))
{
hr = S_FALSE;
}
else
{
wchar_t *string;
string = String_Duplicate(name);
if (NULL == string && NULL != name)
hr = E_FAIL;
else
{
String_Free(displayName);
displayName = string;
if (NULL != eventManager)
eventManager->Notify_DisplayNameChanged(this, displayName);
hr = S_OK;
}
}
}
Unlock();
return hr;
}
HRESULT Device::SetTotalSpace(uint64_t size)
{
Lock();
totalSpace = size;
if (NULL != eventManager)
eventManager->Notify_TotalSpaceChanged(this, totalSpace);
Unlock();
return S_OK;
}
HRESULT Device::SetUsedSpace(uint64_t size)
{
Lock();
usedSpace = size;
if (NULL != eventManager)
eventManager->Notify_UsedSpaceChanged(this, usedSpace);
Unlock();
return S_OK;
}
HRESULT Device::SetModel(const wchar_t *deviceModel)
{
HRESULT hr;
Lock();
if (NULL == deviceModel && NULL == model)
hr = S_FALSE;
else
{
if (NULL != model &&
CSTR_EQUAL == CompareString(LOCALE_USER_DEFAULT, 0, deviceModel, -1, model, -1))
{
hr = S_FALSE;
}
else
{
wchar_t *string;
string = String_Duplicate(deviceModel);
if (NULL == string && NULL != deviceModel)
hr = E_FAIL;
else
{
String_Free(model);
model = string;
if (NULL != eventManager)
eventManager->Notify_ModelChanged(this, model);
hr = S_OK;
}
}
}
Unlock();
return hr;
}
HRESULT Device::SetStatus(const wchar_t *deviceStatus)
{
HRESULT hr;
Lock();
if (NULL == deviceStatus && NULL == status)
hr = S_FALSE;
else
{
if (NULL != status &&
CSTR_EQUAL == CompareString(LOCALE_USER_DEFAULT, 0, deviceStatus, -1, status, -1))
{
hr = S_FALSE;
}
else
{
wchar_t *string;
string = String_Duplicate(deviceStatus);
if (NULL == string && NULL != deviceStatus)
hr = E_FAIL;
else
{
String_Free(status);
status = string;
if (NULL != eventManager)
eventManager->Notify_StatusChanged(this, status);
hr = S_OK;
}
}
}
Unlock();
return hr;
}
HRESULT Device::AddIcon(const wchar_t *path, unsigned int width, unsigned int height)
{
HRESULT hr;
if (NULL == iconStore)
return E_UNEXPECTED;
hr = iconStore->Add(path, width, height, TRUE);
if (SUCCEEDED(hr))
{
if (NULL != eventManager)
eventManager->Notify_IconChanged(this);
}
return hr;
}
HRESULT Device::EnumerateIcons(ifc_deviceiconstore::EnumeratorCallback callback, void *user)
{
if (NULL == iconStore)
return E_UNEXPECTED;
return iconStore->Enumerate(callback, user);
}
HRESULT Device::RemoveIcon(unsigned int width, unsigned int height)
{
HRESULT hr;
if (NULL == iconStore)
return E_UNEXPECTED;
hr = iconStore->Remove(width, height);
if (SUCCEEDED(hr))
{
if (NULL != eventManager)
eventManager->Notify_IconChanged(this);
}
return hr;
}
HRESULT Device::SetHidden(BOOL hiddenState)
{
HRESULT hr;
Lock();
if (hidden == (FALSE != hiddenState))
hr = S_FALSE;
else
{
hidden = (FALSE != hiddenState);
hr = S_OK;
}
Unlock();
if (S_OK == hr && NULL != eventManager)
eventManager->Notify_VisibilityChanged(this, TRUE);
return hr;
}
HRESULT Device::IsConnected()
{
HRESULT hr;
Lock();
hr = (FALSE != connected) ? S_OK : S_FALSE;
Unlock();
return hr;
}
HRESULT Device::Connect()
{
HRESULT hr;
Lock();
if (FALSE != connected)
hr = S_FALSE;
else
{
connected = TRUE;
hr = S_OK;
}
Unlock();
return hr;
}
HRESULT Device::Disconnect()
{
HRESULT hr;
Lock();
if (FALSE == connected)
hr = S_FALSE;
else
{
connected = FALSE;
hr = S_OK;
}
Unlock();
return hr;
}
HRESULT Device::CopyTo(Device *target)
{
if (NULL == target)
return E_POINTER;
Lock();
target->SetDisplayName(displayName);
if (NULL != target->iconStore)
target->iconStore->Release();
if (NULL == iconStore || FAILED(iconStore->Clone(&target->iconStore)))
target->iconStore = NULL;
target->usedSpace = usedSpace;
target->totalSpace = totalSpace;
target->hidden = hidden;
target->attached = attached;
target->connected = connected;
if (NULL != target->commands)
target->commands->Release();
if (NULL == commands || FAILED(commands->Clone(&target->commands, TRUE)))
target->commands = NULL;
Unlock();
return S_OK;
}
HRESULT Device::SetIconBase(const wchar_t *path)
{
if (NULL == iconStore)
return E_UNEXPECTED;
return iconStore->SetBasePath(path);
}
HRESULT Device::AddCommand(const char *command, DeviceCommandFlags flags)
{
if (NULL == commands)
return E_UNEXPECTED;
return commands->Add(command, flags);
}
HRESULT Device::RemoveCommand(const char *command)
{
if (NULL == commands)
return E_UNEXPECTED;
return commands->Remove(command);
}
HRESULT Device::SetCommandFlags(const char *command, DeviceCommandFlags mask, DeviceCommandFlags flags)
{
if (NULL == commands)
return E_UNEXPECTED;
return commands->SetFlags(command, mask, flags);
}
void Device::ActivityStartedCb(DeviceActivity *activity)
{
Device *device;
if(FAILED(activity->GetUser((void**)&device)) || NULL == device)
return;
if (NULL != device->eventManager)
device->eventManager->Notify_ActivityStarted(device, activity);
}
void Device::ActivityFinishedCb(DeviceActivity *activity)
{
Device *device;
if(FAILED(activity->GetUser((void**)&device)) || NULL == device)
return;
device->Lock();
if (activity == device->activity)
device->activity = NULL;
device->Unlock();
if (NULL != device->eventManager)
device->eventManager->Notify_ActivityFinished(device, activity);
activity->Release();
}
void Device::ActivityProgressCb(DeviceActivity *activity, unsigned int progress, unsigned int duration)
{
Device *device;
uint64_t space;
if(FAILED(activity->GetUser((void**)&device)) || NULL == device)
return;
device->Lock();
space = device->usedSpace;
space++;
if (space > device->totalSpace)
space = 0;
device->Unlock();
device->SetUsedSpace(space);
if (NULL != device->eventManager)
device->eventManager->Notify_ActivityChanged(device, activity);
}
HRESULT Device::StartSyncActivity(HWND hostWindow)
{
HRESULT hr;
Lock();
if (NULL != activity)
hr = E_PENDING;
else
{
hr = DeviceActivity::CreateInstance(DeviceActivityFlag_Cancelable | DeviceActivityFlag_SupportProgress,
ActivityStartedCb, ActivityFinishedCb, ActivityProgressCb,
this, &activity);
if (SUCCEEDED(hr))
{
activity->SetDisplayName(L"Synchronizing...");
activity->SetStatus(L"Performing synchronization...");
hr = activity->Start(60000, 20);
if (FAILED(hr))
{
activity->Release();
activity = NULL;
}
}
}
Unlock();
return S_OK;
}
#define CBCLASS Device
START_DISPATCH;
CB(ADDREF, AddRef)
CB(RELEASE, Release)
CB(QUERYINTERFACE, QueryInterface)
CB(API_GETNAME, GetName)
CB(API_GETTYPE, GetType)
CB(API_GETCONNECTION, GetConnection)
CB(API_GETICON, GetIcon)
CB(API_GETDISPLAYNAME, GetDisplayName)
CB(API_GETHIDDEN, GetHidden)
CB(API_GETTOTALSPACE, GetTotalSpace)
CB(API_GETUSEDSPACE, GetUsedSpace)
CB(API_GETATTACHED, GetAttached)
CB(API_ATTACH, Attach)
CB(API_DETACH, Detach)
CB(API_ENUMERATECOMMANDS, EnumerateCommands)
CB(API_SENDCOMMAND, SendCommand)
CB(API_GETCOMMANDFLAGS, GetCommandFlags)
CB(API_GETACTIVITY, GetActivity)
CB(API_ADVISE, Advise)
CB(API_UNADVISE, Unadvise)
CB(API_CREATEVIEW, CreateView)
VCB(API_SETNAVIGATIONITEM, SetNavigationItem)
CB(API_SETDISPLAYNAME, SetDisplayName)
CB(API_GETMODEL, GetModel)
CB(API_GETSTATUS, GetStatus)
END_DISPATCH;
#undef CBCLASS

View File

@ -0,0 +1,114 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <wtypes.h>
class DeviceActivity;
class Device: public ifc_device
{
protected:
Device();
~Device();
public:
static HRESULT CreateInstance(const char *name,
const char *type,
const char *connection,
Device**instance);
public:
/* Dispatchable */
size_t AddRef();
size_t Release();
int QueryInterface(GUID interface_guid, void **object);
/* ifc_device */
const char *GetName();
const char *GetType();
const char *GetConnection();
HRESULT GetIcon(wchar_t *buffer, size_t bufferSize, int width, int height);
HRESULT GetDisplayName(wchar_t *buffer, size_t bufferSize);
BOOL GetHidden();
HRESULT GetTotalSpace(uint64_t *size);
HRESULT GetUsedSpace(uint64_t *size);
BOOL GetAttached();
HRESULT Attach(HWND hostWindow);
HRESULT Detach(HWND hostWindow);
HRESULT EnumerateCommands(ifc_devicesupportedcommandenum **enumerator, DeviceCommandContext context);
HRESULT SendCommand(const char *command, HWND hostWindow, ULONG_PTR param);
HRESULT GetCommandFlags(const char *command, DeviceCommandFlags *flags);
HRESULT GetActivity(ifc_deviceactivity **activity);
HRESULT Advise(ifc_deviceevent *handler);
HRESULT Unadvise(ifc_deviceevent *handler);
HWND CreateView(HWND parentWindow);
void SetNavigationItem(void *navigationItem);
HRESULT GetModel(wchar_t *buffer, size_t bufferSize);
HRESULT GetStatus(wchar_t *buffer, size_t bufferSize);
public:
HRESULT SetConnection(const char *connection);
HRESULT SetDisplayName(const wchar_t *name);
HRESULT SetTotalSpace(uint64_t size);
HRESULT SetUsedSpace(uint64_t size);
HRESULT SetHidden(BOOL hiddenState);
HRESULT SetModel(const wchar_t *deviceModel);
HRESULT SetStatus(const wchar_t *deviceStatus);
HRESULT AddIcon(const wchar_t *path, unsigned int width, unsigned int height);
HRESULT EnumerateIcons(ifc_deviceiconstore::EnumeratorCallback callback, void *user);
HRESULT RemoveIcon(unsigned int width, unsigned int height);
HRESULT AddCommand(const char *command, DeviceCommandFlags flags);
HRESULT RemoveCommand(const char *command);
HRESULT SetCommandFlags(const char *command, DeviceCommandFlags mask, DeviceCommandFlags flags);
HRESULT IsConnected();
HRESULT Connect();
HRESULT Disconnect();
HRESULT CopyTo(Device *target);
HRESULT SetIconBase(const wchar_t *path);
HRESULT StartSyncActivity(HWND hostWindow);
protected:
void Lock();
void Unlock();
static void ActivityStartedCb(DeviceActivity *activity);
static void ActivityFinishedCb(DeviceActivity *activity);
static void ActivityProgressCb(DeviceActivity *activity, unsigned int progress, unsigned int duration);
protected:
size_t ref;
char *name;
char *type;
char *connection;
wchar_t *displayName;
wchar_t *model;
wchar_t *status;
uint64_t totalSpace;
uint64_t usedSpace;
BOOL attached;
BOOL hidden;
BOOL connected;
ifc_deviceiconstore *iconStore;
ifc_deviceeventmanager *eventManager;
ifc_devicesupportedcommandstore *commands;
DeviceActivity *activity;
CRITICAL_SECTION lock;
protected:
RECVS_DISPATCH;
};
#endif //_NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_HEADER

View File

@ -0,0 +1,519 @@
#include "main.h"
#include "./deviceActivity.h"
#include <strsafe.h>
typedef struct DeviceActivityThreadParam
{
DeviceActivity *activity;
unsigned int duration;
unsigned int interval;
HANDLE readyEvent;
}DeviceActivityThreadParam;
DeviceActivity::DeviceActivity(DeviceActivityFlags flags,
DeviceActivityCallback startCb, DeviceActivityCallback finishCb,
DeviceActivityProgressCallback progressCb, void *user)
: ref(1), displayName(NULL), status(NULL), activityThread(FALSE), cancelEvent(NULL), progress(0)
{
InitializeCriticalSection(&lock);
this->flags = flags;
callbackStart = startCb;
callbackFinish = finishCb;
callbackProgress = progressCb;
this->user = user;
}
DeviceActivity::~DeviceActivity()
{
Stop();
String_Free(displayName);
String_Free(status);
DeleteCriticalSection(&lock);
}
HRESULT DeviceActivity::CreateInstance(DeviceActivityFlags flags,
DeviceActivityCallback startCb, DeviceActivityCallback finishCb,
DeviceActivityProgressCallback progressCb, void *user,
DeviceActivity **instance)
{
DeviceActivity *self;
if (NULL == instance)
return E_POINTER;
*instance = NULL;
self = new DeviceActivity(flags, startCb, finishCb, progressCb, user);
if (NULL == self)
return E_OUTOFMEMORY;
*instance = self;
return S_OK;
}
size_t DeviceActivity::AddRef()
{
return InterlockedIncrement((LONG*)&ref);
}
size_t DeviceActivity::Release()
{
if (0 == ref)
return ref;
LONG r = InterlockedDecrement((LONG*)&ref);
if (0 == r)
delete(this);
return r;
}
int DeviceActivity::QueryInterface(GUID interface_guid, void **object)
{
if (NULL == object)
return E_POINTER;
if (IsEqualIID(interface_guid, IFC_DeviceActivity))
*object = static_cast<ifc_deviceactivity*>(this);
else
{
*object = NULL;
return E_NOINTERFACE;
}
if (NULL == *object)
return E_UNEXPECTED;
AddRef();
return S_OK;
}
void DeviceActivity::Lock()
{
EnterCriticalSection(&lock);
}
void DeviceActivity::Unlock()
{
LeaveCriticalSection(&lock);
}
BOOL DeviceActivity::GetActive()
{
BOOL running;
Lock();
running = (NULL != activityThread);
Unlock();
return running;
}
BOOL DeviceActivity::GetCancelable()
{
BOOL cancelable;
Lock();
cancelable = (0 != (DeviceActivityFlag_Cancelable & flags));
Unlock();
return cancelable;
}
HRESULT DeviceActivity::GetProgress(unsigned int *percentCompleted)
{
if (NULL == percentCompleted)
return E_POINTER;
Lock();
*percentCompleted = progress;
Unlock();
return S_OK;
}
HRESULT DeviceActivity::GetDisplayName(wchar_t *buffer, size_t bufferMax)
{
HRESULT hr;
if (NULL == buffer)
return E_POINTER;
Lock();
if (0 == String_CopyTo(buffer, displayName, bufferMax) &&
FALSE == IS_STRING_EMPTY(displayName))
{
hr = E_FAIL;
}
else
hr = S_OK;
Unlock();
return hr;
}
HRESULT DeviceActivity::GetStatus(wchar_t *buffer, size_t bufferMax)
{
HRESULT hr;
if (NULL == buffer)
return E_POINTER;
Lock();
if (0 == String_CopyTo(buffer, status, bufferMax) &&
FALSE == IS_STRING_EMPTY(status))
{
hr = E_FAIL;
}
else
hr = S_OK;
Unlock();
return hr;
}
HRESULT DeviceActivity::Cancel(HWND hostWindow)
{
HRESULT hr;
Lock();
if (0 == (DeviceActivityFlag_Cancelable & flags))
hr = E_NOTIMPL;
else
hr = E_FAIL;
Unlock();
return hr;
}
HRESULT DeviceActivity::Start(unsigned int duration, unsigned int interval)
{
HRESULT hr;
Lock();
if (NULL != activityThread)
hr = E_PENDING;
else
{
hr = S_OK;
if (NULL == cancelEvent)
{
cancelEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (NULL == cancelEvent)
hr = E_FAIL;
}
if (SUCCEEDED(hr))
{
DeviceActivityThreadParam param;
param.activity = this;
param.duration = duration;
param.interval = interval;
param.readyEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (NULL == param.readyEvent)
hr = E_FAIL;
else
{
DWORD threadId;
activityThread = CreateThread(NULL, 0, DeviceActivity_ActivityThreadStarter,
&param, 0, &threadId);
if (NULL == activityThread)
hr = E_FAIL;
else
WaitForSingleObject(param.readyEvent, INFINITE);
CloseHandle(param.readyEvent);
}
}
if (FAILED(hr))
Stop();
}
Unlock();
return hr;
}
HRESULT DeviceActivity::Stop()
{
HRESULT hr;
HANDLE threadHandle, eventHandle;
Lock();
threadHandle = activityThread;
eventHandle = cancelEvent;
activityThread = NULL;
cancelEvent = NULL;
Unlock();
if (NULL != threadHandle)
{
if (NULL != eventHandle)
SetEvent(eventHandle);
WaitForSingleObject(threadHandle, INFINITE);
CloseHandle(threadHandle);
hr = S_OK;
}
else
hr = S_FALSE;
if (NULL != eventHandle)
CloseHandle(eventHandle);
return hr;
}
HRESULT DeviceActivity::SetDisplayName(const wchar_t *name)
{
HRESULT hr;
Lock();
if (NULL == name && NULL == displayName)
hr = S_FALSE;
else
{
if (NULL != displayName &&
CSTR_EQUAL == CompareString(LOCALE_USER_DEFAULT, 0, name, -1, displayName, -1))
{
hr = S_FALSE;
}
else
{
wchar_t *string;
string = String_Duplicate(name);
if (NULL == string && NULL != name)
hr = E_FAIL;
else
{
String_Free(displayName);
displayName = string;
hr = S_OK;
}
}
}
Unlock();
return hr;
}
HRESULT DeviceActivity::SetStatus(const wchar_t *newStatus)
{
HRESULT hr;
if (NULL == newStatus && NULL == status)
return S_FALSE;
Lock();
if (NULL != status &&
CSTR_EQUAL == CompareString(LOCALE_USER_DEFAULT, 0, newStatus, -1, status, -1))
{
hr = S_FALSE;
}
else
{
wchar_t *string;
string = String_Duplicate(newStatus);
if (NULL == string && NULL != newStatus)
hr = E_FAIL;
else
{
String_Free(status);
status = string;
hr = S_OK;
}
}
Unlock();
return hr;
}
HRESULT DeviceActivity::SetUser(void *data)
{
Lock();
user = data;
Unlock();
return S_OK;
}
HRESULT DeviceActivity::GetUser(void **data)
{
if (NULL == data)
return E_POINTER;
Lock();
*data = user;
Unlock();
return S_OK;
}
DWORD DeviceActivity::ActivityThread(unsigned int duration, unsigned int interval)
{
DWORD waitResult, waitTime;
HANDLE cancelEventCopy;
unsigned int position;
if (interval > duration)
interval = duration;
position = 0;
Lock();
progress = 0;
if (NULL == cancelEvent ||
0 == DuplicateHandle(GetCurrentProcess(), cancelEvent, GetCurrentProcess(),
&cancelEventCopy, 0, FALSE, DUPLICATE_SAME_ACCESS))
{
cancelEventCopy = NULL;
}
Unlock();
if(NULL == cancelEventCopy)
return -3;
Lock();
if (NULL != callbackStart)
callbackStart(this);
if (NULL != callbackProgress)
callbackProgress(this, position, duration);
Unlock();
for(;;)
{
waitTime = interval;
if ((position + waitTime) > duration)
waitTime = duration - position;
waitResult = WaitForSingleObject(cancelEventCopy, waitTime);
if (WAIT_TIMEOUT == waitResult)
{
position += waitTime;
Lock();
if (duration != 0)
{
progress = 100 * position / duration;
if (progress > 100)
progress = 100;
}
else
progress = 100;
if (NULL != callbackProgress)
callbackProgress(this, position, duration);
Unlock();
if (position >= duration)
break;
}
else
break;
}
AddRef();
Lock();
if (NULL != activityThread)
{
CloseHandle(activityThread);
activityThread = NULL;
}
if (NULL != cancelEvent)
{
CloseHandle(cancelEvent);
cancelEvent = NULL;
}
if (NULL != callbackFinish)
callbackFinish(this);
Unlock();
Release();
return 0;
}
static DWORD CALLBACK
DeviceActivity_ActivityThreadStarter(void *user)
{
DeviceActivityThreadParam *param;
DeviceActivity *activity;
unsigned int duration, interval;
DWORD result;
param = (DeviceActivityThreadParam*)user;
activity = param->activity;
duration = param->duration;
interval = param->interval;
if (NULL != param->readyEvent)
SetEvent(param->readyEvent);
if (NULL != activity)
result = activity->ActivityThread(duration, interval);
else
result = -2;
return result;
}
#define CBCLASS DeviceActivity
START_DISPATCH;
CB(ADDREF, AddRef)
CB(RELEASE, Release)
CB(QUERYINTERFACE, QueryInterface)
CB(API_GETACTIVE, GetActive)
CB(API_GETCANCELABLE, GetCancelable)
CB(API_GETPROGRESS, GetProgress)
CB(API_GETDISPLAYNAME, GetDisplayName)
CB(API_GETSTATUS, GetStatus)
CB(API_CANCEL, Cancel)
END_DISPATCH;
#undef CBCLASS

View File

@ -0,0 +1,91 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_ACTIVITY_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_ACTIVITY_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <wtypes.h>
typedef enum DeviceActivityFlags
{
DeviceActivityFlag_Cancelable = (1 << 0),
DeviceActivityFlag_SupportProgress = (1 << 0),
} DeviceActivityFlags;
DEFINE_ENUM_FLAG_OPERATORS(DeviceActivityFlags);
typedef void (*DeviceActivityCallback)(DeviceActivity * /*activity*/);
typedef void (*DeviceActivityProgressCallback)(DeviceActivity * /*activity*/, unsigned int /*position*/, unsigned int /*total*/);
class DeviceActivity: public ifc_deviceactivity
{
protected:
DeviceActivity(DeviceActivityFlags flags,
DeviceActivityCallback startCb,
DeviceActivityCallback finishCb,
DeviceActivityProgressCallback progressCb,
void *user);
~DeviceActivity();
public:
static HRESULT CreateInstance(DeviceActivityFlags flags,
DeviceActivityCallback startCb,
DeviceActivityCallback finishCb,
DeviceActivityProgressCallback progressCb,
void *user,
DeviceActivity **instance);
public:
/* Dispatchable */
size_t AddRef();
size_t Release();
int QueryInterface(GUID interface_guid, void **object);
/* ifc_deviceactivity */
BOOL GetActive();
BOOL GetCancelable();
HRESULT GetProgress(unsigned int *percentCompleted);
HRESULT GetDisplayName(wchar_t *buffer, size_t bufferMax);
HRESULT GetStatus(wchar_t *buffer, size_t bufferMax);
HRESULT Cancel(HWND hostWindow);
public:
void Lock();
void Unlock();
HRESULT Start(unsigned int duration, unsigned int interval);
HRESULT Stop();
HRESULT SetDisplayName(const wchar_t *displayName);
HRESULT SetStatus(const wchar_t *status);
HRESULT SetUser(void *data);
HRESULT GetUser(void **data);
protected:
DWORD ActivityThread(unsigned int duration, unsigned int interval);
friend static DWORD CALLBACK DeviceActivity_ActivityThreadStarter(void *param);
protected:
size_t ref;
DeviceActivityFlags flags;
DeviceActivityCallback callbackStart;
DeviceActivityCallback callbackFinish;
DeviceActivityProgressCallback callbackProgress;
void *user;
wchar_t *displayName;
wchar_t *status;
HANDLE activityThread;
HANDLE cancelEvent;
unsigned int progress;
CRITICAL_SECTION lock;
protected:
RECVS_DISPATCH;
};
#endif //_NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_ACTIVITY_HEADER

View File

@ -0,0 +1,75 @@
#include "main.h"
#include "./DeviceCommandNodeParser.h"
#include "../../xml/obj_xml.h"
DeviceCommandNodeParser::DeviceCommandNodeParser()
: reader(NULL), test(NULL)
{
}
DeviceCommandNodeParser::~DeviceCommandNodeParser()
{
End();
}
BOOL DeviceCommandNodeParser::Begin(obj_xml *xmlReader, TestSuite *testSuite)
{
if (NULL != reader || NULL != test)
return FALSE;
if (NULL == xmlReader || NULL == testSuite)
return FALSE;
reader = xmlReader;
reader->AddRef();
test = testSuite;
reader->xmlreader_registerCallback(L"testprovider\fcommands\fcommand", this);
return TRUE;
}
void DeviceCommandNodeParser::End()
{
if (NULL != reader)
{
reader->xmlreader_unregisterCallback(this);
reader->Release();
reader = NULL;
}
if (NULL != test)
test = NULL;
}
void DeviceCommandNodeParser::Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params)
{
elementParser.Begin(reader, params);
}
void DeviceCommandNodeParser::Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag)
{
ifc_devicecommand *result;
if (FALSE != elementParser.End(reader, &result))
{
if (NULL != test)
test->AddCommand(result);
result->Release();
}
}
void DeviceCommandNodeParser::Event_XmlError(int linenum, int errcode, const wchar_t *errstr)
{
}
#define CBCLASS DeviceCommandNodeParser
START_DISPATCH;
VCB(ONSTARTELEMENT, Event_XmlStartElement)
VCB(ONENDELEMENT, Event_XmlEndElement)
VCB(ONERROR, Event_XmlError)
END_DISPATCH;
#undef CBCLASS

View File

@ -0,0 +1,39 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_COMMAND_NODE_PARSER_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_COMMAND_NODE_PARSER_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <wtypes.h>
#include "../../xml/ifc_xmlreadercallback.h"
#include "./deviceCommandParser.h"
class obj_xml;
class DeviceCommandNodeParser : public ifc_xmlreadercallback
{
public:
DeviceCommandNodeParser();
~DeviceCommandNodeParser();
public:
BOOL Begin(obj_xml *xmlReader, TestSuite *testSuite);
void End();
protected:
void Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params);
void Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag);
void Event_XmlError(int linenum, int errcode, const wchar_t *errstr);
protected:
obj_xml *reader;
DeviceCommandParser elementParser;
TestSuite *test;
protected:
RECVS_DISPATCH;
};
#endif //_NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_COMMAND_NODE_PARSER_HEADER

View File

@ -0,0 +1,192 @@
#include "main.h"
#include "./deviceCommandParser.h"
#include "../../xml/obj_xml.h"
typedef void (*COMMANDTAGCALLBACK)(DeviceCommandParser* /*self*/, ifc_devicecommandeditor* /*editor*/, const wchar_t* /*value*/);
typedef struct COMMANDTAG
{
const wchar_t *name;
BOOL multiEntry;
COMMANDTAGCALLBACK callback;
} COMMANDTAG;
static void
DeviceCommandParser_DisplayNameCb(DeviceCommandParser *self, ifc_devicecommandeditor *editor, const wchar_t *value)
{
editor->SetDisplayName(value);
}
static void
DeviceCommandParser_IconCb(DeviceCommandParser *self, ifc_devicecommandeditor *editor, const wchar_t *value)
{
ifc_deviceiconstore *iconStore;
if (SUCCEEDED(editor->GetIconStore(&iconStore)))
{
iconStore->Add(value, self->iconSize.cx, self->iconSize.cy, TRUE);
iconStore->Release();
}
}
static void
DeviceCommandParser_DescirptionCb(DeviceCommandParser *self, ifc_devicecommandeditor *editor, const wchar_t *value)
{
editor->SetDescription(value);
}
static const COMMANDTAG knownTags[COMMAND_TAG_MAX] =
{
{L"displayName", FALSE, DeviceCommandParser_DisplayNameCb},
{L"icon", TRUE, DeviceCommandParser_IconCb},
{L"description", FALSE, DeviceCommandParser_DescirptionCb},
};
DeviceCommandParser::DeviceCommandParser()
: editor(NULL)
{
}
DeviceCommandParser::~DeviceCommandParser()
{
if (NULL != editor)
editor->Release();
}
BOOL DeviceCommandParser::Begin(obj_xml *reader, ifc_xmlreaderparams *params)
{
const wchar_t *name;
ifc_devicecommand *command;
char *nameAnsi;
if (NULL != editor)
return FALSE;
if (NULL == reader || NULL == params)
return FALSE;
name = params->getItemValue(L"name");
if (NULL == name)
return FALSE;
nameAnsi = String_ToAnsi(CP_UTF8, 0, name, -1, NULL, NULL);
if (NULL == nameAnsi)
return FALSE;
if (NULL != WASABI_API_DEVICES &&
SUCCEEDED(WASABI_API_DEVICES->CreateCommand(nameAnsi, &command)))
{
if(FAILED(command->QueryInterface(IFC_DeviceCommandEditor, (void**)&editor)))
editor = NULL;
command->Release();
}
AnsiString_Free(nameAnsi);
if (NULL == editor)
return FALSE;
reader->xmlreader_registerCallback(L"testprovider\fcommands\fcommand\fdisplayName", this);
reader->xmlreader_registerCallback(L"testprovider\fcommands\fcommand\fdescription", this);
reader->xmlreader_registerCallback(L"testprovider\fcommands\fcommand\ficon", this);
ZeroMemory(hitList, sizeof(hitList));
return TRUE;
}
BOOL DeviceCommandParser::End(obj_xml *reader, ifc_devicecommand **command)
{
BOOL result;
if (NULL != reader)
reader->xmlreader_unregisterCallback(this);
if (NULL == command)
return FALSE;
if (NULL == editor)
return FALSE;
if (NULL != command)
{
if (FAILED(editor->QueryInterface(IFC_DeviceCommand, (void**)command)))
result = FALSE;
else
result = TRUE;
}
else
result = TRUE;
editor->Release();
editor = NULL;
return result;
}
void DeviceCommandParser::Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params)
{
elementString.Clear();
if (CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, L"icon", -1, xmltag, -1))
{
const wchar_t *sVal;
int iVal;
sVal = params->getItemValue(L"width");
if (NULL == sVal ||
FALSE == StrToIntEx(sVal, STIF_DEFAULT, &iVal))
{
iVal = 0;
}
iconSize.cx = iVal;
sVal = params->getItemValue(L"height");
if (NULL == sVal ||
FALSE == StrToIntEx(sVal, STIF_DEFAULT, &iVal))
{
iVal = 0;
}
iconSize.cy = iVal;
}
}
void DeviceCommandParser::Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag)
{
if (NULL == editor)
return;
for (size_t i = 0; i < COMMAND_TAG_MAX; i++)
{
if (FALSE == hitList[i] &&
CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, knownTags[i].name, -1, xmltag, -1))
{
knownTags[i].callback(this, editor, elementString.Get());
if (FALSE == knownTags[i].multiEntry)
hitList[i] = TRUE;
break;
}
}
}
void DeviceCommandParser::Event_XmlCharData(const wchar_t *xmlpath, const wchar_t *xmltag, const wchar_t *value)
{
elementString.Append(value);
}
void DeviceCommandParser::Event_XmlError(int linenum, int errcode, const wchar_t *errstr)
{
elementString.Clear();
}
#define CBCLASS DeviceCommandParser
START_DISPATCH;
VCB(ONSTARTELEMENT, Event_XmlStartElement)
VCB(ONENDELEMENT, Event_XmlEndElement)
VCB(ONCHARDATA, Event_XmlCharData)
VCB(ONERROR, Event_XmlError)
END_DISPATCH;
#undef CBCLASS

View File

@ -0,0 +1,47 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_COMMAND_PARSER_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_COMMAND_PARSER_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <wtypes.h>
#include "../../xml/ifc_xmlreadercallback.h"
class obj_xml;
#define COMMAND_TAG_MAX 3
class DeviceCommandParser : public ifc_xmlreadercallback
{
public:
DeviceCommandParser();
~DeviceCommandParser();
public:
BOOL Begin(obj_xml *reader, ifc_xmlreaderparams *params);
BOOL End(obj_xml *reader, ifc_devicecommand **command);
protected:
void Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params);
void Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag);
void Event_XmlCharData(const wchar_t *xmlpath, const wchar_t *xmltag, const wchar_t *value);
void Event_XmlError(int linenum, int errcode, const wchar_t *errstr);
protected:
friend static void DeviceCommandParser_DisplayNameCb(DeviceCommandParser *self, ifc_devicecommandeditor *editor, const wchar_t *value);
friend static void DeviceCommandParser_IconCb(DeviceCommandParser *self, ifc_devicecommandeditor *editor, const wchar_t *value);
friend static void DeviceCommandParser_DescirptionCb(DeviceCommandParser *self, ifc_devicecommandeditor *editor, const wchar_t *value);
protected:
StringBuilder elementString;
ifc_devicecommandeditor *editor;
BOOL hitList[COMMAND_TAG_MAX];
SIZE iconSize;
protected:
RECVS_DISPATCH;
};
#endif // _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_COMMAND_PARSER_HEADER

View File

@ -0,0 +1,75 @@
#include "main.h"
#include "./DeviceConnectionNodeParser.h"
#include "../../xml/obj_xml.h"
DeviceConnectionNodeParser::DeviceConnectionNodeParser()
: reader(NULL), test(NULL)
{
}
DeviceConnectionNodeParser::~DeviceConnectionNodeParser()
{
End();
}
BOOL DeviceConnectionNodeParser::Begin(obj_xml *xmlReader, TestSuite *testSuite)
{
if (NULL != reader || NULL != test)
return FALSE;
if (NULL == xmlReader || NULL == testSuite)
return FALSE;
reader = xmlReader;
reader->AddRef();
test = testSuite;
reader->xmlreader_registerCallback(L"testprovider\fconnections\fconnection", this);
return TRUE;
}
void DeviceConnectionNodeParser::End()
{
if (NULL != reader)
{
reader->xmlreader_unregisterCallback(this);
reader->Release();
reader = NULL;
}
if (NULL != test)
test = NULL;
}
void DeviceConnectionNodeParser::Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params)
{
elementParser.Begin(reader, params);
}
void DeviceConnectionNodeParser::Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag)
{
ifc_deviceconnection *result;
if (FALSE != elementParser.End(reader, &result))
{
if (NULL != test)
test->AddConnection(result);
result->Release();
}
}
void DeviceConnectionNodeParser::Event_XmlError(int linenum, int errcode, const wchar_t *errstr)
{
}
#define CBCLASS DeviceConnectionNodeParser
START_DISPATCH;
VCB(ONSTARTELEMENT, Event_XmlStartElement)
VCB(ONENDELEMENT, Event_XmlEndElement)
VCB(ONERROR, Event_XmlError)
END_DISPATCH;
#undef CBCLASS

View File

@ -0,0 +1,39 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_CONNECTION_NODE_PARSER_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_CONNECTION_NODE_PARSER_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <wtypes.h>
#include "../../xml/ifc_xmlreadercallback.h"
#include "./deviceConnectionParser.h"
class obj_xml;
class DeviceConnectionNodeParser : public ifc_xmlreadercallback
{
public:
DeviceConnectionNodeParser();
~DeviceConnectionNodeParser();
public:
BOOL Begin(obj_xml *xmlReader, TestSuite *testSuite);
void End();
protected:
void Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params);
void Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag);
void Event_XmlError(int linenum, int errcode, const wchar_t *errstr);
protected:
obj_xml *reader;
DeviceConnectionParser elementParser;
TestSuite *test;
protected:
RECVS_DISPATCH;
};
#endif //_NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_CONNECTION_NODE_PARSER_HEADER

View File

@ -0,0 +1,181 @@
#include "main.h"
#include "./deviceConnectionParser.h"
#include "../../xml/obj_xml.h"
typedef void (*CONNECTIONTAGCALLBACK)(DeviceConnectionParser* /*self*/, ifc_deviceconnectioneditor * /*editor*/, const wchar_t* /*value*/);
typedef struct CONNECTIONTAG
{
const wchar_t *name;
BOOL multiEntry;
CONNECTIONTAGCALLBACK callback;
} CONNECTIONTAG;
static void
DeviceConnectionParser_DisplayNameCb(DeviceConnectionParser *self, ifc_deviceconnectioneditor *editor, const wchar_t *value)
{
editor->SetDisplayName(value);
}
static void
DeviceConnectionParser_IconCb(DeviceConnectionParser *self, ifc_deviceconnectioneditor *editor, const wchar_t *value)
{
ifc_deviceiconstore *iconStore;
if (SUCCEEDED(editor->GetIconStore(&iconStore)))
{
iconStore->Add(value, self->iconSize.cx, self->iconSize.cy, TRUE);
iconStore->Release();
}
}
static const CONNECTIONTAG knownTags[CONNECTION_TAG_MAX] =
{
{L"displayName", FALSE, DeviceConnectionParser_DisplayNameCb},
{L"icon", TRUE, DeviceConnectionParser_IconCb},
};
DeviceConnectionParser::DeviceConnectionParser()
: editor(NULL)
{
}
DeviceConnectionParser::~DeviceConnectionParser()
{
if (NULL != editor)
editor->Release();
}
BOOL DeviceConnectionParser::Begin(obj_xml *reader, ifc_xmlreaderparams *params)
{
const wchar_t *name;
ifc_deviceconnection *connection;
char *nameAnsi;
if (NULL != editor)
return FALSE;
if (NULL == reader || NULL == params)
return FALSE;
name = params->getItemValue(L"name");
if (NULL == name)
return FALSE;
nameAnsi = String_ToAnsi(CP_UTF8, 0, name, -1, NULL, NULL);
if (NULL == nameAnsi)
return FALSE;
if (NULL != WASABI_API_DEVICES &&
SUCCEEDED(WASABI_API_DEVICES->CreateConnection(nameAnsi, &connection)))
{
if(FAILED(connection->QueryInterface(IFC_DeviceConnectionEditor, (void**)&editor)))
editor = NULL;
connection->Release();
}
AnsiString_Free(nameAnsi);
if (NULL == editor)
return FALSE;
reader->xmlreader_registerCallback(L"testprovider\fconnections\fconnection\fdisplayName", this);
reader->xmlreader_registerCallback(L"testprovider\fconnections\fconnection\ficon", this);
ZeroMemory(hitList, sizeof(hitList));
return TRUE;
}
BOOL DeviceConnectionParser::End(obj_xml *reader, ifc_deviceconnection **connection)
{
BOOL result;
if (NULL != reader)
reader->xmlreader_unregisterCallback(this);
if (NULL == editor)
return FALSE;
if (NULL != connection)
{
if (FAILED(editor->QueryInterface(IFC_DeviceConnection, (void**)connection)))
result = FALSE;
else
result = TRUE;
}
else
result = TRUE;
editor->Release();
editor = NULL;
return result;
}
void DeviceConnectionParser::Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params)
{
elementString.Clear();
if (CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, L"icon", -1, xmltag, -1))
{
const wchar_t *sVal;
int iVal;
sVal = params->getItemValue(L"width");
if (NULL == sVal ||
FALSE == StrToIntEx(sVal, STIF_DEFAULT, &iVal))
{
iVal = 0;
}
iconSize.cx = iVal;
sVal = params->getItemValue(L"height");
if (NULL == sVal ||
FALSE == StrToIntEx(sVal, STIF_DEFAULT, &iVal))
{
iVal = 0;
}
iconSize.cy = iVal;
}
}
void DeviceConnectionParser::Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag)
{
if (NULL == editor)
return;
for (size_t i = 0; i < CONNECTION_TAG_MAX; i++)
{
if (FALSE == hitList[i] &&
CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, knownTags[i].name, -1, xmltag, -1))
{
knownTags[i].callback(this, editor, elementString.Get());
if (FALSE == knownTags[i].multiEntry)
hitList[i] = TRUE;
break;
}
}
}
void DeviceConnectionParser::Event_XmlCharData(const wchar_t *xmlpath, const wchar_t *xmltag, const wchar_t *value)
{
elementString.Append(value);
}
void DeviceConnectionParser::Event_XmlError(int linenum, int errcode, const wchar_t *errstr)
{
elementString.Clear();
}
#define CBCLASS DeviceConnectionParser
START_DISPATCH;
VCB(ONSTARTELEMENT, Event_XmlStartElement)
VCB(ONENDELEMENT, Event_XmlEndElement)
VCB(ONCHARDATA, Event_XmlCharData)
VCB(ONERROR, Event_XmlError)
END_DISPATCH;
#undef CBCLASS

View File

@ -0,0 +1,46 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_CONNECTION_PARSER_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_CONNECTION_PARSER_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <wtypes.h>
#include "../../xml/ifc_xmlreadercallback.h"
class obj_xml;
#define CONNECTION_TAG_MAX 2
class DeviceConnectionParser : public ifc_xmlreadercallback
{
public:
DeviceConnectionParser();
~DeviceConnectionParser();
public:
BOOL Begin(obj_xml *reader, ifc_xmlreaderparams *params);
BOOL End(obj_xml *reader, ifc_deviceconnection **connection);
protected:
void Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params);
void Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag);
void Event_XmlCharData(const wchar_t *xmlpath, const wchar_t *xmltag, const wchar_t *value);
void Event_XmlError(int linenum, int errcode, const wchar_t *errstr);
protected:
friend static void DeviceConnectionParser_DisplayNameCb(DeviceConnectionParser *self, ifc_deviceconnectioneditor *editor, const wchar_t *value);
friend static void DeviceConnectionParser_IconCb(DeviceConnectionParser *self, ifc_deviceconnectioneditor *editor, const wchar_t *value);
protected:
StringBuilder elementString;
ifc_deviceconnectioneditor *editor;
BOOL hitList[CONNECTION_TAG_MAX];
SIZE iconSize;
protected:
RECVS_DISPATCH;
};
#endif // _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_CONNECTION_PARSER_HEADER

View File

@ -0,0 +1,178 @@
#include "main.h"
#include "./deviceIconEditor.h"
#define DEVICEICONEDITOR_PROP L"NullsoftDevicesIconEditorProp"
static INT_PTR
DeviceIconEditor_DialogProc(HWND hwnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam);
INT_PTR
DeviceIconEditor_Show(HWND parentWindow, DeviceIconInfo *iconInfo)
{
if (NULL == iconInfo)
return -1;
return WASABI_API_DIALOGBOXPARAMW((INT_PTR)IDD_ICON_EDITOR, parentWindow,
DeviceIconEditor_DialogProc, (LPARAM)iconInfo);
}
static void
DeviceIconEditor_UpdateInfo(HWND hwnd)
{
DeviceIconInfo *iconInfo;
HWND controlWindow;
wchar_t *string;
iconInfo = (DeviceIconInfo*)GetProp(hwnd, DEVICEICONEDITOR_PROP);
if (NULL == iconInfo)
return;
controlWindow = GetDlgItem(hwnd, IDC_EDIT_PATH);
if (NULL != controlWindow)
{
String_Free(iconInfo->path);
iconInfo->path = String_FromWindow(controlWindow);
}
controlWindow = GetDlgItem(hwnd, IDC_EDIT_WIDTH);
if (NULL != controlWindow)
{
string = String_FromWindow(controlWindow);
if (NULL == string ||
FALSE == StrToIntEx(string, STIF_DEFAULT, &iconInfo->width))
{
iconInfo->width = 0;
}
String_Free(string);
}
controlWindow = GetDlgItem(hwnd, IDC_EDIT_HEIGHT);
if (NULL != controlWindow)
{
string = String_FromWindow(controlWindow);
if (NULL == string ||
FALSE == StrToIntEx(string, STIF_DEFAULT, &iconInfo->height))
{
iconInfo->height = 0;
}
String_Free(string);
}
}
static INT_PTR
DeviceIconEditor_OnInitDialog(HWND hwnd, HWND focusWindow, LPARAM param)
{
DeviceIconInfo *iconInfo;
HWND controlWindow;
iconInfo = (DeviceIconInfo*)param;
SetProp(hwnd, DEVICEICONEDITOR_PROP, iconInfo);
if (NULL != iconInfo)
{
wchar_t buffer[64];
controlWindow = GetDlgItem(hwnd, IDC_EDIT_PATH);
if (NULL != controlWindow)
SetWindowText(controlWindow, iconInfo->path);
controlWindow = GetDlgItem(hwnd, IDC_EDIT_WIDTH);
if (NULL != controlWindow)
{
_itow_s(iconInfo->width, buffer, 10);
SetWindowText(controlWindow, buffer);
}
controlWindow = GetDlgItem(hwnd, IDC_EDIT_HEIGHT);
if (NULL != controlWindow)
{
_itow_s(iconInfo->height, buffer, 10);
SetWindowText(controlWindow, buffer);
}
}
return 0;
}
static void
DeviceIconEditor_DisplayFileOpen(HWND hwnd)
{
wchar_t buffer[MAX_PATH * 2];
OPENFILENAME ofn;
HWND controlWindow;
buffer[0] = L'\0';
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = L"Portable Network Graphics\0" L"*.png\0"
L"\0";
ofn.lpstrFile = buffer;
ofn.nMaxFile = ARRAYSIZE(buffer);
ofn.lpstrTitle = L"Load Icon";
ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
if (FALSE == GetOpenFileName(&ofn))
return;
controlWindow = GetDlgItem(hwnd, IDC_EDIT_PATH);
if (NULL != controlWindow)
SetWindowText(controlWindow, buffer);
}
static void
DeviceIconEditor_OnDestroy(HWND hwnd)
{
RemoveProp(hwnd, DEVICEICONEDITOR_PROP);
}
static void
DeviceIconEditor_OnCommand(HWND hwnd, INT commandId, INT eventId, HWND controlWindow)
{
switch(commandId)
{
case IDOK:
switch(eventId)
{
case BN_CLICKED:
DeviceIconEditor_UpdateInfo(hwnd);
EndDialog(hwnd, IDOK);
break;
}
break;
case IDCANCEL:
switch(eventId)
{
case BN_CLICKED:
EndDialog(hwnd, IDCANCEL);
break;
}
break;
case IDC_BUTTON_BROWSE:
switch(eventId)
{
case BN_CLICKED:
DeviceIconEditor_DisplayFileOpen(hwnd);
break;
}
break;
}
}
static INT_PTR
DeviceIconEditor_DialogProc(HWND hwnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG: return DeviceIconEditor_OnInitDialog(hwnd, (HWND)wParam, lParam);
case WM_DESTROY: DeviceIconEditor_OnDestroy(hwnd); return TRUE;
case WM_COMMAND: DeviceIconEditor_OnCommand(hwnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam); return TRUE;
}
return 0;
}

View File

@ -0,0 +1,22 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_ICON_EDITOR_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_ICON_EDITOR_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <wtypes.h>
typedef struct DeviceIconInfo
{
int width;
int height;
wchar_t *path;
} DeviceIconInfo;
INT_PTR
DeviceIconEditor_Show(HWND parentWindow,
DeviceIconInfo *iconInfo);
#endif //_NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_ICON_EDITOR_HEADER

View File

@ -0,0 +1,75 @@
#include "main.h"
#include "./DeviceNodeParser.h"
#include "../../xml/obj_xml.h"
DeviceNodeParser::DeviceNodeParser()
: reader(NULL), test(NULL)
{
}
DeviceNodeParser::~DeviceNodeParser()
{
End();
}
BOOL DeviceNodeParser::Begin(obj_xml *xmlReader, TestSuite *testSuite)
{
if (NULL != reader || NULL != test)
return FALSE;
if (NULL == xmlReader || NULL == testSuite)
return FALSE;
reader = xmlReader;
reader->AddRef();
test = testSuite;
reader->xmlreader_registerCallback(L"testprovider\fdevices\fdevice", this);
return TRUE;
}
void DeviceNodeParser::End()
{
if (NULL != reader)
{
reader->xmlreader_unregisterCallback(this);
reader->Release();
reader = NULL;
}
if (NULL != test)
test = NULL;
}
void DeviceNodeParser::Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params)
{
elementParser.Begin(reader, params);
}
void DeviceNodeParser::Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag)
{
Device *result;
if (FALSE != elementParser.End(reader, &result))
{
if (NULL != test)
test->AddDevice(result);
result->Release();
}
}
void DeviceNodeParser::Event_XmlError(int linenum, int errcode, const wchar_t *errstr)
{
}
#define CBCLASS DeviceNodeParser
START_DISPATCH;
VCB(ONSTARTELEMENT, Event_XmlStartElement)
VCB(ONENDELEMENT, Event_XmlEndElement)
VCB(ONERROR, Event_XmlError)
END_DISPATCH;
#undef CBCLASS

View File

@ -0,0 +1,39 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_NODE_PARSER_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_NODE_PARSER_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <wtypes.h>
#include "../../xml/ifc_xmlreadercallback.h"
#include "./deviceParser.h"
class obj_xml;
class DeviceNodeParser : public ifc_xmlreadercallback
{
public:
DeviceNodeParser();
~DeviceNodeParser();
public:
BOOL Begin(obj_xml *xmlReader, TestSuite *testSuite);
void End();
protected:
void Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params);
void Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag);
void Event_XmlError(int linenum, int errcode, const wchar_t *errstr);
protected:
obj_xml *reader;
DeviceParser elementParser;
TestSuite *test;
protected:
RECVS_DISPATCH;
};
#endif //_NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_NODE_PARSER_HEADER

View File

@ -0,0 +1,306 @@
#include "main.h"
#include "./deviceParser.h"
#include "../../xml/obj_xml.h"
typedef void (*DEVICETAGCALLBACK)(DeviceParser* /*self*/, Device* /*device*/, const wchar_t* /*value*/);
typedef struct DEVICETAG
{
const wchar_t *name;
BOOL multiEntry;
DEVICETAGCALLBACK callback;
} DEVICETAG;
static void
DeviceParser_ConnectionCb(DeviceParser *self, Device *device, const wchar_t *value)
{
char *connectionAnsi;
connectionAnsi = (NULL != value) ?
String_ToAnsi(CP_UTF8, 0, value, -1, NULL, NULL) :
NULL;
device->SetConnection(connectionAnsi);
AnsiString_Free(connectionAnsi);
}
static void
DeviceParser_DisplayNameCb(DeviceParser *self, Device *device, const wchar_t *value)
{
device->SetDisplayName(value);
}
static void
DeviceParser_IconCb(DeviceParser *self, Device *device, const wchar_t *value)
{
device->AddIcon(value, self->iconSize.cx, self->iconSize.cy);
}
static void
DeviceParser_TotalSpaceCb(DeviceParser *self, Device *device, const wchar_t *value)
{
size_t size;
if (NULL == value)
size = -1;
else
{
LONGLONG lval;
if (FALSE == StrToInt64Ex(value, STIF_DEFAULT, &lval))
return;
size = (size_t)lval;
}
device->SetTotalSpace(size);
}
static void
DeviceParser_UsedSpaceCb(DeviceParser *self, Device *device, const wchar_t *value)
{
size_t size;
if (NULL == value)
size = -1;
else
{
LONGLONG lval;
if (FALSE == StrToInt64Ex(value, STIF_DEFAULT, &lval))
return;
size = (size_t)lval;
}
device->SetUsedSpace(size);
}
static void
DeviceParser_HiddenCb(DeviceParser *self, Device *device, const wchar_t *value)
{
int hidden;
if (FALSE != StrToIntEx(value, STIF_DEFAULT, &hidden))
device->SetHidden(0 != hidden);
}
static void
DeviceParser_CommandCb(DeviceParser *self, Device *device, const wchar_t *value)
{
char *command;
if (FALSE != IS_STRING_EMPTY(value))
return;
command = String_ToAnsi(CP_UTF8, 0, value, -1, NULL, NULL);
if (NULL != command)
{
device->AddCommand(command, self->commandFlags);
AnsiString_Free(command);
}
}
static void
DeviceParser_ModelCb(DeviceParser *self, Device *device, const wchar_t *value)
{
device->SetModel(value);
}
static void
DeviceParser_StatusCb(DeviceParser *self, Device *device, const wchar_t *value)
{
device->SetStatus(value);
}
static const DEVICETAG knownTags[DEVICE_TAG_MAX] =
{
{L"connection", FALSE, DeviceParser_ConnectionCb},
{L"displayName", FALSE, DeviceParser_DisplayNameCb},
{L"icon", TRUE, DeviceParser_IconCb},
{L"totalSpace", FALSE, DeviceParser_TotalSpaceCb},
{L"usedSpace", FALSE, DeviceParser_UsedSpaceCb},
{L"hidden", FALSE, DeviceParser_HiddenCb},
{L"command", TRUE, DeviceParser_CommandCb},
{L"model", FALSE, DeviceParser_ModelCb},
{L"status", FALSE, DeviceParser_StatusCb},
};
DeviceParser::DeviceParser()
: device(NULL)
{
}
DeviceParser::~DeviceParser()
{
if (NULL != device)
device->Release();
}
BOOL DeviceParser::Begin(obj_xml *reader, ifc_xmlreaderparams *params)
{
const wchar_t *value;
char *nameAnsi, *typeAnsi;
if (NULL != device)
return FALSE;
if (NULL == reader || NULL == params)
return FALSE;
value = params->getItemValue(L"name");
nameAnsi = (NULL != value) ? String_ToAnsi(CP_UTF8, 0, value, -1, NULL, NULL) : NULL;
value = params->getItemValue(L"type");
typeAnsi = (NULL != value) ? String_ToAnsi(CP_UTF8, 0, value, -1, NULL, NULL) : NULL;
if (NULL == nameAnsi ||
NULL == typeAnsi ||
FAILED(Device::CreateInstance(nameAnsi, typeAnsi, NULL, &device)))
{
device = NULL;
}
AnsiString_Free(nameAnsi);
AnsiString_Free(typeAnsi);
if (NULL == device)
return FALSE;
reader->xmlreader_registerCallback(L"testprovider\fdevices\fdevice\fconnection", this);
reader->xmlreader_registerCallback(L"testprovider\fdevices\fdevice\fdisplayName", this);
reader->xmlreader_registerCallback(L"testprovider\fdevices\fdevice\ficon", this);
reader->xmlreader_registerCallback(L"testprovider\fdevices\fdevice\ftotalSpace", this);
reader->xmlreader_registerCallback(L"testprovider\fdevices\fdevice\fusedSpace", this);
reader->xmlreader_registerCallback(L"testprovider\fdevices\fdevice\fhidden", this);
reader->xmlreader_registerCallback(L"testprovider\fdevices\fdevice\fcommand", this);
reader->xmlreader_registerCallback(L"testprovider\fdevices\fdevice\fmodel", this);
reader->xmlreader_registerCallback(L"testprovider\fdevices\fdevice\fstatus", this);
ZeroMemory(hitList, sizeof(hitList));
return TRUE;
}
BOOL DeviceParser::End(obj_xml *reader, Device **result)
{
if (NULL != reader)
reader->xmlreader_unregisterCallback(this);
if (NULL == device)
return FALSE;
if (NULL != result)
{
*result = device;
device->AddRef();
}
device->Release();
device = NULL;
return TRUE;
}
void DeviceParser::Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params)
{
elementString.Clear();
if (CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, L"icon", -1, xmltag, -1))
{
const wchar_t *sVal;
int iVal;
sVal = params->getItemValue(L"width");
if (NULL == sVal ||
FALSE == StrToIntEx(sVal, STIF_DEFAULT, &iVal))
{
iVal = 0;
}
iconSize.cx = iVal;
sVal = params->getItemValue(L"height");
if (NULL == sVal ||
FALSE == StrToIntEx(sVal, STIF_DEFAULT, &iVal))
{
iVal = 0;
}
iconSize.cy = iVal;
}
else if (CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, L"command", -1, xmltag, -1))
{
const wchar_t *sVal;
int iVal;
commandFlags = DeviceCommandFlag_None;
sVal = params->getItemValue(L"primary");
if (FALSE == IS_STRING_EMPTY(sVal) &&
FALSE != StrToIntEx(sVal, STIF_DEFAULT, &iVal) &&
0 != iVal)
{
commandFlags |= DeviceCommandFlag_Primary;
}
sVal = params->getItemValue(L"group");
if (FALSE == IS_STRING_EMPTY(sVal) &&
FALSE != StrToIntEx(sVal, STIF_DEFAULT, &iVal) &&
0 != iVal)
{
commandFlags |= DeviceCommandFlag_Group;
}
sVal = params->getItemValue(L"disabled");
if (FALSE == IS_STRING_EMPTY(sVal) &&
FALSE != StrToIntEx(sVal, STIF_DEFAULT, &iVal) &&
0 != iVal)
{
commandFlags |= DeviceCommandFlag_Disabled;
}
sVal = params->getItemValue(L"hidden");
if (FALSE == IS_STRING_EMPTY(sVal) &&
FALSE != StrToIntEx(sVal, STIF_DEFAULT, &iVal) &&
0 != iVal)
{
commandFlags |= DeviceCommandFlag_Hidden;
}
}
}
void DeviceParser::Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag)
{
if (NULL == device)
return;
for (size_t i = 0; i < DEVICE_TAG_MAX; i++)
{
if (FALSE == hitList[i] &&
CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, knownTags[i].name, -1, xmltag, -1))
{
knownTags[i].callback(this, device, elementString.Get());
if (FALSE == knownTags[i].multiEntry)
hitList[i] = TRUE;
break;
}
}
}
void DeviceParser::Event_XmlCharData(const wchar_t *xmlpath, const wchar_t *xmltag, const wchar_t *value)
{
elementString.Append(value);
}
void DeviceParser::Event_XmlError(int linenum, int errcode, const wchar_t *errstr)
{
elementString.Clear();
}
#define CBCLASS DeviceParser
START_DISPATCH;
VCB(ONSTARTELEMENT, Event_XmlStartElement)
VCB(ONENDELEMENT, Event_XmlEndElement)
VCB(ONCHARDATA, Event_XmlCharData)
VCB(ONERROR, Event_XmlError)
END_DISPATCH;
#undef CBCLASS

View File

@ -0,0 +1,54 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_PARSER_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_PARSER_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <wtypes.h>
#include "../../xml/ifc_xmlreadercallback.h"
#include "./device.h"
class obj_xml;
#define DEVICE_TAG_MAX 9
class DeviceParser : public ifc_xmlreadercallback
{
public:
DeviceParser();
~DeviceParser();
public:
BOOL Begin(obj_xml *reader, ifc_xmlreaderparams *params);
BOOL End(obj_xml *reader, Device **result);
protected:
void Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params);
void Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag);
void Event_XmlCharData(const wchar_t *xmlpath, const wchar_t *xmltag, const wchar_t *value);
void Event_XmlError(int linenum, int errcode, const wchar_t *errstr);
protected:
friend static void DeviceParser_IconCb(DeviceParser *self, Device *device, const wchar_t *value);
friend static void DeviceParser_ConnectionCb(DeviceParser *self, Device *device, const wchar_t *value);
friend static void DeviceParser_DisplayNameCb(DeviceParser *self, Device *device, const wchar_t *value);
friend static void DeviceParser_TotalSpaceCb(DeviceParser *self, Device *device, const wchar_t *value);
friend static void DeviceParser_UsedSpaceCb(DeviceParser *self, Device *device, const wchar_t *value);
friend static void DeviceParser_HiddenCb(DeviceParser *self, Device *device, const wchar_t *value);
friend static void DeviceParser_CommandCb(DeviceParser *self, Device *device, const wchar_t *value);
friend static void DeviceParser_ModelCb(DeviceParser *self, Device *device, const wchar_t *value);
friend static void DeviceParser_StatusCb(DeviceParser *self, Device *device, const wchar_t *value);
protected:
StringBuilder elementString;
Device *device;
BOOL hitList[DEVICE_TAG_MAX];
SIZE iconSize;
DeviceCommandFlags commandFlags;
protected:
RECVS_DISPATCH;
};
#endif // _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_PARSER_HEADER

View File

@ -0,0 +1,75 @@
#include "main.h"
#include "./DeviceTypeNodeParser.h"
#include "../../xml/obj_xml.h"
DeviceTypeNodeParser::DeviceTypeNodeParser()
: reader(NULL), test(NULL)
{
}
DeviceTypeNodeParser::~DeviceTypeNodeParser()
{
End();
}
BOOL DeviceTypeNodeParser::Begin(obj_xml *xmlReader, TestSuite *testSuite)
{
if (NULL != reader || NULL != test)
return FALSE;
if (NULL == xmlReader || NULL == testSuite)
return FALSE;
reader = xmlReader;
reader->AddRef();
test = testSuite;
reader->xmlreader_registerCallback(L"testprovider\ftypes\ftype", this);
return TRUE;
}
void DeviceTypeNodeParser::End()
{
if (NULL != reader)
{
reader->xmlreader_unregisterCallback(this);
reader->Release();
reader = NULL;
}
if (NULL != test)
test = NULL;
}
void DeviceTypeNodeParser::Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params)
{
elementParser.Begin(reader, params);
}
void DeviceTypeNodeParser::Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag)
{
ifc_devicetype *result;
if (FALSE != elementParser.End(reader, &result))
{
if (NULL != test)
test->AddType(result);
result->Release();
}
}
void DeviceTypeNodeParser::Event_XmlError(int linenum, int errcode, const wchar_t *errstr)
{
}
#define CBCLASS DeviceTypeNodeParser
START_DISPATCH;
VCB(ONSTARTELEMENT, Event_XmlStartElement)
VCB(ONENDELEMENT, Event_XmlEndElement)
VCB(ONERROR, Event_XmlError)
END_DISPATCH;
#undef CBCLASS

View File

@ -0,0 +1,39 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_TYPE_NODE_PARSER_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_TYPE_NODE_PARSER_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <wtypes.h>
#include "../../xml/ifc_xmlreadercallback.h"
#include "./deviceTypeParser.h"
class obj_xml;
class DeviceTypeNodeParser : public ifc_xmlreadercallback
{
public:
DeviceTypeNodeParser();
~DeviceTypeNodeParser();
public:
BOOL Begin(obj_xml *xmlReader, TestSuite *testSuite);
void End();
protected:
void Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params);
void Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag);
void Event_XmlError(int linenum, int errcode, const wchar_t *errstr);
protected:
obj_xml *reader;
DeviceTypeParser elementParser;
TestSuite *test;
protected:
RECVS_DISPATCH;
};
#endif //_NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_TYPE_NODE_PARSER_HEADER

View File

@ -0,0 +1,182 @@
#include "main.h"
#include "./deviceTypeParser.h"
#include "../../xml/obj_xml.h"
typedef void (*TYPETAGCALLBACK)(DeviceTypeParser* /*self*/, ifc_devicetypeeditor* /*editor*/, const wchar_t* /*value*/);
typedef struct TYPETAG
{
const wchar_t *name;
BOOL multiEntry;
TYPETAGCALLBACK callback;
} TYPETAG;
static void
DeviceTypeParser_DisplayNameCb(DeviceTypeParser *self, ifc_devicetypeeditor *editor, const wchar_t *value)
{
editor->SetDisplayName(value);
}
static void
DeviceTypeParser_IconCb(DeviceTypeParser *self, ifc_devicetypeeditor *editor, const wchar_t *value)
{
ifc_deviceiconstore *iconStore;
if (SUCCEEDED(editor->GetIconStore(&iconStore)))
{
iconStore->Add(value, self->iconSize.cx, self->iconSize.cy, TRUE);
iconStore->Release();
}
}
static const TYPETAG knownTags[TYPE_TAG_MAX] =
{
{L"displayName", FALSE, DeviceTypeParser_DisplayNameCb},
{L"icon", TRUE, DeviceTypeParser_IconCb},
};
DeviceTypeParser::DeviceTypeParser()
: editor(NULL)
{
}
DeviceTypeParser::~DeviceTypeParser()
{
if (NULL != editor)
editor->Release();
}
BOOL DeviceTypeParser::Begin(obj_xml *reader, ifc_xmlreaderparams *params)
{
const wchar_t *name;
ifc_devicetype *type;
char *nameAnsi;
if (NULL != editor)
return FALSE;
if (NULL == reader || NULL == params)
return FALSE;
name = params->getItemValue(L"name");
if (NULL == name)
return FALSE;
nameAnsi = String_ToAnsi(CP_UTF8, 0, name, -1, NULL, NULL);
if (NULL == nameAnsi)
return FALSE;
if (NULL != WASABI_API_DEVICES &&
SUCCEEDED(WASABI_API_DEVICES->CreateType(nameAnsi, &type)))
{
if(FAILED(type->QueryInterface(IFC_DeviceTypeEditor, (void**)&editor)))
editor = NULL;
type->Release();
}
AnsiString_Free(nameAnsi);
if (NULL == editor)
return FALSE;
reader->xmlreader_registerCallback(L"testprovider\ftypes\ftype\fdisplayName", this);
reader->xmlreader_registerCallback(L"testprovider\ftypes\ftype\ficon", this);
ZeroMemory(hitList, sizeof(hitList));
return TRUE;
}
BOOL DeviceTypeParser::End(obj_xml *reader, ifc_devicetype **deviceType)
{
BOOL result;
if (NULL != reader)
reader->xmlreader_unregisterCallback(this);
if (NULL == editor)
return FALSE;
if (NULL != deviceType)
{
if (FAILED(editor->QueryInterface(IFC_DeviceType, (void**)deviceType)))
result = FALSE;
else
result = TRUE;
}
else
result = TRUE;
editor->Release();
editor = NULL;
return result;
}
void DeviceTypeParser::Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params)
{
elementString.Clear();
if (CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, L"icon", -1, xmltag, -1))
{
const wchar_t *sVal;
int iVal;
sVal = params->getItemValue(L"width");
if (NULL == sVal ||
FALSE == StrToIntEx(sVal, STIF_DEFAULT, &iVal))
{
iVal = 0;
}
iconSize.cx = iVal;
sVal = params->getItemValue(L"height");
if (NULL == sVal ||
FALSE == StrToIntEx(sVal, STIF_DEFAULT, &iVal))
{
iVal = 0;
}
iconSize.cy = iVal;
}
}
void DeviceTypeParser::Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag)
{
if (NULL == editor)
return;
for (size_t i = 0; i < TYPE_TAG_MAX; i++)
{
if (FALSE == hitList[i] &&
CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, knownTags[i].name, -1, xmltag, -1))
{
knownTags[i].callback(this, editor, elementString.Get());
if (FALSE == knownTags[i].multiEntry)
hitList[i] = TRUE;
break;
}
}
}
void DeviceTypeParser::Event_XmlCharData(const wchar_t *xmlpath, const wchar_t *xmltag, const wchar_t *value)
{
elementString.Append(value);
}
void DeviceTypeParser::Event_XmlError(int linenum, int errcode, const wchar_t *errstr)
{
elementString.Clear();
}
#define CBCLASS DeviceTypeParser
START_DISPATCH;
VCB(ONSTARTELEMENT, Event_XmlStartElement)
VCB(ONENDELEMENT, Event_XmlEndElement)
VCB(ONCHARDATA, Event_XmlCharData)
VCB(ONERROR, Event_XmlError)
END_DISPATCH;
#undef CBCLASS

View File

@ -0,0 +1,46 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_TYPE_PARSER_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_TYPE_PARSER_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <wtypes.h>
#include "../../xml/ifc_xmlreadercallback.h"
class obj_xml;
#define TYPE_TAG_MAX 2
class DeviceTypeParser : public ifc_xmlreadercallback
{
public:
DeviceTypeParser();
~DeviceTypeParser();
public:
BOOL Begin(obj_xml *reader, ifc_xmlreaderparams *params);
BOOL End(obj_xml *reader, ifc_devicetype **deviceType);
protected:
void Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params);
void Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag);
void Event_XmlCharData(const wchar_t *xmlpath, const wchar_t *xmltag, const wchar_t *value);
void Event_XmlError(int linenum, int errcode, const wchar_t *errstr);
protected:
friend static void DeviceTypeParser_DisplayNameCb(DeviceTypeParser *self, ifc_devicetypeeditor *editor, const wchar_t *value);
friend static void DeviceTypeParser_IconCb(DeviceTypeParser *self, ifc_devicetypeeditor *editor, const wchar_t *value);
protected:
StringBuilder elementString;
ifc_devicetypeeditor *editor;
BOOL hitList[TYPE_TAG_MAX];
SIZE iconSize;
protected:
RECVS_DISPATCH;
};
#endif // _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_TYPE_PARSER_HEADER

View File

@ -0,0 +1,994 @@
#include "main.h"
#include "./deviceView.h"
#include <wincodec.h>
#include <commctrl.h>
#include <strsafe.h>
#include <vector>
#include <algorithm>
#define DEVICEVIEW_PROP L"NullsoftDevicesViewProp"
static ATOM DEVICEVIEW_ATOM = 0;
typedef struct DeviceView
{
Device *device;
} DeviceView;
typedef std::vector<DeviceIconInfo*> DeviceIconInfoList;
static INT_PTR
DeviceView_DialogProc(HWND hwnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam);
#define DEVICEVIEW(_hwnd) ((DeviceView*)GetPropW((_hwnd), MAKEINTATOM(DEVICEVIEW_ATOM)))
#define DEVICEVIEW_RET_VOID(_view, _hwnd) { (_view) = DEVICEVIEW((_hwnd)); if (NULL == (_view)) return; }
#define DEVICEVIEW_RET_VAL(_view, _hwnd, _error) { (_view) = DEVICEVIEW((_hwnd)); if (NULL == (_view)) return (_error); }
static HBITMAP
DeviceView_HBitmapFromWicSource(IWICBitmapSource *wicSource)
{
HRESULT hr;
HBITMAP bitmap;
BITMAPINFO bitmapInfo;
unsigned int width, height;
void *pixelData = NULL;
HDC windowDC;
unsigned int strideSize, imageSize;
if (NULL == wicSource)
return NULL;
hr = wicSource->GetSize(&width, &height);
if (FAILED(hr))
return NULL;
ZeroMemory(&bitmapInfo, sizeof(bitmapInfo));
bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapInfo.bmiHeader.biWidth = width;
bitmapInfo.bmiHeader.biHeight = -(LONG)height;
bitmapInfo.bmiHeader.biPlanes = 1;
bitmapInfo.bmiHeader.biBitCount = 32;
bitmapInfo.bmiHeader.biCompression = BI_RGB;
windowDC = GetDCEx(NULL, NULL, DCX_WINDOW | DCX_CACHE);
bitmap = CreateDIBSection(windowDC, &bitmapInfo, DIB_RGB_COLORS, &pixelData, NULL, 0);
if (NULL != windowDC)
ReleaseDC(NULL, windowDC);
if (NULL == bitmap)
return NULL;
hr = UIntMult(width, sizeof(DWORD), &strideSize);
if (SUCCEEDED(hr))
{
hr = UIntMult(strideSize, height, &imageSize);
if (SUCCEEDED(hr))
hr = wicSource->CopyPixels(NULL, strideSize, imageSize, (BYTE*)pixelData);
}
if (FAILED(hr))
{
DeleteObject(bitmap);
bitmap = NULL;
}
return bitmap;
}
static HBITMAP
DeviceView_LoadIcon(const wchar_t *path)
{
IWICImagingFactory *wicFactory;
IWICBitmapDecoder *wicDecoder;
HRESULT hr;
HBITMAP bitmap;
hr = CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&wicFactory));
if (FAILED(hr))
return NULL;
bitmap = NULL;
hr = wicFactory->CreateDecoderFromFilename(path, NULL, GENERIC_READ,
WICDecodeMetadataCacheOnDemand, &wicDecoder);
if (SUCCEEDED(hr))
{
IWICBitmapFrameDecode *wicFrame;
hr = wicDecoder->GetFrame(0, &wicFrame);
if(SUCCEEDED(hr))
{
IWICBitmapSource *wicSource;
hr = wicFrame->QueryInterface(IID_IWICBitmapSource,
reinterpret_cast<void **>(&wicSource));
if (SUCCEEDED(hr))
{
WICPixelFormatGUID pixelFormat;
hr = wicSource->GetPixelFormat(&pixelFormat);
if (FAILED(hr) ||
(GUID_WICPixelFormat32bppPBGRA != pixelFormat &&
GUID_WICPixelFormat32bppBGR != pixelFormat &&
GUID_WICPixelFormat32bppBGRA != pixelFormat &&
GUID_WICPixelFormat32bppRGBA != pixelFormat &&
GUID_WICPixelFormat32bppPRGBA != pixelFormat))
{
// try to convert
IWICFormatConverter *wicConverter;
hr = wicFactory->CreateFormatConverter(&wicConverter);
if (SUCCEEDED(hr))
{
hr = wicConverter->Initialize(wicSource, GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone, NULL, 0.f, WICBitmapPaletteTypeCustom);
if (SUCCEEDED(hr))
{
IWICBitmapSource *wicConvertedSource;
hr = wicConverter->QueryInterface(IID_IWICBitmapSource,
reinterpret_cast<void **>(&wicConvertedSource));
if (SUCCEEDED(hr))
{
wicSource->Release();
wicSource = wicConvertedSource;
}
}
wicConverter->Release();
}
}
if (SUCCEEDED(hr))
bitmap = DeviceView_HBitmapFromWicSource(wicSource);
wicSource->Release();
}
wicFrame->Release();
}
wicDecoder->Release();
}
wicFactory->Release();
return bitmap;
}
HWND
DeviceView_CreateWindow(HWND parentWindow, Device *device)
{
HWND hwnd;
if (NULL == device)
return NULL;
if (0 == DEVICEVIEW_ATOM)
{
DEVICEVIEW_ATOM = GlobalAddAtom(DEVICEVIEW_PROP);
if (0 == DEVICEVIEW_ATOM)
return NULL;
}
hwnd = WASABI_API_CREATEDIALOGPARAMW((INT_PTR)IDD_DEVICE_VIEW, parentWindow,
DeviceView_DialogProc, (LPARAM)device);
return hwnd;
}
static void
DeviceView_InitCapacity(HWND hwnd)
{
DeviceView *self;
HWND controlWindow;
uint64_t totalSpace, usedSpace;
DEVICEVIEW_RET_VOID(self, hwnd);
if (NULL != self->device)
{
if (FAILED(self->device->GetTotalSpace(&totalSpace)))
totalSpace = 0;
if (FAILED(self->device->GetUsedSpace(&usedSpace)))
usedSpace = 0;
}
else
{
totalSpace = 0;
usedSpace = 0;
}
controlWindow = GetDlgItem(hwnd, IDC_SPIN_TOTALSPACE);
if (NULL != controlWindow)
{
SendMessage(controlWindow, UDM_SETRANGE32, (WPARAM)0, (LPARAM)0xFFFFFF);
SendMessage(controlWindow, UDM_SETPOS32, (WPARAM)0, (LPARAM)totalSpace);
}
controlWindow = GetDlgItem(hwnd, IDC_SPIN_USEDSPACE);
if (NULL != controlWindow)
{
SendMessage(controlWindow, UDM_SETRANGE32, (WPARAM)0, (LPARAM)totalSpace);
SendMessage(controlWindow, UDM_SETPOS32, (WPARAM)0, (LPARAM)usedSpace);
}
}
static int
DeviceView_CompareDeviceIconInfo(const void *elem1, const void *elem2)
{
DeviceIconInfo *info1;
DeviceIconInfo *info2;
info1 = *((DeviceIconInfo**)elem1);
info2 = *((DeviceIconInfo**)elem2);
if (NULL == info1 || NULL == info2)
return (int)(info1 - info2);
if (info1->width != info2->width)
return (int)(info1->width - info2->width);
if (info1->height != info2->height)
return (int)(info1->height - info2->height);
if (NULL == info1->path || NULL == info2->path)
return (int)(info1->path - info2->path);
return CompareString(CSTR_INVARIANT, NORM_IGNORECASE, info1->path, -1, info2->path, -1) - 2;
}
static int
DeviceView_CompareDeviceIconInfo_V2(const void* elem1, const void* elem2)
{
return DeviceView_CompareDeviceIconInfo(elem1, elem2) < 0;
}
static BOOL
DeviceView_EnumerateIcons(const wchar_t *path, unsigned int width, unsigned int height, void *user)
{
DeviceIconInfo *info;
DeviceIconInfoList *list = (DeviceIconInfoList*)user;
if( NULL == list)
return FALSE;
info = (DeviceIconInfo*)malloc(sizeof(DeviceIconInfo));
if (NULL != info)
{
info->height = height;
info->width = width;
info->path = String_Duplicate(path);
list->push_back(info);
}
return TRUE;
}
static void
DeviceView_DestroyIcons(HWND hwnd)
{
HWND controlWindow;
int count, index;
DeviceIconInfo *info;
controlWindow = GetDlgItem(hwnd, IDC_COMBO_ICONS);
if (NULL == controlWindow)
return;
count = (int)SendMessage(controlWindow, CB_GETCOUNT, 0, 0L);
for(index = 0; index < count; index++)
{
info = (DeviceIconInfo*)SendMessage(controlWindow, CB_GETITEMDATA, index, 0L);
if (CB_ERR != (INT_PTR)info)
{
String_Free(info->path);
free(info);
}
}
SendMessage(controlWindow, CB_RESETCONTENT, 0, 0L);
controlWindow = GetDlgItem(hwnd, IDC_STATIC_PREVIEWICON);
if (NULL != controlWindow)
{
HBITMAP bitmap;
bitmap = (HBITMAP)SendMessage(controlWindow, STM_GETIMAGE, IMAGE_BITMAP, 0L);
if(NULL != bitmap)
DeleteObject(bitmap);
}
}
static void
DeviceView_InitIcons(HWND hwnd, const wchar_t *selectPath)
{
DeviceView *self;
DeviceIconInfoList list;
HWND controlWindow;
wchar_t buffer[2048];
DEVICEVIEW_RET_VOID(self, hwnd);
DeviceView_DestroyIcons(hwnd);
controlWindow = GetDlgItem(hwnd, IDC_COMBO_ICONS);
if (NULL != controlWindow)
{
size_t index, count;
int iItem, iSelect;
DeviceIconInfo *info;
if (NULL != self->device)
{
self->device->EnumerateIcons(DeviceView_EnumerateIcons, &list);
}
count = list.size();
//qsort(list.begin(), count, sizeof(DeviceIconInfo**), DeviceView_CompareDeviceIconInfo);
std::sort(list.begin(), list.end(), DeviceView_CompareDeviceIconInfo_V2);
iSelect = 0;
for(index = 0; index < count; index++)
{
info = list[index];
if (1 == info->width && 1 == info->height)
{
StringCchPrintf(buffer, ARRAYSIZE(buffer), L"%s",
info->path);
}
else
{
StringCchPrintf(buffer, ARRAYSIZE(buffer), L"[%dx%d] - %s",
info->width, info->height, info->path);
}
iItem = (int)SendMessage(controlWindow, CB_ADDSTRING, 0, (LPARAM)buffer);
if (CB_ERR != iItem)
{
if (CB_ERR == (int)SendMessage(controlWindow, CB_SETITEMDATA, index, (LPARAM)info))
{
SendMessage(controlWindow, CB_DELETESTRING, index, 0L);
iItem = CB_ERR;
}
}
if (CB_ERR == iItem)
{
free(info);
}
else if (NULL != selectPath &&
CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE,
info->path, -1, selectPath, -1))
{
iSelect = iItem;
}
}
iItem = (int)SendMessage(controlWindow, CB_GETCOUNT, 0, 0L);
if (CB_ERR == iItem)
iItem = 0;
EnableWindow(GetDlgItem(hwnd, IDC_BUTTON_EDITICON), (0 != iItem));
EnableWindow(GetDlgItem(hwnd, IDC_BUTTON_REMOVEICON),(0 != iItem));
SendMessage(controlWindow, CB_SETCURSEL, iSelect, 0L);
PostMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDC_COMBO_ICONS, CBN_SELENDOK), (LPARAM)controlWindow);
}
}
static void
DeviceView_NewIcon(HWND hwnd)
{
DeviceView *self;
DeviceIconInfo info;
INT_PTR result;
DEVICEVIEW_RET_VOID(self, hwnd);
ZeroMemory(&info, sizeof(info));
result = DeviceIconEditor_Show(hwnd, &info);
if (IDOK == result)
{
if (NULL != self->device &&
SUCCEEDED(self->device->AddIcon(info.path, info.width, info.height)))
{
DeviceView_InitIcons(hwnd, info.path);
}
String_Free(info.path);
}
}
static void
DeviceView_RemoveIcon(HWND hwnd)
{
DeviceView *self;
DeviceIconInfo *info;
int index, count;
HWND controlWindow;
DEVICEVIEW_RET_VOID(self, hwnd);
controlWindow = GetDlgItem(hwnd, IDC_COMBO_ICONS);
if (NULL == controlWindow)
return;
index = (int)SendMessage(controlWindow, CB_GETCURSEL, 0, 0L);
if (CB_ERR == index)
return;
info = (DeviceIconInfo*)SendMessage(controlWindow, CB_GETITEMDATA, index, 0L);
if (CB_ERR != (INT_PTR)info)
{
if (NULL != self->device)
self->device->RemoveIcon(info->width, info->height);
String_Free(info->path);
free(info);
}
SendMessage(controlWindow, CB_DELETESTRING, index, 0L);
count = (int)SendMessage(controlWindow, CB_GETCOUNT, 0, 0L);
if (count > 0)
{
if (index > count)
index = count - 1;
SendMessage(controlWindow, CB_SETCURSEL, index, 0L);
}
else
{
SendMessage(controlWindow, CB_SETCURSEL, -1, 0L);
EnableWindow(GetDlgItem(hwnd, IDC_BUTTON_EDITICON),FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_BUTTON_REMOVEICON),FALSE);
}
PostMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDC_COMBO_ICONS, CBN_SELENDOK), (LPARAM)controlWindow);
UpdateWindow(controlWindow);
}
static void
DeviceView_EditIcon(HWND hwnd)
{
DeviceView *self;
DeviceIconInfo *info;
int index;
unsigned int width, height;
HWND controlWindow;
INT_PTR result;
DEVICEVIEW_RET_VOID(self, hwnd);
controlWindow = GetDlgItem(hwnd, IDC_COMBO_ICONS);
if (NULL == controlWindow)
return;
index = (int)SendMessage(controlWindow, CB_GETCURSEL, 0, 0L);
if (CB_ERR == index)
return;
info = (DeviceIconInfo*)SendMessage(controlWindow, CB_GETITEMDATA, index, 0L);
if (CB_ERR == (INT_PTR)info)
return;
width = info->width;
height = info->height;
result = DeviceIconEditor_Show(hwnd, info);
if (IDOK == result)
{
if (NULL != self->device)
{
self->device->RemoveIcon(width, height);
self->device->AddIcon(info->path, info->width, info->height);
DeviceView_InitIcons(hwnd, info->path);
}
}
UpdateWindow(controlWindow);
}
static void
DeviceView_InitView(HWND hwnd)
{
DeviceView *self;
HWND controlWindow;
wchar_t buffer[1024];
DEVICEVIEW_RET_VOID(self, hwnd);
controlWindow = GetDlgItem(hwnd, IDC_EDIT_NAME);
if (NULL != controlWindow)
{
if (NULL == self->device ||
0 == MultiByteToWideChar(CP_UTF8, 0, self->device->GetName(), -1, buffer, ARRAYSIZE(buffer)))
{
StringCchCopy(buffer, ARRAYSIZE(buffer), L"<unknown>");
}
SetWindowText(controlWindow, buffer);
}
controlWindow = GetDlgItem(hwnd, IDC_EDIT_TITLE);
if (NULL != controlWindow)
{
if (NULL == self->device ||
FAILED(self->device->GetDisplayName(buffer, ARRAYSIZE(buffer))))
{
StringCchCopy(buffer, ARRAYSIZE(buffer), L"<unknown>");
}
SetWindowText(controlWindow, buffer);
}
controlWindow = GetDlgItem(hwnd, IDC_EDIT_TYPE);
if (NULL != controlWindow)
{
buffer[0] = L'\0';
if (NULL != self->device)
{
const char *typeName;
ifc_devicetype *type;
typeName = self->device->GetType();
if (NULL != WASABI_API_DEVICES &&
S_OK == WASABI_API_DEVICES->TypeFind(typeName, &type))
{
if (FAILED(type->GetDisplayName(buffer, ARRAYSIZE(buffer))))
buffer[0] = L'\0';
type->Release();
}
if (L'\0' == *buffer)
MultiByteToWideChar(CP_UTF8, 0, typeName, -1, buffer, ARRAYSIZE(buffer));
}
if (L'\0' == *buffer)
StringCchCopy(buffer, ARRAYSIZE(buffer), L"<unknown>");
SetWindowText(controlWindow, buffer);
}
controlWindow = GetDlgItem(hwnd, IDC_EDIT_CONNECTION);
if (NULL != controlWindow)
{
buffer[0] = L'\0';
if (NULL != self->device)
{
const char *connectionName;
ifc_deviceconnection *connection;
connectionName = self->device->GetConnection();
if (NULL != WASABI_API_DEVICES &&
S_OK == WASABI_API_DEVICES->ConnectionFind(connectionName, &connection))
{
if (FAILED(connection->GetDisplayName(buffer, ARRAYSIZE(buffer))))
buffer[0] = L'\0';
connection->Release();
}
if (L'\0' == *buffer)
MultiByteToWideChar(CP_UTF8, 0, connectionName, -1, buffer, ARRAYSIZE(buffer));
}
if (L'\0' == *buffer)
StringCchCopy(buffer, ARRAYSIZE(buffer), L"<unknown>");
SetWindowText(controlWindow, buffer);
}
controlWindow = GetDlgItem(hwnd, IDC_COMBO_ATTACHED);
if (NULL != controlWindow)
{
SendMessage(controlWindow, CB_RESETCONTENT, 0, 0L);
if (NULL != self->device)
{
const wchar_t *searchString;
SendMessage(controlWindow, CB_ADDSTRING, 0, (LPARAM)L"Yes");
SendMessage(controlWindow, CB_ADDSTRING, 0, (LPARAM)L"No");
if (FALSE == self->device->GetAttached())
searchString = L"No";
else
searchString = L"Yes";
SendMessage(controlWindow, CB_SELECTSTRING, -1, (LPARAM)searchString);
}
else
{
SendMessage(controlWindow, CB_ADDSTRING, 0, (LPARAM)L"<unknown>");
SendMessage(controlWindow, CB_SETCURSEL, 0, 0L);
}
}
controlWindow = GetDlgItem(hwnd, IDC_COMBO_VISIBLE);
if (NULL != controlWindow)
{
SendMessage(controlWindow, CB_RESETCONTENT, 0, 0L);
if (NULL != self->device)
{
const wchar_t *searchString;
SendMessage(controlWindow, CB_ADDSTRING, 0, (LPARAM)L"Yes");
SendMessage(controlWindow, CB_ADDSTRING, 0, (LPARAM)L"No");
if (FALSE != self->device->GetHidden())
searchString = L"No";
else
searchString = L"Yes";
SendMessage(controlWindow, CB_SELECTSTRING, -1, (LPARAM)searchString);
}
else
{
SendMessage(controlWindow, CB_ADDSTRING, 0, (LPARAM)L"<unknown>");
SendMessage(controlWindow, CB_SETCURSEL, 0, 0L);
}
}
DeviceView_InitCapacity(hwnd);
DeviceView_InitIcons(hwnd, NULL);
}
static INT_PTR
DeviceView_OnInitDialog(HWND hwnd, HWND focusWindow, LPARAM param)
{
DeviceView *self;
self = (DeviceView*)malloc(sizeof(DeviceView));
if (NULL != self)
{
ZeroMemory(self, sizeof(DeviceView));
if (FALSE == SetProp(hwnd, MAKEINTATOM(DEVICEVIEW_ATOM), self))
{
free(self);
self = NULL;
}
}
if (NULL == self)
{
DestroyWindow(hwnd);
return 0;
}
self->device = (Device*)param;
if (NULL != self->device)
self->device->AddRef();
DeviceView_InitView(hwnd);
SetWindowPos(hwnd, NULL, 0, 0, 0, 0,
SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_FRAMECHANGED);
return 0;
}
static void
DeviceView_OnDestroy(HWND hwnd)
{
DeviceView *self;
DeviceView_DestroyIcons(hwnd);
self = DEVICEVIEW(hwnd);
RemoveProp(hwnd, MAKEINTATOM(DEVICEVIEW_ATOM));
if (NULL == self)
return;
if (NULL != self->device)
self->device->Release();
free(self);
}
static void
DeviceView_OnTitleEditChanged(HWND hwnd)
{
DeviceView *self;
HWND controlWindow;
wchar_t buffer[1024];
DEVICEVIEW_RET_VOID(self, hwnd);
controlWindow = GetDlgItem(hwnd, IDC_EDIT_TITLE);
if (NULL == controlWindow)
return;
if (NULL == self->device)
return;
GetWindowText(controlWindow, buffer, ARRAYSIZE(buffer));
self->device->SetDisplayName(buffer);
}
static void
DeviceView_OnAttachedComboChanged(HWND hwnd)
{
DeviceView *self;
HWND controlWindow;
wchar_t buffer[1024];
int index;
DEVICEVIEW_RET_VOID(self, hwnd);
controlWindow = GetDlgItem(hwnd, IDC_COMBO_ATTACHED);
if (NULL == controlWindow)
return;
if (NULL == self->device)
return;
index = (int)SendMessage(controlWindow, CB_GETCURSEL, 0, 0);
if (CB_ERR != index &&
CB_ERR != SendMessage(controlWindow, CB_GETLBTEXT, index, (LPARAM)buffer))
{
if (CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, buffer, -1, L"Yes", -1))
{
self->device->Attach(NULL);
}
else if (CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, buffer, -1, L"No", -1))
{
self->device->Detach(NULL);
}
}
}
static void
DeviceView_OnVisibleComboChanged(HWND hwnd)
{
DeviceView *self;
HWND controlWindow;
wchar_t buffer[1024];
int index;
DEVICEVIEW_RET_VOID(self, hwnd);
controlWindow = GetDlgItem(hwnd, IDC_COMBO_VISIBLE);
if (NULL == controlWindow)
return;
if (NULL == self->device)
return;
index = (int)SendMessage(controlWindow, CB_GETCURSEL, 0, 0);
if (-1 != index &&
CB_ERR != SendMessage(controlWindow, CB_GETLBTEXT, index, (LPARAM)buffer))
{
if (CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, buffer, -1, L"Yes", -1))
{
self->device->SetHidden(FALSE);
}
else if (CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, buffer, -1, L"No", -1))
{
self->device->SetHidden(TRUE);
}
}
}
static void
DeviceView_OnIconsComboChanged(HWND hwnd)
{
DeviceView *self;
HWND controlWindow, pictureWindow;
int index;
HBITMAP bitmap, previousBitmap;
DEVICEVIEW_RET_VOID(self, hwnd);
controlWindow = GetDlgItem(hwnd, IDC_COMBO_ICONS);
if (NULL == controlWindow)
return;
if (NULL == self->device)
return;
pictureWindow = GetDlgItem(hwnd, IDC_STATIC_PREVIEWICON);
if (NULL == pictureWindow)
return;
bitmap = NULL;
index = (int)SendMessage(controlWindow, CB_GETCURSEL, 0, 0);\
if (CB_ERR != index)
{
DeviceIconInfo *info;
info = (DeviceIconInfo*)SendMessage(controlWindow, CB_GETITEMDATA, index, 0L);
if (CB_ERR != (INT_PTR)info && NULL != info->path)
{
bitmap = DeviceView_LoadIcon(info->path);
}
}
previousBitmap = (HBITMAP)SendMessage(pictureWindow, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)bitmap);
if (NULL != previousBitmap)
DeleteObject(previousBitmap);
previousBitmap = (HBITMAP)SendMessage(pictureWindow, STM_GETIMAGE, IMAGE_BITMAP, 0L);
if(previousBitmap != bitmap)
{
if (NULL != bitmap)
DeleteObject(bitmap);
}
}
static void
DeviceView_OnTotalSpaceEditChanged(HWND hwnd)
{
DeviceView *self;
HWND controlWindow;
uint64_t totalSpace;
BOOL error;
DEVICEVIEW_RET_VOID(self, hwnd);
controlWindow = GetDlgItem(hwnd, IDC_SPIN_TOTALSPACE);
if (NULL == controlWindow)
return;
if (NULL == self->device)
return;
totalSpace = (size_t)SendMessage(controlWindow, UDM_GETPOS32, 0, (LPARAM)&error);
if (FALSE != error)
return;
if (FAILED(self->device->SetTotalSpace(totalSpace)))
{
if (FAILED(self->device->GetTotalSpace(&totalSpace)))
totalSpace = 0;
}
controlWindow = GetDlgItem(hwnd, IDC_SPIN_USEDSPACE);
if (NULL != controlWindow)
{
SendMessage(controlWindow, UDM_SETRANGE32, (WPARAM)0, (LPARAM)totalSpace);
}
}
static void
DeviceView_OnUsedSpaceEditChanged(HWND hwnd)
{
DeviceView *self;
HWND controlWindow;
uint64_t usedSpace;
BOOL error;
DEVICEVIEW_RET_VOID(self, hwnd);
controlWindow = GetDlgItem(hwnd, IDC_SPIN_USEDSPACE);
if (NULL == controlWindow)
return;
if (NULL == self->device)
return;
usedSpace = (size_t)SendMessage(controlWindow, UDM_GETPOS32, 0, (LPARAM)&error);
if (FALSE != error)
return;
if (FAILED(self->device->SetUsedSpace(usedSpace)))
{
if (FAILED(self->device->GetTotalSpace(&usedSpace)))
usedSpace = 0;
}
}
static void
DeviceView_OnCommand(HWND hwnd, INT commandId, INT eventId, HWND controlWindow)
{
switch(commandId)
{
case IDC_EDIT_TITLE:
switch(eventId)
{
case EN_CHANGE:
DeviceView_OnTitleEditChanged(hwnd);
break;
}
break;
case IDC_COMBO_ATTACHED:
switch(eventId)
{
case CBN_SELENDOK:
DeviceView_OnAttachedComboChanged(hwnd);
break;
}
break;
case IDC_COMBO_VISIBLE:
switch(eventId)
{
case CBN_SELENDOK:
DeviceView_OnVisibleComboChanged(hwnd);
break;
}
break;
case IDC_COMBO_ICONS:
switch(eventId)
{
case CBN_SELENDOK:
DeviceView_OnIconsComboChanged(hwnd);
break;
}
break;
case IDC_EDIT_TOTALSPACE:
switch(eventId)
{
case EN_CHANGE:
DeviceView_OnTotalSpaceEditChanged(hwnd);
break;
}
break;
case IDC_EDIT_USEDSPACE:
switch(eventId)
{
case EN_CHANGE:
DeviceView_OnUsedSpaceEditChanged(hwnd);
break;
}
break;
case IDC_BUTTON_NEWICON:
switch(eventId)
{
case BN_CLICKED:
DeviceView_NewIcon(hwnd);
break;
}
break;
case IDC_BUTTON_REMOVEICON:
switch(eventId)
{
case BN_CLICKED:
DeviceView_RemoveIcon(hwnd);
break;
}
break;
case IDC_BUTTON_EDITICON:
switch(eventId)
{
case BN_CLICKED:
DeviceView_EditIcon(hwnd);
break;
}
break;
}
}
static INT_PTR
DeviceView_DialogProc(HWND hwnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG: return DeviceView_OnInitDialog(hwnd, (HWND)wParam, lParam);
case WM_DESTROY: DeviceView_OnDestroy(hwnd); return TRUE;
case WM_COMMAND: DeviceView_OnCommand(hwnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam); return TRUE;
}
return 0;
}

View File

@ -0,0 +1,15 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_VIEW_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_VIEW_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <wtypes.h>
HWND
DeviceView_CreateWindow(HWND parentWindow,
Device *device);
#endif //_NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_VIEW_HEADER

View File

@ -0,0 +1,415 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="gen_deviceprovider"
ProjectGUID="{A3C7D830-CD01-4C2B-9E1A-FB62B5236BA9}"
RootNamespace="gen_deviceprovider"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../..;../../wasabi;../../agave"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;GEN_DEVICEPROVIDER_EXPORTS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
PrecompiledHeaderThrough=""
WarningLevel="3"
DebugInformationFormat="4"
EnablePREfast="false"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="comctl32.lib shlwapi.lib windowscodecs.lib"
OutputFile="$(ProgramFiles)\winamp\plugins\gen_deviceprovider.dll"
LinkIncremental="2"
IgnoreDefaultLibraryNames="msvcprt.lib"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(OutDir)\$(TargetName).pdb"
SubSystem="2"
SupportUnloadOfDelayLoadedDLL="true"
ImportLibrary="$(OutDir)\$(TargetName).lib"
TargetMachine="1"
Profile="false"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
OutputDocumentFile="$(OutDir)\$(TargetName).xml"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../..;../../wasabi;../../agave"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;GEN_DEVICEPROVIDER_EXPORTS"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="main.h"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="comctl32.lib shlwapi.lib windowscodecs.lib"
OutputFile="$(ProgramFiles)\winamp\plugins\gen_deviceprovider.dll"
LinkIncremental="1"
IgnoreDefaultLibraryNames="msvcprt.lib"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(OutDir)\$(TargetName).pdb"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
SupportUnloadOfDelayLoadedDLL="true"
ImportLibrary="$(OutDir)\$(TargetName).lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
OutputDocumentFile="$(OutDir)\$(TargetName).xml"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="nu"
>
<File
RelativePath="..\..\nu\PtrList.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\nu\PtrList.h"
>
</File>
<File
RelativePath="..\..\nu\trace.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\nu\trace.h"
>
</File>
</Filter>
<File
RelativePath=".\common.h"
>
</File>
<File
RelativePath=".\device.cpp"
>
</File>
<File
RelativePath=".\device.h"
>
</File>
<File
RelativePath=".\deviceActivity.cpp"
>
</File>
<File
RelativePath=".\deviceActivity.h"
>
</File>
<File
RelativePath=".\deviceCommandNodeParser.cpp"
>
</File>
<File
RelativePath=".\deviceCommandNodeParser.h"
>
</File>
<File
RelativePath=".\deviceCommandParser.cpp"
>
</File>
<File
RelativePath=".\deviceCommandParser.h"
>
</File>
<File
RelativePath=".\deviceConnectionNodeParser.cpp"
>
</File>
<File
RelativePath=".\deviceConnectionNodeParser.h"
>
</File>
<File
RelativePath=".\deviceConnectionParser.cpp"
>
</File>
<File
RelativePath=".\deviceConnectionParser.h"
>
</File>
<File
RelativePath=".\deviceIconEditor.cpp"
>
</File>
<File
RelativePath=".\deviceIconEditor.h"
>
</File>
<File
RelativePath=".\deviceNodeParser.cpp"
>
</File>
<File
RelativePath=".\deviceNodeParser.h"
>
</File>
<File
RelativePath=".\deviceParser.cpp"
>
</File>
<File
RelativePath=".\deviceParser.h"
>
</File>
<File
RelativePath=".\deviceTypeNodeParser.cpp"
>
</File>
<File
RelativePath=".\deviceTypeNodeParser.h"
>
</File>
<File
RelativePath=".\deviceTypeParser.cpp"
>
</File>
<File
RelativePath=".\deviceTypeParser.h"
>
</File>
<File
RelativePath=".\deviceView.cpp"
>
</File>
<File
RelativePath=".\deviceView.h"
>
</File>
<File
RelativePath=".\iconStore.cpp"
>
</File>
<File
RelativePath=".\iconStore.h"
>
</File>
<File
RelativePath=".\main.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\main.h"
>
</File>
<File
RelativePath=".\plugin.cpp"
>
</File>
<File
RelativePath=".\plugin.h"
>
</File>
<File
RelativePath=".\provider.cpp"
>
</File>
<File
RelativePath=".\provider.h"
>
</File>
<File
RelativePath=".\resource.h"
>
</File>
<File
RelativePath=".\resources.rc"
>
</File>
<File
RelativePath=".\stringBuilder.cpp"
>
</File>
<File
RelativePath=".\stringBuilder.h"
>
</File>
<File
RelativePath=".\strings.cpp"
>
</File>
<File
RelativePath=".\strings.h"
>
</File>
<File
RelativePath=".\testSuite.cpp"
>
</File>
<File
RelativePath=".\testSuite.h"
>
</File>
<File
RelativePath=".\testSuiteLoader.cpp"
>
</File>
<File
RelativePath=".\testSuiteLoader.h"
>
</File>
<File
RelativePath=".\wasabi.cpp"
>
</File>
<File
RelativePath=".\wasabi.h"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,335 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{A3C7D830-CD01-4C2B-9E1A-FB62B5236BA9}</ProjectGuid>
<RootNamespace>gen_deviceprovider</RootNamespace>
<WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(PlatformShortName)_$(Configuration)\</OutDir>
<IntDir>$(PlatformShortName)_$(Configuration)\</IntDir>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(PlatformShortName)_$(Configuration)\</OutDir>
<IntDir>$(PlatformShortName)_$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(PlatformShortName)_$(Configuration)\</OutDir>
<IntDir>$(PlatformShortName)_$(Configuration)\</IntDir>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
<EmbedManifest>true</EmbedManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(PlatformShortName)_$(Configuration)\</OutDir>
<IntDir>$(PlatformShortName)_$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Label="Vcpkg">
<VcpkgEnableManifest>false</VcpkgEnableManifest>
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<VcpkgInstalledDir>
</VcpkgInstalledDir>
<VcpkgUseStatic>false</VcpkgUseStatic>
<VcpkgConfiguration>Debug</VcpkgConfiguration>
<VcpkgTriplet>x86-windows-static-md</VcpkgTriplet>
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<VcpkgInstalledDir>
</VcpkgInstalledDir>
<VcpkgUseStatic>false</VcpkgUseStatic>
<VcpkgTriplet>x86-windows-static-md</VcpkgTriplet>
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<VcpkgInstalledDir>
</VcpkgInstalledDir>
<VcpkgUseStatic>false</VcpkgUseStatic>
<VcpkgTriplet>x86-windows-static-md</VcpkgTriplet>
<VcpkgConfiguration>Debug</VcpkgConfiguration>
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<VcpkgInstalledDir>
</VcpkgInstalledDir>
<VcpkgUseStatic>false</VcpkgUseStatic>
<VcpkgTriplet>x86-windows-static-md</VcpkgTriplet>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>../..;..\..\..\;..\..\..\..\wasabi;..\..\..\..\agave;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WIN32_WINNT=0x0601;WINVER=0x0601;WIN32;_DEBUG;_WINDOWS;_USRDLL;GEN_DEVICEPROVIDER_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<EnablePREfast>false</EnablePREfast>
<BufferSecurityCheck>true</BufferSecurityCheck>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<FunctionLevelLinking>true</FunctionLevelLinking>
</ClCompile>
<Link>
<AdditionalDependencies>comctl32.lib;shlwapi.lib;windowscodecs.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>$(IntDir)$(TargetName).pdb</ProgramDatabaseFile>
<SubSystem>Windows</SubSystem>
<ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
<TargetMachine>MachineX86</TargetMachine>
<Profile>false</Profile>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
<Xdcmake>
<OutputFile>$(IntDir)$(TargetName).xml</OutputFile>
</Xdcmake>
<PostBuildEvent>
<Command>xcopy /Y /D $(OutDir)$(TargetName)$(TargetExt) ..\..\..\..\..\Build\Winamp_$(PlatformShortName)_$(Configuration)\Plugins\
xcopy /Y /D $(IntDir)$(TargetName).pdb ..\..\..\..\..\Build\Winamp_$(PlatformShortName)_$(Configuration)\Plugins\ </Command>
<Message>Post build event: 'xcopy /Y /D $(OutDir)$(TargetName)$(TargetExt) ..\..\..\..\..\Build\Winamp_$(PlatformShortName)_$(Configuration)\Plugins\'</Message>
</PostBuildEvent>
<ResourceCompile>
<PreprocessorDefinitions>_WIN32_WINNT=0x0601;WINVER=0x0601;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>../..;..\..\..\..\;..\..\..\..\wasabi;..\..\..\..\agave;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WIN32_WINNT=0x0601;WINVER=0x0601;WIN64;_DEBUG;_WINDOWS;_USRDLL;GEN_DEVICEPROVIDER_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<EnablePREfast>false</EnablePREfast>
<BufferSecurityCheck>true</BufferSecurityCheck>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<FunctionLevelLinking>true</FunctionLevelLinking>
</ClCompile>
<Link>
<AdditionalDependencies>comctl32.lib;shlwapi.lib;windowscodecs.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>$(IntDir)$(TargetName).pdb</ProgramDatabaseFile>
<SubSystem>Windows</SubSystem>
<ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
<Profile>false</Profile>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
<Xdcmake>
<OutputFile>$(IntDir)$(TargetName).xml</OutputFile>
</Xdcmake>
<PostBuildEvent>
<Command>xcopy /Y /D $(OutDir)$(TargetName)$(TargetExt) ..\..\..\..\..\Build\Winamp_$(PlatformShortName)_$(Configuration)\Plugins\
xcopy /Y /D $(IntDir)$(TargetName).pdb ..\..\..\..\..\Build\Winamp_$(PlatformShortName)_$(Configuration)\Plugins\ </Command>
<Message>Post build event: 'xcopy /Y /D $(OutDir)$(TargetName)$(TargetExt) ..\..\..\..\..\Build\Winamp_$(PlatformShortName)_$(Configuration)\Plugins\'</Message>
</PostBuildEvent>
<ResourceCompile>
<PreprocessorDefinitions>_WIN32_WINNT=0x0601;WINVER=0x0601;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>../..;..\..\..\..\;..\..\..\..\wasabi;..\..\..\..\agave;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WIN32_WINNT=0x0601;WINVER=0x0601;WIN32;NDEBUG;_WINDOWS;_USRDLL;GEN_DEVICEPROVIDER_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>None</DebugInformationFormat>
<StringPooling>true</StringPooling>
<BufferSecurityCheck>true</BufferSecurityCheck>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
</ClCompile>
<Link>
<AdditionalDependencies>comctl32.lib;shlwapi.lib;windowscodecs.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<GenerateDebugInformation>false</GenerateDebugInformation>
<ProgramDatabaseFile>$(IntDir)$(TargetName).pdb</ProgramDatabaseFile>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
<TargetMachine>MachineX86</TargetMachine>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
<Xdcmake>
<OutputFile>$(IntDir)$(TargetName).xml</OutputFile>
</Xdcmake>
<PostBuildEvent>
<Command>xcopy /Y /D $(OutDir)$(TargetName)$(TargetExt) ..\..\..\..\..\Build\Winamp_$(PlatformShortName)_$(Configuration)\Plugins\ </Command>
<Message>Post build event: 'xcopy /Y /D $(OutDir)$(TargetName)$(TargetExt) ..\..\..\..\..\Build\Winamp_$(PlatformShortName)_$(Configuration)\Plugins\'</Message>
</PostBuildEvent>
<ResourceCompile>
<PreprocessorDefinitions>_WIN32_WINNT=0x0601;WINVER=0x0601;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>../..;..\..\..\..\;..\..\..\..\wasabi;..\..\..\..\agave;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WIN32_WINNT=0x0601;WINVER=0x0601;WIN64;NDEBUG;_WINDOWS;_USRDLL;GEN_DEVICEPROVIDER_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>None</DebugInformationFormat>
<StringPooling>true</StringPooling>
<BufferSecurityCheck>true</BufferSecurityCheck>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
</ClCompile>
<Link>
<AdditionalDependencies>comctl32.lib;shlwapi.lib;windowscodecs.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<GenerateDebugInformation>false</GenerateDebugInformation>
<ProgramDatabaseFile>$(IntDir)$(TargetName).pdb</ProgramDatabaseFile>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
<Xdcmake>
<OutputFile>$(IntDir)$(TargetName).xml</OutputFile>
</Xdcmake>
<PostBuildEvent>
<Command>xcopy /Y /D $(OutDir)$(TargetName)$(TargetExt) ..\..\..\..\..\Build\Winamp_$(PlatformShortName)_$(Configuration)\Plugins\ </Command>
<Message>Post build event: 'xcopy /Y /D $(OutDir)$(TargetName)$(TargetExt) ..\..\..\..\..\Build\Winamp_$(PlatformShortName)_$(Configuration)\Plugins\'</Message>
</PostBuildEvent>
<ResourceCompile>
<PreprocessorDefinitions>_WIN32_WINNT=0x0601;WINVER=0x0601;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\nu\PtrList.cpp" />
<ClCompile Include="..\..\..\..\nu\trace.cpp" />
<ClCompile Include="device.cpp" />
<ClCompile Include="deviceActivity.cpp" />
<ClCompile Include="deviceCommandNodeParser.cpp" />
<ClCompile Include="deviceCommandParser.cpp" />
<ClCompile Include="deviceConnectionNodeParser.cpp" />
<ClCompile Include="deviceConnectionParser.cpp" />
<ClCompile Include="deviceIconEditor.cpp" />
<ClCompile Include="deviceNodeParser.cpp" />
<ClCompile Include="deviceParser.cpp" />
<ClCompile Include="deviceTypeNodeParser.cpp" />
<ClCompile Include="deviceTypeParser.cpp" />
<ClCompile Include="deviceView.cpp" />
<ClCompile Include="iconStore.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="plugin.cpp" />
<ClCompile Include="provider.cpp" />
<ClCompile Include="stringBuilder.cpp" />
<ClCompile Include="strings.cpp" />
<ClCompile Include="testSuite.cpp" />
<ClCompile Include="testSuiteLoader.cpp" />
<ClCompile Include="wasabi.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\nu\trace.h" />
<ClInclude Include="common.h" />
<ClInclude Include="device.h" />
<ClInclude Include="deviceActivity.h" />
<ClInclude Include="deviceCommandNodeParser.h" />
<ClInclude Include="deviceCommandParser.h" />
<ClInclude Include="deviceConnectionNodeParser.h" />
<ClInclude Include="deviceConnectionParser.h" />
<ClInclude Include="deviceIconEditor.h" />
<ClInclude Include="deviceNodeParser.h" />
<ClInclude Include="deviceParser.h" />
<ClInclude Include="deviceTypeNodeParser.h" />
<ClInclude Include="deviceTypeParser.h" />
<ClInclude Include="deviceView.h" />
<ClInclude Include="iconStore.h" />
<ClInclude Include="main.h" />
<ClInclude Include="plugin.h" />
<ClInclude Include="provider.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="stringBuilder.h" />
<ClInclude Include="strings.h" />
<ClInclude Include="testSuite.h" />
<ClInclude Include="testSuiteLoader.h" />
<ClInclude Include="wasabi.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resources.rc" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Wasabi\Wasabi.vcxproj">
<Project>{3e0bfa8a-b86a-42e9-a33f-ec294f823f7f}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,164 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="device.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="deviceActivity.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="deviceCommandNodeParser.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="deviceCommandParser.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="deviceConnectionNodeParser.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="deviceConnectionParser.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="deviceIconEditor.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="deviceNodeParser.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="deviceParser.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="deviceTypeNodeParser.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="deviceTypeParser.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="deviceView.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="iconStore.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="plugin.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="provider.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="stringBuilder.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="strings.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="testSuite.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="testSuiteLoader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="wasabi.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\nu\trace.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\nu\PtrList.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="common.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="device.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="deviceActivity.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="deviceCommandNodeParser.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="deviceCommandParser.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="deviceConnectionNodeParser.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="deviceConnectionParser.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="deviceIconEditor.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="deviceNodeParser.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="deviceParser.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="deviceTypeNodeParser.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="deviceTypeParser.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="deviceView.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="iconStore.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="main.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="plugin.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="provider.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stringBuilder.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="strings.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="testSuite.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="testSuiteLoader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="wasabi.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\nu\trace.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Header Files">
<UniqueIdentifier>{e264ea99-159e-4062-a78a-a85da3815f37}</UniqueIdentifier>
</Filter>
<Filter Include="Ressource Files">
<UniqueIdentifier>{f5beaf0a-f21d-4ae9-8221-adde13e2b65d}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files">
<UniqueIdentifier>{207087f5-3450-4826-bae5-39064e9da43f}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resources.rc">
<Filter>Ressource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,289 @@
#include "main.h"
#include "./iconStore.h"
#include <vector>
typedef struct IconStoreRecord
{
unsigned int width;
unsigned int height;
wchar_t *path;
} IconStoreRecord;
typedef std::vector<IconStoreRecord> RecodList;
struct IconStore
{
RecodList list;
wchar_t *basePath;
};
IconStore *
IconStore_Create()
{
IconStore *self;
self = new IconStore();
if (NULL == self)
return NULL;
self->basePath = NULL;
return self;
}
void
IconStore_Destroy(IconStore *self)
{
size_t index;
IconStoreRecord *record;
if (NULL == self)
return;
index = self->list.size();
while(index--)
{
record = &self->list[index];
String_Free(record->path);
}
String_Free(self->basePath);
}
BOOL
IconStore_Add(IconStore *self, const wchar_t *path, unsigned int width, unsigned int height)
{
IconStoreRecord record, *prec;
size_t index;
if (NULL == self)
return FALSE;
if(width < 1)
width = 1;
if(height < 1)
height = 1;
index = self->list.size();
while(index--)
{
prec = &self->list[index];
if (width == prec->width &&
height == prec->height)
{
String_Free(prec->path);
prec->path = String_Duplicate(path);
return TRUE;
}
}
record.path = String_Duplicate(path);
record.width = width;
record.height = height;
self->list.push_back(record);
return TRUE;
}
BOOL
IconStore_RemovePath(IconStore *self, const wchar_t *path)
{
size_t index;
IconStoreRecord *record;
if (NULL == self)
return FALSE;
index = self->list.size();
while(index--)
{
record = &self->list[index];
if(CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, record->path, -1, path, -1))
{
self->list.eraseAt(index);
}
}
return TRUE;
}
BOOL
IconStore_Remove(IconStore *self, unsigned int width, unsigned int height)
{
size_t index;
IconStoreRecord *record;
if (NULL == self)
return FALSE;
index = self->list.size();
while(index--)
{
record = &self->list[index];
if(record->width == width &&
record->height == height)
{
self->list.eraseAt(index);
}
}
return TRUE;
}
static BOOL
IconStore_GetFullPath(IconStore *self, const wchar_t *path, wchar_t *buffer, size_t bufferMax)
{
if (NULL == buffer)
return FALSE;
if (NULL == self)
return FALSE;
if (FALSE != IS_STRING_EMPTY(path))
{
*buffer = L'\0';
return TRUE;
}
if (FALSE == PathIsRelative(path) ||
IS_STRING_EMPTY(self->basePath))
{
if (0 == String_CopyTo(buffer, path, bufferMax) &&
FALSE == IS_STRING_EMPTY(path))
return FALSE;
else
return TRUE;
}
if (NULL == PathCombine(buffer, self->basePath, path))
return FALSE;
return TRUE;
}
BOOL
IconStore_Get(IconStore *self, wchar_t *buffer, size_t bufferMax, unsigned int width, unsigned int height)
{
const wchar_t *icon;
IconStoreRecord *record;
size_t index;
double widthDbl, heightDbl;
double scaleMin, scaleHorz, scaleVert;
if (NULL == self)
return FALSE;
if (NULL == buffer)
return FALSE;
icon = NULL;
widthDbl = width;
heightDbl = height;
index = self->list.size();
if (index > 0)
{
record = &self->list[--index];
scaleHorz = widthDbl/record->width;
scaleVert = heightDbl/record->height;
scaleMin = (scaleHorz < scaleVert) ? scaleHorz : scaleVert;
icon = record->path;
if (1.0 != scaleMin)
{
scaleMin = fabs(1.0 - scaleMin);
while(index--)
{
record = &self->list[index];
scaleHorz = widthDbl/record->width;
scaleVert = heightDbl/record->height;
if (scaleHorz > scaleVert)
scaleHorz = scaleVert;
if (1.0 == scaleHorz)
{
icon = record->path;
break;
}
scaleHorz = fabs(1.0 - scaleHorz);
if (scaleHorz < scaleMin)
{
scaleMin = scaleHorz;
icon = record->path;
}
}
}
}
return IconStore_GetFullPath(self, icon, buffer, bufferMax);
}
BOOL
IconStore_SetBasePath(IconStore *self, const wchar_t *path)
{
if (NULL == self)
return FALSE;
String_Free(self->basePath);
self->basePath = String_Duplicate(path);
return TRUE;
}
IconStore *
IconStore_Clone(IconStore *self)
{
size_t index;
IconStore *clone;
IconStoreRecord targetRec;
const IconStoreRecord *sourceRec;
if (NULL == self)
return NULL;
clone = IconStore_Create();
if (NULL == clone)
return NULL;
clone->basePath = String_Duplicate(self->basePath);
for(index = 0; index < self->list.size(); index++)
{
sourceRec = &self->list[index];
targetRec.path = String_Duplicate(sourceRec->path);
targetRec.width = sourceRec->width;
targetRec.height = sourceRec->height;
clone->list.push_back(targetRec);
}
return clone;
}
BOOL
IconStore_Enumerate(IconStore *self, IconEnumerator callback, void *user)
{
size_t index;
wchar_t buffer[MAX_PATH*2];
IconStoreRecord *record;
if (NULL == self || NULL == callback)
return FALSE;
index = self->list.size();
while(index--)
{
record = &self->list[index];
if (FALSE != IconStore_GetFullPath(self, record->path, buffer, ARRAYSIZE(buffer)))
{
if (FALSE == callback(buffer, record->width, record->height, user))
return TRUE;
}
}
return TRUE;
}

View File

@ -0,0 +1,53 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_ICON_STORE_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_ICON_STORE_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <wtypes.h>
typedef struct IconStore IconStore;
typedef BOOL (*IconEnumerator)(const wchar_t *path, unsigned int width, unsigned int height, void *user);
IconStore *
IconStore_Create();
void
IconStore_Destroy(IconStore *self);
BOOL
IconStore_Add(IconStore *self,
const wchar_t *path,
unsigned int width,
unsigned int height);
BOOL
IconStore_RemovePath(IconStore *self,
const wchar_t *path);
BOOL
IconStore_Remove(IconStore *self,
unsigned int width,
unsigned int height);
BOOL
IconStore_Get(IconStore *self,
wchar_t *buffer,
size_t bufferMax,
unsigned int width,
unsigned int height);
BOOL
IconStore_SetBasePath(IconStore *self,
const wchar_t *path);
IconStore *
IconStore_Clone(IconStore *self);
BOOL
IconStore_Enumerate(IconStore *self,
IconEnumerator callback,
void *user);
#endif //_NULLSOFT_WINAMP_GEN_DEVICE_ICON_STORE_HEADER

View File

@ -0,0 +1,2 @@
#include <initguid.h>
#include "main.h"

View File

@ -0,0 +1,31 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_MAIN_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_MAIN_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <wtypes.h>
#include "./common.h"
#include "./plugin.h"
#include "./strings.h"
#include "./stringBuilder.h"
#include "./wasabi.h"
#include "./provider.h"
#include "./resource.h"
#include "./device.h"
#include "./deviceActivity.h"
#include "./deviceView.h"
#include "./deviceIconEditor.h"
#include "./testSuite.h"
#include "./testSuiteLoader.h"
#include "./iconStore.h"
#include "../../winamp/wa_ipc.h"
#include "../../nu/trace.h"
#include <math.h>
#include <shlwapi.h>
#endif //_NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_MAIN_HEADER

View File

@ -0,0 +1,114 @@
#include "main.h"
#include "../../winamp/gen.h"
#include <strsafe.h>
static INT
Plugin_Init(void);
static void
Plugin_Quit(void);
static void
Plugin_Config(void);
extern "C" winampGeneralPurposePlugin plugin =
{
GPPHDR_VER,
0,
Plugin_Init,
Plugin_Config,
Plugin_Quit,
};
static DeviceProvider *deviceProvider = NULL;
HINSTANCE
Plugin_GetInstance(void)
{
return plugin.hDllInstance;
}
HWND
Plugin_GetWinampWindow(void)
{
return plugin.hwndParent;
}
static void
Plugin_SetDescription()
{
WCHAR szBuffer[256], szTemplate[256];
if (0 != plugin.description)
AnsiString_Free(plugin.description);
if (NULL != WASABI_API_LNG)
WASABI_API_LNGSTRINGW_BUF(IDS_PLUGIN_NAME, szTemplate, ARRAYSIZE(szTemplate));
else
szTemplate[0] = L'\0';
StringCchPrintf(szBuffer, ARRAYSIZE(szBuffer),
((L'\0' != szTemplate[0]) ? szTemplate : L"Nullsoft Test Device Provider v%d.%d"),
PLUGIN_VERSION_MAJOR, PLUGIN_VERSION_MINOR);
plugin.description = String_ToAnsi(CP_ACP, 0, szBuffer, -1, NULL, NULL);
}
static INT
Plugin_Init(void)
{
if (FALSE == Wasabi_InitializeFromWinamp(plugin.hDllInstance, plugin.hwndParent))
return 1;
Wasabi_LoadDefaultServices();
Plugin_SetDescription();
if (NULL == deviceProvider)
{
if (FAILED(DeviceProvider::CreateInstance(&deviceProvider)))
{
Wasabi_Release();
return 2;
}
deviceProvider->Register(WASABI_API_DEVICES);
}
return 0;
}
static void
Plugin_Quit(void)
{
if (0 != plugin.description)
{
AnsiString_Free(plugin.description);
plugin.description = 0;
}
if (NULL != deviceProvider)
{
deviceProvider->Unregister(WASABI_API_DEVICES);
deviceProvider->Release();
}
Wasabi_Release();
}
static void
Plugin_Config(void)
{
}
EXTERN_C __declspec(dllexport) winampGeneralPurposePlugin *
winampGetGeneralPurposePlugin()
{
if (0 == plugin.description)
{
Plugin_SetDescription();
}
return &plugin;
}

View File

@ -0,0 +1,21 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_PLUGIN_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_PLUGIN_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <wtypes.h>
#define PLUGIN_VERSION_MAJOR 1
#define PLUGIN_VERSION_MINOR 1
// {51B54A05-B711-4509-80AE-5A0AAA502FA5}
DEFINE_GUID(PLUGIN_LANGUAGE_ID,
0x51b54a05, 0xb711, 0x4509, 0x80, 0xae, 0x5a, 0xa, 0xaa, 0x50, 0x2f, 0xa5);
HINSTANCE Plugin_GetInstance(void);
HWND Plugin_GetWinampWindow(void);
#endif //_NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_PLUGIN_HEADER

View File

@ -0,0 +1,336 @@
#include "main.h"
#include "./provider.h"
typedef struct DeviceProviderThreadParam
{
api_devicemanager *manager;
DeviceProvider *provider;
HANDLE readyEvent;
}DeviceProviderThreadParam;
DeviceProvider::DeviceProvider()
: ref(1), discoveryThread(NULL), cancelEvent(NULL)
{
wchar_t buffer[MAX_PATH * 2];
HINSTANCE module;
TestSuiteLoader loader;
InitializeCriticalSection(&lock);
module = Plugin_GetInstance();
if (0 == GetModuleFileName(module, buffer, ARRAYSIZE(buffer)) ||
FALSE == PathRemoveFileSpec(buffer))
{
buffer[0] = L'\0';
}
PathAppend(buffer, L"testprovider.xml");
loader.Load(buffer, &testSuite);
}
DeviceProvider::~DeviceProvider()
{
CancelDiscovery();
DeleteCriticalSection(&lock);
}
HRESULT DeviceProvider::CreateInstance(DeviceProvider **instance)
{
if (NULL == instance)
return E_POINTER;
*instance = new DeviceProvider();
if (NULL == *instance)
return E_OUTOFMEMORY;
return S_OK;
}
size_t DeviceProvider::AddRef()
{
return InterlockedIncrement((LONG*)&ref);
}
size_t DeviceProvider::Release()
{
if (0 == ref)
return ref;
LONG r = InterlockedDecrement((LONG*)&ref);
if (0 == r)
delete(this);
return r;
}
int DeviceProvider::QueryInterface(GUID interface_guid, void **object)
{
if (NULL == object)
return E_POINTER;
if (IsEqualIID(interface_guid, IFC_DeviceProvider))
*object = static_cast<ifc_deviceprovider*>(this);
else
{
*object = NULL;
return E_NOINTERFACE;
}
if (NULL == *object)
return E_UNEXPECTED;
AddRef();
return S_OK;
}
DWORD DeviceProvider::DiscoveryThread(api_devicemanager *manager)
{
DWORD waitResult;
DWORD deviceCount;
DWORD threadId;
DWORD sleepTime;
LARGE_INTEGER perfCounter;
deviceCount = 0;
threadId = GetCurrentThreadId();
// aTRACE_FMT("[test provider] device discovery started (0x%X).\r\n", threadId);
manager->SetProviderActive(this, TRUE);
for(;;)
{
if (FALSE != QueryPerformanceCounter(&perfCounter))
srand(perfCounter.LowPart);
else
srand(GetTickCount());
sleepTime = (DWORD)((double)rand()/(RAND_MAX) * 0);
waitResult = WaitForSingleObject(cancelEvent, sleepTime);
if (WAIT_OBJECT_0 == waitResult)
break;
else if (WAIT_TIMEOUT == waitResult)
{
Device *device;
deviceCount++;
// aTRACE_FMT("[test provider] creating new device[%d] (0x%X).\r\n", deviceCount, threadId);
device = testSuite.GetRandomDevice();
if (NULL != device)
{
device->Connect();
if (0 == manager->DeviceRegister((ifc_device**)&device, 1))
device->Disconnect();
}
if (4 == deviceCount)
break;
}
else
{
// aTRACE_FMT("[test provider] error (0x%X).\r\n", threadId);
break;
}
}
EnterCriticalSection(&lock);
if (NULL != discoveryThread)
{
CloseHandle(discoveryThread);
discoveryThread = NULL;
}
if (NULL != cancelEvent)
{
CloseHandle(cancelEvent);
cancelEvent = NULL;
}
// aTRACE_FMT("[test provider] device discovery finished (0x%X).\r\n", threadId);
LeaveCriticalSection(&lock);
manager->SetProviderActive(this, FALSE);
return 0;
}
static DWORD CALLBACK DeviceProvider_DiscoveryThreadStarter(void *user)
{
DeviceProviderThreadParam *param;
DeviceProvider *provider;
api_devicemanager *manager;
DWORD result;
param = (DeviceProviderThreadParam*)user;
manager = param->manager;
provider = param->provider;
if (NULL != manager)
manager->AddRef();
if (NULL != param->readyEvent)
SetEvent(param->readyEvent);
if (NULL == manager)
return -1;
if (NULL != provider)
result = provider->DiscoveryThread(manager);
else
result = -2;
manager->Release();
return result;
}
HRESULT DeviceProvider::BeginDiscovery(api_devicemanager *manager)
{
HRESULT hr;
if (NULL == manager)
return E_INVALIDARG;
EnterCriticalSection(&lock);
if (NULL != discoveryThread)
hr = E_PENDING;
else
{
hr = S_OK;
if (NULL == cancelEvent)
{
cancelEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (NULL == cancelEvent)
hr = E_FAIL;
}
if (SUCCEEDED(hr))
{
DeviceProviderThreadParam param;
param.provider = this;
param.manager = manager;
param.readyEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (NULL == param.readyEvent)
hr = E_FAIL;
else
{
DWORD threadId;
discoveryThread = CreateThread(NULL, 0, DeviceProvider_DiscoveryThreadStarter, &param, 0, &threadId);
if (NULL == discoveryThread)
hr = E_FAIL;
else
WaitForSingleObject(param.readyEvent, INFINITE);
CloseHandle(param.readyEvent);
}
}
if (FAILED(hr))
CancelDiscovery();
}
LeaveCriticalSection(&lock);
return hr;
}
HRESULT DeviceProvider::CancelDiscovery()
{
HRESULT hr;
HANDLE threadHandle, eventHandle;
EnterCriticalSection(&lock);
threadHandle = discoveryThread;
eventHandle = cancelEvent;
discoveryThread = NULL;
cancelEvent = NULL;
LeaveCriticalSection(&lock);
if (NULL != threadHandle)
{
if (NULL != eventHandle)
SetEvent(eventHandle);
WaitForSingleObject(threadHandle, INFINITE);
CloseHandle(threadHandle);
hr = S_OK;
}
else
hr = S_FALSE;
if (NULL != eventHandle)
CloseHandle(eventHandle);
return hr;
}
HRESULT DeviceProvider::GetActive()
{
HRESULT hr;
EnterCriticalSection(&lock);
hr = (NULL != discoveryThread) ? S_OK : S_FALSE;
LeaveCriticalSection(&lock);
return hr;
}
HRESULT DeviceProvider::Register(api_devicemanager *manager)
{
HRESULT hr;
if (NULL == manager)
return E_POINTER;
hr = manager->RegisterProvider(this);
if (SUCCEEDED(hr))
{
testSuite.RegisterCommands(manager);
testSuite.RegisterTypes(manager);
testSuite.RegisterConnections(manager);
testSuite.RegisterDevices(manager);
}
return hr;
}
HRESULT DeviceProvider::Unregister(api_devicemanager *manager)
{
HRESULT hr;
if (NULL == manager)
return E_POINTER;
hr = manager->UnregisterProvider(this);
testSuite.UnregisterTypes(manager);
testSuite.UnregisterConnections(manager);
testSuite.UnregisterCommands(manager);
testSuite.UnregisterDevices(manager);
return hr;
}
#define CBCLASS DeviceProvider
START_DISPATCH;
CB(ADDREF, AddRef)
CB(RELEASE, Release)
CB(QUERYINTERFACE, QueryInterface)
CB(API_BEGINDISCOVERY, BeginDiscovery)
CB(API_CANCELDISCOVERY, CancelDiscovery)
CB(API_GETACTIVE, GetActive)
END_DISPATCH;
#undef CBCLASS

View File

@ -0,0 +1,50 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_IMPLEMENTATION_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_IMPLEMENTATION_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <wtypes.h>
#include "../../devices/ifc_deviceprovider.h"
#include "./testSuite.h"
class DeviceProvider : public ifc_deviceprovider
{
protected:
DeviceProvider();
~DeviceProvider();
public:
static HRESULT CreateInstance(DeviceProvider **instance);
public:
/* Dispatchable */
size_t AddRef();
size_t Release();
int QueryInterface(GUID interface_guid, void **object);
/* ifc_deviceprovider */
HRESULT BeginDiscovery(api_devicemanager *manager);
HRESULT CancelDiscovery();
HRESULT GetActive();
public:
HRESULT Register(api_devicemanager *manager);
HRESULT Unregister(api_devicemanager *manager);
private:
DWORD DiscoveryThread(api_devicemanager *manager);
friend static DWORD CALLBACK DeviceProvider_DiscoveryThreadStarter(void *param);
protected:
size_t ref;
HANDLE discoveryThread;
HANDLE cancelEvent;
TestSuite testSuite;
CRITICAL_SECTION lock;
protected:
RECVS_DISPATCH;
};
#endif //_NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_IMPLEMENTATION_HEADER

View File

@ -0,0 +1,39 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by resources.rc
//
#define IDS_PLUGIN_NAME 101
#define IDD_DEVICE_VIEW 102
#define IDD_ICON_EDITOR 104
#define IDC_EDIT_NAME 1001
#define IDC_EDIT_TITLE 1002
#define IDC_EDIT_TYPE 1003
#define IDC_EDIT_CONNECTION 1004
#define IDC_COMBO_ATTACHED 1005
#define IDC_COMBO_VISIBLE 1006
#define IDC_EDIT_TOTALSPACE 1007
#define IDC_SPIN_TOTALSPACE 1008
#define IDC_EDIT_USEDSPACE 1009
#define IDC_SPIN_USEDSPACE 1010
#define IDC_COMBO_ICONS 1011
#define IDC_BUTTON_NEWICON 1012
#define IDC_BUTTON_REMOVEICON 1013
#define IDC_STATIC_PREVIEWICON 1014
#define IDC_EDIT_WIDTH 1015
#define IDC_EDIT_HEIGHT 1016
#define IDC_EDIT_PATH 1017
#define IDC_BUTTON_BROWSE 1018
#define IDC_BUTTON1 1019
#define IDC_BUTTON_EDITICON 1019
#define IDS_STRING102 65535
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 105
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1020
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@ -0,0 +1,186 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DEVICE_VIEW DIALOGEX 0, 0, 397, 282
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN
EXSTYLE WS_EX_NOPARENTNOTIFY | WS_EX_CONTROLPARENT
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
EDITTEXT IDC_EDIT_NAME,57,23,101,12,ES_AUTOHSCROLL | ES_READONLY
EDITTEXT IDC_EDIT_TYPE,57,36,101,12,ES_AUTOHSCROLL | ES_READONLY
EDITTEXT IDC_EDIT_CONNECTION,57,50,101,12,ES_AUTOHSCROLL | ES_READONLY
EDITTEXT IDC_EDIT_TITLE,57,70,101,12,ES_AUTOHSCROLL
COMBOBOX IDC_COMBO_ATTACHED,57,85,101,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
COMBOBOX IDC_COMBO_VISIBLE,57,101,101,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
EDITTEXT IDC_EDIT_TOTALSPACE,57,117,101,16,ES_AUTOHSCROLL | ES_NUMBER
CONTROL "",IDC_SPIN_TOTALSPACE,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS,149,118,9,12,WS_EX_TRANSPARENT
EDITTEXT IDC_EDIT_USEDSPACE,57,134,101,16,ES_AUTOHSCROLL | ES_NUMBER
CONTROL "",IDC_SPIN_USEDSPACE,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS,149,136,9,12,WS_EX_TRANSPARENT
COMBOBOX IDC_COMBO_ICONS,169,34,221,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "New",IDC_BUTTON_NEWICON,264,49,40,14
PUSHBUTTON "Edit",IDC_BUTTON_EDITICON,307,49,40,14
PUSHBUTTON "Remove",IDC_BUTTON_REMOVEICON,350,49,40,14
CONTROL "",IDC_STATIC_PREVIEWICON,"Static",SS_BITMAP | SS_CENTERIMAGE,169,70,221,170,WS_EX_STATICEDGE
LTEXT "Device View",IDC_STATIC,7,7,39,8
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,7,16,383,1
LTEXT "Name:",IDC_STATIC,15,24,22,8
LTEXT "Title:",IDC_STATIC,15,71,17,8
LTEXT "Type:",IDC_STATIC,15,37,20,8
LTEXT "Connection:",IDC_STATIC,15,51,40,8
LTEXT "Attached:",IDC_STATIC,15,87,33,8
LTEXT "Visible:",IDC_STATIC,15,103,23,8
LTEXT "Capacity:",IDC_STATIC,15,119,32,8
LTEXT "Used Space:",IDC_STATIC,15,136,41,8
LTEXT "Icons:",IDC_STATIC,169,22,21,8
END
IDD_ICON_EDITOR DIALOGEX 0, 0, 290, 79
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Device Icon"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "OK",IDOK,180,58,50,14
PUSHBUTTON "Cancel",IDCANCEL,233,58,50,14
LTEXT "Width:",IDC_STATIC,8,34,35,8
LTEXT "Height:",IDC_STATIC,47,33,29,8
EDITTEXT IDC_EDIT_WIDTH,7,44,35,14,ES_AUTOHSCROLL | ES_NUMBER
EDITTEXT IDC_EDIT_HEIGHT,46,44,35,14,ES_AUTOHSCROLL | ES_NUMBER
EDITTEXT IDC_EDIT_PATH,7,18,250,14,ES_AUTOHSCROLL
LTEXT "Path:",IDC_STATIC,7,7,18,8
PUSHBUTTON "...",IDC_BUTTON_BROWSE,261,18,22,14
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_DEVICE_VIEW, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 390
VERTGUIDE, 15
VERTGUIDE, 57
VERTGUIDE, 158
VERTGUIDE, 169
TOPMARGIN, 7
BOTTOMMARGIN, 275
END
IDD_ICON_EDITOR, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 283
VERTGUIDE, 42
VERTGUIDE, 46
TOPMARGIN, 7
BOTTOMMARGIN, 72
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog Info
//
IDD_DEVICE_VIEW DLGINIT
BEGIN
IDC_COMBO_ATTACHED, 0x403, 4, 0
0x6559, 0x0073,
IDC_COMBO_ATTACHED, 0x403, 3, 0
0x6f4e, "\000"
IDC_COMBO_VISIBLE, 0x403, 4, 0
0x6559, 0x0073,
IDC_COMBO_VISIBLE, 0x403, 3, 0
0x6f4e, "\000"
0
END
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE
BEGIN
IDS_PLUGIN_NAME "Nullsoft Test Device Provider v%d.%d"
END
STRINGTABLE
BEGIN
65535 "{51B54A05-B711-4509-80AE-5A0AAA502FA5}"
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@ -0,0 +1,85 @@
#include "main.h"
#include "./stringBuilder.h"
#include <strsafe.h>
StringBuilder::StringBuilder()
: buffer(NULL), cursor(NULL), allocated(0), remaining(0)
{
}
StringBuilder::~StringBuilder()
{
String_Free(buffer);
}
HRESULT StringBuilder::Allocate(size_t newSize)
{
if (newSize <= allocated)
return S_FALSE;
LPWSTR t = String_ReAlloc(buffer, newSize);
if (NULL == t) return E_OUTOFMEMORY;
cursor = t + (cursor - buffer);
buffer = t;
remaining += newSize - allocated;
allocated = newSize;
return S_OK;
}
void StringBuilder::Clear(void)
{
if (NULL != buffer)
{
buffer[0] = L'\0';
}
cursor = buffer;
remaining = allocated;
}
LPCWSTR StringBuilder::Get(void)
{
return buffer;
}
HRESULT StringBuilder::Set(size_t index, WCHAR value)
{
if (NULL == buffer)
return E_POINTER;
if (index >= allocated)
return E_INVALIDARG;
buffer[index] = value;
return S_OK;
}
HRESULT StringBuilder::Append(LPCWSTR pszString)
{
HRESULT hr;
if (NULL == buffer)
{
hr = Allocate(1024);
if (FAILED(hr)) return hr;
}
size_t cchCursor = remaining;
hr = StringCchCopyEx(cursor, cchCursor, pszString, &cursor, &remaining, STRSAFE_IGNORE_NULLS);
if (STRSAFE_E_INSUFFICIENT_BUFFER == hr)
{
size_t offset = cchCursor - remaining;
size_t requested = lstrlen(pszString) + (allocated - remaining) + 1;
size_t newsize = allocated * 2;
while (newsize < requested) newsize = newsize * 2;
hr = Allocate(newsize);
if (FAILED(hr)) return hr;
hr = StringCchCopyEx(cursor, remaining, pszString + offset, &cursor, &remaining, STRSAFE_IGNORE_NULLS);
}
return hr;
}

View File

@ -0,0 +1,31 @@
#ifndef NULLSOFT_WINAMP_STRING_BUILDER_HEADER
#define NULLSOFT_WINAMP_STRING_BUILDER_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <wtypes.h>
class StringBuilder
{
public:
StringBuilder();
~StringBuilder();
public:
HRESULT Allocate(size_t newSize);
void Clear(void);
LPCWSTR Get(void);
HRESULT Set(size_t index, WCHAR value);
HRESULT Append(LPCWSTR pszString);
protected:
LPWSTR buffer;
LPWSTR cursor;
size_t allocated;
size_t remaining;
};
#endif //NULLSOFT_WINAMP_STRING_BUILDER_HEADER

View File

@ -0,0 +1,243 @@
#include "main.h"
#include "./strings.h"
#include <strsafe.h>
wchar_t *
String_Malloc(size_t size)
{
return (wchar_t *)malloc(sizeof(wchar_t) * size);
}
wchar_t *
String_ReAlloc(wchar_t *string, size_t size)
{
return (wchar_t *)realloc(string, sizeof(wchar_t) * size);
}
void
String_Free(wchar_t *string)
{
if (NULL != string)
free(string);
}
wchar_t *
String_Duplicate(const wchar_t *string)
{
int length;
wchar_t *copy;
if (NULL == string)
return NULL;
length = lstrlenW(string) + 1;
copy = String_Malloc(length);
if (NULL != copy)
CopyMemory(copy, string, sizeof(wchar_t) * length);
return copy;
}
char *
String_ToAnsi(unsigned int codePage, unsigned long flags, const wchar_t *string,
int stringLength, const char *defaultChar, BOOL *usedDefaultChar)
{
char *buffer;
int bufferSize;
if (stringLength < 0)
stringLength = lstrlen(string);
bufferSize = WideCharToMultiByte(codePage, flags, string, stringLength,
NULL, 0, defaultChar, usedDefaultChar);
if (0 == bufferSize)
return NULL;
buffer = AnsiString_Malloc(bufferSize + 1);
if (NULL == buffer)
return NULL;
bufferSize = WideCharToMultiByte(codePage, flags, string, stringLength,
buffer, bufferSize, defaultChar, usedDefaultChar);
if (0 == bufferSize)
{
AnsiString_Free(buffer);
return NULL;
}
buffer[bufferSize] = '\0';
return buffer;
}
size_t
String_CopyTo(wchar_t *destination, const wchar_t *source, size_t size)
{
size_t remaining;
if (FAILED(StringCchCopyExW(destination, size, source, NULL, &remaining, STRSAFE_IGNORE_NULLS)))
return 0;
return (size - remaining);
}
wchar_t *
String_FromWindowEx(HWND hwnd, size_t *lengthOut, BOOL *errorOut)
{
BOOL error;
size_t length;
wchar_t *string;
error = TRUE;
string = NULL;
length = 0;
if (NULL != hwnd)
{
length = GetWindowTextLength(hwnd);
if (0 != length ||
ERROR_SUCCESS == GetLastError())
{
string = String_Malloc(length + 1);
if(NULL != string)
{
if (0 == length)
{
string[0] = L'\0';
error = FALSE;
}
else
{
length = GetWindowText(hwnd, string, (int)length + 1);
if (0 == length && ERROR_SUCCESS != GetLastError())
{
String_Free(string);
string = NULL;
}
else
error = FALSE;
}
}
}
}
if (NULL != lengthOut)
*lengthOut = length;
if (NULL != errorOut)
*errorOut = error;
return string;
}
char *
AnsiString_Malloc(size_t size)
{
return (char*)malloc(sizeof(char) * size);
}
char *
AnsiString_ReAlloc(char *string, size_t size)
{
return (char*)realloc(string, sizeof(char) * size);
}
void
AnsiString_Free(char *string)
{
if (NULL != string)
free(string);
}
char *
AnsiString_Duplicate(const char *string)
{
char *copy;
INT length;
if (NULL == string)
return NULL;
length = lstrlenA(string) + 1;
copy = AnsiString_Malloc(length);
if (NULL != copy)
CopyMemory(copy, string, sizeof(char) * length);
return copy;
}
wchar_t *
AnsiString_ToUnicode(unsigned int codePage, unsigned long flags, const char* string, INT stringLength)
{
wchar_t *buffer;
int buffferSize;
if (NULL == string)
return NULL;
buffferSize = MultiByteToWideChar(codePage, flags, string, stringLength, NULL, 0);
if (0 == buffferSize)
return NULL;
if (stringLength > 0)
buffferSize++;
buffer = String_Malloc(buffferSize);
if (NULL == buffer)
return NULL;
if (0 == MultiByteToWideChar(codePage, flags, string, stringLength, buffer, buffferSize))
{
String_Free(buffer);
return NULL;
}
if (stringLength > 0)
buffer[buffferSize - 1] = L'\0';
return buffer;
}
wchar_t*
ResourceString_Duplicate(const wchar_t *source)
{
return (FALSE != IS_INTRESOURCE(source)) ?
(LPWSTR)source :
String_Duplicate(source);
}
void
ResourceString_Free(wchar_t *string)
{
if (FALSE == IS_INTRESOURCE(string))
String_Free(string);
}
size_t
ResourceString_CopyTo(wchar_t *destination, const wchar_t *source, size_t size)
{
if (NULL == destination)
return 0;
if (NULL == source)
{
destination[0] = L'\0';
return 0;
}
if (FALSE != IS_INTRESOURCE(source))
{
if (NULL == WASABI_API_LNG)
{
destination[0] = L'\0';
return 0;
}
WASABI_API_LNGSTRINGW_BUF((INT)(INT_PTR)source, destination, size);
return lstrlenW(destination);
}
return String_CopyTo(destination, source, size);
}

View File

@ -0,0 +1,82 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_STRINGS_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_STRINGS_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#define IS_STRING_EMPTY(_string) (NULL == (_string) || L'\0' == *(_string))
wchar_t *
String_Malloc(size_t size);
wchar_t *
String_ReAlloc(wchar_t *string,
size_t size);
void
String_Free(wchar_t *string);
wchar_t *
String_Duplicate(const wchar_t *string);
char *
String_ToAnsi(unsigned int codePage,
unsigned long flags,
const wchar_t *string,
int stringLength,
const char *defaultChar,
BOOL *usedDefaultChar);
size_t
String_CopyTo(wchar_t *destination,
const wchar_t *source,
size_t size);
wchar_t *
String_FromWindowEx(HWND hwnd,
size_t *lengthOut,
BOOL *errorOut);
#define String_FromWindow(/*HWND*/ _hwnd)\
String_FromWindowEx((_hwnd), NULL, NULL)
/*
Ansi String
*/
char *
AnsiString_Malloc(size_t size);
char *
AnsiString_ReAlloc(char *string,
size_t size);
void
AnsiString_Free(char *string);
char *
AnsiString_Duplicate(const char *string);
wchar_t *
AnsiString_ToUnicode(unsigned int codePage,
unsigned long flags,
const char *string,
int stringLength);
/*
Resource String
*/
wchar_t*
ResourceString_Duplicate(const wchar_t *source);
void
ResourceString_Free(wchar_t *string);
size_t
ResourceString_CopyTo(wchar_t *destination,
const wchar_t *source,
size_t size);
#endif //_NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_STRINGS_HEADER

View File

@ -0,0 +1,108 @@
#include "main.h"
#include "./supportedCommand.h"
#include <strsafe.h>
DeviceSupportedCommand::DeviceSupportedCommand()
: ref(1), name(NULL), flags(DeviceCommandFlag_None)
{
}
DeviceSupportedCommand::~DeviceSupportedCommand()
{
AnsiString_Free(name);
}
HRESULT DeviceSupportedCommand::CreateInstance(const char *name, DeviceSupportedCommand **instance)
{
DeviceSupportedCommand *self;
if (NULL == instance)
return E_POINTER;
*instance = NULL;
self = new DeviceSupportedCommand();
if (NULL == self)
return E_OUTOFMEMORY;
self->name = AnsiString_Duplicate(name);
*instance = self;
return S_OK;
}
size_t DeviceSupportedCommand::AddRef()
{
return InterlockedIncrement((LONG*)&ref);
}
size_t DeviceSupportedCommand::Release()
{
if (0 == ref)
return ref;
LONG r = InterlockedDecrement((LONG*)&ref);
if (0 == r)
delete(this);
return r;
}
int DeviceSupportedCommand::QueryInterface(GUID interface_guid, void **object)
{
if (NULL == object)
return E_POINTER;
if (IsEqualIID(interface_guid, IFC_DeviceSupportedCommand))
*object = static_cast<ifc_devicesupportedcommand*>(this);
else
{
*object = NULL;
return E_NOINTERFACE;
}
if (NULL == *object)
return E_UNEXPECTED;
AddRef();
return S_OK;
}
const char *DeviceSupportedCommand::GetName()
{
return name;
}
HRESULT DeviceSupportedCommand::GetFlags(DeviceCommandFlags *flagsOut)
{
if (NULL == flagsOut)
return E_POINTER;
*flagsOut = flags;
return S_OK;
}
HRESULT DeviceSupportedCommand::SetFlags(DeviceCommandFlags mask, DeviceCommandFlags value)
{
DeviceCommandFlags temp;
temp = (flags & mask) | (mask & value);
if (temp == flags)
return S_FALSE;
flags = temp;
return S_OK;
}
#define CBCLASS DeviceSupportedCommand
START_DISPATCH;
CB(ADDREF, AddRef)
CB(RELEASE, Release)
CB(QUERYINTERFACE, QueryInterface)
CB(API_GETNAME, GetName)
CB(API_GETFLAGS, GetFlags)
END_DISPATCH;
#undef CBCLASS

View File

@ -0,0 +1,46 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_SUPPORTED_COMMAND_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_SUPPORTED_COMMAND_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <wtypes.h>
#include <ifc_devicesupportedcommand.h>
class DeviceSupportedCommand : public ifc_devicesupportedcommand
{
protected:
DeviceSupportedCommand();
~DeviceSupportedCommand();
public:
static HRESULT CreateInstance(const char *name,
DeviceSupportedCommand **instance);
public:
/* Dispatchable */
size_t AddRef();
size_t Release();
int QueryInterface(GUID interface_guid, void **object);
/* ifc_devicesupportedcommand */
const char *GetName();
HRESULT GetFlags(DeviceCommandFlags *flags);
public:
HRESULT SetFlags(DeviceCommandFlags mask, DeviceCommandFlags value);
protected:
size_t ref;
char *name;
DeviceCommandFlags flags;
protected:
RECVS_DISPATCH;
};
#endif //_NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_SUPPORTED_COMMAND_HEADER

View File

@ -0,0 +1,555 @@
#include "main.h"
#include "./testSuite.h"
#include <strsafe.h>
TestSuite::TestSuite()
{
}
TestSuite::~TestSuite()
{
size_t index;
index = deviceList.size();
while(index--)
{
deviceList[index]->Release();
}
index = typeList.size();
while(index--)
{
typeList[index]->Release();
}
index = connectionList.size();
while(index--)
{
connectionList[index]->Release();
}
index = commandList.size();
while(index--)
{
commandList[index]->Release();
}
index = insertList.size();
while(index--)
{
AnsiString_Free(insertList[index]);
}
}
BOOL TestSuite::AddDevice(Device *device)
{
if (NULL == device)
return FALSE;
deviceList.push_back(device);
device->AddRef();
return TRUE;
}
size_t TestSuite::GetDeviceCount()
{
return deviceList.size();
}
Device *TestSuite::GetDevice(size_t index)
{
return deviceList[index];
}
static int
String_RemoveCounter(wchar_t *string)
{
int len;
len = lstrlenW(string);
if (len > 3)
{
int cutoff = 0;
if (string[len-1] == L')')
{
WORD charType;
cutoff = 1;
while(len > cutoff &&
FALSE != GetStringTypeW(CT_CTYPE1, string + (len - 1) - cutoff, 1, &charType) &&
0 != (C1_DIGIT & charType))
{
cutoff++;
}
if (len > cutoff &&
cutoff > 1 &&
L'(' == string[len - 1 - cutoff])
{
cutoff++;
if (len > cutoff &&
L' ' == string[len - 1 - cutoff])
{
string[len - 1 - cutoff] = L'\0';
len -= (cutoff + 1);
}
}
}
}
return len;
}
static int
AnsiString_RemoveCounter(char *string)
{
int len;
len = lstrlenA(string);
if (len > 3)
{
int cutoff = 0;
if (string[len-1] == ')')
{
WORD charType;
cutoff = 1;
while(len > cutoff &&
FALSE != GetStringTypeA(LOCALE_SYSTEM_DEFAULT, CT_CTYPE1, string + (len - 1) - cutoff, 1, &charType) &&
0 != (C1_DIGIT & charType))
{
cutoff++;
}
if (len > cutoff &&
cutoff > 1 &&
'(' == string[len - 1 - cutoff])
{
cutoff++;
if (len > cutoff &&
' ' == string[len - 1 - cutoff])
{
string[len - 1 - cutoff] = '\0';
len -= (cutoff + 1);
}
}
}
}
return len;
}
Device *TestSuite::CreateDeviceCopy(Device *source)
{
const char *name;
size_t index, counter;
char buffer[1024];
wchar_t *displayName;
BOOL found;
Device *destination;
int length;
if (NULL == source)
return NULL;
found = FALSE;
counter = 0;
name = source->GetName();
StringCbCopyA(buffer, sizeof(buffer), name);
length = AnsiString_RemoveCounter(buffer);
for (;;)
{
if (0 != counter)
StringCbPrintfA(buffer + length, sizeof(buffer) - length, " (%d)", counter);
found = TRUE;
index = deviceList.size();
while(index--)
{
if (CSTR_EQUAL == CompareStringA(CSTR_INVARIANT, 0, deviceList[index]->GetName(), -1, buffer, -1))
{
found = FALSE;
break;
}
}
if (FALSE != found)
break;
else
counter++;
}
if (FAILED(Device::CreateInstance(buffer, source->GetType(), source->GetConnection(), &destination)))
return NULL;
source->CopyTo(destination);
source->GetDisplayName((wchar_t*)buffer, sizeof(buffer)/sizeof(wchar_t));
displayName = (wchar_t*)buffer;
length = String_RemoveCounter(displayName);
if (0 != counter)
StringCchPrintf(displayName + length, sizeof(buffer)/sizeof(wchar_t) - length, L" (%d)", counter);
destination->SetDisplayName(displayName);
return destination;
}
Device *TestSuite::GetRandomDevice()
{
size_t index;
Device *device;
LARGE_INTEGER perfCounter;
if (0 == deviceList.size())
return NULL;
if (FALSE != QueryPerformanceCounter(&perfCounter))
srand(perfCounter.LowPart);
else
srand(GetTickCount());
index = (size_t)((double)rand()/(RAND_MAX + 1) * deviceList.size());
device = deviceList[index];
if (S_OK == device->IsConnected())
{
size_t search;
for(search = index + 1; search < deviceList.size(); search++)
{
device = deviceList[search];
if (S_FALSE == device->IsConnected())
return device;
}
search = index;
while(search--)
{
device = deviceList[search];
if (S_FALSE == device->IsConnected())
return device;
}
device = CreateDeviceCopy(deviceList[index]);
if (NULL != device)
{
size_t totalSpace, usedSpace;
totalSpace = (size_t)((double)rand()/(RAND_MAX + 1) * 1000);
usedSpace = (size_t)((double)rand()/(RAND_MAX + 1) * totalSpace);
device->SetTotalSpace(totalSpace);
device->SetUsedSpace(usedSpace);
device->Disconnect();
device->Detach(NULL);
AddDevice(device);
}
}
return device;
}
BOOL TestSuite::AddType(ifc_devicetype *type)
{
if (NULL == type)
return FALSE;
typeList.push_back(type);
type->AddRef();
return TRUE;
}
size_t TestSuite::GetTypeCount()
{
return typeList.size();
}
ifc_devicetype *TestSuite::GetType(size_t index)
{
return typeList[index];
}
BOOL TestSuite::RegisterTypes(api_devicemanager *manager)
{
if (NULL == manager)
return FALSE;
if (0 != typeList.size())
manager->TypeRegister((ifc_devicetype**)typeList.begin(), typeList.size());
return TRUE;
}
BOOL TestSuite::UnregisterTypes(api_devicemanager *manager)
{
size_t index;
if (NULL == manager)
return FALSE;
index = typeList.size();
while(index--)
{
manager->TypeUnregister(typeList[index]->GetName());
}
return TRUE;
}
BOOL TestSuite::SetIconBase(const wchar_t *path)
{
size_t index;
Device *device;
ifc_devicetype *type;
ifc_devicetypeeditor *typeEditor;
ifc_deviceiconstore *iconStore;
ifc_deviceconnection *connection;
ifc_deviceconnectioneditor *connectionEditor;
ifc_devicecommand *command;
ifc_devicecommandeditor *commandEditor;
index = deviceList.size();
while(index--)
{
device = deviceList[index];
device->SetIconBase(path);
}
index = typeList.size();
while(index--)
{
type = typeList[index];
if (SUCCEEDED(type->QueryInterface(IFC_DeviceTypeEditor, (void**)&typeEditor)))
{
if(SUCCEEDED(typeEditor->GetIconStore(&iconStore)))
{
iconStore->SetBasePath(path);
iconStore->Release();
}
typeEditor->Release();
}
}
index = commandList.size();
while(index--)
{
command = commandList[index];
if (SUCCEEDED(command->QueryInterface(IFC_DeviceCommandEditor, (void**)&commandEditor)))
{
if(SUCCEEDED(commandEditor->GetIconStore(&iconStore)))
{
iconStore->SetBasePath(path);
iconStore->Release();
}
commandEditor->Release();
}
}
index = connectionList.size();
while(index--)
{
connection = connectionList[index];
if (SUCCEEDED(connection->QueryInterface(IFC_DeviceConnectionEditor, (void**)&connectionEditor)))
{
if(SUCCEEDED(connectionEditor->GetIconStore(&iconStore)))
{
iconStore->SetBasePath(path);
iconStore->Release();
}
connectionEditor->Release();
}
}
return S_OK;
}
BOOL TestSuite::SetConnectList(char **devices, size_t count)
{
size_t index;
char *name;
index = insertList.size();
if (index > 0)
{
while(index--)
{
name = insertList[index];
AnsiString_Free(name);
}
insertList.clear();
}
for(index = 0; index < count; index++)
{
name = AnsiString_Duplicate(devices[index]);
if (NULL != name)
insertList.push_back(name);
}
return TRUE;
}
Device *TestSuite::GetDeviceByName(const char *name)
{
size_t index;
Device *device;
for (index = 0; index < deviceList.size(); index++)
{
device = deviceList[index];
if (CSTR_EQUAL == CompareStringA(CSTR_INVARIANT, NORM_IGNORECASE, name, -1, device->GetName(), -1))
return device;
}
return NULL;
}
BOOL TestSuite::RegisterDevices(api_devicemanager *manager)
{
size_t index;
const char *name;
Device *device;
if (NULL == manager)
return FALSE;
for (index = 0; index < insertList.size(); index++)
{
name = insertList[index];
device = GetDeviceByName(name);
if (NULL != device)
{
manager->DeviceRegister((ifc_device**)&device, 1);
device->Connect();
}
}
return TRUE;
}
BOOL TestSuite::UnregisterDevices(api_devicemanager *manager)
{
size_t index;
Device *device;
if (NULL == manager)
return FALSE;
index = deviceList.size();
while(index--)
{
device = deviceList[index];
if (S_OK == device->IsConnected())
{
device->Disconnect();
manager->DeviceUnregister(device->GetName());
}
}
return TRUE;
}
BOOL TestSuite::AddConnection(ifc_deviceconnection *connection)
{
if (NULL == connection)
return FALSE;
connectionList.push_back(connection);
connection->AddRef();
return TRUE;
}
size_t TestSuite::GetConnectionCount()
{
return connectionList.size();
}
ifc_deviceconnection *TestSuite::GetConnection(size_t index)
{
return connectionList[index];
}
BOOL TestSuite::RegisterConnections(api_devicemanager *manager)
{
if (NULL == manager)
return FALSE;
if (0 != connectionList.size())
manager->ConnectionRegister((ifc_deviceconnection**)connectionList.begin(), connectionList.size());
return TRUE;
}
BOOL TestSuite::UnregisterConnections(api_devicemanager *manager)
{
size_t index;
if (NULL == manager)
return FALSE;
index = connectionList.size();
while(index--)
{
manager->ConnectionUnregister(connectionList[index]->GetName());
}
return TRUE;
}
BOOL TestSuite::AddCommand(ifc_devicecommand *command)
{
if (NULL == command)
return FALSE;
commandList.push_back(command);
command->AddRef();
return TRUE;
}
size_t TestSuite::GetCommandCount()
{
return commandList.size();
}
ifc_devicecommand *TestSuite::GetCommand(size_t index)
{
return commandList[index];
}
BOOL TestSuite::RegisterCommands(api_devicemanager *manager)
{
if (NULL == manager)
return FALSE;
if (0 != commandList.size())
manager->CommandRegister((ifc_devicecommand**)commandList.begin(), commandList.size());
return TRUE;
}
BOOL TestSuite::UnregisterCommands(api_devicemanager *manager)
{
size_t index;
if (NULL == manager)
return FALSE;
index = commandList.size();
while(index--)
{
manager->CommandUnregister(commandList[index]->GetName());
}
return TRUE;
}

View File

@ -0,0 +1,67 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_TEST_SUITE_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_TEST_SUITE_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <wtypes.h>
#include <vector>
#include "./device.h"
class TestSuite
{
public:
TestSuite();
~TestSuite();
public:
BOOL AddDevice(Device *device);
size_t GetDeviceCount();
Device *GetDevice(size_t index);
Device *GetRandomDevice();
Device *CreateDeviceCopy(Device *source);
Device *GetDeviceByName(const char *name);
BOOL RegisterDevices(api_devicemanager *manager);
BOOL UnregisterDevices(api_devicemanager *manager);
BOOL AddType(ifc_devicetype *type);
size_t GetTypeCount();
ifc_devicetype *GetType(size_t index);
BOOL RegisterTypes(api_devicemanager *manager);
BOOL UnregisterTypes(api_devicemanager *manager);
BOOL AddConnection(ifc_deviceconnection *connection);
size_t GetConnectionCount();
ifc_deviceconnection *GetConnection(size_t index);
BOOL RegisterConnections(api_devicemanager *manager);
BOOL UnregisterConnections(api_devicemanager *manager);
BOOL AddCommand(ifc_devicecommand *command);
size_t GetCommandCount();
ifc_devicecommand *GetCommand(size_t index);
BOOL RegisterCommands(api_devicemanager *manager);
BOOL UnregisterCommands(api_devicemanager *manager);
BOOL SetIconBase(const wchar_t *path);
BOOL SetConnectList(char **devices, size_t count);
private:
typedef std::vector<Device*> DeviceList;
typedef std::vector<ifc_devicetype*> TypeList;
typedef std::vector<ifc_deviceconnection*> ConnectionList;
typedef std::vector<ifc_devicecommand*> CommandList;
typedef std::vector<char*> NameList;
private:
DeviceList deviceList;
TypeList typeList;
ConnectionList connectionList;
CommandList commandList;
NameList insertList;
};
#endif // _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_TEST_SUITE_HEADER

View File

@ -0,0 +1,226 @@
#include "main.h"
#include "./testSuiteLoader.h"
#include "../../xml/obj_xml.h"
#include <api/service/waservicefactory.h>
#include <strsafe.h>
typedef void (CALLBACK *LOADERTAGCALLBACK)(TestSuiteLoader* /*loader*/, const wchar_t* /*value*/);
typedef struct LOADERTAG
{
const wchar_t *name;
LOADERTAGCALLBACK callback;
} LOADERTAG;
static void CALLBACK
LoaderTag_ImageBase(TestSuiteLoader *loader, const wchar_t *value)
{
String_Free(loader->imageBase);
loader->imageBase = String_Duplicate(value);
}
static void CALLBACK
LoaderTag_Connect(TestSuiteLoader *loader, const wchar_t *value)
{
if (IS_STRING_EMPTY(value))
return;
const wchar_t *block, *cursor;
char *name;
size_t length;
block = value;
cursor = block;
for(;;)
{
if (L'\0' == *cursor ||
L';' == *cursor ||
L',' == *cursor)
{
if (block < cursor)
{
length = cursor - block;
name = String_ToAnsi(CP_UTF8, 0, block, (int)length, NULL, NULL);
if (NULL != name)
loader->connectList.push_back(name);
}
if (L'\0' == *cursor)
break;
block = cursor + 1;
}
cursor++;
}
//loader->SetImageBase(value);
}
static const LOADERTAG knownTags[LOADER_TAG_MAX] =
{
{L"imageBase", LoaderTag_ImageBase},
{L"connect", LoaderTag_Connect},
};
TestSuiteLoader::TestSuiteLoader()
: imageBase(NULL)
{
}
TestSuiteLoader::~TestSuiteLoader()
{
size_t index;
index = connectList.size();
while(index--)
{
AnsiString_Free(connectList[index]);
}
String_Free(imageBase);
}
BOOL TestSuiteLoader::Load(const wchar_t *path, TestSuite *testSuite)
{
BOOL result;
HANDLE fileHandle;
obj_xml *reader;
if (NULL == testSuite)
return FALSE;
if (NULL == path || L'\0' == *path)
return FALSE;
fileHandle = CreateFile(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (INVALID_HANDLE_VALUE == fileHandle)
return FALSE;
result = FALSE;
if (NULL != WASABI_API_SVC)
{
waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid(obj_xmlGUID);
reader = (NULL != sf) ? (obj_xml*)sf->getInterface() : NULL;
if (NULL != reader)
{
if (OBJ_XML_SUCCESS == reader->xmlreader_open())
{
reader->xmlreader_registerCallback(L"testprovider\fimageBase", this);
reader->xmlreader_registerCallback(L"testprovider\fconnect", this);
ZeroMemory(hitList, sizeof(hitList));
deviceParser.Begin(reader, testSuite);
typeParser.Begin(reader, testSuite);
connectionParser.Begin(reader, testSuite);
commandParser.Begin(reader, testSuite);
result = FeedFile(reader, fileHandle, 8192);
deviceParser.End();
typeParser.End();
connectionParser.End();
commandParser.End();
reader->xmlreader_close();
testSuite->SetIconBase(imageBase);
testSuite->SetConnectList(connectList.begin(), connectList.size());
}
sf->releaseInterface(reader);
}
}
CloseHandle(fileHandle);
return result;
}
BOOL TestSuiteLoader::FeedFile(obj_xml *reader, HANDLE fileHandle, DWORD bufferSize)
{
BOOL result;
DWORD read;
BYTE *buffer;
int readerCode;
if (NULL == reader ||
INVALID_HANDLE_VALUE == fileHandle ||
0 == bufferSize)
{
return FALSE;
}
buffer = (BYTE*)malloc(bufferSize);
if (NULL == buffer)
return FALSE;
readerCode = OBJ_XML_SUCCESS;
result = TRUE;
for(;;)
{
if (FALSE == ReadFile(fileHandle, buffer, bufferSize, &read, NULL) || 0 == read)
{
result = FALSE;
if (0 == read && OBJ_XML_SUCCESS == readerCode)
reader->xmlreader_feed(0, 0);
break;
}
readerCode = reader->xmlreader_feed(buffer, read);
if (OBJ_XML_SUCCESS != readerCode)
{
result = FALSE;
break;
}
}
free(buffer);
return result;
}
void TestSuiteLoader::Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params)
{
elementString.Clear();
}
void TestSuiteLoader::Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag)
{
for (size_t i = 0; i < LOADER_TAG_MAX; i++)
{
if (FALSE == hitList[i] &&
CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, knownTags[i].name, -1, xmltag, -1))
{
knownTags[i].callback(this, elementString.Get());
hitList[i] = TRUE;
break;
}
}
}
void TestSuiteLoader::Event_XmlCharData(const wchar_t *xmlpath, const wchar_t *xmltag, const wchar_t *value)
{
elementString.Append(value);
}
void TestSuiteLoader::Event_XmlError(int linenum, int errcode, const wchar_t *errstr)
{
elementString.Clear();
}
#define CBCLASS TestSuiteLoader
START_DISPATCH;
VCB(ONSTARTELEMENT, Event_XmlStartElement)
VCB(ONENDELEMENT, Event_XmlEndElement)
VCB(ONCHARDATA, Event_XmlCharData)
VCB(ONERROR, Event_XmlError)
END_DISPATCH;
#undef CBCLASS

View File

@ -0,0 +1,60 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_TEST_SUITE_LOADER_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_TEST_SUITE_LOADER_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <wtypes.h>
#include "../../xml/ifc_xmlreadercallback.h"
#include <vector>
#include "./DeviceNodeParser.h"
#include "./DeviceTypeNodeParser.h"
#include "./DeviceConnectionNodeParser.h"
#include "./DeviceCommandNodeParser.h"
class obj_xml;
#define LOADER_TAG_MAX 2
class TestSuiteLoader : public ifc_xmlreadercallback
{
public:
TestSuiteLoader();
~TestSuiteLoader();
public:
BOOL Load(const wchar_t *path, TestSuite *testSuite);
private:
BOOL FeedFile(obj_xml *reader, HANDLE hFile, DWORD bufferSize);
void Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params);
void Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag);
void Event_XmlCharData(const wchar_t *xmlpath, const wchar_t *xmltag, const wchar_t *value);
void Event_XmlError(int linenum, int errcode, const wchar_t *errstr);
protected:
friend static void CALLBACK LoaderTag_ImageBase(TestSuiteLoader *loader, const wchar_t *value);
friend static void CALLBACK LoaderTag_Connect(TestSuiteLoader *loader, const wchar_t *value);
protected:
typedef std::vector<char*> NameList;
protected:
StringBuilder elementString;
DeviceNodeParser deviceParser;
DeviceTypeNodeParser typeParser;
DeviceConnectionNodeParser connectionParser;
DeviceCommandNodeParser commandParser;
BOOL hitList[LOADER_TAG_MAX];
wchar_t *imageBase;
NameList connectList;
protected:
RECVS_DISPATCH;
};
#endif // _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_TEST_SUITE_LOADER_HEADER

View File

@ -0,0 +1,244 @@
<?xml version="1.0" encoding="UTF-8"?>
<testprovider>
<imageBase>c:\winamp\ml_devices\resources\food</imageBase>
<connect>iconTest;apple;banana;grape;pear;pepper;eggplant;cucumber;carrot</connect>
<connections>
<connection name="usb">
<displayName>USB</displayName>
<icon>..\connections\usb.png</icon>
</connection>
<connection name="wifi">
<displayName>Wi-Fi</displayName>
<icon>..\connections\wifi.png</icon>
</connection>
<connection name="bluetooth">
<displayName>Bluetooth</displayName>
<icon>..\connections\bluetooth.png</icon>
</connection>
</connections>
<types>
<type name="vegetables">
<displayName>Vegetables</displayName>
<icon>vegetables.png</icon>
</type>
<type name="fruits">
<displayName>Fruits</displayName>
<icon>fruits.png</icon>
</type>
<type name="grains">
<displayName>Grains</displayName>
<icon>grains.png</icon>
</type>
</types>
<commands>
<command name="sync">
<displayName>&amp;Sync</displayName>
<description>Sync things</description>
<icon>..\commands\sync.png</icon>
</command>
<command name="settings">
<displayName>Se&amp;ttings</displayName>
<description>Open settings page</description>
<icon>..\commands\settings.png</icon>
</command>
<command name="detach">
<displayName>&amp;Detach</displayName>
<description>Detach device</description>
<icon>..\commands\detach.png</icon>
</command>
<command name="eject">
<displayName>&amp;Eject</displayName>
<description>Eject device</description>
<icon>..\commands\eject.png</icon>
</command>
</commands>
<devices>
<device name="iconTest" type="test">
<connection></connection>
<displayName>Icon Test</displayName>
<icon width="24" height="32">..\zoom\24x32.png</icon>
<icon width="48" height="64">..\zoom\48x64.png</icon>
<icon width="96" height="128">..\zoom\96x128.png</icon>
<icon width="192" height="256">..\zoom\192x256.png</icon>
<command primary="1" disabled="0">sync</command>
<command primary="0" disabled="0" hidden="0" group="1">settings</command>
<command primary="0">detach</command>
<command disabled="1" hidden="0">eject</command>
<totalSpace>909242</totalSpace>
<usedSpace>0</usedSpace>
<hidden>0</hidden>
<model>Icon Test v1.0</model>
<status>Icon Test status string</status>
</device>
<device name="apple" type="fruits">
<connection>wifi</connection>
<displayName>Dilicious&#10;Apple</displayName>
<icon>apple.png</icon>
<totalSpace>100</totalSpace>
<usedSpace>0</usedSpace>
<hidden>0</hidden>
<model>iApple 2</model>
<command primary="1">sync</command>
<command group="1">eject</command>
</device>
<device name="banana" type="fruits">
<connection>usb</connection>
<displayName>Banana</displayName>
<icon>banana.png</icon>
<totalSpace>100</totalSpace>
<usedSpace>0</usedSpace>
<hidden>0</hidden>
<model>iBanana 2</model>
<command primary="1">sync</command>
<command group="1">eject</command>
</device>
<device name="peach" type="fruits">
<connection>bluetooth</connection>
<displayName>Peach</displayName>
<icon>peach.png</icon>
<totalSpace>100</totalSpace>
<usedSpace>0</usedSpace>
<hidden>0</hidden>
<model>iPeach 2</model>
<command primary="1">sync</command>
<command group="1">eject</command>
</device>
<device name="orange" type="fruits">
<connection>usb</connection>
<displayName>Orange</displayName>
<icon>orange.png</icon>
<totalSpace>100</totalSpace>
<usedSpace>0</usedSpace>
<hidden>0</hidden>
<model>iOrange 2</model>
<command primary="1">sync</command>
<command group="1">eject</command>
</device>
<device name="pear" type="fruits">
<connection>wifi</connection>
<displayName>Pear</displayName>
<icon>pear.png</icon>
<totalSpace>100</totalSpace>
<usedSpace>0</usedSpace>
<hidden>0</hidden>
<model>iPear 2</model>
<command primary="1">sync</command>
<command group="1">eject</command>
</device>
<device name="grape" type="fruits">
<connection>bluetooth</connection>
<displayName>Grape</displayName>
<icon>grape.png</icon>
<totalSpace>100</totalSpace>
<usedSpace>0</usedSpace>
<hidden>0</hidden>
<model>iGrape 2</model>
<command primary="1">sync</command>
<command group="1">eject</command>
</device>
<device name="lemon" type="fruits">
<connection>usb</connection>
<displayName>Lemon</displayName>
<icon>lemon.png</icon>
<totalSpace>100</totalSpace>
<usedSpace>0</usedSpace>
<hidden>0</hidden>
<model>iLemon 2</model>
<command primary="1">sync</command>
<command group="1">eject</command>
</device>
<device name="carrot" type="vegetables">
<connection>wifi</connection>
<displayName>Carrot</displayName>
<icon>carrot.png</icon>
<totalSpace>100</totalSpace>
<usedSpace>0</usedSpace>
<hidden>0</hidden>
<command primary="1">sync</command>
</device>
<device name="broccoli" type="vegetables">
<connection>bluetooth</connection>
<displayName>Broccoli</displayName>
<icon>broccoli.png</icon>
<totalSpace>100</totalSpace>
<usedSpace>0</usedSpace>
<hidden>0</hidden>
<command primary="1">sync</command>
</device>
<device name="eggplant" type="vegetables">
<connection>usb</connection>
<displayName>Eggplant</displayName>
<icon>eggplant.png</icon>
<totalSpace>100</totalSpace>
<usedSpace>0</usedSpace>
<hidden>0</hidden>
<command primary="1">sync</command>
</device>
<device name="cucumber" type="vegetables">
<connection>wifi</connection>
<displayName>Cucumber</displayName>
<icon>cucumber.png</icon>
<totalSpace>0</totalSpace>
<usedSpace>0</usedSpace>
<hidden>0</hidden>
<command primary="1">sync</command>
</device>
<device name="pepper" type="vegetables">
<connection>bluetooth</connection>
<displayName>Pepper</displayName>
<icon>pepper.png</icon>
<totalSpace>0</totalSpace>
<usedSpace>0</usedSpace>
<hidden>0</hidden>
<command primary="1">sync</command>
</device>
<device name="bread" type="grains">
<connection>usb</connection>
<displayName>Bread</displayName>
<icon>bread.png</icon>
<totalSpace>100</totalSpace>
<usedSpace>0</usedSpace>
<hidden>0</hidden>
</device>
<device name="pasta" type="grains">
<connection>wifi</connection>
<displayName>Pasta</displayName>
<icon>pasta.png</icon>
<totalSpace>100</totalSpace>
<usedSpace>0</usedSpace>
<hidden>0</hidden>
</device>
<device name="rice" type="grains">
<connection>bluetooth</connection>
<displayName>Rice</displayName>
<icon>rice.png</icon>
<totalSpace>100</totalSpace>
<usedSpace>0</usedSpace>
<hidden>0</hidden>
</device>
<device name="cereal" type="grains">
<connection>usb</connection>
<displayName>Cereal</displayName>
<icon>cereal.png</icon>
<totalSpace>100</totalSpace>
<usedSpace>0</usedSpace>
<hidden>0</hidden>
</device>
<device name="muffin" type="grains">
<connection>wifi</connection>
<displayName>Muffin</displayName>
<icon>muffin.png</icon>
<totalSpace>100</totalSpace>
<usedSpace>0</usedSpace>
<hidden>0</hidden>
</device>
<device name="pretzel" type="grains">
<connection>bluetooth</connection>
<displayName>Pretzel</displayName>
<icon>pretzel.png</icon>
<totalSpace>100</totalSpace>
<usedSpace>0</usedSpace>
<hidden>0</hidden>
</device>
</devices>
</testprovider>

View File

@ -0,0 +1,139 @@
#include "main.h"
#include "./wasabi.h"
#include <api/service/waservicefactory.h>
api_service *WASABI_API_SVC = NULL;
api_application *WASABI_API_APP = NULL;
api_language *WASABI_API_LNG = NULL;
api_devicemanager *WASABI_API_DEVICES = NULL;
HINSTANCE WASABI_API_LNG_HINST = NULL;
HINSTANCE WASABI_API_ORIG_HINST = NULL;
static unsigned long wasabiReference = 0;
static BOOL defaultServicesLoaded = FALSE;
static void
Wasabi_Uninitialize()
{
if (NULL != WASABI_API_SVC)
{
Wasabi_ReleaseInterface(applicationApiServiceGuid, WASABI_API_APP);
Wasabi_ReleaseInterface(languageApiGUID, WASABI_API_LNG);
Wasabi_ReleaseInterface(DeviceManagerGUID, WASABI_API_DEVICES);
}
WASABI_API_SVC = NULL;
WASABI_API_APP = NULL;
WASABI_API_LNG = NULL;
WASABI_API_DEVICES = NULL;
defaultServicesLoaded = FALSE;
}
BOOL
Wasabi_Initialize(HINSTANCE instance, api_service *serviceMngr)
{
if (NULL != WASABI_API_SVC)
return FALSE;
defaultServicesLoaded = FALSE;
WASABI_API_SVC = serviceMngr;
if ((api_service*)1 == WASABI_API_SVC)
WASABI_API_SVC = NULL;
if (NULL == WASABI_API_SVC)
return FALSE;
WASABI_API_APP = NULL;
WASABI_API_DEVICES = NULL;
WASABI_API_LNG = NULL;
WASABI_API_ORIG_HINST = instance;
WASABI_API_LNG_HINST = WASABI_API_ORIG_HINST;
Wasabi_AddRef();
return TRUE;
}
BOOL
Wasabi_InitializeFromWinamp(HINSTANCE instance, HWND winampWindow)
{
api_service *serviceMngr;
serviceMngr = (api_service*)SENDWAIPC(winampWindow, IPC_GET_API_SERVICE, 0);
return Wasabi_Initialize(instance, serviceMngr);
}
BOOL
Wasabi_LoadDefaultServices(void)
{
if (NULL == WASABI_API_SVC)
return FALSE;
if (FALSE != defaultServicesLoaded)
return FALSE;
WASABI_API_APP = Wasabi_QueryInterface(api_application, applicationApiServiceGuid);
WASABI_API_DEVICES = Wasabi_QueryInterface(api_devicemanager, DeviceManagerGUID);
WASABI_API_LNG = Wasabi_QueryInterface(api_language, languageApiGUID);
if (NULL != WASABI_API_LNG)
{
WASABI_API_LNG_HINST = WASABI_API_LNG->StartLanguageSupport(WASABI_API_ORIG_HINST,
PLUGIN_LANGUAGE_ID);
}
defaultServicesLoaded = TRUE;
return TRUE;
}
unsigned long
Wasabi_AddRef(void)
{
return InterlockedIncrement((LONG*)&wasabiReference);
}
unsigned long
Wasabi_Release(void)
{
if (0 == wasabiReference)
return wasabiReference;
LONG r = InterlockedDecrement((LONG*)&wasabiReference);
if (0 == r)
{
Wasabi_Uninitialize();
}
return r;
}
void *
Wasabi_QueryInterface0(const GUID &interfaceGuid)
{
waServiceFactory *serviceFactory;
if (NULL == WASABI_API_SVC)
return NULL;
serviceFactory = WASABI_API_SVC->service_getServiceByGuid(interfaceGuid);
if (NULL == serviceFactory)
return NULL;
return serviceFactory->getInterface();
}
void
Wasabi_ReleaseInterface0(const GUID &interfaceGuid, void *interfaceInstance)
{
waServiceFactory *serviceFactory;
if (NULL == WASABI_API_SVC)
return;
serviceFactory = WASABI_API_SVC->service_getServiceByGuid(interfaceGuid);
if (NULL == serviceFactory)
return;
serviceFactory->releaseInterface(interfaceInstance);
}

View File

@ -0,0 +1,57 @@
#ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_WASABI_HEADER
#define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_WASABI_HEADER
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include <api/service/api_service.h>
extern api_service *wasabiManager;
#define WASABI_API_SVC wasabiManager
#include <api/application/api_application.h>
#define WASABI_API_APP applicationApi
#include "../Agave/Language/api_language.h"
#include "../../devices/api_devicemanager.h"
extern api_devicemanager *deviceManagerApi;
#define WASABI_API_DEVICES deviceManagerApi
BOOL
Wasabi_Initialize(HINSTANCE instance,
api_service *serviceMngr);
BOOL
Wasabi_InitializeFromWinamp(HINSTANCE instance,
HWND winampWindow);
BOOL
Wasabi_LoadDefaultServices(void);
unsigned long
Wasabi_AddRef(void);
unsigned long
Wasabi_Release(void);
void *
Wasabi_QueryInterface0(const GUID &interfaceGuid);
#define Wasabi_QueryInterface(_interfaceType, _interfaceGuid)\
((##_interfaceType*)Wasabi_QueryInterface0(_interfaceGuid))
void
Wasabi_ReleaseInterface0(const GUID &interfaceGuid,
void *interfaceInstance);
#define Wasabi_ReleaseInterface(_interfaceGuid, _interfaceInstance)\
(Wasabi_ReleaseInterface0((_interfaceGuid), (_interfaceInstance)))
#define Wasabi_ReleaseObject(_object)\
{if (NULL != (_object)) {((Dispatchable*)(_object))->Release();}}
#endif // _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_WASABI_HEADER