public void Download(Data.RemoteServer _data, string _localFile, string _remoteFile)
 {
     this.data       = _data;
     this.remoteFile = _remoteFile;
     this.localFile  = _localFile;
     string[] files = Utils.Ftp.directoryListDetailed(data, remoteFile.Substring(0, remoteFile.LastIndexOf("/")) + "/");
     foreach (string elem in files)
     {
         string[] splitted = elem.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
         if (splitted.Length >= 9)
         {
             string name = "";
             for (int i = 8; i < splitted.Length; i++)
             {
                 name += splitted[i] + " ";
             }
             name = Utils.Strings.CutLastChars(name, 1);
             if (name == Path.GetFileName(remoteFile))
             {
                 this.fileSize = long.Parse(splitted[4]);
             }
         }
     }
     if (this.fileSize > 65536)
     {
         worker.RunWorkerAsync();
         this.ShowDialog();
     }
     else
     {
         worker_DoWork(null, null);
     }
 }
 public void Download(Data.RemoteServer _data, string _localFile, string _remoteFile)
 {
     this.data = _data;
     this.remoteFile = _remoteFile;
     this.localFile = _localFile;
     string[] files = Utils.Ftp.directoryListDetailed(data, remoteFile.Substring(0, remoteFile.LastIndexOf("/")) + "/");
     foreach(string elem in files)
     {
         string[] splitted = elem.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
         if (splitted.Length >= 9)
         {
             string name = "";
             for (int i = 8; i < splitted.Length; i++)
             {
                 name += splitted[i] + " ";
             }
             name = Utils.Strings.CutLastChars(name, 1);
             if (name == Path.GetFileName(remoteFile))
                 this.fileSize = long.Parse(splitted[4]);
         }
     }
     if (this.fileSize > 65536)
     {
         worker.RunWorkerAsync();
         this.ShowDialog();
     }
     else
     {
         worker_DoWork(null, null);
     }
 }
        public RemoteDirectoryNode(RemoteDirectoryNode parent, string _directory, Data.RemoteServer _data)
        {
            this.data      = _data;
            this.directory = _directory;

            this.ImageIndex         = ServersTreeView.FolderCloseIcon;
            this.SelectedImageIndex = this.ImageIndex;

            this.timer.Tick    += new EventHandler(timer_tick);
            this.timer.Interval = 100;
            this.timer.Start();

            int    last = directory.LastIndexOf('/');
            string name = directory.Substring(0, directory.Length - 1);

            if (last != -1)
            {
                this.Text = name.Substring(name.LastIndexOf("/") + 1);
            }
            else
            {
                this.Text = directory;
            }

            parent.Nodes.Add(this);

            Virtualize();
        }
示例#4
0
        /* Upload File */
        public static void upload(Data.RemoteServer data, string remoteFile, string localFile)
        {
            /* Create an FTP Request */
            ftpRequest = (FtpWebRequest)FtpWebRequest.Create(data.adress + remoteFile);
            /* Log in to the FTP Server with the User Name and Password Provided */
            ftpRequest.Credentials = new NetworkCredential(data.login, data.password);
            /* When in doubt, use these options */
            ftpRequest.UseBinary  = true;
            ftpRequest.UsePassive = true;
            ftpRequest.KeepAlive  = true;
            /* Specify the Type of FTP Request */
            ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
            /* Establish Return Communication with the FTP Server */
            ftpStream = ftpRequest.GetRequestStream();
            /* Open a File Stream to Read the File for Upload */
            FileStream localFileStream = new FileStream(localFile, FileMode.Open);

            /* Buffer for the Downloaded Data */
            byte[] byteBuffer = new byte[bufferSize];
            int    bytesSent  = localFileStream.Read(byteBuffer, 0, bufferSize);

            /* Upload the File by Sending the Buffered Data Until the Transfer is Complete */
            while (bytesSent != 0)
            {
                ftpStream.Write(byteBuffer, 0, bytesSent);
                bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize);
            }

            /* Resource Cleanup */
            localFileStream.Close();
            ftpStream.Close();
            ftpRequest = null;
        }
        public RemoteFileNode(RemoteDirectoryNode _directoryNode, string _file, Data.RemoteServer _data)
        {
            this.directoryNode = _directoryNode;
            this.file          = _file;
            this.data          = _data;

            directoryNode.Nodes.Add(this);

            int last = file.LastIndexOf('/');

            if (last != -1)
            {
                this.Text = file.Substring(file.LastIndexOf("/") + 1);
            }
            else
            {
                this.Text = file;
            }

            try
            {
                this.ImageIndex         = ((ServersTreeView)this.TreeView).GetRemoteFileIconImageIndex(file);
                this.SelectedImageIndex = this.ImageIndex;
            }
            catch (Exception) { }
        }
