Example #1
0
        public void SetCurrentState(StateType currentState, StateType newState)
        {
            var currentValue = currentState.ToRegistryValue() ?? throw new ArgumentException($"Modo de áudio do windows é inválido: '{currentState}'.", nameof(currentState));
            var newValue     = newState.ToRegistryValue() ?? throw new ArgumentException($"Não é possível definir o modo de áudio do windows para '{newState}'.", nameof(newState));

            if (!this.SetAudioRegistry(newValue))
            {
                throw new Exception("Não foi possível definir o modo de aúdio do windows.");
            }

            if (!this.RestartAudioService())
            {
                if (this.SetAudioRegistry(currentValue))
                {
                    throw new Exception("Não foi possível definir o modo de aúdio do windows.");
                }
                else
                {
                    throw new Exception("Não foi possível reiniciar o serviço de audio do windows. Reinicie manualmente para aplicar as mudanças.");
                }
            }
        }