Example #1
0
 internal int nFlag = 0; //diagnostic for arg out of range on xp
 #region DoAction and consequent Action Functions
 public void DoAction(TCWin tcWinParam)
 {
     tcWin = tcWinParam;
     //Log.WritWTime(tcWin.winText.ToString());
     r = winAction.FindIndex(delegate(NextWinAction s) { return(tcWin.winText.ToString().Contains(s.uniqueWinText)); });
     if (r >= 0)
     {
         Log.WritWTime("  " + winAction[r].uniqueWinText + ", r=" + r.ToString());
         Action A = winAction[r].activeFunction;
         A();
     }
     else
     {
         Log.WriteStrm.WriteLine("NEW WINDOW FOUND Static Text=" + tcWin.staticText.ToString());
         foreach (TCWin.WinCtrls item in tcWin.winCtrlList)
         {
             Log.WriteStrm.WriteLine(item.cntrlClass + ", " + item.caption);
         }
         MessageBox.Show(string.Format("The " + TCWin.mainWinTitle + " Process has displayed an unexpected window.\n Exiting, a log file is located at {0}", Log.logPathFile), DoTasksObj.mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
         Environment.Exit(1);//new window
     }
 }
Example #2
0
        public void DoAction(TCWin tcWinParam)
        {
            tcWin = tcWinParam;
            //Log.WritWTime(tcWin.winText.ToString());
            r = winAction.FindIndex(delegate(NextWinAction s) { return tcWin.winText.ToString().Contains(s.uniqueWinText); });
            if (r >= 0)
            {
                Log.WritWTime("  " + winAction[r].uniqueWinText + ", r=" + r.ToString());
                Action A = winAction[r].activeFunction;
                A();
            }
            else
            {
                Log.WriteStrm.WriteLine("NEW WINDOW FOUND Static Text=" + tcWin.staticText.ToString());
                foreach (TCWin.WinCtrls item in tcWin.winCtrlList)
                {
                    Log.WriteStrm.WriteLine(item.cntrlClass + ", " + item.caption);
                }
                MessageBox.Show(string.Format("The " + TCWin.mainWinTitle + " Process has displayed an unexpected window.\n Exiting, a log file is located at {0}", Log.logPathFile), DoTasksObj.mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                Environment.Exit(1);//new window

            }
        }
 public int DoActionWait()
 {
     DoAction(this);// goes to tcaction and does appropriate thing
     // Wait for next window region
         int i = 0;
         while ((Win32.FindWindow("CustomDlg", mainWinTitle) != IntPtr.Zero) & (winChanged != true))
         {//Main Wait loop
             Thread.Sleep(200);
             int j = TestWinUpdate(hWndHandle);
             if (j == 1)
             {
                 //we have a dialog box This may be recursive since one dialog boox may call another
                 Log.WritWTime("  " + "Dialog Box Found. Next Line shows which one");
                 TCWin dlgWin = new TCWin(hWndDialog);
                 i=dlgWin.DoActionWait(); //does action waits for change if change is another dlgbox recursively comes here
                 if (i != 1)
                 {
                     return 0; //break out of loop this indicates that we have a chnage and it is not a dialog box
                 }
                 hWndDialog = IntPtr.Zero;
                return 1;
             }
         }
         Thread.Sleep(200); //to let window show before continue
     //Come out of action and wait loops here so test for exit conditions
     if (Win32.FindWindow("CustomDlg", mainWinTitle) == IntPtr.Zero)   // normal exit when TrueCrypt process has disappeared
     {
         if (actionsList is TcActionExtract)
         {
             i = ((TcActionExtract)actionsList).TestExit();
         }
         if (actionsList is TcActionUninstall)
         {
             i = ((TcActionUninstall)actionsList).TestExit();
         }
         if (actionsList is TcActionFormat)
         {
             i = ((TcActionFormat)actionsList).TestExit();
         }
         if (actionsList is TcActionInstall)
         {
             i = ((TcActionInstall)actionsList).TestExit();
         }
         if (i == 0)  //we have normal exit
         {
             Log.WritWTime("TrueCrypt Normal Exit");
             return 0;
         }
         //WE WILL HAVE TO PUT THIS TEST IN IN tcaction where have access to r
         //if (winaction[r].captionText == "Exit" | winaction[r].captionText == "&Finish" )
         //{   //covers format (exit) and TC setup (&Finish is clicked)
         //    Log.WritWTime("TrueCrypt Normal Exit");
         //    return 0; //ends the loop
         //}
         foreach (WinCtrls item in winCtrlList)
         {
             if (item.cntrlClass == "Button" & item.caption == "&Finish")
             {   //Uninstall
                 Log.WritWTime("TrueCrypt Setup uninstall Normal Exit");
                 return 0; //ends the loop
             }
         }
         if (uninstallFailContinue == true)
         {
             Log.WritWTime("Uninstall failed due to Directory not empty - non Fatal - so Continue");
             return 0;
         }
         Log.WriteStrm.WriteLine(DateTime.Now.ToString() + mainWinTitle + " Process has disappeared");
         MessageBox.Show(string.Format("The " + mainWinTitle + " Process has unexpectedly disappeared.\n A log file is located at {0}", Log.logPathFile), DoTasksObj.mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
         Environment.Exit(1);
     }
     return 1;
 }
        public int DoActionWait()
        {
            DoAction(this);// goes to tcaction and does appropriate thing
// Wait for next window region
            int i = 0;

            while ((Win32.FindWindow("CustomDlg", mainWinTitle) != IntPtr.Zero) & (winChanged != true))
            {    //Main Wait loop
                Thread.Sleep(200);
                int j = TestWinUpdate(hWndHandle);
                if (j == 1)
                {
                    //we have a dialog box This may be recursive since one dialog boox may call another
                    Log.WritWTime("  " + "Dialog Box Found. Next Line shows which one");
                    TCWin dlgWin = new TCWin(hWndDialog);
                    i = dlgWin.DoActionWait();   //does action waits for change if change is another dlgbox recursively comes here
                    if (i != 1)
                    {
                        return(0);    //break out of loop this indicates that we have a chnage and it is not a dialog box
                    }
                    hWndDialog = IntPtr.Zero;
                    return(1);
                }
            }
            Thread.Sleep(200);                                              //to let window show before continue
            //Come out of action and wait loops here so test for exit conditions
            if (Win32.FindWindow("CustomDlg", mainWinTitle) == IntPtr.Zero) // normal exit when TrueCrypt process has disappeared
            {
                if (actionsList is TcActionExtract)
                {
                    i = ((TcActionExtract)actionsList).TestExit();
                }
                if (actionsList is TcActionUninstall)
                {
                    i = ((TcActionUninstall)actionsList).TestExit();
                }
                if (actionsList is TcActionFormat)
                {
                    i = ((TcActionFormat)actionsList).TestExit();
                }
                if (actionsList is TcActionInstall)
                {
                    i = ((TcActionInstall)actionsList).TestExit();
                }
                if (i == 0)  //we have normal exit
                {
                    Log.WritWTime("TrueCrypt Normal Exit");
                    return(0);
                }
                //WE WILL HAVE TO PUT THIS TEST IN IN tcaction where have access to r
                //if (winaction[r].captionText == "Exit" | winaction[r].captionText == "&Finish" )
                //{   //covers format (exit) and TC setup (&Finish is clicked)
                //    Log.WritWTime("TrueCrypt Normal Exit");
                //    return 0; //ends the loop
                //}
                foreach (WinCtrls item in winCtrlList)
                {
                    if (item.cntrlClass == "Button" & item.caption == "&Finish")
                    {              //Uninstall
                        Log.WritWTime("TrueCrypt Setup uninstall Normal Exit");
                        return(0); //ends the loop
                    }
                }
                if (uninstallFailContinue == true)
                {
                    Log.WritWTime("Uninstall failed due to Directory not empty - non Fatal - so Continue");
                    return(0);
                }
                Log.WriteStrm.WriteLine(DateTime.Now.ToString() + mainWinTitle + " Process has disappeared");
                MessageBox.Show(string.Format("The " + mainWinTitle + " Process has unexpectedly disappeared.\n A log file is located at {0}", Log.logPathFile), DoTasksObj.mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                Environment.Exit(1);
            }
            return(1);
        }
 // Function to  setup and run TC install, uninstall on hard drive
 private void StartUpDriveTC(string prgPath,string prgOptions, string uninTxt, string mainWinTitle)
 {
     //edit box1 for Volume location path and editbox 2 for size strings, prgpath is for truecrypt either HD or traveler, unintxt is action (install, uninstall, extract, format, Main winodw title differs for differing actions
     Log.WriteStrm.WriteLine("StartUpDriveTC path=" + prgPath + " opt=" + prgOptions);
     Process proc2 = new Process();
     proc2.StartInfo.FileName = prgPath;
     proc2.StartInfo.Arguments = prgOptions;
     try
     {
         proc2.Start();
     }
     catch (Exception e)
     {
         Log.WritWTime("Problem starting " + uninTxt + ", exception =" + e.Message.ToString());
         MessageBox.Show("Problem starting " + uninTxt + ", exception =" + e.Message.ToString(),mbCaption,MessageBoxButtons.OK,MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
         Environment.Exit(1);
     }
     TCWin.mainWinTitle = mainWinTitle;
     while (Win32.FindWindow(null, mainWinTitle) == IntPtr.Zero) //wait for program startup
     {
         Thread.Sleep(100);
     }
     Thread.Sleep(1000); //first window takes a while to stabalize
     hWnd = Win32.FindWindow("CustomDlg", mainWinTitle);//CustomDlg
     if (hWnd == IntPtr.Zero)
     {
         Log.WritWTime("Automated TrueCrypt " + uninTxt + " failed.\nPlease " + uninTxt + " TrueCrypt manually then restart this program");
         MessageBox.Show("Automated TrueCrypt " + uninTxt + " failed.\nPlease " + uninTxt + " TrueCrypt manually then restart this program", mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
         Environment.Exit(1);
     }
     while (Win32.IsWindowVisible((IntPtr) hWnd) == false)
     {
         Thread.Sleep(100); //again waiting for format to become visible belt and suspenders
         Log.WriteStrm.WriteLine(uninTxt + "start up window still set to non visible - we have entered this section of code");
     }
     int i = 0;
     while (Win32.FindWindow("CustomDlg", TCWin.mainWinTitle) != IntPtr.Zero)
     {
         if (uninTxt == "format")  // format seems to take extra time to unpack itself
         {
             int staticTextLength = 0;
             int count = 0;
             while (staticTextLength < 60)
             {
                 TCWin winExistTest = new TCWin(hWnd);    // need to make sure child windows exist - only need for format
                 staticTextLength = winExistTest.staticText.Length;
                 count++;
                 Thread.Sleep(200);
             }
             if (count > 1)
             {
                 Log.WriteStrm.WriteLine(uninTxt + "Format window still < 60 chars " + count.ToString() + " Times");
             }
         }
         TCWin tcWin = new TCWin(hWnd); //create object for data associatied with window
         i = tcWin.DoActionWait();   //do the action specified in the List for this window and wait for the window to change
         if (i != 1)
         {
             break;
         }
     }
     // Make sure the process has ended
     if (proc2.HasExited == false)
         {
             Thread.Sleep(500);
         }
 }
        // Function to  setup and run TC install, uninstall on hard drive
        private void StartUpDriveTC(string prgPath, string prgOptions, string uninTxt, string mainWinTitle)
        {   //edit box1 for Volume location path and editbox 2 for size strings, prgpath is for truecrypt either HD or traveler, unintxt is action (install, uninstall, extract, format, Main winodw title differs for differing actions
            Log.WriteStrm.WriteLine("StartUpDriveTC path=" + prgPath + " opt=" + prgOptions);
            Process proc2 = new Process();

            proc2.StartInfo.FileName  = prgPath;
            proc2.StartInfo.Arguments = prgOptions;
            try
            {
                proc2.Start();
            }
            catch (Exception e)
            {
                Log.WritWTime("Problem starting " + uninTxt + ", exception =" + e.Message.ToString());
                MessageBox.Show("Problem starting " + uninTxt + ", exception =" + e.Message.ToString(), mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                Environment.Exit(1);
            }
            TCWin.mainWinTitle = mainWinTitle;
            while (Win32.FindWindow(null, mainWinTitle) == IntPtr.Zero) //wait for program startup
            {
                Thread.Sleep(100);
            }
            Thread.Sleep(1000);                                 //first window takes a while to stabalize
            hWnd = Win32.FindWindow("CustomDlg", mainWinTitle); //CustomDlg
            if (hWnd == IntPtr.Zero)
            {
                Log.WritWTime("Automated TrueCrypt " + uninTxt + " failed.\nPlease " + uninTxt + " TrueCrypt manually then restart this program");
                MessageBox.Show("Automated TrueCrypt " + uninTxt + " failed.\nPlease " + uninTxt + " TrueCrypt manually then restart this program", mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                Environment.Exit(1);
            }
            while (Win32.IsWindowVisible((IntPtr)hWnd) == false)
            {
                Thread.Sleep(100); //again waiting for format to become visible belt and suspenders
                Log.WriteStrm.WriteLine(uninTxt + "start up window still set to non visible - we have entered this section of code");
            }
            int i = 0;

            while (Win32.FindWindow("CustomDlg", TCWin.mainWinTitle) != IntPtr.Zero)
            {
                if (uninTxt == "format")  // format seems to take extra time to unpack itself
                {
                    int staticTextLength = 0;
                    int count            = 0;
                    while (staticTextLength < 60)
                    {
                        TCWin winExistTest = new TCWin(hWnd);    // need to make sure child windows exist - only need for format
                        staticTextLength = winExistTest.staticText.Length;
                        count++;
                        Thread.Sleep(200);
                    }
                    if (count > 1)
                    {
                        Log.WriteStrm.WriteLine(uninTxt + "Format window still < 60 chars " + count.ToString() + " Times");
                    }
                }
                TCWin tcWin = new TCWin(hWnd); //create object for data associatied with window
                i = tcWin.DoActionWait();      //do the action specified in the List for this window and wait for the window to change
                if (i != 1)
                {
                    break;
                }
            }
            // Make sure the process has ended
            if (proc2.HasExited == false)
            {
                Thread.Sleep(500);
            }
        }