public GeckoAppInfo AddGeckoPath(string path) { GeckoAppInfo gai = AddGeckoPathImpl(path); SortGeckos(); return(gai); }
GeckoAppInfo AddGeckoPathImpl(string path) { path = Path.GetFullPath(path.Trim()); foreach (var cgai in geckos) { if (String.Compare(cgai.GeckoPath, path, true) == 0) { return(cgai); } } GeckoAppInfo gai = new GeckoAppInfo(path); geckos.Add(gai); return(gai); }
static int GeckosComparer(GeckoAppInfo gai1, GeckoAppInfo gai2) { int d = -gai1.IsGeckoValid.CompareTo(gai2.IsGeckoValid); if (d != 0) { return(d); } d = -gai1.IsVersionSupported.CompareTo(gai2.IsVersionSupported); if (d != 0) { return(d); } d = -gai1.GeckoReleaseStatus.CompareTo(gai2.GeckoReleaseStatus); if (d != 0) { return(d); } d = -gai1.GeckoVersion.CompareTo(gai2.GeckoVersion); return(d); }
private void WalkRegistryKey(RegistryKeyChain key) { try { string path = null, version = null, appname = null; path = key.Value("Install Directory"); if (path == null) { string exe = key.Value("PathToExe"); if (exe != null) { path = Path.GetDirectoryName(exe.Trim()); } } if (path != null) { path = Path.GetFullPath(path.Trim()); } if (path != null && IsGeckoPathKnown(path)) { path = null; } // try to detect gecko version from this or parent key if (path != null) { version = key.Value("GeckoVer"); appname = key.RootName; if (version == null && key.Is("bin") && key.Parent != null) { version = key.Parent.Value("GeckoVer"); appname = key.Parent.Name; } if (version == null && key.Is("Main") && key.Parent != null && key.Parent.Parent != null) { version = key.Parent.Parent.Value(null); appname = String.Format("{0} {1}", key.Parent.Parent.Name, key.Parent.Name); } } if (path != null) { GeckoAppInfo gai = new GeckoAppInfo(path, version, appname) { IsAutoDiscovered = true }; geckos.Add(gai); } } catch {} string[] skeys = key.Subkeys; Array.ForEach(skeys, sk => { try { using (RegistryKeyChain rsk = key.Subkey(sk)) { if (rsk != null) { WalkRegistryKey(rsk); } } } catch { } }); }
/// <summary> /// Initializes XPCOM using the specified GeckoAppInfo. /// </summary> public static void Initialize(GeckoAppInfo geckoInfo) { if (_IsInitialized) { return; } string folder = geckoInfo.GeckoPath; string binDirectory = (folder != Application.StartupPath) ? folder : null; string xpcomPath = Path.Combine(folder, "xpcom.dll"); if (Debugger.IsAttached) { // make sure this DLL is there if (!File.Exists(xpcomPath)) { if (MessageBox.Show(String.Format("Couldn't find XULRunner in '{0}'. Call Xpcom.Initialize() in your application startup code and specify the directory where XULRunner is installed.{1}{1}If you do not have XULRunner installed, click Yes to open the download page. Otherwise, click No, and update your application startup code.", folder, Environment.NewLine), "XULRunner Not Found", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes) { Process.Start("http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/"); } Environment.Exit(0); } } if (binDirectory != null) { Environment.SetEnvironmentVariable("path", String.Format("{0};{1}", Environment.GetEnvironmentVariable("path"), binDirectory), EnvironmentVariableTarget.Process); } object mreAppDir = null; if (binDirectory != null) { using (nsACString str = new nsACString(Path.GetFullPath(binDirectory))) if (NS_NewNativeLocalFile(str, true, out mreAppDir) != 0) { throw new Exception("Failed on NS_NewNativeLocalFile"); } } // temporarily change the current directory so NS_InitEmbedding can find all the DLLs it needs String oldCurrent = Environment.CurrentDirectory; Environment.CurrentDirectory = folder; IntPtr serviceManagerPtr; //int res = NS_InitXPCOM2(out serviceManagerPtr, mreAppDir, new DirectoryServiceProvider()); int res = NS_InitXPCOM2(out serviceManagerPtr, mreAppDir, null); // change back Environment.CurrentDirectory = oldCurrent; if (res != 0) { throw new Exception("Failed on NS_InitXPCOM2"); } // ok, we initialized xpcom, most like we will work, so we need gecko version from now on geckoAppInfo = geckoInfo; ServiceManager = (nsIServiceManager)Marshal.GetObjectForIUnknown(serviceManagerPtr); // get some global objects we will need later NS_GetComponentManager(out ComponentManager); NS_GetComponentRegistrar(out ComponentRegistrar); // a bug in Mozilla 1.8 (https://bugzilla.mozilla.org/show_bug.cgi?id=309877) causes the PSM to // crash when loading a site over HTTPS. in order to work around this bug, we must register an nsIDirectoryServiceProvider // which will provide the location of a profile nsIDirectoryService directoryService = GetService <nsIDirectoryService>("@mozilla.org/file/directory_service;1"); directoryService.RegisterProvider(new ProfileProvider()); XULAppInfo.Initialize(); _IsInitialized = true; }
/// <summary> /// Initializes XPCOM with option to use any available Gecko installed (like Firefox). /// <param name="geckoAutoSearch"></param> /// </summary> public static void Initialize(bool geckoAutoSearch) { if (_IsInitialized) { return; } if (geckoAutoSearch) { GeckoAppInfo gai = null; GeckoAppDiscovery gad = null; DirectoryInfo appDirInfo = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); DirectoryInfo[] xulrunnerDirs = appDirInfo.GetDirectories("xulrunner*"); if (xulrunnerDirs != null && xulrunnerDirs.Length > 0) { List <String> xulrunnerPaths = new List <String>(); Array.ForEach(xulrunnerDirs, dirInfo => { if (dirInfo.Exists) { xulrunnerPaths.Add(dirInfo.FullName); } }); if (xulrunnerPaths.Count > 0) { gad = new GeckoAppDiscovery(xulrunnerPaths.ToArray()); } } if (gad == null) { gad = new GeckoAppDiscovery(); } if (gad.Geckos != null && gad.Geckos.Count > 0) { foreach (GeckoAppInfo appInfo in gad.Geckos) { if (!appInfo.IsGeckoValid) { continue; } gai = appInfo; if (LoadWin32Library(Path.Combine(appInfo.GeckoPath, "mozcrt19.dll")) != IntPtr.Zero) { if (LoadWin32Library(Path.Combine(appInfo.GeckoPath, "AccessibleMarshal.dll")) != IntPtr.Zero) { if (LoadWin32Library(Path.Combine(appInfo.GeckoPath, "nspr4.dll")) != IntPtr.Zero) { if (LoadWin32Library(Path.Combine(appInfo.GeckoPath, "plc4.dll")) != IntPtr.Zero) { if (LoadWin32Library(Path.Combine(appInfo.GeckoPath, "plds4.dll")) != IntPtr.Zero) { if (LoadWin32Library(Path.Combine(appInfo.GeckoPath, "nssutil3.dll")) != IntPtr.Zero) { if (LoadWin32Library(Path.Combine(appInfo.GeckoPath, "nss3.dll")) != IntPtr.Zero) { if (LoadWin32Library(Path.Combine(appInfo.GeckoPath, "ssl3.dll")) != IntPtr.Zero) { if (LoadWin32Library(Path.Combine(appInfo.GeckoPath, "smime3.dll")) != IntPtr.Zero) { if (LoadWin32Library(Path.Combine(appInfo.GeckoPath, "js3250.dll")) != IntPtr.Zero) { if (LoadWin32Library(Path.Combine(appInfo.GeckoPath, "sqlite3.dll")) != IntPtr.Zero) { if (LoadWin32Library(Path.Combine(appInfo.GeckoPath, "softokn3.dll")) != IntPtr.Zero) { if (LoadWin32Library(Path.Combine(appInfo.GeckoPath, "freebl3.dll")) != IntPtr.Zero) { if (LoadWin32Library(Path.Combine(appInfo.GeckoPath, "nssdbm3.dll")) != IntPtr.Zero) { if (LoadWin32Library(Path.Combine(appInfo.GeckoPath, "nssckbi.dll")) != IntPtr.Zero) { bool bLoad = false; if (File.Exists(Path.Combine(appInfo.GeckoPath, "xul.dll"))) { bLoad = (LoadWin32Library(Path.Combine(appInfo.GeckoPath, "xul.dll")) != IntPtr.Zero); } else if (File.Exists(Path.Combine(appInfo.GeckoPath, "xpcom_core.dll"))) { bLoad = (LoadWin32Library(Path.Combine(appInfo.GeckoPath, "xpcom_core.dll")) != IntPtr.Zero); } if (bLoad && LoadWin32Library(Path.Combine(appInfo.GeckoPath, "xpcom.dll")) != IntPtr.Zero) { Initialize(gai); return; } } } } } } } } } } } } } } } } } } throw new Exception(String.Format("Please install Mozilla Firefox 3.6 or download xulrunner from:{0}http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/ {0}and unzip into the \"{1}\" application directory.", Environment.NewLine, Application.ProductName)); } Initialize(new GeckoAppInfo()); }