Represents the executable file for Firefox.
Ejemplo n.º 1
0
        private static string LocateFirefoxBinaryFromPlatform()
        {
            string text = string.Empty;

            if (Platform.CurrentPlatform.IsPlatformType(PlatformType.Windows))
            {
                string      name        = "SOFTWARE\\Mozilla\\Mozilla Firefox";
                RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(name);
                if (registryKey == null)
                {
                    registryKey = Registry.CurrentUser.OpenSubKey(name);
                }
                if (registryKey != null)
                {
                    text = Executable.GetExecutablePathUsingRegistry(registryKey);
                }
                else
                {
                    string[] defaultInstallLocations = new string[]
                    {
                        Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Mozilla Firefox"),
                        Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + " (x86)", "Mozilla Firefox")
                    };
                    text = Executable.GetExecutablePathUsingDefaultInstallLocations(defaultInstallLocations, "Firefox.exe");
                }
            }
            else
            {
                string[] defaultInstallLocations2 = new string[]
                {
                    "/Applications/Firefox.app/Contents/MacOS",
                    string.Format(CultureInfo.InvariantCulture, "/Users/{0}/Applications/Firefox.app/Contents/MacOS", new object[]
                    {
                        Environment.UserName
                    })
                };
                text = Executable.GetExecutablePathUsingDefaultInstallLocations(defaultInstallLocations2, "firefox-bin");
                if (string.IsNullOrEmpty(text))
                {
                    using (Process process = new Process())
                    {
                        process.StartInfo.FileName               = "which";
                        process.StartInfo.Arguments              = "firefox";
                        process.StartInfo.CreateNoWindow         = true;
                        process.StartInfo.RedirectStandardOutput = true;
                        process.StartInfo.UseShellExecute        = false;
                        process.Start();
                        process.WaitForExit();
                        text = process.StandardOutput.ReadToEnd().Trim();
                    }
                }
            }
            if (text != null && File.Exists(text))
            {
                return(text);
            }
            return(Executable.FindBinary(new string[]
            {
                "firefox3",
                "firefox"
            }));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FirefoxBinary"/> class located at a specific file location.
 /// </summary>
 /// <param name="pathToFirefoxBinary">Full path and file name to the Firefox executable.</param>
 public FirefoxBinary(string pathToFirefoxBinary)
 {
     this.executable = new Executable(pathToFirefoxBinary);
 }