Пример #1
0
        /// <summary>
        /// Copy default sound from the specified sound scheme to the SoundManager sound scheme
        /// </summary>
        /// <param name="source">If not specified, sounds are copied from the default sound sheme</param>
        public static void CopyDefault(SoundEvent soundEvent, SoundScheme source = null)
        {
            bool defaultFileFound = false;

            string originalScheme = SchemeDefault;

            if (source != null)
            {
                originalScheme = source.internalName;
            }

            foreach (string registryKey in soundEvent.RegistryKeys)
            {
                RegistryKey defaultSoundKey  = RegCurrentUser.OpenSubKey(RegApps + registryKey + '\\' + originalScheme);
                string      defaultSoundPath = null;
                if (defaultSoundKey != null)
                {
                    defaultSoundPath = Environment.ExpandEnvironmentVariables(defaultSoundKey.GetValue(null) as string ?? "");
                }
                if (!Directory.Exists(Path.GetDirectoryName(soundEvent.FilePath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(soundEvent.FilePath));
                }
                if (File.Exists(defaultSoundPath))
                {
                    Update(soundEvent, defaultSoundPath);
                    defaultFileFound = true;
                }
            }
            if (soundEvent.Imageres && ImageresPatcher.IsWindowsVista7)
            {
                if (FileSystemAdmin.IsAdmin())
                {
                    ImageresPatcher.Restore();
                }
                ImageresPatcher.ExtractDefault(soundEvent.FilePath);
            }
            else if (!defaultFileFound)
            {
                Remove(soundEvent);
            }
        }
Пример #2
0
        /// <summary>
        /// Remove the "SoundManager" sound scheme from registry
        /// </summary>
        public static void Uninstall()
        {
            string currentScheme = RegCurrentUser.OpenSubKey(RegSchemes).GetValue(null) as string;

            if (currentScheme == SchemeManager)
            {
                Apply(GetSchemeDefault(), true);
            }

            RegistryKey apps = RegCurrentUser.OpenSubKey(RegApps);

            foreach (string appName in apps.GetSubKeyNames())
            {
                RegistryKey app = apps.OpenSubKey(appName);
                foreach (string soundName in app.GetSubKeyNames())
                {
                    RegistryKey sound = app.OpenSubKey(soundName, true);
                    if (sound.OpenSubKey(SchemeManager) != null)
                    {
                        sound.DeleteSubKey(SchemeManager);
                    }
                    sound.Close();
                }
            }

            if (RegCurrentUser.OpenSubKey(RegNames + SchemeManager) != null)
            {
                RegCurrentUser.DeleteSubKey(RegNames + SchemeManager);
            }

            //Windows 7 : Also restore imageres.dll when removing sound scheme
            try
            {
                if (ImageresPatcher.IsWindowsVista7 && FileSystemAdmin.IsAdmin())
                {
                    ImageresPatcher.Restore();
                }
            }
            catch (FileNotFoundException) { /* No imageres backup to restore */ }
            catch (UnauthorizedAccessException) { /* Insufficient privileges or file locked */ }
        }