autoload project file if it exists
This commit is contained in:
@@ -301,6 +301,7 @@ namespace PDFWorkflowManager
|
||||
{ }
|
||||
txtProjectDir.ReadOnly = true;
|
||||
checkSimplex.Enabled = true;
|
||||
AutoLoadProjectIfExists();
|
||||
}
|
||||
|
||||
check_input_dir();
|
||||
@@ -732,10 +733,10 @@ namespace PDFWorkflowManager
|
||||
TiffToPdfConverter tiffConverter = new TiffToPdfConverter
|
||||
{
|
||||
// MaxDegreeOfParallelism = trackBarCores.Value // slider to select cores
|
||||
MaxDegreeOfParallelism = 8 // slider to select cores
|
||||
MaxDegreeOfParallelism = 20 // slider to select cores
|
||||
};
|
||||
|
||||
string outputPdfFileName = "output.pdf"; // saved in project folder
|
||||
string outputPdfFileName = Path.Combine(txtProjectDir.Text + txtFileName.Text); // saved in project folder
|
||||
await tiffConverter.ConvertTiffToPdfWithOcrAsync(
|
||||
workOutDir,
|
||||
outputPdfFileName,
|
||||
@@ -1272,47 +1273,84 @@ namespace PDFWorkflowManager
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
string selectedFile = openFileDialog.FileName;
|
||||
var lines = File.ReadAllLines(selectedFile);
|
||||
var dict = new Dictionary<string, string>();
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var parts = line.Split(new[] { '=' }, 2);
|
||||
if (parts.Length == 2)
|
||||
dict[parts[0]] = parts[1];
|
||||
}
|
||||
|
||||
txtFileName.Text = dict.ContainsKey("FileName") ? dict["FileName"] : "";
|
||||
txtTitle.Text = dict.ContainsKey("Title") ? dict["Title"] : "";
|
||||
cmbLanguage.SelectedIndex = cmbLanguage.FindStringExact(dict.ContainsKey("Language") ? dict["Language"] : "");
|
||||
txtLanguages.Text = dict.ContainsKey("Languages") ? dict["Languages"] : "";
|
||||
txtType.Text = dict.ContainsKey("Type") ? dict["Type"] : "";
|
||||
txtPublisher.Text = dict.ContainsKey("Publisher") ? dict["Publisher"] : "";
|
||||
txtAuthor.Text = dict.ContainsKey("Author") ? dict["Author"] : "";
|
||||
txtISBN.Text = dict.ContainsKey("ISBN") ? dict["ISBN"] : "";
|
||||
txtDate.Text = dict.ContainsKey("Date") ? dict["Date"] : "";
|
||||
txtPageCount.Text = dict.ContainsKey("PageCount") ? dict["PageCount"] : "";
|
||||
cmbResolution.SelectedIndex = cmbResolution.FindStringExact(dict.ContainsKey("Resolution") ? dict["Resolution"] : "");
|
||||
checkPhotocopy.Checked = dict.ContainsKey("Photocopy") ? dict["Photocopy"] == "True" : false;
|
||||
checkReplace.Checked = dict.ContainsKey("Replace") ? dict["Replace"] == "True" : false;
|
||||
txtPartnumber.Text = dict.ContainsKey("Partnumber") ? dict["Partnumber"] : "";
|
||||
if (int.TryParse(dict.ContainsKey("Quality") ? dict["Quality"] : "4", out int quality))
|
||||
trackBar1.Value = Math.Max(trackBar1.Minimum, Math.Min(trackBar1.Maximum, quality));
|
||||
txtContributor.Text = dict.ContainsKey("Contributor") ? dict["Contributor"] : "";
|
||||
txtContributorURL.Text = dict.ContainsKey("ContributorURL") ? dict["ContributorURL"] : "";
|
||||
txtPostProcessor.Text = dict.ContainsKey("PostProcessor") ? dict["PostProcessor"] : "";
|
||||
txtTimeSpent.Text = dict.ContainsKey("TimeSpent") ? dict["TimeSpent"] : "";
|
||||
txtPDFAuthor.Text = dict.ContainsKey("PDFMetaAuthor") ? dict["PDFMetaAuthor"] : "";
|
||||
txtPDFKeywords.Text = dict.ContainsKey("PDFKeywords") ? dict["PDFKeywords"] : "";
|
||||
cmbBanner.SelectedIndex = cmbBanner.FindStringExact(dict.ContainsKey("Banner") ? dict["Banner"] : "");
|
||||
chkMagazines.Checked = dict.ContainsKey("Magazine") ? dict["Magazine"] == "True" : false;
|
||||
checkSimplex.Checked = dict.ContainsKey("Simplex") ? dict["Simplex"] == "True" : false;
|
||||
txtProjectDir.Text = dict.ContainsKey("ProjectDir") ? dict["ProjectDir"] : "";
|
||||
|
||||
MessageBox.Show("Loaded file: " + selectedFile, "File Loaded", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
LoadProjectFromFile(selectedFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void LoadProjectFromFile(string filePath)
|
||||
{
|
||||
var lines = File.ReadAllLines(filePath);
|
||||
var dict = new Dictionary<string, string>();
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var parts = line.Split(new[] { '=' }, 2);
|
||||
if (parts.Length == 2)
|
||||
dict[parts[0]] = parts[1];
|
||||
}
|
||||
|
||||
txtFileName.Text = dict.ContainsKey("FileName") ? dict["FileName"] : "";
|
||||
txtTitle.Text = dict.ContainsKey("Title") ? dict["Title"] : "";
|
||||
cmbLanguage.SelectedIndex = cmbLanguage.FindStringExact(dict.ContainsKey("Language") ? dict["Language"] : "");
|
||||
txtLanguages.Text = dict.ContainsKey("Languages") ? dict["Languages"] : "";
|
||||
txtType.Text = dict.ContainsKey("Type") ? dict["Type"] : "";
|
||||
txtPublisher.Text = dict.ContainsKey("Publisher") ? dict["Publisher"] : "";
|
||||
txtAuthor.Text = dict.ContainsKey("Author") ? dict["Author"] : "";
|
||||
txtISBN.Text = dict.ContainsKey("ISBN") ? dict["ISBN"] : "";
|
||||
txtDate.Text = dict.ContainsKey("Date") ? dict["Date"] : "";
|
||||
txtPageCount.Text = dict.ContainsKey("PageCount") ? dict["PageCount"] : "";
|
||||
cmbResolution.SelectedIndex = cmbResolution.FindStringExact(dict.ContainsKey("Resolution") ? dict["Resolution"] : "");
|
||||
checkPhotocopy.Checked = dict.ContainsKey("Photocopy") ? dict["Photocopy"] == "True" : false;
|
||||
checkReplace.Checked = dict.ContainsKey("Replace") ? dict["Replace"] == "True" : false;
|
||||
txtPartnumber.Text = dict.ContainsKey("Partnumber") ? dict["Partnumber"] : "";
|
||||
if (int.TryParse(dict.ContainsKey("Quality") ? dict["Quality"] : "4", out int quality))
|
||||
trackBar1.Value = Math.Max(trackBar1.Minimum, Math.Min(trackBar1.Maximum, quality));
|
||||
txtContributor.Text = dict.ContainsKey("Contributor") ? dict["Contributor"] : "";
|
||||
txtContributorURL.Text = dict.ContainsKey("ContributorURL") ? dict["ContributorURL"] : "";
|
||||
txtPostProcessor.Text = dict.ContainsKey("PostProcessor") ? dict["PostProcessor"] : "";
|
||||
txtTimeSpent.Text = dict.ContainsKey("TimeSpent") ? dict["TimeSpent"] : "";
|
||||
txtPDFAuthor.Text = dict.ContainsKey("PDFMetaAuthor") ? dict["PDFMetaAuthor"] : "";
|
||||
txtPDFKeywords.Text = dict.ContainsKey("PDFKeywords") ? dict["PDFKeywords"] : "";
|
||||
cmbBanner.SelectedIndex = cmbBanner.FindStringExact(dict.ContainsKey("Banner") ? dict["Banner"] : "");
|
||||
chkMagazines.Checked = dict.ContainsKey("Magazine") ? dict["Magazine"] == "True" : false;
|
||||
checkSimplex.Checked = dict.ContainsKey("Simplex") ? dict["Simplex"] == "True" : false;
|
||||
txtProjectDir.Text = dict.ContainsKey("ProjectDir") ? dict["ProjectDir"] : "";
|
||||
|
||||
MessageBox.Show("Loaded file: " + filePath, "File Loaded", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
|
||||
private void AutoLoadProjectIfExists()
|
||||
{
|
||||
try
|
||||
{
|
||||
string projectDir = txtProjectDir.Text;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(projectDir) || !Directory.Exists(projectDir))
|
||||
return;
|
||||
|
||||
var projFiles = Directory.GetFiles(projectDir, "*.pdfproj", SearchOption.TopDirectoryOnly);
|
||||
|
||||
if (projFiles.Length == 0)
|
||||
return;
|
||||
|
||||
var latestProjFile = projFiles
|
||||
.Select(f => new FileInfo(f))
|
||||
.OrderByDescending(fi => fi.LastWriteTime)
|
||||
.First()
|
||||
.FullName;
|
||||
|
||||
LoadProjectFromFile(latestProjFile);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Error while auto-loading project: {ex.Message}",
|
||||
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
using (SaveFileDialog saveFileDialog = new SaveFileDialog())
|
||||
|
Reference in New Issue
Block a user