示例#6
0
 public RemoteServerNode(ServersTreeView treeView, Data.RemoteServer _serverData)
     : base(treeView, "/", _serverData, _serverData.ToString())
 {
     this.ServerData         = _serverData;
     this.ImageIndex         = ServersTreeView.RemoteServerIcon;
     this.SelectedImageIndex = this.ImageIndex;
 }
 public RemoteServerNode(ServersTreeView treeView, Data.RemoteServer _serverData)
     : base(treeView, "/", _serverData, _serverData.ToString())
 {
     this.ServerData = _serverData;
     this.ImageIndex = ServersTreeView.RemoteServerIcon;
     this.SelectedImageIndex = this.ImageIndex;
 }
示例#8
0
        /* Get the Date/Time a File was Created */
        public static string getFileCreatedDateTime(Data.RemoteServer data, string fileName)
        {
            /* Create an FTP Request */
            ftpRequest = (FtpWebRequest)FtpWebRequest.Create(data.adress + fileName);
            /* Log in to the FTP Server with the User Name and Password Provided */
            ftpRequest.Credentials = new NetworkCredential(data.login, data.password);
            /* When in doubt, use these options */
            ftpRequest.UseBinary  = true;
            ftpRequest.UsePassive = true;
            ftpRequest.KeepAlive  = true;
            /* Specify the Type of FTP Request */
            ftpRequest.Method = WebRequestMethods.Ftp.GetDateTimestamp;
            /* Establish Return Communication with the FTP Server */
            ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
            /* Establish Return Communication with the FTP Server */
            ftpStream = ftpResponse.GetResponseStream();
            /* Get the FTP Server's Response Stream */
            StreamReader ftpReader = new StreamReader(ftpStream);
            /* Store the Raw Response */
            string fileInfo = null;

            /* Read the Full Response Stream */
            fileInfo = ftpReader.ReadToEnd();

            /* Resource Cleanup */
            ftpReader.Close();
            ftpStream.Close();
            ftpResponse.Close();
            ftpRequest = null;
            /* Return File Created Date Time */
            return(fileInfo);
        }
 public static RemoteServer Deserialize(string filename)
 {
     Data.RemoteServer serverData = new Data.RemoteServer();
     XmlSerializer serializer = new XmlSerializer(typeof(Data.RemoteServer));
     StreamReader reader = new StreamReader(filename);
     serverData = (Data.RemoteServer)serializer.Deserialize(reader);
     reader.Close();
     return serverData;
 }
示例#10
0
 public new void Load(Data.RemoteServer _data, string name, Tabs tabs)
 {
     DataFileName = Utils.Main.RemoteDirectory + name + Path.DirectorySeparatorChar + "MainData.xml";
     this.data    = _data;
     if (File.Exists(Utils.Main.RemoteDirectory + name + Path.DirectorySeparatorChar + "RconData.xml"))
     {
         LoadFromFile(name, tabs);
     }
 }
 public new void Load(Data.RemoteServer _data, string name, Tabs tabs)
 {
     DataFileName = Utils.Main.RemoteDirectory + name + Path.DirectorySeparatorChar + "MainData.xml";
     this.data = _data;
     if (File.Exists(Utils.Main.RemoteDirectory + name + Path.DirectorySeparatorChar + "RconData.xml"))
     {
         LoadFromFile(name, tabs);
     }
 }
 public new void Load(Controls.ServersTreeNodes.RemoteFileNode node, Tabs tabs)
 {
     this.ftp = true;
     this.Data = node.data;
     this.ftpFile = node.GetFile();
     Dialogs.FtpDownloader downloader = new Dialogs.FtpDownloader();
     string ftpIp = node.data.adress.Replace("/", "").Split(':')[1];
     string ftpLocalFileName =  Utils.Main.TempRemoteDirectory + ftpIp + Path.DirectorySeparatorChar + Path.GetFileName(node.GetFile());
     downloader.Download(node.data, ftpLocalFileName, node.GetFile());
     Load(new FileInfo(ftpLocalFileName), tabs);
 }
