Exemplo n.º 1
0
        public int MoveFile(string filename, string newname, bool replace, DokanFileInfo info)
        {
            WriteTrace("movefile", filename, newname, replace);

            string name = newname.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();

            if (!IsContainerNameValid(name))
            {
                return(-DokanNet.ERROR_INVALID_NAME);
            }

            FileReferences oldReference = files.Value.GetFolderReference(filename);

            if (oldReference == null)
            {
                return(-DokanNet.ERROR_PATH_NOT_FOUND);
            }

            FileReferences newReference = files.Value.GetFolderReference(newname);

            if (newReference == null || newReference.Name == name)
            {
                return(-DokanNet.ERROR_ALREADY_EXISTS);
            }

            FileReferences oldParentReference = files.Value.GetFolderReference(filename.Substring(0, filename.LastIndexOf('\\') + 1));

            newReference.Children.Add(oldReference);
            oldParentReference.Children.Remove(oldReference);
            oldReference.Name = name;

            PersistFileReferences();

            return(DokanNet.DOKAN_SUCCESS);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public int DeleteFile(string filename, DokanFileInfo info)
        {
            WriteTrace("deletefile", filename);

            FileReferences oldParentReference = files.Value.GetFolderReference(filename.Substring(0, filename.LastIndexOf('\\') + 1));

            if (oldParentReference == null)
            {
                return(-DokanNet.ERROR_PATH_NOT_FOUND);
            }

            string         name         = filename.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
            FileReferences oldReference = oldParentReference.Children.FirstOrDefault(child => child.Name == name);

            if (oldReference == null)
            {
                return(-DokanNet.ERROR_PATH_NOT_FOUND);
            }

            oldParentReference.Children.Remove(oldReference);

            PersistFileReferences();

            return(DokanNet.DOKAN_SUCCESS);
        }
Exemplo n.º 4
0
        public int CreateDirectory(string filename, DokanFileInfo info)
        {
            WriteTrace("createdirectory", filename);

            FileReferences folderReference = files.Value.GetFolderReference(filename);

            string name = filename.Split(new [] { '\\' }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();

            if (folderReference == null || string.IsNullOrEmpty(name) || !IsContainerNameValid(name))
            {
                return(-DokanNet.ERROR_INVALID_NAME);
            }

            if (folderReference.Name == name)
            {
                return(-DokanNet.ERROR_ALREADY_EXISTS);
            }

            folderReference.Children.Add(new FileReferences {
                Name = name
            });

            PersistFileReferences();

            return(DokanNet.DOKAN_SUCCESS);
        }
Exemplo n.º 5
0
        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);
            }
        }
Exemplo n.º 6
0
        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();
            });
        }
Exemplo n.º 7
0
        private Lazy <FileDownloaderBase> CreateFileDownloader(string filename)
        {
            string name = filename.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();

            FileReferences fileReference = files.Value.GetFolderReference(filename);

            if (fileReference == null || fileReference.Name != name)
            {
                return(null);
            }

            return(new Lazy <FileDownloaderBase>(() =>
            {
                int timeoutConter = 0;
                while (fileReference.Hash == FileReferences.UNKNOWN_FILE_HASH && timeoutConter < 10)
                {
                    Task.Delay(TimeSpan.FromSeconds(1)).Wait();
                    timeoutConter++;
                }

                return new DycryptedFileDownloader(fileReference.Hash, fileReference.Key, apiUrl);
            }));
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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();
            });
        }