/// <summary> /// 获取总容量和可用容量 /// </summary> /// <param name="deviceContent"></param> /// <param name="storageId"></param> /// <param name="freeSpace"></param> /// <param name="storageCapacity"></param> private static void GetStorageCapacityAnFreeSpace(IPortableDeviceContent deviceContent, string storageId, out ulong freeSpace, out ulong storageCapacity) { try { IPortableDeviceProperties deviceProperties; deviceContent.Properties(out deviceProperties); IPortableDeviceKeyCollection keyCollection = (IPortableDeviceKeyCollection) new PortableDeviceTypesLib.PortableDeviceKeyCollectionClass(); _tagpropertykey freeSpaceKey = new _tagpropertykey(); freeSpaceKey.fmtid = new Guid("01a3057a-74d6-4e80-bea7-dc4c212ce50a"); freeSpaceKey.pid = 5; _tagpropertykey storageCapacityKey = new _tagpropertykey(); storageCapacityKey.fmtid = new Guid("01a3057a-74d6-4e80-bea7-dc4c212ce50a"); storageCapacityKey.pid = 4; keyCollection.Add(freeSpaceKey); keyCollection.Add(storageCapacityKey); IPortableDeviceValues deviceValues; deviceProperties.GetValues(storageId, keyCollection, out deviceValues); deviceValues.GetUnsignedLargeIntegerValue(ref freeSpaceKey, out freeSpace); deviceValues.GetUnsignedLargeIntegerValue(ref storageCapacityKey, out storageCapacity); } catch { freeSpace = 0; storageCapacity = 0; } }
internal IPortableDeviceValues GetProperties(IPortableDeviceKeyCollection keyCol) { this.content.Properties(out IPortableDeviceProperties properties); properties.GetValues(this.ServiceObjectID, keyCol, out IPortableDeviceValues deviceValues); return(deviceValues); }
public static IEnumerable <TEnum> ToEnum <TEnum>(this IPortableDeviceKeyCollection col) where TEnum : struct // enum { uint count = 0; col.GetCount(ref count); for (uint i = 0; i < count; i++) { PropertyKey key = new PropertyKey(); col.GetAt(i, ref key); yield return(GetEnumFromAttrKey <TEnum>(key)); } }
public static IEnumerable <PropertyKey> ToEnum(this IPortableDeviceKeyCollection col) { uint count = 0; col.GetCount(ref count); for (uint i = 0; i < count; i++) { PropertyKey key = new PropertyKey(); col.GetAt(i, ref key); yield return(key); } }
public static void WriteObject(IPortableDeviceKeyCollection collection) { Trace.WriteLine("###############################"); uint num = 0; collection.GetCount(ref num); for (uint index = 0; index < num; index++) { PropertyKey key = new PropertyKey(); collection.GetAt(index, ref key); PropertyKeys propertyKey = key.GetEnumFromAttrKey <PropertyKeys>(); Trace.WriteLine($"##### {propertyKey}"); } }
public static TEnum[] ToArray <TEnum>(this IPortableDeviceKeyCollection col) where TEnum : struct // enum { uint count = 0; col.GetCount(ref count); var result = new TEnum[count]; for (uint i = 0; i < count; i++) { PropertyKey key = new PropertyKey(); col.GetAt(i, ref key); result[i] = GetEnumFromAttrKey <TEnum>(key); } return(result); }
static Item() { // key collection with all used properties keyCollection = (IPortableDeviceKeyCollection) new PortableDeviceKeyCollection(); keyCollection.Add(ref WPD.OBJECT_CONTENT_TYPE); keyCollection.Add(ref WPD.OBJECT_NAME); keyCollection.Add(ref WPD.OBJECT_ORIGINAL_FILE_NAME); keyCollection.Add(ref WPD.OBJECT_HINT_LOCATION_DISPLAY_NAME); keyCollection.Add(ref WPD.OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID); keyCollection.Add(ref WPD.OBJECT_SIZE); keyCollection.Add(ref WPD.OBJECT_DATE_CREATED); keyCollection.Add(ref WPD.OBJECT_DATE_MODIFIED); keyCollection.Add(ref WPD.OBJECT_DATE_AUTHORED); keyCollection.Add(ref WPD.OBJECT_CAN_DELETE); keyCollection.Add(ref WPD.OBJECT_ISSYSTEM); keyCollection.Add(ref WPD.OBJECT_ISHIDDEN); keyCollection.Add(ref WPD.OBJECT_IS_DRM_PROTECTED); keyCollection.Add(ref WPD.OBJECT_PARENT_ID); keyCollection.Add(ref WPD.OBJECT_PERSISTENT_UNIQUE_ID); }
public virtual extern void GetIPortableDeviceKeyCollectionValue([In] ref PropertyKey key, [MarshalAs(UnmanagedType.Interface)] out IPortableDeviceKeyCollection ppValue);
public extern virtual void SetIPortableDeviceKeyCollectionValue([In] ref PropertyKey key, [In, MarshalAs(UnmanagedType.Interface)] IPortableDeviceKeyCollection pValue);
/// <summary> /// Update service /// </summary> protected override void Update() { IPortableDeviceKeyCollection keyCol = (IPortableDeviceKeyCollection) new PortableDeviceKeyCollection(); keyCol.Add(ref WPD.SignalStrength); keyCol.Add(ref WPD.TextMessages); keyCol.Add(ref WPD.NewPictures); keyCol.Add(ref WPD.MissedCalls); keyCol.Add(ref WPD.VoiceMail); keyCol.Add(ref WPD.NetworkName); keyCol.Add(ref WPD.NetworkType); keyCol.Add(ref WPD.Roaming); keyCol.Add(ref WPD.BatteryLife); keyCol.Add(ref WPD.ChargingState); keyCol.Add(ref WPD.StorageCapacity); keyCol.Add(ref WPD.StorageFreeSpace); keyCol.Add(ref WPD.InternetConnected); IPortableDeviceValues values = GetProperties(keyCol); using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.SignalStrength, out value.Value); this.SignalStrength = value; } using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.TextMessages, out value.Value); this.TextMessages = value; } using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.NewPictures, out value.Value); this.NewPictures = value; } using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.MissedCalls, out value.Value); this.MissedCalls = value; } using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.VoiceMail, out value.Value); this.VoiceMail = value; } using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.NetworkName, out value.Value); this.NetworkName = value; } using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.NetworkType, out value.Value); this.NetworkType = value; } using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.Roaming, out value.Value); this.Roaming = (Roaming)(byte)value; } using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.BatteryLife, out value.Value); this.BatteryLife = value; } using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.ChargingState, out value.Value); this.ChargingState = (ChargingState)(byte)value; } using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.StorageCapacity, out value.Value); this.StorageCapacity = value; } using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.StorageFreeSpace, out value.Value); this.StorageFreeSpace = value; } using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.InternetConnected, out value.Value); this.InternetConnected = value; } }
/// <summary> /// Update service /// </summary> protected override void Update() { IPortableDeviceKeyCollection keyCol = (IPortableDeviceKeyCollection) new PortableDeviceKeyCollection(); keyCol.Add(ref WPD.ParentId); keyCol.Add(ref WPD.Name); keyCol.Add(ref WPD.PUOID); keyCol.Add(ref WPD.ObjectFormat); keyCol.Add(ref WPD.ObjectSize); keyCol.Add(ref WPD.StorageID); keyCol.Add(ref WPD.LanguageLocale); keyCol.Add(ref WPD.ContentID); keyCol.Add(ref WPD.DefaultCAB); IPortableDeviceValues values = GetProperties(keyCol); using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.ParentId, out value.Value); this.ParentId = value; } using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.Name, out value.Value); this.Name = value; } using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.PUOID, out value.Value); this.PUOID = value; } using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.ObjectFormat, out value.Value); this.ObjectFormat = value; } using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.ObjectSize, out value.Value); this.ObjectSize = value; } using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.StorageID, out value.Value); this.StorageID = value; } using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.LanguageLocale, out value.Value); this.LanguageLocale = value; } using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.ContentID, out value.Value); this.ContentID = value; } using (PropVariantFacade value = new PropVariantFacade()) { values.GetValue(ref WPD.DefaultCAB, out value.Value); this.DefaultCAB = value; } }