c# - How to rename an object on a WPD device -


i making fork of portabledevicelib works storage service on wpd/mtp device. , stumbled upon problem. want rename file object on device, first thought change wpd_object_original_file_name property of object. exception doing this. if change wpd_object_name, name changes, filename same expected, , there no exception.

so question is, how rename object on wpd device? why exception changing filename property?

the reason, want rename is, when copying files device, if file exists, gets duplicate extension dup0, dup1, etc.

it's old response, but...
below code use rename object on wpd device:

__declspec(dllexport) hresult __cdecl supportscommand( ccomptr<iportabledevice>& device, propertykey thekey ) {     hresult err = s_ok;     ccomptr<iportabledevicecapabilities> capabilities;     ccomptr<iportabledevicekeycollection> commands;     uint numcommands = 0;     device->capabilities( &capabilities );     err = capabilities->getsupportedcommands( &commands );     err = commands->getcount( &numcommands );     propertykey key = wpd_property_null;     for( uint index = 0; index < numcommands; index++) {         err = commands->getat( index, &key );         if( isequalpropertykey(thekey, key) )             return true;     }     return false; }  __declspec(dllexport) hresult __cdecl renameobject( ccomptr<iportabledevice>& device, lpwcstr objectid, lpwcstr newname ) {     hresult err = s_ok;     if (supportscommand(device, wpd_command_object_properties_set) == false)         return (hresult)-1;     ccomptr<iportabledevicevalues> properties, values, results;     err = cocreateinstance( clsid_portabledevicevalues, null, clsctx_inproc_server, iid_iportabledevicevalues, (void**) &properties );     err = cocreateinstance( clsid_portabledevicevalues, null, clsctx_inproc_server, iid_iportabledevicevalues, (void**) &values );<br>     // mount command.     err = properties->setguidvalue( wpd_property_common_command_category         , wpd_command_object_properties_set.fmtid );     err = properties->setunsignedintegervalue( wpd_property_common_command_id         , wpd_command_object_properties_set.pid );<br>     // set values     err = properties->setstringvalue( wpd_property_object_properties_object_id, objectid );     err = values->setstringvalue( wpd_object_original_file_name, newname );     err = properties->setiportabledevicevaluesvalue( wpd_property_object_properties_property_values, values );     err = device->sendcommand( 0, properties, &results );<br>     // show results     uint count = 0;     results->getcount( &count );     propertykey key;     propvariant var;     for( uint = 0; < count; i++ ) {         results->getat( i, &key, &var );         // ...show key , var...     }     return err; } 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -