private void buttonCreateTorrent_Click(object sender, EventArgs e)
        {
            string path;

            // Open the file dialog
            OpenFileDialog file = new OpenFileDialog();

            if (file.ShowDialog() == DialogResult.OK)
            {
                // Get the path
                path = file.FileName;

                // Create and show the create torrent dialog
                CreateTorrentDialog createTorrentDialog = new CreateTorrentDialog(path);
                createTorrentDialog.ShowDialog();

                // If yes is clicked
                if (createTorrentDialog.DialogResult == DialogResult.Yes)
                {
                    // Variable for the user whether they want to show the torrent file on completion
                    bool showFile = createTorrentDialog.ShowFile();
                    createTorrentDialog.Close();

                    // Create and show the loading form
                    LoadingForm loadingForm = new LoadingForm(showFile);
                    loadingForm.StartPosition = FormStartPosition.CenterParent;
                    loadingForm.id            = id;
                    loadingForm.path          = path;
                    loadingForm.ShowDialog(this);

                    // If the loading form completed as normal
                    if (loadingForm.DialogResult == DialogResult.OK)
                    {
                        // Close the form and create a new torrentfile instance
                        string filePath = loadingForm.createdFilePath;
                        loadingForm.Close();
                        torrentFile = new TorrentFile(id, manager.ip, manager.port, uIUpdater);

                        // Open the torrent file and add to the list
                        if (torrentFile.Read(filePath))
                        {
                            manager.torrentFiles.Add(torrentFile);
                            VerifyFile(torrentFile);
                        }
                    }

                    // else the process failed
                    else
                    {
                        loadingForm.Close();
                        MessageBox.Show("Failed to create torrent file");
                    }
                }
            }
        }
        public void CheckFiles()
        {
            startServerMode();

            VerifyTorrentDialog verifyTorrent = new VerifyTorrentDialog();


            while (!manager.connected)
            {
            }

            // Set the path to find torrent files within the ID directory of this user
            string path = System.IO.Directory.GetCurrentDirectory();

            path = path + "\\" + id + "\\TorrentFiles";

            // If the directory exists, then check for files
            if (Directory.Exists(path))
            {
                // For each file in the directory

                verifyTorrent.StartPosition = FormStartPosition.CenterParent;
                verifyTorrent.Show(this);

                foreach (string file in Directory.EnumerateFiles(path, "*.txt"))
                {
                    verifyTorrent.Refresh();
                    // Create a torrentFile instance
                    TorrentFile torrentFile21 = new TorrentFile(id, manager.ip, manager.port, uIUpdater);
                    verifyTorrent.SetFile(torrentFile21.fileName);
                    // read the file into the instance
                    if (torrentFile21.Read(file))
                    {
                        // Add to the torrentfile list and check what parts of the file have been downloaded
                        manager.torrentFiles.Add(torrentFile21);
                        VerifyFile(torrentFile21);
                    }
                }

                verifyTorrent.Close();
            }
        }
        private void buttonFileSelect_Click(object sender, EventArgs e)
        {
            string path;

            // Open a file dialog to select a torrent file
            OpenFileDialog file = new OpenFileDialog();

            if (file.ShowDialog() == DialogResult.OK)
            {
                path = file.FileName;

                // Create a new instance of a torrentfile
                torrentFile = new TorrentFile(id, manager.ip, manager.port, uIUpdater);

                // If the file is read
                if (torrentFile.Read(path))
                {
                    // Start the listener if it is not already
                    if (!manager.connected)
                    {
                        startServerMode();
                    }

                    else
                    {
                        // Check to make sure this torrent file is not already in use in the program
                        if (!manager.CheckTorrentFileDownloading(torrentFile))
                        {
                            // If not add to the list and verify what parts of the file are downloaded
                            manager.torrentFiles.Add(torrentFile);
                            VerifyFile(torrentFile);
                        }

                        else
                        {
                            MessageBox.Show("File is already downloading");
                        }
                    }
                }
            }
        }