Exemplo n.º 1
0
        private bool PerformAutoUpdate(IDIContext container, IUpdateDescription update)
        {
            logger.Info("Performing auto update");

            var uiManager = container.Resolve <IUIManager>();
            var displayId = uiManager.CreateUIElement(() =>
            {
                var f = new ProgressDisplayForm();
                f.Show();
                return(f);
            });

            try
            {
                var progressDisplay = uiManager.GetUIElement <ProgressDisplayForm>(displayId);
                using (var progressMonitor = new ProgressMonitorAdapter(progressDisplay))
                {
                    var patchFolder = System.IO.Path.Combine(GobchatContext.ApplicationLocation, PatchFolder);

                    (var downloadResult, var filePath) = PerformAutoUpdateDownload(update, patchFolder, progressMonitor);
                    logger.Info($"Download complete: {downloadResult}");
                    if (!downloadResult)
                    {
                        return(false);
                    }

                    (var extractionResult, var unpackedArchive) = PerformAutoUpdateExtraction(filePath, patchFolder, progressMonitor);
                    logger.Info($"Extraction complete {extractionResult}");
                    if (!extractionResult)
                    {
                        return(false);
                    }

                    PerformAutoUpdateInstall(unpackedArchive, progressMonitor);
                }

                return(true);
            }
            finally
            {
                uiManager.DisposeUIElement(displayId);
            }
        }
Exemplo n.º 2
0
        public void Initialize(ApplicationStartupHandler handler, IDIContext container)
        {
            var uiSynchronizer = container.Resolve <IUISynchronizer>();
            ProgressDisplayForm progressDisplay = null;

            var cefFolder     = Path.Combine(GobchatContext.ApplicationLocation, "libs", "cef");
            var patcherFolder = Path.Combine(GobchatContext.ApplicationLocation, "patch");
            var installer     = new CefInstaller(cefFolder, patcherFolder);

            if (installer.IsCefAvailable())
            {
                return;
            }

            //TODO message dialog
            {
                logger.Info("CEF missing");
                var dialogResult = MessageBox.Show(
                    Resources.Module_Cef_Dialog_CefMissing_Text,
                    "Gobchat",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Warning
                    );

                if (dialogResult != DialogResult.Yes)
                {
                    handler.StopStartup = true;
                    return;
                }
            }

            try
            {
                uiSynchronizer.RunSync(() =>
                {
                    progressDisplay = new ProgressDisplayForm();
                    progressDisplay.Show();
                });

                using (var progressMonitor = new ProgressMonitorAdapter(progressDisplay))
                {
                    try
                    {
                        installer.DownloadCef(progressMonitor);
                    }
                    catch (Exception e)
                    {
                        logger.Log(LogLevel.Fatal, e, () => "CEF download failed");
                        throw;
                    }
                    try
                    {
                        installer.ExtractCef(progressMonitor);
                    }
                    catch (Exception e)
                    {
                        logger.Log(LogLevel.Fatal, e, () => "CEF extraction failed");
                        throw;
                    }
                }
            }
            catch (Exception e)
            {
                logger.Fatal("CEF installation failed");
                logger.Fatal(e);

                MessageBox.Show(
                    StringFormat.Format(Resources.Module_Cef_Dialog_InstallFailed_Text, e.Message),
                    Resources.Module_Cef_Dialog_InstallFailed_Title,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );

                handler.StopStartup = true;
            }
            finally
            {
                uiSynchronizer.RunSync(() => progressDisplay.Dispose());
            }
        }