Beispiel #1
0
 public int ReadFile(String filename, Byte[] buffer, ref uint readBytes,
                     long offset, DokanFileInfo info)
 {
     lock (info)
     {
         logger.Debug("ReadFile {0} bytes from {1}", buffer.Length, offset);
         try
         {
             PutioFileHandle handle = this.Mounter.PutioFileSystem.GetHandleByGuid((Guid)info.Context);
             // if (this.FindPutioFSItem(filename) == null)
             //    return DokanNet.ERROR_FILE_NOT_FOUND;
             if (offset != handle.Position)
             {
                 handle.Seek(offset);
             }
             readBytes = (uint)handle.Read(buffer, 0, buffer.Length);
         }
         catch (KeyNotFoundException)
         {
             logger.Debug("Trying to read from a closed file.");
             return(-1);
         }
         return(0);
     }
 }
Beispiel #2
0
        public int CloseFile(String filename, DokanFileInfo info)
        {
            if (info.IsDirectory)
            {
                return(0);
            }

            lock (info)
            {
                PutioFsItem item = this.FindPutioFSItem(filename);
                if (item == null)
                {
                    return(DokanNet.ERROR_FILE_NOT_FOUND);
                }
                if (item.IsDirectory)
                {
                    return(0);
                }

                PutioFileHandle handle = this.Mounter.PutioFileSystem.GetHandleByGuid((Guid)info.Context);
                this.Mounter.PutioFileSystem.RemoveHandle(handle);
                handle.Close();
                info.Context = null;
                return(0);
            }
        }
Beispiel #3
0
        public void PutioFileReadTest()
        {
            FileInfo        finfo         = new FileInfo(test_local_file);
            PutioFile       remote_file   = new PutioFile(new PutioFsTestDataProvider(finfo.Name, finfo.FullName, 660, finfo.Length, false, Constants.LocalStoragePath), null);
            PutioFileHandle remote_stream = remote_file.Open();
            //FileStream remote_stream = File.Open(remote_file.DataProvider.LocalStorageFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            FileStream local_stream = File.Open(test_local_file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            byte[] local_data  = new byte[11952];
            byte[] remote_data = new byte[11952];

            local_stream.Seek(367043856, SeekOrigin.Begin);
            local_stream.Read(local_data, 0, local_data.Length);
            // remote_stream.Seek(367043856, SeekOrigin.Begin);
            remote_stream.Seek(367043856);
            remote_stream.Read(remote_data, 0, remote_data.Length);


            CollectionAssert.AreEqual(local_data, remote_data);
        }
Beispiel #4
0
        public void PutioFileVLCReadTest()
        {
            PutioFile       remote_file   = new PutioFile(new PutioFsTestDataProvider("660.avi", test_local_file, 660, 697080622, false, Constants.LocalStoragePath), null);
            PutioFileHandle remote_stream = remote_file.Open();
            FileStream      local_stream  = File.Open(test_local_file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            foreach (int[] p in vlc_read_positions)
            {
                byte[] local_data  = new byte[p[0]];
                byte[] remote_data = new byte[p[0]];

                remote_stream.Seek(p[1]);
                int remote_read = remote_stream.Read(remote_data, 0, p[0]);
                local_stream.Seek(p[1], SeekOrigin.Begin);
                int local_read = local_stream.Read(local_data, 0, p[0]);

                Assert.AreEqual(local_read, remote_read);
                CollectionAssert.AreEqual(remote_data, local_data);
            }
            Debug.WriteLine(":(");
        }
Beispiel #5
0
        public int CreateFile(String filename, FileAccess access, FileShare share,
                              FileMode mode, FileOptions options, DokanFileInfo info)
        {
            lock (info)
            {
                if (access != FileAccess.Read)
                {
                    return(-DokanNet.ERROR_ACCESS_DENIED);
                }


                PutioFsItem fs_item = this.FindPutioFSItem(filename);

                if (fs_item == null)
                {
                    return(-DokanNet.ERROR_FILE_NOT_FOUND);
                }

                if (fs_item.IsDirectory)
                {
                    info.IsDirectory = true;
                }
                else
                {
                    PutioFile putio_file = (PutioFile)fs_item;
                    // if (putio_file.ReachedHandleLimit())
                    //    return DokanNet.ERROR_SHARING_VIOLATION;
                    PutioFileHandle handle = putio_file.Open();
                    this.Mounter.PutioFileSystem.AddHandle(handle);
                    info.Context = handle.Guid;
                    logger.Debug("CreateFile: {0} - {1}", filename, handle);
                }

                return(0);
            }
        }