示例#13
0
 public new void Load(Data.RemoteServer _data, string file, Tabs tabs)
 {
     ftp = true;
     Data = _data;
     ftpFile = file;
     FtpDownloader downloader = new FtpDownloader();
     string ftpIp = this.Data.adress.Replace("/", "").Split(':')[1];
     string ftpLocalFileName = Main.TempRemoteDirectory + ftpIp + Path.DirectorySeparatorChar + Path.GetFileName(file);
     downloader.Download(Data, ftpLocalFileName, file);
     Load(new FileInfo(ftpLocalFileName), tabs);
 }
示例#14
0
        public new void Load(Data.RemoteServer _data, string file, Tabs tabs)
        {
            ftp     = true;
            Data    = _data;
            ftpFile = file;
            FtpDownloader downloader       = new FtpDownloader();
            string        ftpIp            = this.Data.adress.Replace("/", "").Split(':')[1];
            string        ftpLocalFileName = Main.TempRemoteDirectory + ftpIp + Path.DirectorySeparatorChar + Path.GetFileName(file);

            downloader.Download(Data, ftpLocalFileName, file);
            Load(new FileInfo(ftpLocalFileName), tabs);
        }
示例#15
0
        public new void Load(ServersTreeNodes.RemoteFileNode node, Tabs tabs)
        {
            ftp     = true;
            Data    = node.data;
            ftpFile = node.GetFile();
            FtpDownloader downloader       = new FtpDownloader();
            string        ftpIp            = node.data.adress.Replace("/", "").Split(':')[1];
            string        ftpLocalFileName = Main.TempRemoteDirectory + ftpIp + Path.DirectorySeparatorChar + Path.GetFileName(node.GetFile());

            downloader.Download(node.data, ftpLocalFileName, node.GetFile());
            Load(new FileInfo(ftpLocalFileName), tabs);
        }
 private void uploadDirectory(Data.RemoteServer data, string localDirectory, string remoteDirectory)
 {
     foreach (string directory in Directory.GetDirectories(localDirectory))
     {
         string dirname = remoteDirectory + "/" + Path.GetFileName(directory) + "/";
         Ftp.createDirectory(data, dirname);
         uploadDirectory(data, directory, dirname);
     }
     foreach (string file in Directory.GetFiles(localDirectory))
     {
         new FtpUploader().Upload(data, file, remoteDirectory + "/" + Path.GetFileName(file));
     }
 }
        public void FullRefresh()
        {
            _systemIcons.Clear();
            _imageList.Images.Clear();
            Nodes.Clear();

            _imageList.Images.Add(Properties.Resources.FolderOpenIcon);
            _systemIcons.Add(FolderOpenIcon, 0);
            _imageList.Images.Add(Properties.Resources.FolderCloseIcon);
            _systemIcons.Add(FolderCloseIcon, 0);
            _imageList.Images.Add(Properties.Resources.LocalIcon);
            _systemIcons.Add(LocalServerIcon, 0);
            _imageList.Images.Add(Properties.Resources.RemoteIcon);
            _systemIcons.Add(RemoteServerIcon, 0);
            _imageList.Images.Add(Properties.Resources.ConsoleIcon);
            _systemIcons.Add(ConsoleIcon, 0);
            _imageList.Images.Add(Properties.Resources.MenuSettings);

            foreach (string server in Directory.GetDirectories(Utils.Main.ServersDirectory))
            {
                if (File.Exists(server + Path.DirectorySeparatorChar + "ServerCreatorData.xml")) //old file name
                {
                    File.Move(server + Path.DirectorySeparatorChar + "ServerCreatorData.xml", server + Path.DirectorySeparatorChar + "ServerManagerData.xml");
                }
                if (File.Exists(server + Path.DirectorySeparatorChar + "ServerManagerData.xml"))
                {
                    Data.Server serverData = Data.Server.Deserialize(server + Path.DirectorySeparatorChar + "ServerManagerData.xml");

                    ServerNode node = new ServerNode(this, new DirectoryInfo(server), serverData);

                    node.Expand();
                }
            }
            foreach (string importedServer in Directory.GetFiles(Utils.Main.ImportDirectory))
            {
                Data.Server serverData = Data.Server.Deserialize(importedServer);

                ServerNode node = new ServerNode(this, new DirectoryInfo(serverData.path), serverData);
                node.Expand();
            }

            foreach (string remoteServer in Directory.GetDirectories(Utils.Main.RemoteDirectory))
            {
                if (File.Exists(remoteServer + Path.DirectorySeparatorChar + "MainData.xml"))
                {
                    Data.RemoteServer serverData = Data.RemoteServer.Deserialize(remoteServer + Path.DirectorySeparatorChar + "MainData.xml");

                    RemoteServerNode node = new RemoteServerNode(this, serverData);
                }
            }
        }
        public RemoteDirectoryNode(ServersTreeView treeView, string _directory, Data.RemoteServer _data, string name)
            : base(name)
        {
            this.data      = _data;
            this.directory = _directory;

            this.timer.Tick    += new EventHandler(timer_tick);
            this.timer.Interval = 100;
            this.timer.Start();

            treeView.Nodes.Add(this);

            Virtualize();
        }
 public void Upload(Data.RemoteServer _data, string _localFile, string _remoteFile)
 {
     this.data = _data;
     this.remoteFile = _remoteFile;
     this.localFile = _localFile;
     this.fileSize = new FileInfo(localFile).Length;
     if (this.fileSize > 8192)
     {
         worker.RunWorkerAsync();
         this.ShowDialog();
     }
     else
     {
         worker_DoWork(null, null);
     }
 }
 public void Upload(Data.RemoteServer _data, string _localFile, string _remoteFile)
 {
     this.data       = _data;
     this.remoteFile = _remoteFile;
     this.localFile  = _localFile;
     this.fileSize   = new FileInfo(localFile).Length;
     if (this.fileSize > 8192)
     {
         worker.RunWorkerAsync();
         this.ShowDialog();
     }
     else
     {
         worker_DoWork(null, null);
     }
 }
