Added dialog for setting PDF output filename, and setting for outputfile name (in .oncifg)
This commit is contained in:
parent
48bc1ccc74
commit
534f5b32f6
@ -87,9 +87,6 @@
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Xaml">
|
||||
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\Common\PdfScribeSharedAssemblyInfo.cs">
|
||||
@ -111,10 +108,20 @@
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Compile Include="SetOutputFilename.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SetOutputFilename.Designer.cs">
|
||||
<DependentUpon>SetOutputFilename.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Settings.cs" />
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="SetOutputFilename.resx">
|
||||
<DependentUpon>SetOutputFilename.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<None Include="App.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
|
@ -42,24 +42,15 @@ namespace PdfScribe
|
||||
[STAThread]
|
||||
static void Main(string[] args)
|
||||
{
|
||||
|
||||
// Install the global exception handler
|
||||
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Application_UnhandledException);
|
||||
|
||||
|
||||
String standardInputFilename = Path.GetTempFileName();
|
||||
String outputFilename = Path.Combine(Path.GetTempPath(), defaultOutputFilename);
|
||||
|
||||
// Only set absolute minimum parameters, let the postscript input
|
||||
// dictate as much as possible
|
||||
String[] ghostScriptArguments = { "-dBATCH", "-dNOPAUSE", "-dSAFER", "-sDEVICE=pdfwrite",
|
||||
String.Format("-sOutputFile={0}", outputFilename), standardInputFilename };
|
||||
String outputFilename = String.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
// Remove the existing OAISISSOFTSCAN.PDF file if present
|
||||
File.Delete(outputFilename);
|
||||
|
||||
using (BinaryReader standardInputReader = new BinaryReader(Console.OpenStandardInput()))
|
||||
{
|
||||
using (FileStream standardInputFile = new FileStream(standardInputFilename, FileMode.Create, FileAccess.ReadWrite))
|
||||
@ -67,7 +58,18 @@ namespace PdfScribe
|
||||
standardInputReader.BaseStream.CopyTo(standardInputFile);
|
||||
}
|
||||
}
|
||||
GhostScript64.CallAPI(ghostScriptArguments);
|
||||
|
||||
if (GetPdfOutputFilename(ref outputFilename))
|
||||
{
|
||||
// Remove the existing PDF file if present
|
||||
File.Delete(outputFilename);
|
||||
// Only set absolute minimum parameters, let the postscript input
|
||||
// dictate as much as possible
|
||||
String[] ghostScriptArguments = { "-dBATCH", "-dNOPAUSE", "-dSAFER", "-sDEVICE=pdfwrite",
|
||||
String.Format("-sOutputFile={0}", outputFilename), standardInputFilename };
|
||||
|
||||
GhostScript64.CallAPI(ghostScriptArguments);
|
||||
}
|
||||
}
|
||||
catch (IOException ioEx)
|
||||
{
|
||||
@ -144,29 +146,101 @@ namespace PdfScribe
|
||||
errorDialogInstructionUnexpectedError);
|
||||
}
|
||||
|
||||
static bool GetPdfOutputFilename(ref String outputFile)
|
||||
{
|
||||
bool filenameRetrieved = false;
|
||||
switch (Properties.Settings.Default.AskUserForOutputFilename)
|
||||
{
|
||||
case (true) :
|
||||
using (SetOutputFilename dialogOwner = new SetOutputFilename())
|
||||
{
|
||||
dialogOwner.TopMost = true;
|
||||
dialogOwner.TopLevel = true;
|
||||
dialogOwner.Show(); // Form won't actually show - Application.Run() never called
|
||||
// but having a topmost/toplevel owner lets us bring the SaveFileDialog to the front
|
||||
dialogOwner.BringToFront();
|
||||
using (SaveFileDialog pdfFilenameDialog = new SaveFileDialog())
|
||||
{
|
||||
pdfFilenameDialog.AddExtension = true;
|
||||
pdfFilenameDialog.AutoUpgradeEnabled = true;
|
||||
pdfFilenameDialog.CheckPathExists = true;
|
||||
pdfFilenameDialog.Filter = "pdf files (*.pdf)|*.pdf";
|
||||
pdfFilenameDialog.ShowHelp = false;
|
||||
pdfFilenameDialog.Title = "PDF Scribe - Set output filename";
|
||||
pdfFilenameDialog.ValidateNames = true;
|
||||
if (pdfFilenameDialog.ShowDialog(dialogOwner) == DialogResult.OK)
|
||||
{
|
||||
outputFile = pdfFilenameDialog.FileName;
|
||||
filenameRetrieved = true;
|
||||
}
|
||||
}
|
||||
dialogOwner.Close();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
outputFile = GetOutputFilename();
|
||||
filenameRetrieved = true;
|
||||
break;
|
||||
}
|
||||
return filenameRetrieved;
|
||||
|
||||
static String GetOutputFilename()
|
||||
}
|
||||
|
||||
private static String GetOutputFilename()
|
||||
{
|
||||
|
||||
String outputFilename = Path.Combine(Path.GetTempPath(), defaultOutputFilename);
|
||||
|
||||
if (!Properties.Settings.Default.AskUserForOutputFilename)
|
||||
String outputFilename = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), defaultOutputFilename);
|
||||
if (!String.IsNullOrEmpty(Properties.Settings.Default.OutputFile) &&
|
||||
!String.IsNullOrWhiteSpace(Properties.Settings.Default.OutputFile))
|
||||
{
|
||||
if (Directory.Exists(Path.GetFullPath(Properties.Settings.Default.OutputFile)))
|
||||
if (IsFilePathValid(Properties.Settings.Default.OutputFile))
|
||||
{
|
||||
if (
|
||||
outputFilename = Properties.Settings.Default.OutputFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsFilePathValid(Environment.ExpandEnvironmentVariables(Properties.Settings.Default.OutputFile)))
|
||||
{
|
||||
outputFilename = Environment.ExpandEnvironmentVariables(Properties.Settings.Default.OutputFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
logEventSource.TraceEvent(TraceEventType.Warning,
|
||||
(int)TraceEventType.Warning,
|
||||
String.Format("Using default output filename {0}",
|
||||
outputFilename));
|
||||
}
|
||||
return String.Empty;
|
||||
return outputFilename;
|
||||
}
|
||||
|
||||
static bool IsFilePathValid(String filePath)
|
||||
{
|
||||
bool pathIsValid = false;
|
||||
|
||||
if (!String.IsNullOrEmpty(filePath) && filePath.Length <= 260)
|
||||
{
|
||||
String directoryName = Path.GetDirectoryName(filePath);
|
||||
String filename = Path.GetFileName(filePath);
|
||||
|
||||
if (Directory.Exists(directoryName))
|
||||
{
|
||||
// Check for invalid filename chars
|
||||
Regex containsABadCharacter = new Regex("["
|
||||
+ Regex.Escape(new String(System.IO.Path.GetInvalidPathChars())) + "]");
|
||||
pathIsValid = !containsABadCharacter.IsMatch(filename);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logEventSource.TraceEvent(TraceEventType.Warning,
|
||||
(int)TraceEventType.Warning,
|
||||
"Output filename is longer than 260 characters, or blank.");
|
||||
}
|
||||
return pathIsValid;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays up a topmost, OK-only message box for the error message
|
||||
/// </summary>
|
||||
|
71
PdfScribe/SetOutputFilename.Designer.cs
generated
Normal file
71
PdfScribe/SetOutputFilename.Designer.cs
generated
Normal file
@ -0,0 +1,71 @@
|
||||
namespace PdfScribe
|
||||
{
|
||||
partial class SetOutputFilename
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SetOutputFilename));
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(43, 24);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(98, 13);
|
||||
this.label1.TabIndex = 0;
|
||||
this.label1.Text = "Set output filename";
|
||||
//
|
||||
// SetOutputFilename
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.CausesValidation = false;
|
||||
this.ClientSize = new System.Drawing.Size(184, 62);
|
||||
this.ControlBox = false;
|
||||
this.Controls.Add(this.label1);
|
||||
this.DoubleBuffered = true;
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.Name = "SetOutputFilename";
|
||||
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "PDF Scribe";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Label label1;
|
||||
}
|
||||
}
|
19
PdfScribe/SetOutputFilename.cs
Normal file
19
PdfScribe/SetOutputFilename.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace PdfScribe
|
||||
{
|
||||
public partial class SetOutputFilename : Form
|
||||
{
|
||||
public SetOutputFilename()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
1787
PdfScribe/SetOutputFilename.resx
Normal file
1787
PdfScribe/SetOutputFilename.resx
Normal file
File diff suppressed because it is too large
Load Diff
28
PdfScribe/Settings.cs
Normal file
28
PdfScribe/Settings.cs
Normal file
@ -0,0 +1,28 @@
|
||||
namespace PdfScribe.Properties {
|
||||
|
||||
|
||||
// This class allows you to handle specific events on the settings class:
|
||||
// The SettingChanging event is raised before a setting's value is changed.
|
||||
// The PropertyChanged event is raised after a setting's value is changed.
|
||||
// The SettingsLoaded event is raised after the setting values are loaded.
|
||||
// The SettingsSaving event is raised before the setting values are saved.
|
||||
internal sealed partial class Settings {
|
||||
|
||||
public Settings() {
|
||||
// // To add event handlers for saving and changing settings, uncomment the lines below:
|
||||
//
|
||||
// this.SettingChanging += this.SettingChangingEventHandler;
|
||||
//
|
||||
// this.SettingsSaving += this.SettingsSavingEventHandler;
|
||||
//
|
||||
}
|
||||
|
||||
private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
|
||||
// Add code to handle the SettingChangingEvent event here.
|
||||
}
|
||||
|
||||
private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
|
||||
// Add code to handle the SettingsSaving event here.
|
||||
}
|
||||
}
|
||||
}
|
@ -71,22 +71,13 @@ namespace PdfScribeUnitTests
|
||||
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Test_ShowActivityWindows()
|
||||
{
|
||||
var activityWindowTester = new PdfScribe.ActivityNotificationPresenter();
|
||||
activityWindowTester.ShowActivityNotificationWindow();
|
||||
//Thread.Sleep(20000);
|
||||
//activityWindowTester.ShowErrorDialog();
|
||||
activityWindowTester.CloseActivityNotificationWindow();
|
||||
}
|
||||
|
||||
/*
|
||||
//[Test]
|
||||
public void Test_ShowSimpleError()
|
||||
{
|
||||
var errorDialog = new PdfScribeCore.ErrorDialogPresenter("Error Caption", "Error Instructions", "Message text");
|
||||
}
|
||||
|
||||
*/
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user