private void BtnCreate_Click(object sender, RoutedEventArgs e) { // dir 当前路径 fileName 选中那一列的文件名 // versionFloder 保存配置文件夹的路径 //subDirName 对应配置文件生成的目录 subVersionPath 该路径,保存配置文件、复制过去的文件 var btn = sender as Button; var player = btn.DataContext as ConfigList; string dir = System.IO.Directory.GetCurrentDirectory(); Write(dir + "\\fileName.txt", player.ConfigFileName); string fileName = player.ConfigFileName; //判断是否是最新版本,是的话将配置文件移动到 最新版本目录下 if (player.IsVersion) { string newestVersion = System.IO.Path.Combine(dir + "\\Server", "newestFolder"); if (!System.IO.Directory.Exists(newestVersion)) { System.IO.Directory.CreateDirectory(newestVersion); } DeleteFolder(newestVersion);//删除 System.IO.File.Copy(player.ConfigFilePath, newestVersion + "\\" + fileName, true); System.IO.File.Move(newestVersion + "\\" + fileName, newestVersion + "\\newest.ini"); } //判断文件夹是否存在,文件夹设置在哪里比较合适呢? string versionFloder = System.IO.Path.Combine(dir + "\\Server", "versionFolder"); if (!System.IO.Directory.Exists(versionFloder)) { System.IO.Directory.CreateDirectory(versionFloder); } //子文件夹 对应每个配置文件 string subDirName = fileName.Replace('.', '_'); string subVersionPath = System.IO.Path.Combine(versionFloder, subDirName); System.IO.Directory.CreateDirectory(subVersionPath); //复制配置文件到对应的子文件夹下 System.IO.File.Copy(player.ConfigFilePath, subVersionPath + "\\" + fileName, true); //复制选中的文件的内容到该文件下 ObservableCollection <Info> infos = new ModifyProfile().GetFileMessage(); for (int i = 0; i < infos.Count; i++) { if (System.IO.File.Exists(infos[i].path)) { string[] strArr = infos[i].path.Split('\\'); int length = strArr.Length - 1; System.IO.File.Copy(infos[i].path, subVersionPath + "\\" + strArr[length], true); } } //压缩该文件 MessageBox.Show("生成版本成功"); log.Info("生成配置文件版本:" + player.ConfigFileName); }
private void BtnInfo_Click(object sender, RoutedEventArgs e) { var btn = sender as Button; var player = btn.DataContext as ConfigList; string currentPath = System.IO.Directory.GetCurrentDirectory(); Write(currentPath + "\\fileName.txt", player.ConfigFileName); ModifyProfile SWSetting = new ModifyProfile(); SWSetting.WindowStartupLocation = WindowStartupLocation.CenterOwner; SWSetting.Title = "修改配置文件"; SWSetting.ShowDialog(); }