Skip to content

Commit

Permalink
-修复导出信息文件时文件名称异常的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
wmjordan committed Jan 27, 2022
1 parent 90f84d7 commit 9ef4333
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
5 changes: 1 addition & 4 deletions App/Common/FilePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,9 @@ public FilePath ChangeExtension(string extension) {
if (IsEmpty) {
return Empty;
}
if (extension == null) {
if (extension == null || (extension = extension.TrimEnd()).Length == 0) {
extension = String.Empty;
}
else if ((extension = extension.TrimEnd()).Length == 0) {
extension = ".";
}
else if (extension[0] != '.') {
extension = "." + extension;
}
Expand Down
21 changes: 11 additions & 10 deletions App/Functions/InfoExchangerControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,28 +229,29 @@ void _ExportBookmarkButton_Click(object sender, EventArgs e) {
AppContext.MainForm.ResetWorker();
var w = AppContext.MainForm.GetWorker();
w.DoWork += (dummy, arg) => {
var a = arg.Argument as object[];
if (files.Count > 1) {
var p = Path.GetDirectoryName(a[0] as string);
var ext = Path.GetExtension(a[0] as string);
Tracker.SetTotalProgressGoal(files.Count);
foreach (var file in files) {
Processor.Worker.ExportInfo(file.FilePath.ToString(), file.FilePath.Directory.Combine(p).Combine(file.FilePath.ChangeExtension(ext)).ToString());
var b = AppContext.BookmarkFile;
var fs = arg.Argument as List<SourceItem>;
if (fs.Count > 1) {
var p = b.Contains(Path.DirectorySeparatorChar) || b.Contains(Path.AltDirectorySeparatorChar) ? Path.GetDirectoryName(b) : Path.GetFileNameWithoutExtension(b);
var ext = Path.GetExtension(b);
Tracker.SetTotalProgressGoal(fs.Count);
foreach (var file in fs) {
Processor.Worker.ExportInfo(file.FilePath, file.FilePath.Directory.Combine(p).Combine(file.FilePath.ChangeExtension(ext).FileName));
Tracker.IncrementTotalProgress();
if (AppContext.Abort) {
return;
}
}
}
else {
if (files[0].Type != SourceItem.ItemType.Pdf) {
if (fs[0].Type != SourceItem.ItemType.Pdf) {
Tracker.TraceMessage("输入文件不是 PDF 文件。");
return;
}
Processor.Worker.ExportInfo(files[0].FilePath.ToString(), a[0] as string);
Processor.Worker.ExportInfo(fs[0].FilePath, b);
}
};
w.RunWorkerAsync(new object[] { AppContext.BookmarkFile });
w.RunWorkerAsync(files);
}

List<SourceItem> GetSourceItemList() {
Expand Down
9 changes: 5 additions & 4 deletions App/Processor/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,27 +159,28 @@ internal static void RenderPages(string sourceFile, ImageRendererOptions options
}
}

internal static void ExportInfo(string sourceFile, string targetFile) {
internal static void ExportInfo(FilePath sourceFile, FilePath targetFile) {
Tracker.TraceMessage(Tracker.Category.InputFile, sourceFile);
Tracker.TraceMessage(Tracker.Category.OutputFile, targetFile);
var r = OpenPdf(sourceFile, AppContext.LoadPartialPdfFile, false);
if (r == null) {
return;
}
if (FileHelper.IsPathValid(targetFile) == false || Path.GetFileName(targetFile).Length == 0) {
if (targetFile.IsValidPath == false || targetFile.FileName.Length == 0) {
Tracker.TraceMessage(Tracker.Category.Error, Messages.InfoFileNameInvalid);
FormHelper.ErrorBox(Messages.InfoFileNameInvalid);
return;
}
targetFile = FileHelper.MakePathRootedAndWithExtension(targetFile, sourceFile, Ext.Xml, false);
targetFile.CreateContainingDirectory();
var export = new DocInfoExporter(r, AppContext.Exporter);
if (AppContext.Exporter.ExtractImages) {
AppContext.Exporter.Images.OutputPath = FileHelper.CombinePath(Path.GetDirectoryName(targetFile), Path.GetFileNameWithoutExtension(targetFile) + "图片文件\\");
AppContext.Exporter.Images.OutputPath = FileHelper.CombinePath(targetFile.Directory, targetFile.FileNameWithoutExtension + "图片文件\\");
}

try {
Tracker.TraceMessage("正在导出信息文件。");
if (targetFile.EndsWith(Ext.Txt, StringComparison.OrdinalIgnoreCase)) {
if (targetFile.HasExtension(Ext.Txt)) {
Tracker.SetProgressGoal(50);
using (TextWriter w = new StreamWriter(targetFile, false, AppContext.Exporter.GetEncoding())) {
DocInfoExporter.WriteDocumentInfoAttributes(w, sourceFile, r.NumberOfPages);
Expand Down

0 comments on commit 9ef4333

Please sign in to comment.