public bool IsRegistered(RegistrationExtensionEnum regisrationType)
        {
            if (!IsInAprovedList())
            {
                return(false);
            }
            if (!IsComRegistered())
            {
                return(false);
            }
            if ((regisrationType & RegistrationExtensionEnum.Fb2) == RegistrationExtensionEnum.Fb2 && !IsExtensionRegistered(RegistrationExtensionEnum.Fb2))
            {
                return(false);
            }
            if ((regisrationType & RegistrationExtensionEnum.Zip) == RegistrationExtensionEnum.Zip && !IsExtensionRegistered(RegistrationExtensionEnum.Zip))
            {
                return(false);
            }
            if ((regisrationType & RegistrationExtensionEnum.Rar) == RegistrationExtensionEnum.Rar && !IsExtensionRegistered(RegistrationExtensionEnum.Rar))
            {
                return(false);
            }
            if ((regisrationType & RegistrationExtensionEnum.Any) == RegistrationExtensionEnum.Any && !IsExtensionRegistered(RegistrationExtensionEnum.Any))
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Checks the current registration
        /// </summary>
        /// <returns></returns>
        public RegistrationExtensionEnum GetRegistrationState()
        {
            RegistrationExtensionEnum state = RegistrationExtensionEnum.None;

            if (!IsRegistered(RegistrationExtensionEnum.None))
            {
                return(RegistrationExtensionEnum.None);
            }
            if (IsRegistered(RegistrationExtensionEnum.Fb2))
            {
                state |= RegistrationExtensionEnum.Fb2;
            }
            if (IsRegistered(RegistrationExtensionEnum.Zip))
            {
                state |= RegistrationExtensionEnum.Zip;
            }
            if (IsRegistered(RegistrationExtensionEnum.Rar))
            {
                state |= RegistrationExtensionEnum.Rar;
            }
            if (IsRegistered(RegistrationExtensionEnum.Any))
            {
                state |= RegistrationExtensionEnum.Any;
            }

            return(state);
        }
        public string GetRegistredLocation()
        {
            RegistrationExtensionEnum state = GetRegistrationState();

            if (state != RegistrationExtensionEnum.None)
            {
                using (RegistryKey lmKey = Registry.LocalMachine.OpenSubKey(string.Format("Software\\Classes\\CLSID\\{0}\\InprocServer32", ExtensionGuid), false))
                {
                    if (lmKey != null)
                    {
                        return((string)lmKey.GetValue(null));
                    }
                }
            }

            return(string.Empty);
        }
        /// <summary>
        /// Converts extension type enum to corresponding string
        /// </summary>
        /// <param name="registrationExtensionEnum"></param>
        /// <returns></returns>
        private static string ConvertEnumToString(RegistrationExtensionEnum registrationExtensionEnum)
        {
            string res = string.Empty;

            switch (registrationExtensionEnum)
            {
            case RegistrationExtensionEnum.Fb2:
                return(".fb2");

            case RegistrationExtensionEnum.Zip:
                return(".zip");

            case RegistrationExtensionEnum.Rar:
                return(".rar");

            case RegistrationExtensionEnum.Any:
                return("*");
            }
            return(res);
        }
        /// <summary>
        /// Register shell extension and specific file extension
        /// </summary>
        /// <param name="regType">file extension type to register</param>
        public void Register(RegistrationExtensionEnum regType)
        {
            try
            {
                using (RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", true))
                {
                    if (key != null)
                    {
                        key.SetValue(ExtensionGuid, string.Format("{0} extension", ExtensionName));
                    }
                }

                RegisterComServer();

                //RegisterFbeExtension();

                if ((regType & RegistrationExtensionEnum.Any) == RegistrationExtensionEnum.Any)
                {
                    RegisterFileExtension("*", "");
                }
                else
                {
                    UnregisterFileExtension("*", false);
                }

                if ((regType & RegistrationExtensionEnum.Fb2) == RegistrationExtensionEnum.Fb2)
                {
                    RegisterFileExtension(".fb2", "FictionBook.2");
                }
                else
                {
                    UnregisterFileExtension(".fb2", true);
                }

                if ((regType & RegistrationExtensionEnum.Zip) == RegistrationExtensionEnum.Zip)
                {
                    RegisterFileExtension(".zip", "CompressedFolder");
                }
                else
                {
                    UnregisterFileExtension(".zip", true);
                }

                if ((regType & RegistrationExtensionEnum.Rar) == RegistrationExtensionEnum.Rar)
                {
                    RegisterFileExtension(".rar", "WinRAR");
                }
                else
                {
                    UnregisterFileExtension(".rar", true);
                }
            }
            catch (DllNotFoundException)
            {
                Log.ErrorFormat(string.Format("Error registering shell extension due to missing 'Fb2EpubExt.DLL' - please ensure it located in program folder "));
                RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", true);
                if (key != null)
                {
                    try
                    {
                        key.DeleteSubKey(ExtensionGuid);
                    }
                    catch (ArgumentException)
                    { }
                }
            }
            catch (Exception ex)
            {
                Log.ErrorFormat(string.Format("Error registering shell extension: {0}", ex));
                RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", true);
                if (key != null)
                {
                    try
                    {
                        key.DeleteSubKey(ExtensionGuid);
                    }
                    catch (ArgumentException)
                    { }
                }
            }
        }
        //private void UnregisterFbeExtension()
        //{
        //    try
        //    {
        //        using (RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
        //        {
        //            key.DeleteSubKeyTree(string.Format(@"Software\Haali\FBE\Plugins\{0}", FbeExportPluginGuid),false);
        //        }
        //    }
        //    catch (Exception ex)
        //    {

        //        Log.Error(ex);
        //    }
        //}

        public void Unregister(RegistrationExtensionEnum regType)
        {
            try
            {
                if ((regType & RegistrationExtensionEnum.Any) == RegistrationExtensionEnum.Any)
                {
                    UnregisterFileExtension("*", false);
                }
            }
            catch (Exception ex)
            {
                Log.ErrorFormat(string.Format("Error unregistering * shell extension: {0}", ex));
            }

            try
            {
                if ((regType & RegistrationExtensionEnum.Fb2) == RegistrationExtensionEnum.Fb2)
                {
                    UnregisterFileExtension(".fb2", true);
                }
            }
            catch (Exception ex)
            {
                Log.ErrorFormat(string.Format("Error unregistering .fb2 shell extension: {0}", ex));
            }

            try
            {
                if ((regType & RegistrationExtensionEnum.Zip) == RegistrationExtensionEnum.Zip)
                {
                    UnregisterFileExtension(".zip", true);
                }
            }
            catch (Exception ex)
            {
                Log.ErrorFormat(string.Format("Error unregistering .zip shell extension: {0}", ex));
            }

            try
            {
                if ((regType & RegistrationExtensionEnum.Rar) == RegistrationExtensionEnum.Rar)
                {
                    UnregisterFileExtension(".rar", true);
                }
            }
            catch (Exception ex)
            {
                Log.ErrorFormat(string.Format("Error unregistering .rar shell extension: {0}", ex));
            }


            if (regType != RegistrationExtensionEnum.All) // if we not unregistering all nothing more to do
            {
                return;
            }

            try
            {
                using (RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", true))
                {
                    if (key != null)
                    {
                        try
                        {
                            key.DeleteSubKey(ExtensionGuid);
                        }
                        catch (ArgumentException)
                        {}
                        catch (Exception ex)
                        {
                            throw new Exception(string.Format("error deleting extension GUID key", ex));
                        }
                    }
                }
            }
            catch (DllNotFoundException)
            {
                Log.ErrorFormat(string.Format("Error unregistering shell extension due to missing 'Fb2EpubExt.DLL' - please ensure it located in program folder "));
            }
            catch (Exception ex)
            {
                Log.ErrorFormat(string.Format("Error unregistering shell extension: {0}", ex));
            }


            try
            {
                UnRegisterComServer();
            }
            catch (Exception ex)
            {
                Log.ErrorFormat(string.Format("Error unregistering COM server : {0}", ex));
            }
        }
 /// <summary>
 /// Check if speciffic extensoin registered
 /// </summary>
 /// <param name="registrationExtensionEnum"></param>
 /// <returns></returns>
 private static bool IsExtensionRegistered(RegistrationExtensionEnum registrationExtensionEnum)
 {
     return(IsExtensionRegistered(ConvertEnumToString(registrationExtensionEnum), registrationExtensionEnum != RegistrationExtensionEnum.Any));
 }
Beispiel #8
0
 /// <summary>
 /// Check if speciffic extensoin registered
 /// </summary>
 /// <param name="registrationExtensionEnum"></param>
 /// <returns></returns>
 private static bool IsExtensionRegistered(RegistrationExtensionEnum registrationExtensionEnum)
 {
     return IsExtensionRegistered(ConvertEnumToString(registrationExtensionEnum),registrationExtensionEnum != RegistrationExtensionEnum.Any);
 }
Beispiel #9
0
 /// <summary>
 /// Converts extension type enum to corresponding string
 /// </summary>
 /// <param name="registrationExtensionEnum"></param>
 /// <returns></returns>
 private static string ConvertEnumToString(RegistrationExtensionEnum registrationExtensionEnum)
 {
     string res = string.Empty;
     switch (registrationExtensionEnum)
     {
         case RegistrationExtensionEnum.Fb2:
             return ".fb2";
         case RegistrationExtensionEnum.Zip:
             return ".zip";
         case RegistrationExtensionEnum.Rar:
             return ".rar";
         case RegistrationExtensionEnum.Any:
             return "*";
     }
     return res;
 }
Beispiel #10
0
        //private void UnregisterFbeExtension()
        //{
        //    try
        //    {
        //        using (RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
        //        {
        //            key.DeleteSubKeyTree(string.Format(@"Software\Haali\FBE\Plugins\{0}", FbeExportPluginGuid),false);
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        Log.Error(ex);
        //    }
        //}
        public void Unregister(RegistrationExtensionEnum regType)
        {
            try
            {
                if ((regType & RegistrationExtensionEnum.Any) == RegistrationExtensionEnum.Any)
                {
                    UnregisterFileExtension("*",false);
                }
            }
            catch (Exception ex)
            {
                Log.ErrorFormat(string.Format("Error unregistering * shell extension: {0}", ex));
            }

            try
            {
                if ((regType & RegistrationExtensionEnum.Fb2) == RegistrationExtensionEnum.Fb2 )
                {
                    UnregisterFileExtension(".fb2",true);
                }
            }
            catch (Exception ex)
            {
                Log.ErrorFormat(string.Format("Error unregistering .fb2 shell extension: {0}", ex));
            }

            try
            {
                if ((regType & RegistrationExtensionEnum.Zip) == RegistrationExtensionEnum.Zip)
                {
                    UnregisterFileExtension(".zip", true);
                }
            }
            catch (Exception ex)
            {
                Log.ErrorFormat(string.Format("Error unregistering .zip shell extension: {0}", ex));
            }

            try
            {
                if ((regType & RegistrationExtensionEnum.Rar) == RegistrationExtensionEnum.Rar)
                {
                    UnregisterFileExtension(".rar", true);
                }
            }
            catch (Exception ex)
            {
                Log.ErrorFormat(string.Format("Error unregistering .rar shell extension: {0}", ex));
            }

            if (regType != RegistrationExtensionEnum.All) // if we not unregistering all nothing more to do
            {
                return;
            }

            try
            {
                using (RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", true))
                {
                    if (key != null)
                    {
                        try
                        {
                            key.DeleteSubKey(ExtensionGuid);
                        }
                        catch (ArgumentException)
                        {}
                        catch (Exception ex)
                        {
                            throw new Exception(string.Format("error deleting extension GUID key",ex));
                        }
                    }
                }
            }
            catch (DllNotFoundException)
            {
                Log.ErrorFormat(string.Format("Error unregistering shell extension due to missing 'Fb2EpubExt.DLL' - please ensure it located in program folder "));
            }
            catch (Exception ex)
            {
                Log.ErrorFormat(string.Format("Error unregistering shell extension: {0}", ex));
            }

            try
            {
                UnRegisterComServer();
            }
            catch (Exception ex)
            {
                Log.ErrorFormat(string.Format("Error unregistering COM server : {0}", ex));
            }
        }
Beispiel #11
0
        /// <summary>
        /// Register shell extension and specific file extension
        /// </summary>
        /// <param name="regType">file extension type to register</param>
        public void Register(RegistrationExtensionEnum regType)
        {
            try
            {
                using (RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", true))
                {
                    if (key != null)
                    {
                        key.SetValue(ExtensionGuid, string.Format("{0} extension", ExtensionName));
                    }
                }

                RegisterComServer();

                //RegisterFbeExtension();

                if ((regType & RegistrationExtensionEnum.Any) == RegistrationExtensionEnum.Any)
                {
                    RegisterFileExtension("*", "");
                }
                else
                {
                    UnregisterFileExtension("*", false);
                }

                if ((regType & RegistrationExtensionEnum.Fb2) == RegistrationExtensionEnum.Fb2)
                {
                    RegisterFileExtension(".fb2", "FictionBook.2");
                }
                else
                {
                    UnregisterFileExtension(".fb2", true);
                }

                if ((regType & RegistrationExtensionEnum.Zip) == RegistrationExtensionEnum.Zip)
                {
                    RegisterFileExtension(".zip", "CompressedFolder");
                }
                else
                {
                    UnregisterFileExtension(".zip", true);
                }

                if ((regType & RegistrationExtensionEnum.Rar) == RegistrationExtensionEnum.Rar)
                {
                    RegisterFileExtension(".rar", "WinRAR");
                }
                else
                {
                    UnregisterFileExtension(".rar", true);
                }

            }
            catch (DllNotFoundException)
            {
                Log.ErrorFormat(string.Format("Error registering shell extension due to missing 'Fb2EpubExt.DLL' - please ensure it located in program folder "));
                RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", true);
                if (key != null)
                {
                    try
                    {
                        key.DeleteSubKey(ExtensionGuid);
                    }
                    catch (ArgumentException)
                    { }
                }
            }
            catch (Exception ex)
            {
                Log.ErrorFormat(string.Format("Error registering shell extension: {0}", ex));
                RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", true);
                if (key != null)
                {
                    try
                    {
                        key.DeleteSubKey(ExtensionGuid);
                    }
                    catch (ArgumentException)
                    { }
                }
            }
        }
Beispiel #12
0
        public bool IsRegistered(RegistrationExtensionEnum regisrationType)
        {
            if (!IsInAprovedList())
            {
                return false;
            }
            if (!IsComRegistered())
            {
                return false;
            }
            if ((regisrationType & RegistrationExtensionEnum.Fb2) == RegistrationExtensionEnum.Fb2 && !IsExtensionRegistered(RegistrationExtensionEnum.Fb2))
            {
                return false;
            }
            if ((regisrationType & RegistrationExtensionEnum.Zip) == RegistrationExtensionEnum.Zip && !IsExtensionRegistered(RegistrationExtensionEnum.Zip))
            {
                return false;
            }
            if ((regisrationType & RegistrationExtensionEnum.Rar) == RegistrationExtensionEnum.Rar && !IsExtensionRegistered(RegistrationExtensionEnum.Rar))
            {
                return false;
            }
            if ((regisrationType & RegistrationExtensionEnum.Any) == RegistrationExtensionEnum.Any && !IsExtensionRegistered(RegistrationExtensionEnum.Any))
            {
                return false;
            }

            return true;
        }