Ejemplo n.º 1
0
 public void Disconnect()
 {
     if (!_isConnected)
     {
         return;
     }
     _device.Close();
     _isConnected = false;
 }
Ejemplo n.º 2
0
        public void Disconnect()
        {
            if (!_isConnected)
            {
                return;
            }

            PortableDeviceClass.Close();
            _isConnected = false;
        }
Ejemplo n.º 3
0
        public virtual void DisConnect()
        {
            if (!isConnected)
            {
                return;
            }

            device.Close();

            isConnected = false;
        }
        private void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (!string.IsNullOrEmpty(adviseCookie))
                {
                    PortableDeviceClass.Unadvise(adviseCookie);
                }

                if (IsConnected)
                {
                    PortableDeviceClass.Close();
                }
            }

            PortableDeviceClass = null;
        }
Ejemplo n.º 5
0
        public IEnumerable <TransFileObject> GetAllFiles(string ext, MainWindowData mainWnd)
        {
            if (srcDevId == null || srcDirObjId == null)
            {
                return(null);
            }

            var files = new List <TransFileObject>();
            PortableDeviceClass device = new PortableDeviceClass();

            try {
                IPortableDeviceContent    content;
                IPortableDeviceProperties properties;
                var clientInfo = (IPortableDeviceValues) new PortableDeviceValuesClass();
                device.Open(srcDevId, clientInfo);
                device.Content(out content);
                content.Properties(out properties);

                // コピー対象の拡張子と一致するファイルを抽出
                var patExt   = new Regex("." + ext, RegexOptions.Compiled);
                var srcfiles = GetObjects(srcDirObjId, content, TransFileObject.ObjectKind.FILE);
                foreach (var srcfile in srcfiles)
                {
                    if (patExt.IsMatch(srcfile.fileName))
                    {
                        files.Add(new TransFileObject(srcfile.fileName, srcfile.objId, srcfile.updateTime, srcfile.kind));
                    }
                }
            }
            catch (Exception e) {
                mainWnd.DispInfo = string.Format("エラーが発生しました\n{0}", e.Message);
            }
            finally {
                device.Close();
            }
            return(files);
        }
Ejemplo n.º 6
0
        public string[] ExecCopyFile(string destDirpath, IEnumerable <TransFileObject> copyFiles, MainWindowData mainWnd)
        {
            if (srcDevId == null || srcDirObjId == null)
            {
                return(null);
            }

            var filedfile = new List <string>();
            int cnt       = 0;
            int total     = copyFiles.Count();
            PortableDeviceClass device = new PortableDeviceClass();

            IPortableDeviceContent content;
            var clientInfo = (IPortableDeviceValues) new PortableDeviceValuesClass();

            device.Open(srcDevId, clientInfo);
            device.Content(out content);

            foreach (var file in copyFiles)
            {
                try {
                    DownloadFile(file, destDirpath + file.fileName, content);
                    mainWnd.DispInfo += String.Format("成功:{0}\n", file.fileName);
                    cnt++;
                }
                catch (Exception e) {
                    filedfile.Add(file.fileName);
                    mainWnd.DispInfo += String.Format("失敗:{0} [{1}]\n", e.Message, file.fileName);
                }

                mainWnd.Progress = (100 * cnt) / total;
            }

            device.Close();
            return(filedfile.ToArray());
        }
Ejemplo n.º 7
0
        public bool FindSrcDir(string volume, string dirpath, out string retryMsg, MainWindowData mainWnd)
        {
            const string defretryMsg = "機器を接続してOKを選択してください";

            retryMsg = defretryMsg;

            // 接続中のデバイス数を取得
            uint count = 0;

            deviceManager.RefreshDeviceList();
            deviceManager.GetDevices(null, ref count);
            if (count == 0)
            {
                retryMsg = defretryMsg;
                return(false);
            }

            // コピー元デバイス、フォルダの存在チェック
            string[] deviceIds            = new string[count];
            PortableDeviceClass[] devices = new PortableDeviceClass[count];
            deviceManager.GetDevices(deviceIds, ref count);

            var  clientInfo   = (IPortableDeviceValues) new PortableDeviceValuesClass();
            bool existsSrcDir = true;

            foreach (var deviceId in deviceIds)
            {
                PortableDeviceClass device = new PortableDeviceClass();
                try {
                    // デバイス情報の取得
                    IPortableDeviceContent    content;
                    IPortableDeviceProperties properties;
                    device.Open(deviceId, clientInfo);
                    device.Content(out content);
                    content.Properties(out properties);

                    IPortableDeviceValues propertyValues;
                    properties.GetValues("DEVICE", null, out propertyValues);

                    var    property = new _tagpropertykey();
                    string devicename;
                    property.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C);
                    property.pid   = 4;
                    propertyValues.GetStringValue(property, out devicename);
                    //Console.WriteLine(devicename);

                    // 対象デバイスで無ければスキップ
                    if (devicename != volume)
                    {
                        continue;
                    }

                    // コピー元デバイスのアクセス許可状態のチェック
                    var rootObjs = GetObjects("DEVICE", content); // ルートオブジェクトが見えるか
                    if (rootObjs.Count() <= 0)
                    {
                        retryMsg = "対象機器へのアクセスが許可されていません\n" +
                                   "対象機器でMTP転送を有効後にOKを選択してください";
                        return(false);
                    }

                    // コピー元フォルダのデバイスIDを取得
                    existsSrcDir = true;
                    string curDirId = "DEVICE";
                    foreach (string searchdir in dirpath.TrimStart('\\').TrimEnd('\\').Split('\\'))
                    {
                        //Console.WriteLine(searchdir);
                        bool existCurDir = false;
                        var  dirObjs     = GetObjects(curDirId, content, TransFileObject.ObjectKind.DIR);

                        foreach (var dirobj in dirObjs)
                        {
                            if (dirobj.fileName == searchdir)
                            {
                                existCurDir = true;
                                curDirId    = dirobj.objId;
                                break;
                            }
                        }
                        if (!existCurDir)
                        {
                            existsSrcDir = false;
                            break;
                        }
                    }
                    if (existsSrcDir)
                    {
                        srcDirObjId = curDirId;
                        srcDevId    = deviceId;
                        retryMsg    = "";
                        break;
                    }
                }
                catch (Exception e) {
                    mainWnd.DispInfo = string.Format("コピー元の検出失敗\n{0}", e.Message);
                    existsSrcDir     = false;
                }
                finally {
                    device.Close();
                }
            }

            return(existsSrcDir);
        }