get filepath form title by default

This commit is contained in:
zhuangkh 2021-11-12 01:00:58 +08:00
parent 91c595cc6d
commit faa9a059bc
4 changed files with 80 additions and 43 deletions

View File

@ -15,7 +15,8 @@
<listeners>
<add name="textwriterListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="PdfScribe_trace.log" traceOutputOptions="DateTime"/>
<remove name="Default"/>
<clear/> <!-- Remove the <clear /> element to turn on tracing output -->
<clear/>
<!-- Remove the <clear /> element to turn on tracing output -->
</listeners>
</source>
</sources>
@ -31,9 +32,12 @@
<setting name="OpenAfterCreating" serializeAs="String">
<value>False</value>
</setting>
<setting name="AskUserForOutputFilename" serializeAs="String">
<setting name="UsePrintTitleAsOutputFileName" serializeAs="String">
<value>True</value>
</setting>
<setting name="AskUserForOutputFilename" serializeAs="String">
<value>False</value>
</setting>
</PdfScribe.Properties.Settings>
</applicationSettings>
</configuration>

View File

@ -59,6 +59,7 @@ namespace PdfScribe
}
}
GetPathFormTitle(ref outputFilename, standardInputFilename);
if (GetPdfOutputFilename(ref outputFilename))
{
// Remove the existing PDF file if present
@ -170,6 +171,7 @@ namespace PdfScribe
pdfFilenameDialog.ShowHelp = false;
pdfFilenameDialog.Title = "PDF Scribe - Set output filename";
pdfFilenameDialog.ValidateNames = true;
pdfFilenameDialog.FileName = outputFile;
if (pdfFilenameDialog.ShowDialog(dialogOwner) == DialogResult.OK)
{
outputFile = pdfFilenameDialog.FileName;
@ -182,7 +184,7 @@ namespace PdfScribe
default:
try
{
outputFile = GetOutputFilename();
outputFile = Properties.Settings.Default.UsePrintTitleAsOutputFileName && string.IsNullOrEmpty(outputFile) ? GetOutputFilename() : outputFile;
// Test if we can write to the destination
using (FileStream newOutputFile = File.Create(outputFile))
{ }
@ -227,6 +229,25 @@ namespace PdfScribe
}
private static void GetPathFormTitle(ref String outputFilename,
String standardInputFilename)
{
const String titlePrefix = "%%Title: ";
using (var fs = new FileStream(standardInputFilename, FileMode.Open, FileAccess.Read))
using (var sr = new StreamReader(fs))
{
string line = String.Empty;
while ((line = sr.ReadLine()) != null)
{
if (line.StartsWith(titlePrefix))
{
outputFilename = line.Substring(titlePrefix.Length);
break;
}
}
}
}
private static String GetOutputFilename()
{
String outputFilename = Path.GetFullPath(Environment.ExpandEnvironmentVariables(Properties.Settings.Default.OutputFile));

View File

@ -1,10 +1,10 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
@ -12,7 +12,7 @@ namespace PdfScribe.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
@ -44,6 +44,15 @@ namespace PdfScribe.Properties {
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool UsePrintTitleAsOutputFileName {
get {
return ((bool)(this["UsePrintTitleAsOutputFileName"]));
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("False")]
public bool AskUserForOutputFilename {
get {
return ((bool)(this["AskUserForOutputFilename"]));

View File

@ -8,8 +8,11 @@
<Setting Name="OpenAfterCreating" Type="System.Boolean" Scope="Application">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="AskUserForOutputFilename" Type="System.Boolean" Scope="Application">
<Setting Name="UsePrintTitleAsOutputFileName" Type="System.Boolean" Scope="Application">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="AskUserForOutputFilename" Type="System.Boolean" Scope="Application">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>