public bool Read(Android.Content.Context context) { var prefs = Android.Preferences.PreferenceManager.GetDefaultSharedPreferences(context); bool hasPrefs = prefs.GetInt("version", 0) > 0; MessageFilterLevel = prefs.GetInt("messageFilterLevel", 2); String musicFolder = prefs.GetString("musicFolder", GetDefaultMusicDirectory().Serialize()); MusicFolder = FolderFactory.CreateFromSerialization(musicFolder).Result; String soundFolder = prefs.GetString("soundFolder", GetDefaultSoundDirectory().Serialize()); SoundFolder = FolderFactory.CreateFromSerialization(soundFolder).Result; String projectFolder = prefs.GetString("projectFolder", GetDefaultProjectDirectory().Serialize()); ProjectFolder = FolderFactory.CreateFromSerialization(projectFolder).Result; GlobalVolume = prefs.GetInt("overallVolume", 100); MusicVolume = prefs.GetInt("musicVolume", 100); SoundVolume = prefs.GetInt("soundVolume", 100); UdpPort = prefs.GetInt("udpPort", 8009); TcpPort = prefs.GetInt("tcpPort", 11112); String lastProject = prefs.GetString("lastProject", String.Empty); if (!String.IsNullOrEmpty(lastProject)) { RecentFiles.AddFile(new RecentFiles.ProjectEntry(lastProject, "Project0")); } TagMusicFadeTime = prefs.GetInt("tagMusicFadeTime", 0); TagMusicFadeOnlyOnChange = prefs.GetBoolean("tagMusicFadeOnlyOnChange", false); ButtonMusicFadeMode = prefs.GetInt("buttonMusicFadeMode", 0); ButtonMusicFadeTime = prefs.GetInt("buttonMusicFadeTime", 0); PlayerName = prefs.GetString("playerName", "Android Player"); return(hasPrefs); }
private void InitDefaults() { Version = 1; WindowLayout = null; RecentFiles = new RecentFiles(); #if !ANDROID MusicDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic); SoundDirectory = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic), "Sounds"); #else MusicFolder = GetDefaultMusicDirectory(); SoundFolder = GetDefaultSoundDirectory(); #endif LastDownloadLocation = SoundDirectory; GlobalVolume = MusicVolume = SoundVolume = 100; TcpPort = 11112; WebTcpPort = 11113; UseLegacyNetwork = true; #if !ANDROID UseWebNetwork = true; #else UseWebNetwork = false; #endif UdpPort = 8009; IPAddress = String.Empty; #if !ANDROID CheckForUpdate = true; #else CheckForUpdate = false; #endif SoundFileEditor = String.Empty; ExternalMusicPlayer = String.Empty; MessageFilterLevel = 2; // warning UseStreaming = false; StreamingServerAddress = "localhost"; StreamingServerPort = 8000; StreamingPassword = "******"; StreamingEncoder = 1; StreamingStreamName = "Ares"; StreamingBitrate = 128; StreamingUserName = String.Empty; ShowKeysInButtons = false; GlobalKeyHook = false; OnlineDBUserId = String.Empty; ShowDialogAfterDownload = true; ShowDialogAfterUpload = true; TagMusicFadeTime = 0; TagMusicFadeOnlyOnChange = false; PlayMusicOnAllSpeakers = false; ButtonMusicFadeMode = 0; ButtonMusicFadeTime = 0; LocalPlayerPath = String.Empty; ShowTipOfTheDay = true; LastTipOfTheDay = -1; OutputDeviceIndex = -1; AllowFileMove = true; #if ANDROID ProjectFolder = GetDefaultProjectDirectory(); PlayerName = "Android Player"; #endif }
public void Write(Android.Content.Context context) { var prefs = Android.Preferences.PreferenceManager.GetDefaultSharedPreferences(context); var editor = prefs.Edit(); editor.PutInt("version", Version); editor.PutInt("messageFilterLevel", MessageFilterLevel); editor.PutString("musicFolder", MusicFolder.Serialize()); editor.PutString("soundFolder", SoundFolder.Serialize()); editor.PutString("projectFolder", ProjectFolder.Serialize()); editor.PutInt("overallVolume", GlobalVolume); editor.PutInt("musicVolume", MusicVolume); editor.PutInt("soundVolume", SoundVolume); editor.PutInt("udpPort", UdpPort); editor.PutInt("tcpPort", TcpPort); editor.PutString("lastProject", RecentFiles.GetFiles().Count > 0 ? RecentFiles.GetFiles()[0].FilePath : String.Empty); editor.PutInt("tagMusicFadeTime", TagMusicFadeTime); editor.PutBoolean("tagMusicFadeOnlyOnChange", TagMusicFadeOnlyOnChange); editor.PutInt("buttonMusicFadeMode", ButtonMusicFadeMode); editor.PutInt("buttonMusicFadeTime", ButtonMusicFadeTime); editor.PutString("playerName", PlayerName); editor.Apply(); }
private void ReadSettings(XmlReader reader) { RecentFiles = new RecentFiles(); if (!reader.IsStartElement("Settings")) { throw new XmlException("Expected Settings element"); } Version = reader.GetIntegerAttributeOrDefault("Version", 0); LastDownloadLocation = String.Empty; reader.Read(); while (reader.IsStartElement()) { if (reader.IsStartElement("MusicDirectory")) { MusicDirectory = reader.ReadElementString(); } else if (reader.IsStartElement("SoundsDirectory")) { SoundDirectory = reader.ReadElementString(); } else if (reader.IsStartElement("LastDownloadLocation")) { LastDownloadLocation = reader.ReadElementString(); } else if (reader.IsStartElement("WindowLayout")) { if (!reader.IsEmptyElement) { WindowLayout = reader.ReadInnerXml(); } else { reader.Read(); } } else if (reader.IsStartElement("RecentFiles")) { RecentFiles.ReadFiles(reader); } else if (reader.IsStartElement("Volumes")) { GlobalVolume = reader.GetIntegerAttribute("Overall"); MusicVolume = reader.GetIntegerAttribute("Music"); SoundVolume = reader.GetIntegerAttribute("Sound"); if (GlobalVolume > 100) { GlobalVolume = 100; } if (GlobalVolume < 0) { GlobalVolume = 0; } if (MusicVolume > 100) { MusicVolume = 100; } if (MusicVolume < 0) { MusicVolume = 0; } if (SoundVolume > 100) { SoundVolume = 100; } if (SoundVolume < 0) { SoundVolume = 0; } if (reader.IsEmptyElement) { reader.Read(); } else { reader.Read(); reader.ReadInnerXml(); reader.ReadEndElement(); } } else if (reader.IsStartElement("Network")) { UdpPort = reader.GetIntegerAttribute("UdpPort"); TcpPort = reader.GetIntegerAttribute("TcpPort"); WebTcpPort = reader.GetIntegerAttributeOrDefault("WebTcpPort", TcpPort + 1); IPAddress = reader.GetAttribute("IPAddress"); CheckForUpdate = reader.GetBooleanAttributeOrDefault("CheckForUpdate", true); UseLegacyNetwork = reader.GetBooleanAttributeOrDefault("Enabled", true); UseWebNetwork = reader.GetBooleanAttributeOrDefault("UseWebNetwork", true); if (IPAddress == null) { IPAddress = String.Empty; } if (reader.IsEmptyElement) { reader.Read(); } else { reader.Read(); reader.ReadInnerXml(); reader.ReadEndElement(); } } else if (reader.IsStartElement("Tools")) { reader.Read(); while (reader.IsStartElement()) { if (reader.IsStartElement("SoundFileEditor")) { SoundFileEditor = reader.ReadElementString(); } else if (reader.IsStartElement("ExternalMusicPlayer")) { ExternalMusicPlayer = reader.ReadElementString(); } else { reader.ReadOuterXml(); } } reader.ReadEndElement(); } else if (reader.IsStartElement("Options")) { MessageFilterLevel = reader.GetIntegerAttribute("MessageFilterLevel"); ShowKeysInButtons = reader.GetBooleanAttributeOrDefault("ShowKeys", false); GlobalKeyHook = reader.GetBooleanAttributeOrDefault("GlobalKeyHook", false); OutputDeviceIndex = reader.GetIntegerAttributeOrDefault("OutputDevice", -1); if (reader.IsEmptyElement) { reader.Read(); } else { reader.Read(); reader.ReadInnerXml(); reader.ReadEndElement(); } } else if (reader.IsStartElement("Streaming")) { UseStreaming = reader.GetBooleanAttribute("Active"); StreamingServerAddress = reader.GetAttribute("Address"); StreamingServerPort = reader.GetIntegerAttribute("Port"); StreamingPassword = reader.GetAttribute("Password"); StreamingEncoder = reader.GetIntegerAttribute("Encoding"); StreamingStreamName = reader.GetAttribute("StreamName"); if (String.IsNullOrEmpty(StreamingStreamName)) { StreamingStreamName = "Ares"; } StreamingBitrate = reader.GetIntegerAttributeOrDefault("Bitrate", 128); StreamingUserName = reader.GetAttribute("UserName"); if (StreamingUserName == null) { StreamingUserName = String.Empty; } if (reader.IsEmptyElement) { reader.Read(); } else { reader.Read(); reader.ReadInnerXml(); reader.ReadEndElement(); } } else if (reader.IsStartElement("OnlineDB")) { OnlineDBUserId = reader.GetAttribute("UserId"); ShowDialogAfterUpload = reader.GetBooleanAttributeOrDefault("DialogAfterUpload", true); ShowDialogAfterDownload = reader.GetBooleanAttributeOrDefault("DialogAfterDownload", true); if (reader.IsEmptyElement) { reader.Read(); } else { reader.Read(); reader.ReadInnerXml(); reader.ReadEndElement(); } } else if (reader.IsStartElement("TagMusicFading")) { TagMusicFadeTime = reader.GetIntegerAttributeOrDefault("FadeTime", 0); TagMusicFadeOnlyOnChange = reader.GetBooleanAttributeOrDefault("FadeOnlyOnChange", false); if (reader.IsEmptyElement) { reader.Read(); } else { reader.Read(); reader.ReadInnerXml(); reader.ReadEndElement(); } } else if (reader.IsStartElement("Music")) { PlayMusicOnAllSpeakers = reader.GetBooleanAttributeOrDefault("PlayOnAllSpeakers", false); ButtonMusicFadeMode = reader.GetIntegerAttributeOrDefault("ButtonFadeMode", 0); ButtonMusicFadeTime = reader.GetIntegerAttributeOrDefault("ButtonFadeTime", 0); if (reader.IsEmptyElement) { reader.Read(); } else { reader.Read(); reader.ReadInnerXml(); reader.ReadEndElement(); } } else if (reader.IsStartElement("Controllers")) { LocalPlayerPath = reader.GetAttribute("LocalPlayerPath"); if (LocalPlayerPath == null) { LocalPlayerPath = String.Empty; } if (reader.IsEmptyElement) { reader.Read(); } else { reader.Read(); reader.ReadInnerXml(); reader.ReadEndElement(); } } else if (reader.IsStartElement("TipOfTheDay")) { ShowTipOfTheDay = reader.GetBooleanAttributeOrDefault("ShowTip", true); LastTipOfTheDay = reader.GetIntegerAttributeOrDefault("LastTip", 0); if (reader.IsEmptyElement) { reader.Read(); } else { reader.Read(); reader.ReadInnerXml(); reader.ReadEndElement(); } } else if (reader.IsStartElement("Tpm2NetTarget")) { Tpm2NetTargetHost = reader.GetAttribute("Host"); Tpm2NetTargetPort = reader.GetIntegerAttributeOrDefault("Port", 65506); if (reader.IsEmptyElement) { reader.Read(); } else { reader.Read(); reader.ReadInnerXml(); reader.ReadEndElement(); } } else { reader.ReadOuterXml(); } } reader.ReadEndElement(); if (LastDownloadLocation == String.Empty) { LastDownloadLocation = SoundDirectory; } }
private void WriteSettings(XmlWriter writer) { writer.WriteStartElement("Settings"); writer.WriteAttributeString("Version", 1.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteElementString("MusicDirectory", MusicDirectory); writer.WriteElementString("SoundsDirectory", SoundDirectory); writer.WriteElementString("LastDownloadLocation", LastDownloadLocation); writer.WriteStartElement("WindowLayout"); writer.WriteRaw(WindowLayout); writer.WriteEndElement(); writer.WriteStartElement("Volumes"); writer.WriteAttributeString("Overall", GlobalVolume.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteAttributeString("Music", MusicVolume.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteAttributeString("Sound", SoundVolume.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteEndElement(); writer.WriteStartElement("Network"); writer.WriteAttributeString("TcpPort", TcpPort.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteAttributeString("UdpPort", UdpPort.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteAttributeString("IPAddress", IPAddress); writer.WriteAttributeString("CheckForUpdate", CheckForUpdate ? "true" : "false"); writer.WriteAttributeString("Enabled", UseLegacyNetwork ? "true" : "false"); writer.WriteAttributeString("WebTcpPort", WebTcpPort.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteAttributeString("UseWebNetwork", UseWebNetwork ? "true" : "false"); writer.WriteEndElement(); RecentFiles.WriteFiles(writer); writer.WriteStartElement("Tools"); writer.WriteElementString("SoundFileEditor", SoundFileEditor); writer.WriteElementString("ExternalMusicPlayer", ExternalMusicPlayer); writer.WriteEndElement(); writer.WriteStartElement("Options"); writer.WriteAttributeString("MessageFilterLevel", MessageFilterLevel.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteAttributeString("ShowKeys", ShowKeysInButtons ? "true" : "false"); writer.WriteAttributeString("GlobalKeyHook", GlobalKeyHook ? "true" : "false"); writer.WriteAttributeString("OutputDevice", OutputDeviceIndex.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteEndElement(); writer.WriteStartElement("Streaming"); writer.WriteAttributeString("Active", UseStreaming ? "true" : "false"); writer.WriteAttributeString("Address", StreamingServerAddress); writer.WriteAttributeString("Port", StreamingServerPort.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteAttributeString("Password", StreamingPassword); writer.WriteAttributeString("Encoding", StreamingEncoder.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteAttributeString("StreamName", StreamingStreamName); writer.WriteAttributeString("Bitrate", StreamingBitrate.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteAttributeString("UserName", StreamingUserName); writer.WriteEndElement(); writer.WriteStartElement("OnlineDB"); writer.WriteAttributeString("UserId", OnlineDBUserId); writer.WriteAttributeString("DialogAfterDownload", ShowDialogAfterDownload ? "true" : "false"); writer.WriteAttributeString("DialogAfterUpload", ShowDialogAfterUpload ? "true" : "false"); writer.WriteEndElement(); writer.WriteStartElement("TagMusicFading"); writer.WriteAttributeString("FadeTime", TagMusicFadeTime.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteAttributeString("FadeOnlyOnChange", TagMusicFadeOnlyOnChange ? "true" : "false"); writer.WriteEndElement(); writer.WriteStartElement("Music"); writer.WriteAttributeString("PlayOnAllSpeakers", PlayMusicOnAllSpeakers ? "true" : "false"); writer.WriteAttributeString("ButtonFadeMode", ButtonMusicFadeMode.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteAttributeString("ButtonFadeTime", ButtonMusicFadeTime.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteEndElement(); writer.WriteStartElement("Controllers"); writer.WriteAttributeString("LocalPlayerPath", LocalPlayerPath); writer.WriteEndElement(); writer.WriteStartElement("TipOfTheDay"); writer.WriteAttributeString("ShowTip", ShowTipOfTheDay ? "true" : "false"); writer.WriteAttributeString("LastTip", LastTipOfTheDay.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteEndElement(); writer.WriteStartElement("Tpm2NetTarget"); writer.WriteAttributeString("Host", Tpm2NetTargetHost); writer.WriteAttributeString("Port", Tpm2NetTargetPort.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteEndElement(); writer.WriteEndElement(); }