public async Task UninstallAsync(IRPackageViewModel package) { await _coreShell.SwitchToMainThreadAsync(); if (!package.IsInstalled || package.IsChanging) { return; } var confirmUninstall = _coreShell.ShowMessage(string.Format(CultureInfo.CurrentCulture, Resources.PackageManager_PackageUninstallWarning, package.Name, package.LibraryPath), MessageButtons.YesNo); if (confirmUninstall != MessageButtons.Yes) { return; } BeforeLoadUnload(package); var startingTab = _selectedTab; if (package.IsLoaded) { try { await _packageManager.UnloadPackageAsync(package.Name); } catch (RHostDisconnectedException) { AddErrorMessage(string.Format(CultureInfo.CurrentCulture, Resources.PackageManager_CantUnloadPackageNoRSession, package.Name)); } catch (RPackageManagerException ex) { AddErrorMessage(ex.Message); } await ReloadLoadedPackagesAsync(); } if (!package.IsLoaded) { try { var libPath = package.LibraryPath.ToRPath(); var packageLockState = await _packageManager.UninstallPackageAsync(package.Name, libPath); if (packageLockState != PackageLockState.Unlocked) { ShowPackageLockedMessage(packageLockState, package.Name); } } catch (RHostDisconnectedException) { AddErrorMessage(string.Format(CultureInfo.CurrentCulture, Resources.PackageManager_CantUninstallPackageNoRSession, package.Name)); } catch (RPackageManagerException ex) { AddErrorMessage(ex.Message); } await ReloadInstalledAndLoadedPackagesAsync(); } await AfterLoadUnloadAsync(package, startingTab); }
public async Task UpdateAsync(IRPackageViewModel package) { await _coreShell.SwitchToMainThreadAsync(); if (!package.IsInstalled || package.IsChanging) { return; } var confirmUpdate = _coreShell.ShowMessage(string.Format(CultureInfo.CurrentCulture, Resources.PackageManager_PackageUpdateWarning, package.Name), MessageButtons.YesNo); if (confirmUpdate != MessageButtons.Yes) { return; } package.IsChanging = true; if (_selectedTab == SelectedTab.InstalledPackages || _selectedTab == SelectedTab.LoadedPackages) { IsLoading = true; } if (package.IsLoaded) { try { await _packageManager.UnloadPackageAsync(package.Name); } catch (RPackageManagerException ex) { AddErrorMessage(ex.Message); } await ReloadLoadedPackagesAsync(); } if (!package.IsLoaded) { try { var libPath = package.LibraryPath.ToRPath(); var packageLockState = _packageManager.GetPackageLockState(package.Name, libPath); if (packageLockState == PackageLockState.Unlocked) { await _packageManager.UninstallPackageAsync(package.Name, libPath); await _packageManager.InstallPackageAsync(package.Name, libPath); } else { ShowPackageLockedMessage(packageLockState, package.Name); } } catch (RPackageManagerException ex) { AddErrorMessage(ex.Message); } await ReloadInstalledAndLoadedPackagesAsync(); } if (_selectedTab == SelectedTab.InstalledPackages) { ReplaceItems(_installedPackages); IsLoading = false; } else if (_selectedTab == SelectedTab.LoadedPackages) { ReplaceItems(_loadedPackages); IsLoading = false; } package.IsChanging = false; }