0

I am having an issue in my script with things running sequentially. I have an initial script to decompile an swf. A second that searches for one string in one of the decompiled files and a third for recompiling into a new swf.

How can I make each process wait until it completes before the next is started?

I am also having trouble with making the second script actually work. It would be nice if I could display something about what it replaced after it finished.

Here is my script so far:

  Imports System.Net

    Public Class Form3
        Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click
            If TextBox4.Text = "" Then
                MessageBox.Show("Please select a directory")
            Else

                Dim fd As OpenFileDialog = New Ope

nFileDialog()
            Dim strFileName As String
            fd.Title = "Open File Dialog"
            fd.InitialDirectory = TextBox1.Text
            fd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
            fd.FilterIndex = 2
            fd.RestoreDirectory = True

            If fd.ShowDialog() = DialogResult.OK Then
                strFileName = fd.FileName
                If InStr(strFileName, ".swf") <> 0 Then
                    TextBox2.Text = strFileName
                Else
                    MessageBox.Show("You have to pick a .swf silly...")
                End If
            End If
        End If
    End Sub

    Private Sub Button8_Click(sender As System.Object, e As System.EventArgs) Handles Button8.Click
        Me.Close()
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim Folder = TextBox4.Text & "\HEXED"
        If TextBox2.Text = "" Then
                MessageBox.Show("You have to pick a .swf silly...")
            Else
                If My.Computer.FileSystem.DirectoryExists(Folder) Then
                    My.Computer.FileSystem.DeleteDirectory(Folder, FileIO.DeleteDirectoryOption.DeleteAllContents)
                End If
            My.Computer.FileSystem.CopyDirectory("C:\Users\Matt\Documents\My_Games\ROTMG\ShadyGamer\WindowsApplication1\WindowsApplication1\RABCDasm", Folder)
                My.Computer.FileSystem.CopyFile(TextBox2.Text, Folder & "\client.swf", True)

            Dim FILE_NAME As String = Folder & "\decompile.bat"
                Dim i As Integer
                Dim aryText(4) As String
                aryText(0) = "cd " & Folder
                aryText(1) = "swfdecompress client.swf"
                aryText(2) = "abcexport client.swf"
                aryText(3) = "rabcdasm client-1.abc"
                Dim objWriter As New System.IO.StreamWriter(FILE_NAME, False)
                For i = 0 To 3
                    objWriter.WriteLine(aryText(i))
                Next
                objWriter.Close()

            Dim psi As New ProcessStartInfo(Folder & "\decompile.bat")
                psi.RedirectStandardError = True
                psi.RedirectStandardOutput = True
                psi.CreateNoWindow = False
                psi.WindowStyle = ProcessWindowStyle.Hidden
                psi.UseShellExecute = False
            Dim decompile As New Process
            Process.Start(psi)

            MessageBox.Show("Click Step 2")
            Button1.Visible = False
            Button3.Visible = True
        End If
    End Sub

    Private Sub TextBox4_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox4.TextChanged

    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog
        MyFolderBrowser.Description = "Select the Folder"
        MyFolderBrowser.ShowNewFolderButton = False
        Dim dlgResult As DialogResult = MyFolderBrowser.ShowDialog()
        If dlgResult = Windows.Forms.DialogResult.OK Then
            TextBox4.Text = MyFolderBrowser.SelectedPath
        End If
    End Sub

    Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
        Dim Folder = TextBox4.Text & "\HEXED"
        Const quote As String = """"
        Dim MyFile As String = Folder & "\client-1\com\company\assembleegameclient\parameters\Parameters.class.asasm"
        Replace(MyFile, quote & TextBox1.Text & quote, quote & TextBox3.Text & quote)
        MessageBox.Show("Click Step 3")
        Button3.Visible = False
        Button4.Visible = True
    End Sub

    Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
        Dim Folder = TextBox4.Text & "\HEXED"
        Dim FILE_NAME2 As String = Folder & "\recompile.bat"
        Dim j As Integer
        Dim aryText2(4) As String
        aryText2(0) = "cd " & Folder
        aryText2(1) = "rabcasm client-1\client-1.main.asasm"
        aryText2(2) = "abcreplace client.swf 1 client-1\client-1.main.abc"
        Dim objWriter2 As New System.IO.StreamWriter(FILE_NAME2, False)
        For j = 0 To 2
            objWriter2.WriteLine(aryText2(j))
        Next
        objWriter2.Close()

        Dim ps As New ProcessStartInfo(Folder & "\recompile.bat")
        ps.RedirectStandardError = True
        ps.RedirectStandardOutput = True
        ps.CreateNoWindow = False
        ps.WindowStyle = ProcessWindowStyle.Hidden
        ps.UseShellExecute = False
        Dim recompile As Process = Process.Start(ps)

        My.Computer.FileSystem.CopyFile(Folder & "\client.swf", TextBox4.Text & "\hexed.swf", True)
    End Sub
    End Class
4

1 回答 1

1

You can use process.WaitForExit() - msdn here - http://msdn.microsoft.com/en-us/library/system.diagnostics.process.waitforexit.aspx

Update

You'll need to change the way you start the process to use this:

        Dim ps As New System.Diagnostics.Process()
        Dim psi As New System.Diagnostics.ProcessStartInfo(folder & "\decompile.bat")
        psi.RedirectStandardError = True
        psi.RedirectStandardOutput = True
        psi.CreateNoWindow = False
        psi.WindowStyle = ProcessWindowStyle.Hidden
        psi.UseShellExecute = False

        ps.StartInfo = psi

        ps.Start()
        ps.WaitForExit()
于 2013-05-15T00:42:37.347 回答