diff --git a/UserManagerTool/InstallWindow.xaml.cs b/UserManagerTool/InstallWindow.xaml.cs index 271770a..c2ce44c 100644 --- a/UserManagerTool/InstallWindow.xaml.cs +++ b/UserManagerTool/InstallWindow.xaml.cs @@ -8,7 +8,9 @@ using System.Windows.Threading; using Microsoft.Win32; using UserManagerTool.Model.Helper; using Path = System.IO.Path; +using System.Configuration; using IWshRuntimeLibrary; +using File = System.IO.File; namespace UserManagerTool; @@ -70,6 +72,7 @@ public partial class InstallWindow : Window string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); // 桌面路径 CreateShortcut(filePath, desktopPath, shortcutName); } + UpdateConfig(); StatusTextBlock.Text = "安装完成"; MessageBox.Show("部署完成"); } @@ -94,7 +97,44 @@ public partial class InstallWindow : Window copyResult = await CopyDirectory(dbPath, InstallPath.Text); return copyResult; } - + public void UpdateConfig() + { + string key = "BaseUrl"; + string value = CutUrl.Text; + var configPath = Path.Combine(InstallPath.Text, "SparkClient.dll.config"); + // 打开配置文件 + + // 检查配置文件是否存在 + if (!File.Exists(configPath)) + { + throw new FileNotFoundException("配置文件未找到", configPath); + } + + // 创建ExeConfigurationFileMap对象,指定配置文件路径 + var configFileMap = new ExeConfigurationFileMap + { + ExeConfigFilename = configPath + }; + + // 加载指定路径的配置文件 + var config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None); + + // 修改AppSettings中的值 + if (config.AppSettings.Settings[key] != null) + { + config.AppSettings.Settings[key].Value = value; + } + else + { + config.AppSettings.Settings.Add(key, value); + } + + // 保存更改 + config.Save(ConfigurationSaveMode.Modified); + + // 刷新ConfigurationManager + ConfigurationManager.RefreshSection("appSettings"); + } private decimal CountFile(string path) { if (Directory.Exists(path))