public static void ShowUnRegister(Type type, RegisterCall registerCall, InstallScope scope, OfficeUnRegisterKeyState keyState, string from) { string text = String.Format( "Register Type:{1}{0}Assembly Name:{2}{0}Assembly Version:{3}{0}RegisterCall:{4}{0}Scope:{5}{0}KeyState:{6}{0}", Environment.NewLine, type, type.Assembly.GetName().Name, type.Assembly.GetName().Version, registerCall, scope, keyState); if (_enabled) MessageBox.Show(text, "Unregister " + from); else Console.WriteLine("Unregister " + from + " :" + text); }
private static void OptimizedUnregisterFunction(Type type, int scope, int keyState) { if (null == type) { throw new ArgumentNullException("type"); } InstallScope currentScope = (InstallScope)scope; OfficeUnRegisterKeyState currentKeyState = (OfficeUnRegisterKeyState)keyState; UnRegisterHandler.Proceed(type, new string[] { _addinOfficeRegistryKey }, currentScope, currentKeyState); }
private static void OptimizedUnregisterFunction(Type type, int scope, int keyState) { if (null == type) { throw new ArgumentNullException("type"); } if (null != type.GetCustomAttribute <DontRegisterAddinAttribute>()) { return; } OfficeUnRegisterKeyState currentKeyState = (OfficeUnRegisterKeyState)keyState; COMAddinUnRegisterHandler.ProceedUser(type, new string[] { _addinOfficeRegistryKey, _addinOfficeRegistryKey64 }, currentKeyState); }
private static void OptimizedUnregisterFunction(Type type, int scope, int keyState) { if (null == type) { throw new ArgumentNullException("type"); } InstallScope currentScope = (InstallScope)scope; OfficeUnRegisterKeyState currentKeyState = (OfficeUnRegisterKeyState)keyState; MultiRegisterAttribute attribute = MultiRegisterAttribute.GetAttribute(type); string[] product = new string[attribute.Products.Length]; for (int i = 0; i < attribute.Products.Length; i++) { product[i] = String.Format(_addinOfficeRegistryKey, MultiRegisterAttribute.RegistryEntry(attribute.Products[i])); } COMAddinUnRegisterHandler.Proceed(type, product, currentScope, currentKeyState); }
/// <summary> /// Do unregister process /// </summary> /// <param name="type">addin type</param> /// <param name="addinOfficeRegistryKey">office application registry path</param> /// <param name="scope">the current installation scope</param> /// <param name="keyState">the office registry key need to delete</param> public static void Proceed(Type type, string[] addinOfficeRegistryKey, InstallScope scope, OfficeUnRegisterKeyState keyState) { try { MethodInfo registerMethod = null; UnRegisterFunctionAttribute registerAttribute = null; bool registerMethodPresent = AttributeReflector.GetUnRegisterAttribute(type, ref registerMethod, ref registerAttribute); if ((null != registerAttribute && true == registerMethodPresent) && (registerAttribute.Value == RegisterMode.CallBefore || registerAttribute.Value == RegisterMode.CallBeforeAndAfter || registerAttribute.Value == RegisterMode.Replace)) { if (!CallDerivedUnRegisterMethod(registerMethod, type, registerAttribute.Value == RegisterMode.Replace ? RegisterCall.Replace : RegisterCall.CallBefore, scope, keyState)) { if (!RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.UnRegister, new UnregisterException())) { return; } } if (registerAttribute.Value == RegisterMode.Replace) { return; } } ProgIdAttribute progId = AttributeReflector.GetProgIDAttribute(type); RegistryLocationAttribute location = AttributeReflector.GetRegistryLocationAttribute(type); CodebaseAttribute codebase = AttributeReflector.GetCodebaseAttribute(type); ProgrammableAttribute programmable = AttributeReflector.GetProgrammableAttribute(type); bool isSystemComponent = location.IsMachineComponentTarget(scope); bool isSystemAddin = location.IsMachineAddinTarget(scope); if (null != programmable) { ProgrammableAttribute.DeleteKeys(type.GUID, isSystemComponent, false); } if (null != codebase && codebase.Value == true) { Assembly thisAssembly = Assembly.GetAssembly(type); string assemblyVersion = thisAssembly.GetName().Version.ToString(); CodebaseAttribute.DeleteValue(type.GUID, isSystemComponent, assemblyVersion, false); } if (keyState == OfficeUnRegisterKeyState.NeedToDelete) { foreach (string item in addinOfficeRegistryKey) { RegistryLocationAttribute.TryDeleteApplicationKey(isSystemAddin, item, progId.Value); } } if ((null != registerAttribute && true == registerMethodPresent) && (registerAttribute.Value == RegisterMode.CallAfter || registerAttribute.Value == RegisterMode.CallBeforeAndAfter)) { if (!CallDerivedUnRegisterMethod(registerMethod, type, RegisterCall.CallAfter, scope, keyState)) { RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.UnRegister, new UnregisterException()); } } } catch (System.Exception exception) { NetOffice.DebugConsole.Default.WriteException(exception); if (!RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.UnRegister, exception)) { throw; } } }
/// <summary> /// Do unregister process per user uninstallation /// </summary> /// <param name="type">addin type</param> /// <param name="addinOfficeRegistryKey">office application registry path</param> /// <param name="keyState">the office registry key need to delete</param> public static void ProceedUser(Type type, string[] addinOfficeRegistryKey, OfficeUnRegisterKeyState keyState) { Proceed(type, addinOfficeRegistryKey, InstallScope.User, keyState); }
/// <summary> /// Derived UnRegister Call Helper /// </summary> /// <param name="registerMethod">the method to call</param> /// <param name="type">type for derived class</param> /// <param name="callType">kind of call, defined in Register attribute</param> /// <param name="scope">current register scope</param> /// <param name="keyState">office reg key state</param> /// <returns>true if no exception occurs, otherwise false</returns> private static bool CallDerivedUnRegisterMethod(MethodInfo registerMethod, Type type, RegisterCall callType, InstallScope scope, OfficeUnRegisterKeyState keyState) { try { ParameterInfo[] arguments = registerMethod.GetParameters(); int argumentsCount = arguments.Length; switch (argumentsCount) { case 0: registerMethod.Invoke(null, new object[0]); break; case 1: if (arguments[0].ParameterType.GUID == typeof(InstallScope).GUID) { registerMethod.Invoke(null, new object[] { scope }); } else if (arguments[0].ParameterType.GUID == typeof(RegisterCall).GUID) { registerMethod.Invoke(null, new object[] { callType }); } else { registerMethod.Invoke(null, new object[] { type }); } break; case 2: registerMethod.Invoke(null, new object[] { type, callType }); break; case 3: registerMethod.Invoke(null, new object[] { type, callType, scope }); break; case 4: registerMethod.Invoke(null, new object[] { type, callType, scope, keyState }); break; default: break; } return(true); } catch (Exception) { return(false); } }
[UnRegisterFunction(RegisterMode.CallBeforeAndAfter)] // We want that NetOffice call this method before and after unregister private static void UnRegister(Type type, RegisterCall registerCall, InstallScope scope, OfficeUnRegisterKeyState keyState) { }
private static void UnRegister(Type type, RegisterCall registerCall, InstallScope scope, OfficeUnRegisterKeyState keyState) { MessageDialog.ShowUnRegister(type, registerCall, scope, keyState, "Excel"); }
public static void ShowUnRegister(Type type, RegisterCall registerCall, InstallScope scope, OfficeUnRegisterKeyState keyState, string from) { string text = String.Format( "Register Type:{1}{0}Assembly Name:{2}{0}Assembly Version:{3}{0}RegisterCall:{4}{0}Scope:{5}{0}KeyState:{6}{0}", Environment.NewLine, type, type.Assembly.GetName().Name, type.Assembly.GetName().Version, registerCall, scope, keyState); if (_enabled) { MessageBox.Show(text, "Unregister " + from); } else { Console.WriteLine("Unregister " + from + " :" + text); } }
private static void UnRegister(Type type, RegisterCall registerCall, InstallScope scope, OfficeUnRegisterKeyState keyState) { MessageDialog.ShowUnRegister(type, registerCall, scope, keyState, "Excel"); }