autoload project file if it exists
This commit is contained in:
		@@ -301,6 +301,7 @@ namespace PDFWorkflowManager
 | 
				
			|||||||
                { }
 | 
					                { }
 | 
				
			||||||
                txtProjectDir.ReadOnly = true;
 | 
					                txtProjectDir.ReadOnly = true;
 | 
				
			||||||
                checkSimplex.Enabled = true;
 | 
					                checkSimplex.Enabled = true;
 | 
				
			||||||
 | 
					                AutoLoadProjectIfExists();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            check_input_dir();
 | 
					            check_input_dir();
 | 
				
			||||||
@@ -732,10 +733,10 @@ namespace PDFWorkflowManager
 | 
				
			|||||||
                TiffToPdfConverter tiffConverter = new TiffToPdfConverter
 | 
					                TiffToPdfConverter tiffConverter = new TiffToPdfConverter
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    // MaxDegreeOfParallelism = trackBarCores.Value // slider to select cores
 | 
					                    // 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(
 | 
					                await tiffConverter.ConvertTiffToPdfWithOcrAsync(
 | 
				
			||||||
                    workOutDir,
 | 
					                    workOutDir,
 | 
				
			||||||
                    outputPdfFileName,
 | 
					                    outputPdfFileName,
 | 
				
			||||||
@@ -1272,7 +1273,15 @@ namespace PDFWorkflowManager
 | 
				
			|||||||
                if (openFileDialog.ShowDialog() == DialogResult.OK)
 | 
					                if (openFileDialog.ShowDialog() == DialogResult.OK)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    string selectedFile = openFileDialog.FileName;
 | 
					                    string selectedFile = openFileDialog.FileName;
 | 
				
			||||||
                    var lines = File.ReadAllLines(selectedFile);
 | 
					                    LoadProjectFromFile(selectedFile);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private void LoadProjectFromFile(string filePath)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            var lines = File.ReadAllLines(filePath);
 | 
				
			||||||
            var dict = new Dictionary<string, string>();
 | 
					            var dict = new Dictionary<string, string>();
 | 
				
			||||||
            foreach (var line in lines)
 | 
					            foreach (var line in lines)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@@ -1308,11 +1317,40 @@ namespace PDFWorkflowManager
 | 
				
			|||||||
            checkSimplex.Checked = dict.ContainsKey("Simplex") ? dict["Simplex"] == "True" : false;
 | 
					            checkSimplex.Checked = dict.ContainsKey("Simplex") ? dict["Simplex"] == "True" : false;
 | 
				
			||||||
            txtProjectDir.Text = dict.ContainsKey("ProjectDir") ? dict["ProjectDir"] : "";
 | 
					            txtProjectDir.Text = dict.ContainsKey("ProjectDir") ? dict["ProjectDir"] : "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    MessageBox.Show("Loaded file: " + selectedFile, "File Loaded", MessageBoxButtons.OK, MessageBoxIcon.Information);
 | 
					            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)
 | 
					        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            using (SaveFileDialog saveFileDialog = new SaveFileDialog())
 | 
					            using (SaveFileDialog saveFileDialog = new SaveFileDialog())
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user