FileLocations.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using System;
  2. using System.IO;
  3. using UnityEngine;
  4. #if UNITY_EDITOR
  5. using UnityEditor;
  6. #endif
  7. namespace ZenFulcrum.EmbeddedBrowser {
  8. public static class FileLocations {
  9. public const string SlaveExecutable = "ZFGameBrowser";
  10. private static CEFDirs _dirs;
  11. public static CEFDirs Dirs {
  12. get { return _dirs ?? (_dirs = GetCEFDirs()); }
  13. }
  14. public class CEFDirs {
  15. /** Where to find cef.pak, et al */
  16. public string resourcesPath;
  17. /** Where to find .dll, .so, natives_blob.bin, etc */
  18. public string binariesPath;
  19. /** Where to find en-US.pak et al */
  20. public string localesPath;
  21. /** The executable to run for browser processes. */
  22. public string subprocessFile;
  23. /** Editor/application log file */
  24. public string logFile;
  25. }
  26. private static CEFDirs GetCEFDirs() {
  27. #if UNITY_EDITOR
  28. //In the editor we don't know exactly where we are at, but we can look up one of our scripts and move from there
  29. var guids = AssetDatabase.FindAssets("EditorWebResources");
  30. if (guids.Length != 1) throw new FileNotFoundException("Failed to locate a single EditorWebResources file");
  31. string scriptPath = AssetDatabase.GUIDToAssetPath(guids[0]);
  32. // ReSharper disable once PossibleNullReferenceException
  33. var baseDir = Directory.GetParent(scriptPath).Parent.FullName + "/Plugins";
  34. var resourcesPath = baseDir + "/CEFResources";
  35. var localesDir = resourcesPath + "/locales";
  36. var platformDir = baseDir;
  37. #if UNITY_EDITOR_WIN
  38. #if UNITY_EDITOR_64
  39. platformDir += "/w64";
  40. #else
  41. platformDir += "/w32";
  42. #endif
  43. //Silly MS.
  44. resourcesPath = resourcesPath.Replace("/", "\\");
  45. localesDir = localesDir.Replace("/", "\\");
  46. platformDir = platformDir.Replace("/", "\\");
  47. var subprocessFile = platformDir + "/" + SlaveExecutable + ".exe";
  48. var logFile = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "/Unity/Editor/Editor.log";
  49. #elif UNITY_EDITOR_LINUX
  50. #if UNITY_EDITOR_64
  51. platformDir += "/l64";
  52. #else
  53. platformDir += "/w32";
  54. #endif
  55. var subprocessFile = platformDir + "/" + SlaveExecutable;
  56. var logFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/unity3d/Editor.log";
  57. #elif UNITY_EDITOR_OSX
  58. platformDir += "/m64";
  59. resourcesPath = platformDir + "/BrowserLib.app/Contents/Frameworks/Chromium Embedded Framework.framework/Resources";
  60. localesDir = resourcesPath;
  61. //Chromium's base::mac::GetAppBundlePath will walk up the tree until it finds an ".app" folder and start
  62. //looking for pieces from there. That's why everything is hidden in a fake "BrowserLib.app"
  63. //folder that's not actually an app.
  64. var subprocessFile = platformDir + "/BrowserLib.app/Contents/Frameworks/" + SlaveExecutable + ".app/Contents/MacOS/" + SlaveExecutable;
  65. var logFile = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/Library/Logs/Unity/Editor.log";
  66. #else
  67. #error Web textures are not supported on this platform
  68. #endif
  69. return new CEFDirs() {
  70. resourcesPath = resourcesPath,
  71. binariesPath = platformDir,
  72. localesPath = localesDir,
  73. subprocessFile = subprocessFile,
  74. logFile = logFile,
  75. };
  76. #elif UNITY_STANDALONE_WIN
  77. var resourcesPath = Application.dataPath + "/Plugins";
  78. var logFile = Application.dataPath + "/output_log.txt";
  79. #if UNITY_2017_2_OR_NEWER
  80. var appLowDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "Low/" + Application.companyName + "/" + Application.productName;
  81. if (Directory.Exists(appLowDir)) {
  82. logFile = appLowDir + "/output_log.txt";
  83. }
  84. #endif
  85. return new CEFDirs() {
  86. resourcesPath = resourcesPath,
  87. binariesPath = resourcesPath,
  88. localesPath = resourcesPath + "/locales",
  89. subprocessFile = resourcesPath + "/" + SlaveExecutable + ".exe",
  90. logFile = logFile,
  91. };
  92. #elif UNITY_STANDALONE_LINUX
  93. var resourcesPath = Application.dataPath + "/Plugins";
  94. return new CEFDirs() {
  95. resourcesPath = resourcesPath,
  96. binariesPath = resourcesPath,
  97. localesPath = resourcesPath + "/locales",
  98. subprocessFile = resourcesPath + "/" + SlaveExecutable,
  99. logFile = "/dev/null",
  100. // Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/unity3d/" +
  101. // Application.companyName + "/" + Application.productName + "/Player.log",
  102. };
  103. #elif UNITY_STANDALONE_OSX
  104. return new CEFDirs() {
  105. resourcesPath = Application.dataPath + "/Frameworks/Chromium Embedded Framework.framework/Resources",
  106. binariesPath = Application.dataPath + "/Plugins",
  107. localesPath = Application.dataPath + "/Frameworks/Chromium Embedded Framework.framework/Resources",
  108. subprocessFile = Application.dataPath + "/Frameworks/ZFGameBrowser.app/Contents/MacOS/" + SlaveExecutable,
  109. logFile = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/Library/Logs/Unity/Player.log",
  110. };
  111. #else
  112. #error Web textures are not supported on this platform
  113. #endif
  114. }
  115. }
  116. }