示例#21
0
 /* Delete File */
 public static void deleteFile(Data.RemoteServer data, string deleteFile)
 {
     /* Create an FTP Request */
     ftpRequest = (FtpWebRequest)WebRequest.Create(data.adress + deleteFile);
     /* Log in to the FTP Server with the User Name and Password Provided */
     ftpRequest.Credentials = new NetworkCredential(data.login, data.password);
     /* When in doubt, use these options */
     ftpRequest.UseBinary  = true;
     ftpRequest.UsePassive = true;
     ftpRequest.KeepAlive  = true;
     /* Specify the Type of FTP Request */
     ftpRequest.Method = WebRequestMethods.Ftp.DeleteFile;
     /* Establish Return Communication with the FTP Server */
     ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
     /* Resource Cleanup */
     ftpResponse.Close();
     ftpRequest = null;
 }
示例#22
0
        /* List Directory Contents in Detail (Name, Size, Created, etc.) */
        public static string[] directoryListDetailed(Data.RemoteServer data, string directory)
        {
            /* Create an FTP Request */
            ftpRequest = (FtpWebRequest)FtpWebRequest.Create(data.adress + directory);
            /* Log in to the FTP Server with the User Name and Password Provided */
            ftpRequest.Credentials = new NetworkCredential(data.login, data.password);
            /* When in doubt, use these options */
            ftpRequest.UseBinary  = true;
            ftpRequest.UsePassive = true;
            ftpRequest.KeepAlive  = true;
            /* Specify the Type of FTP Request */
            ftpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
            /* Establish Return Communication with the FTP Server */
            ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
            /* Establish Return Communication with the FTP Server */
            ftpStream = ftpResponse.GetResponseStream();
            /* Get the FTP Server's Response Stream */
            StreamReader ftpReader = new StreamReader(ftpStream);
            /* Store the Raw Response */
            string directoryRaw = null;

            /* Read Each Line of the Response and Append a Pipe to Each Line for Easy Parsing */
            while (ftpReader.Peek() != -1)
            {
                directoryRaw += ftpReader.ReadLine() + "|";
            }

            /* Resource Cleanup */
            ftpReader.Close();
            ftpStream.Close();
            ftpResponse.Close();
            ftpRequest = null;

            if (directoryRaw == null)
            {
                return new string[] {}
            }
            ;

            /* Return the Directory Listing as a string Array by Parsing 'directoryRaw' with the Delimiter you Append (I use | in This Example) */
            string[] directoryList = directoryRaw.Split("|".ToCharArray()); return(directoryList);
        }
    }
