/// <summary>
        /// Creates a profile related to the default firefox profile
        /// </summary>
        public FirefoxProfile()
        {
            // find it!

            FirefoxProfileInfo profile = FirefoxProfileInfo.FindPrimaryProfile();


            if (profile == null)
            {
                throw new Exception("Could not find a Firefox profile");
            }
            ProfilePath = profile.AbsolutePath;
        }
        private void buttonFindProfiles_Click(object sender, EventArgs e)
        {

            DialogResult result = MessageBox.Show(
                "Yes - If you wish to load profiles via the profiles ini file." + Environment.NewLine +
                "No  - To directly select a profiles folder.",
                "Load Profiles ini file?",
                MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);


            if (result == DialogResult.Yes)
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog();

                openFileDialog1.Title = "Select a Firefox Profiles.ini file";
                openFileDialog1.Filter = "INI files (*.ini)|*.ini|All files (*.*)|*.*";
                openFileDialog1.FilterIndex = 1;
                //   openFileDialog1.RestoreDirectory = true;

                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    List<FirefoxProfileInfo> list = (List<FirefoxProfileInfo>)this.comboBoxProfile.DataSource;
                    FirefoxProfileInfo.FindFirefoxProfileInfosFromIniFile(openFileDialog1.FileName, list);

                    // get it to refresh!
                    this.comboBoxProfile.DataSource = null;
                    this.comboBoxProfile.DataSource = list;
                }
            }

            if (result == DialogResult.No)
            {
                FolderBrowserDialog openFolderDialog1 = new FolderBrowserDialog();

                openFolderDialog1.Description = "Select a Firefox Profile folder";
                openFolderDialog1.ShowNewFolderButton = false;


                if (openFolderDialog1.ShowDialog() == DialogResult.OK)
                {

                    List<FirefoxProfileInfo> list = (List<FirefoxProfileInfo>)this.comboBoxProfile.DataSource;
                    FirefoxProfileInfo profile = new FirefoxProfileInfo();

                    profile.Name = openFolderDialog1.SelectedPath.Substring(openFolderDialog1.SelectedPath.LastIndexOf(@"\") + 1);
                    profile.Path = openFolderDialog1.SelectedPath;
                    profile.Default = false;
                    profile.IsRelative = false;

                    list.Add(profile);

                    // get it to refresh!
                    this.comboBoxProfile.DataSource = null;
                    this.comboBoxProfile.DataSource = list;
                }
            }
        }
		/// <summary>
		/// Create a profile based on a profile info object
		/// </summary>
		/// <param name="profile"></param>
		public FirefoxProfile(FirefoxProfileInfo profile)
		{
			ProfilePath = profile.AbsolutePath;
		}
 /// <summary>
 /// Create a profile based on a profile info object
 /// </summary>
 /// <param name="profile"></param>
 public FirefoxProfile(FirefoxProfileInfo profile)
 {
     ProfilePath = profile.AbsolutePath;
 }
        public static void FindFirefoxProfileInfosFromIniFile(string profilesIni, List <FirefoxProfileInfo> profiles)
        {
            // searcvh the profile for a profile entry that contains "Default=1"
            if (File.Exists(profilesIni))
            {
                KeePassUtilities.LogMessage("File exists at " + profilesIni);

                StreamReader reader = File.OpenText(profilesIni);

                try
                {
                    FirefoxProfileInfo profile = null;

                    string line = reader.ReadLine();
                    while (line != null)
                    {
                        string lowerLine = line.ToLower().Replace(" ", "");
                        if (lowerLine.StartsWith("["))                         // new section
                        {
                            if (lowerLine.StartsWith("[profile"))              // new section
                            {
                                profile = new FirefoxProfileInfo();

                                profile.Code = line.Trim().TrimStart('[').TrimEnd(']');

                                profile.BasePath = profilesIni.Substring(0, profilesIni.LastIndexOf("\\"));

                                profiles.Add(profile);
                            }
                            else
                            {
                                profile = null;
                            }
                        }

                        if (profile != null)
                        {
                            if (lowerLine.StartsWith("name="))                             // this is the default profile
                            {
                                profile.Name = line.Substring(5);
                            }

                            if (lowerLine.StartsWith("path="))                             // this is the default profile
                            {
                                profile.Path = line.Substring(5);
                            }

                            if (lowerLine == "default=1")                             // this is the default profile
                            {
                                profile.Default = true;
                            }

                            if (lowerLine == "isrelative=1")                             // this is the default profile
                            {
                                profile.IsRelative = true;
                            }

                            if (lowerLine == "isrelative=0") // this is the default profile
                            {
                                profile.IsRelative = false;
                            }
                        }

                        line = reader.ReadLine();
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
            else
            {
                KeePassUtilities.LogMessage("File does not exist at " + profilesIni);
            }
        }
        public static void FindFirefoxProfileInfosFromIniFile(string profilesIni, List<FirefoxProfileInfo> profiles)
        {

			// searcvh the profile for a profile entry that contains "Default=1"
			if (File.Exists(profilesIni))
			{
				KeePassUtilities.LogMessage("File exists at " + profilesIni);

				StreamReader reader = File.OpenText(profilesIni);

				try
				{

					FirefoxProfileInfo profile = null;

					string line = reader.ReadLine();
					while (line != null)
					{
						string lowerLine = line.ToLower().Replace(" ", "");
						if (lowerLine.StartsWith("[")) // new section
						{
							if (lowerLine.StartsWith("[profile")) // new section
							{
								profile = new FirefoxProfileInfo();

								profile.Code = line.Trim().TrimStart('[').TrimEnd(']');

                                profile.BasePath = profilesIni.Substring(0,profilesIni.LastIndexOf("\\"));

								profiles.Add(profile);
							}
							else
								profile = null;
						}

						if (profile != null)
						{
							if (lowerLine.StartsWith("name=")) // this is the default profile
								profile.Name = line.Substring(5);

							if (lowerLine.StartsWith("path=")) // this is the default profile
								profile.Path = line.Substring(5);

							if (lowerLine == "default=1") // this is the default profile
								profile.Default = true;

							if (lowerLine == "isrelative=1") // this is the default profile
								profile.IsRelative = true;

                            if (lowerLine == "isrelative=0") // this is the default profile
                                profile.IsRelative = false;
						}

						line = reader.ReadLine();
					}
				}
				finally
				{
					reader.Close();
				}
			}
			else
				KeePassUtilities.LogMessage("File does not exist at " + profilesIni);
		}