コード例 #1
0
        private void ChooseInputFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog d = new OpenFileDialog();

            d.InitialDirectory = PathRoutines.GetDirFromPath(InputFile.Text);
            d.ShowDialog();
            if (!string.IsNullOrWhiteSpace(d.FileName))
            {
                InputFile.Text = d.FileName;
            }
        }
コード例 #2
0
        public ProjectInstaller()
        {
            InitializeComponent();

            this.Committed += delegate
            {
                //try
                //{
                ServiceController sc = new ServiceController(Program.SERVICE_NAME);
                sc.Start();
                //}
                //catch (Exception e)
                //{
                //    //Message.Error(ex);//brings to an error: object is null
                //    System.Windows.Forms.MessageBox.Show(e.Message);
                //}
            };

            this.BeforeUninstall += delegate
            {
                //try
                //{
                ServiceController sc = new ServiceController(Program.SERVICE_NAME);
                if (sc.Status != ServiceControllerStatus.Stopped)
                {
                    sc.Stop();
                    double timeoutSecs = 20;
                    sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(timeoutSecs));
                    if (sc.Status != ServiceControllerStatus.Stopped)
                    {
                        throw new Exception("Could not stop service '" + Cliver.CisteraScreenCaptureService.Program.SERVICE_NAME + "'. To unistall it, stop it manually.");
                    }
                }
                //}
                //catch (Exception e)
                //{
                //    //Message.Error(ex);//brings to an error: object is null
                //    MessageBox.Show();
                //    throw e;//to stop uninstalling(?)
                //}

                try
                {
                    string servicePath = this.Context.Parameters["assemblypath"];
                    AssemblyRoutines.AssemblyInfo ai = new AssemblyRoutines.AssemblyInfo(servicePath);
                    WindowsFirewall.DeleteRule(ai.AssemblyProduct, servicePath);

                    WindowsFirewall.DeleteRule(ffmpegFirewallRuleName, PathRoutines.GetDirFromPath(servicePath) + "\\ffmpeg.exe");
                }
                catch (Exception e)
                {
                    //MessageBox.Show("You'll may need to set firewall manually because of the following error that happened while setting firewall:\r\n" + e.Message, "Cistera Screen Capture", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    //    throw e;
                }
            };

            this.AfterInstall += delegate
            {
                try
                {
                    string servicePath = this.Context.Parameters["assemblypath"];
                    AssemblyRoutines.AssemblyInfo ai = new AssemblyRoutines.AssemblyInfo(servicePath);
                    WindowsFirewall.DeleteRule(ai.AssemblyProduct);
                    WindowsFirewall.AllowProgram(ai.AssemblyProduct, servicePath, WindowsFirewall.Direction.IN);
                    WindowsFirewall.AllowProgram(ai.AssemblyProduct, servicePath, WindowsFirewall.Direction.OUT);

                    WindowsFirewall.DeleteRule(ffmpegFirewallRuleName);
                    WindowsFirewall.AllowProgram(ffmpegFirewallRuleName, PathRoutines.GetDirFromPath(servicePath) + "\\ffmpeg.exe", WindowsFirewall.Direction.OUT);
                }
                catch (Exception e)
                {
                    MessageBox.Show("You'll may need to set firewall manually because of the following error that happened while setting firewall:\r\n" + e.Message, "Cistera Screen Capture", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    //    throw e;
                }
            };
        }