示例#23
0
        /* Delete Directory */
        public static void deleteDirectory(Data.RemoteServer data, string directory)
        {
            string[]      listed = directoryListDetailed(data, directory);
            List <string> dirs   = new List <string>();
            List <string> files  = new List <string>();

            foreach (string elem in listed)
            {
                string[] splitted = elem.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                if (splitted.Length >= 9 && splitted[0].IndexOf("d") > -1)
                {
                    string name = "";
                    for (int i = 8; i < splitted.Length; i++)
                    {
                        name += splitted[i] + " ";
                    }
                    name = Utils.Strings.CutLastChars(name, 1);
                    dirs.Add(directory + name + "/");
                }
                else if (splitted.Length >= 9)
                {
                    string name = "";
                    for (int i = 8; i < splitted.Length; i++)
                    {
                        name += splitted[i] + " ";
                    }
                    name = Utils.Strings.CutLastChars(name, 1);
                    files.Add(directory + name);
                }
            }
            foreach (string dir in dirs)
            {
                deleteDirectory(data, dir);
            }
            foreach (string file in files)
            {
                deleteFile(data, file);
            }
            deleteDirectoryWithoutContent(data, directory);
        }
示例#24
0
        /* Get the Size of a File */
        public static long getFileSize(Data.RemoteServer data, string fileName)
        {
            /* Create an FTP Request */
            ftpRequest = (FtpWebRequest)FtpWebRequest.Create(data.adress + fileName);
            /* Log in to the FTP Server with the User Name and Password Provided */
            ftpRequest.Credentials = new NetworkCredential(data.login, data.password);
            /* When in doubt, use these options */
            ftpRequest.UseBinary  = true;
            ftpRequest.UsePassive = true;
            ftpRequest.KeepAlive  = true;
            /* Specify the Type of FTP Request */
            ftpRequest.Method = WebRequestMethods.Ftp.GetFileSize;
            /* Establish Return Communication with the FTP Server */
            ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
            /* Establish Return Communication with the FTP Server */
            ftpStream = ftpResponse.GetResponseStream();
            /* Get the FTP Server's Response Stream */
            StreamReader ftpReader = new StreamReader(ftpStream);

            /* Read the Full Response Stream */
            return(ftpResponse.ContentLength);
        }
示例#25
0
 /* Rename File */
 public static void rename(Data.RemoteServer data, string currentFileNameAndPath, string newFileName)
 {
     /* Create an FTP Request */
     if (Strings.GetLastChar(currentFileNameAndPath) == '/')
     {
         currentFileNameAndPath = Strings.CutLastChars(currentFileNameAndPath, 1);
     }
     ftpRequest = (FtpWebRequest)WebRequest.Create(data.adress + currentFileNameAndPath);
     /* Log in to the FTP Server with the User Name and Password Provided */
     ftpRequest.Credentials = new NetworkCredential(data.login, data.password);
     /* When in doubt, use these options */
     ftpRequest.UseBinary  = true;
     ftpRequest.UsePassive = true;
     ftpRequest.KeepAlive  = true;
     /* Specify the Type of FTP Request */
     ftpRequest.Method = WebRequestMethods.Ftp.Rename;
     /* Rename the File */
     ftpRequest.RenameTo = newFileName;
     /* Establish Return Communication with the FTP Server */
     ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
     /* Resource Cleanup */
     ftpResponse.Close();
     ftpRequest = null;
 }
