Skip to content

Commit

Permalink
DYN-5873 Removal of Update Manager (#14632)
Browse files Browse the repository at this point in the history
* Removal of Update Manager

* Remove UpdateManager CleanUp

* Update

* Clean Up

* Update to rely on PathResolver so integrators can implement GetDynamoUserDataLocations() differently

* Null check for PathResolver

* Comments
  • Loading branch information
QilongTang authored Dec 4, 2023
1 parent c9c76aa commit 7def796
Show file tree
Hide file tree
Showing 22 changed files with 143 additions and 2,456 deletions.
38 changes: 37 additions & 1 deletion src/DynamoApplications/PathResolvers.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Dynamo.Interfaces;

namespace Dynamo.Applications
Expand Down Expand Up @@ -58,13 +60,41 @@ public IEnumerable<string> PreloadedLibraryPaths

public string UserDataRootFolder
{
get { return string.Empty; }
get { return Path.Combine(Environment.GetFolderPath(
Environment.SpecialFolder.ApplicationData),
"Dynamo", "Dynamo Core").ToString(); }
}

public string CommonDataRootFolder
{
get { return string.Empty; }
}

/// <summary>
/// Returns the full path of user data location of all version of this
/// Dynamo product installed on this system. The default implementation
/// returns list of all subfolders in %appdata%\Dynamo as well as
/// %appdata%\Dynamo\Dynamo Core\ folders.
/// </summary>
/// <returns></returns>
public IEnumerable<string> GetDynamoUserDataLocations()
{
var appDatafolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var dynamoFolder = Path.Combine(appDatafolder, "Dynamo");
if (!Directory.Exists(dynamoFolder)) return Enumerable.Empty<string>();

var paths = new List<string>();
var coreFolder = new FileInfo(UserDataRootFolder).FullName;
//Dynamo Core folder has to be enumerated first to cater migration from
//Dynamo 1.0 to Dynamo Core 1.0
if (Directory.Exists(coreFolder))
{
paths.AddRange(Directory.EnumerateDirectories(coreFolder));
}

paths.AddRange(Directory.EnumerateDirectories(dynamoFolder));
return paths;
}
}

internal class CLIPathResolver : IPathResolver
Expand Down Expand Up @@ -125,5 +155,11 @@ public IEnumerable<string> PreloadedLibraryPaths
public string UserDataRootFolder { get; private set; }

public string CommonDataRootFolder { get; private set; }

public IEnumerable<string> GetDynamoUserDataLocations()
{
// Do nothing for now.
return Enumerable.Empty<string>();
}
}
}
59 changes: 0 additions & 59 deletions src/DynamoApplications/StartupUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,48 +75,6 @@ public static class StartupUtils
/// </summary>
public static event Action<string> ASMPreloadFailure;

#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
internal class SandboxLookUp : DynamoLookUp
{
public override IEnumerable<string> GetDynamoInstallLocations()
{
const string regKey64 = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\";
//Open HKLM for 64bit registry
var regKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
//Open Windows/CurrentVersion/Uninstall registry key
regKey = regKey.OpenSubKey(regKey64);

//Get "InstallLocation" value as string for all the subkey that starts with "Dynamo"
return regKey.GetSubKeyNames().Where(s => s.StartsWith("Dynamo")).Select(
(s) => regKey.OpenSubKey(s).GetValue("InstallLocation") as string);
}
}

/// <summary>
///this class is left unimplemented,unclear how to
///lookup installation locations on nix/mac
/// </summary>
internal class CLILookUp : DynamoLookUp
{
public override IEnumerable<string> GetDynamoInstallLocations()
{
throw new NotImplementedException();
int p = (int)Environment.OSVersion.Platform;
if ((p == 4) || (p == 6) || (p == 128))
{
Console.WriteLine("Running on Unix");
}
else
{
Console.WriteLine("NOT running on Unix");
}

return null;
}
}

public struct CommandLineArguments
{
public static CommandLineArguments Parse(string[] args)
Expand Down Expand Up @@ -211,22 +169,6 @@ public static void PreloadShapeManager(ref string geometryFactoryPath, ref strin
preloaderLocation = preloader.PreloaderLocation;
}

/// <summary>
///if we are building a model for CLI mode, then we don't want to start an updateManager
///for now, building an updatemanager instance requires finding Dynamo install location
///which if we are running on mac os or *nix will use different logic then SandboxLookup
/// </summary>
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
private static IUpdateManager InitializeUpdateManager()
{
var cfg = UpdateManagerConfiguration.GetSettings(new SandboxLookUp());
var um = new Dynamo.Updates.UpdateManager(cfg);
Debug.Assert(cfg.DynamoLookUp != null);
return um;
}

/// <summary>
/// Use this overload to construct a DynamoModel in CLI context when the location of ASM to use is known, host analytics info is known and you want to set data paths.
/// </summary>
Expand Down Expand Up @@ -391,7 +333,6 @@ private static DynamoModel StartDynamoWithDefaultConfig(bool CLImode,
HostAnalyticsInfo = info,
CLIMode = CLImode,
AuthProvider = CLImode || noNetworkMode ? null : new Core.IDSDKManager(),
UpdateManager = CLImode ? null : OSHelper.IsWindows() ? InitializeUpdateManager() : null,
StartInTestMode = CLImode,
PathResolver = CreatePathResolver(CLImode, preloaderLocation, userDataFolder, commonDataFolder),
IsServiceMode = isServiceMode,
Expand Down
15 changes: 15 additions & 0 deletions src/DynamoCore/Configuration/IPathResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public interface IPathResolver
/// as it will be appended by PathManager.
/// </summary>
string CommonDataRootFolder { get; }

/// <summary>
/// Returns a list of user data folders on this system.
/// </summary>
/// <returns>
/// The implementation of this interface method should return a list of user
/// data folders, one for each of Dynamo product installed on the system. When
/// there is no Dynamo product installed, this method returns an empty list.
/// </returns>
IEnumerable<string> GetDynamoUserDataLocations();
}

/// <summary>
Expand Down Expand Up @@ -189,6 +199,11 @@ public interface IPathManager
/// </summary>
int MinorFileVersion { get; }

/// <summary>
/// Integration specific PathResolver
/// </summary>
IPathResolver PathResolver { get; }

/// <summary>
/// Call this method to add additional path for consideration when path
/// resolution take place.
Expand Down
21 changes: 21 additions & 0 deletions src/DynamoCore/Configuration/PathManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ internal static Lazy<PathManager>

private readonly int majorFileVersion;
private readonly int minorFileVersion;
private Updates.BinaryVersion productVersion;
private readonly string dynamoCoreDir;
private string hostApplicationDirectory;
private string userDataDir;
Expand All @@ -102,6 +103,14 @@ internal static Lazy<PathManager>

internal IPreferences Preferences { get; set; }

/// <summary>
/// PathResolver is used to resolve paths for custom nodes, packages, and preloaded libraries.
/// </summary>
public IPathResolver PathResolver
{
get { return pathResolver; }
}

private IEnumerable<string> RootDirectories
{
get
Expand Down Expand Up @@ -631,6 +640,18 @@ internal string GetUserDataFolder()
return GetDynamoDataFolder(Path.Combine(folder, "Dynamo", "Dynamo Core"));
}

/// <summary>
/// Returns the current Dynamo product version.
/// </summary>
/// <returns></returns>
public Updates.BinaryVersion GetProductVersion()
{
if (null != productVersion) return productVersion;
var executingAssemblyName = Assembly.GetExecutingAssembly().GetName();
productVersion = Updates.BinaryVersion.FromString(executingAssemblyName.Version.ToString());
return productVersion;
}

private string GetCommonDataFolder()
{
if (pathResolver != null && !string.IsNullOrEmpty(pathResolver.CommonDataRootFolder))
Expand Down
47 changes: 34 additions & 13 deletions src/DynamoCore/Core/DynamoMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,12 @@ protected virtual DynamoMigratorBase MigrateFrom(DynamoMigratorBase sourceMigrat
/// definitions from the last but one version to the currently installed Dynamo version
/// </summary>
/// <param name="pathManager"></param>
/// <param name="dynamoLookup"></param>
/// <returns>new migrator instance after migration</returns>
public static DynamoMigratorBase MigrateBetweenDynamoVersions(IPathManager pathManager, IDynamoLookUp dynamoLookup = null)
public static DynamoMigratorBase MigrateBetweenDynamoVersions(IPathManager pathManager)
{
//Get the current version from the current path manager user data directory.
var currentVersion = GetInstallVersionFromUserDataFolder(pathManager.UserDataDirectory);
var previousVersion = GetLatestVersionToMigrate(pathManager, dynamoLookup, currentVersion);
var previousVersion = GetLatestVersionToMigrate(pathManager, currentVersion);

if (!previousVersion.HasValue || previousVersion.Value.UserDataRoot == null)
return null; //Don't have previous version for migration
Expand All @@ -201,12 +200,11 @@ public static DynamoMigratorBase MigrateBetweenDynamoVersions(IPathManager pathM
/// Returns the most recent version to migrate to the given current version.
/// </summary>
/// <param name="pathManager"></param>
/// <param name="dynamoLookup"></param>
/// <param name="currentVersion"></param>
/// <returns>FileVersion?</returns>
public static FileVersion? GetLatestVersionToMigrate(IPathManager pathManager, IDynamoLookUp dynamoLookup, FileVersion currentVersion)
public static FileVersion? GetLatestVersionToMigrate(IPathManager pathManager, FileVersion currentVersion)
{
var versions = GetInstalledVersions(pathManager, dynamoLookup);
var versions = GetInstalledVersions(pathManager);

if (versions.Count() < 2)
return null; // No need for migration
Expand Down Expand Up @@ -265,17 +263,14 @@ public static IEnumerable<FileVersion> GetInstalledVersions(string rootFolder)
}

/// <summary>
/// Returns list of FileVersion objects, given the IPathManager and
/// IDynamoLookUp objects. If a valid IDynamoLookUp interface object
/// is passed, this method uses the lookup to get Dynamo user data locations.
/// Returns list of FileVersion objects, given the IPathManager.
/// </summary>
/// <param name="pathManager"></param>
/// <param name="dynamoLookup"></param>
/// <returns></returns>
public static IEnumerable<FileVersion> GetInstalledVersions(IPathManager pathManager, IDynamoLookUp dynamoLookup)
public static IEnumerable<FileVersion> GetInstalledVersions(IPathManager pathManager)
{
return dynamoLookup != null
? GetInstalledVersionsCore(() => dynamoLookup.GetDynamoUserDataLocations())
var installedVersions = GetInstalledVersionsCore(() => pathManager.PathResolver != null? pathManager.PathResolver.GetDynamoUserDataLocations() : Enumerable.Empty<string>());
return installedVersions.Any() ? installedVersions
: GetInstalledVersions(Path.GetDirectoryName(pathManager.UserDataDirectory));
}

Expand Down Expand Up @@ -403,6 +398,32 @@ public string CommonDataRootFolder
{
get { return string.Empty; }
}

/// <summary>
/// Returns the full path of user data location of all version of this
/// Dynamo product installed on this system. The default implementation
/// returns list of all subfolders in %appdata%\Dynamo as well as
/// %appdata%\Dynamo\Dynamo Core\ folders.
/// </summary>
/// <returns></returns>
public IEnumerable<string> GetDynamoUserDataLocations()
{
var appDatafolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var dynamoFolder = Path.Combine(appDatafolder, "Dynamo");
if (!Directory.Exists(dynamoFolder)) return Enumerable.Empty<string>();

var paths = new List<string>();
var coreFolder = new FileInfo(UserDataRootFolder).FullName;
//Dynamo Core folder has to be enumerated first to cater migration from
//Dynamo 1.0 to Dynamo Core 1.0
if (Directory.Exists(coreFolder))
{
paths.AddRange(Directory.EnumerateDirectories(coreFolder));
}

paths.AddRange(Directory.EnumerateDirectories(dynamoFolder));
return paths;
}
}

}
Loading

0 comments on commit 7def796

Please sign in to comment.