コード例 #1
0
ファイル: frmMain.cs プロジェクト: z3nth10n/HugeLauncher
        public PhaseManager(PackType t, params DownloadPack[] dls)
        {
            instance = this;
            _Type    = t;

            foreach (DownloadPack dl in dls)
            {
                Packs.Enqueue(dl);
            }

            NextDownload = (dl) =>
            {
                DownloadManager.StartDownload(frmMain.mainInstance, dl.col, _Type, dl.TotalBytes);
            };

            DownloadManager.DownloadCompleted += (comp) =>
            {
                if (comp)
                {
                    NextDownload?.Invoke(Dequeue());
                    Console.WriteLine("Download queue finished, starting a new phase!");
                }
                else
                {
                    Console.WriteLine("Finished a download, waiting to until the end.");
                }
            };
        }
コード例 #2
0
ファイル: frmMain.cs プロジェクト: z3nth10n/HugeLauncher
        private static void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            form.BeginInvoke((MethodInvoker) delegate
            {
                if (timer == null)
                {
                    timer       = new Timer();
                    timer.Tick += (sender1, e1) =>
                    {
                        double downloadRate = CurByteValue - LastByteValue;
                        LastByteValue       = CurByteValue;
                        AvByteValue        += Math.Abs(downloadRate);
                        ++loop;

                        double currentRate = AvByteValue / loop;

                        lblMetrics.Text = string.Format("ETA: {0}; Download rate: {1}/s", currentRate > 0 ? TimeSpan.FromSeconds((int)Math.Truncate(TotalBytes / currentRate)).ToString(@"hh\h\ mm\m\ ss\s") : "Inf", currentRate.BytesToString());
                    };
                    timer.Interval = 1000;
                    timer.Start();
                }

                try
                {
                    if (cancellingDownload)
                    {
                        client.DownloadProgressChanged -= new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                        client.DownloadFileCompleted   -= new AsyncCompletedEventHandler(client_DownloadFileCompleted);
                        client.Dispose();
                        _downloads = null;
                        return;
                    }
                    double phasePercentage = (double)CurFilesCount / FileLength * 100,
                    totalPercentage        = PhaseManager.GetSummedValue(),
                    percentage             = (double)e.BytesReceived / e.TotalBytesToReceive * 100;

                    string fileName = Path.GetFileName(curDownload.Path);

                    lblFileProgress.Text  = string.Format("Downloaded {0} of {1} ({2:F2}%) ", e.BytesReceived.BytesToString(), e.TotalBytesToReceive.BytesToString(), percentage);
                    pbFileProgress.Value  = (int)Math.Truncate(percentage);
                    lblTotalProgress.Text = string.Format("Fase {0}: {1} de {2} archivos descargados ({3:F2}%)\nArchivo: {4} (Total: {5:F2}%)", PhaseManager.PackIndex, CurFilesCount, FileLength, phasePercentage, fileName.GetFileStr(), totalPercentage);
                    pbTotalProgress.Value = (int)Math.Truncate(totalPercentage);

                    CurByteValue = e.BytesReceived;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception occurred! Message:\n\n{0}", ex.ToString());
                }
            });
        }
コード例 #3
0
ファイル: frmMain.cs プロジェクト: z3nth10n/HugeLauncher
        private void DownloadData(PackType type)
        {
            downloadingData = true;

            frmDescription.instance.Hide();

            int    index            = comboBox1.SelectedIndex;
            string path             = GetFolderPathVer(index, type);
            JToken verObj           = GetVersion(index, type);
            JEnumerable <JToken> dl = verObj["Files"].Children();

            if (type == PackType.Client)
            {
                btnRuninsClient.Text = "Cancelar instalacion";
            }
            else
            {
                btnRunisServer.Text = "Cancelar instalacion";
            }

            //Set maximums
            pbFileProgress.Maximum  = 100; //verObj["TotalSize"].ToObject<int>();
            pbTotalProgress.Maximum = 100;

            PhaseManager.PhaseCompleted += (i) =>
            {
                switch (i)
                {       //Do something special when...
                case 0: //... Modpack downloaded
                    break;

                case 1:     //... TLauncher Files downloaded
                    break;

                case 2:     //... TLauncher Config downloaded
                    ModifyMCLProperties(LauncherFolderPath);
                    break;
                }
            };

            PhaseManager phase = new PhaseManager(type,
                                                  new DownloadPack(verObj["TotalSize"].ToObject <long>(),
                                                                   dl.Select(token =>
            {
                return(new DownloadPath(new Uri(token["FileUrl"].ToObject <string>()), Path.Combine(path, token["FileRelPath"].ToObject <string>())));
            })
                                                                   ),
                                                  new DownloadPack(TLauncherData, LauncherFolderPath));

            //Check if appdata folder exists and if not add download and then do the following or if it exists modify the value from the config to another one

            if (!File.Exists(MCLPath))
            {
                PhaseManager.instance.AddDownload(new DownloadPack(TLauncherConfig, Path.GetDirectoryName(MCLPath)));
            }
            else
            {
                ModifyMCLProperties(LauncherFolderPath);
            }

            phase.Download(1);
        }