Exemplo n.º 1
0
        public VisualStudioInstance(ISetupInstance2 FromInstance)
        {
            this.IsLaunchable = FromInstance.IsLaunchable();
            this.IsComplete   = FromInstance.IsComplete();
            this.Name         = FromInstance.GetInstallationName();
            this.Path         = FromInstance.GetInstallationPath();
            this.Version      = FromInstance.GetInstallationVersion();
            this.DisplayName  = FromInstance.GetDisplayName();
            this.Description  = FromInstance.GetDescription();
            this.ResolvePath  = FromInstance.ResolvePath();
            this.EnginePath   = FromInstance.GetEnginePath();
            this.InstanceId   = FromInstance.GetInstanceId();
            this.ProductPath  = FromInstance.GetProductPath();

            try
            {
                var   time     = FromInstance.GetInstallDate();
                ulong high     = (ulong)time.dwHighDateTime;
                uint  low      = (uint)time.dwLowDateTime;
                long  fileTime = (long)((high << 32) + low);

                this.InstallDate = DateTime.FromFileTimeUtc(fileTime);
            }
            catch
            {
                this.InstallDate = DateTime.UtcNow;
            }

            // FromInstance.GetState();
            // FromInstance.GetPackages();
            // FromInstance.GetProduct();
            // FromInstance.GetProperties();
            // FromInstance.GetErrors();
        }
Exemplo n.º 2
0
        private static VisualStudioInstance FillInInstanceData(ISetupInstance2 instance,
                                                               int lcid,
                                                               Boolean includePackages)
        {
            VisualStudioInstance result = new VisualStudioInstance()
            {
                InstanceId             = instance.GetInstanceId(),
                InstalledVersionNumber = instance.GetInstallationVersion(),
                Description            = instance.GetDescription(lcid),
                DisplayName            = instance.GetDisplayName(lcid)
            };

            // Hides the non-CLS clompliant uint.
            var tempState = instance.GetState();

            if (tempState == InstanceState.Complete)
            {
                result.Status = InstanceStatus.Complete;
            }
            else
            {
                result.Status = (InstanceStatus)tempState;
            }

            result.InstallationPath = instance.GetInstallationPath();

            ISetupPackageReference prod = instance.GetProduct();

            if (prod != null)
            {
                result.ProductName = prod.GetId();
            }

            if ((result.Status & InstanceStatus.Local) == InstanceStatus.Local)
            {
                result.InstallationPath = instance.GetInstallationPath();
            }


            if (includePackages)
            {
                ProcessPackages(instance, result);
            }

            return(result);
        }