コード例 #3
0
        public TemplateForm(TemplateManager templateManager)
        {
            InitializeComponent();

            Icon = AssemblyRoutines.GetAppIcon();
            Text = Program.Name + ": Template Editor";

            this.templateManager = templateManager;

            initializeAnchorsTable();
            initializeConditionsTable();
            initializeFieldsTable();

            picture.MouseDown += delegate(object sender, MouseEventArgs e)
            {
                if (pages == null)
                {
                    return;
                }

                Point p = new Point((int)(e.X / (float)pictureScale.Value), (int)(e.Y / (float)pictureScale.Value));

                ResizebleBox rb = findResizebleBox(p, out ResizebleBoxSides resizebleBoxSide);
                if (rb != null)
                {
                    drawingMode        = resizebleBoxSide == ResizebleBoxSides.Left || resizebleBoxSide == ResizebleBoxSides.Right ? DrawingModes.resizingSelectionBoxV : DrawingModes.resizingSelectionBoxH;
                    Cursor.Current     = drawingMode == DrawingModes.resizingSelectionBoxV ? Cursors.VSplit : Cursors.HSplit;
                    selectionBoxPoint0 = rb.R.Location;
                    selectionBoxPoint1 = rb.R.Location;
                    selectionBoxPoint2 = new Point(rb.R.Right, rb.R.Bottom);
                }
                else
                {
                    drawingMode        = DrawingModes.drawingSelectionBox;
                    selectionBoxPoint0 = p;
                    selectionBoxPoint1 = p;
                    selectionBoxPoint2 = p;
                }
                selectionCoordinates.Text = selectionBoxPoint1.ToString();
            };

            picture.MouseMove += delegate(object sender, MouseEventArgs e)
            {
                if (pages == null)
                {
                    return;
                }

                Point p = new Point((int)(e.X / (float)pictureScale.Value), (int)(e.Y / (float)pictureScale.Value));

                switch (drawingMode)
                {
                case DrawingModes.NULL:
                    selectionCoordinates.Text = p.ToString();

                    if (findResizebleBox(p, out ResizebleBoxSides resizebleBoxSide) != null)
                    {
                        Cursor.Current = resizebleBoxSide == ResizebleBoxSides.Left || resizebleBoxSide == ResizebleBoxSides.Right ? Cursors.VSplit : Cursors.HSplit;
                    }
                    else
                    {
                        Cursor.Current = Cursors.Default;
                    }
                    return;

                case DrawingModes.drawingSelectionBox:
                    if (selectionBoxPoint0.X < p.X)
                    {
                        selectionBoxPoint1.X = selectionBoxPoint0.X;
                        selectionBoxPoint2.X = p.X;
                    }
                    else
                    {
                        selectionBoxPoint1.X = p.X;
                        selectionBoxPoint2.X = selectionBoxPoint0.X;
                    }
                    if (selectionBoxPoint0.Y < p.Y)
                    {
                        selectionBoxPoint1.Y = selectionBoxPoint0.Y;
                        selectionBoxPoint2.Y = p.Y;
                    }
                    else
                    {
                        selectionBoxPoint1.Y = p.Y;
                        selectionBoxPoint2.Y = selectionBoxPoint0.Y;
                    }
                    break;

                case DrawingModes.resizingSelectionBoxV:
                    if (Math.Abs(selectionBoxPoint2.X - p.X) < Math.Abs(p.X - selectionBoxPoint1.X))
                    {
                        selectionBoxPoint2.X = p.X;
                    }
                    else
                    {
                        selectionBoxPoint1.X = p.X;
                    }
                    break;

                case DrawingModes.resizingSelectionBoxH:
                    if (Math.Abs(selectionBoxPoint2.Y - p.Y) < Math.Abs(p.Y - selectionBoxPoint1.Y))
                    {
                        selectionBoxPoint2.Y = p.Y;
                    }
                    else
                    {
                        selectionBoxPoint1.Y = p.Y;
                    }
                    break;
                }
                selectionCoordinates.Text = selectionBoxPoint1.ToString() + ":" + selectionBoxPoint2.ToString();
                RectangleF r = new RectangleF(selectionBoxPoint1.X, selectionBoxPoint1.Y, selectionBoxPoint2.X - selectionBoxPoint1.X, selectionBoxPoint2.Y - selectionBoxPoint1.Y);
                clearImageFromBoxes();
                drawBoxes(Settings.Appearance.SelectionBoxColor, Settings.Appearance.SelectionBoxBorderWidth, new List <System.Drawing.RectangleF> {
                    r
                });
            };

            picture.MouseUp += delegate(object sender, MouseEventArgs e)
            {
                try
                {
                    if (pages == null)
                    {
                        return;
                    }

                    if (drawingMode == DrawingModes.NULL)
                    {
                        return;
                    }
                    drawingMode = DrawingModes.NULL;

                    Template.RectangleF r = new Template.RectangleF(selectionBoxPoint1.X, selectionBoxPoint1.Y, selectionBoxPoint2.X - selectionBoxPoint1.X, selectionBoxPoint2.Y - selectionBoxPoint1.Y);
                    if (r.Width == 0 || r.Y == 0)//accidental tap
                    {
                        return;
                    }

                    switch (settingMode)
                    {
                    case SettingModes.SetAnchor:
                    {
                        if (currentAnchorControl == null)
                        {
                            break;
                        }

                        currentAnchorControl.SetTagFromControl();
                        Template.Anchor a = (Template.Anchor)currentAnchorControl.Row.Tag;
                        a.Position = new Template.PointF {
                            X = r.X, Y = r.Y
                        };
                        try
                        {
                            switch (a.Type)
                            {
                            case Template.Anchor.Types.PdfText:
                            {
                                Template.Anchor.PdfText pt = (Template.Anchor.PdfText)a;
                                pt.CharBoxs = new List <Template.Anchor.PdfText.CharBox>();
                                List <Pdf.Line> lines = Pdf.RemoveDuplicatesAndGetLines(Pdf.GetCharBoxsSurroundedByRectangle(pages[currentPageI].PdfCharBoxs, r.GetSystemRectangleF(), true), null);
                                foreach (Pdf.Line l in lines)
                                {
                                    foreach (Pdf.CharBox cb in l.CharBoxs)
                                    {
                                        pt.CharBoxs.Add(new Template.Anchor.PdfText.CharBox
                                                {
                                                    Char      = cb.Char,
                                                    Rectangle = new Template.RectangleF(cb.R.X, cb.R.Y, cb.R.Width, cb.R.Height),
                                                });
                                    }
                                }
                                pt.Size = new Template.SizeF {
                                    Width = r.Width, Height = r.Height
                                };
                            }
                            break;

                            case Template.Anchor.Types.OcrText:
                            {
                                Template.Anchor.OcrText ot = (Template.Anchor.OcrText)a;
                                ot.CharBoxs = new List <Template.Anchor.OcrText.CharBox>();
                                var selectedOcrCharBoxs = new List <Ocr.CharBox>();
                                if (ot.OcrEntirePage)
                                {
                                    selectedOcrCharBoxs.AddRange(Ocr.GetCharBoxsSurroundedByRectangle(pages[currentPageI].ActiveTemplateOcrCharBoxs, r.GetSystemRectangleF()));
                                }
                                else
                                {
                                    foreach (Ocr.CharBox cb in Ocr.This.GetCharBoxs(pages[currentPageI].GetRectangleFromActiveTemplateBitmap(r.X / Settings.Constants.Image2PdfResolutionRatio, r.Y / Settings.Constants.Image2PdfResolutionRatio, r.Width / Settings.Constants.Image2PdfResolutionRatio, r.Height / Settings.Constants.Image2PdfResolutionRatio)))
                                    {
                                        cb.R.X += r.X;
                                        cb.R.Y += r.Y;
                                        selectedOcrCharBoxs.Add(cb);
                                    }
                                }
                                foreach (Ocr.Line l in Ocr.GetLines(selectedOcrCharBoxs, null))
                                {
                                    foreach (Ocr.CharBox cb in l.CharBoxs)
                                    {
                                        ot.CharBoxs.Add(new Template.Anchor.OcrText.CharBox
                                                {
                                                    Char      = cb.Char,
                                                    Rectangle = new Template.RectangleF(cb.R.X, cb.R.Y, cb.R.Width, cb.R.Height),
                                                });
                                    }
                                }
                                ot.Size = new Template.SizeF {
                                    Width = r.Width, Height = r.Height
                                };
                            }
                            break;

                            case Template.Anchor.Types.ImageData:
                            {
                                Template.Anchor.ImageData id = (Template.Anchor.ImageData)a;
                                using (Bitmap rb = pages[currentPageI].GetRectangleFromActiveTemplateBitmap(r.X / Settings.Constants.Image2PdfResolutionRatio, r.Y / Settings.Constants.Image2PdfResolutionRatio, r.Width / Settings.Constants.Image2PdfResolutionRatio, r.Height / Settings.Constants.Image2PdfResolutionRatio))
                                {
                                    using (Bitmap b = ImageData.GetScaled(rb, Settings.Constants.Image2PdfResolutionRatio))
                                        id.Image = new ImageData(b, false);
                                }
                            }
                            break;

                            default:
                                throw new Exception("Unknown option: " + a.Type);
                            }
                            setAnchorRow(currentAnchorControl.Row, a);
                            clearImageFromBoxes();
                            findAndDrawAnchor(a.Id);
                        }
                        finally
                        {
                            anchors.EndEdit();
                        }
                    }
                    break;

                    case SettingModes.SetField:
                    {
                        if (fields.SelectedRows.Count < 1)
                        {
                            break;
                        }
                        var            row = fields.SelectedRows[0];
                        Template.Field f   = (Template.Field)row.Tag;
                        f.Rectangle = r;

                        if (f.LeftAnchor != null)
                        {
                            Page.AnchorActualInfo aai = pages[currentPageI].GetAnchorActualInfo(f.LeftAnchor.Id);
                            f.LeftAnchor.Shift = aai.Shift.Width;
                        }
                        if (f.TopAnchor != null)
                        {
                            Page.AnchorActualInfo aai = pages[currentPageI].GetAnchorActualInfo(f.TopAnchor.Id);
                            f.TopAnchor.Shift = aai.Shift.Height;
                        }
                        if (f.RightAnchor != null)
                        {
                            Page.AnchorActualInfo aai = pages[currentPageI].GetAnchorActualInfo(f.RightAnchor.Id);
                            f.RightAnchor.Shift = aai.Shift.Width;
                        }
                        if (f.BottomAnchor != null)
                        {
                            Page.AnchorActualInfo aai = pages[currentPageI].GetAnchorActualInfo(f.BottomAnchor.Id);
                            f.BottomAnchor.Shift = aai.Shift.Height;
                        }

                        setFieldRow(row, f);
                        extractFieldAndDrawSelectionBox(f);
                        //owners2resizebleBox[f] = new ResizebleBox(f, f.Rectangle.GetSystemRectangleF(), Settings.Appearance.SelectionBoxBorderWidth);
                    }
                    break;

                    case SettingModes.NULL:
                        break;

                    default:
                        throw new Exception("Unknown option: " + settingMode);
                    }
                }
                catch (Exception ex)
                {
                    Message.Error2(ex);
                }
            };

            Shown += delegate
            {
                Application.DoEvents();//make form be drawn completely
                setUIFromTemplate(templateManager.Template);
            };

            FormClosed += delegate
            {
                if (scaledCurrentPageBitmap != null)
                {
                    scaledCurrentPageBitmap.Dispose();
                    scaledCurrentPageBitmap = null;
                }
                if (pages != null)
                {
                    pages.Dispose();
                    pages = null;
                }

                templateManager.LastTestFile = testFile.Text;
            };

            this.EnumControls((Control c) =>
            {
                if (c is SplitContainer s)
                {
                    s.BackColor        = Color.FromArgb(80, 70, 0);
                    s.SplitterWidth    = 2;
                    s.Panel1.BackColor = SystemColors.Control;
                    s.Panel2.BackColor = SystemColors.Control;
                }
            }, true);

            testFile.TextChanged += delegate
            {
                try
                {
                    if (picture.Image != null)
                    {
                        picture.Image.Dispose();
                        picture.Image = null;
                    }
                    if (scaledCurrentPageBitmap != null)
                    {
                        scaledCurrentPageBitmap.Dispose();
                        scaledCurrentPageBitmap = null;
                    }
                    if (pages != null)
                    {
                        pages.Dispose();
                        pages = null;
                    }

                    if (string.IsNullOrWhiteSpace(testFile.Text))
                    {
                        return;
                    }

                    testFile.SelectionStart = testFile.Text.Length;
                    testFile.ScrollToCaret();

                    if (!File.Exists(testFile.Text))
                    {
                        Log.Message.Error("File '" + testFile.Text + "' does not exist!");
                        return;
                    }

                    pages            = new PageCollection(testFile.Text);
                    totalPageNumber  = pages.PdfReader.NumberOfPages;
                    lTotalPages.Text = " / " + totalPageNumber;
                    showPage(1);
                }
                catch (Exception ex)
                {
                    Log.Message.Error(ex);
                }
            };

            pictureScale.ValueChanged += delegate
            {
                if (!loadingTemplate)
                {
                    setScaledImage();
                }
            };

            pageRotation.SelectedIndexChanged += delegate
            {
                reloadPageBitmaps();
                //showPage(currentPageI);
            };

            autoDeskew.CheckedChanged += delegate
            {
                reloadPageBitmaps();
                //showPage(currentPageI);
            };

            Load += delegate
            {
            };

            save.Click            += Save_Click;
            cancel.Click          += delegate { Close(); };
            Help.LinkClicked      += Help_LinkClicked;
            Configure.LinkClicked += Configure_LinkClicked;
            About.LinkClicked     += About_LinkClicked;

            bTestFile.Click += delegate(object sender, EventArgs e)
            {
                OpenFileDialog d = new OpenFileDialog();
                if (!string.IsNullOrWhiteSpace(testFile.Text))
                {
                    d.InitialDirectory = PathRoutines.GetDirFromPath(testFile.Text);
                }
                else
                if (!string.IsNullOrWhiteSpace(templateManager.TestFileDefaultFolder))
                {
                    d.InitialDirectory = templateManager.TestFileDefaultFolder;
                }

                d.Filter = "PDF|*.pdf|"
                           + "All files (*.*)|*.*";
                if (d.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }
                testFile.Text = d.FileName;
            };

            ShowPdfText.LinkClicked += ShowPdfText_LinkClicked;
            ShowOcrText.LinkClicked += ShowOcrText_LinkClicked;
            ShowAsJson.LinkClicked  += showAsJson_LinkClicked;

            tCurrentPage.Leave += delegate
            {
                changeCurrentPage();
            };
            tCurrentPage.KeyDown += delegate(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Enter)
                {
                    changeCurrentPage();
                }
            };
        }
コード例 #4
0
 private void bTestFileFilterRegex_Click(object sender, EventArgs e)
 {
     try
     {
         string         d = string.IsNullOrWhiteSpace(template2.Template.Editor.TestFile) ? Settings.General.InputFolder : PathRoutines.GetDirFromPath(template2.Template.Editor.TestFile);
         FileFilterForm f = new FileFilterForm(d, Serialization.Json.Deserialize <Regex>(FileFilterRegex.Text));
         f.ShowDialog();
     }
     catch (Exception ex)
     {
         Log.Message.Error(ex);
     }
 }