private ICatalogObject CreateApplication(ApplicationSpec spec, bool checkExistence) { if (checkExistence && (this.FindApplication(this._appColl, spec) != null)) { throw new RegistrationException(Resource.FormatString("Reg_AppExistsErr", spec)); } ICatalogObject obj3 = (ICatalogObject)this._appColl.Add(); this.CheckForAppSecurityAttribute(spec.Assembly); this.ApplicationDefaults(obj3, this._appColl); obj3.SetValue("Name", spec.Name); if (spec.ID != null) { obj3.SetValue("ID", spec.ID); } if (spec.AppRootDir != null) { obj3.SetValue("ApplicationDirectory", spec.AppRootDir); } SaveChanges(this._appColl); this.ConfigureObject(spec.Assembly, obj3, this._appColl, "Application", this._cache); spec.Name = (string)obj3.GetValue("Name"); SaveChanges(this._appColl); return(obj3); }
private void ConfigureComponents(ApplicationSpec spec) { ICatalogCollection coll = null; try { ICatalogObject obj2 = this.FindApplication(this._appColl, spec); if (obj2 == null) { throw new RegistrationException(Resource.FormatString("Reg_AppNotFoundErr", spec)); } this._cache["Application"] = obj2; this._cache["ApplicationType"] = spec.Assembly; this._cache["ApplicationCollection"] = this._appColl; coll = (ICatalogCollection)this._appColl.GetCollection(CollectionName.Components, obj2.Key()); this.ConfigureCollection(coll, new ComponentConfigCallback(coll, spec, this._cache, this, this._installFlags)); } catch (RegistrationException) { throw; } catch (COMException exception) { throw this.WrapCOMException(coll, exception, Resource.FormatString("Reg_ConfigErr")); } catch (Exception exception2) { if ((exception2 is NullReferenceException) || (exception2 is SEHException)) { throw; } throw new RegistrationException(Resource.FormatString("Reg_ConfigUnkErr"), exception2); } }
internal void UnregisterAssembly(Assembly asm, ApplicationSpec spec) { bool flag = true; if ((null != asm) && ((spec != null) && (spec.ConfigurableTypes != null))) { foreach (Type type in spec.ConfigurableTypes) { string str = "{" + Marshal.GenerateGuidForType(type).ToString() + "}"; try { int num = 0; Type type2 = this._cat.GetType(); try { object[] args = new object[5]; args[0] = str; num = (int)this.InvokeMemberHelper(type2, "GetComponentVersions", BindingFlags.InvokeMethod, null, this._cat, args); } catch (COMException exception) { if (-2147352570 != exception.ErrorCode) { throw; } num = (int)this.InvokeMemberHelper(type2, "GetComponentVersionCount", BindingFlags.InvokeMethod, null, this._cat, new object[] { str }); } if (num > 0) { flag = false; break; } } catch (COMException exception2) { if (-2147221164 != exception2.ErrorCode) { throw; } } } if (flag) { this.ClassicUnregistration(asm); try { this.UnregisterTypeLib(asm); } catch (Exception exception3) { if ((exception3 is NullReferenceException) || (exception3 is SEHException)) { throw; } } } } }
public ComponentConfigCallback(ICatalogCollection coll, ApplicationSpec spec, Hashtable cache, RegistrationDriver driver, InstallationFlags installFlags) { this._spec = spec; this._coll = coll; this._cache = cache; this._driver = driver; this._installFlags = installFlags; RegistrationDriver.Populate(coll); }
internal bool IsAssemblyRegistered(ApplicationSpec spec) { bool flag = false; if ((spec == null) || (spec.ConfigurableTypes == null)) { return(false); } RegistryKey key = Registry.ClassesRoot.OpenSubKey("CLSID"); if (key == null) { throw new RegistrationException(Resource.FormatString("Reg_RegistryErr")); } foreach (Type type in spec.ConfigurableTypes) { string name = "{" + Marshal.GenerateGuidForType(type).ToString() + "}"; RegistryKey key2 = null; RegistryKey key3 = null; try { key2 = key.OpenSubKey(name); if (key2 != null) { key3 = key2.OpenSubKey("InprocServer32"); if (((key3 != null) && (key3.GetValue("Assembly") != null)) && (key3.GetValue("Class") != null)) { flag = true; break; } } } catch (Exception exception) { if ((exception is NullReferenceException) || (exception is SEHException)) { throw; } } finally { if (key3 != null) { key3.Close(); } if (key2 != null) { key2.Close(); } } } key.Close(); return(flag); }
private ICatalogObject FindApplication(ICatalogCollection apps, ApplicationSpec spec) { for (int i = 0; i < apps.Count(); i++) { ICatalogObject obj2 = (ICatalogObject)apps.Item(i); if (spec.Matches(obj2)) { return(obj2); } } return(null); }
private bool ValidateBitness(ApplicationSpec spec, out string message) { bool flag = false; bool flag2 = true; message = string.Empty; if (Wow64Helper.IsWow64Supported()) { flag = Wow64Helper.IsWow64Process(); ICatalogObject obj2 = this.FindApplication(this._appColl, spec); if (obj2 == null) { return(flag2); } ICatalogCollection collection = (ICatalogCollection)this._appColl.GetCollection(CollectionName.Components, obj2.Key()); Populate(collection); int num = collection.Count(); if (num <= 0) { return(flag2); } Guid[] arr = new Guid[spec.ConfigurableTypes.Length]; for (int i = 0; i < spec.ConfigurableTypes.Length; i++) { arr[i] = Marshal.GenerateGuidForType(spec.ConfigurableTypes[i]); } for (int j = 0; j < num; j++) { ICatalogObject obj3 = (ICatalogObject)collection.Item(j); string g = (string)obj3.Key(); Guid key = new Guid(g); if (this.FindIndexOf(arr, key) != -1) { int num4 = (int)obj3.GetValue("Bitness"); if (flag && (num4 == 2)) { message = Resource.FormatString("Reg_Already64bit"); return(false); } if (!flag && (num4 == 1)) { message = Resource.FormatString("Reg_Already32bit"); return(false); } } } } return(flag2); }
public ComponentConfigCallback(ICatalogCollection coll, ApplicationSpec spec, Hashtable cache, RegistrationDriver driver, InstallationFlags installFlags) { _spec = spec; _coll = coll; _cache = cache; _driver = driver; _installFlags = installFlags; // TODO: Populate w/ QueryByKey // TODO: Cache for FindObject RegistrationDriver.Populate(coll); }
private void PostProcessApplication(ICatalogObject app, ApplicationSpec spec) { try { if (this.AfterSaveChanges(spec.Assembly, app, this._appColl, "Application", this._cache)) { SaveChanges(this._appColl); } } catch (Exception exception) { if ((exception is NullReferenceException) || (exception is SEHException)) { throw; } throw new RegistrationException(Resource.FormatString("Reg_ConfigUnkErr"), exception); } }
private ICatalogObject FindOrCreateApplication(ApplicationSpec spec, bool configure) { ICatalogObject obj2 = this.FindApplication(this._appColl, spec); if (obj2 == null) { return(this.CreateApplication(spec, false)); } if (configure) { this.CheckForAppSecurityAttribute(spec.Assembly); this.ApplicationDefaults(obj2, this._appColl); obj2.SetValue("Name", spec.Name); obj2.SetValue("ApplicationDirectory", (spec.AppRootDir == null) ? "" : spec.AppRootDir); this.ConfigureObject(spec.Assembly, obj2, this._appColl, "Application", this._cache); spec.Name = (string)obj2.GetValue("Name"); SaveChanges(this._appColl); } return(obj2); }
private void InstallTypeLibrary(ApplicationSpec spec) { try { object[] fileNames = new object[] { spec.TypeLib }; Type[] normalTypes = spec.NormalTypes; if (normalTypes != null) { if ((normalTypes == null) || (normalTypes.Length == 0)) { throw new RegistrationException(Resource.FormatString("Reg_NoConfigTypesErr")); } object[] cLSIDS = new object[normalTypes.Length]; for (int i = 0; i < normalTypes.Length; i++) { cLSIDS[i] = "{" + Marshal.GenerateGuidForType(normalTypes[i]).ToString() + "}"; } this._cat.InstallMultipleComponents(spec.DefinitiveName, ref fileNames, ref cLSIDS); } normalTypes = spec.EventTypes; if (normalTypes != null) { if ((normalTypes == null) || (normalTypes.Length == 0)) { throw new RegistrationException(Resource.FormatString("Reg_NoConfigTypesErr")); } object[] objArray3 = new object[normalTypes.Length]; for (int j = 0; j < normalTypes.Length; j++) { objArray3[j] = "{" + Marshal.GenerateGuidForType(normalTypes[j]).ToString() + "}"; } this._cat.InstallMultipleEventClasses(spec.DefinitiveName, ref fileNames, ref objArray3); } } catch (COMException exception) { throw this.WrapCOMException(null, exception, Resource.FormatString("Reg_TypeLibInstallErr", spec.TypeLib, spec.Name)); } }
private ICatalogObject FindOrCreateApplication(ApplicationSpec spec, bool configure) { ICatalogObject obj2 = this.FindApplication(this._appColl, spec); if (obj2 == null) { return this.CreateApplication(spec, false); } if (configure) { this.CheckForAppSecurityAttribute(spec.Assembly); this.ApplicationDefaults(obj2, this._appColl); obj2.SetValue("Name", spec.Name); obj2.SetValue("ApplicationDirectory", (spec.AppRootDir == null) ? "" : spec.AppRootDir); this.ConfigureObject(spec.Assembly, obj2, this._appColl, "Application", this._cache); spec.Name = (string) obj2.GetValue("Name"); SaveChanges(this._appColl); } return obj2; }
internal bool IsAssemblyRegistered(ApplicationSpec spec) { bool flag = false; if ((spec == null) || (spec.ConfigurableTypes == null)) { return false; } RegistryKey key = Registry.ClassesRoot.OpenSubKey("CLSID"); if (key == null) { throw new RegistrationException(Resource.FormatString("Reg_RegistryErr")); } foreach (Type type in spec.ConfigurableTypes) { string name = "{" + Marshal.GenerateGuidForType(type).ToString() + "}"; RegistryKey key2 = null; RegistryKey key3 = null; try { key2 = key.OpenSubKey(name); if (key2 != null) { key3 = key2.OpenSubKey("InprocServer32"); if (((key3 != null) && (key3.GetValue("Assembly") != null)) && (key3.GetValue("Class") != null)) { flag = true; break; } } } catch (Exception exception) { if ((exception is NullReferenceException) || (exception is SEHException)) { throw; } } finally { if (key3 != null) { key3.Close(); } if (key2 != null) { key2.Close(); } } } key.Close(); return flag; }
public void InstallAssembly(RegistrationConfig regConfig, object obSync) { Assembly asm = null; ApplicationSpec spec = null; CatalogSync sync = null; bool flag = false; bool flag2 = false; SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode); try { permission.Demand(); permission.Assert(); ICatalogObject app = null; this.PrepArguments(regConfig); asm = this.NewLoadAssembly(regConfig.AssemblyFile); spec = new ApplicationSpec(asm, regConfig); if (spec.ConfigurableTypes == null) { regConfig.Application = null; regConfig.TypeLibrary = null; } else { if (obSync != null) { if (!(obSync is CatalogSync)) { throw new ArgumentException(Resource.FormatString("Err_obSync")); } sync = (CatalogSync)obSync; } this.PrepDriver(ref spec); string message = string.Empty; if (!this.ValidateBitness(spec, out message)) { throw new RegistrationException(message); } if ((regConfig.InstallationFlags & InstallationFlags.Register) != InstallationFlags.Default) { flag = !this.IsAssemblyRegistered(spec); this.ClassicRegistration(spec.Assembly); if ((regConfig.InstallationFlags & InstallationFlags.ExpectExistingTypeLib) != InstallationFlags.Default) { RegisterTypeLibrary(spec.TypeLib); } else { flag2 = true; GenerateTypeLibrary(spec.Assembly, spec.TypeLib, new Report(this.ReportWarning)); } } if (((regConfig.InstallationFlags & InstallationFlags.Install) != InstallationFlags.Default) && (spec.ConfigurableTypes != null)) { if ((regConfig.InstallationFlags & InstallationFlags.CreateTargetApplication) != InstallationFlags.Default) { app = this.CreateApplication(spec, true); } else if ((regConfig.InstallationFlags & InstallationFlags.FindOrCreateTargetApplication) != InstallationFlags.Default) { app = this.FindOrCreateApplication(spec, (regConfig.InstallationFlags & InstallationFlags.ReconfigureExistingApplication) != InstallationFlags.Default); } this.InstallTypeLibrary(spec); if (sync != null) { sync.Set(); } } if (((regConfig.InstallationFlags & InstallationFlags.Configure) != InstallationFlags.Default) && (spec.ConfigurableTypes != null)) { this.ConfigureComponents(spec); if (sync != null) { sync.Set(); } } if (app != null) { this.PostProcessApplication(app, spec); } this.CleanupDriver(); } } catch (Exception exception) { if ((exception is NullReferenceException) || (exception is SEHException)) { throw; } if (((exception is SecurityException) || (exception is UnauthorizedAccessException)) || ((exception.InnerException != null) && ((exception.InnerException is SecurityException) || (exception.InnerException is UnauthorizedAccessException)))) { exception = new RegistrationException(Resource.FormatString("Reg_Unauthorized"), exception); } if (flag && (null != asm)) { try { this.ClassicUnregistration(asm); } catch (Exception exception2) { if ((exception2 is NullReferenceException) || (exception2 is SEHException)) { throw; } } } if (flag2 && (null != asm)) { try { this.UnregisterTypeLib(asm); } catch (Exception exception3) { if ((exception3 is NullReferenceException) || (exception3 is SEHException)) { throw; } } } throw exception; } }
private ICatalogObject CreateApplication(ApplicationSpec spec, bool checkExistence) { if (checkExistence && (this.FindApplication(this._appColl, spec) != null)) { throw new RegistrationException(Resource.FormatString("Reg_AppExistsErr", spec)); } ICatalogObject obj3 = (ICatalogObject) this._appColl.Add(); this.CheckForAppSecurityAttribute(spec.Assembly); this.ApplicationDefaults(obj3, this._appColl); obj3.SetValue("Name", spec.Name); if (spec.ID != null) { obj3.SetValue("ID", spec.ID); } if (spec.AppRootDir != null) { obj3.SetValue("ApplicationDirectory", spec.AppRootDir); } SaveChanges(this._appColl); this.ConfigureObject(spec.Assembly, obj3, this._appColl, "Application", this._cache); spec.Name = (string) obj3.GetValue("Name"); SaveChanges(this._appColl); return obj3; }
private void PrepDriver(ref ApplicationSpec spec) { try { this._cat = (ICatalog) new xCatalog(); } catch (Exception exception) { if ((exception is NullReferenceException) || (exception is SEHException)) { throw; } throw new RegistrationException(Resource.FormatString("Reg_CatalogErr"), exception); } if (((spec.Partition == null) || (spec.Partition.Length == 0)) && (spec.ID != null)) { try { Type type = this._cat.GetType(); try { spec.Partition = (string)this.InvokeMemberHelper(type, "GetAppPartitionId", BindingFlags.InvokeMethod, null, this._cat, new object[] { spec.ID }); } catch (COMException exception2) { if (-2147352570 == exception2.ErrorCode) { spec.Partition = (string)this.InvokeMemberHelper(type, "GetPartitionID", BindingFlags.InvokeMethod, null, this._cat, new object[] { spec.ID }); } } } catch (Exception exception3) { if ((exception3 is NullReferenceException) || (exception3 is SEHException)) { throw; } } } if ((spec.Partition != null) && (spec.Partition.Length != 0)) { try { Type type2 = this._cat.GetType(); try { this.InvokeMemberHelper(type2, "SetApplicationPartition", BindingFlags.InvokeMethod, null, this._cat, new object[] { spec.Partition }); } catch (COMException exception4) { if (-2147352570 != exception4.ErrorCode) { throw; } this.InvokeMemberHelper(type2, "CurrentPartition", BindingFlags.SetProperty, null, this._cat, new object[] { spec.Partition }); } } catch (Exception exception5) { if ((exception5 is NullReferenceException) || (exception5 is SEHException)) { throw; } throw new RegistrationException(Resource.FormatString("Reg_PartitionErr", spec.Partition), exception5); } } try { this._appColl = (ICatalogCollection)this._cat.GetCollection(CollectionName.Applications); Populate(this._appColl); } catch (Exception exception6) { if ((exception6 is NullReferenceException) || (exception6 is SEHException)) { throw; } throw new RegistrationException(Resource.FormatString("Reg_CatalogErr"), exception6); } this._cache = new Hashtable(); }
private void ConfigureComponents(ApplicationSpec spec) { ICatalogCollection coll = null; try { ICatalogObject obj2 = this.FindApplication(this._appColl, spec); if (obj2 == null) { throw new RegistrationException(Resource.FormatString("Reg_AppNotFoundErr", spec)); } this._cache["Application"] = obj2; this._cache["ApplicationType"] = spec.Assembly; this._cache["ApplicationCollection"] = this._appColl; coll = (ICatalogCollection) this._appColl.GetCollection(CollectionName.Components, obj2.Key()); this.ConfigureCollection(coll, new ComponentConfigCallback(coll, spec, this._cache, this, this._installFlags)); } catch (RegistrationException) { throw; } catch (COMException exception) { throw this.WrapCOMException(coll, exception, Resource.FormatString("Reg_ConfigErr")); } catch (Exception exception2) { if ((exception2 is NullReferenceException) || (exception2 is SEHException)) { throw; } throw new RegistrationException(Resource.FormatString("Reg_ConfigUnkErr"), exception2); } }
private void PrepDriver(ref ApplicationSpec spec) { try { this._cat = (ICatalog) new xCatalog(); } catch (Exception exception) { if ((exception is NullReferenceException) || (exception is SEHException)) { throw; } throw new RegistrationException(Resource.FormatString("Reg_CatalogErr"), exception); } if (((spec.Partition == null) || (spec.Partition.Length == 0)) && (spec.ID != null)) { try { Type type = this._cat.GetType(); try { spec.Partition = (string) this.InvokeMemberHelper(type, "GetAppPartitionId", BindingFlags.InvokeMethod, null, this._cat, new object[] { spec.ID }); } catch (COMException exception2) { if (-2147352570 == exception2.ErrorCode) { spec.Partition = (string) this.InvokeMemberHelper(type, "GetPartitionID", BindingFlags.InvokeMethod, null, this._cat, new object[] { spec.ID }); } } } catch (Exception exception3) { if ((exception3 is NullReferenceException) || (exception3 is SEHException)) { throw; } } } if ((spec.Partition != null) && (spec.Partition.Length != 0)) { try { Type type2 = this._cat.GetType(); try { this.InvokeMemberHelper(type2, "SetApplicationPartition", BindingFlags.InvokeMethod, null, this._cat, new object[] { spec.Partition }); } catch (COMException exception4) { if (-2147352570 != exception4.ErrorCode) { throw; } this.InvokeMemberHelper(type2, "CurrentPartition", BindingFlags.SetProperty, null, this._cat, new object[] { spec.Partition }); } } catch (Exception exception5) { if ((exception5 is NullReferenceException) || (exception5 is SEHException)) { throw; } throw new RegistrationException(Resource.FormatString("Reg_PartitionErr", spec.Partition), exception5); } } try { this._appColl = (ICatalogCollection) this._cat.GetCollection(CollectionName.Applications); Populate(this._appColl); } catch (Exception exception6) { if ((exception6 is NullReferenceException) || (exception6 is SEHException)) { throw; } throw new RegistrationException(Resource.FormatString("Reg_CatalogErr"), exception6); } this._cache = new Hashtable(); }
internal void UnregisterAssembly(Assembly asm, ApplicationSpec spec) { bool flag = true; if ((null != asm) && ((spec != null) && (spec.ConfigurableTypes != null))) { foreach (Type type in spec.ConfigurableTypes) { string str = "{" + Marshal.GenerateGuidForType(type).ToString() + "}"; try { int num = 0; Type type2 = this._cat.GetType(); try { object[] args = new object[5]; args[0] = str; num = (int) this.InvokeMemberHelper(type2, "GetComponentVersions", BindingFlags.InvokeMethod, null, this._cat, args); } catch (COMException exception) { if (-2147352570 != exception.ErrorCode) { throw; } num = (int) this.InvokeMemberHelper(type2, "GetComponentVersionCount", BindingFlags.InvokeMethod, null, this._cat, new object[] { str }); } if (num > 0) { flag = false; break; } } catch (COMException exception2) { if (-2147221164 != exception2.ErrorCode) { throw; } } } if (flag) { this.ClassicUnregistration(asm); try { this.UnregisterTypeLib(asm); } catch (Exception exception3) { if ((exception3 is NullReferenceException) || (exception3 is SEHException)) { throw; } } } } }
public void UninstallAssembly(RegistrationConfig regConfig, object obSync) { CatalogSync sync = null; SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode); permission.Demand(); permission.Assert(); if (obSync != null) { if (!(obSync is CatalogSync)) { throw new ArgumentException(Resource.FormatString("Err_obSync")); } sync = (CatalogSync) obSync; } Assembly asm = this.NewLoadAssembly(regConfig.AssemblyFile); ApplicationSpec spec = new ApplicationSpec(asm, regConfig); if (spec.ConfigurableTypes != null) { this.PrepDriver(ref spec); if (spec.ConfigurableTypes != null) { ICatalogObject obj2 = this.FindApplication(this._appColl, spec); if (obj2 == null) { throw new RegistrationException(Resource.FormatString("Reg_AppNotFoundErr", spec)); } ICatalogCollection collection = (ICatalogCollection) this._appColl.GetCollection(CollectionName.Components, obj2.Key()); string[] arr = new string[spec.ConfigurableTypes.Length]; int index = 0; foreach (Type type in spec.ConfigurableTypes) { arr[index] = Marshal.GenerateGuidForType(type).ToString(); index++; } Populate(collection); bool flag = true; int lIndex = 0; while (lIndex < collection.Count()) { ICatalogObject obj3 = (ICatalogObject) collection.Item(lIndex); string g = (string) obj3.Key(); g = new Guid(g).ToString(); if (this.FindIndexOf(arr, g) != -1) { collection.Remove(lIndex); if (sync != null) { sync.Set(); } } else { lIndex++; flag = false; } } SaveChanges(collection); if (flag) { for (int i = 0; i < this._appColl.Count(); i++) { ICatalogObject obj4 = (ICatalogObject) this._appColl.Item(i); if (obj4.Key().Equals(obj2.Key())) { this._appColl.Remove(i); if (sync != null) { sync.Set(); } break; } } SaveChanges(this._appColl); } } this.UnregisterAssembly(asm, spec); this.CleanupDriver(); } }
public void UninstallAssembly(RegistrationConfig regConfig, object obSync) { CatalogSync sync = null; SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode); permission.Demand(); permission.Assert(); if (obSync != null) { if (!(obSync is CatalogSync)) { throw new ArgumentException(Resource.FormatString("Err_obSync")); } sync = (CatalogSync)obSync; } Assembly asm = this.NewLoadAssembly(regConfig.AssemblyFile); ApplicationSpec spec = new ApplicationSpec(asm, regConfig); if (spec.ConfigurableTypes != null) { this.PrepDriver(ref spec); if (spec.ConfigurableTypes != null) { ICatalogObject obj2 = this.FindApplication(this._appColl, spec); if (obj2 == null) { throw new RegistrationException(Resource.FormatString("Reg_AppNotFoundErr", spec)); } ICatalogCollection collection = (ICatalogCollection)this._appColl.GetCollection(CollectionName.Components, obj2.Key()); string[] arr = new string[spec.ConfigurableTypes.Length]; int index = 0; foreach (Type type in spec.ConfigurableTypes) { arr[index] = Marshal.GenerateGuidForType(type).ToString(); index++; } Populate(collection); bool flag = true; int lIndex = 0; while (lIndex < collection.Count()) { ICatalogObject obj3 = (ICatalogObject)collection.Item(lIndex); string g = (string)obj3.Key(); g = new Guid(g).ToString(); if (this.FindIndexOf(arr, g) != -1) { collection.Remove(lIndex); if (sync != null) { sync.Set(); } } else { lIndex++; flag = false; } } SaveChanges(collection); if (flag) { for (int i = 0; i < this._appColl.Count(); i++) { ICatalogObject obj4 = (ICatalogObject)this._appColl.Item(i); if (obj4.Key().Equals(obj2.Key())) { this._appColl.Remove(i); if (sync != null) { sync.Set(); } break; } } SaveChanges(this._appColl); } } this.UnregisterAssembly(asm, spec); this.CleanupDriver(); } }
private ICatalogObject FindApplication(ICatalogCollection apps, ApplicationSpec spec) { for (int i = 0; i < apps.Count(); i++) { ICatalogObject obj2 = (ICatalogObject) apps.Item(i); if (spec.Matches(obj2)) { return obj2; } } return null; }
private bool ValidateBitness(ApplicationSpec spec, out string message) { bool flag = false; bool flag2 = true; message = string.Empty; if (Wow64Helper.IsWow64Supported()) { flag = Wow64Helper.IsWow64Process(); ICatalogObject obj2 = this.FindApplication(this._appColl, spec); if (obj2 == null) { return flag2; } ICatalogCollection collection = (ICatalogCollection) this._appColl.GetCollection(CollectionName.Components, obj2.Key()); Populate(collection); int num = collection.Count(); if (num <= 0) { return flag2; } Guid[] arr = new Guid[spec.ConfigurableTypes.Length]; for (int i = 0; i < spec.ConfigurableTypes.Length; i++) { arr[i] = Marshal.GenerateGuidForType(spec.ConfigurableTypes[i]); } for (int j = 0; j < num; j++) { ICatalogObject obj3 = (ICatalogObject) collection.Item(j); string g = (string) obj3.Key(); Guid key = new Guid(g); if (this.FindIndexOf(arr, key) != -1) { int num4 = (int) obj3.GetValue("Bitness"); if (flag && (num4 == 2)) { message = Resource.FormatString("Reg_Already64bit"); return false; } if (!flag && (num4 == 1)) { message = Resource.FormatString("Reg_Already32bit"); return false; } } } } return flag2; }
public void InstallAssembly(RegistrationConfig regConfig, object obSync) { Assembly asm = null; ApplicationSpec spec = null; CatalogSync sync = null; bool flag = false; bool flag2 = false; SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode); try { permission.Demand(); permission.Assert(); ICatalogObject app = null; this.PrepArguments(regConfig); asm = this.NewLoadAssembly(regConfig.AssemblyFile); spec = new ApplicationSpec(asm, regConfig); if (spec.ConfigurableTypes == null) { regConfig.Application = null; regConfig.TypeLibrary = null; } else { if (obSync != null) { if (!(obSync is CatalogSync)) { throw new ArgumentException(Resource.FormatString("Err_obSync")); } sync = (CatalogSync) obSync; } this.PrepDriver(ref spec); string message = string.Empty; if (!this.ValidateBitness(spec, out message)) { throw new RegistrationException(message); } if ((regConfig.InstallationFlags & InstallationFlags.Register) != InstallationFlags.Default) { flag = !this.IsAssemblyRegistered(spec); this.ClassicRegistration(spec.Assembly); if ((regConfig.InstallationFlags & InstallationFlags.ExpectExistingTypeLib) != InstallationFlags.Default) { RegisterTypeLibrary(spec.TypeLib); } else { flag2 = true; GenerateTypeLibrary(spec.Assembly, spec.TypeLib, new Report(this.ReportWarning)); } } if (((regConfig.InstallationFlags & InstallationFlags.Install) != InstallationFlags.Default) && (spec.ConfigurableTypes != null)) { if ((regConfig.InstallationFlags & InstallationFlags.CreateTargetApplication) != InstallationFlags.Default) { app = this.CreateApplication(spec, true); } else if ((regConfig.InstallationFlags & InstallationFlags.FindOrCreateTargetApplication) != InstallationFlags.Default) { app = this.FindOrCreateApplication(spec, (regConfig.InstallationFlags & InstallationFlags.ReconfigureExistingApplication) != InstallationFlags.Default); } this.InstallTypeLibrary(spec); if (sync != null) { sync.Set(); } } if (((regConfig.InstallationFlags & InstallationFlags.Configure) != InstallationFlags.Default) && (spec.ConfigurableTypes != null)) { this.ConfigureComponents(spec); if (sync != null) { sync.Set(); } } if (app != null) { this.PostProcessApplication(app, spec); } this.CleanupDriver(); } } catch (Exception exception) { if ((exception is NullReferenceException) || (exception is SEHException)) { throw; } if (((exception is SecurityException) || (exception is UnauthorizedAccessException)) || ((exception.InnerException != null) && ((exception.InnerException is SecurityException) || (exception.InnerException is UnauthorizedAccessException)))) { exception = new RegistrationException(Resource.FormatString("Reg_Unauthorized"), exception); } if (flag && (null != asm)) { try { this.ClassicUnregistration(asm); } catch (Exception exception2) { if ((exception2 is NullReferenceException) || (exception2 is SEHException)) { throw; } } } if (flag2 && (null != asm)) { try { this.UnregisterTypeLib(asm); } catch (Exception exception3) { if ((exception3 is NullReferenceException) || (exception3 is SEHException)) { throw; } } } throw exception; } }