|
@@ -28,6 +28,25 @@ public class PseudoCIFSDiskDriver implements DiskInterface {
|
|
|
|
|
|
private TreeConnection SMBTree;
|
|
|
|
|
|
+ private static class FileNode {
|
|
|
+ public String name;
|
|
|
+ public int type;
|
|
|
+ public int parent;
|
|
|
+
|
|
|
+ public FileNode(String name, int type, int parent){
|
|
|
+ this.name = name;
|
|
|
+ this.type = type;
|
|
|
+ this.parent = parent;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private FileNode[] filesystem = new FileNode[]{
|
|
|
+ new FileNode("/", FileAttribute.Directory, 0),
|
|
|
+ new FileNode("/testDir", FileAttribute.Directory, "/".hashCode()),
|
|
|
+ new FileNode("/testDir2", FileAttribute.Directory, "/".hashCode()),
|
|
|
+ new FileNode("/muhahaha.txt", 0, "/".hashCode())
|
|
|
+ };
|
|
|
+
|
|
|
private static class PseudoNetworkFile extends NetworkFile {
|
|
|
public PseudoNetworkFile(String name){
|
|
|
super(name);
|
|
@@ -98,25 +117,33 @@ public class PseudoCIFSDiskDriver implements DiskInterface {
|
|
|
|
|
|
@Override
|
|
|
public int fileExists(SrvSession srvSession, TreeConnection treeConnection, String s) {
|
|
|
-
|
|
|
DeviceContext ctx = treeConnection.getContext();
|
|
|
String filename = FileName.buildPath(ctx.getDeviceName(), s, null, File.separatorChar);
|
|
|
|
|
|
- File chkFile = new File(filename);
|
|
|
+ FileNode fileNode = getFileNode(filename);
|
|
|
|
|
|
- if(chkFile.isFile()){
|
|
|
- return FileStatus.FileExists;
|
|
|
- }
|
|
|
- else {
|
|
|
- return FileStatus.DirectoryExists;
|
|
|
- }
|
|
|
- }
|
|
|
+ if(fileNode == null) return FileStatus.NotExist;
|
|
|
+
|
|
|
+ if(fileNode.type == FileAttribute.Directory){
|
|
|
+ return FileStatus.DirectoryExists;
|
|
|
+ } else {
|
|
|
+ return FileStatus.FileExists;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public void flushFile(SrvSession srvSession, TreeConnection treeConnection, NetworkFile networkFile) throws IOException {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private FileNode getFileNode(String name){
|
|
|
+ for(FileNode node: this.filesystem){
|
|
|
+ if(node.name.equals(name)) return node;
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public FileInfo getFileInformation(SrvSession srvSession, TreeConnection treeConnection, String name) throws IOException {
|
|
|
//String path = FileName.buildPath(treeConnection.getContext().getDeviceName(), "/", "jlan", java.io.File.separatorChar);
|
|
@@ -126,16 +153,23 @@ public class PseudoCIFSDiskDriver implements DiskInterface {
|
|
|
//int fattr = FileAttribute.ReadOnly;
|
|
|
|
|
|
String path = FileName.buildPath(treeConnection.getContext().getDeviceName(), name, null, java.io.File.separatorChar);
|
|
|
+ FileNode fileNode = getFileNode(path);
|
|
|
+
|
|
|
+ if(fileNode == null){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
System.out.println("PATH::::"+path);
|
|
|
- int fattr = FileAttribute.Directory;
|
|
|
+ int fattr = fileNode.type + FileAttribute.ReadOnly;
|
|
|
|
|
|
FileInfo finfo = new FileInfo(path, 0, fattr);
|
|
|
long fdate = System.currentTimeMillis();
|
|
|
finfo.setModifyDateTime(fdate);
|
|
|
- finfo.setFileId(path.hashCode());
|
|
|
-
|
|
|
finfo.setCreationDateTime(fdate - 1000);
|
|
|
finfo.setChangeDateTime(fdate);
|
|
|
+ finfo.setDirectoryId(fileNode.parent);
|
|
|
+ finfo.setFileId(fileNode.name.hashCode());
|
|
|
+
|
|
|
return finfo;
|
|
|
}
|
|
|
|
|
@@ -148,18 +182,19 @@ public class PseudoCIFSDiskDriver implements DiskInterface {
|
|
|
public NetworkFile openFile(SrvSession srvSession, TreeConnection treeConnection, FileOpenParams fileOpenParams) throws IOException {
|
|
|
System.out.println("openFile method::::"+srvSession + " - " + treeConnection + " - " + fileOpenParams);
|
|
|
String fname = FileName.buildPath(treeConnection.getContext().getDeviceName(), fileOpenParams.getPath(), null, java.io.File.separatorChar);
|
|
|
- File file = new File(fname);
|
|
|
- File subFile = new File("/test.txt");
|
|
|
|
|
|
- NetworkFile netFile = new JavaNetworkFile(file,fname);
|
|
|
- netFile.setGrantedAccess(fileOpenParams.getAttributes());
|
|
|
- netFile.setAttributes(FileAttribute.Directory);
|
|
|
- netFile.setDirectoryId(5);
|
|
|
+ FileNode fileNode = getFileNode(fname);
|
|
|
+ if(fileNode == null) return null;
|
|
|
+
|
|
|
+ String[] path = fileNode.name.split("" + java.io.File.separatorChar);
|
|
|
|
|
|
- NetworkFile subNetFile = new JavaNetworkFile(subFile, "/test.txt");
|
|
|
- subNetFile.setGrantedAccess(NetworkFile.READONLY);
|
|
|
- subNetFile.setAttributes(FileAttribute.ReadOnly);
|
|
|
- subNetFile.setDirectoryId(netFile.getDirectoryId());
|
|
|
+ NetworkFile netFile = new PseudoNetworkFile(path.length == 0 ? "/" : path[path.length - 1]);
|
|
|
+ netFile.setFullName(fileNode.name);
|
|
|
+ netFile.setDirectoryId(fileNode.parent);
|
|
|
+ netFile.setFileId(fileNode.name.hashCode());
|
|
|
+ netFile.setAttributes(fileNode.type);
|
|
|
+ netFile.setGrantedAccess(NetworkFile.READONLY);
|
|
|
+ netFile.setAttributes(FileAttribute.ReadOnly);
|
|
|
|
|
|
return netFile;
|
|
|
}
|
|
@@ -188,6 +223,7 @@ public class PseudoCIFSDiskDriver implements DiskInterface {
|
|
|
|
|
|
@Override
|
|
|
public SearchContext startSearch(SrvSession srvSession, TreeConnection treeConnection, String s, int i) throws FileNotFoundException {
|
|
|
+ System.out.println("Start search!!!");
|
|
|
throw new FileNotFoundException();
|
|
|
}
|
|
|
|