/// <summary> /// 搜索 /// </summary> /// <param name="node">搜索根节点,必须是文件夹类型 即IsFile为false</param> /// <param name="args">搜索条件</param> /// <param name="async">异步通知</param> protected virtual void DoSearch(FileBrowingNode node, IEnumerable <FilterArgs> args, CancellationTokenSource cancellationTokenSource, FileBrowingIAsyncTaskProgress async) { if (cancellationTokenSource.IsCancellationRequested) { return; } if (null == node.ChildNodes) {//查找子节点 node.ChildNodes = DoGetChildNodes(node); if (null == node.ChildNodes) { return; } } //先搜索文件,再搜索文件夹 foreach (var file in node.ChildNodes.Where(f => f.IsFile)) { if (cancellationTokenSource.IsCancellationRequested) { return; } if (Filter(file, args)) {//满足搜索要求 async?.OnSearchFileNodeHande(file); } } foreach (var dir in node.ChildNodes.Where(f => !f.IsFile)) { if (cancellationTokenSource.IsCancellationRequested) { return; } DoSearch(dir, args, cancellationTokenSource, async); } }
/// <summary> /// 下载 /// </summary> /// <param name="node">下载节点 可以是文件或者文件夹</param> /// <param name="savePath">保存路径</param> /// <param name="persistRelativePath">是否保留相对路径</param> /// <param name="async">异步通知</param> public async Task <bool> Download(FileBrowingNode node, string savePath, bool persistRelativePath, CancellationTokenSource cancellationTokenSource, FileBrowingIAsyncTaskProgress async) { return(await Task.Run(() => { DoDownload(node, savePath, persistRelativePath, cancellationTokenSource, async); return true; })); }
/// <summary> /// 搜索 /// </summary> /// <param name="node">搜索根节点,必须是文件夹类型 即IsFile为false</param> /// <param name="args">搜索条件</param> /// <param name="cancellationToken">异步取消</param> /// <param name="async">异步通知</param> public async Task <bool> Search(FileBrowingNode node, IEnumerable <FilterArgs> args, CancellationTokenSource cancellationTokenSource, FileBrowingIAsyncTaskProgress async) { return(await Task.Run(() => { if (null == node || node.IsFile) { return false; } if (null == args || !args.Any()) { return false; } BeginSearch(node, args, cancellationTokenSource, async); return true; }, cancellationTokenSource.Token)); }
/// <summary> /// 开始搜索 /// </summary> /// <param name="node">搜索根节点,必须是文件夹类型 即IsFile为false</param> /// <param name="args">搜索条件</param> /// <param name="async">异步通知</param> protected virtual void BeginSearch(FileBrowingNode node, IEnumerable <FilterArgs> args, CancellationTokenSource cancellationTokenSource, FileBrowingIAsyncTaskProgress async) { if (cancellationTokenSource.IsCancellationRequested) { return; } DoSearch(node, args, cancellationTokenSource, async); }
/// <summary> /// 下载 /// </summary> /// <param name="node">下载节点 可以是文件或者文件夹</param> /// <param name="savePath">保存路径</param> /// <param name="persistRelativePath">是否保留相对路径</param> /// <param name="async">异步通知</param> protected virtual void DoDownload(FileBrowingNode node, string savePath, bool persistRelativePath, CancellationTokenSource cancellationTokenSource, FileBrowingIAsyncTaskProgress async) { if (cancellationTokenSource.IsCancellationRequested) { return; } if (null == node) { return; } if (node.NodeType == FileBrowingNodeType.File) { try { if (node.FileSize == 0) { return; } var filefullname = DownLoadFile(node, savePath, persistRelativePath, cancellationTokenSource, async); if (FileHelper.IsValid(filefullname)) { ////修改文件时间 //File.SetCreationTime(filefullname, GetValidDateTime(node.CreateTime)); //File.SetLastWriteTime(filefullname, GetValidDateTime(node.LastWriteTime)); //File.SetLastAccessTime(filefullname, GetValidDateTime(node.LastAccessTime)); async.OnExportFileNodeSuccessHandle(node, true, filefullname); } else { async.OnExportFileNodeSuccessHandle(node, false); } } catch (Exception ex) { LoggerManagerSingle.Instance.Error(ex, "文件导出失败!"); async.OnExportFileNodeSuccessHandle(node, false); } } else { var cSavePath = string.Empty; if (persistRelativePath) { cSavePath = savePath.Replace('/', '\\'); } else { cSavePath = Path.Combine(savePath, node.Name).Replace('/', '\\'); } try { FileHelper.CreateDirectory(cSavePath); foreach (var cnode in DoGetChildNodes(node)) { if (cancellationTokenSource.IsCancellationRequested) { return; } DoDownload(cnode, cSavePath, persistRelativePath, cancellationTokenSource, async); } } catch (Exception ex) { LoggerManagerSingle.Instance.Error(ex, "文件夹导出失败!"); async.OnExportFileNodeSuccessHandle(node, false); } } return; }
/// <summary> /// 下载文件 /// </summary> /// <param name="fileNode"></param> /// <param name="savePath"></param> /// <param name="persistRelativePath"></param> /// <param name="cancellationTokenSource"></param> /// <param name="async"></param> /// <returns>文件本地保存路径</returns> protected abstract string DownLoadFile(FileBrowingNode fileNode, string savePath, bool persistRelativePath, CancellationTokenSource cancellationTokenSource, FileBrowingIAsyncTaskProgress async);
protected override string DownLoadFile(FileBrowingNode fileNode, string savePath, bool persistRelativePath, CancellationTokenSource cancellationTokenSource, FileBrowingIAsyncTaskProgress async) { var mPnode = fileNode as AndroidMirrorFileBrowingNode; return(FileServiceX.ExportFileX(mPnode.FNode, savePath, persistRelativePath, isThrowEx: true)); }
protected override string DownLoadFile(FileBrowingNode fileNode, string savePath, bool persistRelativePath, CancellationTokenSource cancellationTokenSource, FileBrowingIAsyncTaskProgress async) { var ifileNode = fileNode as IOSMirrorFileBrowingNode; try { var tSavePath = string.Empty; if (persistRelativePath) { tSavePath = Path.Combine(savePath, ifileNode.SourcePath.Replace('/', '\\').TrimStart("\\").TrimStart(DataSourcePath).TrimStart("\\")); } else { tSavePath = Path.Combine(savePath, ifileNode.Name).Replace('/', '\\'); } FileHelper.CreateDirectory(FileHelper.GetFilePath(tSavePath)); File.Copy(ifileNode.SourcePath, tSavePath); return(tSavePath); } catch { } return(null); }
/// <summary> /// 开始搜索 /// </summary> /// <param name="node">搜索根节点,必须是文件夹类型 即IsFile为false</param> /// <param name="args">搜索条件</param> /// <param name="async">异步通知</param> protected override void BeginSearch(FileBrowingNode node, IEnumerable <FilterArgs> args, CancellationTokenSource cancellationTokenSource, FileBrowingIAsyncTaskProgress async) { var stateArg = args.FirstOrDefault(a => a is FilterByEnumStateArgs); if (null != stateArg && (stateArg as FilterByEnumStateArgs).State != EnumDataState.Normal) {//如果要搜索删除状态的文件,直接返回。因为IOS镜像文件浏览不会有删除状态的文件。 //TODO:通知搜索结束 return; } var dateArg = args.FirstOrDefault(a => a is FilterByDateRangeArgs); if (null != stateArg) {//如果要搜索指定创建时间范围的文件,直接返回。因为IOS镜像文件浏览无法获取文件创建时间。 //TODO:通知搜索结束 return; } base.BeginSearch(node, args, cancellationTokenSource, async); }
protected override string DownLoadFile(FileBrowingNode fileNode, string savePath, bool persistRelativePath, CancellationTokenSource cancellationTokenSource, FileBrowingIAsyncTaskProgress async) { FileHelper.CreateDirectory(savePath); var ifileNode = fileNode as IOSDeviceFileBrowingNode; try { var tSavePath = string.Empty; if (persistRelativePath) { tSavePath = Path.Combine(savePath, ifileNode.SourcePath).Replace('/', '\\'); } else { tSavePath = Path.Combine(savePath, ifileNode.Name).Replace('/', '\\'); } if (FileHelper.IsValid(tSavePath)) { return(tSavePath); } FileHelper.CreateDirectory(FileHelper.GetFilePath(tSavePath)); // 1,设置服务 uint result = IOSDeviceCoreDll.SetIphoneFileService(IPhone.ID, IPhone.IsRoot); // 2,下载 result = IOSDeviceCoreDll.CopyOneIosFile(IPhone.ID, ifileNode.SourcePath, tSavePath); return(tSavePath); } catch { } finally { // 3,关闭服务 IOSDeviceCoreDll.CloseIphoneFileService(IPhone.ID); } return(null); }
protected override string DownLoadFile(FileBrowingNode fileNode, string savePath, bool persistRelativePath, CancellationTokenSource cancellationTokenSource, FileBrowingIAsyncTaskProgress async) { return(AndroidHelper.Instance.CopyFile(AndroidPhone, (fileNode as AndroidDeviceFileBrowingNode).SourcePath, savePath, null, persistRelativePath)); }