示例#1
0
        void Upload(object move)
        {
            bool movebol =(bool)move;
            if (!connected)
                return;
            try
            {
                ShowProgress(true,movebol);
                int totalFiles = lvDragItem.Count();
                int currentFile = 0;
                bool rewriteAll = false;
                bool keepAll = false;
                foreach (ListViewItem lvItem in lvDragItem)
                {
                    currentFile++;
                    CurrentFilePos = currentFile + "/" + totalFiles;
                    CurrentItem = lvItem.Text;
                    CurrentDir = RemoteFolder;
                    if (Directory.Exists(System.IO.Path.Combine(LocalFolder, lvItem.Text)))
                    {
                        UploadRecursive(movebol,rewriteAll,keepAll,System.IO.Path.Combine(LocalFolder, lvItem.Text),nfsClient.Combine(CurrentItem, RemoteFolder));
                        if(movebol)
                        Directory.Delete(System.IO.Path.Combine(LocalFolder, lvItem.Text));
                        continue;
                    }
                    if (nfsClient.FileExists(nfsClient.Combine(lvItem.Text, RemoteFolder)))
                    {
                        if (rewriteAll)
                        {
                            nfsClient.DeleteFile(nfsClient.Combine(lvItem.Text, RemoteFolder));
                        }
                        else if (keepAll)
                            continue;

                        else
                        {

                            Rewrite rw = new Rewrite("NFSClient","Do you want to overwrite " + lvItem.Text + "?");
                            DialogResult dl = rw.ShowDialog();
                            if (dl == DialogResult.OK || dl == DialogResult.Retry)
                            {

                                nfsClient.DeleteFile(nfsClient.Combine(lvItem.Text, RemoteFolder));

                                if (dl == DialogResult.Retry)
                                    rewriteAll = true;
                            }
                            else
                            {
                                if (dl == DialogResult.Ignore)
                                    keepAll = true;

                                continue;
                            }
                        }
                    }
                    CurrentSize = long.Parse(lvItem.SubItems[1].Text);
                    _lTotal = 0;
                    string SourceName = System.IO.Path.Combine(LocalFolder, CurrentItem);
                    nfsClient.Write(nfsClient.Combine(CurrentItem, RemoteFolder), SourceName);
                    if (movebol)
                        System.IO.File.Delete(SourceName);

                }
                ShowProgress(false,movebol);
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "NFS Client - Error");
                ShowProgress(false,movebol);
            }
        }
示例#2
0
        void DownloadRecursive(bool move,bool rewriteAll,bool keepAll,string remoteFolder,string localfolder)
        {
            if (!Directory.Exists(localfolder))
            {
                Directory.CreateDirectory(localfolder);
            }

            List<string> folder_contents =  nfsClient.GetItemList(remoteFolder);
            int totalFiles = folder_contents.Count();
            int currentFile = 0;
            foreach (string Item in folder_contents)
            {
                currentFile++;
                CurrentFilePos = currentFile + "/" + totalFiles;
                CurrentItem = Item;
                CurrentDir = localfolder;
                string current_remote_file_path = nfsClient.Combine(Item, remoteFolder);
                string current_local_file_path = System.IO.Path.Combine(localfolder,Item);

                if (nfsClient.IsDirectory(current_remote_file_path))
                {
                    DownloadRecursive(move, rewriteAll, keepAll, current_remote_file_path, current_local_file_path);
                    if (move)
                        nfsClient.DeleteDirectory(current_remote_file_path);
                    continue;
                }

                if (System.IO.File.Exists(current_local_file_path))
                {

                    if (rewriteAll)
                    {
                        try
                        {
                            System.IO.File.Delete(current_local_file_path);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("An error has occurred deleting the file (" + ex.Message + ")", "NFS Client", MessageBoxButtons.OK);
                            continue;
                        }
                    }
                    else if (keepAll)
                        continue;

                    else
                    {
                        Rewrite rw = new Rewrite("NFSClient", "Do you want to overwrite " + current_local_file_path + "?");
                        DialogResult dl = rw.ShowDialog();
                        if (dl == DialogResult.OK || dl == DialogResult.Retry)
                        {
                            try
                            {
                                System.IO.File.Delete(current_local_file_path);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("An error has occurred deleting the file (" + ex.Message + ")", "NFS Client", MessageBoxButtons.OK);
                                continue;
                            }

                            if (dl == DialogResult.Retry)
                                rewriteAll = true;
                        }
                        else
                        {
                            if (dl == DialogResult.Ignore)
                                keepAll = true;

                            continue;
                        }

                    }

                }



                CurrentSize = nfsClient.GetItemAttributes(current_remote_file_path).Size;

                _lTotal = 0;
                nfsClient.Read(current_remote_file_path, current_local_file_path);
                if (move)
                    nfsClient.DeleteFile(current_remote_file_path);

            } 
        }
