Example #1
0
 /// <summary>
 /// 保存路径配置
 /// </summary>
 private void SavePathConfig()
 {
     if (!File.Exists(AppConfigPath))
     {
         File.Create(AppConfigPath);
     }
     //保存路径
     ProfileHelper.WritePrivateProfileString("Main", "Path", Lbl_AEInstallPath.Text, AppConfigPath);
 }
Example #2
0
        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安装路径";
            }
        }
Example #3
0
 private void WriteConfig(string profileName, ProfileType profileType)
 {
     if (File.Exists(profileName))
     {
         if (profileType == ProfileType.ini)
         {
             //写ini配置文件
             if (Lbl_CurrentLanguage.Tag.ToString() == AE_Lang_EN)
             {
                 var a = ProfileHelper.WritePrivateProfileString("Config", "Language", "zh_CN", profileName);
             }
             else if (Lbl_CurrentLanguage.Tag.ToString() == AE_Lang_CN)
             {
                 var a = ProfileHelper.WritePrivateProfileString("Config", "Language", "en_US", profileName);
             }
             else
             {
                 MessageBox.Show("未知错误!");
             }
         }
         else if (profileType == ProfileType.xml)
         {
             XmlDocument document = new XmlDocument();
             document.Load(profileName);
             var target = document.SelectSingleNode("/Configuration/Payload/Data[@key='installedLanguages']");
             if (Lbl_CurrentLanguage.Tag.ToString() == AE_Lang_EN)
             {
                 target.InnerText = AE_Lang_CN;
             }
             else if (Lbl_CurrentLanguage.Tag.ToString() == AE_Lang_CN)
             {
                 target.InnerText = AE_Lang_EN;
             }
             document.Save(profileName);
         }
     }
 }
Example #4
0
 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;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }