Ejemplo n.º 1
0
        private void FolderClick(object sender, MouseButtonEventArgs e)
        {
            EntryControl entry = (sender as EntryControl);

            if (entry.Type == "dir")
            {
                prevAddress     = entry.address;
                addressBox.Text = entry.address + entry.FileName.Text + "/";
                Refresh();
            }
            else if (entry.Type == "up")
            {
                GoBack();
            }
            else
            {
                DownloadFile(entry);
            }
        }
Ejemplo n.º 2
0
        private async void DownloadFile(EntryControl entry)
        {
            statusBox.Text = "";
            if (isLoading)
            {
                ShowException("Another loading is in progress,\nplease wait for it to finish.");
                return;
            }
            SaveFileDialog sfd = new SaveFileDialog
            {
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Downloads",
                RestoreDirectory = true,
                Filter           = "All files(*.*)|*.*",
                FileName         = entry.FileName.Text
            };

            if (sfd.ShowDialog() == true)
            {
                pBar.Visibility       = Visibility.Visible;
                percentage.Visibility = Visibility.Visible;
                string filename = entry.FileName.Text;
                isLoading = true;

                await Task.Run(() =>
                {
                    try
                    {
                        status = client.DownloadFile(filename, sfd.FileName, pBar);
                    }
                    catch (Exception ex)
                    {
                        ShowException(ex.Message);
                    }
                });

                isLoading = false;

                statusBox.Text        = status;
                pBar.Visibility       = Visibility.Hidden;
                percentage.Visibility = Visibility.Hidden;
            }
        }
Ejemplo n.º 3
0
        private void RemoveFolder(object sender, RoutedEventArgs e)
        {
            EntryControl      entry    = filesList.SelectedItem as EntryControl;
            ConfimationWindow yesNoWin = new ConfimationWindow(entry.FileName.Text)
            {
                Owner = this,
                WindowStartupLocation = WindowStartupLocation.CenterOwner
            };

            yesNoWin.yBtn.Click += (s, _) =>
            {
                try
                {
                    status = client.RemoveFolder(entry.FileName.Text);
                    Refresh();
                }
                catch (Exception ex)
                {
                    ShowException(ex.Message);
                }
            };
            yesNoWin.ShowDialog();
        }
Ejemplo n.º 4
0
        private async void ConnectBtnClick(object sender, RoutedEventArgs e)
        {
            string uri   = addressBox.Text.Trim();
            string login = loginBox.Text.Trim();
            string pass  = passBox.Password.Trim();

            string[]     r     = { };
            EntryControl entry = null;

            if (!(uri.StartsWith("ftp://")))
            {
                addressBox.Text = "ftp://" + addressBox.Text;
                uri             = addressBox.Text;
            }
            if (!(uri.EndsWith("/")))
            {
                addressBox.Text = addressBox.Text + "/";
                uri             = addressBox.Text;
            }

            try
            {
                ripple.Visibility = Visibility.Visible;
                statusBox.Text    = "Connecting...";
                await Task.Run(() =>
                {
                    try
                    {
                        client = new FtpClient.Client(uri, login, pass);
                        r      = client.ListDirectoryDetails();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                });

                Cursor            = Cursors.Arrow;
                ripple.Visibility = Visibility.Hidden;

                Regex regex = new Regex(@"^([d-])([rwxt-]{3}){3}\s+\d{1,}\s+.*?(\d{1,})\s+(\w+\s+\d{1,2}\s+(?:\d{4})?)(\d{1,2}:\d{2})?\s+(.+?)\s?$",
                                        RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
                List <EntryControl> list = r.Select(s =>
                {
                    Match match = regex.Match(s);
                    if (match.Length > 5)
                    {
                        string type = match.Groups[1].Value == "d" ? "dir" : "file";
                        string img  = "";
                        string ext  = Path.GetExtension(match.Groups[6].Value).Trim('.').ToLower();
                        #region Extension check
                        if (type == "dir")
                        {
                            img = "img/folder.png";
                        }
                        else if (picExt.Contains(ext))
                        {
                            img = picExt[0];
                        }
                        else if (archiveExt.Contains(ext))
                        {
                            img = archiveExt[0];
                        }
                        else if (docsExt.Contains(ext))
                        {
                            img = docsExt[0];
                        }
                        else if (sheetsExt.Contains(ext))
                        {
                            img = sheetsExt[0];
                        }
                        else if (musicExt.Contains(ext))
                        {
                            img = musicExt[0];
                        }
                        else if (videoExt.Contains(ext))
                        {
                            img = videoExt[0];
                        }
                        else if (ext == "txt")
                        {
                            img = "img/txt.png";
                        }
                        else if (ext == "pdf")
                        {
                            img = "img/pdf.png";
                        }
                        else
                        {
                            img = "img/file.png";
                        }
                        #endregion
                        string size = "";
                        if (type == "file")
                        {
                            size = string.Format("{0:n0}", (Int64.Parse(match.Groups[3].Value.Trim()) / 1024)) + " KB";
                        }
                        entry = new EntryControl(size, type, match.Groups[6].Value, match.Groups[4].Value, img, uri);
                        entry.MouseDoubleClick += FolderClick;
                        return(entry);
                    }
                    else
                    {
                        return(new EntryControl());
                    }
                }).ToList();
                if (!(uri.Count(c => c == '/') <= 3))
                {
                    entry = new EntryControl("", "up", "..", "", "img/up.png", uri);
                    entry.MouseDoubleClick += FolderClick;
                    list.Add(entry);
                }
                list.Reverse();

                filesList.Items.Clear();
                foreach (EntryControl entryControl in list)
                {
                    filesList.Items.Add(entryControl);
                    if (entryControl.Type == "dir")
                    {
                        entryControl.ContextMenu = this.FindResource("cmFolder") as ContextMenu;
                    }
                    else
                    {
                        entryControl.ContextMenu = this.FindResource("cmFile") as ContextMenu;
                    }
                }
                statusBox.Text = status;
                status         = "";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString() + ": \n" + ex.Message);
            }
        }