public static bool HasIdentity(this Application app) { #if VSDEBUG if (Debugger.IsAttached) { return(false); } #endif if (_hasIdentity == null) { try { _hasIdentity = (Package.Current.Id != null); } catch (InvalidOperationException ex) { #if !DEBUG // We do not expect this to occur in production when the app is packaged. AppTrace.LogWarning(ex); #else Trace.WriteLine(ex); #endif _hasIdentity = false; } } return((bool)_hasIdentity); }
private void MoveAppToDeviceInternal(IAppItemViewModel app, DeviceViewModel dev) { var searchId = dev?.Id; if (dev == null) { searchId = _deviceManager.DefaultPlaybackDevice.Id; } DeviceViewModel oldDevice = AllDevices.First(d => d.Apps.Contains(app)); DeviceViewModel newDevice = AllDevices.First(d => searchId == d.Id); try { bool isLogicallyMovingDevices = (oldDevice != newDevice); var tempApp = new TemporaryAppItemViewModel(app); app.MoveToDevice(dev?.Id, hide: isLogicallyMovingDevices); // Update the UI if the device logically changed places. if (isLogicallyMovingDevices) { oldDevice.AppVirtuallyLeavingFromThisDevice(app); newDevice.AppVirtuallMovingToThisDevice(tempApp); } } catch (Exception ex) { AppTrace.LogWarning(ex); } }
static string ReadSetting(string key) { string ret = null; if (App.Current.HasIdentity()) { try { ret = (string)Windows.Storage.ApplicationData.Current.LocalSettings.Values[key]; } catch (Exception ex) { Trace.TraceError($"{ex}"); AppTrace.LogWarning(ex); return(ret); } } else { using (var regKey = Registry.CurrentUser.CreateSubKey(@"Software\EarTrumpet", true)) { ret = (string)regKey.GetValue(key); } } return(ret); }
private void CreateAndAddSession(IAudioSessionControl session) { try { if (!_parent.TryGetTarget(out IAudioDevice parent)) { throw new Exception("Device session parent is invalid but device is still notifying."); } var newSession = new AudioDeviceSession(parent, session); _dispatcher.BeginInvoke((Action)(() => { if (newSession.State == SessionState.Moved) { _movedSessions.Add(newSession); newSession.PropertyChanged += MovedSession_PropertyChanged; } else { AddSession(newSession); } })); } catch (ZombieProcessException ex) { // No need to log these to the cloud, but the debug output // can still be helpful for troubleshooting. Trace.TraceError($"{ex}"); } catch (Exception ex) { AppTrace.LogWarning(ex); } }
public AudioDeviceSessionCollection(IAudioDevice parent, IMMDevice device) { Trace.WriteLine($"AudioDeviceSessionCollection Create dev={device.GetId()}"); _parent = new WeakReference <IAudioDevice>(parent); _dispatcher = App.Current.Dispatcher; Task.Factory.StartNew(() => { try { _sessionManager = device.Activate <IAudioSessionManager2>(); _sessionManager.RegisterSessionNotification(this); var enumerator = _sessionManager.GetSessionEnumerator(); int count = enumerator.GetCount(); for (int i = 0; i < count; i++) { CreateAndAddSession(enumerator.GetSession(i)); } } catch (Exception ex) { AppTrace.LogWarning(ex); } }); }
private void LoadIconResources() { var originalIcon = new Icon(Application.GetResourceStream(new Uri("pack://application:,,,/EarTrumpet;component/Assets/Tray.ico")).Stream); try { _icons.Add(IconId.OriginalIcon, originalIcon); _icons.Add(IconId.NoDevice, GetIconFromFile(_trayIconPath, (int)IconId.NoDevice)); _icons.Add(IconId.Muted, GetIconFromFile(_trayIconPath, (int)IconId.Muted)); _icons.Add(IconId.SpeakerZeroBars, GetIconFromFile(_trayIconPath, (int)IconId.SpeakerZeroBars)); _icons.Add(IconId.SpeakerOneBar, GetIconFromFile(_trayIconPath, (int)IconId.SpeakerOneBar)); _icons.Add(IconId.SpeakerTwoBars, GetIconFromFile(_trayIconPath, (int)IconId.SpeakerTwoBars)); _icons.Add(IconId.SpeakerThreeBars, GetIconFromFile(_trayIconPath, (int)IconId.SpeakerThreeBars)); } catch (Exception ex) { AppTrace.LogWarning(ex); _icons.Clear(); _icons.Add(IconId.OriginalIcon, originalIcon); _icons.Add(IconId.NoDevice, originalIcon); _icons.Add(IconId.Muted, originalIcon); _icons.Add(IconId.SpeakerZeroBars, originalIcon); _icons.Add(IconId.SpeakerOneBar, originalIcon); _icons.Add(IconId.SpeakerTwoBars, originalIcon); _icons.Add(IconId.SpeakerThreeBars, originalIcon); } }
static void WriteSetting <T>(string key, T value) { try { Windows.Storage.ApplicationData.Current.LocalSettings.Values[key] = value; } catch (Exception ex) { // Windows Bug: Windows Storage APIs are still unreliable AppTrace.LogWarning(ex); } }
internal static IDisposable StartNoThrowAndLogWarning(string fileName) { try { return(Process.Start(fileName)); } catch (Exception ex) { AppTrace.LogWarning(ex); } return(null); }
private static void Set <T>(string key, T value) { try { Windows.Storage.ApplicationData.Current.LocalSettings.Values[key] = value; } catch (Exception ex) { Trace.TraceError($"{ex}"); AppTrace.LogWarning(ex); } }
private static T Get <T>(string key) { try { return((T)Windows.Storage.ApplicationData.Current.LocalSettings.Values[key]); } catch (Exception ex) { Trace.TraceError($"{ex}"); AppTrace.LogWarning(ex); } return(default(T)); }
private static bool HasKey(string key) { try { return(Windows.Storage.ApplicationData.Current.LocalSettings.Values.ContainsKey(key)); } catch (Exception ex) { Trace.TraceError($"{ex}"); AppTrace.LogWarning(ex); } return(false); }
public bool HasKey(string key) { var ret = false; try { ret = Windows.Storage.ApplicationData.Current.LocalSettings.Values.ContainsKey(key); } catch (Exception ex) { AppTrace.LogWarning(ex); } return(ret); }
static T ReadSetting <T>(string key) { T ret = default(T); try { ret = (T)Windows.Storage.ApplicationData.Current.LocalSettings.Values[key]; } catch (Exception ex) { // Windows Bug: Windows Storage APIs are still unreliable AppTrace.LogWarning(ex); } return(ret); }
public static string GetDefaultEndPoint(int processId) { try { EnsurePolicyConfig(); s_sharedPolicyConfig.GetPersistedDefaultAudioEndpoint((uint)processId, EDataFlow.eRender, ERole.eMultimedia | ERole.eConsole, out string deviceId); return(UnpackDeviceId(deviceId)); } catch (Exception ex) { AppTrace.LogWarning(ex); } return(null); }
private void RegisterForRawMouseInput(uint flags) { User32.RAWINPUTDEVICE mouseRawDevice = new User32.RAWINPUTDEVICE(); mouseRawDevice.usUsagePage = (ushort)User32.HidUsagePage.GENERIC; mouseRawDevice.usUsage = (ushort)User32.HidUsage.Mouse; mouseRawDevice.dwFlags = flags; mouseRawDevice.hwndTarget = (flags == User32.RIDEV_REMOVE ? IntPtr.Zero : _hwnd); var devicePtr = Marshal.AllocHGlobal(Marshal.SizeOf(mouseRawDevice)); Marshal.StructureToPtr(mouseRawDevice, devicePtr, false); if (User32.RegisterRawInputDevices(devicePtr, 1, (uint)Marshal.SizeOf(mouseRawDevice)) == false) { AppTrace.LogWarning(new Exception($"Couldn't register for raw input: {flags} {Marshal.GetLastWin32Error()} {_hwnd}")); } Marshal.FreeHGlobal(devicePtr); }
public AudioDeviceManager(AudioDeviceKind kind) { _kind = kind; _dispatcher = Dispatcher.CurrentDispatcher; _devices = new AudioDeviceCollection(); _policyConfigService = new AudioPolicyConfigService(Flow); TraceLine($"Create"); Task.Factory.StartNew(() => { try { _enumerator = (IMMDeviceEnumerator) new MMDeviceEnumerator(); _enumerator.RegisterEndpointNotificationCallback(this); var devices = _enumerator.EnumAudioEndpoints(Flow, DeviceState.ACTIVE); uint deviceCount = devices.GetCount(); for (uint i = 0; i < deviceCount; i++) { ((IMMNotificationClient)this).OnDeviceAdded(devices.Item(i).GetId()); } _dispatcher.Invoke((Action)(() => { QueryDefaultDevice(); Loaded?.Invoke(this, null); })); } catch (Exception ex) { // Even through we're going to be broken, show the tray icon so the user can collect debug data. AppTrace.LogWarning(ex); _dispatcher.Invoke((Action)(() => { Loaded?.Invoke(this, null); })); } }); TraceLine($"Create Exit"); }
public static void Register(SettingsService.HotkeyData hotkey) { Trace.WriteLine($"HotkeyService Register {hotkey}"); if (s_hook != null) { s_hook.Dispose(); } s_hook = new KeyboardHook(); s_hook.KeyPressed += Hotkey_KeyPressed; try { s_hook.RegisterHotKey(hotkey.Key, hotkey.Modifiers); } catch (Exception ex) { AppTrace.LogWarning(ex); } }
static void WriteSetting(string key, string value) { if (App.Current.HasIdentity()) { try { Windows.Storage.ApplicationData.Current.LocalSettings.Values[key] = value; } catch (Exception ex) { // Windows Bug: Windows Storage APIs are still unreliable Trace.TraceError($"{ex}"); AppTrace.LogWarning(ex); } } else { using (var regKey = Registry.CurrentUser.CreateSubKey(@"Software\EarTrumpet", true)) { regKey.SetValue(key, value); } } }
public static void SetDefaultEndPoint(string deviceId, int processId) { Trace.WriteLine($"AudioPolicyConfigService SetDefaultEndPoint {deviceId} {processId}"); try { EnsurePolicyConfig(); IntPtr hstring = IntPtr.Zero; if (!string.IsNullOrWhiteSpace(deviceId)) { var str = GenerateDeviceId(deviceId); Combase.WindowsCreateString(str, (uint)str.Length, out hstring); } s_sharedPolicyConfig.SetPersistedDefaultAudioEndpoint((uint)processId, EDataFlow.eRender, ERole.eMultimedia, hstring); s_sharedPolicyConfig.SetPersistedDefaultAudioEndpoint((uint)processId, EDataFlow.eRender, ERole.eConsole, hstring); } catch (Exception ex) { AppTrace.LogWarning(ex); } }