private void Form1_Load(object sender, EventArgs e) { //从已保存的配置文件中读取数据 if (File.Exists(AppConfigPath)) { StringBuilder sb = new StringBuilder(); ProfileHelper.GetPrivateProfileString("Main", "Path", "", sb, 512, AppConfigPath); if (File.Exists(sb.ToString())) { Lbl_AEInstallPath.Text = sb.ToString(); } else { Lbl_AEInstallPath.Text = GetAEInstallPath(); } } else { Lbl_AEInstallPath.Text = GetAEInstallPath(); } AE_InstallPath = Lbl_AEInstallPath.Text; if (File.Exists(AE_InstallPath + AE_ProfileName1)) { CurrentProfileType = ProfileType.ini; AE_ConfigFileName = AE_InstallPath + AE_ProfileName1; ReadConfig(AE_ConfigFileName, ProfileType.ini); } else if (File.Exists(AE_InstallPath + AE_ProfileName2)) { CurrentProfileType = ProfileType.xml; AE_ConfigFileName = AE_InstallPath + AE_ProfileName2; ReadConfig(AE_ConfigFileName, ProfileType.xml); } else { Lbl_AEInstallPath.Text = "请单击选择AE安装路径"; } }
private void ReadConfig(string profileName, ProfileType profileType) { if (File.Exists(profileName)) { if (profileType == ProfileType.ini) { File.SetAttributes(profileName, FileAttributes.Normal); int size = 512; StringBuilder sb = new StringBuilder(size); ProfileHelper.WritePrivateProfileString("Config", "ForceLanguage", "1", profileName); ProfileHelper.GetPrivateProfileString("Config", "Language", "", sb, size, profileName); if (sb.ToString() == "") { Lbl_CurrentLanguage.Text = "未知"; Lbl_CurrentLanguage.Tag = string.Empty; } else if (sb.ToString().Trim() == AE_Lang_CN) { Lbl_CurrentLanguage.Text = "简体中文"; Lbl_CurrentLanguage.Tag = AE_Lang_CN; } else if (sb.ToString().Trim() == AE_Lang_EN) { Lbl_CurrentLanguage.Text = "英语"; Lbl_CurrentLanguage.Tag = AE_Lang_EN; } } else if (profileType == ProfileType.xml) { //读取xml文件 using (XmlReader reader = XmlReader.Create(profileName)) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (reader.Name == "Data") { if (reader.GetAttribute("key") == "installedLanguages") { if (reader.Read()) { string v = reader.Value; if (v.ToUpper() == AE_Lang_CN.ToUpper()) { Lbl_CurrentLanguage.Text = "简体中文"; Lbl_CurrentLanguage.Tag = AE_Lang_CN; } else if (v.ToUpper() == AE_Lang_EN.ToUpper()) { Lbl_CurrentLanguage.Text = "英语"; Lbl_CurrentLanguage.Tag = AE_Lang_EN; } else { Lbl_CurrentLanguage.Text = "未知"; Lbl_CurrentLanguage.Tag = string.Empty; } } } } } } } } } }