Remove use of linked SAC shim and depend on DLL version (which doesn't exist yet)

This commit is contained in:
John Maguire 2012-11-13 17:04:54 +01:00
parent e5d02fddb6
commit 543a6bf2fa
8 changed files with 79 additions and 29 deletions

View File

@ -63,7 +63,6 @@ pkg_check_modules(CHROMAPRINT libchromaprint)
if (WIN32)
find_package(ZLIB REQUIRED)
find_library(MSWMDM_LIBRARIES mswmdm)
find_library(SAC_SHIM_LIBRARIES sac_shim)
find_library(QTSPARKLE_LIBRARIES qtsparkle)
endif (WIN32)
@ -162,9 +161,6 @@ endif(NOT GETTEXT_MSGFMT_EXECUTABLE)
# Optional bits
if(WIN32)
option(ENABLE_WIN32_CONSOLE "Show the windows console even outside Debug mode" OFF)
if(SAC_SHIM_LIBRARIES)
set(HAVE_SAC ON)
endif(SAC_SHIM_LIBRARIES)
endif(WIN32)
optional_component(BREAKPAD OFF "Crash reporting")

View File

@ -990,7 +990,7 @@ optional_source(HAVE_LIBMTP
)
# Windows media lister
optional_source(HAVE_SAC
optional_source(WIN32
SOURCES
devices/wmdmdevice.cpp
devices/wmdmlister.cpp
@ -1199,11 +1199,6 @@ if (WIN32)
${QTSPARKLE_LIBRARIES}
qtwin
)
if (HAVE_SAC)
target_link_libraries(clementine_lib
${SAC_SHIM_LIBRARIES}
)
endif (HAVE_SAC)
endif (WIN32)
if (UNIX AND NOT APPLE)

View File

@ -35,7 +35,6 @@
#cmakedefine HAVE_LIBMTP
#cmakedefine HAVE_MOODBAR
#cmakedefine HAVE_QCA
#cmakedefine HAVE_SAC
#cmakedefine HAVE_SPARKLE
#cmakedefine HAVE_SPOTIFY
#cmakedefine HAVE_SPOTIFY_DOWNLOADER

View File

@ -46,9 +46,7 @@
#include <id3v1genres.h>
#ifdef Q_OS_WIN32
# ifdef HAVE_SAC
# include <mswmdm.h>
# endif
# include <mswmdm.h>
# include <QUuid>
#endif // Q_OS_WIN32
@ -703,7 +701,7 @@ void Song::InitFromLastFM(const lastfm::Track& track) {
}
#endif
#if defined(Q_OS_WIN32) && defined(HAVE_SAC)
#if defined(Q_OS_WIN32)
static void AddWmdmItem(IWMDMMetaData* metadata, const wchar_t* name,
const QVariant& value) {
switch (value.type()) {

View File

@ -39,7 +39,7 @@ class QUrl;
struct LIBMTP_track_struct;
#endif
#if defined(Q_OS_WIN32) && defined(HAVE_SAC)
#if defined(Q_OS_WIN32)
struct IWMDMMetaData;
#endif
@ -120,7 +120,7 @@ class Song {
void ToMTP(LIBMTP_track_struct* track) const;
#endif
#if defined(Q_OS_WIN32) && defined(HAVE_SAC)
#if defined(Q_OS_WIN32)
void InitFromWmdm(IWMDMMetaData* metadata);
void ToWmdm(IWMDMMetaData* metadata) const;
#endif

View File

@ -39,10 +39,8 @@
# include "macdevicelister.h"
#endif
#ifdef Q_OS_WIN32
# ifdef HAVE_SAC
# include "wmdmlister.h"
# include "wmdmdevice.h"
# endif
# include "wmdmlister.h"
# include "wmdmdevice.h"
#endif
#ifdef HAVE_LIBGPOD
# include "gpoddevice.h"
@ -206,7 +204,7 @@ DeviceManager::DeviceManager(Application* app, QObject *parent)
#ifdef Q_OS_DARWIN
AddLister(new MacDeviceLister);
#endif
#if defined(Q_OS_WIN32) && defined(HAVE_SAC)
#if defined(Q_OS_WIN32)
AddLister(new WmdmLister);
AddDeviceClass<WmdmDevice>();
#endif

View File

@ -21,18 +21,34 @@
#include <mswmdm.h>
#include <QtDebug>
#include <boost/scoped_array.hpp>
#include <QCoreApplication>
#include <QLibrary>
#include <QMutexLocker>
#include <QtDebug>
BYTE abPVK[] = {0x00};
BYTE abCert[] = {0x00};
QMutex WmdmThread::sLoadLock;
bool WmdmThread::sIsLoaded;
decltype(&CSecureChannelClient_New) WmdmThread::_CSecureChannelClient_New;
decltype(&CSecureChannelClient_Free) WmdmThread::_CSecureChannelClient_Free;
decltype(&CSecureChannelClient_SetCertificate) WmdmThread::_CSecureChannelClient_SetCertificate;
decltype(&CSecureChannelClient_SetInterface) WmdmThread::_CSecureChannelClient_SetInterface;
decltype(&CSecureChannelClient_Authenticate) WmdmThread::_CSecureChannelClient_Authenticate;
WmdmThread::WmdmThread()
: device_manager_(NULL),
sac_(NULL)
{
if (!MaybeStaticInit()) {
qLog(Warning) << "Error loading SAC shim DLL";
}
// Initialise COM
CoInitialize(0);
@ -44,15 +60,15 @@ WmdmThread::WmdmThread()
return;
}
sac_ = CSecureChannelClient_New();
if (CSecureChannelClient_SetCertificate(
sac_ = _CSecureChannelClient_New();
if (_CSecureChannelClient_SetCertificate(
sac_, SAC_CERT_V1, abCert, sizeof(abCert), abPVK, sizeof(abPVK))) {
qLog(Warning) << "Error setting SAC certificate";
return;
}
CSecureChannelClient_SetInterface(sac_, auth);
if (CSecureChannelClient_Authenticate(sac_, SAC_PROTOCOL_V1)) {
_CSecureChannelClient_SetInterface(sac_, auth);
if (_CSecureChannelClient_Authenticate(sac_, SAC_PROTOCOL_V1)) {
qLog(Warning) << "Error authenticating with SAC";
return;
}
@ -72,13 +88,49 @@ WmdmThread::~WmdmThread() {
if (sac_) {
// SAC
CSecureChannelClient_Free(sac_);
_CSecureChannelClient_Free(sac_);
}
// Uninitialise COM
CoUninitialize();
}
namespace {
template <typename T>
T Resolve(QLibrary* library, const char* name) {
return reinterpret_cast<T>(library->resolve(name));
}
} // namespace
bool WmdmThread::MaybeStaticInit() {
QMutexLocker locker(&sLoadLock);
if (!sIsLoaded) {
QLibrary library(QCoreApplication::applicationDirPath() + "/sac_shim.dll");
if (!library.load()) {
return false;
}
_CSecureChannelClient_New = Resolve<decltype(_CSecureChannelClient_New)>(
&library, "CSecureChannelClient_New");
_CSecureChannelClient_Free = Resolve<decltype(_CSecureChannelClient_Free)>(
&library, "CSecureChannelClient_Free");
_CSecureChannelClient_SetCertificate = Resolve<decltype(_CSecureChannelClient_SetCertificate)>(
&library, "CSecureChannelClient_SetCertificate");
_CSecureChannelClient_SetInterface = Resolve<decltype(_CSecureChannelClient_SetInterface)>(
&library, "CSecureChannelClient_SetInterface");
if (_CSecureChannelClient_New &&
_CSecureChannelClient_Free &&
_CSecureChannelClient_SetCertificate &&
_CSecureChannelClient_SetInterface) {
sIsLoaded = true;
return true;
}
}
return false;
}
IWMDMDevice* WmdmThread::GetDeviceByCanonicalName(const QString& device_name) {
ScopedWCharArray name(device_name);

View File

@ -18,6 +18,7 @@
#ifndef WMDMTHREAD_H
#define WMDMTHREAD_H
#include <QMutex>
#include <QtGlobal>
#include <sac_shim.h>
@ -37,10 +38,21 @@ public:
IWMDMStorage* GetRootStorage(const QString& device_name);
private:
static bool MaybeStaticInit();
Q_DISABLE_COPY(WmdmThread);
IWMDeviceManager2* device_manager_;
SacHandle sac_;
static decltype(&CSecureChannelClient_New) _CSecureChannelClient_New;
static decltype(&CSecureChannelClient_Free) _CSecureChannelClient_Free;
static decltype(&CSecureChannelClient_SetCertificate) _CSecureChannelClient_SetCertificate;
static decltype(&CSecureChannelClient_SetInterface) _CSecureChannelClient_SetInterface;
static decltype(&CSecureChannelClient_Authenticate) _CSecureChannelClient_Authenticate;
static QMutex sLoadLock;
static bool sIsLoaded;
};
#endif // WMDMTHREAD_H