예제 #1
0
        public override async Task DownloadGameFiles(Progress <PatchProgress> progress)
        {
            await base.DownloadGameFiles(progress);

            GetMirrors();

            if (status == PatcherStatus.MirrorsFailure)
            {
                return;
            }

            var tasks = new List <Task>();

            ct = cts.Token;
            patchProgress.NewWork(progress, filesToUpdate.Count + filesNeeded.Count);

            foreach (var file in filesToUpdate)
            {
                RewrittenPatch patchInfo = file.Value;
                tasks.Add(Task.Run(() => AcquireFileAsync(patchInfo.Filename, patchInfo.CompPatchHash), ct)
                          .ContinueWith(_ => patchProgress.FileProcessed(progress, ct)));
            }

            foreach (var file in filesNeeded)
            {
                RewrittenFile fileInfo = file.Value;
                tasks.Add(Task.Run(() => AcquireFileAsync(fileInfo.Dl, fileInfo.Hash), ct)
                          .ContinueWith(_ => patchProgress.FileProcessed(progress, ct)));
            }

            await Task.WhenAll(tasks);
        }
예제 #2
0
        public override void CheckGameFiles(Progress <PatchProgress> progress)
        {
            base.CheckGameFiles(progress);

            patchProgress.NewWork(progress, patchManifest.Count);
            string gamePath = config.RewrittenPath;

            foreach (var file in patchManifest)
            {
                RewrittenFile fileObject = file.Value;

                //meh
                patchProgress.FileProcessed(progress);

                if (!fileObject.Only.Contains("win64"))
                {
                    continue;
                }

                bool   hasPatchAvailable = false;
                string localFile         = gamePath + file.Key;

                if (File.Exists(localFile))
                {
                    string fileHash = GamePatchUtils.GetSha1FileHash(localFile);

                    if (fileHash == fileObject.Hash)
                    {
                        continue;
                    }

                    foreach (var patch in fileObject.Patches)
                    {
                        if (fileHash == patch.Key)
                        {
                            hasPatchAvailable         = true;
                            patch.Value.FinalFileHash = fileObject.Hash;
                            filesToUpdate.Add(file.Key, patch.Value);
                            break;
                        }
                    }
                }

                if (!hasPatchAvailable)
                {
                    filesNeeded.Add(file.Key, file.Value);
                }
            }
        }
예제 #3
0
        public override void PatchGameFiles(Progress <PatchProgress> progress)
        {
            base.PatchGameFiles(progress);

            string rewrittenPath = config.RewrittenPath;

            patchProgress.NewWork(progress, filesToUpdate.Count + filesNeeded.Count);

            foreach (var file in filesToUpdate)
            {
                string         fileName  = file.Key;
                RewrittenPatch patchInfo = file.Value;

                string localFilePath     = rewrittenPath + fileName;
                string extractedFilePath = rewrittenPath + patchInfo.Filename + ".extracted";

                GamePatchUtils.Patch(extractedFilePath, localFilePath);
                string patchedFilePath = localFilePath + ".tmp";

                if (GamePatchUtils.FileIsCorrect(patchedFilePath, patchInfo.FinalFileHash))
                {
                    File.Delete(localFilePath);
                    File.Move(patchedFilePath, localFilePath);
                    patchProgress.FileProcessed(progress);
                }
                else
                {
                    File.Delete(patchedFilePath);
                    status = PatcherStatus.PatchFailure;
                }
                File.Delete(extractedFilePath);
            }

            foreach (var file in filesNeeded)
            {
                string        filename = file.Key;
                RewrittenFile fileInfo = file.Value;

                string localFilePath     = rewrittenPath + filename;
                string extractedFilePath = rewrittenPath + fileInfo.Dl + ".extracted";

                File.Delete(localFilePath);
                File.Move(extractedFilePath, localFilePath);

                patchProgress.FileProcessed(progress);
            }
        }