Update code to reflect change in config file.

The configuration now seperates the output path and filename into
seperate componentants.
This commit is contained in:
efrick 2024-08-05 14:32:13 -04:00
parent f85361ed27
commit 1d332927d6
5 changed files with 56 additions and 7 deletions

View File

@ -2,7 +2,8 @@
<configuration> <configuration>
<appSettings> <appSettings>
<add key="PDF-Path" value="C:\Users\ltdvw\Documents\PDF-Test"/> <add key="PDF-Path" value="C:\Users\ltdvw\Documents\PDF-Test"/>
<add key="PDF-Output" value="C:\Users\ltdvw\Documents\PDF-Test\merged.pdf"/> <add key="PDF-Output" value="C:\Users\ltdvw\Documents\PDF-Test\"/>
<add key="PDF-Name" value="merged.pdf"/>
<add key="overwrite" value="true"/> <add key="overwrite" value="true"/>
</appSettings> </appSettings>
</configuration> </configuration>

29
ConfForm.Designer.cs generated
View File

@ -40,11 +40,13 @@ namespace PDF_Merge
overrideCBox = new CheckBox(); overrideCBox = new CheckBox();
sourceDirBtn = new Button(); sourceDirBtn = new Button();
outPathBtn = new Button(); outPathBtn = new Button();
FileLable = new Label();
FileNameBox = new TextBox();
SuspendLayout(); SuspendLayout();
// //
// saveBtn // saveBtn
// //
saveBtn.Location = new Point(327, 175); saveBtn.Location = new Point(327, 227);
saveBtn.Name = "saveBtn"; saveBtn.Name = "saveBtn";
saveBtn.Size = new Size(112, 34); saveBtn.Size = new Size(112, 34);
saveBtn.TabIndex = 0; saveBtn.TabIndex = 0;
@ -54,7 +56,7 @@ namespace PDF_Merge
// //
// cancelBtn // cancelBtn
// //
cancelBtn.Location = new Point(193, 175); cancelBtn.Location = new Point(193, 227);
cancelBtn.Name = "cancelBtn"; cancelBtn.Name = "cancelBtn";
cancelBtn.Size = new Size(112, 34); cancelBtn.Size = new Size(112, 34);
cancelBtn.TabIndex = 1; cancelBtn.TabIndex = 1;
@ -99,7 +101,7 @@ namespace PDF_Merge
overrideCBox.AutoSize = true; overrideCBox.AutoSize = true;
overrideCBox.Checked = true; overrideCBox.Checked = true;
overrideCBox.CheckState = CheckState.Checked; overrideCBox.CheckState = CheckState.Checked;
overrideCBox.Location = new Point(171, 105); overrideCBox.Location = new Point(171, 152);
overrideCBox.Name = "overrideCBox"; overrideCBox.Name = "overrideCBox";
overrideCBox.Size = new Size(179, 29); overrideCBox.Size = new Size(179, 29);
overrideCBox.TabIndex = 6; overrideCBox.TabIndex = 6;
@ -124,12 +126,31 @@ namespace PDF_Merge
outPathBtn.TabIndex = 8; outPathBtn.TabIndex = 8;
outPathBtn.Text = "..."; outPathBtn.Text = "...";
outPathBtn.UseVisualStyleBackColor = true; outPathBtn.UseVisualStyleBackColor = true;
outPathBtn.Click += outPathBtn_Click;
//
// FileLable
//
FileLable.AutoSize = true;
FileLable.Location = new Point(25, 108);
FileLable.Name = "FileLable";
FileLable.Size = new Size(82, 25);
FileLable.TabIndex = 9;
FileLable.Text = "Filename";
//
// FileNameBox
//
FileNameBox.Location = new Point(171, 108);
FileNameBox.Name = "FileNameBox";
FileNameBox.Size = new Size(150, 31);
FileNameBox.TabIndex = 10;
// //
// ConfForm // ConfForm
// //
AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(500, 282); ClientSize = new Size(500, 282);
Controls.Add(FileNameBox);
Controls.Add(FileLable);
Controls.Add(outPathBtn); Controls.Add(outPathBtn);
Controls.Add(sourceDirBtn); Controls.Add(sourceDirBtn);
Controls.Add(overrideCBox); Controls.Add(overrideCBox);
@ -157,5 +178,7 @@ namespace PDF_Merge
private CheckBox overrideCBox; private CheckBox overrideCBox;
private Button sourceDirBtn; private Button sourceDirBtn;
private Button outPathBtn; private Button outPathBtn;
private Label FileLable;
private TextBox FileNameBox;
} }
} }

