public static void TipToCheckModConfliction(this DEModPack self) { var sb = new StringBuilder(); try { var checkResult = self.GetConflictionInfo(); string title = ""; sb.Append($"总文件数: {checkResult.TotalCount}, 无冲突文件数: {checkResult.ValidCount}, 冲突文件数: {checkResult.ConflictedCount}\n"); if (checkResult.ConflictedCount <= 0) { title = "检查结果 - 无冲突"; } else { title = "检查结果 - 以下文件存在冲突"; int conflictID = 1; foreach (string conflictedFile in checkResult.ConflictedFiles.Keys) { sb.Append($"[{conflictID}]{conflictedFile}\n"); foreach (string relatedFile in checkResult.ConflictedFiles[conflictedFile]) { sb.Append($" > {relatedFile}\n"); } sb.Append('\n'); conflictID += 1; } } View.InformationWindow.Show(sb.ToString(), title, Application.Current.MainWindow); } catch (Exception exp) { MessageBox.Show($"冲突检查出错,原因:{exp.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error); } }
public static void TipToExportMergedResource(this DEModPack self) { var sfd = new System.Windows.Forms.SaveFileDialog(); sfd.FileName = self.PackName; sfd.InitialDirectory = Environment.CurrentDirectory; sfd.Filter = "zip压缩包|*.zip"; sfd.AddExtension = true; if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { string outputFile = sfd.FileName; int conflictedItems = self.GetConflictionInfo().ConflictedCount; string fileName = Path.GetFileNameWithoutExtension(outputFile); string mergeWorkingFolder = $@"{DOOMEternal.ModPacksDirectory}\MERGE_WORKING_FOLDER_{fileName}"; if (conflictedItems > 0) { throw new NotSupportedException("该模组配置存在冲突,请解决冲突后再导出"); } try { if (Directory.Exists(mergeWorkingFolder)) { Directory.Delete(mergeWorkingFolder, true); } Directory.CreateDirectory(mergeWorkingFolder); foreach (var resource in self.Resources) { using (var zipFile = ZipFile.OpenRead($@"{DOOMEternal.ModPacksDirectory}\{resource.Path}")) { zipFile.ExtractToDirectory(mergeWorkingFolder); } } ZipFile.CreateFromDirectory(mergeWorkingFolder, outputFile, CompressionLevel.Fastest, false); } catch (Exception) { throw; } finally { Directory.Delete(mergeWorkingFolder, true); } MessageBox.Show($"导出成功,文件已保存至{sfd.FileName}", "完成", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception exp) { MessageBox.Show($"无法生成组合包,原因:{exp.Message}", "生成错误", MessageBoxButton.OK, MessageBoxImage.Error); } } }