public void DoTasks(TasksBitField tasklistPassed,TrueCryptFile tcFileHDOld, TrueCryptFile tcFileTravOld)
        {
            tasklist = tasklistPassed;
            TrueCryptFile tcFileHDoldS = null;
            progOverall = new ProgessOverall(); //get teh progress form initialized
            Thread progressThread = new Thread(new ThreadStart(progOverall.ProgShow)); // starts progress window in new thread initial text is in progshow method
            progressThread.Start();
            Thread.Sleep(200); //allow window to appear
            progUpdate = new ProgUpdateDelegate(progOverall.ProgUpdate); //delegate for later use in updating window
            progUpdateLin2 = new ProgUpdateDelegate(progOverall.ProgUpdate2); //used for second line in traveler section
            progUpdateLin2notVis = new ProgUpdateDelegate1(progOverall.ProgUpdLin2notVis); //used to make second line in traveler section not visible
            Log.WritSection("Starting TaskList");

             #region HD Rename old TC File(s)
            if (tasklist.IsOn(TasksBitField.Flag.hdTcfileOldRename))
            {
                Log.WritWTime("HD Renaming = " + tcFileHDOld.FileNamePath);
                tcFileHDOld.ReName("oldtpdata.tc");
                string fileNames = "";
                //check for existence of s file
                if (File.Exists(tcFileHDOld.FileNamePath.Substring(0,tcFileHDOld.FileNamePath.LastIndexOf('\\')) + "\\tsdata.tc"))
                {//create a new tcfile object
                    tcFileHDoldS = new TrueCryptFile();
                    tcFileHDoldS.FileNamePath = tcFileHDOld.FileNamePath.Substring(0,tcFileHDOld.FileNamePath.LastIndexOf('\\')) + "\\tsdata.tc";
                    Log.WritWTime("HD Renaming = " + tcFileHDoldS.FileNamePath);
                    tcFileHDoldS.ReName("oldtsdata.tc");
                    fileNames = tcFileHDoldS.FileNamePath +",";    // we know we will be adding p
                }
                fileNames += tcFileHDOld.FileNamePath;   //done to ensure order of copying later is s then P
                Microsoft.Win32.Registry.SetValue(regKeyName, "TFTAOld", fileNames);
            }
             #endregion
            // Get all passwords here After we know whether HD S exists
            string regKeyMigrationHD = (string)Microsoft.Win32.Registry.GetValue(regKeyName, "TFTAOld", ""); //get this here in case started with old file existing from previous run of utility
            string regKeyMigrationTrav = (string)Microsoft.Win32.Registry.GetValue(regKeyName, "TFTATravOld", ""); //same for Traveler, this key not set at this point in a normal run of utility
            PasswordCollectForm passCollect = new PasswordCollectForm(tasklist, regKeyMigrationTrav != "",regKeyMigrationHD != "",tcFileHDoldS != null);
            if (tasklist.IsOn(TasksBitField.Flag.hdTCFileFormat) || tasklist.IsOn(TasksBitField.Flag.travtcFileFormat))
            {//need to get passwords
                passCollect.ShowDialog();
            }

             #region HD TA SW old Delete
            if (tasklist.IsOn(TasksBitField.Flag.hdTASwOldDelete))
            {
                Log.WritWTime("Removing HD Old TA Files");
                RemoveOldTaxAideFiles();
            }
             #endregion

             #region HD TC SW uninstall
            if (tasklist.IsOn(TasksBitField.Flag.hdTcSwUninstall))
            {
                Log.WritWTime("Upgrade TrueCrypt on the Hard Drive");
                progOverall.Invoke(progUpdate, new object[] { "Hard Drive TrueCrypt Uninstall, re-install" });
                //Close any TrueCrypt Drives
                Process proc1 = Process.Start(tcProgramFQN, " /q /d /f");
                while (proc1.HasExited == false)
                {
                    Thread.Sleep(100);
                }
                if (proc1.ExitCode != 0)
                {
                    MessageBox.Show(" TrueCrypt Drive Closing failed in some way before uninstall\nPlease close the TrueCrypt Drives manually and restart\n   Exiting", mbCaption,MessageBoxButtons.OK,MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                    Application.Exit();
                }
                Log.WritSection("Uninstalling Hard Drive TrueCrypt Version " + FileVersionInfo.GetVersionInfo(tcProgramFQN).FileVersion);
                TCWin.actionsList = new TcActionUninstall();   //sets up correct list of windows for tc uninstall
                StartUpDriveTC(tcProgramFQN.Substring(0, tcProgramFQN.Length - 4) + " setup.exe", " /u", "uninstall", "TrueCrypt Setup");
                Thread.Sleep(2000); //Let uninstall settle
                //now have to make sure uninstall has really gone
                Process[] myProcArray = Process.GetProcessesByName("TrueCrypt Setup");
                if (myProcArray.GetLength(0) > 0)
                {//the calling procedure is still running likely due to slow processor need to kill it.
                    Log.WritWTime("TrueCrypt uninstall did not exit properly have to kill it");
                    myProcArray[0].Kill();
                    Thread.Sleep(1000); //wait for kill to take effect
                }
            #region Delete any directories and files in truecrypt folder for 64 bit conversion
                string[] directories;
                if (Directory.Exists(tcProgramDirectory)) // make sure directory is truly gone because tc7.0 move to prog files from prog file(x86)
                {
                    directories = Directory.GetDirectories(tcProgramDirectory);
                    foreach (var dir in directories)
                    {
                        DeleteFilesInDir(dir);
                    }
                    DeleteFilesInDir(tcProgramDirectory); //finally the main directory
                }
            #endregion
            }
             #endregion

             #region HD TC SW Install
            if (tasklist.IsOn(TasksBitField.Flag.hdTcSwInstall))
            {
                progOverall.Invoke(progUpdate, new object[] { "Extracting TrueCrypt Setup File" });
                CopyFileFromThisAssembly(tcSetupProgramName, Environment.GetEnvironmentVariable("temp"));
                Log.WritSection("Installing  on Hard Drive " + tcSetupProgramName.Substring(0, tcSetupProgramName.Length - 4));
                progOverall.Invoke(progUpdate, new object[] { "TrueCrypt Hard Drive Install" });
                TCWin.actionsList = new TcActionInstall();
                StartUpDriveTC(Environment.GetEnvironmentVariable("temp") + "\\" + tcSetupProgramName, "", "install", tcSetupProgramName.Substring(0, tcSetupProgramName.Length - 4));
                //setup static field entries in case this is first time install
                tCryptRegEntry = (string)Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\TrueCryptVolume\Shell\open\command", "", "");
                Log.WriteStrm.WriteLine("TrueCrypt Registry Entry = " + tCryptRegEntry);
                tcProgramFQN = tCryptRegEntry.Substring(1, tCryptRegEntry.Length - 10); //registry entry has a leading quote that needs to go
                tcProgramDirectory = tcProgramFQN.Substring(0, tcProgramFQN.Length - 14);
                File.Delete(Dlls.GetAllUsersDesktopFolderPath() + "\\TrueCrypt.lnk"); //gets newly installed truecrypt icon off desktop for xp
                if (DoTasksObj.osVer >= 6)
                {
                    File.Delete(Dlls.GetSharedDesktop() + "\\TrueCrypt.lnk"); //gets newly installed truecrypt icon off desktop for vista 7
                }
            }
             #endregion

             #region HD Tax-Aide SW Install
            if (tasklist.IsOn(TasksBitField.Flag.hdTaxaideSwInstall))
            {
                progOverall.Invoke(progUpdate, new object[] { "Copying Tax-Aide script files" });
                if (!Directory.Exists(tcProgramDirectory + "\\Tax-Aide"))
                {
                    Directory.CreateDirectory(tcProgramDirectory + "\\Tax-Aide");
                }
                CopyTAFilesFromThisAssembly(tcProgramDirectory + "\\Tax-Aide");
            }
             #endregion

             #region HD TC File Create/Format and OLD File Copy
            if (tasklist.IsOn(TasksBitField.Flag.hdTCFileFormat))
            {
                progOverall.Invoke(progUpdate, new object[] { "TrueCrypt Volume Creation" });
                Log.WritSection("Start HD TrueCrypt Volume creation/Formatting");
                TcActionFormat fo = new TcActionFormat();
                TCWin.actionsList = fo;
                fo.SetEditBoxes(TrueCryptFilesNew.tcFileHDNewPath, TrueCryptFilesNew.tcFileHDNewSize.ToString(), passCollect.passHDnewP.Text + "\t" + passCollect.passHDnewP.Text);  // password entry by duplicating it and separating by tab because TCAction only does single text entries.
                StartUpDriveTC(tcProgramDirectory + "\\TrueCrypt Format.exe","", "format", "Truecrypt volume creation wizard");
                progOverall.Invoke(progUpdate, new object[] { "Migrating old Hard Drive TrueCrypt volume(s) files\r across to new Hard Drive TrueCrypt Volume" });
                //test for file move due to old file
                if (regKeyMigrationHD != "") //thie string loaded early for password checking
                {//We have old files to move
                    Log.WritSection("Have to Migrate old HD TrueCrypt volume(s) files across to new TrueCrypt Volume");
                    string[] oldFilePaths = regKeyMigrationHD.Split(new char[] { ',' });
                    //Prepare the user
                    tcDriveOpen(TrueCryptFilesNew.tcFileHDNewPath, "NEW P", "", tcDriveLetter, passCollect.passHDnewP.Text);
                    foreach (var item in oldFilePaths)
                    {
                        if (item.Contains("oldtsdata"))
                        {
                            tcDriveOpen(item, "OLD S", "", "S",passCollect.passHDoldS.Text);
                        }
                        else { tcDriveOpen(item, "OLD P", "", "S", passCollect.passHDoldP.Text); }
                        try
                        {
                            Log.WritWTime("About to Copy old " + item);
                            CopyDirectories("s:\\", tcDriveLetter + "\\");
                        }
                        catch (Exception e)
                        {
                            Log.WritSection("Help = " + e.Message);
                            MessageBox.Show("A problem occurred during copying. Restart the Utility to allow the recovery routines to work. The exception was\n" + e.Message);
                            tcDriveClose("s");
                            tcDriveClose("p");
                            Environment.Exit(1);
                        }
                        tcDriveClose("s");
                    }
                    tcDriveClose(tcDriveLetter.Substring(0,1)); //close p after copying old drives across
                    foreach (var item in oldFilePaths)
                    {// s already closed in loop so now delete files
                        File.Delete(item);
                    }
                    Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(regsubKeyName);
                    rk.DeleteValue("TFTAOld");
                }
            }
            if (!tasklist.TestTrav())
            {//no traveler
                progressThread.Abort();
            }
             #endregion

             #region Trav TC file move to HD
            if (tasklist.IsOn(TasksBitField.Flag.travTcfileOldCopy))
            {
                Log.WritSection("Copying Old traveler TC File to hard drive");
                progOverall.Invoke(progUpdate, new object[] { "Copy old Traveler TrueCrypt volume to the hard drive" });
                string moveLoc = TrueCryptFilesNew.tcFileHDNewPath.Substring(0, TrueCryptFilesNew.tcFileHDNewPath.Length - GetTasksHI.tcFilename.Length) + "oldtrav" + GetTasksHI.tcFilename; // picks up path we are using on this system for tcfiles and standard new file name modified by old
                try
                {
                    FileSystem.MoveFile(tcFileTravOld.FileNamePath, moveLoc, UIOption.AllDialogs);
                }
                catch (Exception e)
                {
                    Log.WritWTime("There was some kind of problem copying the existing TrueCrypt Traveler Volume. The exception is " + e.ToString());
                    MessageBox.Show("There was some kind of problem copying the existing TrueCrypt Traveler Volume. The exception is " + e.ToString() + "Exiting", DoTasksObj.mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Environment.Exit(1);
                }
                //Now let's set registry key for old file note traveler old file object path not updated by move
                Microsoft.Win32.Registry.SetValue(regKeyName, "TFTATravOld", moveLoc);    // record in registry in case of reboot
                regKeyMigrationTrav = moveLoc; //setsup value for later testing for migration
            }
             #endregion

             #region Trav SW old delete
            if (tasklist.IsOn(TasksBitField.Flag.travTASwOldDelete))
            {
                Log.WritWTime("Traveler TrueCrypt being upgraded=" + TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 2)); //must use new filename for disk because old may not exist
                Log.WritWTime(" Now deleting old traveler files");
                if (tasklist.IsOn(TasksBitField.Flag.travTASwOldIsver6_2))
                {
                    RemoveTravelerTCFiles(TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 2) + "\\Tax-Aide_Traveler\\");
                }
                else
                {//pre 6.2 traveler
                    RemoveTravelerTCFiles(TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 3));
                }
            }
             #endregion

             #region Trav Sw Install
            if (tasklist.IsOn(TasksBitField.Flag.travSwInstall))
            {
                progOverall.Invoke(progUpdate, new object[] { "Done deleting software, now for Traveler software install" });
                Directory.CreateDirectory(TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 2) + "\\Tax-Aide_Traveler"); //TA files copied at the end
                if (File.Exists(Environment.GetEnvironmentVariable("temp") + "\\" + tcSetupProgramName))    //COPY TC setup program so it is available to start script
                {   //copies TC setup file to traveler so traveler script has it to upgrade
                    progOverall.Invoke(progUpdateLin2, new object[] { "Copying TrueCrypt Setup from Windows\\temp directory" });
                    try
                    {
                        File.Copy(Environment.GetEnvironmentVariable("temp") + "\\" + tcSetupProgramName, TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 2) + "\\Tax-Aide_Traveler\\" + tcSetupProgramName, true);
                    }
                    catch (Exception e)
                    {
                        Log.WritWTime("Exception in TC setup file Copying is " + e.ToString());
                        MessageBox.Show("Error in Copying file see log File, Exiting", mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Environment.Exit(1);
                    }
                }
                else
                {
                    progOverall.Invoke(progUpdateLin2, new object[] { "Extracting TrueCrypt Setup" });
                    CopyFileFromThisAssembly(tcSetupProgramName, TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 2) + "\\Tax-Aide_Traveler");
                }
                if (tCryptRegEntry != null)
                {
                    progOverall.Invoke(progUpdateLin2, new object[] { "Copying TrueCrypt Software to Traveler\r from hard drive" });
                    try
                    {
                        File.Copy(tcProgramDirectory + "\\TrueCrypt.exe", TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 2) + "\\Tax-Aide_Traveler\\TrueCrypt.exe", true);
                        File.Copy(tcProgramDirectory + "\\TrueCrypt.sys", TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 2) + "\\Tax-Aide_Traveler\\TrueCrypt.sys", true);
                        progOverall.Invoke(progUpdateLin2, new object[] { "Copying TrueCrypt FORMATTING Software to Traveler\r from hard drive" });
                        File.Copy(tcProgramDirectory + "\\TrueCrypt Format.exe", TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 2) + "\\Tax-Aide_Traveler\\TrueCrypt Format.exe", true);
                        File.Copy(tcProgramDirectory + "\\TrueCrypt-x64.sys", TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 2) + "\\Tax-Aide_Traveler\\TrueCrypt-x64.sys", true);
                    }
                    catch (Exception e)
                    {
                        Log.WritWTime("Exception in Truecrypt Files Copying is " + e.ToString());
                        MessageBox.Show("Error in Copying files see log File, Exiting", mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Environment.Exit(1);
                    }
                    Log.WriteStrm.WriteLine("Traveler TrueCrypt upgraded to latest TrueCrypt release by copying host\'s files");
                }
                else  // no TC on host so must use Traveler TC
                {   //have to extract TC files from setup since no TC on host have to cpy setup to temp
                    progOverall.Invoke(progUpdateLin2, new object[] { "Extracting Tax-Aide TrueCrypt Software to Traveler" });
                    tcProgramFQN = TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 2) + "\\Tax-Aide_Traveler\\truecrypt.exe";
                    tcProgramDirectory = tcProgramFQN.Substring(0, tcProgramFQN.Length - 14);
                    CopyFileFromThisAssembly(tcSetupProgramName, Environment.GetEnvironmentVariable("temp"));
                    Log.WritSection("Traveler TrueCrypt being upgraded to latest TrueCrypt release by extracting from TC setup");
                    progOverall.Invoke(progUpdateLin2, new object[] { "Extracting TrueCrypt Software to Traveler" });
                    TcActionExtract ex = new TcActionExtract();
                    TCWin.actionsList = ex;
                    ex.SetPath(TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 3) + "Tax-Aide_Traveler");
                    StartUpDriveTC(Environment.GetEnvironmentVariable("temp") + "\\" + tcSetupProgramName, "", "extract", tcSetupProgramName.Substring(0, tcSetupProgramName.Length - 4));
                }
                //TrueCrypt files setup copy Taxaide files here
                progOverall.Invoke(progUpdateLin2, new object[] { "Extracting Tax-Aide Scripts to Traveler" });
                CopyTAFilesFromThisAssembly(TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 3) + "Tax-Aide_Traveler");
                Log.WritSection("TrueCrypt Program Path to be used for Traveler purposes = " + tcProgramFQN);
                progOverall.Invoke(progUpdateLin2notVis);
            }
             #endregion

             #region Trav tc File Create/Format and OLD File copy
            if (tasklist.IsOn(TasksBitField.Flag.travtcFileFormat))
            {
                progOverall.Invoke(progUpdate, new object[] { "Create and Format Traveler TrueCrypt Volume" });
                Log.WritSection("Traveler TrueCrypt Volume formatting starting");
                TcActionFormat trfo = new TcActionFormat();
                TCWin.actionsList = trfo;
                trfo.SetEditBoxes(TrueCryptFilesNew.tcFileTravNewPath, TrueCryptFilesNew.tcFileTravNewSize.ToString(), passCollect.passTravNewP.Text + "\t" + passCollect.passTravNewP.Text); // specify password as a single text entry by the use of Tab key which is recognized in TCAction later
                StartUpDriveTC(tcProgramDirectory + "\\TrueCrypt Format.exe", "", "format", "Truecrypt volume creation wizard");
                //copy old files
                //test for file move due to old file
                if (regKeyMigrationTrav != "")
                {//We have old files to move
                    Log.WritSection("Have to Migrate old Traveler files across to new TrueCrypt Volume");
                    progOverall.Invoke(progUpdate, new object[] { "Migrate old Traveler files across to new TrueCrypt Volume" });
                    tcDriveOpen(TrueCryptFilesNew.tcFileTravNewPath, "NEW P", "Traveler", tcDriveLetter, passCollect.passTravNewP.Text);
                    tcDriveOpen(regKeyMigrationTrav, "OLD", "Traveler", "S", passCollect.passTravOldP.Text);
                    try
                    {
                        Log.WritWTime("About to Copy old " + regKeyMigrationTrav);
                        CopyDirectories("s:\\", tcDriveLetter + "\\");
                    }
                    catch (Exception e)
                    {
                        Log.WritSection("Help = " + e.Message);
                        MessageBox.Show("A problem occurred during copying. Restart the Utility to allow the recovery routines to work. The exception was\n" + e.Message);
                        tcDriveClose("s");
                        tcDriveClose("p");
                        Environment.Exit(1);
                    }
                    tcDriveClose("s");
                    tcDriveClose(tcDriveLetter);
                    File.Delete(regKeyMigrationTrav);
                    Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(@"SYSTEM\CurrentControlSet\Control\Session Manager\Environment");
                    rk.DeleteValue("TFTATravOld");
                }
            }
             #endregion

            if (File.Exists(Environment.GetEnvironmentVariable("temp") + "\\" + tcSetupProgramName))
            {//a little housekeeping neatness
                File.Delete(Environment.GetEnvironmentVariable("temp") + "\\" + tcSetupProgramName);
            }
            progressThread.Abort();//close down status window
            Log.WritSection("Successfully Completed TaskList");
            MessageBox.Show("Tasks Successfully Completed", mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
        }
        public void DoTasks(TasksBitField tasklistPassed, TrueCryptFile tcFileHDOld, TrueCryptFile tcFileTravOld)
        {
            tasklist = tasklistPassed;
            TrueCryptFile tcFileHDoldS = null;

            progOverall = new ProgessOverall();                                        //get teh progress form initialized
            Thread progressThread = new Thread(new ThreadStart(progOverall.ProgShow)); // starts progress window in new thread initial text is in progshow method

            progressThread.Start();
            Thread.Sleep(200);                                                             //allow window to appear
            progUpdate           = new ProgUpdateDelegate(progOverall.ProgUpdate);         //delegate for later use in updating window
            progUpdateLin2       = new ProgUpdateDelegate(progOverall.ProgUpdate2);        //used for second line in traveler section
            progUpdateLin2notVis = new ProgUpdateDelegate1(progOverall.ProgUpdLin2notVis); //used to make second line in traveler section not visible
            Log.WritSection("Starting TaskList");


            #region HD Rename old TC File(s)
            if (tasklist.IsOn(TasksBitField.Flag.hdTcfileOldRename))
            {
                Log.WritWTime("HD Renaming = " + tcFileHDOld.FileNamePath);
                tcFileHDOld.ReName("oldtpdata.tc");
                string fileNames = "";
                //check for existence of s file
                if (File.Exists(tcFileHDOld.FileNamePath.Substring(0, tcFileHDOld.FileNamePath.LastIndexOf('\\')) + "\\tsdata.tc"))
                {//create a new tcfile object
                    tcFileHDoldS = new TrueCryptFile();
                    tcFileHDoldS.FileNamePath = tcFileHDOld.FileNamePath.Substring(0, tcFileHDOld.FileNamePath.LastIndexOf('\\')) + "\\tsdata.tc";
                    Log.WritWTime("HD Renaming = " + tcFileHDoldS.FileNamePath);
                    tcFileHDoldS.ReName("oldtsdata.tc");
                    fileNames = tcFileHDoldS.FileNamePath + ","; // we know we will be adding p
                }
                fileNames += tcFileHDOld.FileNamePath;           //done to ensure order of copying later is s then P
                Microsoft.Win32.Registry.SetValue(regKeyName, "TFTAOld", fileNames);
            }
            #endregion
            // Get all passwords here After we know whether HD S exists
            string regKeyMigrationHD        = (string)Microsoft.Win32.Registry.GetValue(regKeyName, "TFTAOld", "");     //get this here in case started with old file existing from previous run of utility
            string regKeyMigrationTrav      = (string)Microsoft.Win32.Registry.GetValue(regKeyName, "TFTATravOld", ""); //same for Traveler, this key not set at this point in a normal run of utility
            PasswordCollectForm passCollect = new PasswordCollectForm(tasklist, regKeyMigrationTrav != "", regKeyMigrationHD != "", tcFileHDoldS != null);
            if (tasklist.IsOn(TasksBitField.Flag.hdTCFileFormat) || tasklist.IsOn(TasksBitField.Flag.travtcFileFormat))
            {//need to get passwords
                passCollect.ShowDialog();
            }

            #region HD TA SW old Delete
            if (tasklist.IsOn(TasksBitField.Flag.hdTASwOldDelete))
            {
                Log.WritWTime("Removing HD Old TA Files");
                RemoveOldTaxAideFiles();
            }
            #endregion

            #region HD TC SW uninstall
            if (tasklist.IsOn(TasksBitField.Flag.hdTcSwUninstall))
            {
                Log.WritWTime("Upgrade TrueCrypt on the Hard Drive");
                progOverall.Invoke(progUpdate, new object[] { "Hard Drive TrueCrypt Uninstall, re-install" });
                //Close any TrueCrypt Drives
                Process proc1 = Process.Start(tcProgramFQN, " /q /d /f");
                while (proc1.HasExited == false)
                {
                    Thread.Sleep(100);
                }
                if (proc1.ExitCode != 0)
                {
                    MessageBox.Show(" TrueCrypt Drive Closing failed in some way before uninstall\nPlease close the TrueCrypt Drives manually and restart\n   Exiting", mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                    Application.Exit();
                }
                Log.WritSection("Uninstalling Hard Drive TrueCrypt Version " + FileVersionInfo.GetVersionInfo(tcProgramFQN).FileVersion);
                TCWin.actionsList = new TcActionUninstall(); //sets up correct list of windows for tc uninstall
                StartUpDriveTC(tcProgramFQN.Substring(0, tcProgramFQN.Length - 4) + " setup.exe", " /u", "uninstall", "TrueCrypt Setup");
                Thread.Sleep(2000);                          //Let uninstall settle
                //now have to make sure uninstall has really gone
                Process[] myProcArray = Process.GetProcessesByName("TrueCrypt Setup");
                if (myProcArray.GetLength(0) > 0)
                {//the calling procedure is still running likely due to slow processor need to kill it.
                    Log.WritWTime("TrueCrypt uninstall did not exit properly have to kill it");
                    myProcArray[0].Kill();
                    Thread.Sleep(1000); //wait for kill to take effect
                }
                #region Delete any directories and files in truecrypt folder for 64 bit conversion
                string[] directories;
                if (Directory.Exists(tcProgramDirectory)) // make sure directory is truly gone because tc7.0 move to prog files from prog file(x86)
                {
                    directories = Directory.GetDirectories(tcProgramDirectory);
                    foreach (var dir in directories)
                    {
                        DeleteFilesInDir(dir);
                    }
                    DeleteFilesInDir(tcProgramDirectory); //finally the main directory
                }
                #endregion
            }
            #endregion

            #region HD TC SW Install
            if (tasklist.IsOn(TasksBitField.Flag.hdTcSwInstall))
            {
                progOverall.Invoke(progUpdate, new object[] { "Extracting TrueCrypt Setup File" });
                CopyFileFromThisAssembly(tcSetupProgramName, Environment.GetEnvironmentVariable("temp"));
                Log.WritSection("Installing  on Hard Drive " + tcSetupProgramName.Substring(0, tcSetupProgramName.Length - 4));
                progOverall.Invoke(progUpdate, new object[] { "TrueCrypt Hard Drive Install" });
                TCWin.actionsList = new TcActionInstall();
                StartUpDriveTC(Environment.GetEnvironmentVariable("temp") + "\\" + tcSetupProgramName, "", "install", tcSetupProgramName.Substring(0, tcSetupProgramName.Length - 4));
                //setup static field entries in case this is first time install
                tCryptRegEntry = (string)Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\TrueCryptVolume\Shell\open\command", "", "");
                Log.WriteStrm.WriteLine("TrueCrypt Registry Entry = " + tCryptRegEntry);
                tcProgramFQN       = tCryptRegEntry.Substring(1, tCryptRegEntry.Length - 10); //registry entry has a leading quote that needs to go
                tcProgramDirectory = tcProgramFQN.Substring(0, tcProgramFQN.Length - 14);
                File.Delete(Dlls.GetAllUsersDesktopFolderPath() + "\\TrueCrypt.lnk");         //gets newly installed truecrypt icon off desktop for xp
                if (DoTasksObj.osVer >= 6)
                {
                    File.Delete(Dlls.GetSharedDesktop() + "\\TrueCrypt.lnk"); //gets newly installed truecrypt icon off desktop for vista 7
                }
            }
            #endregion

            #region HD Tax-Aide SW Install
            if (tasklist.IsOn(TasksBitField.Flag.hdTaxaideSwInstall))
            {
                progOverall.Invoke(progUpdate, new object[] { "Copying Tax-Aide script files" });
                if (!Directory.Exists(tcProgramDirectory + "\\Tax-Aide"))
                {
                    Directory.CreateDirectory(tcProgramDirectory + "\\Tax-Aide");
                }
                CopyTAFilesFromThisAssembly(tcProgramDirectory + "\\Tax-Aide");
            }
            #endregion

            #region HD TC File Create/Format and OLD File Copy
            if (tasklist.IsOn(TasksBitField.Flag.hdTCFileFormat))
            {
                progOverall.Invoke(progUpdate, new object[] { "TrueCrypt Volume Creation" });
                Log.WritSection("Start HD TrueCrypt Volume creation/Formatting");
                TcActionFormat fo = new TcActionFormat();
                TCWin.actionsList = fo;
                fo.SetEditBoxes(TrueCryptFilesNew.tcFileHDNewPath, TrueCryptFilesNew.tcFileHDNewSize.ToString(), passCollect.passHDnewP.Text + "\t" + passCollect.passHDnewP.Text);  // password entry by duplicating it and separating by tab because TCAction only does single text entries.
                StartUpDriveTC(tcProgramDirectory + "\\TrueCrypt Format.exe", "", "format", "Truecrypt volume creation wizard");
                progOverall.Invoke(progUpdate, new object[] { "Migrating old Hard Drive TrueCrypt volume(s) files\r across to new Hard Drive TrueCrypt Volume" });
                //test for file move due to old file
                if (regKeyMigrationHD != "") //thie string loaded early for password checking
                {                            //We have old files to move
                    Log.WritSection("Have to Migrate old HD TrueCrypt volume(s) files across to new TrueCrypt Volume");
                    string[] oldFilePaths = regKeyMigrationHD.Split(new char[] { ',' });
                    //Prepare the user
                    tcDriveOpen(TrueCryptFilesNew.tcFileHDNewPath, "NEW P", "", tcDriveLetter, passCollect.passHDnewP.Text);
                    foreach (var item in oldFilePaths)
                    {
                        if (item.Contains("oldtsdata"))
                        {
                            tcDriveOpen(item, "OLD S", "", "S", passCollect.passHDoldS.Text);
                        }
                        else
                        {
                            tcDriveOpen(item, "OLD P", "", "S", passCollect.passHDoldP.Text);
                        }
                        try
                        {
                            Log.WritWTime("About to Copy old " + item);
                            CopyDirectories("s:\\", tcDriveLetter + "\\");
                        }
                        catch (Exception e)
                        {
                            Log.WritSection("Help = " + e.Message);
                            MessageBox.Show("A problem occurred during copying. Restart the Utility to allow the recovery routines to work. The exception was\n" + e.Message);
                            tcDriveClose("s");
                            tcDriveClose("p");
                            Environment.Exit(1);
                        }
                        tcDriveClose("s");
                    }
                    tcDriveClose(tcDriveLetter.Substring(0, 1)); //close p after copying old drives across
                    foreach (var item in oldFilePaths)
                    {                                            // s already closed in loop so now delete files
                        File.Delete(item);
                    }
                    Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(regsubKeyName);
                    rk.DeleteValue("TFTAOld");
                }
            }
            if (!tasklist.TestTrav())
            {//no traveler
                progressThread.Abort();
            }
            #endregion

            #region Trav TC file move to HD
            if (tasklist.IsOn(TasksBitField.Flag.travTcfileOldCopy))
            {
                Log.WritSection("Copying Old traveler TC File to hard drive");
                progOverall.Invoke(progUpdate, new object[] { "Copy old Traveler TrueCrypt volume to the hard drive" });
                string moveLoc = TrueCryptFilesNew.tcFileHDNewPath.Substring(0, TrueCryptFilesNew.tcFileHDNewPath.Length - GetTasksHI.tcFilename.Length) + "oldtrav" + GetTasksHI.tcFilename; // picks up path we are using on this system for tcfiles and standard new file name modified by old
                try
                {
                    FileSystem.MoveFile(tcFileTravOld.FileNamePath, moveLoc, UIOption.AllDialogs);
                }
                catch (Exception e)
                {
                    Log.WritWTime("There was some kind of problem copying the existing TrueCrypt Traveler Volume. The exception is " + e.ToString());
                    MessageBox.Show("There was some kind of problem copying the existing TrueCrypt Traveler Volume. The exception is " + e.ToString() + "Exiting", DoTasksObj.mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Environment.Exit(1);
                }
                //Now let's set registry key for old file note traveler old file object path not updated by move
                Microsoft.Win32.Registry.SetValue(regKeyName, "TFTATravOld", moveLoc); // record in registry in case of reboot
                regKeyMigrationTrav = moveLoc;                                         //setsup value for later testing for migration
            }
            #endregion

            #region Trav SW old delete
            if (tasklist.IsOn(TasksBitField.Flag.travTASwOldDelete))
            {
                Log.WritWTime("Traveler TrueCrypt being upgraded=" + TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 2)); //must use new filename for disk because old may not exist
                Log.WritWTime(" Now deleting old traveler files");
                if (tasklist.IsOn(TasksBitField.Flag.travTASwOldIsver6_2))
                {
                    RemoveTravelerTCFiles(TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 2) + "\\Tax-Aide_Traveler\\");
                }
                else
                {//pre 6.2 traveler
                    RemoveTravelerTCFiles(TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 3));
                }
            }
            #endregion

            #region Trav Sw Install
            if (tasklist.IsOn(TasksBitField.Flag.travSwInstall))
            {
                progOverall.Invoke(progUpdate, new object[] { "Done deleting software, now for Traveler software install" });
                Directory.CreateDirectory(TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 2) + "\\Tax-Aide_Traveler"); //TA files copied at the end
                if (File.Exists(Environment.GetEnvironmentVariable("temp") + "\\" + tcSetupProgramName))                //COPY TC setup program so it is available to start script
                {                                                                                                       //copies TC setup file to traveler so traveler script has it to upgrade
                    progOverall.Invoke(progUpdateLin2, new object[] { "Copying TrueCrypt Setup from Windows\\temp directory" });
                    try
                    {
                        File.Copy(Environment.GetEnvironmentVariable("temp") + "\\" + tcSetupProgramName, TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 2) + "\\Tax-Aide_Traveler\\" + tcSetupProgramName, true);
                    }
                    catch (Exception e)
                    {
                        Log.WritWTime("Exception in TC setup file Copying is " + e.ToString());
                        MessageBox.Show("Error in Copying file see log File, Exiting", mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Environment.Exit(1);
                    }
                }
                else
                {
                    progOverall.Invoke(progUpdateLin2, new object[] { "Extracting TrueCrypt Setup" });
                    CopyFileFromThisAssembly(tcSetupProgramName, TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 2) + "\\Tax-Aide_Traveler");
                }
                if (tCryptRegEntry != null)
                {
                    progOverall.Invoke(progUpdateLin2, new object[] { "Copying TrueCrypt Software to Traveler\r from hard drive" });
                    try
                    {
                        File.Copy(tcProgramDirectory + "\\TrueCrypt.exe", TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 2) + "\\Tax-Aide_Traveler\\TrueCrypt.exe", true);
                        File.Copy(tcProgramDirectory + "\\TrueCrypt.sys", TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 2) + "\\Tax-Aide_Traveler\\TrueCrypt.sys", true);
                        progOverall.Invoke(progUpdateLin2, new object[] { "Copying TrueCrypt FORMATTING Software to Traveler\r from hard drive" });
                        File.Copy(tcProgramDirectory + "\\TrueCrypt Format.exe", TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 2) + "\\Tax-Aide_Traveler\\TrueCrypt Format.exe", true);
                        File.Copy(tcProgramDirectory + "\\TrueCrypt-x64.sys", TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 2) + "\\Tax-Aide_Traveler\\TrueCrypt-x64.sys", true);
                    }
                    catch (Exception e)
                    {
                        Log.WritWTime("Exception in Truecrypt Files Copying is " + e.ToString());
                        MessageBox.Show("Error in Copying files see log File, Exiting", mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Environment.Exit(1);
                    }
                    Log.WriteStrm.WriteLine("Traveler TrueCrypt upgraded to latest TrueCrypt release by copying host\'s files");
                }
                else  // no TC on host so must use Traveler TC
                {   //have to extract TC files from setup since no TC on host have to cpy setup to temp
                    progOverall.Invoke(progUpdateLin2, new object[] { "Extracting Tax-Aide TrueCrypt Software to Traveler" });
                    tcProgramFQN       = TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 2) + "\\Tax-Aide_Traveler\\truecrypt.exe";
                    tcProgramDirectory = tcProgramFQN.Substring(0, tcProgramFQN.Length - 14);
                    CopyFileFromThisAssembly(tcSetupProgramName, Environment.GetEnvironmentVariable("temp"));
                    Log.WritSection("Traveler TrueCrypt being upgraded to latest TrueCrypt release by extracting from TC setup");
                    progOverall.Invoke(progUpdateLin2, new object[] { "Extracting TrueCrypt Software to Traveler" });
                    TcActionExtract ex = new TcActionExtract();
                    TCWin.actionsList = ex;
                    ex.SetPath(TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 3) + "Tax-Aide_Traveler");
                    StartUpDriveTC(Environment.GetEnvironmentVariable("temp") + "\\" + tcSetupProgramName, "", "extract", tcSetupProgramName.Substring(0, tcSetupProgramName.Length - 4));
                }
                //TrueCrypt files setup copy Taxaide files here
                progOverall.Invoke(progUpdateLin2, new object[] { "Extracting Tax-Aide Scripts to Traveler" });
                CopyTAFilesFromThisAssembly(TrueCryptFilesNew.tcFileTravNewPath.Substring(0, 3) + "Tax-Aide_Traveler");
                Log.WritSection("TrueCrypt Program Path to be used for Traveler purposes = " + tcProgramFQN);
                progOverall.Invoke(progUpdateLin2notVis);
            }
            #endregion

            #region Trav tc File Create/Format and OLD File copy
            if (tasklist.IsOn(TasksBitField.Flag.travtcFileFormat))
            {
                progOverall.Invoke(progUpdate, new object[] { "Create and Format Traveler TrueCrypt Volume" });
                Log.WritSection("Traveler TrueCrypt Volume formatting starting");
                TcActionFormat trfo = new TcActionFormat();
                TCWin.actionsList = trfo;
                trfo.SetEditBoxes(TrueCryptFilesNew.tcFileTravNewPath, TrueCryptFilesNew.tcFileTravNewSize.ToString(), passCollect.passTravNewP.Text + "\t" + passCollect.passTravNewP.Text); // specify password as a single text entry by the use of Tab key which is recognized in TCAction later
                StartUpDriveTC(tcProgramDirectory + "\\TrueCrypt Format.exe", "", "format", "Truecrypt volume creation wizard");
                //copy old files
                //test for file move due to old file
                if (regKeyMigrationTrav != "")
                {//We have old files to move
                    Log.WritSection("Have to Migrate old Traveler files across to new TrueCrypt Volume");
                    progOverall.Invoke(progUpdate, new object[] { "Migrate old Traveler files across to new TrueCrypt Volume" });
                    tcDriveOpen(TrueCryptFilesNew.tcFileTravNewPath, "NEW P", "Traveler", tcDriveLetter, passCollect.passTravNewP.Text);
                    tcDriveOpen(regKeyMigrationTrav, "OLD", "Traveler", "S", passCollect.passTravOldP.Text);
                    try
                    {
                        Log.WritWTime("About to Copy old " + regKeyMigrationTrav);
                        CopyDirectories("s:\\", tcDriveLetter + "\\");
                    }
                    catch (Exception e)
                    {
                        Log.WritSection("Help = " + e.Message);
                        MessageBox.Show("A problem occurred during copying. Restart the Utility to allow the recovery routines to work. The exception was\n" + e.Message);
                        tcDriveClose("s");
                        tcDriveClose("p");
                        Environment.Exit(1);
                    }
                    tcDriveClose("s");
                    tcDriveClose(tcDriveLetter);
                    File.Delete(regKeyMigrationTrav);
                    Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(@"SYSTEM\CurrentControlSet\Control\Session Manager\Environment");
                    rk.DeleteValue("TFTATravOld");
                }
            }
            #endregion

            if (File.Exists(Environment.GetEnvironmentVariable("temp") + "\\" + tcSetupProgramName))
            {//a little housekeeping neatness
                File.Delete(Environment.GetEnvironmentVariable("temp") + "\\" + tcSetupProgramName);
            }
            progressThread.Abort();//close down status window
            Log.WritSection("Successfully Completed TaskList");
            MessageBox.Show("Tasks Successfully Completed", mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
        }