2016-12-14 18 views
0

PortableDevice API를 사용하여 MTP 장치 검색 및 장치 속성을 가져옵니다. 나는 스토리지의 용량과 같은 MTP 장치 저장을 얻으려면 가능한 storage.Here 내가 장치 저장 및 무료을 읽을 수 장치의 친숙한 이름이 점점 내 샘플 코드,MTP 장치를 얻는 방법 C#을 사용하여 스토리지 및 스토리지 용량을 사용할 수 있습니까?

public string FriendlyName 
    { 
     get 
     { 
      if (!this._isConnected) 
      { 
       throw new InvalidOperationException("Not connected to device."); 
      } 

      // Retrieve the properties of the device 
      IPortableDeviceContent content; 
      IPortableDeviceProperties properties; 
      this._device.Content(out content); 
      content.Properties(out properties); 

      // Retrieve the values for the properties 
      IPortableDeviceValues propertyValues; 
      properties.GetValues("DEVICE", null, out propertyValues); 

      // Identify the property to retrieve 
      var property = new _tagpropertykey(); 
      property.fmtid = new Guid(0x26D4979A, 0xE643, 0x4626, 0x9E, 0x2B, 
             0x73, 0x6D, 0xC0, 0xC9, 0x2F, 0xDC); 
      property.pid = 12; 

      // Retrieve the friendly name 
      string propertyValue; 
      propertyValues.GetStringValue(ref property, out propertyValue); 

      return propertyValue; 
     } 
    } 

같은 방법입니다 MTP 장치의 공간.

나는이 같은 시도,하지만 난

IPortableDeviceKeyCollection keys; 
     properties.GetSupportedProperties(objectId, out keys); 

     IPortableDeviceValues values; 
     properties.GetValues(objectId, keys, out values); 

     // Get the name of the object 
     string name; 
     var property = new _tagpropertykey();    
     property.fmtid = new Guid(0x01A3057A, 0x74D6, 0x4E80, 0xBE, 0xA7, 0xDC, 0x4C, 0x21, 0x2C, 0xE5, 0x0A); 
     property.pid = 7; 
     values.GetStringValue(property, out name); 

     // Get the type of the object 
     Guid contentType; 
     property = new _tagpropertykey(); 

     property.fmtid = new Guid(0x01A3057A, 0x74D6, 0x4E80, 0xBE, 0xA7, 0xDC, 0x4C, 0x21, 0x2C, 0xE5, 0x0A); 

     property.pid = 5; 
     values.GetGuidValue(property, out contentType); 

     var storageType = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C); 

     var functionalType = new Guid(0x8F052D93, 0xABCA, 0x4FC5, 0xA5, 0xAC, 0xB0, 0x1D, 0xF4, 0xDB, 0xE5, 0x98); 

을 어떤 것을 잃었 ........................... ........... ...................................

미리 감사드립니다.

답변

0
//Collecting the supported keys 
IPortableDeviceKeyCollection keys; 
properties.GetSupportedProperties(objectId, out keys); 

//Init 
_tagpropertykey key = new _tagpropertykey(); 
uint count = 0; 
keys.GetCount(ref count); 

//temporarily store each key and display 
for (uint i = 0; i < count; i++) 
{ 
    keys.GetAt(i, ref key); 
    Console.WriteLine("fmtid " + key.fmtid + " pid " + key.pid); 
} 

참고로 이것은 지원되는 속성 키를 표시하는 코드입니다. 루트 폴더의하지 ObjectId가 전달하지만, (예를 내부 저장에 대한 탐색기에서) 첫 번째 폴더, 당신은

WPD_STORAGE_CAPACITY _tagpropertykey 

을 볼 수 있다면 내가보기 엔 그것이 것, 모든 PropertyKeys¹를 저장하는 클래스를 만들 것을 권장합니다 훨씬 더 잘 보일 수 있습니다.

나는 cgeers 튜토리얼을 한눈에 봐야한다고 생각한다. 그래서 나는 그것을 기본으로 삼을 것이다.

  1. 는 쉽게 액세스 할 수 있도록 PortableDevice 클래스에 루트 폴더를 추가합니다 (예 : 내부 저장을 위해 이전에 언급 한 바와 같이)

    private readonly PortableDeviceFolder root = new PortableDeviceFolder("DEVICE", "DEVICE"); 
    public PortableDeviceFolder Root 
    { 
        get 
        { 
         return root; 
        } 
    } 
    
  2. IPortableDeviceProperties properties; 
    content.Properties(out properties); 
    
    IPortableDeviceValues values; 
    properties.GetValues(objectId, keys, out values); 
    
    //capacity stored as UI8 in PropVariant as stated in ² -> ulong 
    ulong capacity = 0; 
    values.GetUnsignedLargeIntegerValue(WPD_STORAGE_CAPACITY_IN_OBJECTS, out capacity); 
    
폴더 OBJECTID 동안 그 코드를 사용하여

이 코드는 Refresh 메소드 (및 submethods)의 일부와 매우 유사합니다. 따라서 폴더 개체가 이미 만들어져 있어야합니다.

이 폴더에서이 정보를 검색 할 수 있다는 사실은 순수 지식/상식입니다 (Windows 탐색기는 해당 폴더에 대한 정보도 표시 함). 맨 위에있는 첫 번째 코드 줄을 실행하여 학습 할 수 있습니다.

나 자신을 위해 - PortableDeviceFolder 구조체를 변경했습니다.이 구조체는 폴더에있는 PortableDeviceObject 컬렉션을 포함하며 각각은 부모도 저장합니다.
처럼 폴더에 대한 액세스는 예를 얻을하기가 매우 쉽다는 것을 당신의 난 그냥이 코드를 사용하십시오 folderId를 원하는 :

PortableDeviceCollection c = new PortableDeviceCollection(); 
c.Refresh(); 
PortableDevice device = c.First(); 
device.Root.RefreshFiles(); 
PortableDeviceFolder internalstorageFolder = (PortableDeviceFolder)device.Root.Files.First(); 

당신은 이런 식으로 자신을 구조를 구현하기 위해 시도하거나 완전히 다른 길을 갈 수 있습니다 , 나는 접근을위한 완벽한 구조가 없다고 생각한다. 그래서 가장 잘 맞는 것이 무엇인지 알아 내야한다.

¹ : https://github.com/gtaglang/WpdLib/blob/master/src/WpdLib/WpdProperties.cs

² : https://msdn.microsoft.com/de-de/library/ff597918(v=vs.85).aspx