コード例 #1
0
ファイル: MainForm.cs プロジェクト: zodapoplinsky/nekodrive
 void Download()
 {
     try
     {
         ShowProgress(true);
         foreach (ListViewItem lvItem in lvDragItem)
         {
             string OutputFile = System.IO.Path.Combine(LocalFolder, lvItem.Text);
             if (System.IO.File.Exists(OutputFile))
             {
                 if (MessageBox.Show("Do you want to overwrite " + OutputFile + "?", "NFSClient", MessageBoxButtons.YesNo) == DialogResult.Yes)
                 {
                     try
                     {
                         System.IO.File.Delete(OutputFile);
                     }
                     catch (Exception ex)
                     {
                         MessageBox.Show("An error has occurred deleting the file (" + ex.Message + ")", "NFS Client", MessageBoxButtons.OK);
                         continue;
                     }
                 }
                 else
                 {
                     continue;
                 }
             }
             CurrentItem = lvItem.Text;
             CurrentSize = long.Parse(lvItem.SubItems[1].Text);
             _lTotal     = 0;
             nfsClient.Read(nfsClient.Combine(CurrentItem, RemoteFolder), OutputFile);
         }
         ShowProgress(false);
     }
     catch (ThreadAbortException)
     {
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString(), "NFS Client");
         ShowProgress(false);
     }
 }
コード例 #2
0
        public int ReadFile(string filename, byte[] buffer, ref uint readBytes, long offset, DokanFileInfo info)
        {
            int ret = DokanNet.DOKAN_SUCCESS;

            filename = CleanFileName(filename);

            if (nfsClient.IsDirectory(filename))
            {
                return(DokanNet.DOKAN_SUCCESS);
            }

            try
            {
                Debug("ReadFile {0}", filename);
                string Directory = nfsClient.GetDirectoryName(filename);
                string FileName  = nfsClient.GetFileName(filename);
                string FullPath  = nfsClient.Combine(FileName, Directory);

                Debug("ReadFile {0} {1} {2} {3}", Directory, FileName, offset, buffer.Length);
                long Bytes = (long)buffer.Length;
                nfsClient.Read(FullPath, (long)offset, ref Bytes, ref buffer);
                if (Bytes != -1)
                {
                    readBytes = (uint)Bytes;
                    Debug("ReadFile bytes {0}", readBytes);
                }
                else
                {
                    ret = DokanNet.DOKAN_ERROR;
                }
            }
            catch (Exception ex)
            {
                ret = DokanNet.DOKAN_ERROR;
                Debug("ReadFile file {0} exception {1}", filename, ex.Message);
            }
            return(ret);
        }