summaryrefslogtreecommitdiffstats
path: root/win/C#/frmReadDVD.cs
blob: eaecf823fd4ff483e7d3e37018065eaef157dbc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Diagnostics;


namespace Handbrake
{
    public partial class frmReadDVD : Form
    {
        private string inputFile;
        private frmMain mainWindow;
        private frmDvdInfo dvdInfo;
        private Parsing.DVD thisDvd;
        private Process hbProc;
        private delegate void UpdateUIHandler();

        public frmReadDVD(string inputFile, frmMain parent, frmDvdInfo dvdInfoWindow)
        {
            InitializeComponent();
            this.inputFile = inputFile;
            this.mainWindow = parent;
            this.dvdInfo = dvdInfoWindow;
            Parsing.Parser.OnScanProgress += Parser_OnScanProgress;
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            btn_ok.Enabled = false;
            lbl_pressOk.Visible = false;
            scanProgress.Value = 0;
            scanProgress.Visible = true;
            // throw cli call and parsing on it's own thread
            ThreadPool.QueueUserWorkItem(startProc);
        }
     
        private void updateUIElements()
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new UpdateUIHandler(updateUIElements));
                return;
            }
            // Now pass this streamreader to frmMain so that it can be used there.
            mainWindow.setStreamReader(thisDvd);

            mainWindow.drp_dvdtitle.Items.Clear();
            mainWindow.drp_dvdtitle.Items.AddRange(thisDvd.Titles.ToArray());

            this.Close();
        }

        private void startProc(object state)
        {
            string query = "-i " + '"' + inputFile + '"' + " -t0";
          
            Functions.CLI process = new Functions.CLI();
            hbProc = process.runCli(this, query, true, true, false, true);

            Parsing.Parser readData = new Parsing.Parser(hbProc.StandardError.BaseStream);
            //hbProc.WaitForExit();
            hbProc.Close();

            // Setup the parser
            thisDvd = Parsing.DVD.Parse(readData);

            updateUIElements();
        }

        private void Parser_OnScanProgress(object Sender, int CurrentTitle, int TitleCount)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new Parsing.ScanProgressEventHandler(Parser_OnScanProgress), new object[] { Sender, CurrentTitle, TitleCount });
                return;
            }
            this.scanProgress.Value = Convert.ToInt32(Convert.ToDouble(CurrentTitle) / Convert.ToDouble(TitleCount) * 100) + 1;
        }

    }
}