private async void CheckUpdates() { try { var httpApplicationInfoLoader = new HttpApplicationInfoLoader(); using (var appUpdater = new AppUpdater(httpApplicationInfoLoader)) { await appUpdater.InitializeAsync(); var appInfo = appUpdater.CheckIsUpdateAvailable(ProgramInfo.AssemblyGuid, Assembly.GetExecutingAssembly().Location, out bool isUpdateAvailable); IsUpdateAvailable = isUpdateAvailable; if (IsUpdateAvailable) { UpdateApplicationInfo = appInfo; var mainWindowViewModel = Current.MainWindow?.DataContext as MainWindowViewModel; mainWindowViewModel?.ShowUpdateView(); } } } catch (Exception e) { LogProvider.Log.Error(this, "Updates couldn't be checked.", e); } }
public async virtual void InitializeAsync() { var appLoader = new HttpApplicationInfoLoader(); try { if (IsAppRunning()) { await Task.Delay(5000); if (IsAppRunning()) { StatusMessage = Resources.Error_ManyApps; return; } } using (var appUpdater = new AppUpdater(appLoader)) { appUpdater.OperationChanged += OnOperationChanged; appUpdater.ProgressChanged += OnProgressChanged; appUpdater.UnzippingFileChanged += OnUnzippingFileChanged; appUpdater.CopyingFileChanged += OnCopyingFileChanged; await appUpdater.InitializeAsync(); if (!appUpdater.CheckIsUpdateAvailable(DriveHUDUpdaterPaths.MainApplicationGuid, DriveHUDUpdaterPaths.MainApplicationProccess)) { StatusMessage = Resources.Error_NoUpdate; return; } var unpackedDirectory = await appUpdater.UpdateApplicationAsync(DriveHUDUpdaterPaths.MainApplicationGuid, DriveHUDUpdaterPaths.MainApplicationProccess, true); StatusMessage = Resources.Message_Operation_Completed; var installerPath = Path.Combine(unpackedDirectory.FullName, DriveHUDUpdaterPaths.MainApplicationInstaller); RunApplication(installerPath); } } catch (UpdaterException ex) { HandleUpdaterError(ex); } catch (FileNotFoundException) { StatusMessage = Resources.Error_AssemblyNotFound; } catch { StatusMessage = Resources.Error_Unexpected; } }
private async void RunUpdater() { IsBusy = true; var appLoader = new HttpApplicationInfoLoader(); try { using (var appUpdater = new AppUpdater(appLoader)) { appUpdater.OperationChanged += OnOperationChanged; appUpdater.ProgressChanged += OnProgressChanged; appUpdater.UnzippingFileChanged += OnProcessingFileChanged; appUpdater.CopyingFileChanged += OnProcessingFileChanged; await appUpdater.InitializeAsync(); var applicationPath = Assembly.GetExecutingAssembly().Location; var guid = ProgramInfo.AssemblyGuid; if (!appUpdater.CheckIsUpdateAvailable(guid, applicationPath)) { StatusMessage = CommonResourceManager.Instance.GetResourceString("Error_NoUpdate"); return; } var unpackedDirectory = await appUpdater.UpdateApplicationAsync(guid, applicationPath, true); StatusMessage = CommonResourceManager.Instance.GetResourceString("Common_UpdateView_Completed"); var installerName = CommonResourceManager.Instance.GetResourceString("SystemSettings_Installer"); var installerPath = Path.Combine(unpackedDirectory.FullName, installerName); RunApplication(installerPath); } } catch (UpdaterException ex) { HandleUpdaterError(ex); } catch (FileNotFoundException) { StatusMessage = CommonResourceManager.Instance.GetResourceString("Error_AssemblyNotFound"); } catch (Exception e) { LogProvider.Log.Error(this, "Could not update app.", e); StatusMessage = CommonResourceManager.Instance.GetResourceString("Error_Unexpected"); } IsBusy = false; }