public void UpdateQueue(MegaFileDownload d)
        {
            lock (downloadQueue)
            {
                d.Finished              = true;
                d.ProgressBar.Tag       = null;
                d.ProgressBar.Value     = 0;
                d.ProgressLabel.Visible = false;

                if (downloadQueue.Count > 0 && !cancellationTokenSource.IsCancellationRequested)
                {
                    //if (d.ProgressBar.Tag == null)
                    //{
                    MegaFileDownload newd = downloadQueue.Dequeue();
                    newd.ProgressBar   = d.ProgressBar;
                    newd.ProgressLabel = d.ProgressLabel;
                    newd.StartDownload();
                    //}
                }
                if (finishedDownloads == downloads.Count && !cancellationTokenSource.IsCancellationRequested)
                {
                    DownloadsFinishedForm downloadsFinishedForm = new DownloadsFinishedForm(downloadFolderPath, "All downloads are finished!");
                    downloadsFinishedForm.Show();
                }
            }
            finishedDownloads++;
            progresslabels[progresslabels.Length - 1].Text = $"{finishedDownloads}/{downloads.Count} files finished";
        }
        void CreateJdLinkcontainer()
        {
            DirectoryInfo di = new DirectoryInfo("Links");

            if (checkedFiles.Count == 0)
            {
                MessageBox.Show("No files checked!");
                return;
            }
            Directory.CreateDirectory("Links");
            List <JDPackage> packages = new List <JDPackage>();

            if (cloudServiceType == CloudServiceType.Mega && megaApiClient == null)
            {
                megaApiClient = new MegaApiClient();
                megaApiClient.LoginAnonymous();
            }

            foreach (CloudFile file in checkedFiles)
            {
                string    folderPath = file.Path.Replace(file.Name, "");
                JDPackage pak;
                if (!packages.ConvertAll(x => x.name).Contains(folderPath))
                {
                    pak                = new JDPackage(folderPath, folderPath);
                    pak.numberId       = packages.Count.ToString("D3");
                    pak.downloadFolder = folderPath;
                    packages.Add(pak);
                    File.WriteAllText("Links" + @"\" + pak.numberId, JsonConvert.SerializeObject(pak));
                }
                else
                {
                    pak = packages.Find(x => x.name == folderPath);
                }
                JDLink link;
                switch (cloudServiceType)
                {
                case CloudServiceType.Mega:
                    //string downloadLink = ""; //megaApiClient.GetDownloadLink(file.MegaNode).ToString();
                    link = new JDLink(file.Name, file.PublicUrl.OriginalString);
                    break;

                case CloudServiceType.Yadisk:
                    YandexDiskSharp.RestClient restClient = new YandexDiskSharp.RestClient();
                    string downloadLink = restClient.GetPublicResourceDownloadLink(rootFolder.PublicKey, file.Path).Href.ToString();
                    link = new JDLink(file.Name, downloadLink);
                    break;

                default:
                    link = new JDLink(file.Name, file.PublicUrl.OriginalString);
                    break;
                }
                link.downloadLink.size = (int)file.Size;
                File.WriteAllText("Links" + @"\" + pak.numberId + "_" + pak.linksCount.ToString("D3"), JsonConvert.SerializeObject(link));
                pak.linksCount++;
            }

            DialogResult dialogResult = MessageBox.Show("Got links for " + (checkedFiles.Count) + " files! Continue?", "Result", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.No)
            {
                return;
            }

            Random rnd    = new Random();
            int    number = rnd.Next(1, 9999);

            string rootFolderName = rootFolder.Name;

            foreach (char c in Path.GetInvalidFileNameChars())
            {
                rootFolderName = rootFolderName.Replace(c.ToString(), "");
            }

            string dirPath = @"linkcontainers\" + rootFolderName;

            Directory.CreateDirectory(dirPath);
            System.IO.Compression.ZipFile.CreateFromDirectory("Links", dirPath + @"\linkcollector" + number + ".zip");

            foreach (FileInfo file in di.EnumerateFiles())
            {
                file.Delete();
            }
            foreach (DirectoryInfo dir in di.EnumerateDirectories())
            {
                dir.Delete(true);
            }
            Directory.Delete("Links");

            DownloadsFinishedForm downloadsFinishedForm = new DownloadsFinishedForm(dirPath, @"linkcollector" + number + ".zip created!");

            downloadsFinishedForm.Show();
        }