Пример #1
0
 public PasswordCollectForm(TasksBitField tasklist, bool oldTravExists, bool oldHDExists, bool tsdataExists)
 {
     InitializeComponent();
     // setup form panels and size for passwords needed
     this.ActiveControl = this.passHDnewP;
     if (!tasklist.TestTrav())
     {                                    // No traveler
         this.Height -= panelTrav.Height; //HD only no traveler
         this.Controls.Remove(panelTrav);
     }
     else if (!tasklist.TestHD())
     {//Traveler only no hard drive
         this.Controls.Remove(panelHD);
         this.Height       -= panelHD.Height;
         this.ActiveControl = this.passTravNewP;
     }
     if (tasklist.TestTrav() && !(tasklist.IsOn(TasksBitField.Flag.travTcfileOldCopy) || oldTravExists))
     {// we have NO old Trav file therefore no old P
         this.panelTrav.Controls.Remove(panelTravOldP);
         this.panelTrav.Height -= panelTravOldP.Height;
         this.panelTrav.Top    += panelTravOldP.Height;
         this.Height           -= panelTravOldP.Height;
     }
     if (tasklist.TestHD() && !(tasklist.IsOn(TasksBitField.Flag.hdTcfileOldRename) || oldHDExists))
     {                                              // we have NO old HD files therefore no old P,S
         this.panelHD.Controls.Remove(panelHDoldP); //no HD old p ie just create new P
         this.Height -= panelHDoldP.Height;
     }
     if (tasklist.TestHD() && !tsdataExists)
     {//no HD old S drive
         this.panelHD.Controls.Remove(panelHDoldS);
         this.Height -= panelHDoldS.Height;
     }
 }
 public PasswordCollectForm(TasksBitField tasklist, bool oldTravExists, bool oldHDExists, bool tsdataExists)
 {
     InitializeComponent();
     // setup form panels and size for passwords needed
     this.ActiveControl = this.passHDnewP;
     if(!tasklist.TestTrav())
     {// No traveler
         this.Height -= panelTrav.Height;  //HD only no traveler
         this.Controls.Remove(panelTrav);
     }
     else if (!tasklist.TestHD())
     {//Traveler only no hard drive
         this.Controls.Remove(panelHD);
         this.Height -= panelHD.Height;
         this.ActiveControl = this.passTravNewP;
     }
     if (tasklist.TestTrav() && !(tasklist.IsOn(TasksBitField.Flag.travTcfileOldCopy)|| oldTravExists))
     {// we have NO old Trav file therefore no old P
         this.panelTrav.Controls.Remove(panelTravOldP);
         this.panelTrav.Height -= panelTravOldP.Height;
         this.panelTrav.Top += panelTravOldP.Height;
         this.Height -= panelTravOldP.Height;
     }
     if (tasklist.TestHD() && !(tasklist.IsOn(TasksBitField.Flag.hdTcfileOldRename) || oldHDExists))
     {// we have NO old HD files therefore no old P,S
     this.panelHD.Controls.Remove(panelHDoldP); //no HD old p ie just create new P
     this.Height -= panelHDoldP.Height;
     }
     if (tasklist.TestHD() && !tsdataExists)
     {//no HD old S drive
         this.panelHD.Controls.Remove(panelHDoldS);
         this.Height -= panelHDoldS.Height;
     }
 }
        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);
        }
