Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pinzart committed Mar 25, 2021
1 parent dc63bb8 commit 58e5853
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 74 deletions.
55 changes: 19 additions & 36 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2333,4 +2333,11 @@ Uninstall the following packages: {0}?</value>
<value>_Extensions</value>
<comment>Extensions menu</comment>
</data>
<data name="MessagePackageHasDepsInStdLib" xml:space="preserve">
<value>{0} has dependencies that conflict with packages in the Stadard Library: {1}.
To install {0}, please change the package loading order (see https://primer.dynamobim.org/11_Packages/11-Packages.html for more details), then try and download it again.</value>
</data>
<data name="MessageSamePackageInStdLibg" xml:space="preserve">
<value>"The package {0} is already installed as part of the Standard Library. To reinstall it, you must first change the package loading order (see https://primer.dynamobim.org/11_Packages/11-Packages.html for more details), then try to download it again"</value>
</data>
</root>
21 changes: 7 additions & 14 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2317,22 +2317,15 @@ Uninstall the following packages: {0}?</value>
<data name="PreferencesViewVisualSettingsTab" xml:space="preserve">
<value>Visual Settings</value>
</data>
<data name="PreferencesWindowLanguages" xml:space="preserve">
<value>English,Czech,German,Spanish,French,Italian,Japanese,Korean,Polish,Portuguese,Brazilian,Russian,Chinese Simplified,Chinese Traditional</value>
</data>
<data name="PreferencesViewFontSizeLabel" xml:space="preserve">
<value>Node Font Size</value>
</data>
<data name="PreferencesViewLanguageLabel" xml:space="preserve">
<value>Language</value>
<comment>Label used in the general tab</comment>
</data>
<data name="PreferencesViewRunSettingsLabel" xml:space="preserve">
<value>Default Run Settings</value>
<comment>Label used in the general tab</comment>
</data>
<data name="DynamoViewExtensionsMenu" xml:space="preserve">
<value>_Extensions</value>
<comment>Extensions menu</comment>
</data>
<data name="MessagePackageHasDepsInStdLib" xml:space="preserve">
<value>{0} has dependencies that conflict with packages in the Stadard Library: {1}.
To install {0}, please change the package loading order (see https://primer.dynamobim.org/11_Packages/11-Packages.html for more details), then try and download it again.</value>
</data>
<data name="MessageSamePackageInStdLibg" xml:space="preserve">
<value>"The package {0} is already installed as part of the Standard Library. To reinstall it, you must first change the package loading order (see https://primer.dynamobim.org/11_Packages/11-Packages.html for more details), then try to download it again"</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,17 @@ private string JoinPackageNames(IEnumerable<Package> pkgs)
return String.Join(", ", pkgs.Select(x => x.Name + " " + x.VersionName));
}

internal void ExecutePackageDownload(string name, PackageVersion version, string downloadPath)
private IEnumerable<Package> GetPackagesLocatedInStandardLibrary(IEnumerable<Package> packages)
{
var pmExt = DynamoViewModel.Model.GetPackageManagerExtension();
return packages.Where(x => x.RootDirectory.Contains(pmExt.PackageLoader.StandardLibraryDirectory));
}

internal void ExecutePackageDownload(string name, PackageVersion package, string downloadPath)
{
string msg = String.IsNullOrEmpty(downloadPath) ?
String.Format(Resources.MessageConfirmToInstallPackage, name, version.version) :
String.Format(Resources.MessageConfirmToInstallPackageToFolder, name, version.version, downloadPath);
String.Format(Resources.MessageConfirmToInstallPackage, name, package.version) :
String.Format(Resources.MessageConfirmToInstallPackageToFolder, name, package.version, downloadPath);

var result = MessageBox.Show(msg,
Resources.PackageDownloadConfirmMessageBoxTitle,
Expand All @@ -498,11 +504,11 @@ internal void ExecutePackageDownload(string name, PackageVersion version, string
if (result == MessageBoxResult.OK)
{
// get all of the dependency version headers
var dependencyVersionHeaders = version.full_dependency_ids.Select((dep, i) =>
var dependencyVersionHeaders = package.full_dependency_ids.Select((dep, i) =>
{
try
{
var depVersion = version.full_dependency_versions[i];
var depVersion = package.full_dependency_versions[i];
var res = Model.GetPackageVersionHeader(dep._id, depVersion);
return res;
}
Expand Down Expand Up @@ -564,18 +570,23 @@ internal void ExecutePackageDownload(string name, PackageVersion version, string
}
}

var localPkgs = pmExt.PackageLoader.LocalPackages;
var pkgVersion = VersionUtilities.PartialParse(package.version);

var localPkgs = pmExt.PackageLoader.LocalPackages;

var uninstallsRequiringRestart = new List<Package>();
var uninstallRequiringUserModifications = new List<Package>();
var immediateUninstalls = new List<Package>();

// if a package is already installed we need to uninstall it, allowing
// the user to cancel if they do not want to uninstall the package
foreach (var localPkg in version.full_dependency_ids.Select(dep => localPkgs.FirstOrDefault(v => v.ID == dep._id)))
foreach (var localPkg in package.full_dependency_ids.Select(dep => localPkgs.FirstOrDefault(v => v.Name == dep.name)))
{
if (localPkg == null) continue;

// should we also uninstall deps with the same version?
//if (VersionUtilities.PartialParse(localPkg.VersionName) == pkgVersion) continue;

if (localPkg.LoadedAssemblies.Any())
{
uninstallsRequiringRestart.Add(localPkg);
Expand All @@ -591,11 +602,24 @@ internal void ExecutePackageDownload(string name, PackageVersion version, string
immediateUninstalls.Add(localPkg);
}

var stdLibHasTopPriority = pmExt.PackageLoader.Priority(pmExt.PackageLoader.StandardLibraryDirectory) >
pmExt.PackageLoader.Priority(downloadPath);

if (uninstallRequiringUserModifications.Any())
{
MessageBox.Show(String.Format(Resources.MessageUninstallToContinue,
DynamoViewModel.BrandingResourceProvider.ProductName,
JoinPackageNames(uninstallRequiringUserModifications)),
var message = String.Format(Resources.MessageUninstallToContinue,
DynamoViewModel.BrandingResourceProvider.ProductName,
JoinPackageNames(uninstallRequiringUserModifications));

var stdLibPkgs = GetPackagesLocatedInStandardLibrary(uninstallRequiringUserModifications);
if (stdLibHasTopPriority && stdLibPkgs.Count() > 0) {
// Some or all dependencies are in standard library.
message = String.Format(Resources.MessagePackageHasDepsInStdLib,
name + " " + package.version,
JoinPackageNames(stdLibPkgs));
}

MessageBox.Show(message,
Resources.CannotDownloadPackageMessageBoxTitle,
MessageBoxButton.OK, MessageBoxImage.Error);
return;
Expand All @@ -605,18 +629,35 @@ internal void ExecutePackageDownload(string name, PackageVersion version, string

if (uninstallsRequiringRestart.Any())
{
var samePackage = uninstallsRequiringRestart.Count == 1 &&
uninstallsRequiringRestart.First().Name == name &&
uninstallsRequiringRestart.First().VersionName == package.version;

var stdLibPkgs = GetPackagesLocatedInStandardLibrary(uninstallsRequiringRestart);
if (stdLibHasTopPriority && stdLibPkgs.Count() > 0)
{
var errMsg = samePackage ? String.Format(Resources.MessageSamePackageInStdLibg,
name + " " + package.version) :
String.Format(Resources.MessagePackageHasDepsInStdLib,
name + " " + package.version,
JoinPackageNames(stdLibPkgs));

MessageBox.Show(errMsg,
Resources.CannotDownloadPackageMessageBoxTitle,
MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

var message = string.Format(Resources.MessageUninstallToContinue2,
DynamoViewModel.BrandingResourceProvider.ProductName,
JoinPackageNames(uninstallsRequiringRestart),
name + " " + version.version);
DynamoViewModel.BrandingResourceProvider.ProductName,
JoinPackageNames(uninstallsRequiringRestart),
name + " " + package.version);

// different message for the case that the user is
// trying to install the same package/version they already have installed.
if (uninstallsRequiringRestart.Count == 1 &&
uninstallsRequiringRestart.First().Name == name &&
uninstallsRequiringRestart.First().VersionName == version.version)
if (samePackage)
{
message = String.Format(Resources.MessageUninstallSamePackage, name + " " + version.version);
message = String.Format(Resources.MessageUninstallSamePackage, name + " " + package.version);
}
var dialogResult = MessageBox.Show(message,
Resources.CannotDownloadPackageMessageBoxTitle,
Expand All @@ -625,13 +666,15 @@ internal void ExecutePackageDownload(string name, PackageVersion version, string
if (dialogResult == MessageBoxResult.Yes)
{
// mark for uninstallation
uninstallsRequiringRestart.ForEach(x => x.MarkForUninstall(settings));
uninstallsRequiringRestart.ForEach(x => x.MarkForUninstall(settings, pmExt.PackageLoader));
}
return;
}

if (immediateUninstalls.Any())
{
var stdLibPkgs = GetPackagesLocatedInStandardLibrary(immediateUninstalls);

// if the package is not in use, tell the user we will be uninstall it and give them the opportunity to cancel
if (MessageBox.Show(String.Format(Resources.MessageAlreadyInstallDynamo,
DynamoViewModel.BrandingResourceProvider.ProductName,
Expand All @@ -654,7 +697,7 @@ internal void ExecutePackageDownload(string name, PackageVersion version, string
// Note that Name will be empty when calling from DownloadAndInstallPackage.
// This is currently not an issue, as the code path belongs to the Workspace Dependency
// extension, which does not display dependencies names.
var dependencyPackageHeader = version.full_dependency_ids[i];
var dependencyPackageHeader = package.full_dependency_ids[i];
return new PackageDownloadHandle()
{
Id = dependencyPackageHeader._id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ private void ConflictingCustomNodePackageLoaded(Package installed, Package confl
{
// mark for uninstallation
var settings = PackageManagerClientViewModel.DynamoViewModel.Model.PreferenceSettings;
installed.MarkForUninstall(settings);
installed.MarkForUninstall(settings, PackageManagerClientViewModel.PackageManagerExtension.PackageLoader);
}
}

Expand Down
15 changes: 13 additions & 2 deletions src/DynamoPackages/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,21 @@ private bool IsWorkspaceFromPackageOpen(DynamoModel dynamoModel)
.Any(guids.Contains);
}

internal void MarkForUninstall(IPreferences prefs)
internal bool MarkForUninstall(IPreferences prefs, PackageLoader packageLoader)
{
if (RootDirectory.Contains(packageLoader.StandardLibraryDirectory))
{
// cannot uninstall standard library pakcages.
return false;
}

MarkedForUninstall = true;

if (!prefs.PackageDirectoriesToUninstall.Contains(RootDirectory))
{
prefs.PackageDirectoriesToUninstall.Add(RootDirectory);
}
return true;
}

internal void UnmarkForUninstall(IPreferences prefs)
Expand All @@ -442,12 +449,16 @@ internal void UninstallCore(CustomNodeManager customNodeManager, PackageLoader p
{
if (LoadedAssemblies.Any())
{
MarkForUninstall(prefs);
MarkForUninstall(prefs, packageLoader);
return;
}

try
{
if (RootDirectory.Contains(packageLoader.StandardLibraryDirectory))
{
throw new Exception("Cannot delete packages from the standard library location");
}
LoadedCustomNodes.ToList().ForEach(x => customNodeManager.Remove(x.FunctionId));
packageLoader.Remove(this);
Directory.Delete(RootDirectory, true);
Expand Down
Loading

0 comments on commit 58e5853

Please sign in to comment.