mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-27 09:41:32 +01:00
Add some better error handling when copying files to WMDM devices, and receive progress notifications (they're not used yet except to output to stderr)
This commit is contained in:
parent
f5cbeabb9b
commit
299fb16c99
@ -562,6 +562,7 @@ IF(WIN32)
|
||||
list(APPEND SOURCES devices/wmdmdevice.cpp)
|
||||
list(APPEND SOURCES devices/wmdmlister.cpp)
|
||||
list(APPEND SOURCES devices/wmdmloader.cpp)
|
||||
list(APPEND SOURCES devices/wmdmprogress.cpp)
|
||||
list(APPEND SOURCES devices/wmdmthread.cpp)
|
||||
|
||||
list(APPEND HEADERS devices/wmdmdevice.h)
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "wmdmdevice.h"
|
||||
#include "wmdmlister.h"
|
||||
#include "wmdmloader.h"
|
||||
#include "wmdmprogress.h"
|
||||
#include "wmdmthread.h"
|
||||
#include "core/utilities.h"
|
||||
#include "library/librarybackend.h"
|
||||
@ -95,11 +96,13 @@ bool WmdmDevice::CopyToStorage(
|
||||
storage_->CreateEmptyMetadataObject(&metadata_iface);
|
||||
song.ToWmdm(metadata_iface);
|
||||
|
||||
|
||||
// Convert the filenames to wchars
|
||||
ScopedWCharArray source_filename(QDir::toNativeSeparators(source));
|
||||
ScopedWCharArray dest_filename(song.basefilename());
|
||||
|
||||
// Create the progress object
|
||||
WmdmProgress progress;
|
||||
|
||||
// Copy the file
|
||||
IWMDMStorage* new_storage = NULL;
|
||||
if (storage_control_->Insert3(
|
||||
@ -109,7 +112,7 @@ bool WmdmDevice::CopyToStorage(
|
||||
source_filename,
|
||||
dest_filename,
|
||||
NULL, // operation
|
||||
NULL, // progress
|
||||
&progress, // progress
|
||||
metadata_iface,
|
||||
NULL, // data
|
||||
&new_storage)) {
|
||||
@ -119,6 +122,9 @@ bool WmdmDevice::CopyToStorage(
|
||||
}
|
||||
metadata_iface->Release();
|
||||
|
||||
if (!new_storage)
|
||||
return false;
|
||||
|
||||
// Get the metadata from the newly copied file
|
||||
IWMDMStorage3* new_storage3 = NULL;
|
||||
IWMDMMetaData* new_metadata = NULL;
|
||||
@ -129,6 +135,9 @@ bool WmdmDevice::CopyToStorage(
|
||||
new_storage->Release();
|
||||
new_storage3->Release();
|
||||
|
||||
if (!new_metadata)
|
||||
return false;
|
||||
|
||||
// Add it to our LibraryModel
|
||||
Song new_song;
|
||||
new_song.InitFromWmdm(new_metadata);
|
||||
|
79
src/devices/wmdmprogress.cpp
Normal file
79
src/devices/wmdmprogress.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
/* This file is part of Clementine.
|
||||
|
||||
Clementine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Clementine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "wmdmprogress.h"
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
WmdmProgress::WmdmProgress()
|
||||
{
|
||||
}
|
||||
|
||||
LONG WmdmProgress::QueryInterface(const IID& riid, void** object) {
|
||||
*object = 0;
|
||||
|
||||
if (riid == IID_IUnknown)
|
||||
*object = (IUnknown*) this;
|
||||
else if (riid == IID_IWMDMProgress)
|
||||
*object = (IWMDMProgress*) this;
|
||||
else if (riid == IID_IWMDMProgress2)
|
||||
*object = (IWMDMProgress2*) this;
|
||||
else if (riid == IID_IWMDMProgress3)
|
||||
*object = (IWMDMProgress3*) this;
|
||||
else
|
||||
return E_NOINTERFACE;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
ULONG WmdmProgress::AddRef() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ULONG WmdmProgress::Release() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
HRESULT WmdmProgress::Begin(DWORD estimated_ticks) {
|
||||
return Begin3(EVENT_WMDM_CONTENT_TRANSFER, estimated_ticks, NULL);
|
||||
}
|
||||
|
||||
HRESULT WmdmProgress::End() {
|
||||
return End3(EVENT_WMDM_CONTENT_TRANSFER, S_OK, NULL);
|
||||
}
|
||||
|
||||
HRESULT WmdmProgress::Progress(DWORD transpired_ticks) {
|
||||
return Progress3(EVENT_WMDM_CONTENT_TRANSFER, transpired_ticks, NULL);
|
||||
}
|
||||
|
||||
HRESULT WmdmProgress::End2(HRESULT completion_code) {
|
||||
return End3(EVENT_WMDM_CONTENT_TRANSFER, completion_code, NULL);
|
||||
}
|
||||
|
||||
HRESULT WmdmProgress::Begin3(GUID event_id, DWORD estimated_ticks, OPAQUECOMMAND* context) {
|
||||
qDebug() << Q_FUNC_INFO << estimated_ticks;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT WmdmProgress::End3(GUID event_id, HRESULT completion_code, OPAQUECOMMAND* context) {
|
||||
qDebug() << Q_FUNC_INFO << completion_code;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT WmdmProgress::Progress3(GUID event_id, DWORD transpired_ticks, OPAQUECOMMAND* context) {
|
||||
qDebug() << Q_FUNC_INFO << transpired_ticks;
|
||||
return S_OK;
|
||||
}
|
49
src/devices/wmdmprogress.h
Normal file
49
src/devices/wmdmprogress.h
Normal file
@ -0,0 +1,49 @@
|
||||
/* This file is part of Clementine.
|
||||
|
||||
Clementine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Clementine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef WMDMPROGRESS_H
|
||||
#define WMDMPROGRESS_H
|
||||
|
||||
#include <mswmdm.h>
|
||||
|
||||
class WmdmProgress : public IWMDMProgress3 {
|
||||
public:
|
||||
WmdmProgress();
|
||||
|
||||
// IUnknown
|
||||
// The __stdcall is *really* important
|
||||
virtual LONG __stdcall QueryInterface(const IID& riid, void** object);
|
||||
virtual ULONG __stdcall AddRef();
|
||||
virtual ULONG __stdcall Release();
|
||||
|
||||
// IWMDMProgress
|
||||
virtual HRESULT __stdcall Begin(DWORD estimated_ticks);
|
||||
virtual HRESULT __stdcall End();
|
||||
virtual HRESULT __stdcall Progress(DWORD transpired_ticks);
|
||||
|
||||
// IWMDMProgress2
|
||||
virtual HRESULT __stdcall End2(HRESULT completion_code);
|
||||
|
||||
// IWMDMProgress3
|
||||
virtual HRESULT __stdcall Begin3(GUID event_id, DWORD estimated_ticks,
|
||||
OPAQUECOMMAND* context);
|
||||
virtual HRESULT __stdcall End3(GUID event_id, HRESULT completion_code,
|
||||
OPAQUECOMMAND* context);
|
||||
virtual HRESULT __stdcall Progress3(GUID event_id, DWORD transpired_ticks,
|
||||
OPAQUECOMMAND* context);
|
||||
};
|
||||
|
||||
#endif // WMDMPROGRESS_H
|
Loading…
x
Reference in New Issue
Block a user