예제 #1
0
        public MainWindow(string pso2BinPath, UpdateChecker.UpdateInformation updateInformation)
        {
            InitializeComponent();

            _ViewModel  = new MainWindowViewModel(pso2BinPath, updateInformation);
            DataContext = _ViewModel;
        }
예제 #2
0
        public InstallSelectorWindow(InstallSelectorWindowViewModel viewModel, UpdateChecker.UpdateInformation updateInformation)
        {
            _UpdateInformation = updateInformation;

            InitializeComponent();

            _ViewModel  = viewModel;
            DataContext = _ViewModel;
        }
예제 #3
0
        private async Task <bool> _UpdateClientAsync(UpdateChecker.UpdateInformation updateInformation)
        {
            if (updateInformation.ExecutableAsset == null)
            {
                var manualUpdateResult = MessageBox.Show(
                    LocaleManager.Instance["Astra_ManualUpdate_WindowMessage"],
                    LocaleManager.Instance["PSRTAstra"],
                    MessageBoxButton.YesNo,
                    MessageBoxImage.Warning);

                if (manualUpdateResult == MessageBoxResult.Yes)
                {
                    Process.Start(updateInformation.GitHubUri.AbsoluteUri);
                    return(false);
                }
            }
            else
            {
                Logger.Info(nameof(App), "Updating Astra");
                try
                {
                    var executableLocation = Assembly.GetExecutingAssembly().Location;
                    if (Path.GetExtension(executableLocation) != ".exe")
                    {
                        throw new Exception($"Astra executable under the name \"{executableLocation}\" must end with a .exe file extension");
                    }
                    var oldExecutableLocation = $"{executableLocation}.old";

                    using (var client = new GitHubHttpClient())
                    {
                        var data = await client.GetByteArrayAsync(updateInformation.ExecutableAsset.DownloadUri);

                        File.Move(executableLocation, oldExecutableLocation);
                        var writeUpdateAttempts = 0;
                        while (true)
                        {
                            try
                            {
                                using (var fs = File.Create(executableLocation))
                                    await fs.WriteAsync(data, 0, data.Length);

                                break;
                            }
                            catch (Exception ex) when(ex is IOException || ex is UnauthorizedAccessException)
                            {
                                writeUpdateAttempts++;
                                if (writeUpdateAttempts >= 5)
                                {
                                    throw;
                                }

                                await Task.Delay(1000);
                            }
                        }
                    }

                    // preserve command line arguments on restart
                    var commandLine = Environment.CommandLine
                                      .Replace($"\"{Environment.GetCommandLineArgs()[0]}\"", string.Empty)
                                      .TrimStart();
                    Process.Start(executableLocation, commandLine);
                    return(false);
                }
                catch (Exception ex)
                {
                    Logger.Error(nameof(App), "Error updating Astra", ex);

                    var errorMessageResult = MessageBox.Show(
                        LocaleManager.Instance["Astra_ErrorUpdating_WindowMessage"],
                        LocaleManager.Instance["PSRTAstra"],
                        MessageBoxButton.YesNo,
                        MessageBoxImage.Error);

                    if (errorMessageResult == MessageBoxResult.Yes)
                    {
                        UploadAndOpenLog(ex);
                    }
                }
            }

            var launchAnywayResult = MessageBox.Show(
                LocaleManager.Instance["Astra_LaunchAnyway_WindowMessage"],
                LocaleManager.Instance["PSRTAstra"],
                MessageBoxButton.YesNo,
                MessageBoxImage.Warning);

            return(launchAnywayResult == MessageBoxResult.Yes);
        }
예제 #4
0
        //

        public MainWindowViewModel(string pso2BinDirectory, UpdateChecker.UpdateInformation updateInformation)
        {
            InstallConfiguration      = new InstallConfiguration(pso2BinDirectory);
            UpdatedVersionInformation = updateInformation;
        }