public static SubsonicSettings ReadSettingsFromFile(string settingsFilename) { var settings = new SubsonicSettings(); try { if (!File.Exists(settingsFilename)) { return(Subsonic.GetCurrentSettings()); } using (var reader = new StreamReader(settingsFilename)) { var protocolText = AesEncryption.Decrypt(reader.ReadLine(), Passphrase); settings.Protocol = protocolText.Equals("HTTP") ? SubsonicSettings.ConnectionProtocol.Http : SubsonicSettings.ConnectionProtocol.Https; settings.Host = AesEncryption.Decrypt(reader.ReadLine(), Passphrase); settings.Port = AesEncryption.Decrypt(reader.ReadLine(), Passphrase); settings.BasePath = AesEncryption.Decrypt(reader.ReadLine(), Passphrase); settings.Username = AesEncryption.Decrypt(reader.ReadLine(), Passphrase); settings.Password = AesEncryption.Decrypt(reader.ReadLine(), Passphrase); settings.Transcode = AesEncryption.Decrypt(reader.ReadLine(), Passphrase) == "Y"; settings.Auth = AesEncryption.Decrypt(reader.ReadLine(), Passphrase) == "HexPass" ? SubsonicSettings.AuthMethod.HexPass : SubsonicSettings.AuthMethod.Token; settings.BitRate = AesEncryption.Decrypt(reader.ReadLine(), Passphrase); if (string.IsNullOrEmpty(settings.BitRate)) { settings.BitRate = "Unlimited"; } settings.UseIndexCache = AesEncryption.Decrypt(reader.ReadLine(), Passphrase) == "Y"; return(settings); } } catch (Exception ex) { const string caption = "Error while trying to load settings"; MessageBox.Show($@"An error occurred while trying to load the settings file! Reverting to defaults... Exception: {ex}", caption, MessageBoxButtons.OK, MessageBoxIcon.Error); return(Subsonic.GetCurrentSettings()); } }
private void UpdateAll() { var currentSettings = Subsonic.GetCurrentSettings(); TextBoxHostname.Text = currentSettings.Host; TextBoxPort.Text = currentSettings.Port; TextBoxPath.Text = currentSettings.BasePath; TextBoxUsername.Text = currentSettings.Username; TextBoxPassword.Text = currentSettings.Password; CheckBoxTranscode.Checked = currentSettings.Transcode; ComboBoxBitrate.SelectedItem = string.IsNullOrEmpty(currentSettings.BitRate) ? "128K" : currentSettings.BitRate; ComboBoxBitrate.Enabled = CheckBoxTranscode.Checked; ComboBoxProtocol.SelectedItem = currentSettings.Protocol.ToFriendlyString(); ComboBoxAuth.SelectedIndex = (int)currentSettings.Auth; }