public PatchHistoryFetchLoadingScreen()
        {
            latestPatchHistoryPath = NetworkObjectParameters.LatestPatchHistoryPath;

            HttpWebRequest.AsyncDownloadFile(
                NetworkObjectParameters.BuildFetchHistoryURL(),
                latestPatchHistoryPath,
                onFailToDownload: OnFailToDownload,
                onFinishDownload: OnFinishDownload
                );
        }
示例#2
0
        private void updateButton_Click(object sender, EventArgs e)
        {
            //If someone attempt to shut down the updater before it has finished.
            FormClosing += abortButton_Click;

            Queue<Action> actQueue = new Queue<Action>();
            List<PatchHistory> downloadedFileList = new List<PatchHistory>();

            InsertOnLogListBox(Language.Patching1Downloading);

            string patchDir = @$"{Directory.GetCurrentDirectory()}\{NetworkObjectParameters.PatchTemporaryPath}\";

            Directory.CreateDirectory(patchDir);

            foreach (PatchHistory pH in patchesToBeDownloaded)
            {
                actQueue.Enqueue(() =>
                {
                    DateTime downloadStartTime = DateTime.Now;

                    InsertOnLogListBox($"{Language.Patching2Downloading} {pH.BuildPatchPath}");

                    UpdateMenuLabels(MenuState.Downloading, new Dictionary<string, string>()
                    {
                        { "filename", pH.BuildPatchPath },
                        { "current", $"{currentDownloadedFile + 1}" },
                        { "total", $"{patchesToBeDownloaded.Count}" },

                        { "remaining", "0" },
                        { "downloaded", "0" },
                        { "speed", "0" }
                    });

                    currentProgressBar.Value = 0;

                    HttpWebRequest.AsyncDownloadFile(
                        $@"{NetworkObjectParameters.BuildGamePatchURL()}/{pH.BuildPatchPath}",
                        $@"{patchDir}\{pH.BuildPatchPath}",
                        onReceiveData: 
                            (percentage, receivedBytes, totalBytes) =>
                            {
                                OnReceiveData(pH.BuildPatchPath, currentDownloadedFile, percentage, receivedBytes, totalBytes, downloadStartTime);
                            },
                        onReceiveLastData: () => { OnFinalizeDownloadingFile(actQueue, pH); },
                        onFailToDownload: (ex) => { OnFailToDownloadPatch(ex, pH); });
                });
            }

            //Start triggeting the asynchronous callback hell
            actQueue.Dequeue().Invoke();
        }