@Override public List<FileItem> getTDDownloadList(int complete) { List<FileItem> fileItems = new ArrayList<FileItem>(); int pageIndex = 0; int pageCapacity = 100; List<FileItem> list = getTasklist(complete, pageIndex, pageCapacity); if (list != null && list.size() > 0) { fileItems.addAll(list); } while (list != null && list.size() >= 100) { pageIndex++; list = getTasklist(complete, pageIndex, pageCapacity); if (list != null && list.size() > 0) { fileItems.addAll(list); } } if (complete == GetTaskListAPI.TYPE_TASK_COMPLETED) { // 取路由器文件cid for (FileItem item : fileItems) { if (!TextUtils.isEmpty(item.filePath)) { String smbPath = SmbUtil.getSmbPathFromPlayUrl(item.filePath); try { SmbFile smbFile = new SmbFile(smbPath); BufferedInputStream bis = new BufferedInputStream(new SmbFileInputStream(smbFile)); String cid = CidUtil.queryCid(bis, smbFile.length()); if (!TextUtils.isEmpty(cid)) { item.cid = cid; } else { item.cid = ""; } } catch (SmbException e) { } catch (MalformedURLException e) { } catch (UnknownHostException e) { } } } } else { for (int i = fileItems.size() - 1; i >= 0; i--) { FileItem item = fileItems.get(i); if (item.fileStatus != Constants.TDTASK_STATUS_DOWNLOADING) { fileItems.remove(item); } } } return fileItems; }
public static List<FileItem> getChildFiles(String smbPath, Context context) { try { List<FileItem> list = new ArrayList<FileItem>(); SmbFile smbRootFile = new SmbFile(smbPath); if (!smbRootFile.exists()) { return null; } SmbFile[] fileList = smbRootFile.listFiles(); if (fileList == null || fileList.length == 0) { return null; } FileExploreHistoryManager fileExploreHistoryManager = new FileExploreHistoryManager(context); DeviceItem deviceItem = new DeviceItem(); deviceItem.setType(DeviceItem.DeviceType.XL_ROUTER_TDDOWNLOAD); for (SmbFile smbFile : fileList) { FileItem item = new FileItem(); String fileName = smbFile.getName(); String filePath = smbFile.getCanonicalPath(); item.filePath = filePath; item.lastModifyTime = smbFile.getLastModified(); item.canRead = smbFile.canRead(); item.canWrite = smbFile.canWrite(); try { BufferedInputStream bis = new BufferedInputStream(new SmbFileInputStream(smbFile)); String cid = CidUtil.queryCid(bis, smbFile.length()); if (!TextUtils.isEmpty(cid)) { item.cid = cid; } else { item.cid = ""; } } catch (SmbException e) { } catch (MalformedURLException e) { } catch (UnknownHostException e) { } if (smbFile.isDirectory()) { fileName = fileName.substring(0, fileName.length() - 1); item.fileName = fileName; item.category = FileCategory.DIR; item.fileSize = 0; item.isNew = fileExploreHistoryManager.isFileNew(item, deviceItem); list.add(item); } else if (smbFile.isFile()) { item.category = FileCategoryHelper.getFileCategoryByName(fileName); item.fileSize = smbFile.getContentLength(); item.fileName = fileName; if (item.category == FileCategory.VIDEO) { item.isNew = fileExploreHistoryManager.isFileNew(item, deviceItem); list.add(item); } } } return list; } catch (MalformedURLException e) { AppConfig.logRemote( "[[XlrounterDownloadMgr]] createFileItem MalformedURLException:" + e.getMessage()); } catch (SmbException e) { AppConfig.logRemote("[[XlrounterDownloadMgr]] createFileItem SmbException:" + e.getMessage()); } return null; }