Exemple #1
0
        public void Unregister()
        {
            var capabilitiesPath = RegistryHelper.GetValueLocal(@"Software\RegisteredApplications", _associator.AppName, null);

            if (capabilitiesPath != null)
            {
                var fileAssocPath = String.Format(@"{0}\FileAssociations", capabilitiesPath);

                string[]    extensions;
                RegistryKey key = null;
                try
                {
                    key = Registry.LocalMachine.OpenSubKey(fileAssocPath);
                    if (key != null)
                    {
                        extensions = key.GetValueNames();
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                catch
                {
                    return; // what else?
                }
                finally
                {
                    if (key != null)
                    {
                        key.Close();
                    }
                }

                foreach (string ext in extensions)
                {
                    if (ext != String.Empty) // check for an accident default value (which should never be the case but still)
                    {
                        if (_associator.CanAssociate)
                        {
                            _associator.UnAssociate(ext);
                        }

                        var docType = RegistryHelper.GetValueLocal(fileAssocPath, ext, null);
                        if (docType != null)
                        {
                            DeleteDocID(docType);
                        }
                    }
                }

                DeleteAppRegistration(capabilitiesPath);
            }
        }