示例#26
0
        public static void move(Data.RemoteServer data, string currentPath, string destinationPath)
        {
            Uri uriSource         = new Uri(data.adress + currentPath, UriKind.Absolute);
            Uri uriDestination    = new Uri(data.adress + destinationPath, UriKind.Absolute);
            Uri targetUriRelative = uriSource.MakeRelativeUri(uriDestination);

            /* Create an FTP Request */
            ftpRequest = (FtpWebRequest)WebRequest.Create(uriSource);
            /* Log in to the FTP Server with the User Name and Password Provided */
            ftpRequest.Credentials = new NetworkCredential(data.login, data.password);
            /* When in doubt, use these options */
            ftpRequest.UseBinary  = true;
            ftpRequest.UsePassive = true;
            ftpRequest.KeepAlive  = true;
            /* Specify the Type of FTP Request */
            ftpRequest.Method = WebRequestMethods.Ftp.Rename;
            /* Rename the File */
            ftpRequest.RenameTo = Uri.UnescapeDataString(targetUriRelative.OriginalString);
            /* Establish Return Communication with the FTP Server */
            ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
            /* Resource Cleanup */
            ftpResponse.Close();
            ftpRequest = null;
        }
示例#27
0
        private void readyButton_Click(object sender, EventArgs e)
        {
            int ftpPortNumber, rconPortNumber;

            if (serverName.Text == "")
            {
                Error.Show("ErrorNoServerName");
            }
            else if (engineSelect.SelectedItem == null)
            {
                Error.Show("ErrorNoEngine");
            }
            else if (versionSelect.SelectedItem == null)
            {
                Error.Show("ErrorNoVersion");
            }
            else if (serverIP.Text == "")
            {
                Error.Show("ErrorNoServerIp");
            }
            else if (ftpUser.Text == "" || ftpPassword.Text == "" || ftpPort.Text == "")
            {
                Error.Show("ErrorNoFtpData");
            }
            else if (rconPassword.Text == "" || rconPort.Text == "")
            {
                Error.Show("ErrorNoRconData");
            }
            else if (!int.TryParse(ftpPort.Text, out ftpPortNumber))
            {
                Error.Show("ErrorNanPortFtp");
            }
            else if (ftpPortNumber < 0 || ftpPortNumber > 65535)
            {
                Error.Show("ErrorOorPortFtp");
            }
            else if (!int.TryParse(rconPort.Text, out rconPortNumber))
            {
                Error.Show("ErrorNanPortRcon");
            }
            else if (rconPortNumber < 0 || rconPortNumber > 65535)
            {
                Error.Show("ErrorOorPortRcon");
            }
            else
            {
                ftpData          = new Data.RemoteServer();
                ftpData.adress   = "ftp://" + serverIP.Text + ":" + ftpPort.Text + "/";
                ftpData.login    = ftpUser.Text;
                ftpData.password = ftpPassword.Text;
                ftpData.name     = serverName.Text;
                ftpData.engine   = engineSelect.SelectedItem.ToString();
                ftpData.version  = versionSelect.SelectedItem.ToString();

                rconData          = new Data.RemoteServerRcon();
                rconData.adress   = serverIP.Text;
                rconData.name     = serverName.Text;
                rconData.port     = rconPortNumber;
                rconData.password = rconPassword.Text;

                Enabled = false;
                worker.RunWorkerAsync();
            }
        }
 private void renameMenu_Click(object sender, System.EventArgs e)
 {
     if (base.SelectedNode is FileNode)
     {
         FileNode node = (FileNode)base.SelectedNode;
         FileInfo file = node.GetFile();
         string newName = Dialogs.TextInput.ShowDialog("Zmiana nazwy", "Podaj nową nazwę pliku:", file.Name, "Zmień nazwę", "Anuluj");
         if (newName != "" && (file.DirectoryName + Path.DirectorySeparatorChar + newName) != file.FullName)
         {
             try
             {
                 file.MoveTo(file.DirectoryName + Path.DirectorySeparatorChar + newName);
             }
             catch (NotSupportedException)
             {
                 MessageBox.Show("Podana nazwa pliku jest nieprawidłowa!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             catch (IOException)
             {
                 MessageBox.Show("Plik o podanej nazwie już istnieje!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             ((DirectoryNode)node.Parent).Refresh();
         }
     }
     else if (base.SelectedNode is ServerNode)
     {
         ServerNode node = (ServerNode)base.SelectedNode;
         DirectoryInfo directory = node.GetDirectory();
         string newName = Dialogs.TextInput.ShowDialog("Zmiana nazwy", "Podaj nową nazwę serwera:", directory.Name, "Zmień nazwę", "Anuluj");
         if (newName != "" && (directory.Parent.FullName + Path.DirectorySeparatorChar + newName + Path.DirectorySeparatorChar) != directory.FullName)
         {
             try
             {
                 directory.MoveTo(directory.Parent.FullName + Path.DirectorySeparatorChar + newName);
                 node.GetServerData().name = newName;
                 node.GetServerData().Save();
                 FullRefresh();
             }
             catch (ArgumentException)
             {
                 MessageBox.Show("Podana nazwa serwera jest nieprawidłowa!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             catch (IOException)
             {
                 MessageBox.Show("Serwer o podanej nazwie już istnieje!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
     else if (base.SelectedNode is DirectoryNode)
     {
         DirectoryNode node = (DirectoryNode)base.SelectedNode;
         DirectoryInfo directory = node.GetDirectory();
         string newName = Dialogs.TextInput.ShowDialog("Zmiana nazwy", "Podaj nową nazwę folderu:", directory.Name, "Zmień nazwę", "Anuluj");
         if (newName != "" && (directory.Parent.FullName + Path.DirectorySeparatorChar + newName) != directory.FullName)
         {
             try
             {
                 directory.MoveTo(directory.Parent.FullName + Path.DirectorySeparatorChar + newName);
                 ((DirectoryNode)node.Parent).Refresh();
             }
             catch (ArgumentException)
             {
                 MessageBox.Show("Podana nazwa folderu jest nieprawidłowa!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             catch (IOException)
             {
                 MessageBox.Show("Folder o podanej nazwie już istnieje!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
     else if (base.SelectedNode is RemoteServerNode)
     {
         RemoteServerNode node = (RemoteServerNode)base.SelectedNode;
         string newName = Dialogs.TextInput.ShowDialog("Zmiana nazwy", "Podaj nową nazwę serwera:", node.GetServerData().name, "Zmień nazwę", "Anuluj");
         Data.RemoteServer data = new Data.RemoteServer();
         data.name = newName;
         if (!Directory.Exists(data.GetDirectory()))
         {
             Directory.Move(node.GetServerData().GetDirectory(), data.GetDirectory());
             node.GetServerData().name = newName;
             node.GetServerData().Save();
             FullRefresh();
         }
     }
     else if (base.SelectedNode is RemoteDirectoryNode)
     {
         RemoteDirectoryNode node = (RemoteDirectoryNode)base.SelectedNode;
         string directory = Path.GetFileName(Utils.Strings.CutLastChars(node.directory, 1));
         string newName = Dialogs.TextInput.ShowDialog("Zmiana nazwy", "Podaj nową nazwę folderu:", directory, "Zmień nazwę", "Anuluj");
         if (newName != "" && newName != directory)
         {
             Utils.Ftp.rename(node.data, node.directory, newName);
             ((RemoteDirectoryNode)node.Parent).Refresh();
         }
     }
     else if (base.SelectedNode is RemoteFileNode)
     {
         RemoteFileNode node = (RemoteFileNode)base.SelectedNode;
         string file = Path.GetFileName(node.GetFile());
         string newName = Dialogs.TextInput.ShowDialog("Zmiana nazwy", "Podaj nową nazwę pliku:", file, "Zmień nazwę", "Anuluj");
         if (newName != "" && newName !=  file)
         {
             Utils.Ftp.rename(node.data, node.GetFile(), newName);
             ((RemoteDirectoryNode)node.Parent).Refresh();
         }
     }
 }
        private void readyButton_Click(object sender, EventArgs e)
        {
            int ftpPortNumber, rconPortNumber;
            if (serverName.Text == "")
                Error.Show("ErrorNoServerName");
            else if (engineSelect.SelectedItem == null)
                Error.Show("ErrorNoEngine");
            else if (versionSelect.SelectedItem == null)
                Error.Show("ErrorNoVersion");
            else if (serverIP.Text == "")
                Error.Show("ErrorNoServerIp");
            else if (ftpUser.Text == "" || ftpPassword.Text == "" || ftpPort.Text == "")
                Error.Show("ErrorNoFtpData");
            else if (rconPassword.Text == "" || rconPort.Text == "")
                Error.Show("ErrorNoRconData");
            else if (!int.TryParse(ftpPort.Text, out ftpPortNumber))
                Error.Show("ErrorNanPortFtp");
            else if (ftpPortNumber < 0 || ftpPortNumber > 65535)
                Error.Show("ErrorOorPortFtp");
            else if (!int.TryParse(rconPort.Text, out rconPortNumber))
                Error.Show("ErrorNanPortRcon");
            else if (rconPortNumber < 0 || rconPortNumber > 65535)
                Error.Show("ErrorOorPortRcon");
            else {
                ftpData = new Data.RemoteServer();
                ftpData.adress = "ftp://" + serverIP.Text + ":" + ftpPort.Text + "/";
                ftpData.login = ftpUser.Text;
                ftpData.password = ftpPassword.Text;
                ftpData.name = serverName.Text;
                ftpData.engine = engineSelect.SelectedItem.ToString();
                ftpData.version = versionSelect.SelectedItem.ToString();

                rconData = new Data.RemoteServerRcon();
                rconData.adress = serverIP.Text;
                rconData.name = serverName.Text;
                rconData.port = rconPortNumber;
                rconData.password = rconPassword.Text;

                Enabled = false;
                worker.RunWorkerAsync();
            }
        }
        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
            }
        }
        private void readyButton_Click(object sender, EventArgs e)
        {
            #region validation
            if (serverName.Text == "")
            {
                MessageBox.Show("Podaj nazwę serwera!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (engineSelect.SelectedItem == null)
            {
                MessageBox.Show("Wybierz silnik!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (this.versionSelect.SelectedItem == null)
            {
                MessageBox.Show("Wybierz wersję!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (serverIP.Text == "")
            {
                MessageBox.Show("Podaj adres IP serwera!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (ftpUser.Text == "" || ftpPassword.Text == "" || ftpPort.Text == "")
            {
                MessageBox.Show("Podaj dane FTP!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (rconPassword.Text == "" || rconPort.Text == "")
            {
                MessageBox.Show("Podaj dane RCON!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            int ftpPortNumber, rconPortNumber;
            if (!int.TryParse(ftpPort.Text, out ftpPortNumber))
            {
                MessageBox.Show("Numer portu FTP musi być liczbą!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (ftpPortNumber < 0 || ftpPortNumber > 65535)
            {
                MessageBox.Show("Numer portu FTP jest poza zakresem!");
            }

            if (!int.TryParse(rconPort.Text, out rconPortNumber))
            {
                MessageBox.Show("Numer portu RCON musi być liczbą!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (rconPortNumber < 0 || rconPortNumber > 65535)
            {
                MessageBox.Show("Numer portu RCON jest poza zakresem!");
            }
            #endregion

            string ip = serverIP.Text;
            int port = ftpPortNumber;
            string user = ftpUser.Text;
            string password = ftpPassword.Text;

            Data.RemoteServer ftpData = new Data.RemoteServer();
            Data.RemoteServerRcon rconData = new Data.RemoteServerRcon();

            try
            {
                ftpData.adress = "ftp://" + ip + ":" + port + "/";
                ftpData.login = user;
                ftpData.password = password;
                ftpData.name = serverName.Text;
                ftpData.engine = engineSelect.SelectedItem.ToString();
                ftpData.version = versionSelect.SelectedItem.ToString();

                Utils.Ftp.directoryListSimple(ftpData, "");

                ftpData.Save();
            }
            catch (WebException)
            {
                MessageBox.Show("Nie udało się połączyć z serwerem FTP! Czy na pewno wpisałeś poprawne dane?", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            RconClient rcon = RconClient.INSTANCE;
            rcon.setupStream(serverIP.Text, rconPortNumber, rconPassword.Text);
            if (rcon.isInit)
            {
                rconData.name = serverName.Text;
                rconData.adress = serverIP.Text;
                rconData.password = rconPassword.Text;
                rconData.port = rconPortNumber;
                rconData.Save();
            }
            else
            {
                MessageBox.Show("Nie udało się połączyć z konsolą serwera przez RCON! Czy na pewno wpisałeś poprawne dane?\nPamiętaj o wstawieniu w pliku server.properties następujących linii:\nenable-rcon=true\nrcon.port=Twój port RCON\nrcon.password=Twoje hasło RCON", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            rconData.Save();
            ftpData.Save();

            this.Enabled = false;

            tabs.mainWindow.serversTree.FullRefresh();
        }
        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
            }
        }