Exemplo n.º 3
0
        private static VSInstance ParseInstance(ISetupInstance2 setupInstance2)
        {
            VSInstance inst = new VSInstance();

            string[] prodParts = setupInstance2.GetProduct().GetId().Split('.');
            Array.Reverse(prodParts);
            inst["Product"]              = prodParts[0];
            inst["ID"]                   = setupInstance2.GetInstanceId();
            inst["Name"]                 = setupInstance2.GetDisplayName(0x1000);
            inst["Description"]          = setupInstance2.GetDescription(0x1000);
            inst["InstallationName"]     = setupInstance2.GetInstallationName();
            inst["Version"]              = setupInstance2.GetInstallationVersion();
            inst["State"]                = Enum.GetName(typeof(InstanceState), setupInstance2.GetState());
            inst["InstallationPath"]     = setupInstance2.GetInstallationPath();
            inst["IsComplete"]           = setupInstance2.IsComplete();
            inst["IsLaunchable"]         = setupInstance2.IsLaunchable();
            inst["Common7ToolsPath"]     = inst["InstallationPath"] + @"\Common7\Tools\";
            inst["CmdPath"]              = inst["Common7ToolsPath"] + "VsDevCmd.bat";
            inst["VCAuxiliaryBuildPath"] = inst["InstallationPath"] + @"\VC\Auxiliary\Build\";
            inst["VCVarsAllPath"]        = inst["VCAuxiliaryBuildPath"] + "vcvarsall.bat";

            inst["Win8SDK"]        = "";
            inst["SDK10Full"]      = "";
            inst["VisualCppTools"] = "";

            Regex trimmer = new Regex(@"\.\d+$");

            List <string> packs = new List <String>();

            foreach (ISetupPackageReference package in setupInstance2.GetPackages())
            {
                string id = package.GetId();

                string ver    = package.GetVersion();
                string detail = "{\"id\": \"" + id + "\", \"version\":\"" + ver + "\"}";
                packs.Add("        " + detail);

                if (id.Contains("Component.MSBuild"))
                {
                    inst["MSBuild"]        = detail;
                    inst["MSBuildVerFull"] = ver;
                }
                else if (id.Contains("Microsoft.VisualCpp.Tools.Core"))
                {
                    inst["VCTools"] = detail;
                    inst["VisualCppToolsFullVersion"] = ver;
                    string majorMinor = trimmer.Replace(trimmer.Replace(ver, ""), "");
                    inst["VisualCppToolsVersionMinor"] = majorMinor;
                    inst["VCToolsVersionCode"]         = "vc" + majorMinor.Replace(".", "");
                }
                else if (id.Contains("Microsoft.Windows.81SDK"))
                {
                    if (inst["Win8SDK"].ToString().CompareTo(ver) > 0)
                    {
                        continue;
                    }
                    inst["Win8SDK"] = ver;
                }
                else if (id.Contains("Win10SDK_10"))
                {
                    if (inst["SDK10Full"].ToString().CompareTo(ver) > 0)
                    {
                        continue;
                    }
                    inst["SDK10Full"] = ver;
                }
            }
            packs.Sort();
            inst["Packages"] = packs.ToArray();

            string[] sdk10Parts = inst["SDK10Full"].ToString().Split('.');
            sdk10Parts[sdk10Parts.Length - 1] = "0";
            inst["SDK10"] = String.Join(".", sdk10Parts);
            inst["SDK"]   = inst["SDK10"].ToString() != "0" ? inst["SDK10"] : inst["Win8SDK"];
            if (inst.ContainsKey("MSBuildVerFull"))
            {
                string ver = trimmer.Replace(trimmer.Replace((string)inst["MSBuildVerFull"], ""), "");
                inst["MSBuildVer"]       = ver;
                inst["MSBuildToolsPath"] = inst["InstallationPath"] + @"\MSBuild\" + ver + @"\Bin\";
                inst["MSBuildPath"]      = inst["MSBuildToolsPath"] + "MSBuild.exe";
            }
            if (inst.ContainsKey("VCTools"))
            {
                string ver = trimmer.Replace((string)inst["VisualCppToolsFullVersion"], "");
                inst["VisualCppToolsX64"]   = inst["InstallationPath"] + @"\VC\Tools\MSVC\" + ver + @"\bin\HostX64\x64\";
                inst["VisualCppToolsX64CL"] = inst["VisualCppToolsX64"] + "cl.exe";
                inst["VisualCppToolsX86"]   = inst["InstallationPath"] + @"\VC\Tools\MSVC\" + ver + @"\bin\HostX86\x86\";
                inst["VisualCppToolsX86CL"] = inst["VisualCppToolsX86"] + "cl.exe";
                inst["VisualCppTools"]      = Is64() ? inst["VisualCppToolsX64"] : inst["VisualCppToolsX86"];
                inst["VisualCppToolsCL"]    = Is64() ? inst["VisualCppToolsX64CL"] : inst["VisualCppToolsX86CL"];
            }
            inst["IsVcCompatible"] = inst.JSONBool("SDK") && inst.JSONBool("MSBuild") && inst.JSONBool("VisualCppTools");
            return(inst);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Instance"/> class.
        /// </summary>
        /// <param name="instance">The <see cref="ISetupInstance2"/> to adapt.</param>
        /// <exception cref="ArgumentNullException"><paramref name="instance"/> is null.</exception>
        internal Instance(ISetupInstance2 instance)
        {
            Validate.NotNull(instance, nameof(instance));

            // The instance ID is required, but then try to set other properties to release the COM object and its resources ASAP.
            InstanceId = instance.GetInstanceId();

            TrySet(ref installationName, nameof(InstallationName), instance.GetInstallationName);
            TrySet(ref installationPath, nameof(InstallationPath), instance.GetInstallationPath);
            TrySet(ref installationVersion, nameof(InstallationVersion), () =>
            {
                Version version;

                var versionString = instance.GetInstallationVersion();
                if (Version.TryParse(versionString, out version))
                {
                    return(version.Normalize());
                }

                return(null);
            });

            TrySet(ref installDate, nameof(InstallDate), () =>
            {
                var ft = instance.GetInstallDate();
                var l  = ((long)ft.dwHighDateTime << 32) + ft.dwLowDateTime;

                return(DateTime.FromFileTime(l));
            });

            TrySet(ref state, nameof(State), instance.GetState);

            var lcid = CultureInfo.CurrentUICulture.LCID;

            TrySet(ref displayName, nameof(DisplayName), () =>
            {
                return(instance.GetDisplayName(lcid));
            });

            TrySet(ref description, nameof(Description), () =>
            {
                return(instance.GetDescription(lcid));
            });

            TrySet(ref productPath, nameof(ProductPath), () =>
            {
                var path = instance.GetProductPath();
                return(instance.ResolvePath(path));
            });

            TrySet(ref product, nameof(Product), () =>
            {
                var reference = instance.GetProduct();
                if (reference != null)
                {
                    return(new PackageReference(reference));
                }

                return(null);
            });

            TrySet(ref packages, nameof(Packages), () =>
            {
                return(new List <PackageReference>(GetPackages(instance)));
            });

            if (packages != null && packages.Any())
            {
                Packages = new ReadOnlyCollection <PackageReference>(packages);
            }

            TrySet(ref properties, nameof(Properties), () =>
            {
                var properties = instance.GetProperties();
                return(properties?.GetNames()
                       .ToDictionary(name => name.ToPascalCase(), name => properties.GetValue(name), StringComparer.OrdinalIgnoreCase));
            });

            if (properties != null)
            {
                Properties = new ReadOnlyDictionary <string, object>(properties);
            }
            else
            {
                // While accessing properties on a null object succeeds in PowerShell, accessing the indexer does not.
                Properties = ReadOnlyDictionary <string, object> .Empty;
            }

            TrySet(ref enginePath, nameof(EnginePath), instance.GetEnginePath);
            TrySet(ref isComplete, nameof(IsComplete), instance.IsComplete);
            TrySet(ref isLaunchable, nameof(IsLaunchable), instance.IsLaunchable);

            // Get all properties of the instance not explicitly declared.
            var store = (ISetupPropertyStore)instance;

            AdditionalProperties = store.GetNames()
                                   .Where(name => !DeclaredProperties.Contains(name))
                                   .ToDictionary(name => name.ToPascalCase(), name => store.GetValue(name), StringComparer.OrdinalIgnoreCase);
        }
 public string GetDescription(int lcid             = 0) => RunOnMainThread(() => _setupInstance.GetDescription(lcid));