public static FileItem createFileItem(String smbPath) { try { SmbFile smbFile = new SmbFile(smbPath); if (!smbFile.exists()) { return null; } FileItem item = new FileItem(); String fileName = smbFile.getName(); String filePath = smbFile.getCanonicalPath(); if (smbFile.isDirectory()) { fileName = fileName.substring(0, fileName.length() - 1); item.category = FileCategory.DIR; item.fileSize = 0; } else if (smbFile.isFile()) { item.category = FileCategoryHelper.getFileCategoryByName(fileName); item.fileSize = smbFile.getContentLength(); } item.fileName = fileName; item.filePath = filePath; item.lastModifyTime = smbFile.getLastModified(); item.canRead = smbFile.canRead(); item.canWrite = smbFile.canWrite(); item.cid = ""; return item; } catch (MalformedURLException e) { AppConfig.logRemote( "[[XlrounterDownloadMgr]] createFileItem MalformedURLException:" + e.getMessage()); } catch (SmbException e) { AppConfig.logRemote("[[XlrounterDownloadMgr]] createFileItem SmbException:" + e.getMessage()); } return null; }
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; }