示例#1
0
        public void OnEvent(IPortableDeviceValues pEventParameters)
        {
            pEventParameters.GetStringValue(WpdHelper.pKey.WPD_EVENT_PARAMETER_PNP_DEVICE_ID, out deviceId);
            pEventParameters.GetStringValue(WpdHelper.pKey.WPD_EVENT_PARAMETER_EVENT_ID, out eventId);

            if (eventId.Contains(WpdHelper.pGuid.WPD_EVENT_DEVICE_RESET.ToString().ToUpper()) ||
                eventId.Contains(WpdHelper.pGuid.WPD_EVENT_DEVICE_REMOVED.ToString().ToUpper()))
            {
                if (WpdHelper.UnexpectedClosed != null)
                {
                    WpdHelper.UnexpectedClosed();
                }
            }
            else
            {
                /*
                 * if (eventId.Contains(WpdHelper.pGuid.WPD_EVENT_OBJECT_ADDED.ToString().ToUpper()))
                 * {
                 *  eventId = "1";
                 * }
                 * else if (eventId.Contains(WpdHelper.pGuid.WPD_EVENT_OBJECT_REMOVED.ToString().ToUpper()))
                 * {
                 *  eventId = "2";
                 * }
                 * else if (eventId.Contains(WpdHelper.pGuid.WPD_EVENT_OBJECT_UPDATED.ToString().ToUpper()))
                 * {
                 *  eventId = "3";
                 * }
                 * */
            }
        }
示例#2
0
        public string Demo_DirAndWriteFile(string fromFile, string toPath)
        {
            string info = "";

            WpdHelper wpd      = new WpdHelper();
            string    deviceId = wpd.GetDeviceId();

            if (wpd.Connect(deviceId))
            {
                List <string> storageIds  = wpd.GetChildrenObjectIds("DEVICE");
                string        findObjName = "";
                string        findObjId   = "";
                string        objName     = "";

                foreach (string storageId in storageIds)
                {
                    objName = wpd.GetObjectName(storageId);
                    info   += string.Format("storage name:{0}\r\n", objName);

                    List <string> objectIds = wpd.GetChildrenObjectIds(storageId);

                    foreach (string objId in objectIds)
                    {
                        objName = wpd.GetObjectFileName(objId);
                        info   += string.Format("object name:{0}\r\n", objName);

                        if (fromFile == objName)
                        {
                            findObjId   = objId;
                            findObjName = objName;
                        }
                    }
                }

                if (toPath == "root" || toPath == "/")
                {
                    findObjId   = storageIds[0];
                    findObjName = wpd.GetObjectName(storageIds[0]);
                }

                if (findObjId != "")
                {
                    info += string.Format("dest write name:{0}\r\n", findObjName);
                }

                bool isOk = wpd.WriteFile(fromFile, toPath);
                info += (isOk ? "write success\r\n" : "write failed\r\n");
            }
            wpd.Disconnect();

            return(info);
        }
示例#3
0
        public string Demo_DeleteFile(string fileName)
        {
            string    info     = "";
            WpdHelper wpd      = new WpdHelper();
            string    deviceId = wpd.GetDeviceId();

            if (wpd.Connect(deviceId))
            {
                bool isOk = wpd.DeleteFile(fileName);
                info += (isOk ? "delete success\r\n" : "delete failed\r\n");
            }
            wpd.Disconnect();

            return(info);
        }
示例#4
0
        public string Demo_getDeviceInfo()
        {
            string info = "";

            //string deviceId_KT50_B2 = "\\\\?\\usb#vid_0e8d&pid_2008#0123456789abcdef#{6ac27878-a6fa-4155-ba85-f98f491d4f33}";
            //string deviceId_HUAWEI_P10 = "\\\\?\\usb#vid_12d1&pid_107e&mi_00#6&10069075&0&0000#{6ac27878-a6fa-4155-ba85-f98f491d4f33}";

            WpdHelper wpd      = new WpdHelper();
            string    deviceId = wpd.GetDeviceId();

            if (wpd.Connect(deviceId))
            {
                List <string> storagesIds     = wpd.GetChildrenObjectIds("DEVICE");
                ulong         freeSpace       = 0;
                ulong         storageCapacity = 0;

                //设备支持WIFI则包含网络这个假设备,也是无法获取到容量的
                foreach (string storageId in storagesIds)
                {
                    if (storageId == "s10001")
                    {
                        wpd.GetStorageCapacityAnFreeSpace(storageId, out freeSpace, out storageCapacity);
                        break;
                    }
                }

                info += string.Format("设备名称:{0}\r\n", wpd.GetDeviceName());
                info += string.Format("设备型号:{0}\r\n", wpd.GetModel());
                info += string.Format("设备类型:{0}\r\n", wpd.GetDeviceType());
                info += string.Format("设备厂商:{0}\r\n", wpd.GetManufacturer());
                info += string.Format("固件版本:{0}\r\n", wpd.GetFirmwareVersion());
                info += string.Format("存储空间:可用{0}GB / 总共{1}GB\r\n",
                                      Math.Round((double)freeSpace / (1000 * 1000 * 1000), 3),
                                      Math.Round((double)storageCapacity / (1000 * 1000 * 1000), 3));
            }
            wpd.Disconnect();

            return(info);
        }