All pastes #909715 Raw Edit

Something

public text v1 · immutable
·published 2008-02-19 13:13 UTC
rendered paste body
class AutoExtracter {
        BackgroundWorker backgroundWorker1;
        Process notePad;
        string Directory = "";

        System.Windows.Forms.RichTextBox output;
    
       
        // This delegate enables asynchronous calls for setting
        // the text property on a TextBox control.
        delegate void SetTextCallback(string text);

        public AutoExtracter() {
            backgroundWorker1 = new BackgroundWorker();
            this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
            this.backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted);
        }

        void dostuff() {
            if(dirs != null) {
                Directory = dirs[counter++];
                this.output = "";
                backgroundWorker1.RunWorkerAsync();
            }
        }      

        private void SetText(string text) {
            // InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.
                        
            if(this.output.InvokeRequired) {
                SetTextCallback d = new SetTextCallback(SetText);
                this.Invoke(d, new object[] { text });
            } else {
                this.output.Text += text + "\r\n";
            }
        }

        void notePad_OutputDataReceived(object sender, DataReceivedEventArgs e) {
            this.SetText(e.Data);
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) {
            if(!String.IsNullOrEmpty(Directory)) {
                notePad = new Process();
                notePad.StartInfo.FileName = @"filenamehere";
              
                notePad.StartInfo.Arguments = "vt \""+Directory+"\""; 
                notePad.OutputDataReceived += new DataReceivedEventHandler(notePad_OutputDataReceived);
                notePad.StartInfo.CreateNoWindow = true;
                notePad.StartInfo.RedirectStandardOutput = true;
                notePad.StartInfo.UseShellExecute = false;
                notePad.Start();
                notePad.BeginOutputReadLine();
                notePad.WaitForExit();
            }
        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
            Regex obj = new Regex("--------[\n\r]*? ((.|\r|\n)*?)[\r\n]*?------", RegexOptions.Multiline); 
            Regex obj2 = new Regex("(.*?)\\r"); 
            Regex obj3 = new Regex("(\\d+)(\\s+\\d+\\s+[\\d%<>-]+\\s+[\\d-]+\\s[\\d:]+\\s+)([\\w\\.-]+)");

            string[] d = obj.Match(output).Groups[1].Value.Split('\n'); 

            List<dir> ls = new List<dir>();

            for(int i = 0; i<d.Length; i+=3) {
                dir di = new dir();
                if(!obj2.Match(d[i]).Groups[1].Value.Trim().Contains("Data header type:")) {
                    
                    
                        ls.Add(di);
                    
                }
            }  

            
        }

      
    }