public MainWindow() { InitializeComponent(); vdata = new MainWindowData(); DataContext = vdata; LoadSetting(); }
public IEnumerable <TransFileObject> GetAllFiles(string ext, MainWindowData mainWnd) { if (srcdir == null) { return(null); } var ret = new List <TransFileObject>(); foreach (var filename in Directory.GetFiles(srcdir, ext, SearchOption.AllDirectories)) { // MSCモードでは更新日時は使わないので、ひとまず現在時刻にする ret.Add(new TransFileObject(Path.GetFileName(filename), null, DateTime.Now, TransFileObject.ObjectKind.FILE)); } return(ret); }
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); }
public TransFiles(MainWindowData vdata) { this.vdata = vdata; }
public string[] ExecCopyFile(string destDirpath, IEnumerable <TransFileObject> copyFiles, MainWindowData mainWnd) { if (srcdir == null) { return(null); } var filedfile = new List <string>(); int cnt = 0; int total = copyFiles.Count(); foreach (var file in copyFiles) { try { File.Copy(srcdir + file.fileName, destDirpath + file.fileName, false); 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; } return(filedfile.ToArray()); }
public bool FindSrcDir(string volume, string srcDirpath, out string retryMsg, MainWindowData mainWnd) { bool ret = false; retryMsg = "メディアを挿入してOKを選択してください"; // ボリューム名が一致するドライブのパスを取得 DriveInfo[] drives = DriveInfo.GetDrives(); foreach (DriveInfo drive in drives) { if (drive.IsReady && drive.VolumeLabel == volume) { string temp = drive.Name.TrimEnd('\\') + srcDirpath; if (Directory.Exists(temp)) { ret = true; srcdir = temp; break; } } } return(ret); }
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); }
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()); }