/// <summary> /// 载入应用程序保存的配置信息。并设置相关控件的属性等。 /// </summary> private void LoadApplicationSettings() { if (File.Exists(@"配置文件夹\Application.config")) { try { //读取应用程序配置信息。 SharedPreferences sp = new SharedPreferences(@"配置文件夹\Application.config", true); //读取并设置是否保存配置 saveConfig = sp.GetBoolean("saveConfig", true); saveSongList = sp.GetBoolean("saveSongList", true); isFirstTimeRunning = sp.GetBoolean("isFirstTimeRunning", true); userName = sp.GetString("userName", ""); if (File.Exists(@"配置文件夹\songlist.xml") && saveSongList) { LoadSongListPath(); } if (saveConfig) { //读取并设置窗口透明度 BorderImage.Opacity = sp.GetDouble("windowOpacity", 1d); borderOpacity = BorderImage.Opacity; //读取并设置是否显示频谱图 showSpectrum = sp.GetBoolean("showSpectrum", true); //读取并设置是否自动加载歌词文件 autoLoadLyricFile = sp.GetBoolean("autoLoadLyricFile", true); //读取并设置歌词文件的编码方式 string str = sp.GetString("lyricFileEncoding", "null"); if (str != "null") { encoding = Encoding.GetEncoding(Int32.Parse(str)); } //读取并设置桌面歌词字体大小 dskLrcFontSize = sp.GetInt32("dskLyricFontSize", 40); string tempStr = string.Empty; //读取并设置桌面歌词字体 tempStr = sp.GetString("dskLyricFontFamily", "null"); if (tempStr != "null" && tempStr != "") { dskLrcFontFamily = tempStr; } // tempStr = sp.GetString("dskLyricFontStyle", "null"); if (tempStr != "null" && tempStr != "") { dskLrcFontStyle = tempStr; } //读取并设置已播放歌词颜色 tempStr = sp.GetString("playedLyricForeColor", "null"); if (tempStr != "null") { playedForecolor = (Color)(ColorConverter.ConvertFromString(tempStr)); } //读取并设置未播放歌词的颜色 tempStr = sp.GetString("unplayedLyricForeColor", "null"); if (tempStr != "null") { unplayedForecolor = (Color)(ColorConverter.ConvertFromString(tempStr)); } //读取并设置歌名前景色 tempStr = sp.GetString("songNameForeColor", "null"); if (tempStr != "null") { nowPlayingSong.Foreground = GetBrushFromString(tempStr); } //读取并设置标题前景色 tempStr = sp.GetString("windowTitleForeColor", "null"); if (tempStr != "null") { WindowTitle.Foreground = GetBrushFromString(tempStr); } //读取并设置桌面歌词未播放颜色 tempStr = sp.GetString("dskLrcUnplayedForeColor", "null"); if (tempStr != "null") { dskLrcUnplayedForecolor = (Color)(ColorConverter.ConvertFromString(tempStr)); } //读取并设置桌面歌词已播放的 tempStr = sp.GetString("dskLrcPlayedForeColor", "null"); if (tempStr != "null") { dskLrcPlayedForecolor = (Color)(ColorConverter.ConvertFromString(tempStr)); } //读取并设置标题颜色 tempStr = sp.GetString("titleForeColor", "null"); if (tempStr != "null") { titleTB.Foreground = GetBrushFromString(tempStr); } //读取并设置列表项目颜色 tempStr = sp.GetString("unselectedItemForeColor", "null"); if (tempStr != "null") { songListLB.Foreground = GetBrushFromString(tempStr); } //读取并更换背景图片。 borderImagePath = sp.GetString("borderBackImagePath", "null"); if (borderImagePath != "null") { ChangeBorderBackImage(borderImagePath); } //读取并设置为上次关闭时的音量。 this.volumeValuePrb.Value = sp.GetDouble("volume", 50); //读取并设置是否显示桌面歌词 showDesktopLyricItem.IsChecked = sp.GetBoolean("showDskLyric", true); //读取并设置为上次关闭时设置的播放模式 playmodeIndex = sp.GetInt32("playmodeIndex", -1) - 1; PlayerButtonClickDown(playmodeBt); #region 播放器状态还原代码。有点烦。。。 rememberExitPosition = sp.GetBoolean("remeberExitPosition", true); if (songListLB.Items.Count != 0) { if (rememberExitPosition) { if (saveSongList && saveConfig) { if (sp.GetInt32("nowplayingIndex", -2) != -2) { //读取并设置为上次关闭时播放器状态 songListLB.SelectedIndex = sp.GetInt32("nowplayingIndex", -1); //进行播放 PlayerButtonClickDown(mediaControlBt); bassPlayer.ChannelPosition = TimeSpan.FromMilliseconds(sp.GetDouble("pausePosition", 0)); GetLyricIndex(bassPlayer.ChannelPosition.TotalMilliseconds); //再暂停,等待用户操作。 PlayerButtonClickDown(mediaControlBt); } } } } #endregion } } catch (Exception) { try { File.Delete(@"配置文件夹\Application.config"); MessageBox.Show("Sorry, 检测到配置文件损坏,因为格式有误,无法读取。已强制删除配置文件。"); } catch (Exception) { } } } if (isFirstTimeRunning) { //表示是第一次运行程序。 //WelcomeToUse(string.Format("", userName)); isFirstTimeRunning = false; //TestFunc(); } }