예제 #1
0
        protected override async void OnClick()
        {
            try
            {
                PatcherService.ChangeEnableState(this, false);
                if (_workingEvent.WaitOne(0) && !CancelEvent.WaitOne(0))
                {
                    Label = "Отмена...";
                    CancelEvent.Set();
                    return;
                }

                string label = Label;
                try
                {
                    await DoAction();
                }
                finally
                {
                    _workingEvent.Reset();
                    CancelEvent.Reset();
                    Label = label;
                }
            }
            catch (Exception ex)
            {
                UiHelper.ShowError(this, ex);
            }
            finally
            {
                PatcherService.ChangeEnableState(this, true);
            }
        }
예제 #2
0
        public async Task Encrypt(Stream input, Stream output)
        {
            _aes.GenerateIV();

            if (_cancelEvent.IsSet())
            {
                return;
            }

            byte[] vector       = _aes.IV;
            byte[] vectorLength = BitConverter.GetBytes(vector.Length);
            output.Write(vectorLength, 0, 4);
            output.Write(vector, 0, vector.Length);

            if (_cancelEvent.IsSet())
            {
                return;
            }

            using (ICryptoTransform encryptor = _aes.CreateEncryptor())
                using (CryptoStream encryptionStream = new CryptoStream(output, encryptor, CryptoStreamMode.Write))
                {
                    if (_cancelEvent.IsSet())
                    {
                        return;
                    }

                    await PatcherService.CopyAsync(input, encryptionStream, _cancelEvent, Progress);

                    encryptionStream.FlushFinalBlock();
                }
        }
예제 #3
0
        private async Task Download(String url, Stream output)
        {
            if (_cancelEvent.WaitOne(0))
            {
                return;
            }

            using (HttpClient client = new HttpClient())
                using (Stream input = await client.GetStreamAsync(url))
                    await PatcherService.CopyAsync(input, output, _cancelEvent, DownloadProgress);
        }
예제 #4
0
        private async Task Patch(DirectoryInfo translationDir)
        {
            Position = 0;

            if (CancelEvent.IsSet())
                return;

            FFXIIIGamePart gamePart = FFXIIIGamePart.Part1; // TODO
            InteractionService.SetGamePart(gamePart);

            String configurationFilePath = Path.Combine(translationDir.FullName, PatcherService.ConfigurationFileName);
            XmlElement config = XmlHelper.LoadDocument(configurationFilePath);
            LocalizatorEnvironmentInfo info = LocalizatorEnvironmentInfo.FromXml(config["LocalizatorEnvironment"]);
            info.Validate();

            LocalizatorEnvironmentInfo currentInfo = InteractionService.LocalizatorEnvironment.Provide();
            currentInfo.UpdateUrls(info);

            InteractionService.LocalizatorEnvironment.SetValue(currentInfo);
            InteractionService.WorkingLocation.SetValue(new WorkingLocationInfo(translationDir.FullName));

            if (currentInfo.IsIncompatible(typeof(App).Assembly.GetName().Version))
            {
                if (MessageBox.Show(this.GetParentElement<Window>(), "Ваша версия программы установки несовместима с текущим перевод. Обновить?", "Ошибка!", MessageBoxButton.YesNo, MessageBoxImage.Error) != MessageBoxResult.Yes)
                    return;

                string path = await DownloadLatestPatcher();
                DirectoryInfo updatePath = ExtractZipToTempFolder(path);
                string destination = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\');

                string patcherPath = Path.Combine(updatePath.FullName, "Pulse.Patcher.exe");
                ProcessStartInfo procInfo = new ProcessStartInfo(patcherPath, $"/u \"{destination}\"")
                {
                    CreateNoWindow = true,
                    UseShellExecute = false,
                    WorkingDirectory = updatePath.FullName
                };
                
                Process.Start(procInfo);
                Environment.Exit(0);
            }

            if (CancelEvent.IsSet())
                return;

            GameLocationInfo gameLocation = PatcherService.GetGameLocation(gamePart);
            await Task.Run(() => Patch(translationDir, gameLocation));
        }
예제 #5
0
        public async Task Decrypt(Stream input, Stream output)
        {
            _aes.IV = input.EnsureRead(BitConverter.ToInt32(input.EnsureRead(4), 0));
            Progress.NullSafeInvoke(4);

            using (ICryptoTransform decryptor = _aes.CreateDecryptor())
                using (CryptoStream encryptionStream = new CryptoStream(input, decryptor, CryptoStreamMode.Read))
                {
                    if (_cancelEvent.IsSet())
                    {
                        return;
                    }

                    await PatcherService.CopyAsync(encryptionStream, output, _cancelEvent, Progress);
                }
        }
예제 #6
0
        protected override async Task DoAction()
        {
            Label = PlayingLabel;
            try
            {
                Maximum = 2;

                GameLocationInfo gameLocation = PatcherService.GetGameLocation(FFXIIIGamePart.Part1);
                gameLocation.Validate();
                Position = 1;

                if (CancelEvent.WaitOne(0))
                {
                    return;
                }

                if (MusicPlayer != null && MusicPlayer.PlaybackState == NAudio.Wave.PlaybackState.Playing)
                {
                    MusicPlayer.Pause();
                }

                String args = GameSettings.GetGameProcessArguments();

                await Task.Factory.StartNew(() => Process.Start(gameLocation.ExecutablePath, args));

                Position = 2;

                if (InteractionService.LocalizatorEnvironment.Provide().ExitAfterRunGame)
                {
                    Application.Current.MainWindow.Close();
                }
            }
            finally
            {
                Label = PlayLabel;
            }
        }
예제 #7
0
 private void OnDispatcherShutdownStarted(object sender, EventArgs e)
 {
     PatcherService.UnregisterControl(this);
 }
예제 #8
0
 private void OnLoaded(object sender, RoutedEventArgs e)
 {
     PatcherService.RegisterControl(this);
 }
예제 #9
0
 private void OnDispatcherShutdownStarted(object sender, EventArgs e)
 {
     _progressThread.Dispose();
     _progressThread = null;
     PatcherService.UnregisterControl(this);
 }
예제 #10
0
 private void OnLoaded(object sender, RoutedEventArgs e)
 {
     _progressThread = new TimeoutAction(DrawProgressBar, 25);
     PatcherService.RegisterControl(this);
 }