Ejemplo n.º 1
0
        private void OpenSharedFileButton_Click(object sender, RoutedEventArgs e)
        {
            if (Tree.SelectedItem != null)
            {
                string         filePath       = ((TreeViewItem)Tree.SelectedItem).Tag.ToString();
                FileAttributes fileAttributes = File.GetAttributes(filePath);
                if (fileAttributes.HasFlag(FileAttributes.Directory))
                {
                    MessageBox.Show("You must select a file!");
                    return;
                }

                try
                {
                    UserActions.openSharedFile(filePath);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error!");
                    return;
                }
            }
            else
            {
                MessageBox.Show("No file has been selected");
                return;
            }
        }
Ejemplo n.º 2
0
        private void UploadButton_Click(object sender, RoutedEventArgs e)
        {
            if (Tree.SelectedItem != null)
            {
                string         filePath       = ((TreeViewItem)Tree.SelectedItem).Tag.ToString();
                FileAttributes fileAttributes = File.GetAttributes(filePath);
                if (!fileAttributes.HasFlag(FileAttributes.Directory))
                {
                    MessageBox.Show("You must select a folder!");
                    return;
                }
                OpenFileDialog dialog = new OpenFileDialog();
                FileStream     fileStream;

                if (dialog.ShowDialog() == true)
                {
                    if ((fileStream = (FileStream)dialog.OpenFile()) != null)
                    {
                        UserActions.uploadFile(fileStream.Name, filePath);
                    }
                }
            }
            else
            {
                MessageBox.Show("No folder selected!");
            }
            refresh();
        }
Ejemplo n.º 3
0
 private void OpenButton_Click(object sender, RoutedEventArgs e)
 {
     if (Tree.SelectedItem != null)
     {
         string         filePath       = ((TreeViewItem)Tree.SelectedItem).Tag.ToString();
         FileAttributes fileAttributes = File.GetAttributes(filePath);
         if (fileAttributes.HasFlag(FileAttributes.Directory))
         {
             MessageBox.Show("You must select a file!");
             return;
         }
         //success
         UserActions.openFile(filePath);
     }
     else
     {
         MessageBox.Show("No file has been selected");
         return;
     }
     refresh();
 }
Ejemplo n.º 4
0
 private void EditButton_Click(object sender, RoutedEventArgs e)
 {
     if (Tree.SelectedItem != null)
     {
         string         filePath       = ((TreeViewItem)Tree.SelectedItem).Tag.ToString();
         FileAttributes fileAttributes = File.GetAttributes(filePath);
         if (!fileAttributes.HasFlag(FileAttributes.Directory) && System.IO.Path.GetExtension(filePath).ToString() == ".txt")
         {
             UserActions.editFile(filePath);
         }
         else
         {
             MessageBox.Show("You must select a text file!");
         }
     }
     else
     {
         MessageBox.Show("No file selected");
         return;
     }
     refresh();
 }
Ejemplo n.º 5
0
        private void ShareFileButton_Click(object sender, RoutedEventArgs e)
        {
            if (Tree.SelectedItem != null)
            {
                string filePath = ((TreeViewItem)Tree.SelectedItem).Tag.ToString();

                FileAttributes fileAttributes = File.GetAttributes(filePath);
                if (fileAttributes.HasFlag(FileAttributes.Directory))
                {
                    MessageBox.Show("You must select a file!");
                    return;
                }
                ShareFileWindow shareFileWindow = new ShareFileWindow();
                shareFileWindow.ShowDialog();

                string targetUser = ((ShareFileWindow)Application.Current.MainWindow).userComboBox.SelectedItem.ToString();
                Application.Current.MainWindow.Close();
                Application.Current.MainWindow = this;

                //sign it and encrypt with public key of the target
                //and place file in the shared folder
                try
                {
                    UserActions.shareFile(filePath, targetUser);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
            }
            else
            {
                MessageBox.Show("No file has been selected");
                return;
            }
            refresh();
        }
Ejemplo n.º 6
0
        private void NewTextFileButton_Click(object sender, RoutedEventArgs e)
        {
            if (Tree.SelectedItem != null)
            {
                string         filePath       = ((TreeViewItem)Tree.SelectedItem).Tag.ToString();
                FileAttributes fileAttributes = File.GetAttributes(filePath);
                if (!fileAttributes.HasFlag(FileAttributes.Directory))
                {
                    MessageBox.Show("You must select a folder!");
                    return;
                }


                NewFileWindow window = new NewFileWindow();


                window.ShowDialog();
                string content  = ((NewFileWindow)Application.Current.MainWindow).Content.Text;
                string fileName = ((NewFileWindow)Application.Current.MainWindow).Title.Text;


                Application.Current.MainWindow = this;
                if (File.Exists(filePath + "\\" + fileName))
                {
                    MessageBox.Show("File with the same name on that location already exists");
                    return;
                }
                ///sucess
                UserActions.createNewTextFile(content, fileName, filePath);
            }
            else
            {
                MessageBox.Show("No location has been selected");
                return;
            }
            refresh();
        }