private static void LoadSettings() { if (File.Exists(SettingsFullPath)) { try { var bytes = Convert.FromBase64String(File.ReadAllText(SettingsFullPath)); using (var s = new MemoryStream(bytes)) { Settings = (AppSettings) new BinaryFormatter().Deserialize(s); if (!Settings.UserHasRated) { Settings.LaunchCount++; } } return; } catch (Exception e) { Logger.Error("Failed to load settings file", e); } } //write default values to file on first launch or if config file doesn't exist or deserialization failed Settings = new AppSettings { CurrentAppTheme = SystemColorHelper.WindowsTheme, FirstLaunchDate = DateTime.Today }; Settings.AppLanguage = TranslationSource.GetSystemLanguage(); SaveSettings().GetAwaiter().GetResult(); }
private static void LoadSettings() { if (File.Exists(SettingsFullPath)) { try { using (var fileStream = new FileStream(SettingsFullPath, FileMode.Open)) { fileStream.Position = 0; Settings = (AppSettings) new BinaryFormatter().Deserialize(fileStream); } return; } catch (Exception e) { Logger.Error("Failed to load settings file", e); } } //write default values to file on first launch or if config file doesn't exist or deserialization failed Settings = new AppSettings { CurrentAppTheme = AppTheme.System, AppLanguage = TranslationSource.GetSystemLanguage() }; SaveSettings().GetAwaiter().GetResult(); }
internal static AudioSessionModel GetAudioSessionModel(this IAudioSessionControl sControl, out bool isSystemSession) { if (sControl == null) { isSystemSession = false; return(null); } var sessionControl = (IAudioSessionControl2)sControl; Process process; try { Marshal.ThrowExceptionForHR(sessionControl.GetProcessId(out var processId)); process = Process.GetProcessById((int)processId); } catch (Exception e) { Logger.Error($"Failed to get session process", e); isSystemSession = false; return(null); } try { ImageSource iconImageSource = null; string sessionName = string.Empty; try { sessionName = process.ProcessName; } catch { } if (sessionControl.IsNotSystemSounds()) { App.Current.Dispatcher.Invoke(() => iconImageSource = ExtractSessionIcon(process, sControl)); isSystemSession = false; } else { isSystemSession = true; //check if the system language was changed to get a new localized name for the system sounds session var systemLanguage = TranslationSource.GetSystemLanguage(); if (SettingsProvider.Settings.SystemSoundsName == null || SettingsProvider.Settings.SystemLanguage != systemLanguage) { //returns resources "DllPath,index" sessionName = sControl.GetSystemSoundsName(); SettingsProvider.Settings.SystemLanguage = systemLanguage; SettingsProvider.Settings.SystemSoundsName = sessionName; SettingsProvider.SaveSettings().GetAwaiter().GetResult(); } else { sessionName = SettingsProvider.Settings.SystemSoundsName; } try { App.Current.Dispatcher.Invoke(() => { Icon icon = Icon.ExtractAssociatedIcon(Environment.ExpandEnvironmentVariables("%SystemRoot%\\System32\\AudioSrv.dll")); iconImageSource = IconHelper.GetImageSourceFromIcon(icon); }); } catch (Exception e) { Logger.Error($"Failed to extract system sounds icon from AudioSrv.dll.", e); } } var sessionVolume = new AudioSessionVolume(sessionControl); var muteState = sessionVolume.GetMute(); var volume = sessionVolume.GetVolume(); sessionControl.GetSessionIdentifier(out var sessionId); AudioSessionStateNotifications sessionStateNotifications = new AudioSessionStateNotifications(sessionControl); try { sessionStateNotifications.RegisterNotifications(); } catch (Exception e) { Logger.Error($"Failed to register audio session notifications, process: [{sessionName}]", e); } AudioSessionModel session = new AudioSessionModel(muteState, Convert.ToInt32(volume * 100), sessionName, sessionId, iconImageSource, sessionVolume, sessionStateNotifications); return(session); } catch (Exception e) { Logger.Error($"Failed to create audio session model, process: [{process.ProcessName}]", e); } isSystemSession = false; return(null); }