private void copyDirectoryMenu_Click(object sender, EventArgs e)
 {
     if (base.SelectedNode is DirectoryNode)
     {
         DirectoryNode       node = (DirectoryNode)base.SelectedNode;
         FolderBrowserDialog fbd  = new FolderBrowserDialog();
         if (fbd.ShowDialog() == DialogResult.OK)
         {
             string newName = node.GetDirectory().FullName + Path.DirectorySeparatorChar + Path.GetFileName(fbd.SelectedPath);
             if (Directory.Exists(newName))
             {
                 Error.Show("ErrorDirectoryExists");
                 return;
             }
             try
             {
                 new Computer().FileSystem.CopyDirectory(fbd.SelectedPath, newName, UIOption.AllDialogs);
             }
             catch (OperationCanceledException) { }
         }
     }
     else if (base.SelectedNode is RemoteDirectoryNode)
     {
         RemoteDirectoryNode node = (RemoteDirectoryNode)base.SelectedNode;
         FolderBrowserDialog fbd  = new FolderBrowserDialog();
         if (fbd.ShowDialog() == DialogResult.OK)
         {
             string remoteName = node.directory + Path.GetFileName(fbd.SelectedPath);
             Utils.Ftp.createDirectory(node.data, remoteName);
             uploadDirectory(node.data, fbd.SelectedPath, remoteName);
         }
         node.Refresh();
     }
 }
 private void copyFileMenu_Click(object sender, EventArgs e)
 {
     if (base.SelectedNode is DirectoryNode)
     {
         DirectoryNode  node     = (DirectoryNode)base.SelectedNode;
         OpenFileDialog openFile = new OpenFileDialog();
         openFile.Multiselect = true;
         if (openFile.ShowDialog() == DialogResult.OK)
         {
             string[] fileNames = openFile.FileNames;
             for (int j = 0; j < fileNames.Length; j++)
             {
                 string filename = fileNames[j];
                 string newName  = node.GetDirectory().FullName + Path.DirectorySeparatorChar + Path.GetFileName(filename);
                 if (File.Exists(newName))
                 {
                     Error.Show("ErrorFileExists");
                     return;
                 }
                 try
                 {
                     new Computer().FileSystem.CopyFile(filename, newName, UIOption.AllDialogs);
                 }
                 catch (OperationCanceledException) { }
                 node.Refresh();
             }
         }
     }
     else if (base.SelectedNode is RemoteDirectoryNode)
     {
         RemoteDirectoryNode node     = (RemoteDirectoryNode)base.SelectedNode;
         OpenFileDialog      openFile = new OpenFileDialog();
         openFile.Multiselect = true;
         if (openFile.ShowDialog() == DialogResult.OK)
         {
             string[] fileNames = openFile.FileNames;
             for (int j = 0; j < fileNames.Length; j++)
             {
                 string filename = fileNames[j];
                 string newName  = node.directory + Path.GetFileName(filename);
                 new Dialogs.FtpUploader().Upload(node.data, filename, newName);
                 node.Refresh();
             }
         }
     }
 }
        private void ServersTreeView_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Effect != DragDropEffects.Move)
            {
                return;
            }

            Point    point = this.PointToClient(new Point(e.X, e.Y));
            TreeNode node  = this.GetNodeAt(point);

            if (node is DirectoryNode)
            {
                DirectoryInfo directory = ((DirectoryNode)node).GetDirectory();
                if (DragNode is FileNode)
                {
                    FileInfo file = ((FileNode)DragNode).GetFile();
                    file.MoveTo(directory.FullName + Path.DirectorySeparatorChar + file.Name);
                }
                else if (DragNode is DirectoryNode)
                {
                    DirectoryNode movedDirectoryNode = ((DirectoryNode)DragNode);
                    DirectoryInfo movedDirectory     = movedDirectoryNode.GetDirectory();
                    movedDirectory.MoveTo(directory.FullName + Path.DirectorySeparatorChar + movedDirectory.Name);
                }
            }
            else if (node is RemoteDirectoryNode)
            {
                RemoteDirectoryNode remoteDirectoryNode = ((RemoteDirectoryNode)node);
                string directory = remoteDirectoryNode.directory;
                if (DragNode is RemoteFileNode)
                {
                    string file = ((RemoteFileNode)DragNode).GetFile();
                    Ftp.move(remoteDirectoryNode.data, file, directory + Path.GetFileName(file));
                    DragNode.Remove();
                    remoteDirectoryNode.Refresh();
                }
            }
        }
        private void removeMenu_Click(object sender, EventArgs e)
        {
            if (base.SelectedNode is FileNode)
            {
                FileNode     node   = (FileNode)base.SelectedNode;
                FileInfo     file   = node.GetFile();
                DialogResult result = MessageBox.Show(
                    String.Format(Language.GetString("DialogFileRemove"), file.Name),
                    Language.GetString("Warning"), MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                if (result == DialogResult.Yes)
                {
                    file.Delete();
                    node.Remove();
                }
            }
            else if (base.SelectedNode is DirectoryNode)
            {
                DirectoryNode node      = (DirectoryNode)base.SelectedNode;
                DirectoryInfo directory = node.GetDirectory();
                string        message;
                if (base.SelectedNode is ServerNode)
                {
                    message = String.Format(Language.GetString("DialogDirectoryRemove"), directory.Name);
                }
                else
                {
                    message = String.Format(Language.GetString("DialogServerRemove"), directory.Name);
                }
                DialogResult result = MessageBox.Show(message, Language.GetString("Warning"),
                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        if (directory.Exists)
                        {
                            new Computer().FileSystem.DeleteDirectory(directory.FullName, UIOption.AllDialogs, RecycleOption.SendToRecycleBin);
                        }
                        if (base.SelectedNode is ServerNode && ((ServerNode)base.SelectedNode).GetServerData().isImported)
                        {
                            File.Delete(((ServerNode)base.SelectedNode).GetServerData().GetFile());
                        }
                        node.Destroy();
                    }
                    catch (OperationCanceledException) { }
                }
            }
            else if (base.SelectedNode is RemoteServerNode)
            {
                RemoteServerNode node   = (RemoteServerNode)base.SelectedNode;
                DialogResult     result = MessageBox.Show(
                    String.Format(Language.GetString("DialogRemoteServerRemove"), node.GetServerData().name),
                    Language.GetString("Warning"), MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                if (result == DialogResult.Yes)
                {
                    Directory.Delete(Main.RemoteDirectory + node.GetServerData().name, true);
                    node.Destroy();
                }
            }
            else if (base.SelectedNode is RemoteDirectoryNode)
            {
                RemoteDirectoryNode node = (RemoteDirectoryNode)base.SelectedNode;
                DialogResult        dr   = MessageBox.Show(
                    String.Format(Language.GetString("DialogDirectoryRemove"), node.Text),
                    Language.GetString("Warning"), MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

                if (dr == DialogResult.Yes)
                {
                    Ftp.deleteDirectory(node.data, node.directory);
                    node.Destroy();
                }
            }
            else if (base.SelectedNode is RemoteFileNode)
            {
                RemoteFileNode node = (RemoteFileNode)base.SelectedNode;
                DialogResult   dr   = MessageBox.Show(
                    String.Format(Language.GetString("DialogFileRemove"), node.Text),
                    Language.GetString("Warning"), MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

                if (dr == DialogResult.Yes)
                {
                    Ftp.deleteFile(node.data, node.GetFile());
                    node.Remove();
                }
            }
        }
        private void ServersTreeView_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
        {
            LabelEditAction EditAction = this.EditAction;

            this.EditAction = LabelEditAction.None;
            if (e.Label == null || e.Label == "")
            {
                if (EditAction == LabelEditAction.Rename)
                {
                    if (OldLabelEditName != null)
                    {
                        e.Node.Text = OldLabelEditName;
                    }
                }
                else if (EditAction == LabelEditAction.NewFile || EditAction == LabelEditAction.NewDirectory)
                {
                    e.Node.Remove();
                }
                e.CancelEdit = true;
                return;
            }

            if (EditAction == LabelEditAction.Rename)
            {
                #region ActionRename
                if (e.Node is FileNode)
                {
                    FileNode node = (FileNode)e.Node;
                    FileInfo file = node.GetFile();
                    string   path = file.DirectoryName + Path.DirectorySeparatorChar + e.Label;

                    if (File.Exists(path))
                    {
                        Error.Show("ErrorFileExists");
                        e.CancelEdit = true; return;
                    }
                    try { file.MoveTo(path); }
                    catch (IOException)
                    {
                        Error.Show("ErrorFileInvalidName");
                        e.CancelEdit = true; return;
                    }
                }

                else if (e.Node is ServerNode)
                {
                    ServerNode    node      = (ServerNode)e.Node;
                    DirectoryInfo directory = node.GetDirectory();
                    string        path      = directory.Parent.FullName + Path.DirectorySeparatorChar + e.Label;

                    if (Directory.Exists(path))
                    {
                        Error.Show("ErrorServerExists");
                    }
                    else
                    {
                        try
                        {
                            directory.MoveTo(path);
                            node.GetServerData().name = e.Label;
                            node.GetServerData().Save();
                        }
                        catch (IOException)
                        {
                            Error.Show("ErrorServerInvalidName");
                        }
                    }
                    node.Text    = node.GetServerData().ToString();
                    e.CancelEdit = true;
                }

                else if (e.Node is DirectoryNode)
                {
                    DirectoryNode node      = (DirectoryNode)e.Node;
                    DirectoryInfo directory = node.GetDirectory();
                    string        path      = directory.Parent.FullName + Path.DirectorySeparatorChar + e.Label;

                    if (Directory.Exists(path))
                    {
                        Error.Show("ErrorDirectoryExists");
                        e.CancelEdit = true; return;
                    }
                    try
                    {
                        directory.MoveTo(path);
                    }
                    catch (IOException)
                    {
                        Error.Show("ErrorDirectoryInvalidName");
                        e.CancelEdit = true; return;
                    }
                }

                else if (e.Node is RemoteServerNode)
                {
                    RemoteServerNode  node = (RemoteServerNode)e.Node;
                    Data.RemoteServer data = new Data.RemoteServer();
                    data.name = e.Label;
                    if (!Directory.Exists(data.GetDirectory()))
                    {
                        Directory.Move(node.GetServerData().GetDirectory(), data.GetDirectory());
                        node.GetServerData().name = e.Label;
                        node.GetServerData().Save();
                    }
                    node.Text    = node.GetServerData().ToString();
                    e.CancelEdit = true;
                }

                else if (e.Node is RemoteDirectoryNode)
                {
                    RemoteDirectoryNode node = (RemoteDirectoryNode)e.Node;
                    Ftp.rename(node.data, node.directory, e.Label);
                    ((RemoteDirectoryNode)e.Node.Parent).Refresh();
                    e.CancelEdit = true;
                }

                else if (e.Node is RemoteFileNode)
                {
                    RemoteFileNode node = (RemoteFileNode)e.Node;
                    Ftp.rename(node.data, node.GetFile(), e.Label);
                    ((RemoteDirectoryNode)e.Node.Parent).Refresh();
                    e.CancelEdit = true;
                }
                #endregion
            }

            else if (EditAction == LabelEditAction.NewFile)
            {
                #region ActionNewFile
                if (e.Node.Parent is DirectoryNode)
                {
                    DirectoryNode node = (DirectoryNode)e.Node.Parent;
                    string        path = node.GetDirectory().FullName + Path.DirectorySeparatorChar + e.Label;
                    if (File.Exists(path))
                    {
                        Error.Show("ErrorFileExists");
                    }
                    else
                    {
                        try
                        {
                            File.Create(path).Close();
                        }
                        catch (IOException)
                        {
                            Error.Show("ErrorFileInvalidName");
                        }
                    }
                    e.Node.Remove();
                }
                else if (e.Node.Parent is RemoteDirectoryNode)
                {
                    RemoteDirectoryNode node = (RemoteDirectoryNode)e.Node.Parent;
                    File.Create(Main.TempDirectory + e.Label).Close();
                    Ftp.upload(node.data, node.directory + e.Label, Main.TempDirectory + e.Label);
                    e.Node.Remove();
                    node.Refresh();
                }
                #endregion ;
            }

            else if (EditAction == LabelEditAction.NewDirectory)
            {
                #region ActionNewDirectory
                if (e.Node.Parent is DirectoryNode)
                {
                    DirectoryNode node = (DirectoryNode)e.Node.Parent;
                    string        path = node.GetDirectory().FullName + Path.DirectorySeparatorChar + e.Label;
                    if (Directory.Exists(path))
                    {
                        Error.Show("ErrorDirectoryExists");
                    }
                    else
                    {
                        try
                        {
                            Directory.CreateDirectory(path);
                        }
                        catch (IOException)
                        {
                            Error.Show("ErrorDirectoryInvalidName");
                        }
                    }
                    e.Node.Remove();
                }
                else if (e.Node.Parent is RemoteDirectoryNode)
                {
                    RemoteDirectoryNode node = (RemoteDirectoryNode)e.Node.Parent;
                    Ftp.createDirectory(node.data, node.directory + e.Label);
                    e.Node.Remove();
                    node.Refresh();
                }
                #endregion
            }
        }