Ejemplo n.º 1
0
        internal TC_Data_File(ProgramData thisProg, TrueCryptSWObj tcswobjpassed)
        {
            thisProginst = thisProg;
            tcSWobj      = tcswobjpassed;
            if (Directory.Exists(tCryptDriveName))
            {
                CloseTcFile(); //attempt a file close
                if (Directory.Exists(tCryptDriveName))
                {              // test again after trial close
                    MessageBox.Show("The P Drive exists. Please close it and restart this program", thisProginst.mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Environment.Exit(1);
                }
            }
            if (!Environment.GetEnvironmentVariable("HomeDrive").StartsWith(thisProginst.drvLetter, StringComparison.CurrentCultureIgnoreCase) | Environment.OSVersion.Version.Major < 6)
            {//traveler or xp
                tpdataPath = thisProginst.drvLetter + ":\\" + dataFileName;
            }
            else
            {//not traveler, not xp
                tpdataPath = Environment.GetEnvironmentVariable("Public") + "\\" + dataFileName;
            }
            //Find out if we have errors conditions
            // First see if migration registry key is set
            if (thisProginst.removable == false)
            {
                migration = (string)Microsoft.Win32.Registry.GetValue(regKeyName, "TFTAOld", "");
            }
            else
            {
                migration = (string)Microsoft.Win32.Registry.GetValue(regKeyName, "TFTATravOld", "");
            }
            if (migration == "")
            {
                if (File.Exists(tpdataPath))
                {
                    return; //non error path is return here error path below here
                }

                //ERROR PATH BELOW HERE
                #region Deal with Migration errors
                else
                {
                    DialogResult mbResult = MessageBox.Show("The Tax-Aide TrueCypt data file does not exist, Create it?", thisProginst.mbCaption, MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                    if (mbResult == DialogResult.OK)
                    {
                        StartTAUtility("format"); // go create the file Use Format argument
                    }
                    else
                    {
                        Environment.Exit(1);
                    }
                }
            }
            // below this point have a registry entry when we should not have one means something went wrong in migration
            string migrationS = string.Empty;
            if (migration.Contains(","))
            {                                                          // we have old P & old S
                migrationS = migration.Substring(migration.IndexOf(",") + 1);
                migration  = migration.Remove(migration.IndexOf(",")); // gets the P string
            }
            if (File.Exists(migration))
            {//We have reg entry plus old P
                if (File.Exists(tpdataPath))
                {
                    migrationFileActionForm migForm = new migrationFileActionForm();
                    if (thisProg.removable == true)
                    {//Setup migration form for traveler
                        DriveInfo drv     = new DriveInfo(thisProginst.drvLetter);
                        string    drvName = thisProginst.drvLetter + " (" + drv.VolumeLabel + ") ";
                        migForm.delInitialExplain.Text  = "A TrueCrypt TPDATA file (the P drive) exists on the Traveler Drive\n" + drvName + "In addition an old Traveler TrueCrypt file exists \non the Hard Drive.This looks like a failed migration of user data from \nan old Traveler based Truecrypt file to a new Traveler TrueCrypt file.";
                        migForm.delNewPStartTAutil.Text = "Delete the current traveler TPDATA file, Start the Tax-Aide Utility \nto create a new Traveler TPDATA file and complete the migration \nthat failed. Effectively start the whole process over.";
                        migForm.delOldTCFiles.Text      = "Delete the old Traveler TrueCrypt file, Assumes data migration is \ndone correctly, and the old file is not needed. Warning - it will be \npermanently deleted. Then open the traveler file as the P drive.";
                        migForm.radBtGrpBox.Text       += " for " + drvName;
                    }
                    DialogResult mbResult = migForm.ShowDialog();
                    if (mbResult == DialogResult.OK)
                    {
                        return; // have to simply open p drive ignore state of old stuff
                    }
                    else if (mbResult == DialogResult.Retry)
                    {//Delete new tp File and start over
                        File.Delete(tpdataPath);
                        StartTAUtility("");
                    }
                    else if (mbResult == DialogResult.Yes)
                    {// delete old TC file(s) and open P drive
                        File.Delete(migration);
                        if (migrationS != string.Empty)
                        {
                            File.Delete(migrationS);
                        }
                        DeleteMigrationRegEntries();
                        return;
                    }
                }
                else
                {// have registry entry and old tpdataa no new tpdata
                    DialogResult mbResult = MessageBox.Show("An old TrueCrypt TPDATA file exists, with a migration flag set.\rNo new TrueCrypt TPDATA file exists, the Tax-Aide utility will be started to create a new data file, migration will happen automatically?", thisProginst.mbCaption, MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                    if (mbResult == DialogResult.OK)
                    {
                        StartTAUtility("");
                    }
                    else
                    {
                        Environment.Exit(1);
                    }
                }
            }
            else
            {// reg entry no old file
                if (File.Exists(tpdataPath))
                {
                    DialogResult mbResult = MessageBox.Show("There is a migration data flag set, but no old TPDATA file, \r\nDelete the Migration Flag?", thisProginst.mbCaption, MessageBoxButtons.OKCancel, MessageBoxIcon.Error); //Delete reg entries and return on OK, exit on cancel
                    if (mbResult == DialogResult.OK)
                    {
                        DeleteMigrationRegEntries();
                        return;
                    }
                    else
                    {
                        Environment.Exit(1);
                    }
                }
                else
                {
                    DialogResult mbResult = MessageBox.Show("There is a migration data flag set, but no old TPDATA file, \r\nDelete the Migration Flag?", thisProginst.mbCaption, MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                    if (mbResult == DialogResult.OK)
                    {
                        DeleteMigrationRegEntries();
                        StartTAUtility("");
                    }
                    else
                    {
                        Environment.Exit(1);
                    }
                }
            }
            #endregion
        }
Ejemplo n.º 2
0
        internal TC_Data_File(ProgramData thisProg,TrueCryptSWObj tcswobjpassed)
        {
            thisProginst = thisProg;
            tcSWobj = tcswobjpassed;
            if (Directory.Exists(tCryptDriveName))
            {
                CloseTcFile(); //attempt a file close
                if (Directory.Exists(tCryptDriveName))
                {// test again after trial close
                    MessageBox.Show("The P Drive exists. Please close it and restart this program", thisProginst.mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Environment.Exit(1);
                }
            }
            if (!Environment.GetEnvironmentVariable("HomeDrive").StartsWith(thisProginst.drvLetter, StringComparison.CurrentCultureIgnoreCase) | Environment.OSVersion.Version.Major < 6)
            {//traveler or xp
                tpdataPath = thisProginst.drvLetter + ":\\" + dataFileName;
            }
            else
            {//not traveler, not xp
                tpdataPath = Environment.GetEnvironmentVariable("Public") + "\\" + dataFileName;
            }
            //Find out if we have errors conditions
            // First see if migration registry key is set
            if (thisProginst.removable == false)
            {
                migration = (string)Microsoft.Win32.Registry.GetValue(regKeyName, "TFTAOld", "");
            }
            else
            {
                migration = (string)Microsoft.Win32.Registry.GetValue(regKeyName, "TFTATravOld", "");
            }
            if (migration == "")
            {
                if (File.Exists(tpdataPath))
                {
                    return; //non error path is return here error path below here
                }

            //ERROR PATH BELOW HERE
            #region Deal with Migration errors
                        else
                {
                    DialogResult mbResult = MessageBox.Show("The Tax-Aide TrueCypt data file does not exist, Create it?", thisProginst.mbCaption, MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                    if (mbResult == DialogResult.OK)
                    {
                        StartTAUtility("format"); // go create the file Use Format argument
                    }
                    else
                    {
                        Environment.Exit(1);
                    }
                }
            }
            // below this point have a registry entry when we should not have one means something went wrong in migration
            string migrationS = string.Empty;
            if (migration.Contains(","))
            {// we have old P & old S
                migrationS = migration.Substring(migration.IndexOf(",") + 1);
                migration = migration.Remove(migration.IndexOf(",")); // gets the P string
            }
            if (File.Exists(migration))
            {//We have reg entry plus old P
                if (File.Exists(tpdataPath))
                {
                    migrationFileActionForm migForm = new migrationFileActionForm();
                    if (thisProg.removable == true)
                    {//Setup migration form for traveler
                        DriveInfo drv = new DriveInfo(thisProginst.drvLetter);
                        string drvName = thisProginst.drvLetter + " (" + drv.VolumeLabel + ") ";
                        migForm.delInitialExplain.Text = "A TrueCrypt TPDATA file (the P drive) exists on the Traveler Drive\n" + drvName + "In addition an old Traveler TrueCrypt file exists \non the Hard Drive.This looks like a failed migration of user data from \nan old Traveler based Truecrypt file to a new Traveler TrueCrypt file.";
                        migForm.delNewPStartTAutil.Text = "Delete the current traveler TPDATA file, Start the Tax-Aide Utility \nto create a new Traveler TPDATA file and complete the migration \nthat failed. Effectively start the whole process over.";
                        migForm.delOldTCFiles.Text = "Delete the old Traveler TrueCrypt file, Assumes data migration is \ndone correctly, and the old file is not needed. Warning - it will be \npermanently deleted. Then open the traveler file as the P drive.";
                        migForm.radBtGrpBox.Text += " for " + drvName;
                    }
                    DialogResult mbResult = migForm.ShowDialog();
                    if (mbResult == DialogResult.OK)
                        return; // have to simply open p drive ignore state of old stuff
                    else if (mbResult == DialogResult.Retry)
                    {//Delete new tp File and start over
                        File.Delete(tpdataPath);
                        StartTAUtility("");
                    }
                    else if (mbResult == DialogResult.Yes)
                    {// delete old TC file(s) and open P drive
                        File.Delete(migration);
                        if (migrationS != string.Empty)
                            File.Delete(migrationS);
                        DeleteMigrationRegEntries();
                        return;
                    }
                }
                else
                {// have registry entry and old tpdataa no new tpdata
                    DialogResult mbResult = MessageBox.Show("An old TrueCrypt TPDATA file exists, with a migration flag set.\rNo new TrueCrypt TPDATA file exists, the Tax-Aide utility will be started to create a new data file, migration will happen automatically?", thisProginst.mbCaption, MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                    if (mbResult == DialogResult.OK)
                    {
                        StartTAUtility("");
                    }
                    else
                    {
                        Environment.Exit(1);
                    }
                }
            }
            else
            {// reg entry no old file
                if (File.Exists(tpdataPath))
                {
                    DialogResult mbResult = MessageBox.Show("There is a migration data flag set, but no old TPDATA file, \r\nDelete the Migration Flag?", thisProginst.mbCaption, MessageBoxButtons.OKCancel, MessageBoxIcon.Error); //Delete reg entries and return on OK, exit on cancel
                    if (mbResult == DialogResult.OK)
                    {
                        DeleteMigrationRegEntries();
                        return;
                    }
                    else
                        Environment.Exit(1);
                }
                else
                {
                    DialogResult mbResult = MessageBox.Show("There is a migration data flag set, but no old TPDATA file, \r\nDelete the Migration Flag?", thisProginst.mbCaption, MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                    if (mbResult == DialogResult.OK)
                    {
                        DeleteMigrationRegEntries();
                        StartTAUtility("");
                    }
                    else
                        Environment.Exit(1);
                }
            }
            #endregion
        }