示例#3
0
        private void DeleteLocalFiles()
        {
            int i = 0;
            if (listViewLocal.SelectedItems != null)
            {
                bool deleteAll = false;
                foreach (ListViewItem lvi in listViewLocal.SelectedItems)
                {
                    DialogResult dl = DialogResult.None;
                    if (!deleteAll)
                    {
                        Rewrite del = new Rewrite("NFS Client", "Do you really want to delete " + lvi.Text + " ?");
                        dl = del.ShowDialog();
                        if (dl == DialogResult.Retry)
                            deleteAll = true;
                        else if (dl == DialogResult.Ignore)
                            break;
                    }

                    if (deleteAll || dl == DialogResult.OK)
                    {
                        try
                        {
                            if (lvi.ImageIndex == 1)
                                Directory.Delete(System.IO.Path.Combine(this.tbLocalPath.Text, lvi.Text),true);
                            else
                                System.IO.File.Delete(System.IO.Path.Combine(this.tbLocalPath.Text, lvi.Text));
                            i++;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "NFS Client - Error");
                        }
                    }
                }
                addToStatusLog("Deleted " + i + " files and folders from " + this.tbLocalPath.Text);
                RefreshLocal(tbLocalPath.Text);
            }
        }
示例#4
0
        void Download(object move)
        {
            bool movebol = (bool)move;
            if (!connected)
                return;
            try
            {
                ShowProgress(true,movebol);
                int totalFiles = lvDragItem.Count();
                int currentFile = 0;
                bool rewriteAll = false;
                bool keepAll = false;
                foreach (ListViewItem lvItem in lvDragItem)
                {
                    currentFile++;
                    CurrentFilePos = currentFile + "/" + totalFiles;
                    string OutputFile = System.IO.Path.Combine(LocalFolder, lvItem.Text);
                    if (nfsClient.IsDirectory(nfsClient.Combine(lvItem.Text, RemoteFolder)))
                    {
                        DownloadRecursive(movebol, rewriteAll, keepAll, nfsClient.Combine(lvItem.Text, RemoteFolder), OutputFile);
                        if (movebol)
                            nfsClient.DeleteDirectory(nfsClient.Combine(lvItem.Text, RemoteFolder));
                        continue;
                    }

                    if (System.IO.File.Exists(OutputFile))
                    {

                        if (rewriteAll)
                        {
                            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 if (keepAll)
                            continue;
                        else
                        {
                            Rewrite rw = new Rewrite("NFSClient", "Do you want to overwrite " + OutputFile + "?");
                            DialogResult dl = rw.ShowDialog();
                            if (dl == DialogResult.OK || dl == DialogResult.Retry)
                            {
                                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;
                                }

                                if (dl == DialogResult.Retry)
                                    rewriteAll = true;
                            }
                            else
                            {
                                if (dl == DialogResult.Ignore)
                                    keepAll = true;

                                continue;
                            }

                        }
                    }
                    CurrentItem = lvItem.Text;
                    CurrentSize = long.Parse(lvItem.SubItems[1].Text);
                    CurrentDir = LocalFolder;
                    _lTotal = 0;
                    nfsClient.Read(nfsClient.Combine(CurrentItem, RemoteFolder), OutputFile);
                    if (movebol)
                        nfsClient.DeleteFile(nfsClient.Combine(CurrentItem, RemoteFolder));
                }
                ShowProgress(false,movebol);
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "NFS Client");
                ShowProgress(false,movebol);
            }
        }
示例#5
0
        private void DeleteRemoteFiles()
        {
            int i = 0;
            if (listViewRemote.SelectedItems != null)
            {
                bool deleteAll = false;
                
                foreach (ListViewItem lvi in listViewRemote.SelectedItems)
                {
                    DialogResult dl = DialogResult.None;
                    if (!deleteAll)
                    {
                        Rewrite del = new Rewrite("NFS Client", "Do you really want to delete " + lvi.Text + " ?");
                        dl = del.ShowDialog();
                        if (dl == DialogResult.Retry)
                            deleteAll = true;
                        else if (dl == DialogResult.Ignore)
                            break;
                    }

                    if (deleteAll || dl == DialogResult.OK)
                    {
                        if (lvi.ImageIndex == 0)
                        {
                            nfsClient.DeleteFile(nfsClient.Combine(lvi.Text, RemoteFolder));
                        }
                        else
                            nfsClient.DeleteDirectory(nfsClient.Combine(lvi.Text, RemoteFolder),true);

                        i++;
                    }
                }
                addToStatusLog("Deleted " + i + " files and folders from " + RemoteFolder);
                tryToRefreshRemote();
            }
        }