View File

@ -19,9 +19,11 @@ namespace PDF_Merge
string sourcePath = ConfigurationManager.AppSettings["PDF-Path"]; string sourcePath = ConfigurationManager.AppSettings["PDF-Path"];
string outputPath = ConfigurationManager.AppSettings["PDF-Output"]; string outputPath = ConfigurationManager.AppSettings["PDF-Output"];
string outputName = ConfigurationManager.AppSettings["PDF-Name"];
sourceBox.Text = sourcePath; sourceBox.Text = sourcePath;
outputBox.Text = outputPath; outputBox.Text = outputPath;
FileNameBox.Text = outputName;
if (ConfigurationManager.AppSettings["overwrite"] == true.ToString()) if (ConfigurationManager.AppSettings["overwrite"] == true.ToString())
{ {
overrideCBox.Checked = true; overrideCBox.Checked = true;
@ -57,6 +59,14 @@ namespace PDF_Merge
{ {
MessageBox.Show("Output path cannot be empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Output path cannot be empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
if (FileNameBox.Text.Length > 0)
{
appSettings.Settings["PDF-Name"].Value = FileNameBox.Text;
}
else
{
MessageBox.Show("File must be named.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
appSettings.Settings["overwrite"].Value = overrideCBox.Checked.ToString(); appSettings.Settings["overwrite"].Value = overrideCBox.Checked.ToString();
appConfig.Save(ConfigurationSaveMode.Modified); appConfig.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings"); ConfigurationManager.RefreshSection("appSettings");
@ -67,12 +77,26 @@ namespace PDF_Merge
{ {
using (var SourceDirPicker = new FolderBrowserDialog()) using (var SourceDirPicker = new FolderBrowserDialog())
{ {
if(SourceDirPicker.ShowDialog() == DialogResult.OK) if (sourceBox.Text == "")
{
SourceDirPicker.RootFolder = Environment.SpecialFolder.MyDocuments;
}
else
{
string startingDir = sourceBox.Text;
SourceDirPicker.SelectedPath = startingDir;
}
if (SourceDirPicker.ShowDialog() == DialogResult.OK)
{ {
var sourceDir = SourceDirPicker.SelectedPath; var sourceDir = SourceDirPicker.SelectedPath;
sourceBox.Text = sourceDir; sourceBox.Text = sourceDir;
} }
} }
} }
private void outPathBtn_Click(object sender, EventArgs e)
{
using (var OutPathPicker = new OpenFileDialog()) { }
}
} }
} }

View File

@ -50,7 +50,8 @@ namespace PDF_Merge
private void button1_Click(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e)
{ {
string[] pdf_files = MergePDFs.CollectPdfFiles(); string[] pdf_files = MergePDFs.CollectPdfFiles();
MergePDFs.MergePdfFiles(pdf_files, ConfigurationManager.AppSettings["PDF-Output"]); string pdfPath = ConfigurationManager.AppSettings["PDF-Output"] + "/" + ConfigurationManager.AppSettings["PDF-Name"];
MergePDFs.MergePdfFiles(pdf_files, pdfPath);
} }
private void exitToolStripMenuItem_Click(object sender, EventArgs e) private void exitToolStripMenuItem_Click(object sender, EventArgs e)

View File

@ -14,7 +14,7 @@
using (var output = new PdfDocument()) using (var output = new PdfDocument())
{ {
if (ConfigurationManager.AppSettings["overwrite"] == "true") if (ConfigurationManager.AppSettings["overwrite"] == true.ToString())
{ {
if (File.Exists(outputPath)) if (File.Exists(outputPath))
{ {