From 1d332927d608db30814925ff6ad9127439218062 Mon Sep 17 00:00:00 2001 From: efrick Date: Mon, 5 Aug 2024 14:32:13 -0400 Subject: [PATCH] Update code to reflect change in config file. The configuration now seperates the output path and filename into seperate componentants. --- App.config | 3 ++- ConfForm.Designer.cs | 29 ++++++++++++++++++++++++++--- ConfForm.cs | 26 +++++++++++++++++++++++++- MainForm.cs | 3 ++- MergePDFs.cs | 2 +- 5 files changed, 56 insertions(+), 7 deletions(-) diff --git a/App.config b/App.config index d75b3d3..3ad63fd 100644 --- a/App.config +++ b/App.config @@ -2,7 +2,8 @@ - + + \ No newline at end of file diff --git a/ConfForm.Designer.cs b/ConfForm.Designer.cs index d837486..545b413 100644 --- a/ConfForm.Designer.cs +++ b/ConfForm.Designer.cs @@ -40,11 +40,13 @@ namespace PDF_Merge overrideCBox = new CheckBox(); sourceDirBtn = new Button(); outPathBtn = new Button(); + FileLable = new Label(); + FileNameBox = new TextBox(); SuspendLayout(); // // saveBtn // - saveBtn.Location = new Point(327, 175); + saveBtn.Location = new Point(327, 227); saveBtn.Name = "saveBtn"; saveBtn.Size = new Size(112, 34); saveBtn.TabIndex = 0; @@ -54,7 +56,7 @@ namespace PDF_Merge // // cancelBtn // - cancelBtn.Location = new Point(193, 175); + cancelBtn.Location = new Point(193, 227); cancelBtn.Name = "cancelBtn"; cancelBtn.Size = new Size(112, 34); cancelBtn.TabIndex = 1; @@ -99,7 +101,7 @@ namespace PDF_Merge overrideCBox.AutoSize = true; overrideCBox.Checked = true; overrideCBox.CheckState = CheckState.Checked; - overrideCBox.Location = new Point(171, 105); + overrideCBox.Location = new Point(171, 152); overrideCBox.Name = "overrideCBox"; overrideCBox.Size = new Size(179, 29); overrideCBox.TabIndex = 6; @@ -124,12 +126,31 @@ namespace PDF_Merge outPathBtn.TabIndex = 8; outPathBtn.Text = "..."; 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 // AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(500, 282); + Controls.Add(FileNameBox); + Controls.Add(FileLable); Controls.Add(outPathBtn); Controls.Add(sourceDirBtn); Controls.Add(overrideCBox); @@ -157,5 +178,7 @@ namespace PDF_Merge private CheckBox overrideCBox; private Button sourceDirBtn; private Button outPathBtn; + private Label FileLable; + private TextBox FileNameBox; } } \ No newline at end of file diff --git a/ConfForm.cs b/ConfForm.cs index b4729f0..9fa2c9f 100644 --- a/ConfForm.cs +++ b/ConfForm.cs @@ -19,9 +19,11 @@ namespace PDF_Merge string sourcePath = ConfigurationManager.AppSettings["PDF-Path"]; string outputPath = ConfigurationManager.AppSettings["PDF-Output"]; + string outputName = ConfigurationManager.AppSettings["PDF-Name"]; sourceBox.Text = sourcePath; outputBox.Text = outputPath; + FileNameBox.Text = outputName; if (ConfigurationManager.AppSettings["overwrite"] == true.ToString()) { overrideCBox.Checked = true; @@ -57,6 +59,14 @@ namespace PDF_Merge { 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(); appConfig.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); @@ -67,12 +77,26 @@ namespace PDF_Merge { 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; sourceBox.Text = sourceDir; } } } + + private void outPathBtn_Click(object sender, EventArgs e) + { + using (var OutPathPicker = new OpenFileDialog()) { } + } } } diff --git a/MainForm.cs b/MainForm.cs index f9d615d..fbf1b37 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -50,7 +50,8 @@ namespace PDF_Merge private void button1_Click(object sender, EventArgs e) { 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) diff --git a/MergePDFs.cs b/MergePDFs.cs index 7aa1740..ec87d90 100644 --- a/MergePDFs.cs +++ b/MergePDFs.cs @@ -14,7 +14,7 @@ using (var output = new PdfDocument()) { - if (ConfigurationManager.AppSettings["overwrite"] == "true") + if (ConfigurationManager.AppSettings["overwrite"] == true.ToString()) { if (File.Exists(outputPath)) {