Пример #4
0
        public GetTasksHI(TasksBitField tasklistpassed, TrueCryptFile tcFileHDOld, TrueCryptFile tcFileTravOld, string calledArg)
        {
            InitializeComponent();
            newFileSizeMB.Text = defaultTCFileSize.ToString() + " "; //space to offset numbers
            tasklist1 = tasklistpassed;
            tcFileHDOldLoc = tcFileHDOld;
            tcFileTravOldLoc = tcFileTravOld;
            taskChoice1.Text = "Text";
            assem = System.Reflection.Assembly.GetExecutingAssembly();
            System.Reflection.AssemblyName assemName = assem.GetName();
            //this.Text += " Ver " + assemName.Version.ToString();// used to put version into title
            //radioButton2.Enabled = false;

            #region Get data for decisions on hard drive and traveler drive
            //Build list of usb connected drives first so can test against it in tcfileobject instance
            if (calledArg != "format" || assem.Location.Substring(0, 2) != Environment.GetEnvironmentVariable("HOMEDRIVE"))
            {//ie do this if not being called from start tax-aide drive to do a format on the hard drive
                GetUSBDrives(); //returns travusbdrv which is logical drive name and vol label and a combo string tcfile poss to be set here
            }
            //Analyze hard drive situation
            TrueCryptFilesNew.tcFileHDNewPath = Environment.GetEnvironmentVariable("HOMEDRIVE") + "\\" + tcFilename; //sets up new name will be changed next for vista/w7
            // Find out if hard drive tpdata exists
            if (File.Exists(Environment.GetEnvironmentVariable("HOMEDRIVE") + "\\" + tcFilename))
            {
                tcFileHDOldLoc.FileNamePath = Environment.GetEnvironmentVariable("HOMEDRIVE") + "\\" + tcFilename;
                TrueCryptFilesNew.tcFileHDNewPath = Environment.GetEnvironmentVariable("HOMEDRIVE") + "\\" + tcFilename; //set wrongly for vista/w7 here fixed in next clause
            }
            if (DoTasksObj.osVer == 6)
            {
                TrueCryptFilesNew.tcFileHDNewPath = Environment.GetEnvironmentVariable("PUBLIC") + "\\" + tcFilename;
                if (File.Exists(Environment.GetEnvironmentVariable("PUBLIC") + "\\" + tcFilename))
                {
                    tcFileHDOldLoc.FileNamePath = Environment.GetEnvironmentVariable("PUBLIC") + "\\" + tcFilename;
                    TrueCryptFilesNew.tcFileHDNewPath = Environment.GetEnvironmentVariable("PUBLIC") + "\\" + tcFilename;
                }
            }
            //Now analyze usb drive situation
            //for (int i = 0; i < travUSBDrv.Count; i++)
            foreach (DrvInfo drv in travUSBDrv)
            {
                if (File.Exists(drv.drvName + @"\" + tcFilenamesOldTrav[0]))
                {
                    drv.tcFilePoss = drv.drvName + @"\" + tcFilenamesOldTrav[0];
                    travTcFilePossCount++;
                }
                else if (File.Exists(drv.drvName + @"\" + tcFilenamesOldTrav[1]))
                {
                    drv.tcFilePoss = drv.drvName + @"\" + tcFilenamesOldTrav[1];
                    travTcFilePossCount++;
                }
                else if (File.Exists(drv.drvName + @"\" + tcFilenamesOldTrav[2]))
                {
                    drv.tcFilePoss = drv.drvName + @"\" + tcFilenamesOldTrav[2];
                    travTcFilePossCount++;
                }
            }
            Log.WritSection("Trav TC File poss count = " + travTcFilePossCount.ToString() + ", USB Drives count = " + travUSBDrv.Count.ToString());
            #endregion

            #region Decisions to setup initial form
            //1st priority to see if running from an existing installation, if so only thing can do is format. After that priority to flash keys if they are inserted. button 1 is only one that contains requirements for volume size to be filled out button 2 is strictly for software upgrades except for 2 blank travelers
            //if (assem.Location.Contains("TrueCrypt\\Tax-Aide")||assem.Location.Contains("Tax-Aide_Traveler"))
            if (calledArg == "format")
            {//we are running from an existing install probably called from Start_Tax-Aide_drive.exe
                SetFormatClsStartProcess();
            }
            else if (travTcFilePossCount > 0 | travUSBDrv.Count > 0)
            {
                // Check for Traveler failed migration has to occur after have inof on usb flash drives available
                SetButtons4Traveler();
            }
            else
            {//just go straight to install on c drive
                SetButtons4HD();
                taskChoice3.Visible = false;
            }

            #endregion
        }
Пример #5
0
 private int CheckEditBox(RadioButton radioButton, TasksBitField radBut)
 {
     int input; float inputf = 0;
     newFileSizeMB.Text.Trim();
     if (!Int32.TryParse(newFileSizeMB.Text, out input))
     {
         if (gBytes.Checked && Single.TryParse(newFileSizeMB.Text, out inputf))
         {
             input = (int)(inputf * 1000);
         }
         else
         {
             MessageBox.Show("Non Numeric or non Integer Megabyte entry in Volume Size\n\n\t" + newFileSizeMB.Text, DoTasksObj.mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
             newFileSizeMB.Focus();
             return 0;
         }
     }
     if (gBytes.Checked && inputf == 0) { input *= 1000; }
     if (radBut.IsOn(TasksBitField.Flag.travtcFileFormat))
     {//we have traveler so must check sizing
         long oldFSize = 0;
         if (!string.IsNullOrEmpty(tcFileTravOldLoc.FileNamePath)) //ie have old file which is taking up flash room
         {
             oldFSize = tcFileTravOldLoc.size;
         }
         DriveInfo drv = new DriveInfo(travUSBDrv[(int)radioButton.Tag].drvName);
         long maxSize = drv.TotalFreeSpace - 10000000 + oldFSize;
         if (maxSize / 1048576 < input)
         {
             MessageBox.Show("Volume Size is larger that possible on this flash drive\n\t" + input.ToString() + " MBytes\n\nThe Maximum is " + (maxSize / 1048576).ToString() + " MBytes", DoTasksObj.mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
             newFileSizeMB.Text = "";
             newFileSizeMB.Focus();
             return 0;
         }
     }
     if (radBut.IsOn(TasksBitField.Flag.hdTCFileFormat) && radBut.IsOn(TasksBitField.Flag.hdTcfileOldRename))
     {// we have to do HD format check if old files and that size is appropriate
         long totalOldFileSize = tcFileHDOldLoc.size;
         string oldSDrvpath = tcFileHDOldLoc.FileNamePath.Substring(0, tcFileHDOldLoc.FileNamePath.LastIndexOf('\\')) + "\\tsdata.tc";
         if (File.Exists(oldSDrvpath))
         {
             FileInfo f = new FileInfo(oldSDrvpath);
             totalOldFileSize += f.Length;
         }
         totalOldFileSize /= 1048576;
         if (totalOldFileSize > input)
         {
             if (DialogResult.No == MessageBox.Show("Are you sure you meant this Volume size\n" + input.ToString() + "MBytes\n\nThis is less than the size of the existing TrueCrypt file(s) \nwhich is " + totalOldFileSize.ToString() + "MBytes", DoTasksObj.mbCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question))
             {
                 newFileSizeMB.Focus();
                 return 0;
             }
         }
     }
     if (input > 7000)
     {
         if (DialogResult.No == MessageBox.Show("Are you sure you meant this Volume size\n" + input.ToString() + "MB will take a really long time to format", DoTasksObj.mbCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question))
         {
             newFileSizeMB.Focus();
             return 0;
         }
     }
     if (input < 0)
     {
         MessageBox.Show("Negative entry in Volume Size\n\n\t" + newFileSizeMB.Text, DoTasksObj.mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
         newFileSizeMB.Focus();
         return 0;
     }
     if (input < 5)
     {
         if (DialogResult.No == MessageBox.Show("Are you sure you meant this Volume size\n\n\t" + input.ToString() + "MB is really small??", DoTasksObj.mbCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question))
         {
             newFileSizeMB.Focus();
             return 0;
         }
     }
     if (newFileSizeMB.ForeColor == SystemColors.GrayText)
     {
         if (DialogResult.No == MessageBox.Show("There has been no entry in the Volume Size Box. Did you intend to use the default of " + newFileSizeMB.Text + "MBytes?", DoTasksObj.mbCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question))
         {
             newFileSizeMB.Focus();
             return 0;
         }
     }
     if (input == 0) { return 0; }
     return input;
 }
Пример #6
0
        static void Main(string[] args)
        {
            //first check to see if already running
            Regex   myPatt         = new Regex(@"\((.*)\)"); //extract process friendly name from full process
            Process myProc         = Process.GetCurrentProcess();
            Match   myMatch        = myPatt.Match(myProc.ToString());
            String  myProcFriendly = myMatch.Value.Substring(1, myMatch.Length - 2);//get rid of parentheses

            Process[] myProcArray = Process.GetProcessesByName(myProcFriendly);
            if (myProcArray.GetLength(0) > 1)
            {
                MessageBox.Show("This program is already running", DoTasksObj.mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Environment.Exit(1);
            }
            System.Security.Principal.WindowsIdentity  me   = System.Security.Principal.WindowsIdentity.GetCurrent();
            System.Security.Principal.WindowsPrincipal prin = new System.Security.Principal.WindowsPrincipal(me);
            if (!prin.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
            {//we are not an administrator user need to exit
                MessageBox.Show("This program must run under a Windows Administrator User", DoTasksObj.mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Environment.Exit(1);
            }
            Log tcFileResizerLog = new Log(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\TA Utility 4TC TY11.log");

            if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\TA Utility 4TC TY10.log"))
            {
                File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\TA Utility 4TC TY10.log");
            }
            string        hostUpgOrFormatCall;
            TrueCryptFile tcFileHDOld   = new TrueCryptFile(); //setup object to hold original file information name path for Hard Drive
            TrueCryptFile tcFileTravOld = new TrueCryptFile(); //setup object to hold original file information name path for Traveler
            TasksBitField tasklist      = new TasksBitField(); //setup object to hold flags of things to be done1
            DoTasksObj    TcSoftware    = new DoTasksObj();    //setup object that has all methods to actually do stuff

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (args.Length == 0)
            {
                hostUpgOrFormatCall = "";
            }
            else
            {
                hostUpgOrFormatCall = args[0];
            }
            //hostUpgOrFormatCall = "hostupg"; //for debug purposes format hostupg May also need a change in SetFormatClsStartProcess for debug purposes
            GetTasksHI InfoFromUser = new GetTasksHI(tasklist, tcFileHDOld, tcFileTravOld, hostUpgOrFormatCall);

            if (hostUpgOrFormatCall != "hostupg")
            {//user usage or call to format so need to actually show dialog box for interaction
                InfoFromUser.ShowDialog();
                if (InfoFromUser.DialogResult != DialogResult.OK)
                {
                    Environment.Exit(1);
                }
            }
            else
            {                                     //have to upgrade host due to traveler insertion called from autoit start script
                Log.WritWTime("Host upgrade requested by parameter call");
                InfoFromUser.Check4HostUpgrade(); // sets up necessary flags for upgrade
                if (TrueCryptFilesNew.tcFileHDNewSize > 0)
                {
                    Log.WritWTime("Host tpdata.tc to be upgraded, new size = " + TrueCryptFilesNew.tcFileHDNewSize.ToString() + "MB");
                }
            }
            Log.WritSection(string.Format("TaskList = 0x{0:X}", tasklist.taskList));
            tasklist.LogTasks();
            //Next  TC software object does tasklist
            //Environment.Exit(1);  //used to stop program here at the point where can examine Log but before and changes are done
            TcSoftware.DoTasks(tasklist, tcFileHDOld, tcFileTravOld);
        }
        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);
        }
 static void Main(string[] args)
 {
     //first check to see if already running
     Regex myPatt = new Regex(@"\((.*)\)"); //extract process friendly name from full process
     Process myProc = Process.GetCurrentProcess();
     Match myMatch = myPatt.Match(myProc.ToString());
     String myProcFriendly = myMatch.Value.Substring(1, myMatch.Length - 2);//get rid of parentheses
     Process[] myProcArray = Process.GetProcessesByName(myProcFriendly);
     if (myProcArray.GetLength(0) > 1)
     {
         MessageBox.Show("This program is already running", DoTasksObj.mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         Environment.Exit(1);
     }
     System.Security.Principal.WindowsIdentity me = System.Security.Principal.WindowsIdentity.GetCurrent();
     System.Security.Principal.WindowsPrincipal prin = new System.Security.Principal.WindowsPrincipal(me);
     if (!prin.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
     {//we are not an administrator user need to exit
         MessageBox.Show("This program must run under a Windows Administrator User", DoTasksObj.mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         Environment.Exit(1);
     }
     Log tcFileResizerLog = new Log(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\TA Utility 4TC TY11.log");
     if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\TA Utility 4TC TY10.log"))
         File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\TA Utility 4TC TY10.log");
     string hostUpgOrFormatCall;
     TrueCryptFile tcFileHDOld = new TrueCryptFile(); //setup object to hold original file information name path for Hard Drive
     TrueCryptFile tcFileTravOld = new TrueCryptFile();  //setup object to hold original file information name path for Traveler
     TasksBitField tasklist = new TasksBitField(); //setup object to hold flags of things to be done1
     DoTasksObj TcSoftware = new DoTasksObj();//setup object that has all methods to actually do stuff
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     if (args.Length == 0)
     {
         hostUpgOrFormatCall = "";
     }
     else
     {
         hostUpgOrFormatCall = args[0];
     }
     //hostUpgOrFormatCall = "hostupg"; //for debug purposes format hostupg May also need a change in SetFormatClsStartProcess for debug purposes
     GetTasksHI InfoFromUser = new GetTasksHI(tasklist, tcFileHDOld, tcFileTravOld,hostUpgOrFormatCall);
     if (hostUpgOrFormatCall != "hostupg")
     {//user usage or call to format so need to actually show dialog box for interaction
         InfoFromUser.ShowDialog();
         if (InfoFromUser.DialogResult != DialogResult.OK)
         {
             Environment.Exit(1);
         }
     }
     else
     {//have to upgrade host due to traveler insertion called from autoit start script
         Log.WritWTime("Host upgrade requested by parameter call");
         InfoFromUser.Check4HostUpgrade(); // sets up necessary flags for upgrade
         if (TrueCryptFilesNew.tcFileHDNewSize > 0)
         {
             Log.WritWTime("Host tpdata.tc to be upgraded, new size = " + TrueCryptFilesNew.tcFileHDNewSize.ToString() + "MB");
         }
     }
     Log.WritSection(string.Format("TaskList = 0x{0:X}", tasklist.taskList));
     tasklist.LogTasks();
     //Next  TC software object does tasklist
     //Environment.Exit(1);  //used to stop program here at the point where can examine Log but before and changes are done
     TcSoftware.DoTasks(tasklist,tcFileHDOld,tcFileTravOld);
 }