Exemplo n.º 1
0
        public async Task ApplyPatchesAsync()
        {
            var processor = new PatchProcessor();

            processor.PatchProgressChanged += delegate(object sender, PatchProcessor.PatchProgressEventArgs e)
            {
                var percentage = int.Parse(Math.Truncate((double)e.Current / e.All * 100).ToString(CultureInfo.InvariantCulture));
                SetPatchInfo(e.ContentType, $"Применение: {percentage}%");
            };

            processor.PatchApplied += delegate(object sender, PatchProcessor.PatchAppliedEventArgs e)
            {
                SetPatchInfo(e.ContentType, e.Errors < 0 ? "Неудача" : "Успех");
            };

            var results = await processor.PatchAsync(SwapManager.EntityA.DatController, _patch.Patches.Values);

            _patch.Scan();

            Unlock();
            Dispatcher.Invoke(() =>
            {
                if (results.Count > 0)
                {
                    if (results.Any(x => x.Value == -2))
                    {
                        _message.ShowMonolog(MessageType.Red, StaticData.OldClientDat);
                        Application.Current.Shutdown();
                        return;
                    }

                    string summary;
                    _message.ShowMonolog(
                        !Utils.PreparePatchMessage(results, out summary) ? MessageType.Red : MessageType.Blue, summary,
                        "Отчёт");
                }
            });
        }