private List <FileBrowingNode> ConvertFileNode(List <LSFile> listFiles, FileBrowingNode parentNode) { if (listFiles.IsInvalid()) { return(new List <FileBrowingNode>()); } List <FileBrowingNode> res = new List <FileBrowingNode>(); foreach (var file in listFiles.Where(f => f.Type == "Directory" || f.Type == "File")) { res.Add(new AndroidDeviceFileBrowingNode() { Name = file.Name, Parent = parentNode, FileSize = (UInt64)file.Size, NodeType = GetNodeType(file.Type), CreateTime = file.CreateDate, LastAccessTime = file.LastAccessDate, LastWriteTime = file.LastWriteData, SourcePath = file.FullPath, }); } return(res); }
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="parentNode"></param> /// <returns></returns> public async Task <List <FileBrowingNode> > GetChildNodes(FileBrowingNode parentNode) { return(await Task.Run(() => { if (null == parentNode.ChildNodes) { var list = DoGetChildNodes(parentNode); list.Sort((l, r) => { if (!l.IsFile && r.IsFile) { return -1; } else if (l.IsFile && !r.IsFile) { return 1; } return string.Compare(l.Name, r.Name); }); parentNode.ChildNodes = list; } return parentNode.ChildNodes; })); }
private List <FileBrowingNode> GetIOSFileSystem(string folderPath, FileBrowingNode parentNode) { List <FileBrowingNode> list = new List <FileBrowingNode>(); try { // 1,设置服务 uint result = IOSDeviceCoreDll.SetIphoneFileService(IPhone.ID, IPhone.IsRoot); if (0 != result) { return(list); } IntPtr allFileInfosInDir = IntPtr.Zero; result = IOSDeviceCoreDll.GetIphoneALLFileInfosInDir(IPhone.ID, folderPath, ref allFileInfosInDir); if (result != 0 || allFileInfosInDir == IntPtr.Zero) { return(list); } //它返回的当前文件下的第一级文件系统,其中可能包括文件和文件夹。 IosFileSystemList iosFileSystemlist = allFileInfosInDir.ToStruct <IosFileSystemList>(); IntPtr fileSysNodes = iosFileSystemlist.FileSystemNodes; IosFileSystem iosFileSystem; //读取每一个文件系统实体。根据FileSystemList大小,一次解析一个文件系统,根据Type判断是文件还是文件夹。 for (int i = 0; i < iosFileSystemlist.Length && fileSysNodes != IntPtr.Zero; i++) { iosFileSystem = fileSysNodes.ToStruct <IosFileSystem>(); string name = iosFileSystem.Name.ToAnsiString(); //掉过掉Unix特有的隐藏文件“.”和"..",他们两个的作用是前进和后退。 if (name != "." && name != "..") { list.Add(new IOSDeviceFileBrowingNode() { Name = name, SourcePath = string.Format("{0}/{1}", folderPath.TrimStart('/'), name), FileSize = iosFileSystem.Size, CreateTime = DynamicConvert.ToSafeDateTime(iosFileSystem.CreateTime), NodeType = iosFileSystem.Type == 1 ? FileBrowingNodeType.Directory : FileBrowingNodeType.File, Parent = parentNode, }); } fileSysNodes = fileSysNodes.Increment <IosFileSystem>(); } } catch { } finally { // 3,关闭服务 IOSDeviceCoreDll.CloseIphoneFileService(IPhone.ID); } return(list); }
/// <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> 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; })); }
internal void OnSearchFileNodeHande(FileBrowingNode node) { try { SearchFileNodeHandle?.Invoke(node); } catch { } }
internal void OnExportFileNodeSuccessHandle(FileBrowingNode node, bool isSuccess, string filesavepath = null) { try { ExportFileNodeHandle?.Invoke(node, isSuccess, filesavepath); } catch { } }
public AndroidDeviceFileBrowsingService(Device device) { AndroidPhone = device; RootNode = new AndroidDeviceFileBrowingNode() { Name = device.Name, NodeType = FileBrowingNodeType.Root }; }
protected virtual bool Filter(FileBrowingNode filenode, FilterByEnumStateArgs arg) { if (arg.State == Domains.EnumDataState.Normal) {//搜索正常的 return(!filenode.IsDelete); } else {//搜索删除的 return(filenode.IsDelete); } }
public IOSDeviceFileBrowsingService(Device device) { IPhone = device; RootNode = new IOSDeviceFileBrowingNode() { Name = device.Name, NodeType = FileBrowingNodeType.Directory, SourcePath = "/" }; }
/// <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; } base.BeginSearch(node, args, cancellationTokenSource, async); }
/// <summary> /// 判断文件节点是否符合搜索要求 /// </summary> /// <param name="filenode">文件节点 即IsFile为true</param> /// <param name="args">搜索条件</param> /// <returns>符合返回true 不符合返回false</returns> protected virtual bool Filter(FileBrowingNode filenode, IEnumerable <FilterArgs> args) { foreach (var arg in args) { switch (arg) { case FilterByDateRangeArgs dateRangeArg: //日期查询 if (!Filter(filenode, dateRangeArg)) { return(false); } break; case FilterByStringContainsArgs keywordArg: //字符串查询 if (!Filter(filenode, keywordArg)) { return(false); } break; case FilterByRegexArgs regexArg: //正则查询 if (!Filter(filenode, regexArg)) { return(false); } break; case FilterByEnumStateArgs stateArg: //文件状态查询 if (!Filter(filenode, stateArg)) { return(false); } break; case FilterByEnumFileTypeArgs filetypeArg: //文件类型查询 if (!Filter(filenode, filetypeArg)) { return(false); } break; default: break; } } return(true); }
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); }
/// <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)); }
protected virtual bool Filter(FileBrowingNode filenode, FilterByDateRangeArgs arg) { if (null == filenode.CreateTime) { return(false); } if (null != arg.StartTime && arg.StartTime > filenode.CreateTime) { return(false); } if (null != arg.EndTime && arg.EndTime < filenode.CreateTime.Value.Date) { return(false); } return(true); }
protected override List <FileBrowingNode> DoGetChildNodes(FileBrowingNode parentNode) { List <FileBrowingNode> list = new List <FileBrowingNode>(); if (null == parentNode || parentNode.NodeType == FileBrowingNodeType.File) { return(list); } var path = (parentNode as IOSMirrorFileBrowingNode).SourcePath; var parentPathInfo = new DirectoryInfo(path); if (parentPathInfo.Exists) { foreach (var di in parentPathInfo.GetDirectories()) { list.Add(new IOSMirrorFileBrowingNode() { Name = di.Name, NodeType = FileBrowingNodeType.Directory, SourcePath = di.FullName, Parent = parentNode, }); } foreach (var fi in parentPathInfo.GetFiles()) { list.Add(new IOSMirrorFileBrowingNode() { Name = fi.Name, NodeType = FileBrowingNodeType.File, SourcePath = fi.FullName, FileSize = (UInt64)fi.Length, Parent = parentNode, }); } } return(list); }
/// <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); } }
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)); }
/// <summary> /// 获取子节点 /// </summary> /// <param name="parentNode"></param> /// <returns></returns> protected abstract List <FileBrowingNode> DoGetChildNodes(FileBrowingNode parentNode);
protected override List <FileBrowingNode> DoGetChildNodes(FileBrowingNode parentNode) { return(DoGetChildNodes(parentNode as IOSDeviceFileBrowingNode)); }
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 virtual bool Filter(FileBrowingNode filenode, FilterByEnumFileTypeArgs arg) { return(filenode.FileType == arg.FileType); }
protected override List <FileBrowingNode> DoGetChildNodes(FileBrowingNode parentNode) { if (parentNode.NodeType == FileBrowingNodeType.Root) {//根节点,获取分区列表 List <FileBrowingNode> list = new List <FileBrowingNode>(); foreach (var part in FileServiceX.Device.Parts) { list.Add(new AndroidMirrorFileBrowingNode() { Name = part.VolName.IsValid() ? string.Format("{0}-{1}", part.Name, part.VolName) : part.Name, NodeType = FileBrowingNodeType.Partition, Part = part, Parent = parentNode, }); } return(list); } else if (parentNode.NodeType == FileBrowingNodeType.Partition) {//分区,扫描分区 var mPnode = parentNode as AndroidMirrorFileBrowingNode; if (null == mPnode.ChildNodes) { mPnode.ChildNodes = new List <FileBrowingNode>(); foreach (var node in FileServiceX.GetFileSystemByDir(mPnode.Part)) { mPnode.ChildNodes.Add(new AndroidMirrorFileBrowingNode() { Name = node.FileName, FileSize = node.Size, NodeType = node.IsFolder ? FileBrowingNodeType.Directory : FileBrowingNodeType.File, NodeState = node.IsDelete ? EnumDataState.Deleted : EnumDataState.Normal, CreateTime = BaseTypeExtension.ToSafeDateTime(node.Source.CreateTime), LastWriteTime = BaseTypeExtension.ToSafeDateTime(node.Source.ModifyTime), LastAccessTime = BaseTypeExtension.ToSafeDateTime(node.Source.LastAccessTime), Parent = parentNode, Part = mPnode.Part, FNode = node, }); } } return(mPnode.ChildNodes); } else if (parentNode.NodeType == FileBrowingNodeType.Directory) {//文件夹 扫描文件节点 var mPnode = parentNode as AndroidMirrorFileBrowingNode; if (null == mPnode.ChildNodes) { mPnode.ChildNodes = new List <FileBrowingNode>(); foreach (var node in FileServiceX.GetFileSystemByDir(mPnode.FNode)) { mPnode.ChildNodes.Add(new AndroidMirrorFileBrowingNode() { Name = node.FileName, FileSize = node.Size, NodeType = node.IsFolder ? FileBrowingNodeType.Directory : FileBrowingNodeType.File, CreateTime = BaseTypeExtension.ToSafeDateTime(node.Source.CreateTime), LastWriteTime = BaseTypeExtension.ToSafeDateTime(node.Source.ModifyTime), LastAccessTime = BaseTypeExtension.ToSafeDateTime(node.Source.LastAccessTime), Parent = parentNode, Part = mPnode.Part, FNode = node, }); } } return(mPnode.ChildNodes); } else { return(null); } }
protected virtual bool Filter(FileBrowingNode filenode, FilterByRegexArgs arg) { return(arg.Regex.IsMatch(filenode.Name)); }
protected virtual bool Filter(FileBrowingNode filenode, FilterByStringContainsArgs arg) { return(filenode.Name.Contains(arg.PatternText)); }
/// <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);