示例#1
0
        public AppItemViewModel(IAudioMixerViewModelCallback callback, EarTrumpetAudioSessionModelGroup sessions)
        {
            _sessions = sessions;
            // select a session at random as sndvol does.
            var session = _sessions.Sessions.First();

            IconHeight = IconWidth = 32;
            SessionId  = session.SessionId;
            ProcessId  = session.ProcessId;
            ExeName    = GetExeName(session.DisplayName);
            IsDesktop  = session.IsDesktop;

            _volume = Convert.ToInt32(Math.Round((session.Volume * 100),
                                                 MidpointRounding.AwayFromZero));
            _isMuted  = session.IsMuted;
            _callback = callback;

            if (session.IsDesktop)
            {
                try
                {
                    if (Path.GetExtension(session.IconPath) == ".dll")
                    {
                        Icon = IconExtensions.ExtractIconFromDll(session.IconPath);
                    }
                    else
                    {
                        // override for SpeechRuntime.exe (Repo -> HEY CORTANA)
                        if (session.IconPath.ToLowerInvariant().Contains("speechruntime.exe"))
                        {
                            var sysType = Environment.Is64BitOperatingSystem ? "SysNative" : "System32";
                            Icon = IconExtensions.ExtractIconFromDll(Path.Combine("%windir%", sysType, "Speech\\SpeechUX\\SpeechUXWiz.exe"), 0);
                        }
                        else
                        {
                            Icon = System.Drawing.Icon.ExtractAssociatedIcon(session.IconPath).ToImageSource();
                        }
                    }
                }
                catch
                {
                    // ignored
                }
                Background = new SolidColorBrush(Colors.Transparent);
            }
            else
            {
                if (File.Exists(session.IconPath)) //hack until we invoke the resource manager correctly.
                {
                    Icon = new BitmapImage(new Uri(session.IconPath));
                }
                Background = new SolidColorBrush(AccentColorService.FromABGR(session.BackgroundColor));
            }
        }
示例#2
0
        public AppItemViewModel(IAudioMixerViewModelCallback callback, EarTrumpetAudioSessionModelGroup sessions,
                                ProcessTitleProvider titleProvider)
        {
            _sessions = sessions;
            // select a session at random as sndvol does.
            var session = _sessions.Sessions.First();

            IconHeight  = IconWidth = 32;
            SessionId   = session.SessionId;
            DisplayName = session.DisplayName.Equals("System Sounds") ? EarTrumpet.Properties.Resources.SystemSoundsDisplayName : session.DisplayName;
            IsDesktop   = session.IsDesktop;

            _volume = Convert.ToInt32(Math.Round((session.Volume * 100),
                                                 MidpointRounding.AwayFromZero));
            _callback = callback;

            if (session.IsDesktop)
            {
                try
                {
                    Icon = Path.GetExtension(session.IconPath) == ".dll" ? IconExtensions.ExtractIconFromDll(session.IconPath) : System.Drawing.Icon.ExtractAssociatedIcon(session.IconPath).ToImageSource();
                }
                catch
                {
                    // ignored
                }

                Background = new SolidColorBrush(Colors.Transparent);

                try
                {
                    string gotTitle;
                    if (titleProvider.TryGetTitleForProcess(session.ProcessId, out gotTitle))
                    {
                        DisplayName = gotTitle;
                    }
                }
                catch { } // we fallback to exe name if DisplayName is not set in the try above.
            }
            else
            {
                if (File.Exists(session.IconPath)) //hack until we invoke the resource manager correctly.
                {
                    Icon = new BitmapImage(new Uri(session.IconPath));
                }
                Background = new SolidColorBrush(AccentColorService.FromABGR(session.BackgroundColor));
            }
        }