Index: tools/install/Installer.cs ================================================================== --- tools/install/Installer.cs +++ tools/install/Installer.cs @@ -56,14 +56,11 @@ /////////////////////////////////////////////////////////////////////////// internal delegate bool VisualStudioRegistryCallback( RegistryKey rootKey, Version vsVersion, - Guid packageId, - Guid serviceId, - Guid dataSourceId, - Guid dataProviderId, + Installer.Package package, object clientData, bool whatIf, bool verbose, ref string error ); @@ -1292,10 +1289,71 @@ } #endregion /////////////////////////////////////////////////////////////////////// + #region Package Class + internal sealed class Package + { + #region Public Constructors + public Package() + { + // do nothing. + } + #endregion + + /////////////////////////////////////////////////////////////////// + + #region Public Properties + private Guid packageId; + public Guid PackageId + { + get { return packageId; } + set { packageId = value; } + } + + /////////////////////////////////////////////////////////////////// + + private Guid serviceId; + public Guid ServiceId + { + get { return serviceId; } + set { serviceId = value; } + } + + /////////////////////////////////////////////////////////////////// + + private Guid dataSourceId; + public Guid DataSourceId + { + get { return dataSourceId; } + set { dataSourceId = value; } + } + + /////////////////////////////////////////////////////////////////// + + private Guid dataProviderId; + public Guid DataProviderId + { + get { return dataProviderId; } + set { dataProviderId = value; } + } + + /////////////////////////////////////////////////////////////////// + + private Guid adoNetTechnologyId; + public Guid AdoNetTechnologyId + { + get { return adoNetTechnologyId; } + set { adoNetTechnologyId = value; } + } + #endregion + } + #endregion + + /////////////////////////////////////////////////////////////////////// + #region Configuration Class private sealed class Configuration { #region Private Constants private const char Switch = '-'; @@ -2139,12 +2197,11 @@ /////////////////////////////////////////////////////////////////// public static bool CheckImageRuntimeVersion( Configuration configuration, - VersionListMap fromtoyou, - VersionList versionList, + VsList vsList, bool strict, ref string error ) { try @@ -2502,10 +2559,114 @@ set { confirm = value; } } #endregion } #endregion + + /////////////////////////////////////////////////////////////////////// + + #region FrameworkList Class + private sealed class FrameworkList + { + #region Public Constructors + public FrameworkList() + { + // do nothing. + } + #endregion + + /////////////////////////////////////////////////////////////////// + + #region Public Methods + private RegistryKey rootKey; + public RegistryKey RootKey + { + get { return rootKey; } + set { rootKey = value; } + } + + /////////////////////////////////////////////////////////////////// + + private StringList names; + public StringList Names + { + get { return names; } + set { names = value; } + } + + /////////////////////////////////////////////////////////////////// + + private VersionMap versions; + public VersionMap Versions + { + get { return versions; } + set { versions = value; } + } + + /////////////////////////////////////////////////////////////////// + + private StringList platformNames; + public StringList PlatformNames + { + get { return platformNames; } + set { platformNames = value; } + } + #endregion + } + #endregion + + /////////////////////////////////////////////////////////////////////// + + #region VsList Class + private sealed class VsList + { + #region Public Constructors + public VsList() + { + // do nothing. + } + #endregion + + /////////////////////////////////////////////////////////////////// + + #region Public Properties + private RegistryKey rootKey; + public RegistryKey RootKey + { + get { return rootKey; } + set { rootKey = value; } + } + + /////////////////////////////////////////////////////////////////// + + private VersionList versions; + public VersionList Versions + { + get { return versions; } + set { versions = value; } + } + + /////////////////////////////////////////////////////////////////// + + private VersionListMap frameworkVersions; + public VersionListMap FrameworkVersions + { + get { return frameworkVersions; } + set { frameworkVersions = value; } + } + + /////////////////////////////////////////////////////////////////// + + private VersionList installedVersions; + public VersionList InstalledVersions + { + get { return installedVersions; } + set { installedVersions = value; } + } + #endregion + } + #endregion #endregion /////////////////////////////////////////////////////////////////////// #region Private Constant Data @@ -2559,28 +2720,10 @@ private static string traceCategory = Path.GetFileName( thisAssembly.Location); private static TraceCallback traceCallback = AppTrace; - - /////////////////////////////////////////////////////////////////////// - - private static RegistryKey frameworkRootKey; - private static StringList frameworkNameList; - private static VersionMap frameworkVersionMap; - private static StringList platformNameList; - - /////////////////////////////////////////////////////////////////////// - - private static RegistryKey vsRootKey; - private static VersionList vsVersionList; - private static VersionListMap vsFrameworkVersionMap; - private static Guid? vsPackageId; - private static Guid? vsServiceId; - private static Guid? vsDataSourcesId; - private static Guid? vsDataProviderId; - private static Guid? vsAdoNetTechnologyId; #endregion /////////////////////////////////////////////////////////////////////// #region Trace Handling @@ -2649,10 +2792,32 @@ #endregion /////////////////////////////////////////////////////////////////////// #region .NET Framework Handling + private static string GetImageRuntimeVersion( + string fileName + ) + { + try + { + Assembly assembly = + Assembly.ReflectionOnlyLoadFrom(fileName); /* throw */ + + if (assembly != null) + return assembly.ImageRuntimeVersion; + } + catch + { + // do nothing. + } + + return null; + } + + /////////////////////////////////////////////////////////////////////// + private static string GetFrameworkDirectory( RegistryKey rootKey, Version frameworkVersion, bool whatIf, bool verbose @@ -2796,87 +2961,81 @@ #endregion /////////////////////////////////////////////////////////////////////// #region Per-Framework/Platform Handling - private static void ResetAllFrameworks() - { - frameworkRootKey = null; - - if (frameworkNameList != null) - { - frameworkNameList.Clear(); - frameworkNameList = null; - } - - if (frameworkVersionMap != null) - { - frameworkVersionMap.Clear(); - frameworkVersionMap = null; - } - } - - /////////////////////////////////////////////////////////////////////// - - private static void InitializeAllFrameworks( - Configuration configuration - ) - { - if (frameworkRootKey == null) - frameworkRootKey = Registry.LocalMachine; - - if (frameworkNameList == null) - { - frameworkNameList = new StringList(); - - if ((configuration == null) || !configuration.NoDesktop) - frameworkNameList.Add(".NETFramework"); - - if ((configuration == null) || !configuration.NoCompact) - { - frameworkNameList.Add(".NETCompactFramework"); - frameworkNameList.Add(".NETCompactFramework"); - frameworkNameList.Add(".NETCompactFramework"); - } - } - - if (frameworkVersionMap == null) - frameworkVersionMap = new VersionMap(); - - if ((configuration == null) || !configuration.NoDesktop) - { - VersionList desktopVersionList = new VersionList(); - - if ((configuration == null) || !configuration.NoNetFx20) - desktopVersionList.Add(new Version(2, 0, 50727)); - - if ((configuration == null) || !configuration.NoNetFx40) - desktopVersionList.Add(new Version(4, 0, 30319)); - - frameworkVersionMap.Add(".NETFramework", desktopVersionList); - } - - if ((configuration == null) || !configuration.NoCompact) - { - frameworkVersionMap.Add(".NETCompactFramework", - new VersionList(new Version[] { - new Version(2, 0, 0, 0), new Version(3, 5, 0, 0) - })); - } - - if (platformNameList == null) - { - platformNameList = new StringList(); - - if ((configuration == null) || !configuration.NoDesktop) - platformNameList.Add(null); - - if ((configuration == null) || !configuration.NoCompact) - { - platformNameList.Add("PocketPC"); - platformNameList.Add("Smartphone"); - platformNameList.Add("WindowsCE"); + private static void InitializeFrameworkList( + Configuration configuration, + ref FrameworkList frameworkList + ) + { + if (frameworkList == null) + frameworkList = new FrameworkList(); + + if (frameworkList.RootKey == null) + frameworkList.RootKey = Registry.LocalMachine; + + /////////////////////////////////////////////////////////////////// + + if (frameworkList.Names == null) + { + frameworkList.Names = new StringList(); + + if ((configuration == null) || !configuration.NoDesktop) + frameworkList.Names.Add(".NETFramework"); + + if ((configuration == null) || !configuration.NoCompact) + { + frameworkList.Names.Add(".NETCompactFramework"); + frameworkList.Names.Add(".NETCompactFramework"); + frameworkList.Names.Add(".NETCompactFramework"); + } + } + + /////////////////////////////////////////////////////////////////// + + if (frameworkList.Versions == null) + { + frameworkList.Versions = new VersionMap(); + + if ((configuration == null) || !configuration.NoDesktop) + { + VersionList desktopVersionList = new VersionList(); + + if ((configuration == null) || !configuration.NoNetFx20) + desktopVersionList.Add(new Version(2, 0, 50727)); + + if ((configuration == null) || !configuration.NoNetFx40) + desktopVersionList.Add(new Version(4, 0, 30319)); + + frameworkList.Versions.Add(".NETFramework", + desktopVersionList); + } + + if ((configuration == null) || !configuration.NoCompact) + { + frameworkList.Versions.Add(".NETCompactFramework", + new VersionList(new Version[] { + new Version(2, 0, 0, 0), new Version(3, 5, 0, 0) + })); + } + } + + /////////////////////////////////////////////////////////////////// + + if (frameworkList.PlatformNames == null) + { + frameworkList.PlatformNames = new StringList(); + + if ((configuration == null) || !configuration.NoDesktop) + frameworkList.PlatformNames.Add(null); + + if ((configuration == null) || !configuration.NoCompact) + { + frameworkList.PlatformNames.Add("PocketPC"); + frameworkList.PlatformNames.Add("Smartphone"); + frameworkList.PlatformNames.Add("WindowsCE"); } } } /////////////////////////////////////////////////////////////////////// @@ -2920,10 +3079,11 @@ } /////////////////////////////////////////////////////////////////////// private static bool ForEachFrameworkConfig( + FrameworkList frameworkList, FrameworkConfigCallback callback, string invariant, string name, string description, string typeName, @@ -2933,11 +3093,17 @@ bool verbose, ref bool saved, ref string error ) { - RegistryKey rootKey = frameworkRootKey; + if (frameworkList == null) + { + error = "invalid framework list"; + return false; + } + + RegistryKey rootKey = frameworkList.RootKey; if (rootKey == null) { error = "invalid root key"; return false; @@ -2948,45 +3114,45 @@ { error = "root key must be per-user or per-machine"; return false; } - if (frameworkNameList == null) + if (frameworkList.Names == null) { error = "no framework names found"; return false; } - if (frameworkVersionMap == null) + if (frameworkList.Versions == null) { error = "no framework versions found"; return false; } - if (platformNameList == null) + if (frameworkList.PlatformNames == null) { error = "no platform names found"; return false; } - if (frameworkNameList.Count != platformNameList.Count) + if (frameworkList.Names.Count != frameworkList.PlatformNames.Count) { error = String.Format("framework name count {0} does not " + - "match platform name count {1}", frameworkNameList.Count, - platformNameList.Count); + "match platform name count {1}", frameworkList.Names.Count, + frameworkList.PlatformNames.Count); return false; } - for (int index = 0; index < frameworkNameList.Count; index++) + for (int index = 0; index < frameworkList.Names.Count; index++) { // // NOTE: Grab the name of the framework (e.g. ".NETFramework") // and the name of the platform (e.g. "WindowsCE"). // - string frameworkName = frameworkNameList[index]; - string platformName = platformNameList[index]; + string frameworkName = frameworkList.Names[index]; + string platformName = frameworkList.PlatformNames[index]; // // NOTE: Skip all non-desktop frameworks (i.e. if the platform // name is not null). // @@ -2997,11 +3163,11 @@ // NOTE: Grab the supported versions of this particular // framework. // VersionList frameworkVersionList; - if (!frameworkVersionMap.TryGetValue( + if (!frameworkList.Versions.TryGetValue( frameworkName, out frameworkVersionList) || (frameworkVersionList == null)) { continue; } @@ -3099,18 +3265,25 @@ } /////////////////////////////////////////////////////////////////////// private static bool ForEachFrameworkRegistry( + FrameworkList frameworkList, FrameworkRegistryCallback callback, object clientData, bool whatIf, bool verbose, ref string error ) { - RegistryKey rootKey = frameworkRootKey; + if (frameworkList == null) + { + error = "invalid framework list"; + return false; + } + + RegistryKey rootKey = frameworkList.RootKey; if (rootKey == null) { error = "invalid root key"; return false; @@ -3121,53 +3294,53 @@ { error = "root key must be per-user or per-machine"; return false; } - if (frameworkNameList == null) + if (frameworkList.Names == null) { error = "no framework names found"; return false; } - if (frameworkVersionMap == null) + if (frameworkList.Versions == null) { error = "no framework versions found"; return false; } - if (platformNameList == null) + if (frameworkList.PlatformNames == null) { error = "no platform names found"; return false; } - if (frameworkNameList.Count != platformNameList.Count) + if (frameworkList.Names.Count != frameworkList.PlatformNames.Count) { error = String.Format("framework name count {0} does not " + - "match platform name count {1}", frameworkNameList.Count, - platformNameList.Count); + "match platform name count {1}", frameworkList.Names.Count, + frameworkList.PlatformNames.Count); return false; } - for (int index = 0; index < frameworkNameList.Count; index++) + for (int index = 0; index < frameworkList.Names.Count; index++) { // // NOTE: Grab the name of the framework (e.g. ".NETFramework") // and the name of the platform (e.g. "WindowsCE"). // - string frameworkName = frameworkNameList[index]; - string platformName = platformNameList[index]; + string frameworkName = frameworkList.Names[index]; + string platformName = frameworkList.PlatformNames[index]; // // NOTE: Grab the supported versions of this particular // framework. // VersionList frameworkVersionList; - if (!frameworkVersionMap.TryGetValue( + if (!frameworkList.Versions.TryGetValue( frameworkName, out frameworkVersionList) || (frameworkVersionList == null)) { continue; } @@ -3210,102 +3383,79 @@ #endregion /////////////////////////////////////////////////////////////////////// #region Per-Visual Studio Version Handling - private static void InitializeVsRootKeyAndIds() - { - if (vsRootKey == null) - vsRootKey = Registry.LocalMachine; - - if (vsAdoNetTechnologyId == null) - vsAdoNetTechnologyId = new Guid( - "77AB9A9D-78B9-4BA7-91AC-873F5338F1D2"); - - if (vsPackageId == null) - vsPackageId = new Guid( - "DCBE6C8D-0E57-4099-A183-98FF74C64D9C"); - - if (vsServiceId == null) - vsServiceId = new Guid( - "DCBE6C8D-0E57-4099-A183-98FF74C64D9D"); - - if (vsDataSourcesId == null) - vsDataSourcesId = new Guid( - "0EBAAB6E-CA80-4B4A-8DDF-CBE6BF058C71"); - - if (vsDataProviderId == null) - vsDataProviderId = new Guid( - "0EBAAB6E-CA80-4B4A-8DDF-CBE6BF058C70"); - } - - /////////////////////////////////////////////////////////////////////// - - private static void ResetVsFrameworkVersionMap() - { - if (vsFrameworkVersionMap != null) - { - vsFrameworkVersionMap.Clear(); - vsFrameworkVersionMap = null; - } - } - - /////////////////////////////////////////////////////////////////////// - - private static void InitializeVsFrameworkVersionMap( - Configuration configuration - ) - { - if (vsFrameworkVersionMap == null) - { - vsFrameworkVersionMap = new VersionListMap(); - - // vsFrameworkVersionMap.Add(new Version(8, 0), + private static void InitializeVsList( + Configuration configuration, + ref VsList vsList + ) + { + if (vsList == null) + vsList = new VsList(); + + if (vsList.RootKey == null) + vsList.RootKey = Registry.LocalMachine; + + if (vsList.Versions == null) + { + vsList.Versions = new VersionList(); + + // vsList.Versions.Add(new Version(8, 0)); // Visual Studio 2005 + + if ((configuration == null) || !configuration.NoVs2008) + vsList.Versions.Add(new Version(9, 0)); // Visual Studio 2008 + + if ((configuration == null) || !configuration.NoVs2010) + vsList.Versions.Add(new Version(10, 0));// Visual Studio 2010 + } + + if (vsList.FrameworkVersions == null) + { + vsList.FrameworkVersions = new VersionListMap(); + + // vsList.FrameworkVersions.Add(new Version(8, 0), // new VersionList(new Version[] { // new Version(2, 0, 50727) })); if ((configuration == null) || !configuration.NoVs2008) - vsFrameworkVersionMap.Add(new Version(9, 0), + vsList.FrameworkVersions.Add(new Version(9, 0), new VersionList(new Version[] { new Version(2, 0, 50727) })); if ((configuration == null) || !configuration.NoVs2010) - vsFrameworkVersionMap.Add(new Version(10, 0), + vsList.FrameworkVersions.Add(new Version(10, 0), new VersionList(new Version[] { new Version(2, 0, 50727), new Version(4, 0, 30319) })); } } /////////////////////////////////////////////////////////////////////// - private static void ResetAllVsVersions() - { - if (vsVersionList != null) - { - vsVersionList.Clear(); - vsVersionList = null; - } - } - - /////////////////////////////////////////////////////////////////////// - - private static void InitializeAllVsVersions( - Configuration configuration - ) - { - if (vsVersionList == null) - { - vsVersionList = new VersionList(); - - // vsVersionList.Add(new Version(8, 0)); // Visual Studio 2005 - - if ((configuration == null) || !configuration.NoVs2008) - vsVersionList.Add(new Version(9, 0)); // Visual Studio 2008 - - if ((configuration == null) || !configuration.NoVs2010) - vsVersionList.Add(new Version(10, 0));// Visual Studio 2010 + private static void InitializeVsPackage( + ref Package package + ) + { + if (package == null) + { + package = new Package(); + + package.AdoNetTechnologyId = new Guid( + "77AB9A9D-78B9-4BA7-91AC-873F5338F1D2"); + + package.PackageId = new Guid( + "DCBE6C8D-0E57-4099-A183-98FF74C64D9C"); + + package.ServiceId = new Guid( + "DCBE6C8D-0E57-4099-A183-98FF74C64D9D"); + + package.DataSourceId = new Guid( + "0EBAAB6E-CA80-4B4A-8DDF-CBE6BF058C71"); + + package.DataProviderId = new Guid( + "0EBAAB6E-CA80-4B4A-8DDF-CBE6BF058C70"); } } /////////////////////////////////////////////////////////////////////// @@ -3314,10 +3464,13 @@ Version vsVersion, bool whatIf, bool verbose ) { + if (vsVersion == null) + return false; + string format = "Software\\Microsoft\\VisualStudio\\{0}"; string keyName = String.Format(format, vsVersion); using (MockRegistryKey key = RegistryHelper.OpenSubKey( rootKey, keyName, false, whatIf, verbose)) @@ -3344,22 +3497,26 @@ } /////////////////////////////////////////////////////////////////////// private static bool ForEachVsVersionRegistry( + VsList vsList, VisualStudioRegistryCallback callback, - Guid packageId, - Guid serviceId, - Guid dataSourceId, - Guid dataProviderId, + Package package, object clientData, bool whatIf, bool verbose, ref string error ) { - RegistryKey rootKey = vsRootKey; + if (vsList == null) + { + error = "invalid VS list"; + return false; + } + + RegistryKey rootKey = vsList.RootKey; if (rootKey == null) { error = "invalid root key"; return false; @@ -3370,17 +3527,17 @@ { error = "root key must be per-user or per-machine"; return false; } - if (vsVersionList == null) + if (vsList.Versions == null) { error = "no VS versions found"; return false; } - foreach (Version vsVersion in vsVersionList) + foreach (Version vsVersion in vsList.Versions) { TraceOps.Trace( TracePriority.Lower, traceCallback, String.Format( "vsVersion = {0}", ForDisplay(vsVersion)), traceCategory); @@ -3396,12 +3553,11 @@ if (callback == null) continue; if (!callback( - rootKey, vsVersion, packageId, serviceId, - dataSourceId, dataProviderId, clientData, whatIf, + rootKey, vsVersion, package, clientData, whatIf, verbose, ref error)) { return false; } } @@ -3753,10 +3909,13 @@ #region Visual Studio Handling private static string GetVsKeyName( Version vsVersion ) { + if (vsVersion == null) + return null; + return String.Format("Software\\Microsoft\\VisualStudio\\{0}", vsVersion); } /////////////////////////////////////////////////////////////////////// @@ -3763,24 +3922,30 @@ #region Visual Studio Version Handling private static bool AddVsVersion( RegistryKey rootKey, Version vsVersion, - Guid packageId, - Guid serviceId, - Guid dataSourceId, - Guid dataProviderId, + Package package, object clientData, bool whatIf, bool verbose, ref string error ) { - VersionList versionList = clientData as VersionList; + if (vsVersion != null) + { + VsList vsList = clientData as VsList; - if (versionList != null) - versionList.Add(vsVersion); + if (vsList != null) + { + if (vsList.InstalledVersions == null) + vsList.InstalledVersions = new VersionList(); + + if (!vsList.InstalledVersions.Contains(vsVersion)) + vsList.InstalledVersions.Add(vsVersion); + } + } return true; } #endregion @@ -3788,17 +3953,28 @@ #region Visual Studio Data Source Handling private static bool AddVsDataSource( RegistryKey rootKey, Version vsVersion, - Guid dataSourceId, - Guid dataProviderId, + Package package, bool whatIf, bool verbose, ref string error ) { + if (vsVersion == null) + { + error = "invalid VS version"; + return false; + } + + if (package == null) + { + error = "invalid VS package"; + return false; + } + string keyName = GetVsKeyName(vsVersion); using (MockRegistryKey key = RegistryHelper.OpenSubKey( rootKey, keyName, false, whatIf, verbose)) { @@ -3821,19 +3997,20 @@ key); return false; } - using (MockRegistryKey dataSourceKey = RegistryHelper.CreateSubKey( - subKey, dataSourceId.ToString(VsIdFormat), whatIf, - verbose)) + using (MockRegistryKey dataSourceKey = + RegistryHelper.CreateSubKey(subKey, + package.DataSourceId.ToString(VsIdFormat), + whatIf, verbose)) { if (dataSourceKey == null) { error = String.Format( - "could not create registry key: {0}\\{1}", - key, dataSourceId.ToString(VsIdFormat)); + "could not create registry key: {0}\\{1}", key, + package.DataSourceId.ToString(VsIdFormat)); return false; } RegistryHelper.SetValue( @@ -3841,12 +4018,12 @@ "{0} Database File", ProjectName), whatIf, verbose); RegistryHelper.CreateSubKey(dataSourceKey, String.Format("SupportingProviders\\{0}", - dataProviderId.ToString(VsIdFormat)), whatIf, - verbose); + package.DataProviderId.ToString(VsIdFormat)), + whatIf, verbose); } } } return true; @@ -3855,16 +4032,28 @@ /////////////////////////////////////////////////////////////////////// private static bool RemoveVsDataSource( RegistryKey rootKey, Version vsVersion, - Guid dataSourceId, + Package package, bool whatIf, bool verbose, ref string error ) { + if (vsVersion == null) + { + error = "invalid VS version"; + return false; + } + + if (package == null) + { + error = "invalid VS package"; + return false; + } + string keyName = GetVsKeyName(vsVersion); using (MockRegistryKey key = RegistryHelper.OpenSubKey( rootKey, keyName, false, whatIf, verbose)) { @@ -3888,12 +4077,12 @@ return false; } RegistryHelper.DeleteSubKeyTree( - subKey, dataSourceId.ToString(VsIdFormat), whatIf, - verbose); + subKey, package.DataSourceId.ToString(VsIdFormat), + whatIf, verbose); } } return true; } @@ -3901,20 +4090,23 @@ /////////////////////////////////////////////////////////////////////// private static bool ProcessVsDataSource( RegistryKey rootKey, Version vsVersion, - Guid packageId, /* NOT USED */ - Guid serviceId, /* NOT USED */ - Guid dataSourceId, - Guid dataProviderId, + Package package, object clientData, bool whatIf, bool verbose, ref string error ) { + if (package == null) + { + error = "invalid VS package"; + return false; + } + AnyPair pair = clientData as AnyPair; if (pair == null) { error = "invalid VS callback data"; @@ -3922,18 +4114,16 @@ } if (pair.Y) { return AddVsDataSource( - rootKey, vsVersion, dataSourceId, dataProviderId, - whatIf, verbose, ref error); + rootKey, vsVersion, package, whatIf, verbose, ref error); } else { return RemoveVsDataSource( - rootKey, vsVersion, dataSourceId, whatIf, verbose, - ref error); + rootKey, vsVersion, package, whatIf, verbose, ref error); } } #endregion /////////////////////////////////////////////////////////////////////// @@ -3940,21 +4130,26 @@ #region Visual Studio Data Provider Handling private static bool AddVsDataProvider( RegistryKey rootKey, Version vsVersion, - Guid serviceId, - Guid dataProviderId, + Package package, string fileName, bool whatIf, bool verbose, ref string error ) { - if (vsAdoNetTechnologyId == null) + if (vsVersion == null) + { + error = "invalid VS version"; + return false; + } + + if (package == null) { - error = "invalid ADO.NET technology Id"; + error = "invalid VS package"; return false; } string keyName = GetVsKeyName(vsVersion); @@ -3980,19 +4175,20 @@ key); return false; } - using (MockRegistryKey dataProviderKey = RegistryHelper.CreateSubKey( - subKey, dataProviderId.ToString(VsIdFormat), whatIf, - verbose)) + using (MockRegistryKey dataProviderKey = + RegistryHelper.CreateSubKey(subKey, + package.DataProviderId.ToString(VsIdFormat), + whatIf, verbose)) { if (dataProviderKey == null) { error = String.Format( - "could not create registry key: {0}\\{1}", - key, dataProviderId.ToString(VsIdFormat)); + "could not create registry key: {0}\\{1}", key, + package.DataProviderId.ToString(VsIdFormat)); return false; } RegistryHelper.SetValue( @@ -4003,20 +4199,21 @@ dataProviderKey, "InvariantName", InvariantName, whatIf, verbose); RegistryHelper.SetValue( dataProviderKey, "Technology", - ((Guid)vsAdoNetTechnologyId).ToString(VsIdFormat), + package.AdoNetTechnologyId.ToString(VsIdFormat), whatIf, verbose); RegistryHelper.SetValue( dataProviderKey, "CodeBase", fileName, whatIf, verbose); RegistryHelper.SetValue( dataProviderKey, "FactoryService", - serviceId.ToString(VsIdFormat), whatIf, verbose); + package.ServiceId.ToString(VsIdFormat), whatIf, + verbose); RegistryHelper.CreateSubKey(dataProviderKey, "SupportedObjects\\DataConnectionUIControl", whatIf, verbose); @@ -4045,16 +4242,22 @@ /////////////////////////////////////////////////////////////////////// private static bool RemoveVsDataProvider( RegistryKey rootKey, Version vsVersion, - Guid dataProviderId, + Package package, bool whatIf, bool verbose, ref string error ) { + if (vsVersion == null) + { + error = "invalid VS version"; + return false; + } + string keyName = GetVsKeyName(vsVersion); using (MockRegistryKey key = RegistryHelper.OpenSubKey( rootKey, keyName, false, whatIf, verbose)) { @@ -4078,12 +4281,12 @@ return false; } RegistryHelper.DeleteSubKeyTree( - subKey, dataProviderId.ToString(VsIdFormat), whatIf, - verbose); + subKey, package.DataProviderId.ToString(VsIdFormat), + whatIf, verbose); } } return true; } @@ -4091,14 +4294,11 @@ /////////////////////////////////////////////////////////////////////// private static bool ProcessVsDataProvider( RegistryKey rootKey, Version vsVersion, - Guid packageId, /* NOT USED */ - Guid serviceId, - Guid dataSourceId, /* NOT USED */ - Guid dataProviderId, + Package package, object clientData, bool whatIf, bool verbose, ref string error ) @@ -4112,18 +4312,18 @@ } if (pair.Y) { return AddVsDataProvider( - rootKey, vsVersion, serviceId, dataProviderId, pair.X, + rootKey, vsVersion, package, pair.X, whatIf, verbose, ref error); } else { return RemoveVsDataProvider( - rootKey, vsVersion, dataProviderId, whatIf, verbose, - ref error); + rootKey, vsVersion, package, whatIf, + verbose, ref error); } } #endregion /////////////////////////////////////////////////////////////////////// @@ -4130,18 +4330,29 @@ #region Visual Studio Package Handling private static bool AddVsPackage( RegistryKey rootKey, Version vsVersion, - Guid packageId, - Guid serviceId, + Package package, string fileName, bool whatIf, bool verbose, ref string error ) { + if (vsVersion == null) + { + error = "invalid VS version"; + return false; + } + + if (package == null) + { + error = "invalid VS package"; + return false; + } + string keyName = GetVsKeyName(vsVersion); using (MockRegistryKey key = RegistryHelper.OpenSubKey( rootKey, keyName, false, whatIf, verbose)) { @@ -4165,18 +4376,18 @@ return false; } using (MockRegistryKey packageKey = RegistryHelper.CreateSubKey( - subKey, packageId.ToString(VsIdFormat), whatIf, + subKey, package.PackageId.ToString(VsIdFormat), whatIf, verbose)) { if (packageKey == null) { error = String.Format( "could not create registry key: {0}\\{1}", - key, packageId.ToString(VsIdFormat)); + key, package.PackageId.ToString(VsIdFormat)); return false; } RegistryHelper.SetValue(packageKey, null, String.Format( @@ -4239,12 +4450,12 @@ return false; } RegistryHelper.SetValue( - subKey, packageId.ToString(VsIdFormat), ", 1000, 3", - whatIf, verbose); + subKey, package.PackageId.ToString(VsIdFormat), + ", 1000, 3", whatIf, verbose); } using (MockRegistryKey subKey = RegistryHelper.OpenSubKey( key, "Services", true, whatIf, verbose)) { @@ -4256,24 +4467,25 @@ return false; } using (MockRegistryKey serviceKey = RegistryHelper.CreateSubKey( - subKey, serviceId.ToString(VsIdFormat), whatIf, + subKey, package.ServiceId.ToString(VsIdFormat), whatIf, verbose)) { if (serviceKey == null) { error = String.Format( "could not create registry key: {0}\\{1}", - key, serviceId.ToString(VsIdFormat)); + key, package.ServiceId.ToString(VsIdFormat)); return false; } RegistryHelper.SetValue(serviceKey, null, - packageId.ToString(VsIdFormat), whatIf, verbose); + package.PackageId.ToString(VsIdFormat), whatIf, + verbose); RegistryHelper.SetValue(serviceKey, "Name", String.Format("{0} Designer Service", ProjectName), whatIf, verbose); } @@ -4286,17 +4498,28 @@ /////////////////////////////////////////////////////////////////////// private static bool RemoveVsPackage( RegistryKey rootKey, Version vsVersion, - Guid packageId, - Guid serviceId, + Package package, bool whatIf, bool verbose, ref string error ) { + if (vsVersion == null) + { + error = "invalid VS version"; + return false; + } + + if (package == null) + { + error = "invalid VS package"; + return false; + } + string keyName = GetVsKeyName(vsVersion); using (MockRegistryKey key = RegistryHelper.OpenSubKey( rootKey, keyName, false, whatIf, verbose)) { @@ -4320,11 +4543,12 @@ return false; } RegistryHelper.DeleteSubKeyTree( - key, packageId.ToString(VsIdFormat), whatIf, verbose); + key, package.PackageId.ToString(VsIdFormat), whatIf, + verbose); } using (MockRegistryKey subKey = RegistryHelper.OpenSubKey( key, "Menus", true, whatIf, verbose)) { @@ -4336,11 +4560,11 @@ return false; } RegistryHelper.DeleteValue( - subKey, packageId.ToString(VsIdFormat), whatIf, + subKey, package.PackageId.ToString(VsIdFormat), whatIf, verbose); } using (MockRegistryKey subKey = RegistryHelper.OpenSubKey( key, "Services", true, whatIf, verbose)) @@ -4353,11 +4577,11 @@ return false; } RegistryHelper.DeleteSubKeyTree( - subKey, serviceId.ToString(VsIdFormat), whatIf, + subKey, package.ServiceId.ToString(VsIdFormat), whatIf, verbose); } } return true; @@ -4366,14 +4590,11 @@ /////////////////////////////////////////////////////////////////////// private static bool ProcessVsPackage( RegistryKey rootKey, Version vsVersion, - Guid packageId, - Guid serviceId, - Guid dataSourceId, - Guid dataProviderId, + Package package, object clientData, bool whatIf, bool verbose, ref string error ) @@ -4387,52 +4608,33 @@ } if (pair.Y) { return AddVsPackage( - rootKey, vsVersion, packageId, serviceId, pair.X, whatIf, + rootKey, vsVersion, package, pair.X, whatIf, verbose, ref error); } else { return RemoveVsPackage( - rootKey, vsVersion, packageId, serviceId, whatIf, verbose, + rootKey, vsVersion, package, whatIf, verbose, ref error); } } #endregion #endregion /////////////////////////////////////////////////////////////////////// #region Application Entry Point - public static string GetImageRuntimeVersion( - string fileName - ) - { - try - { - Assembly assembly = - Assembly.ReflectionOnlyLoadFrom(fileName); /* throw */ - - if (assembly != null) - return assembly.ImageRuntimeVersion; - } - catch - { - // do nothing. - } - - return null; - } - - /////////////////////////////////////////////////////////////////////// - private static int Main( string[] args ) { + Package package = null; + FrameworkList frameworkList = null; + VsList vsList = null; Configuration configuration = null; string error = null; /////////////////////////////////////////////////////////////////// @@ -4447,58 +4649,50 @@ error, traceCategory, MessageBoxButtons.OK, MessageBoxIcon.Error); return 1; /* FAILURE */ } + + /////////////////////////////////////////////////////////////////// + + InitializeVsPackage(ref package); + InitializeFrameworkList(configuration, ref frameworkList); + InitializeVsList(configuration, ref vsList); #endregion /////////////////////////////////////////////////////////////////// +#if false #region Check Installed VS Versions - InitializeVsRootKeyAndIds(); - InitializeAllFrameworks(null); - InitializeAllVsVersions(null); - - VersionList installedVsVersions = new VersionList(); - if (configuration.HasFlags(InstallFlags.All, /* any */ false)) { - if (!ForEachVsVersionRegistry(AddVsVersion, - Guid.Empty, Guid.Empty, Guid.Empty, Guid.Empty, - installedVsVersions, configuration.WhatIf, - configuration.Verbose, ref error)) + if (!ForEachVsVersionRegistry( + vsList, AddVsVersion, null, vsList, + configuration.WhatIf, configuration.Verbose, + ref error)) + { + TraceOps.ShowMessage( + TracePriority.Highest, traceCallback, null, + error, traceCategory, MessageBoxButtons.OK, + MessageBoxIcon.Error); + + return 1; /* FAILURE */ + } + + if (!Configuration.CheckImageRuntimeVersion( + configuration, vsList, true, ref error)) { TraceOps.ShowMessage( TracePriority.Highest, traceCallback, null, error, traceCategory, MessageBoxButtons.OK, MessageBoxIcon.Error); return 1; /* FAILURE */ } } - - InitializeVsFrameworkVersionMap(configuration); - - /////////////////////////////////////////////////////////////////// - - if (!Configuration.CheckImageRuntimeVersion( - configuration, vsFrameworkVersionMap, - installedVsVersions, true, ref error)) - { - TraceOps.ShowMessage( - TracePriority.Highest, traceCallback, thisAssembly, - error, traceCategory, MessageBoxButtons.OK, - MessageBoxIcon.Error); - - return 1; /* FAILURE */ - } - - /////////////////////////////////////////////////////////////////// - - InitializeAllFrameworks(configuration); - InitializeAllVsVersions(configuration); #endregion +#endif /////////////////////////////////////////////////////////////////// AssemblyName assemblyName = AssemblyName.GetAssemblyName( configuration.CoreFileName); /* throw */ @@ -4563,11 +4757,12 @@ /////////////////////////////////////////////////////////////////// #region .NET AssemblyFolders if (configuration.HasFlags(InstallFlags.AssemblyFolders, true)) { - if (!ForEachFrameworkRegistry(ProcessAssemblyFolders, + if (!ForEachFrameworkRegistry( + frameworkList, ProcessAssemblyFolders, directoryPair, configuration.WhatIf, configuration.Verbose, ref error)) { TraceOps.ShowMessage( TracePriority.Highest, traceCallback, null, @@ -4584,11 +4779,12 @@ #region .NET DbProviderFactory if (configuration.HasFlags(InstallFlags.DbProviderFactory, true)) { bool saved = false; - if (!ForEachFrameworkConfig(ProcessDbProviderFactory, + if (!ForEachFrameworkConfig( + frameworkList, ProcessDbProviderFactory, InvariantName, ProviderName, Description, FactoryTypeName, assemblyName, directoryPair, configuration.WhatIf, configuration.Verbose, ref saved, ref error)) { @@ -4605,15 +4801,14 @@ /////////////////////////////////////////////////////////////////// #region VS Package if (configuration.HasFlags(InstallFlags.VsPackage, true)) { - if (!ForEachVsVersionRegistry(ProcessVsPackage, - (Guid)vsPackageId, (Guid)vsServiceId, - (Guid)vsDataSourcesId, (Guid)vsDataProviderId, - fileNamePair, configuration.WhatIf, - configuration.Verbose, ref error)) + if (!ForEachVsVersionRegistry( + vsList, ProcessVsPackage, package, fileNamePair, + configuration.WhatIf, configuration.Verbose, + ref error)) { TraceOps.ShowMessage( TracePriority.Highest, traceCallback, null, error, traceCategory, MessageBoxButtons.OK, MessageBoxIcon.Error); @@ -4626,15 +4821,14 @@ /////////////////////////////////////////////////////////////////// #region VS DataSource if (configuration.HasFlags(InstallFlags.VsDataSource, true)) { - if (!ForEachVsVersionRegistry(ProcessVsDataSource, - (Guid)vsPackageId, (Guid)vsServiceId, - (Guid)vsDataSourcesId, (Guid)vsDataProviderId, - fileNamePair, configuration.WhatIf, - configuration.Verbose, ref error)) + if (!ForEachVsVersionRegistry( + vsList, ProcessVsDataSource, package, fileNamePair, + configuration.WhatIf, configuration.Verbose, + ref error)) { TraceOps.ShowMessage( TracePriority.Highest, traceCallback, null, error, traceCategory, MessageBoxButtons.OK, MessageBoxIcon.Error); @@ -4647,15 +4841,14 @@ /////////////////////////////////////////////////////////////////// #region VS DataProvider if (configuration.HasFlags(InstallFlags.VsDataProvider, true)) { - if (!ForEachVsVersionRegistry(ProcessVsDataProvider, - (Guid)vsPackageId, (Guid)vsServiceId, - (Guid)vsDataSourcesId, (Guid)vsDataProviderId, - fileNamePair, configuration.WhatIf, - configuration.Verbose, ref error)) + if (!ForEachVsVersionRegistry( + vsList, ProcessVsDataProvider, package, fileNamePair, + configuration.WhatIf, configuration.Verbose, + ref error)) { TraceOps.ShowMessage( TracePriority.Highest, traceCallback, null, error, traceCategory, MessageBoxButtons.OK, MessageBoxIcon.Error);