Example #1
0
        public async Task InstallSdk(VirtualFile packedSdk, VirtualDirectory destination, ChangeObservable observable,
                                     bool force)
        {
            using (IEditableSettings editableSettings = settingsProvider.StartSettingTransaction())
            {
                if (!force && destination.Files(searchRecursive: true).Any())
                {
                    throw new FileExistsException(destination.FullName);
                }

                using (IProgressNotifier progressNotifier = Console.IsInputRedirected || Console.IsOutputRedirected ? null : progressVisualizer.Spawn(1, "Install SDK.", null))
                {
                    await fileUnpackService.Unpack(packedSdk, destination, progressNotifier, observable).ConfigureAwait(false);
                }

                editableSettings.AddSetting(Constants.SdkPathsKey, $"{destination.FullName}");
            }
        }
Example #2
0
        public async Task InstallVersion(VirtualFile setup, VirtualDirectory tempDirectory, IProgressNotifier parentProgress = null)
        {
            VirtualDirectory destination = tempDirectory.Directory(Guid.NewGuid().ToByteString());

            using (IProgressNotifier progressNotifier = parentProgress?.Spawn(installationSteps.Count() + 1, "Installing version"))
            {
                await fileUnpackService.Unpack(setup, destination, progressNotifier).ConfigureAwait(false);

                foreach (IInstallationStep installationStep in installationSteps)
                {
                    await installationStep.Install(destination, progressNotifier).ConfigureAwait(false);
                }

                await ReplaceApplication().ConfigureAwait(false);
            }

            async Task ReplaceApplication()
            {
                userInterface.WriteInformation("Replace current version with new version");

                if (environmentService.Platform != OSPlatform.Windows)
                {
                    await destination.CopyToAsync(fileSystem.GetDirectory(environmentService.AssemblyDirectory)).ConfigureAwait(false);

                    tempDirectory.Delete();
                }
                else
                {
                    VirtualFile batchFile       = tempDirectory.File("copy_version.bat");
                    Assembly    currentAssembly = Assembly.GetAssembly(GetType());
                    using (Stream batchResourceStream = currentAssembly.GetManifestResourceStream("PlcNext.Common.Installation.copy_version.bat"))
                        using (Stream batchFileStream = batchFile.OpenWrite())
                        {
                            batchResourceStream?.CopyTo(batchFileStream);
                        }

                    processManager.StartProcess(batchFile.FullName,
                                                $"\"{destination.FullName}\" \"{environmentService.AssemblyDirectory}\" " +
                                                $"\"{tempDirectory.FullName}\" \"{binariesLocator.GetExecutable("application").Name}\"", userInterface, null, showOutput: false, showError: false, killOnDispose: false);
                }
            }
        }