コード例 #1
0
ファイル: MForm.cs プロジェクト: HiraokaHyperTools/OCRPattern
        private void RunCmd(string fp, string fppic, string fpcsv, Move2Temp m2t) {
            if (cbMoveInAfter.Checked) {
                m2t.Add(fp);
            }

            if (cbRunOutCmd.Checked) {
                ProcessStartInfo psi = new ProcessStartInfo(Environment.ExpandEnvironmentVariables(tbOutCmd.Text), tbOutParm.Text
                    .Replace("%csv%", fpcsv)
                    .Replace("%pic%", fppic)
                    );
                String cwd = Path.GetDirectoryName(fpxml); // new cwd at fpxml.
                if (cwd != null && Directory.Exists(cwd)) psi.WorkingDirectory = cwd;
                Process p = Process.Start(psi);
                p.WaitForExit();
            }

            if (cbMoveOutAfter.Checked) {
                m2t.Add(fpcsv);
                m2t.Add(fppic);
            }
        }
コード例 #2
0
ファイル: MForm.cs プロジェクト: HiraokaHyperTools/OCRPattern
        private void bRun_Click(object sender, EventArgs e) {
            CRContext crc = new CRContext();
            if (!crc.ReadSet(Path.GetDirectoryName(fpxml))) {
                MessageBox.Show(this, "OCRPattern テンプレート ファイルが見付かりません。\n\n先に作成してください。\n\n中止します。", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            String outDir = tbDirOut.Text;
            if (String.IsNullOrEmpty(outDir) || !Directory.Exists(outDir)) {
                MessageBox.Show(this, "保存できる出力フォルダを先に設定してください。\n\n中止します。", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            String recycDir = cbUseRecyc.Checked ? tbRecycDir.Text : null;
            String formSel = cbOnlyThis.Checked ? tbSeledForm.Text : "";
            FPUt fput = new FPUt(outDir);
            FPUt fputRecyc = (recycDir != null) ? new FPUt(recycDir) : null;
            using (Move2Temp m2t = new Move2Temp())
            using (OCRWIPForm form = OCRWIPForm.Show1()) {
                form.panelWIP.Show();
                foreach (String fp in tbFiles.Lines) {
                    if (!File.Exists(fp)) continue;
                    form.lfn.Text = Path.GetFileName(fp);
                    form.ldir.Text = Path.GetDirectoryName(fp);
                    fput.Flush();
                    String fext = Path.GetExtension(fp);
                    bool isPDF = String.Compare(fext, ".pdf", true) == 0;

                    using (UtPICio pdf = isPDF ? new UtPDFio(fp) as UtPICio : new UtTIFio(fp)) {
                        int cz = pdf.NumPages;
                        for (int z = 0; z < cz; z++) {
                            if (cbDoNotSplit.Checked && z != 0) continue;
                            form.HintPage(1 + z, true);
                            using (Bitmap pic = pdf.Rasterize(z)) {
                                crc.dtCR.Columns.Clear();
                                crc.dtCR.Rows.Clear();
                                CRRes resc;
                                if (CanSave(resc = TryCR(pic, fp, z, crc, form, cbRotate4.Checked, formSel))) {
                                    // 認識:成功
                                    if (resc == CRRes.SaveAll) {
                                        fput.Prepare(fext, ".csv");
                                        File.Copy(fp, fput.fp1, true);
                                        SCUt.SaveCsv(fput.fp2, crc.dtCR, Encoding.Default);
                                        RunCmd(fp, fput.fp1, fput.fp2, m2t);
                                        crc.ClearTempl();
                                        break;
                                    }
                                    else {
                                        fput.Prepare(fext, ".csv");
                                        pdf.SavePageAs(fput.fp1, 1 + z);
                                        SCUt.SaveCsv(fput.fp2, crc.dtCR, Encoding.Default);
                                        RunCmd(fp, fput.fp1, fput.fp2, m2t);
                                    }
                                }
                                else if (fputRecyc != null) {
                                    // 認識:失敗、保存有り
                                    if (cbDoNotSplit.Checked) {
                                        fputRecyc.Prepare(fext, fext);
                                        File.Copy(fp, fputRecyc.fp1, true);
                                        pdf.Dispose();
                                        try {
                                            File.Delete(fp);
                                        }
                                        catch (Exception) { }
                                        break;
                                    }
                                    else {
                                        fputRecyc.Prepare(fext, fext);
                                        pdf.SavePageAs(fputRecyc.fp1, 1 + z);
                                    }
                                }
                            }
                        }
                    }

                }
            }

            Updatefl();
            MessageBox.Show(this, "完了しました。", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }