BrowserSelector.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Azylee.Core.DataUtils.StringUtils;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. namespace Azylee.Core.WindowsUtils.BrowserUtils
  8. {
  9. /// <summary>
  10. /// 浏览器选择器
  11. /// </summary>
  12. public class BrowserSelector
  13. {
  14. /// <summary>
  15. /// 现代浏览器
  16. /// </summary>
  17. /// <param name="browser"></param>
  18. /// <returns></returns>
  19. public static bool ModernBrowser(out string browser)
  20. {
  21. browser = "";
  22. string edge_86 = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";
  23. string chrome = @"C:\Program Files\Google\Chrome\Application\chrome.exe";
  24. string chrome_86 = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
  25. string chrome_app = @"C:\Users\Administrator\AppData\Local\Google\Chrome\Application\chrome.exe";
  26. string firefox = @"C:\Program Files\Mozilla Firefox\firefox.exe";
  27. string firefox_86 = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
  28. if (File.Exists(edge_86)) browser = edge_86;
  29. else if (File.Exists(chrome)) browser = chrome;
  30. else if (File.Exists(chrome_86)) browser = chrome_86;
  31. else if (File.Exists(chrome_app)) browser = chrome_app;
  32. else if (File.Exists(firefox)) browser = firefox;
  33. else if (File.Exists(firefox_86)) browser = firefox_86;
  34. if (Str.Ok(browser)) return true;
  35. return false;
  36. }
  37. /// <summary>
  38. /// 石器时代浏览器IE
  39. /// </summary>
  40. /// <param name="browser"></param>
  41. /// <returns></returns>
  42. public static bool StoneAgeIE(out string browser)
  43. {
  44. browser = "";
  45. string ie = @"C:\Program Files\internet explorer\iexplore.exe";
  46. string ie_86 = @"C:\Program Files (x86)\Internet Explorer\iexplore.exe";
  47. if (File.Exists(ie)) browser = ie;
  48. else if (File.Exists(ie_86)) browser = ie_86;
  49. if (Str.Ok(browser)) return true;
  50. return false;
  51. }
  52. }
  53. }