Jump to content
Sign in to follow this  
BatMan22

Is there a way to clean this up?

Recommended Posts

So my program checks to see if another program is frozen at various steps or not.

It's checking to see if the program is stuck on a "GeneratingApplicationMap" or "VerifyingApplication" stage..

If it is, then it pauses and checks again over and over till either it goes to "Completed" or till the three checks all fail to change.. then it forced the process closed and the function ends. Testing is also a pain in the ass because the program never freezes for me so I can't test it. 

I appreciate any help :)

 

Func Finishedyet()
    Local $flagforfinished = "0", $seenbeforeV = "0", $seenbeforeG = "0"

    Do
        Sleep(2000)
        $finished = ControlGetText("Cydia Impactor", "", "Static1")
        If $finished = "Complete" Then $flagforfinished = 1

        If $finished = "GeneratingApplicationMap" And $seenbeforeG = 1 Then
            TrayTip("ERROR", "CydiaImpactor is stuck at Generating Application Map, forcing closed!", 10)
            Sleep(500)
            ProcessClose("Impactor.exe")
            $flagforfinished = 1
        EndIf

        If $finished = "GeneratingApplicationMap" And $seenbeforeG = 0 Then
            TrayTip("Generating Application Map Step Detected", "Checking every 3seconds for freezen step", 3)
            Sleep(3000)
        EndIf

        If $finished = "GeneratingApplicationMap" And $seenbeforeG = 0 Then
            TrayTip("Generating Application Map Step Detected", "Checking every 3seconds for freezen step", 3)
            Sleep(3000)
        EndIf

        If $finished = "GeneratingApplicationMap" And $seenbeforeG = 0 Then
            TrayTip("Generating Application Map Step Detected", "Checking every 3seconds for freezen step", 3)
            Sleep(3000)
        EndIf

        If $finished = "GeneratingApplicationMap" And $seenbeforeG = 0 Then
            $seenbeforeG = 1
            Sleep(3000)
        EndIf

        If $finished = "VerifyingApplication" And $seenbeforeV = 1 Then
            TrayTip("ERROR", "CydiaImpactor is stuck at VerifyingStage, forcing closed!", 10)
            Sleep(500)
            ProcessClose("Impactor.exe")
            $flagforfinished = 1
        EndIf

        $finished = ControlGetText("Cydia Impactor", "", "Static1")
        If $finished = "VerifyingApplication" And $seenbeforeV = 0 Then
            TrayTip("Verifying Application Step Detected", "Checking every 3seconds for freezen step", 3)
            Sleep(3000)
        EndIf

        $finished = ControlGetText("Cydia Impactor", "", "Static1")
        If $finished = "VerifyingApplication" And $seenbeforeV = 0 Then
            TrayTip("Verifying Application Step Detected", "Checking every 3seconds for freezen step", 3)
            Sleep(3000)
        EndIf

        $finished = ControlGetText("Cydia Impactor", "", "Static1")
        If $finished = "VerifyingApplication" And $seenbeforeV = 0 Then
            TrayTip("Verifying Application Step Detected", "Checking every 3seconds for freezen step", 3)
            Sleep(3000)
        EndIf

        $finished = ControlGetText("Cydia Impactor", "", "Static1")
        If $finished = "VerifyingApplication" And $seenbeforeV = 0 Then
            $seenbeforeV = 1
        EndIf

    Until $flagforfinished = 1 ; Check for finished flag

    $flagforfinished = 0
    $seenbefore = 0

EndFunc   ;==>Finishedyet

 

Share this post


Link to post
Share on other sites

I really want to know how to break a statement halfway through if possible... For "If" and "While" situations... Is that possible? I was thinking about re-writing the code to be something like this.. 

If $finished = "GeneratingApplicationMap" Then
            Do
                $finished = ControlGetText("Cydia Impactor", "", "Static1")
                If $finished <> "GeneratingApplicationMap" Then GetOutOfBothTheseLoopsWhatDoIDoHereToMakeThatHappen?
                Sleep(500)
                $frozen += 1
            Until $frozen = 20
        EndIf
        
        If $frozen = 20 OR $frozen2 = 20 Then
            $flagforfinished = 1
        EndIf

 

Share this post


Link to post
Share on other sites

I came up with this.. Seems clean and it works :)

Func Finishedyet()
    Local $flagforfinished = "0", $frozen = "0", $frozen2 = "0"

    Do
        Sleep(10)
        $finished = ControlGetText("Cydia Impactor", "", "Static1")
        If $finished = "Complete" Then $flagforfinished = 1

        If $finished = "VerifyingApplication" Then
            Do
                $finished = ControlGetText("Cydia Impactor", "", "Static1")
                If $finished <> "VerifyingApplication" Then ExitLoop
                Sleep(1000)
                $frozen2 += 1
                ConsoleWrite("frozen2 is: " & $frozen2 & @CRLF)
            Until $frozen2 = 25
        EndIf

        If $finished = "GeneratingApplicationMap" Then
            Do
                $finished = ControlGetText("Cydia Impactor", "", "Static1")
                If $finished <> "GeneratingApplicationMap" Then ExitLoop
                Sleep(1000)
                $frozen += 1
                ConsoleWrite("frozen is: " & $frozen & @CRLF)
            Until $frozen = 25
        EndIf

        If $frozen = 20 Or $frozen2 = 20 Then
            $flagforfinished = 1
        EndIf

    Until $flagforfinished = 1 ; Check for finished flag

    $flagforfinished = 0
    $frozen = 0
    $frozen2 = 0

EndFunc   ;==>Finishedyet

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...