public int GetFileInformation(string filename, Dokan.FileInformation fileinfo, DokanFileInfo info) { WriteTrace("getfileinformation", filename); FileReferences fileReference = files.Value.GetFolderReference(filename); string name = filename.Split(new [] { '\\' }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault(); if (fileReference != null && (fileReference.Name ?? string.Empty) != (name ?? string.Empty)) { return(-DokanNet.ERROR_FILE_NOT_FOUND); } if (fileReference != null) { fileinfo.Attributes = fileReference.IsFolder() ? FileAttributes.Directory : FileAttributes.Normal; fileinfo.LastAccessTime = fileReference.Date ?? DateTime.Now; fileinfo.LastWriteTime = fileReference.Date ?? DateTime.Now; fileinfo.CreationTime = fileReference.Date ?? DateTime.Now; fileinfo.FileName = fileReference.Name; fileinfo.Length = fileReference.Size; return(DokanNet.DOKAN_SUCCESS); } return(-DokanNet.ERROR_FILE_NOT_FOUND); }
public int CreateFile(string filename, FileAccess access, FileShare share, FileMode mode, FileOptions options, DokanFileInfo info) { WriteTrace("createfile", filename, access, share, mode, options); FileReferences fileReference = files.Value.GetFolderReference(filename); string name = filename.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault(); if (share == FileShare.Delete) { return(DeleteFile(filename, info)); } if (!(info.Context is FileUploader) && (mode == FileMode.CreateNew || mode == FileMode.Create || mode == FileMode.OpenOrCreate)) { if (fileReference != null && fileReference.Name == name && mode != FileMode.OpenOrCreate) { return(-DokanNet.ERROR_ALREADY_EXISTS); } info.Context = CreateFileUploader(filename); info.IsDirectory = false; return(DokanNet.DOKAN_SUCCESS); } if (!(info.Context is Lazy <FileDownloaderBase>) && (mode == FileMode.Open) && (fileReference == null || !fileReference.IsFolder())) { if (fileReference == null || fileReference.Name != name) { return(-DokanNet.ERROR_FILE_NOT_FOUND); } info.Context = CreateFileDownloader(filename); info.IsDirectory = false; return(DokanNet.DOKAN_SUCCESS); } if (fileReference != null) { info.IsDirectory = fileReference.IsFolder(); return(DokanNet.DOKAN_SUCCESS); } else { return(-DokanNet.ERROR_FILE_NOT_FOUND); } }
private void OnUploadComplete(FileUploader fileUploader, string filename) { FileReferences fileReference = files.Value.GetFolderReference(filename); if (fileUploader == null || fileReference == null) { EndCommunication(); return; } if (fileReference.Name != fileUploader.FileName && fileReference.IsFolder()) { FileReferences newFileReference = new FileReferences { Name = fileUploader.FileName }; fileReference.Children.Add(newFileReference); fileReference = newFileReference; } fileReference.Size = fileUploader.Size; fileReference.Date = DateTime.Now; fileReference.Hash = FileReferences.UNKNOWN_FILE_HASH; fileReference.Key = FileReferences.UNKNOWN_FILE_HASH; PersistFileReferences(); Task.Factory.StartNew(() => { UploadedFile cloudFile = fileUploader.Close().Result; if (cloudFile == null) { EndCommunication(); return; } fileReference.Hash = cloudFile.FileHash; fileReference.Key = cloudFile.Key; PersistFileReferences(); EndCommunication(); }); }
public int FindFiles(string filename, ArrayList fileList, DokanFileInfo info) { WriteTrace("findfiles", filename); FileReferences folderReference = files.Value.GetFolderReference(filename); if (folderReference == null || !folderReference.IsFolder()) { return(-DokanNet.ERROR_PATH_NOT_FOUND); } fileList.AddRange(folderReference.Children.Select(child => new Dokan.FileInformation { Attributes = child.IsFolder() ? FileAttributes.Directory : FileAttributes.Normal, FileName = child.Name, LastAccessTime = child.Date ?? DateTime.Now, LastWriteTime = child.Date ?? DateTime.Now, CreationTime = child.Date ?? DateTime.Now, Length = child.Size }).ToArray()); return(DokanNet.DOKAN_SUCCESS); }