public IActionResult Index() { InstallerViewModel model = new InstallerViewModel(); model.installers = _appContext.installers.Select(m => m).ToList(); return(View(model)); }
private InstallationResultViewModel CreateInstallationResultViewModel(InstallerViewModel parent) { if (parent == null) { throw new ArgumentNullException(nameof(parent)); } return(new InstallationResultViewModel { Parent = parent, InstallerName = parent.FileName, IsDirty = false }); }
public IActionResult Index(InstallerViewModel model) { if (model.attachment != null) { //write file to a physical path var uniqueFileName = model.attachment.FileName; var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "installer"); var filePath = Path.Combine(uploads, uniqueFileName); model.attachment.CopyTo(new FileStream(filePath, FileMode.Create)); //save the attachment to the database Models.Installer_Info attachment = new Models.Installer_Info(); attachment.System = uniqueFileName; attachment.cur_version = model.cur_version; attachment.location = filePath; _appContext.installers.Add(attachment); _appContext.SaveChanges(); } return(RedirectToAction("index")); }
protected override void Run() { try { string[] args = this.Command.GetCommandLineArgs(); bool runIpc = false; bool showPrompts = true; Engine.Log(LogLevel.Standard, $"Arguments: {string.Join(", ", args)}"); foreach (string arg in args) { if (arg == "/ipc") { runIpc = true; } else if (arg == "/nomodals") { showPrompts = false; } else if (arg == "/waitforexit") { WaitForFilterExit = true; } } BootstrapperDispatcher = Dispatcher.CurrentDispatcher; Application app = new Application(); ISetupUI setupUi = null; InstallerViewModel model = new InstallerViewModel(this); // NOTE: This runIpc check can be removed if our current system proves itself. if (runIpc) { if (server == null) { server = new UpdateIPCServer(UpdateIPCServer.PipeName); server.MessageReceived += CheckExit; server.RegisterObject("InstallerViewModel", model); server.Start(); } setupUi = new IpcWindow(server, model, showPrompts); server.RegisterObject("SetupUI", setupUi); server.MessageReceived += CheckStartCommand; // Wait for the first start command to begin installing. setupUi.Closed += (sender, e) => SignalExit(); server.ClientConnected += () => { Engine.Log(LogLevel.Standard, "Resynchronizing UI with new client."); (setupUi as IpcWindow)?.ResynchronizeUI(); }; model.SetSetupUi(setupUi); model.PropertyChanged += (sender, e) => { server.PushMessage(new Message() { Command = IPC.Command.PropertyChanged, Property = e.PropertyName }); }; this.Engine.Detect(); } else { setupUi = new MainWindow(model, showPrompts); setupUi.Closed += (sender, e) => { Engine.Log(LogLevel.Standard, "Closing installer."); BootstrapperDispatcher.BeginInvokeShutdown(DispatcherPriority.Normal); Engine.Log(LogLevel.Standard, "Shutdown invoked."); }; model.SetSetupUi(setupUi); Engine.Detect(); if (Command.Display != Display.None && Command.Display != Display.Embedded) { setupUi.Show(); } Dispatcher.Run(); this.Engine.Quit(0); } } catch (Exception ex) { Engine.Log(LogLevel.Error, "A .NET error occurred while running CloudVeilInstallerUI"); Engine.Log(LogLevel.Error, $"Error Type: {ex.GetType().Name}"); Engine.Log(LogLevel.Error, $"Error info: {ex}"); this.Engine.Quit(1); } }
private async Task UpdateApplicationViewModelAsync(ApplicationViewModel viewModel, Application?application = null) { if (viewModel == null) { throw new ArgumentNullException(nameof(viewModel)); } if (application == null) { if (viewModel.EntityId.IsDefault()) { throw new Exception(Strings.EntityNotFound); } application = _configurationService.Configuration.Applications.FirstOrDefault(af => af.Id == viewModel.EntityId); if (application == null) { throw new Exception(Strings.EntityNotFound); } } viewModel.EntityId = application.Id; viewModel.Name = application.Name; viewModel.EnableSilentInstallation = application.EnableSilentInstallation; viewModel.DisableReboot = application.DisableReboot; viewModel.EnableInstallationLogging = application.EnableInstallationLogging; viewModel.AutomaticallyDeleteInstallationLogs = application.AutomaticallyDeleteInstallationLogs; viewModel.KeepNewestInstallationLogs = application.KeepNewestInstallationLogs; viewModel.FilterDuplicateInstallers = application.FilterDuplicateInstallers; viewModel.ProviderType = application.Configuration?.ProviderType; viewModel.InstallerBundles.Clear(); try { var configuration = application.Configuration; if (configuration == null) { throw new Exception("No configuration is set"); } using var provider = _installerFileBundleProviderFactory.Create(configuration); viewModel.ProviderLink = provider.ProviderLink; var installerBundles = await provider.GetInstallerFileBundlesAsync(); foreach (var installerBundle in installerBundles) { var bundleViewModel = new InstallerBundleViewModel { Parent = viewModel, Name = installerBundle.Name, Created = installerBundle.Created, }; foreach (var installerFile in installerBundle.InstallerFiles) { var installerViewModel = new InstallerViewModel { Parent = bundleViewModel, FileName = installerFile.FileName, Created = installerFile.Created }; installerViewModel.InstallerFileProvider = new InstallerFileProvider(async(filePath, progress, cancellationToken) => { await installerFile.SaveFileAsync(filePath, _msiService, progress, cancellationToken); installerViewModel.Name = installerFile.Name; installerViewModel.Culture = installerFile.Culture.IetfLanguageTag; installerViewModel.Version = installerFile.Version; installerViewModel.ProductCode = installerFile.ProductCode; installerViewModel.IsInstalled = _productService.IsProductInstalled(installerFile.ProductCode); }); installerViewModel.IsDirty = false; bundleViewModel.Installers.Add(installerViewModel); } viewModel.InstallerBundles.Add(bundleViewModel); bundleViewModel.IsDirty = false; } } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception exception) { Log.Error("Getting installer file bundles failed", exception); viewModel.InstallerBundles.Clear(); } #pragma warning restore CA1031 // Do not catch general exception types viewModel.SelectedInstallerBundle = viewModel.InstallerBundles.LastOrDefault(); }
private static InstallationResultViewModel CreateSkippedResult(IViewModelService viewModelService, InstallerViewModel installerViewModel) { var installationResultViewModel = viewModelService.CreateViewModel <InstallationResultViewModel>(installerViewModel); installationResultViewModel.State = InstallationResultState.Skipped; return(installationResultViewModel); }
private static InstallationResultViewModel CreateInstallationFailedResult(IViewModelService viewModelService, InstallerViewModel installerViewModel, Exception exception) { var installationResultViewModel = viewModelService.CreateViewModel <InstallationResultViewModel>(installerViewModel); installationResultViewModel.State = InstallationResultState.InstallationFailed; installationResultViewModel.Exception = viewModelService.CreateViewModel <ExceptionViewModel>(installationResultViewModel, exception); return(installationResultViewModel); }
private static InstallationResultViewModel CreateDownloadFailedResult(IViewModelService viewModelService, InstallerViewModel installerViewModel, IDownloadResult downloadResult) { if (downloadResult.Result != DownloadResultState.Failed) { throw new ArgumentException($"Result is {downloadResult.Result.ToString()}, expected {nameof(DownloadResultState.Failed)}.", nameof(downloadResult)); } Exception exception; if (downloadResult is FailedDownloadResult failedDownloadResult) { exception = failedDownloadResult.Exception; } else { exception = new Exception(Strings.ErrorOccured); Log.Error($"DownloadResult with failed state is not of type {nameof(FailedDownloadResult)}."); } return(CreateDownloadFailedResult(viewModelService, installerViewModel, exception)); }
private static async Task <InstallationResultViewModel> PerformOperation(IViewModelService viewModelService, IInstallService installService, INotificationService notificationService, InstallerViewModel installerViewModel, InstallationViewModel currentInstallationViewModel, string installerFilePath, bool enableSilentInstallation, bool disableReboot, bool enableInstallationLogging, string?logFolderPath = null) { string?installLogFilePath = null; string?uninstallLogFilePath = null; if (enableInstallationLogging) { if (String.IsNullOrEmpty(logFolderPath)) { Log.Warn("Installation logging is enabled but the logFolderPath is null or empty."); } else if (!Directory.Exists(logFolderPath)) { Log.Warn("logFolderPath is set but the directory doesn't exist."); } else { installLogFilePath = GetLogFilePathForInstaller(logFolderPath !, installerViewModel.Name ?? "unkown", "install"); uninstallLogFilePath = GetLogFilePathForInstaller(logFolderPath !, installerViewModel.Name ?? "unkown", "uninstall"); } } var installArguments = GetArguments( enableSilentInstallation, disableReboot, enableInstallationLogging, installLogFilePath).ToArray(); var uninstallArguments = GetArguments( enableSilentInstallation, disableReboot, enableInstallationLogging, uninstallLogFilePath).ToArray(); var installationResultViewModel = viewModelService.CreateViewModel <InstallationResultViewModel>(installerViewModel); try { switch (installerViewModel.SelectedOperation) { case InstallerOperation.Install: if (installerViewModel.IsInstalled != false) { if (installerViewModel.IsInstalled == null) { Log.Warn($"Installation status of file \"{installerViewModel.FileName}\" is unavailable, trying to uninstall."); } else { Log.Info($"The application \"{installerViewModel.Name}\" with ProductCode \"{installerViewModel.ProductCode}\" is already installed. It will now be uninstalled first."); } if (String.IsNullOrWhiteSpace(installerViewModel.ProductCode)) { var exception = new Exception($"Uninstalling \"{installerViewModel.FileName}\" failed: ProductCode is not set."); Log.Error(exception); if (installerViewModel.IsInstalled == true) { return(CreateInstallationFailedResult(viewModelService, installerViewModel, exception)); } } else { Log.Info($"Uninstalling application of installer \"{installerViewModel.FileName}\" now."); currentInstallationViewModel.CurrentOperation = InstallationOperation.Uninstall; if (enableInstallationLogging && uninstallLogFilePath is string) { installationResultViewModel.InstallationLogFilePaths.Add(uninstallLogFilePath); } try { await installService.PerformAsync(new Operation(installerViewModel.ProductCode, OperationType.Uninstall, uninstallArguments)); Log.Info($"Finished uninstalling."); } catch (Exception exception) { // suppress exception if installation status is unknown if (installerViewModel.IsInstalled == true) { throw; } Log.Warn("Uninstalling failed, but since the installation state is unavailable, the operation will continue", exception); } } } Log.Info($"Installing \"{installerViewModel.FileName}\" now."); currentInstallationViewModel.CurrentOperation = InstallationOperation.Install; if (enableInstallationLogging && installLogFilePath is string) { installationResultViewModel.InstallationLogFilePaths.Add(installLogFilePath); } await installService.PerformAsync(new Operation(installerFilePath, OperationType.Install, installArguments)); Log.Info($"Finished installing."); installationResultViewModel.State = InstallationResultState.Success; break; case InstallerOperation.Uninstall: if (installerViewModel.IsInstalled == null) { Log.Warn($"Installation status of file \"{installerViewModel.FileName}\" is unavailable, trying to uninstall."); } else if (installerViewModel.IsInstalled == false) { Log.Warn($"The application \"{installerViewModel.Name}\" with ProductCode \"{installerViewModel.ProductCode}\" is not installed. Trying to uninstall anyways but it will likely fail."); } else { Log.Info($"The application \"{installerViewModel.Name}\" with ProductCode \"{installerViewModel.ProductCode}\" will now be uninstalled."); } if (String.IsNullOrWhiteSpace(installerViewModel.ProductCode)) { var exception = new Exception($"Uninstalling \"{installerViewModel.FileName}\" failed: ProductCode is not set."); Log.Error(exception); return(CreateInstallationFailedResult(viewModelService, installerViewModel, exception)); } Log.Info($"Uninstalling application of installer \"{installerViewModel.FileName}\" now."); currentInstallationViewModel.CurrentOperation = InstallationOperation.Uninstall; if (enableInstallationLogging && uninstallLogFilePath is string) { installationResultViewModel.InstallationLogFilePaths.Add(uninstallLogFilePath); } await installService.PerformAsync(new Operation(installerViewModel.ProductCode, OperationType.Uninstall, uninstallArguments)); Log.Info($"Finished uninstalling."); installationResultViewModel.State = InstallationResultState.Success; break; default: installationResultViewModel.State = InstallationResultState.Skipped; break; } } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception exception) { Log.Error(exception); var errorMessage = installerViewModel.SelectedOperation switch { InstallerOperation.Install => Strings.InstallationOfXFailed, InstallerOperation.Uninstall => Strings.UninstallationOfXFailed, _ => Strings.OperationOfXFailed, }; notificationService.ShowError(String.Format(errorMessage, installerViewModel.Name)); return(CreateInstallationFailedResult(viewModelService, installerViewModel, exception)); } #pragma warning restore CA1031 // Do not catch general exception types return(installationResultViewModel); }
protected override void Run() { try { sentry = SentrySdk.Init(CloudVeil.Windows.CompileSecrets.SentryDsn); } catch { sentry = null; } try { string[] args = this.Command.GetCommandLineArgs(); bool runIpc = false; bool showPrompts = true; Engine.Log(LogLevel.Standard, $"Arguments: {string.Join(", ", args)}"); foreach (string arg in args) { if (arg == "/ipc") { runIpc = true; } else if (arg == "/nomodals") { showPrompts = false; } else if (arg == "/waitforexit") { WaitForFilterExit = true; } else if (arg == "/upgrade") { Updating = true; } else if (arg.Contains("/userid=")) { UserId = arg.Replace("/userid=", ""); } } if (Updating == false && WaitForFilterExit == true) { Updating = true; } if (UserId.Length == 0) { try { var email = new RegistryAuthenticationStorage().UserEmail; var fingerPrint = new WindowsFingerprint().Value; UserId = email + ":" + fingerPrint; Engine.Log(LogLevel.Standard, $"My autoset id: {UserId}"); } catch { Engine.Log(LogLevel.Error, "Can't set User id, probably fresh install"); } } BootstrapperDispatcher = Dispatcher.CurrentDispatcher; Application app = new Application(); ISetupUI setupUi = null; InstallerViewModel model = new InstallerViewModel(this); // NOTE: This runIpc check can be removed if our current system proves itself. if (runIpc) { if (server == null) { server = new UpdateIPCServer(UpdateIPCServer.PipeName); server.MessageReceived += CheckExit; server.RegisterObject("InstallerViewModel", model); server.Start(); } setupUi = new IpcWindow(server, model, showPrompts); server.RegisterObject("SetupUI", setupUi); server.MessageReceived += CheckStartCommand; // Wait for the first start command to begin installing. setupUi.Closed += (sender, e) => SignalExit(); server.ClientConnected += () => { Engine.Log(LogLevel.Standard, "Resynchronizing UI with new client."); (setupUi as IpcWindow)?.ResynchronizeUI(); }; model.SetSetupUi(setupUi); model.PropertyChanged += (sender, e) => { server.PushMessage(new Message() { Command = IPC.Command.PropertyChanged, Property = e.PropertyName }); }; this.Engine.Detect(); } else { setupUi = new MainWindow(model, showPrompts); setupUi.Closed += (sender, e) => { Engine.Log(LogLevel.Standard, "Closing installer."); BootstrapperDispatcher.BeginInvokeShutdown(DispatcherPriority.Normal); Engine.Log(LogLevel.Standard, "Shutdown invoked."); }; model.SetSetupUi(setupUi); Engine.Detect(); if (Command.Display != Display.None && Command.Display != Display.Embedded) { setupUi.Show(); } Dispatcher.Run(); if (sentry != null) { sentry.Dispose(); } this.Engine.Quit(0); } } catch (Exception ex) { Engine.Log(LogLevel.Error, "A .NET error occurred while running CloudVeilInstallerUI"); Engine.Log(LogLevel.Error, $"Error Type: {ex.GetType().Name}"); Engine.Log(LogLevel.Error, $"Error info: {ex}"); this.Engine.Quit(1); } }